@typeonce/effect-machine 0.45.1 → 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} +254 -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} +49 -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 +1205 -1478
- 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 +32 -21
- 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.js +5 -3
- 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 +1149 -2134
- 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 +73 -70
- 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 +7 -7
- 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/src/Machine.ts
CHANGED
|
@@ -28,7 +28,7 @@ import * as internal from "./internal/machine/machine.js"
|
|
|
28
28
|
import { InitialEventTypeId } from "./internal/machine/machine.js"
|
|
29
29
|
import type { EnsureExecutable } from "./internal/machine/readiness.js"
|
|
30
30
|
import type { ExcludeCompatibleRuntime } from "./internal/machine/requirements.js"
|
|
31
|
-
import type
|
|
31
|
+
import type { MachineRuntime } from "./internal/machine/runtimeProtocol.js"
|
|
32
32
|
import type * as StateDefinition from "./internal/machine/stateDefinition.js"
|
|
33
33
|
import type * as Topology from "./internal/machine/topology.js"
|
|
34
34
|
|
|
@@ -49,17 +49,32 @@ export type TypeId = "~effect/Machine"
|
|
|
49
49
|
*/
|
|
50
50
|
export const TypeId: TypeId = "~effect/Machine"
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
declare const
|
|
52
|
+
// Type-level keys of public interfaces. Each is a string literal, as in
|
|
53
|
+
// Effect's own modules, so a consumer's emitted declaration prints the key
|
|
54
|
+
// itself instead of naming a private constant. None of them exists at runtime:
|
|
55
|
+
// a value that needs a runtime marker keeps a private symbol, and the public
|
|
56
|
+
// interface carries the string key as a brand only.
|
|
57
|
+
declare const MachineOutputStatesTypeId: "~effect/Machine/OutputStates"
|
|
58
|
+
declare const MachineTypeId: "~effect/Machine/TypeCarrier"
|
|
59
|
+
declare const EventConstructionTypeId: "~effect/Machine/EventConstruction"
|
|
60
|
+
declare const EmittedEventConstructionTypeId: "~effect/Machine/EmittedEventConstruction"
|
|
61
|
+
declare const EventProtocolTypeId: "~effect/Machine/EventProtocol"
|
|
62
|
+
declare const ParentModeTypeId: "~effect/Machine/ParentMode"
|
|
63
|
+
declare const ChildMachineLogicTypeId: "~effect/Machine/ChildMachineLogic"
|
|
64
|
+
declare const InvokeTypeId: "~effect/Machine/Invoke"
|
|
65
|
+
declare const StateConstructionTypeId: "~effect/Machine/StateConstruction"
|
|
66
|
+
declare const TargetSnapshotTypeId: "~effect/Machine/TargetSnapshot"
|
|
67
|
+
declare const HistoryTargetTypeId: "~effect/Machine/HistoryTarget"
|
|
68
|
+
declare const InitialTargetTypeId: "~effect/Machine/InitialTarget"
|
|
69
|
+
declare const ChoiceTargetTypeId: "~effect/Machine/ChoiceTarget"
|
|
70
|
+
declare const NoTargetTypeId: "~effect/Machine/NoTarget"
|
|
71
|
+
declare const DeclinedTypeId: "~effect/Machine/Declined"
|
|
72
|
+
declare const StateUpdateTypeId: "~effect/Machine/StateUpdate"
|
|
73
|
+
declare const CombinedTargetTypeId: "~effect/Machine/CombinedTarget"
|
|
74
|
+
declare const SelectedBranchTypeId: "~effect/Machine/SelectedBranch"
|
|
58
75
|
|
|
59
76
|
const ParentTypeId = "~effect/Machine/Parent"
|
|
60
77
|
|
|
61
|
-
const ChildMachineLogicTypeId: typeof internal.ChildMachineLogicTypeId = internal.ChildMachineLogicTypeId
|
|
62
|
-
|
|
63
78
|
/**
|
|
64
79
|
* Type identifier used for the synthetic event passed to startup lifecycle
|
|
65
80
|
* actions.
|
|
@@ -112,29 +127,38 @@ type IsAny<A> = 0 extends (1 & A) ? true : false
|
|
|
112
127
|
* **Gotchas**
|
|
113
128
|
*
|
|
114
129
|
* Use `guard` to decline a transition before constructing its next state.
|
|
115
|
-
*
|
|
130
|
+
* List `{ decline: true }` in `branches` when `resolve` may return `select.decline()`.
|
|
116
131
|
* Register cancellable state-scoped delays in `make({ timers })`.
|
|
117
132
|
*
|
|
118
|
-
* **Example**
|
|
133
|
+
* **Example** (Declining an event with a guard)
|
|
119
134
|
*
|
|
120
|
-
* ```ts
|
|
135
|
+
* ```ts import.meta.vitest
|
|
121
136
|
* import { Machine } from "@typeonce/effect-machine"
|
|
122
|
-
* import { Schema } from "effect"
|
|
137
|
+
* import { Effect, Schema } from "effect"
|
|
138
|
+
*
|
|
123
139
|
* const events = Machine.events({ Add: { by: Schema.Number } })
|
|
124
140
|
* const Root = Machine.state({ fields: { count: Schema.Number } })
|
|
125
|
-
*
|
|
141
|
+
* const counter = Machine.make({
|
|
126
142
|
* root: Root,
|
|
127
143
|
* events
|
|
128
144
|
* }).handle({
|
|
129
145
|
* root: () => ({ count: 0 }),
|
|
130
146
|
* on: {
|
|
131
147
|
* Add: {
|
|
132
|
-
* update:
|
|
133
|
-
* guard: ({ event }) => event.by > 0
|
|
134
|
-
* data: ({ root, event }) => ({ count: root.count + event.by })
|
|
148
|
+
* update: { root: ({ root, event }) => ({ count: root.count + event.by }) },
|
|
149
|
+
* guard: ({ event }) => event.by > 0
|
|
135
150
|
* }
|
|
136
151
|
* }
|
|
137
152
|
* })
|
|
153
|
+
*
|
|
154
|
+
* const accepts = (by: number) =>
|
|
155
|
+
* Effect.gen(function*() {
|
|
156
|
+
* const initial = yield* Machine.planInitial(counter)
|
|
157
|
+
* return yield* Machine.can(counter, initial.state, events.Add({ by }))
|
|
158
|
+
* })
|
|
159
|
+
*
|
|
160
|
+
* await Effect.runPromise(accepts(1)) // => true
|
|
161
|
+
* await Effect.runPromise(accepts(0)) // => false
|
|
138
162
|
* ```
|
|
139
163
|
*
|
|
140
164
|
* @category models
|
|
@@ -303,19 +327,27 @@ export interface Definition<
|
|
|
303
327
|
* captured by value, so later mutation of the supplied objects cannot alter
|
|
304
328
|
* the resulting machine.
|
|
305
329
|
*
|
|
306
|
-
* **Example**
|
|
307
|
-
*
|
|
308
|
-
* ```ts
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* }
|
|
318
|
-
* }
|
|
330
|
+
* **Example** (Adding handlers to a definition)
|
|
331
|
+
*
|
|
332
|
+
* ```ts import.meta.vitest
|
|
333
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
334
|
+
* import { Effect, Schema } from "effect"
|
|
335
|
+
*
|
|
336
|
+
* const Events = Machine.events({ Increment: { by: Schema.Number } })
|
|
337
|
+
* const definition = Machine.make({ root: Machine.state({ fields: { count: Schema.Number } }), events: Events })
|
|
338
|
+
*
|
|
339
|
+
* const counter = definition.handle({
|
|
340
|
+
* root: { count: 0 },
|
|
341
|
+
* on: { Increment: { update: { root: ({ root, event }) => ({ count: root.count + event.by }) } } }
|
|
342
|
+
* })
|
|
343
|
+
*
|
|
344
|
+
* const count = Effect.gen(function*() {
|
|
345
|
+
* const initial = yield* Machine.planInitial(counter)
|
|
346
|
+
* const planned = yield* Machine.plan(counter, initial.state, Events.Increment({ by: 2 }))
|
|
347
|
+
* return planned.next.value.count
|
|
348
|
+
* })
|
|
349
|
+
*
|
|
350
|
+
* await Effect.runPromise(count) // => 2
|
|
319
351
|
* ```
|
|
320
352
|
*
|
|
321
353
|
* @since 0.4.0
|
|
@@ -412,9 +444,31 @@ export {
|
|
|
412
444
|
StoppedError
|
|
413
445
|
} from "./internal/machine/machine.js"
|
|
414
446
|
|
|
447
|
+
export type {
|
|
448
|
+
/**
|
|
449
|
+
* Service required by operations that act on the machine executing them,
|
|
450
|
+
* such as `sendTo`, `stopChild`, and `spawn`.
|
|
451
|
+
*
|
|
452
|
+
* **When to use**
|
|
453
|
+
*
|
|
454
|
+
* Name this requirement when annotating a reusable helper built from those
|
|
455
|
+
* operations, or when exporting a value whose inferred type includes it.
|
|
456
|
+
*
|
|
457
|
+
* **Details**
|
|
458
|
+
*
|
|
459
|
+
* A running machine provides this service to the effects it executes, so it
|
|
460
|
+
* never appears in the requirements of the machine itself. Only the type is
|
|
461
|
+
* public: the service cannot be constructed or provided outside a running
|
|
462
|
+
* machine.
|
|
463
|
+
*
|
|
464
|
+
* @category services
|
|
465
|
+
* @since 0.47.0
|
|
466
|
+
*/
|
|
467
|
+
MachineRuntime
|
|
468
|
+
} from "./internal/machine/runtimeProtocol.js"
|
|
469
|
+
|
|
415
470
|
const RuntimeRequirementTypeId = "~effect/Machine/RuntimeRequirement"
|
|
416
471
|
const ActionRequirementTypeId = "~effect/Machine/ActionRequirement"
|
|
417
|
-
type MachineRuntimeRequirement = internalRuntime.MachineRuntime
|
|
418
472
|
|
|
419
473
|
/**
|
|
420
474
|
* Opaque marker used to keep staged action errors and services separate from
|
|
@@ -462,8 +516,8 @@ export type PlanningServices<Requirements> = Exclude<Requirements, ActionRequire
|
|
|
462
516
|
* @since 0.4.0
|
|
463
517
|
*/
|
|
464
518
|
export type ExecutionServices<Requirements> =
|
|
465
|
-
| Exclude<PlanningServices<Requirements>,
|
|
466
|
-
| Exclude<ActionServices<Requirements>,
|
|
519
|
+
| Exclude<PlanningServices<Requirements>, MachineRuntime>
|
|
520
|
+
| Exclude<ActionServices<Requirements>, MachineRuntime>
|
|
467
521
|
|
|
468
522
|
/**
|
|
469
523
|
* Managed runtime capability used to deliver raised events and publish
|
|
@@ -617,33 +671,6 @@ export type Command =
|
|
|
617
671
|
* @since 0.4.0
|
|
618
672
|
*/
|
|
619
673
|
export declare namespace Runtime {
|
|
620
|
-
/**
|
|
621
|
-
* Protocol annotation for managed event delivery.
|
|
622
|
-
*
|
|
623
|
-
* @category models
|
|
624
|
-
* @since 0.4.0
|
|
625
|
-
*/
|
|
626
|
-
export interface Protocol {
|
|
627
|
-
readonly events?: unknown
|
|
628
|
-
readonly emits?: unknown
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
/**
|
|
632
|
-
* Extracts the events required by a runtime protocol annotation.
|
|
633
|
-
*
|
|
634
|
-
* @category utility types
|
|
635
|
-
* @since 0.4.0
|
|
636
|
-
*/
|
|
637
|
-
export type Events<Protocol> = Protocol extends { readonly events: infer Events } ? Events : never
|
|
638
|
-
|
|
639
|
-
/**
|
|
640
|
-
* Extracts the emitted events required by a runtime protocol annotation.
|
|
641
|
-
*
|
|
642
|
-
* @category utility types
|
|
643
|
-
* @since 0.4.0
|
|
644
|
-
*/
|
|
645
|
-
export type Emits<Protocol> = Protocol extends { readonly emits: infer Emits } ? Emits : never
|
|
646
|
-
|
|
647
674
|
/**
|
|
648
675
|
* Opaque service requirement for a machine runtime capability.
|
|
649
676
|
*
|
|
@@ -666,8 +693,6 @@ type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Run
|
|
|
666
693
|
: Requirements
|
|
667
694
|
: never
|
|
668
695
|
|
|
669
|
-
const InvokeTypeId: typeof internal.InvokeTypeId = internal.InvokeTypeId
|
|
670
|
-
|
|
671
696
|
type StateDefinitionError<
|
|
672
697
|
Message extends string,
|
|
673
698
|
Path extends PropertyKey = never,
|
|
@@ -706,8 +731,6 @@ type ActiveStateKey<States extends Machine.StateSchemas> = Machine.ActiveStateKe
|
|
|
706
731
|
|
|
707
732
|
type HistoryStateKey<States extends Machine.StateSchemas> = Machine.HistoryStateKey<States>
|
|
708
733
|
|
|
709
|
-
type ChoiceStateKey<States extends Machine.StateSchemas> = Machine.ChoiceStateKey<States>
|
|
710
|
-
|
|
711
734
|
type StateDefinitionPath<Prefix extends string, Key extends PropertyKey> = Key extends string ?
|
|
712
735
|
Key extends "" ? Prefix extends "" ? "<empty>" : `${Prefix}.<empty>`
|
|
713
736
|
: Prefix extends "" ? Key
|
|
@@ -816,29 +839,6 @@ type ValidateOutputSchema<Node> = "output" extends keyof Node ? Node extends { r
|
|
|
816
839
|
: StateDefinitionError<"State output must be a schema">
|
|
817
840
|
: unknown
|
|
818
841
|
|
|
819
|
-
type SelectorChildKey<Children extends Machine.StateSchemas> = ActiveStateKey<Children> | ChoiceStateKey<Children>
|
|
820
|
-
|
|
821
|
-
type ValidateInitialSelectorChild<Children extends Machine.StateSchemas, Path extends PropertyKey> = "initial" extends
|
|
822
|
-
SelectorChildKey<Children> ? StateDefinitionError<
|
|
823
|
-
"Active and choice child states cannot use the reserved target selector key \"initial\"",
|
|
824
|
-
StateDefinitionPath<Extract<Path, string>, "initial">,
|
|
825
|
-
"initial"
|
|
826
|
-
>
|
|
827
|
-
: unknown
|
|
828
|
-
|
|
829
|
-
type ValidateWithSelectorChild<
|
|
830
|
-
Node extends Machine.StateNodeConfig,
|
|
831
|
-
Children extends Machine.StateSchemas,
|
|
832
|
-
Path extends PropertyKey
|
|
833
|
-
> = Node extends { readonly schema: Machine.TaggedSchema } ?
|
|
834
|
-
"with" extends SelectorChildKey<Children> ? StateDefinitionError<
|
|
835
|
-
"Schema-backed compound child states cannot use the reserved local target selector key \"with\"",
|
|
836
|
-
StateDefinitionPath<Extract<Path, string>, "with">,
|
|
837
|
-
"with"
|
|
838
|
-
>
|
|
839
|
-
: unknown
|
|
840
|
-
: unknown
|
|
841
|
-
|
|
842
842
|
type ValidateStateNodeWithChildren<
|
|
843
843
|
Node extends Machine.StateNodeConfig,
|
|
844
844
|
Children,
|
|
@@ -846,9 +846,8 @@ type ValidateStateNodeWithChildren<
|
|
|
846
846
|
> = Children extends Machine.StateSchemas ?
|
|
847
847
|
Node extends { readonly type: "final" } ? StateDefinitionError<"Final states cannot declare child states">
|
|
848
848
|
: Node extends { readonly type: "parallel" } ?
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
: { readonly states: ValidateStateTree<Children, true, Extract<Path, string>> } & ValidateOutputSchema<Node>)
|
|
849
|
+
"initial" extends keyof Node ? StateDefinitionError<"Parallel states cannot declare an initial child">
|
|
850
|
+
: { readonly states: ValidateStateTree<Children, true, Extract<Path, string>> } & ValidateOutputSchema<Node>
|
|
852
851
|
: "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output">
|
|
853
852
|
: ValidateCompoundStateNode<Node, Children, Path>
|
|
854
853
|
: StateDefinitionError<"Child states must be a state tree">
|
|
@@ -858,9 +857,7 @@ type ValidateCompoundStateNode<
|
|
|
858
857
|
Children extends Machine.StateSchemas,
|
|
859
858
|
Path extends PropertyKey
|
|
860
859
|
> = "initial" extends keyof Node ? StateDefinitionError<"Declare initial edges in handle", Path>
|
|
861
|
-
:
|
|
862
|
-
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>
|
|
863
|
-
}
|
|
860
|
+
: { readonly states: ValidateStateTree<Children, true, Extract<Path, string>> }
|
|
864
861
|
|
|
865
862
|
type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "initial" extends keyof Node ?
|
|
866
863
|
StateDefinitionError<"Atomic states cannot declare an initial child">
|
|
@@ -926,7 +923,27 @@ type StateFieldsValidation<Node> = Node extends { readonly [StateTypeId]: typeof
|
|
|
926
923
|
} :
|
|
927
924
|
unknown)
|
|
928
925
|
|
|
929
|
-
|
|
926
|
+
/**
|
|
927
|
+
* Declaration of one state node accepted by {@link state}: its schema or
|
|
928
|
+
* fields, its kind, and its nested child states.
|
|
929
|
+
*
|
|
930
|
+
* **When to use**
|
|
931
|
+
*
|
|
932
|
+
* Name this type when a declaration you emit includes the signature of
|
|
933
|
+
* `Machine.state`. Build state trees with `Machine.state` itself, which checks
|
|
934
|
+
* the declaration further.
|
|
935
|
+
*
|
|
936
|
+
* **Details**
|
|
937
|
+
*
|
|
938
|
+
* Each entry of `states` is a tagged schema, a nested declaration, or a
|
|
939
|
+
* descriptor returned by `Machine.state`. `Machine.state` validates the whole
|
|
940
|
+
* tree further, so satisfying this type alone does not make a declaration
|
|
941
|
+
* valid.
|
|
942
|
+
*
|
|
943
|
+
* @category models
|
|
944
|
+
* @since 0.47.0
|
|
945
|
+
*/
|
|
946
|
+
export interface StateDeclaration {
|
|
930
947
|
readonly schema?: Machine.TaggedSchema
|
|
931
948
|
readonly fields?: Schema.Struct.Fields
|
|
932
949
|
readonly type?: "active" | "parallel" | "final" | "history" | "choice"
|
|
@@ -934,7 +951,7 @@ interface StateInput {
|
|
|
934
951
|
readonly states?: Readonly<
|
|
935
952
|
Record<
|
|
936
953
|
string,
|
|
937
|
-
Machine.TaggedSchema |
|
|
954
|
+
Machine.TaggedSchema | StateDeclaration | {
|
|
938
955
|
readonly [StateTypeId]: typeof StateTypeId
|
|
939
956
|
readonly node: Machine.StateNodeConfig
|
|
940
957
|
}
|
|
@@ -945,8 +962,8 @@ interface StateInput {
|
|
|
945
962
|
readonly annotations?: Machine.SchemaLessStateAnnotations
|
|
946
963
|
}
|
|
947
964
|
|
|
948
|
-
|
|
949
|
-
<const Node extends
|
|
965
|
+
type StateConstructor = {
|
|
966
|
+
<const Node extends StateDeclaration>(
|
|
950
967
|
node: Node & StateFieldsValidation<NoInfer<Node>>,
|
|
951
968
|
..._validation: ValidateDefinedState<NormalizeState<NoInfer<Node>>>
|
|
952
969
|
): State<NormalizedState<Node>>
|
|
@@ -996,217 +1013,12 @@ type ValidateEventProtocolBuilder<
|
|
|
996
1013
|
> = [Duplicate] extends [never] ? unknown
|
|
997
1014
|
: EventProtocolError<"Event protocol tags must be unique", Duplicate>
|
|
998
1015
|
|
|
999
|
-
const SnapshotBuilderStateTypeId: typeof internal.SnapshotBuilderStateTypeId = internal.SnapshotBuilderStateTypeId
|
|
1000
|
-
const SnapshotBuilderConstructionTypeId: unique symbol = Symbol("effect/Machine/SnapshotBuilderConstruction")
|
|
1001
|
-
|
|
1002
|
-
type SnapshotBuilderComplete<Regions, Constructed extends boolean = false> = {
|
|
1003
|
-
readonly [SnapshotBuilderStateTypeId]: Regions
|
|
1004
|
-
readonly [SnapshotBuilderConstructionTypeId]: Constructed
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
type FromCallable<Arguments extends ReadonlyArray<unknown>, Result> = Arguments extends
|
|
1008
|
-
readonly [infer Input, ...infer Rest extends ReadonlyArray<unknown>] ? {} extends Input ? {
|
|
1009
|
-
(...args: Rest): Result
|
|
1010
|
-
(...args: Arguments): Result
|
|
1011
|
-
}
|
|
1012
|
-
: (...args: Arguments) => Result
|
|
1013
|
-
: (...args: Arguments) => Result
|
|
1014
|
-
|
|
1015
|
-
type FromMethod<in out Arguments extends ReadonlyArray<unknown>, out Result> = {
|
|
1016
|
-
/**
|
|
1017
|
-
* Constructs the selected state from its schema make input while the
|
|
1018
|
-
* machine plans the resulting configuration. The input may be omitted when
|
|
1019
|
-
* the schema accepts an empty constructor object.
|
|
1020
|
-
*
|
|
1021
|
-
* @since 0.4.0
|
|
1022
|
-
*/
|
|
1023
|
-
readonly from: FromCallable<Arguments, Machine.StateConstruction<Result>>
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
type DecodedMethod<Arguments extends ReadonlyArray<unknown>, Result> = {
|
|
1027
|
-
/**
|
|
1028
|
-
* Constructs the selected state from an already-decoded schema value. The
|
|
1029
|
-
* machine validates the value against the schema's type side while planning.
|
|
1030
|
-
*
|
|
1031
|
-
* @since 0.22.0
|
|
1032
|
-
*/
|
|
1033
|
-
readonly decoded: (...args: Arguments) => Result
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
type ConstructionResult<Result> = Result | Machine.StateConstruction<Result>
|
|
1037
|
-
|
|
1038
|
-
type UnwrapConstruction<Result> = Result extends Machine.StateConstruction<infer Value> ? Value : Result
|
|
1039
|
-
|
|
1040
1016
|
type NodeValue<Node> = [Machine.NodeSchema<Node>] extends [never] ? undefined
|
|
1041
1017
|
: Machine.NodeSchema<Node>["Type"]
|
|
1042
1018
|
|
|
1043
1019
|
type NodeMakeInput<Node> = [Machine.NodeSchema<Node>] extends [never] ? never
|
|
1044
1020
|
: Machine.NodeSchema<Node>["~type.make.in"]
|
|
1045
1021
|
|
|
1046
|
-
type WithNodeValue<Node, Rest extends ReadonlyArray<unknown>> = Machine.NodeSchema<Node> extends never ? Rest
|
|
1047
|
-
: readonly [value: NodeValue<Node>, ...Rest]
|
|
1048
|
-
|
|
1049
|
-
type WithNodeInput<Node, Rest extends ReadonlyArray<unknown>> = Machine.NodeSchema<Node> extends never ? Rest
|
|
1050
|
-
: readonly [input: NodeMakeInput<Node>, ...Rest]
|
|
1051
|
-
|
|
1052
|
-
type NodeBuilderMethod<
|
|
1053
|
-
Node,
|
|
1054
|
-
Arguments extends ReadonlyArray<unknown>,
|
|
1055
|
-
Result,
|
|
1056
|
-
FromArguments extends ReadonlyArray<unknown>,
|
|
1057
|
-
FromResult
|
|
1058
|
-
> = Machine.NodeSchema<Node> extends never ? {
|
|
1059
|
-
readonly from: FromCallable<FromArguments, FromResult>
|
|
1060
|
-
}
|
|
1061
|
-
: DecodedMethod<Arguments, Result> & { readonly from: FromCallable<FromArguments, FromResult> }
|
|
1062
|
-
|
|
1063
|
-
type NodeMethod<
|
|
1064
|
-
Node,
|
|
1065
|
-
Arguments extends ReadonlyArray<unknown>,
|
|
1066
|
-
Result,
|
|
1067
|
-
FromArguments extends ReadonlyArray<unknown>
|
|
1068
|
-
> = Machine.NodeSchema<Node> extends never ? FromMethod<FromArguments, Result>
|
|
1069
|
-
: DecodedMethod<Arguments, Result> & FromMethod<FromArguments, Result>
|
|
1070
|
-
|
|
1071
|
-
type NodeMethodWithInitial<
|
|
1072
|
-
Node,
|
|
1073
|
-
Arguments extends ReadonlyArray<unknown>,
|
|
1074
|
-
Result,
|
|
1075
|
-
FromArguments extends ReadonlyArray<unknown>,
|
|
1076
|
-
Path extends string
|
|
1077
|
-
> = Machine.NodeSchema<Node> extends never ? {
|
|
1078
|
-
readonly from: FromCallable<FromArguments, Machine.StateConstruction<Result>>
|
|
1079
|
-
readonly initial: InitialTargetFactory<Node, Path>
|
|
1080
|
-
}
|
|
1081
|
-
:
|
|
1082
|
-
& DecodedMethod<Arguments, Result>
|
|
1083
|
-
& {
|
|
1084
|
-
readonly from: FromCallable<FromArguments, Machine.StateConstruction<Result>>
|
|
1085
|
-
readonly initial: InitialTargetFactory<Node, Path>
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
interface InitialTargetMethod<
|
|
1089
|
-
Node,
|
|
1090
|
-
Path extends string
|
|
1091
|
-
> {
|
|
1092
|
-
/** Enters this state through its declared initial configuration. */
|
|
1093
|
-
readonly initial: InitialTargetFactory<Node, Path>
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
interface InitialTargetFactory<
|
|
1097
|
-
Node,
|
|
1098
|
-
Path extends string
|
|
1099
|
-
> {
|
|
1100
|
-
readonly from: FromCallable<
|
|
1101
|
-
WithNodeInput<Node, readonly []>,
|
|
1102
|
-
Machine.StateConstruction<Machine.InitialTarget<Path>>
|
|
1103
|
-
>
|
|
1104
|
-
readonly decoded: (...args: WithNodeValue<Node, readonly []>) => Machine.InitialTarget<Path>
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
type NodeConstructionSelectorFromCallable<Node, Builder, Result> = Machine.NodeSchema<Node> extends never ? {
|
|
1108
|
-
<Selected extends ConstructionResult<Result>>(
|
|
1109
|
-
state: (builder: Builder) => Selected
|
|
1110
|
-
): Machine.StateConstruction<UnwrapConstruction<Selected>>
|
|
1111
|
-
}
|
|
1112
|
-
: ConstructionSelectorFromCallable<NodeMakeInput<Node>, Builder, Result>
|
|
1113
|
-
|
|
1114
|
-
type NestedTargetMethod<Node, Builder, Result, Path extends string> = Machine.NodeSchema<Node> extends never ? {
|
|
1115
|
-
readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result>
|
|
1116
|
-
readonly initial: InitialTargetFactory<Node, Path>
|
|
1117
|
-
}
|
|
1118
|
-
: {
|
|
1119
|
-
readonly decoded: <Selected extends ConstructionResult<Result>>(
|
|
1120
|
-
value: NodeValue<Node>,
|
|
1121
|
-
state: (builder: Builder) => Selected
|
|
1122
|
-
) => Selected
|
|
1123
|
-
readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result>
|
|
1124
|
-
readonly initial: InitialTargetFactory<Node, Path>
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input ? {
|
|
1128
|
-
<Selected extends ConstructionResult<Result>>(
|
|
1129
|
-
state: (builder: Builder) => Selected
|
|
1130
|
-
): Machine.StateConstruction<UnwrapConstruction<Selected>>
|
|
1131
|
-
<Selected extends ConstructionResult<Result>>(
|
|
1132
|
-
input: Input,
|
|
1133
|
-
state: (builder: Builder) => Selected
|
|
1134
|
-
): Machine.StateConstruction<UnwrapConstruction<Selected>>
|
|
1135
|
-
}
|
|
1136
|
-
: <Selected extends ConstructionResult<Result>>(
|
|
1137
|
-
input: Input,
|
|
1138
|
-
state: (builder: Builder) => Selected
|
|
1139
|
-
) => Machine.StateConstruction<UnwrapConstruction<Selected>>
|
|
1140
|
-
|
|
1141
|
-
type FullSnapshotBuilderWithPrefix<
|
|
1142
|
-
in out States extends Machine.StateSchemas,
|
|
1143
|
-
in out Prefix extends string = ""
|
|
1144
|
-
> = {
|
|
1145
|
-
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]: Key extends ActiveStateKey<States>
|
|
1146
|
-
? FullSnapshotMethod<States, Key, Prefix>
|
|
1147
|
-
: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
type FullSnapshotMethod<
|
|
1151
|
-
in out States extends Machine.StateSchemas,
|
|
1152
|
-
in out StateId extends ActiveStateKey<States>,
|
|
1153
|
-
in out Prefix extends string
|
|
1154
|
-
> = {
|
|
1155
|
-
readonly [
|
|
1156
|
-
/** Constructs this node using schema make input or an already decoded value. */
|
|
1157
|
-
Method in Machine.NodeSchema<States[StateId]> extends never ? "from" : "from" | "decoded"
|
|
1158
|
-
]: Method extends "from" ? FromCallable<
|
|
1159
|
-
FullSnapshotFromArguments<States, StateId, Prefix>,
|
|
1160
|
-
Machine.StateConstruction<FullSnapshotResult<States, StateId, Prefix>>
|
|
1161
|
-
>
|
|
1162
|
-
: (...args: FullSnapshotArguments<States, StateId, Prefix>) => FullSnapshotResult<States, StateId, Prefix>
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
type FullSnapshotArguments<
|
|
1166
|
-
States extends Machine.StateSchemas,
|
|
1167
|
-
StateId extends ActiveStateKey<States>,
|
|
1168
|
-
Prefix extends string,
|
|
1169
|
-
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1170
|
-
> = States[StateId] extends infer Node ?
|
|
1171
|
-
Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1172
|
-
WithNodeValue<Node, [
|
|
1173
|
-
states: (
|
|
1174
|
-
builder: FullParallelBuilder<Children, Path>
|
|
1175
|
-
) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
|
|
1176
|
-
]>
|
|
1177
|
-
: Node extends { readonly states: infer Children extends Machine.StateSchemas } ? WithNodeValue<Node, [
|
|
1178
|
-
state: (
|
|
1179
|
-
builder: FullSnapshotBuilderWithPrefix<Children, Path>
|
|
1180
|
-
) =>
|
|
1181
|
-
| Machine.SnapshotWithPrefix<Children, Path>
|
|
1182
|
-
| Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>
|
|
1183
|
-
]>
|
|
1184
|
-
: WithNodeValue<Node, []>
|
|
1185
|
-
: never
|
|
1186
|
-
|
|
1187
|
-
type FullSnapshotFromArguments<
|
|
1188
|
-
States extends Machine.StateSchemas,
|
|
1189
|
-
StateId extends ActiveStateKey<States>,
|
|
1190
|
-
Prefix extends string,
|
|
1191
|
-
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1192
|
-
> = States[StateId] extends infer Node ?
|
|
1193
|
-
Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1194
|
-
WithNodeInput<Node, [
|
|
1195
|
-
states: (
|
|
1196
|
-
builder: FullParallelBuilder<Children, Path>
|
|
1197
|
-
) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
1198
|
-
]>
|
|
1199
|
-
: Node extends { readonly states: infer Children extends Machine.StateSchemas } ? WithNodeInput<Node, [
|
|
1200
|
-
state: (
|
|
1201
|
-
builder: FullSnapshotBuilderWithPrefix<Children, Path>
|
|
1202
|
-
) => ConstructionResult<
|
|
1203
|
-
| Machine.SnapshotWithPrefix<Children, Path>
|
|
1204
|
-
| Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>
|
|
1205
|
-
>
|
|
1206
|
-
]>
|
|
1207
|
-
: WithNodeInput<Node, []>
|
|
1208
|
-
: never
|
|
1209
|
-
|
|
1210
1022
|
type FullSnapshotResult<
|
|
1211
1023
|
States extends Machine.StateSchemas,
|
|
1212
1024
|
StateId extends ActiveStateKey<States>,
|
|
@@ -1214,88 +1026,6 @@ type FullSnapshotResult<
|
|
|
1214
1026
|
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1215
1027
|
> = Machine.SnapshotByIdentifierWithPath<States, StateId, Path>
|
|
1216
1028
|
|
|
1217
|
-
type InitialEntryStateKey<States extends Machine.StateSchemas> = {
|
|
1218
|
-
readonly [Key in ActiveStateKey<States>]: States[Key] extends { readonly states: Machine.StateSchemas } ? Key : never
|
|
1219
|
-
}[ActiveStateKey<States>]
|
|
1220
|
-
|
|
1221
|
-
type FullInitialTargetBuilder<States extends Machine.StateSchemas> = {
|
|
1222
|
-
readonly [Key in InitialEntryStateKey<States>]: InitialTargetMethod<States[Key], Key>
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
type FullParallelBuilder<
|
|
1226
|
-
States extends Machine.StateSchemas,
|
|
1227
|
-
Prefix extends string,
|
|
1228
|
-
Remaining extends ActiveStateKey<States> = ActiveStateKey<States>,
|
|
1229
|
-
Regions = {},
|
|
1230
|
-
Constructed extends boolean = false
|
|
1231
|
-
> =
|
|
1232
|
-
& SnapshotBuilderComplete<Regions, Constructed>
|
|
1233
|
-
& {
|
|
1234
|
-
readonly [Key in Remaining]: NodeBuilderMethod<
|
|
1235
|
-
States[Key],
|
|
1236
|
-
FullSnapshotArguments<States, Key, Prefix>,
|
|
1237
|
-
FullParallelBuilder<
|
|
1238
|
-
States,
|
|
1239
|
-
Prefix,
|
|
1240
|
-
Exclude<Remaining, Key>,
|
|
1241
|
-
Regions & { readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix> },
|
|
1242
|
-
Constructed
|
|
1243
|
-
>,
|
|
1244
|
-
FullSnapshotFromArguments<States, Key, Prefix>,
|
|
1245
|
-
FullParallelBuilder<
|
|
1246
|
-
States,
|
|
1247
|
-
Prefix,
|
|
1248
|
-
Exclude<Remaining, Key>,
|
|
1249
|
-
Regions & { readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix> },
|
|
1250
|
-
true
|
|
1251
|
-
>
|
|
1252
|
-
>
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
type HistorySnapshotArguments<
|
|
1256
|
-
States extends Machine.StateSchemas,
|
|
1257
|
-
StateId extends ActiveStateKey<States>,
|
|
1258
|
-
Prefix extends string,
|
|
1259
|
-
Owner extends string,
|
|
1260
|
-
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1261
|
-
> = Path extends Owner ? FullSnapshotArguments<States, StateId, Prefix>
|
|
1262
|
-
: States[StateId] extends infer Node ?
|
|
1263
|
-
Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1264
|
-
WithNodeValue<Node, [
|
|
1265
|
-
states: (
|
|
1266
|
-
builder: HistoryParallelBuilder<Children, Path, Owner>
|
|
1267
|
-
) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>>
|
|
1268
|
-
]>
|
|
1269
|
-
: Node extends { readonly states: infer Children extends Machine.StateSchemas } ? WithNodeValue<Node, [
|
|
1270
|
-
state: (
|
|
1271
|
-
builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>
|
|
1272
|
-
) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
|
|
1273
|
-
]>
|
|
1274
|
-
: never
|
|
1275
|
-
: never
|
|
1276
|
-
|
|
1277
|
-
type HistorySnapshotFromArguments<
|
|
1278
|
-
States extends Machine.StateSchemas,
|
|
1279
|
-
StateId extends ActiveStateKey<States>,
|
|
1280
|
-
Prefix extends string,
|
|
1281
|
-
Owner extends string,
|
|
1282
|
-
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1283
|
-
> = Path extends Owner ? FullSnapshotFromArguments<States, StateId, Prefix>
|
|
1284
|
-
: States[StateId] extends infer Node ?
|
|
1285
|
-
Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1286
|
-
WithNodeInput<Node, [
|
|
1287
|
-
states: (
|
|
1288
|
-
builder: HistoryParallelBuilder<Children, Path, Owner>
|
|
1289
|
-
) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>, boolean>
|
|
1290
|
-
]>
|
|
1291
|
-
: Node extends { readonly states: infer Children extends Machine.StateSchemas } ? WithNodeInput<Node, [
|
|
1292
|
-
state: (
|
|
1293
|
-
builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>
|
|
1294
|
-
) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
|
|
1295
|
-
]>
|
|
1296
|
-
: never
|
|
1297
|
-
: never
|
|
1298
|
-
|
|
1299
1029
|
type HistorySnapshotResult<
|
|
1300
1030
|
States extends Machine.StateSchemas,
|
|
1301
1031
|
StateId extends ActiveStateKey<States>,
|
|
@@ -1318,22 +1048,6 @@ type HistorySnapshotResult<
|
|
|
1318
1048
|
: never
|
|
1319
1049
|
: never
|
|
1320
1050
|
|
|
1321
|
-
type HistorySnapshotMethod<
|
|
1322
|
-
in out States extends Machine.StateSchemas,
|
|
1323
|
-
in out StateId extends ActiveStateKey<States>,
|
|
1324
|
-
in out Prefix extends string,
|
|
1325
|
-
in out Owner extends string
|
|
1326
|
-
> = {
|
|
1327
|
-
readonly [Key in Machine.NodeSchema<States[StateId]> extends never ? "from" : "from" | "decoded"]: Key extends
|
|
1328
|
-
"from" ? FromCallable<
|
|
1329
|
-
HistorySnapshotFromArguments<States, StateId, Prefix, Owner>,
|
|
1330
|
-
Machine.StateConstruction<HistorySnapshotResult<States, StateId, Prefix, Owner>>
|
|
1331
|
-
> :
|
|
1332
|
-
(
|
|
1333
|
-
...args: HistorySnapshotArguments<States, StateId, Prefix, Owner>
|
|
1334
|
-
) => HistorySnapshotResult<States, StateId, Prefix, Owner>
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
1051
|
type HistorySnapshotWithPrefix<
|
|
1338
1052
|
States extends Machine.StateSchemas,
|
|
1339
1053
|
Owner extends string,
|
|
@@ -1346,352 +1060,20 @@ type HistorySnapshotWithPrefix<
|
|
|
1346
1060
|
: never
|
|
1347
1061
|
}[ActiveStateKey<States>]
|
|
1348
1062
|
|
|
1349
|
-
type
|
|
1350
|
-
States extends Machine.StateSchemas,
|
|
1351
|
-
Owner extends string,
|
|
1352
|
-
Prefix extends string = ""
|
|
1353
|
-
> = {
|
|
1354
|
-
readonly [
|
|
1355
|
-
Key in ActiveStateKey<States> as Owner extends
|
|
1356
|
-
| Machine.JoinPath<Prefix, Key>
|
|
1357
|
-
| (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? Key
|
|
1358
|
-
: never
|
|
1359
|
-
]: HistorySnapshotMethod<States, Key, Prefix, Owner>
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
type HistorySnapshotRegions<
|
|
1363
|
-
States extends Machine.StateSchemas,
|
|
1364
|
-
Prefix extends string,
|
|
1365
|
-
Owner extends string
|
|
1366
|
-
> = {
|
|
1367
|
-
readonly [Key in ActiveStateKey<States>]: Owner extends
|
|
1368
|
-
| Machine.JoinPath<Prefix, Key>
|
|
1369
|
-
| (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ?
|
|
1370
|
-
HistorySnapshotResult<States, Key, Prefix, Owner>
|
|
1371
|
-
: FullSnapshotResult<States, Key, Prefix>
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
type HistoryParallelBuilder<
|
|
1375
|
-
States extends Machine.StateSchemas,
|
|
1376
|
-
Prefix extends string,
|
|
1377
|
-
Owner extends string,
|
|
1378
|
-
Remaining extends ActiveStateKey<States> = ActiveStateKey<States>,
|
|
1379
|
-
Regions = {},
|
|
1380
|
-
Constructed extends boolean = false
|
|
1381
|
-
> =
|
|
1382
|
-
& SnapshotBuilderComplete<Regions, Constructed>
|
|
1383
|
-
& {
|
|
1384
|
-
readonly [Key in Remaining]: Owner extends
|
|
1385
|
-
| Machine.JoinPath<Prefix, Key>
|
|
1386
|
-
| (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ?
|
|
1387
|
-
NodeBuilderMethod<
|
|
1388
|
-
States[Key],
|
|
1389
|
-
HistorySnapshotArguments<States, Key, Prefix, Owner>,
|
|
1390
|
-
HistoryParallelBuilder<
|
|
1391
|
-
States,
|
|
1392
|
-
Prefix,
|
|
1393
|
-
Owner,
|
|
1394
|
-
Exclude<Remaining, Key>,
|
|
1395
|
-
Regions & { readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner> },
|
|
1396
|
-
Constructed
|
|
1397
|
-
>,
|
|
1398
|
-
HistorySnapshotFromArguments<States, Key, Prefix, Owner>,
|
|
1399
|
-
HistoryParallelBuilder<
|
|
1400
|
-
States,
|
|
1401
|
-
Prefix,
|
|
1402
|
-
Owner,
|
|
1403
|
-
Exclude<Remaining, Key>,
|
|
1404
|
-
Regions & { readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner> },
|
|
1405
|
-
true
|
|
1406
|
-
>
|
|
1407
|
-
>
|
|
1408
|
-
: NodeBuilderMethod<
|
|
1409
|
-
States[Key],
|
|
1410
|
-
FullSnapshotArguments<States, Key, Prefix>,
|
|
1411
|
-
HistoryParallelBuilder<
|
|
1412
|
-
States,
|
|
1413
|
-
Prefix,
|
|
1414
|
-
Owner,
|
|
1415
|
-
Exclude<Remaining, Key>,
|
|
1416
|
-
Regions & { readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix> },
|
|
1417
|
-
Constructed
|
|
1418
|
-
>,
|
|
1419
|
-
FullSnapshotFromArguments<States, Key, Prefix>,
|
|
1420
|
-
HistoryParallelBuilder<
|
|
1421
|
-
States,
|
|
1422
|
-
Prefix,
|
|
1423
|
-
Owner,
|
|
1424
|
-
Exclude<Remaining, Key>,
|
|
1425
|
-
Regions & { readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix> },
|
|
1426
|
-
true
|
|
1427
|
-
>
|
|
1428
|
-
>
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
type ParentPath<Path extends string> = Machine.ImmediateParentStateIdentifier<Path>
|
|
1432
|
-
|
|
1433
|
-
type IsCompoundNode<Node> = Node extends { readonly type: "parallel" } ? false
|
|
1434
|
-
: Node extends { readonly states: Machine.StateSchemas } ? true
|
|
1435
|
-
: false
|
|
1436
|
-
|
|
1437
|
-
type NearestCompoundScope<
|
|
1438
|
-
States extends Machine.StateSchemas,
|
|
1439
|
-
Source extends Machine.StateNodeIdentifier<States>
|
|
1440
|
-
> = Source extends Machine.StateIdentifier<States> ?
|
|
1441
|
-
IsCompoundNode<Machine.NodeByIdentifier<States, Source>> extends true ? Source
|
|
1442
|
-
: ParentPath<Source> extends infer Parent extends Machine.StateIdentifier<States> ?
|
|
1443
|
-
NearestCompoundScope<States, Parent>
|
|
1444
|
-
: never
|
|
1445
|
-
: ParentPath<Source> extends infer Parent extends Machine.StateIdentifier<States> ?
|
|
1446
|
-
NearestCompoundScope<States, Parent>
|
|
1447
|
-
: never
|
|
1448
|
-
|
|
1449
|
-
type ChildrenOf<
|
|
1450
|
-
States extends Machine.StateSchemas,
|
|
1451
|
-
Path extends Machine.StateIdentifier<States>
|
|
1452
|
-
> = Machine.NodeByIdentifier<States, Path> extends { readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1453
|
-
Children
|
|
1454
|
-
: never
|
|
1455
|
-
|
|
1456
|
-
type StateIdentifierFromPath<
|
|
1457
|
-
States extends Machine.StateSchemas,
|
|
1458
|
-
Path extends string
|
|
1459
|
-
> = Extract<Path, Machine.StateIdentifier<States>>
|
|
1460
|
-
|
|
1461
|
-
type LocalTargetResult<
|
|
1462
|
-
AllStates extends Machine.StateSchemas,
|
|
1463
|
-
States extends Machine.StateSchemas,
|
|
1464
|
-
StateId extends ActiveStateKey<States>,
|
|
1465
|
-
Prefix extends string,
|
|
1466
|
-
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1467
|
-
> = States[StateId] extends { readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1468
|
-
States[StateId] extends { readonly type: "parallel" } ?
|
|
1469
|
-
Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>
|
|
1470
|
-
: LocalTargetResultWithPrefix<AllStates, Children, Path>
|
|
1471
|
-
: Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>
|
|
1472
|
-
|
|
1473
|
-
type LocalTargetResultWithPrefix<
|
|
1474
|
-
AllStates extends Machine.StateSchemas,
|
|
1475
|
-
States extends Machine.StateSchemas,
|
|
1476
|
-
Prefix extends string
|
|
1477
|
-
> =
|
|
1478
|
-
| {
|
|
1479
|
-
readonly [Key in ActiveStateKey<States>]: LocalTargetResult<AllStates, States, Key, Prefix>
|
|
1480
|
-
}[ActiveStateKey<States>]
|
|
1481
|
-
| Machine.ChoiceTarget<
|
|
1482
|
-
AllStates,
|
|
1483
|
-
Extract<Machine.JoinPath<Prefix, ChoiceStateKey<States>>, Machine.ChoiceIdentifier<AllStates>>
|
|
1484
|
-
>
|
|
1485
|
-
|
|
1486
|
-
type LocalTargetBuilderWithPrefix<
|
|
1487
|
-
AllStates extends Machine.StateSchemas,
|
|
1488
|
-
States extends Machine.StateSchemas,
|
|
1489
|
-
Prefix extends string,
|
|
1490
|
-
Source extends Machine.StateNodeIdentifier<AllStates>
|
|
1491
|
-
> =
|
|
1492
|
-
& {
|
|
1493
|
-
readonly [Key in ActiveStateKey<States>]: LocalTargetMethod<AllStates, States, Key, Prefix, Source>
|
|
1494
|
-
}
|
|
1495
|
-
& {
|
|
1496
|
-
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTarget<
|
|
1497
|
-
AllStates,
|
|
1498
|
-
Extract<Machine.JoinPath<Prefix, Key>, Machine.ChoiceIdentifier<AllStates>>
|
|
1499
|
-
>
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
type LocalTargetMethod<
|
|
1503
|
-
AllStates extends Machine.StateSchemas,
|
|
1504
|
-
States extends Machine.StateSchemas,
|
|
1505
|
-
StateId extends ActiveStateKey<States>,
|
|
1506
|
-
Prefix extends string,
|
|
1507
|
-
Source extends Machine.StateNodeIdentifier<AllStates>,
|
|
1508
|
-
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1509
|
-
> = States[StateId] extends infer Node ?
|
|
1510
|
-
Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1511
|
-
Source extends Path | (Path extends "" ? string : `${Path}.${string}`) ? NestedTargetMethod<
|
|
1512
|
-
Node,
|
|
1513
|
-
LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
|
|
1514
|
-
LocalTargetResultWithPrefix<AllStates, Children, Path>,
|
|
1515
|
-
Path
|
|
1516
|
-
>
|
|
1517
|
-
: NodeMethodWithInitial<
|
|
1518
|
-
Node,
|
|
1519
|
-
WithNodeValue<Node, [
|
|
1520
|
-
states: (
|
|
1521
|
-
builder: FullParallelBuilder<Children, Path>
|
|
1522
|
-
) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
|
|
1523
|
-
]>,
|
|
1524
|
-
Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>,
|
|
1525
|
-
WithNodeInput<Node, [
|
|
1526
|
-
states: (
|
|
1527
|
-
builder: FullParallelBuilder<Children, Path>
|
|
1528
|
-
) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
1529
|
-
]>,
|
|
1530
|
-
Path
|
|
1531
|
-
>
|
|
1532
|
-
: Node extends { readonly states: infer Children extends Machine.StateSchemas } ? NestedTargetMethod<
|
|
1533
|
-
Node,
|
|
1534
|
-
LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
|
|
1535
|
-
LocalTargetResultWithPrefix<AllStates, Children, Path>,
|
|
1536
|
-
Path
|
|
1537
|
-
>
|
|
1538
|
-
: NodeMethod<
|
|
1539
|
-
Node,
|
|
1540
|
-
WithNodeValue<Node, []>,
|
|
1541
|
-
Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>,
|
|
1542
|
-
WithNodeInput<Node, []>
|
|
1543
|
-
>
|
|
1544
|
-
: never
|
|
1545
|
-
|
|
1546
|
-
type LocalTargetBuilderForScope<
|
|
1547
|
-
States extends Machine.StateSchemas,
|
|
1548
|
-
Scope extends Machine.StateIdentifier<States>,
|
|
1549
|
-
Source extends Machine.StateNodeIdentifier<States>
|
|
1550
|
-
> = ChildrenOf<States, Scope> extends infer Children extends Machine.StateSchemas ?
|
|
1551
|
-
& LocalTargetBuilderWithPrefix<States, Children, Scope, Source>
|
|
1552
|
-
& (Scope extends Machine.ValuedStateIdentifier<States> ? {
|
|
1553
|
-
/**
|
|
1554
|
-
* Updates the value of the state containing the local group and moves to
|
|
1555
|
-
* one of the states inside it. Values in other active branches are kept.
|
|
1556
|
-
*
|
|
1557
|
-
* @since 0.4.0
|
|
1558
|
-
*/
|
|
1559
|
-
readonly with: {
|
|
1560
|
-
readonly decoded: <Result extends ConstructionResult<LocalTargetResultWithPrefix<States, Children, Scope>>>(
|
|
1561
|
-
value: Machine.StateByIdentifier<States, Scope>,
|
|
1562
|
-
state: (
|
|
1563
|
-
builder: LocalTargetBuilderWithPrefix<States, Children, Scope, Source>
|
|
1564
|
-
) => Result
|
|
1565
|
-
) => Result
|
|
1566
|
-
readonly from: ConstructionSelectorFromCallable<
|
|
1567
|
-
Machine.SchemaByIdentifier<States, Scope>["~type.make.in"],
|
|
1568
|
-
LocalTargetBuilderWithPrefix<States, Children, Scope, Source>,
|
|
1569
|
-
LocalTargetResultWithPrefix<States, Children, Scope>
|
|
1570
|
-
>
|
|
1571
|
-
}
|
|
1572
|
-
} :
|
|
1573
|
-
{})
|
|
1574
|
-
: {}
|
|
1575
|
-
|
|
1576
|
-
type BranchTargetResult<
|
|
1577
|
-
AllStates extends Machine.StateSchemas,
|
|
1578
|
-
States extends Machine.StateSchemas,
|
|
1579
|
-
StateId extends ActiveStateKey<States>,
|
|
1580
|
-
Prefix extends string,
|
|
1581
|
-
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1582
|
-
> = States[StateId] extends { readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1583
|
-
States[StateId] extends { readonly type: "parallel" } ?
|
|
1584
|
-
Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>
|
|
1585
|
-
: BranchTargetResultWithPrefix<AllStates, Children, Path>
|
|
1586
|
-
: Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>
|
|
1587
|
-
|
|
1588
|
-
type BranchTargetResultWithPrefix<
|
|
1589
|
-
AllStates extends Machine.StateSchemas,
|
|
1590
|
-
States extends Machine.StateSchemas,
|
|
1591
|
-
Prefix extends string
|
|
1592
|
-
> =
|
|
1593
|
-
| {
|
|
1594
|
-
readonly [Key in ActiveStateKey<States>]: BranchTargetResult<AllStates, States, Key, Prefix>
|
|
1595
|
-
}[ActiveStateKey<States>]
|
|
1596
|
-
| Machine.ChoiceTarget<
|
|
1597
|
-
AllStates,
|
|
1598
|
-
Extract<Machine.JoinPath<Prefix, ChoiceStateKey<States>>, Machine.ChoiceIdentifier<AllStates>>
|
|
1599
|
-
>
|
|
1600
|
-
|
|
1601
|
-
type BranchTargetBuilderWithPrefix<
|
|
1602
|
-
AllStates extends Machine.StateSchemas,
|
|
1603
|
-
States extends Machine.StateSchemas,
|
|
1604
|
-
Prefix extends string,
|
|
1605
|
-
Source extends Machine.StateNodeIdentifier<AllStates>
|
|
1606
|
-
> =
|
|
1607
|
-
& {
|
|
1608
|
-
readonly [Key in ActiveStateKey<States>]: BranchTargetMethod<AllStates, States, Key, Prefix, Source>
|
|
1609
|
-
}
|
|
1610
|
-
& {
|
|
1611
|
-
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTarget<
|
|
1612
|
-
AllStates,
|
|
1613
|
-
Extract<Machine.JoinPath<Prefix, Key>, Machine.ChoiceIdentifier<AllStates>>
|
|
1614
|
-
>
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
type BranchTargetMethod<
|
|
1618
|
-
AllStates extends Machine.StateSchemas,
|
|
1619
|
-
States extends Machine.StateSchemas,
|
|
1620
|
-
StateId extends ActiveStateKey<States>,
|
|
1621
|
-
Prefix extends string,
|
|
1622
|
-
Source extends Machine.StateNodeIdentifier<AllStates>,
|
|
1623
|
-
Path extends string = Machine.JoinPath<Prefix, StateId>
|
|
1624
|
-
> = States[StateId] extends infer Node ?
|
|
1625
|
-
Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1626
|
-
Source extends Path | (Path extends "" ? string : `${Path}.${string}`) ?
|
|
1627
|
-
& NestedTargetMethod<
|
|
1628
|
-
Node,
|
|
1629
|
-
BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
|
|
1630
|
-
BranchTargetResultWithPrefix<AllStates, Children, Path>,
|
|
1631
|
-
Path
|
|
1632
|
-
>
|
|
1633
|
-
& BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>
|
|
1634
|
-
: NodeMethodWithInitial<
|
|
1635
|
-
Node,
|
|
1636
|
-
WithNodeValue<Node, [
|
|
1637
|
-
states: (
|
|
1638
|
-
builder: FullParallelBuilder<Children, Path>
|
|
1639
|
-
) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
|
|
1640
|
-
]>,
|
|
1641
|
-
Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>,
|
|
1642
|
-
WithNodeInput<Node, [
|
|
1643
|
-
states: (
|
|
1644
|
-
builder: FullParallelBuilder<Children, Path>
|
|
1645
|
-
) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
1646
|
-
]>,
|
|
1647
|
-
Path
|
|
1648
|
-
>
|
|
1649
|
-
: Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1650
|
-
& NestedTargetMethod<
|
|
1651
|
-
Node,
|
|
1652
|
-
BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
|
|
1653
|
-
BranchTargetResultWithPrefix<AllStates, Children, Path>,
|
|
1654
|
-
Path
|
|
1655
|
-
>
|
|
1656
|
-
& BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>
|
|
1657
|
-
: NodeMethod<
|
|
1658
|
-
Node,
|
|
1659
|
-
WithNodeValue<Node, []>,
|
|
1660
|
-
Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>,
|
|
1661
|
-
WithNodeInput<Node, []>
|
|
1662
|
-
>
|
|
1663
|
-
: never
|
|
1664
|
-
|
|
1665
|
-
type BranchTargetBuilderForRoot<
|
|
1666
|
-
States extends Machine.StateSchemas,
|
|
1667
|
-
Root extends ActiveStateKey<States>,
|
|
1668
|
-
Source extends Machine.StateNodeIdentifier<States>
|
|
1669
|
-
> = {
|
|
1670
|
-
readonly [Key in Root]: BranchTargetMethod<States, States, Key, "", Source>
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
|
-
type HistoryContainingKey<States extends Machine.StateSchemas> = {
|
|
1674
|
-
readonly [Key in Extract<keyof States, string>]: States[Key] extends Machine.HistoryStateNodeConfig ? Key
|
|
1675
|
-
: States[Key] extends { readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1676
|
-
[Machine.HistoryIdentifier<Children>] extends [never] ? never : Key
|
|
1677
|
-
: never
|
|
1678
|
-
}[Extract<keyof States, string>]
|
|
1679
|
-
|
|
1680
|
-
type HistoryTargetBuilderWithPrefix<
|
|
1681
|
-
AllStates extends Machine.StateSchemas,
|
|
1063
|
+
type HistorySnapshotRegions<
|
|
1682
1064
|
States extends Machine.StateSchemas,
|
|
1683
|
-
Prefix extends string
|
|
1065
|
+
Prefix extends string,
|
|
1066
|
+
Owner extends string
|
|
1684
1067
|
> = {
|
|
1685
|
-
readonly [Key in
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
>
|
|
1690
|
-
: States[Key] extends { readonly states: infer Children extends Machine.StateSchemas } ?
|
|
1691
|
-
HistoryTargetBuilderWithPrefix<AllStates, Children, Machine.JoinPath<Prefix, Key>>
|
|
1692
|
-
: never
|
|
1068
|
+
readonly [Key in ActiveStateKey<States>]: Owner extends
|
|
1069
|
+
| Machine.JoinPath<Prefix, Key>
|
|
1070
|
+
| (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ?
|
|
1071
|
+
HistorySnapshotResult<States, Key, Prefix, Owner>
|
|
1072
|
+
: FullSnapshotResult<States, Key, Prefix>
|
|
1693
1073
|
}
|
|
1694
1074
|
|
|
1075
|
+
type ParentPath<Path extends string> = Machine.ImmediateParentStateIdentifier<Path>
|
|
1076
|
+
|
|
1695
1077
|
type HasDirectShallowHistory<States extends Machine.StateSchemas> = {
|
|
1696
1078
|
readonly [Key in HistoryStateKey<States>]: States[Key] extends { readonly history: "deep" } ? never : Key
|
|
1697
1079
|
}[HistoryStateKey<States>] extends never ? false : true
|
|
@@ -1762,7 +1144,7 @@ type SpawnError<Options extends SpawnOptions> = SpawnIdError<Options>
|
|
|
1762
1144
|
type SpawnResult<State, Event, Error, Requirements, Output, SpawnError, InitialError = never> = Effect.Effect<
|
|
1763
1145
|
MachineRef<State, Event, Error, Output>,
|
|
1764
1146
|
SpawnError | InitialError,
|
|
1765
|
-
|
|
1147
|
+
MachineRuntime | SpawnRequirements<Requirements>
|
|
1766
1148
|
>
|
|
1767
1149
|
|
|
1768
1150
|
/**
|
|
@@ -2065,9 +1447,14 @@ export interface Prepared<out State, in Event, out Error, out Output, out Emitte
|
|
|
2065
1447
|
* `send` reports whether an event was accepted for delivery. A running
|
|
2066
1448
|
* machine reference is local, so an idle machine processes an accepted event
|
|
2067
1449
|
* in the sender's turn: work that completes without suspending is reflected
|
|
2068
|
-
* by `snapshot` when `send` returns. Work
|
|
2069
|
-
*
|
|
2070
|
-
*
|
|
1450
|
+
* by `snapshot` when `send` returns. Work invoked by an entered state also
|
|
1451
|
+
* starts in the sender's turn and runs until it first suspends, so browser
|
|
1452
|
+
* APIs that require user activation, such as `window.open`, can run in the
|
|
1453
|
+
* first step of an invoked Effect. Work that suspends continues in the
|
|
1454
|
+
* background, and its outcome is handled in a later turn, even when the work
|
|
1455
|
+
* completes without suspending, so the entered state is always observed
|
|
1456
|
+
* before the outcome leaves it. An event sent while the machine is processing
|
|
1457
|
+
* is queued behind the current work. `changes` subscribers receive every committed
|
|
2071
1458
|
* snapshot in order once the sender yields, with consecutive sends delivered
|
|
2072
1459
|
* together. This guarantee belongs to `MachineRef`; a `MachineTarget` only
|
|
2073
1460
|
* promises delivery. Errors that occur while processing an accepted event are
|
|
@@ -2110,7 +1497,8 @@ export interface MachineRef<out State, in Event, out Error = never, out Output =
|
|
|
2110
1497
|
/**
|
|
2111
1498
|
* Accepts an event for processing by this local machine. An idle machine
|
|
2112
1499
|
* processes it in the sender's turn until the work first suspends, so
|
|
2113
|
-
* `snapshot` reflects it when `send` returns.
|
|
1500
|
+
* `snapshot` reflects it when `send` returns. Work invoked by an entered
|
|
1501
|
+
* state starts in the same turn; its outcome is handled in a later turn.
|
|
2114
1502
|
*/
|
|
2115
1503
|
readonly send: (event: Event) => Effect.Effect<void, StoppedError>
|
|
2116
1504
|
|
|
@@ -2284,10 +1672,11 @@ type InvokeLifecycleId = string & { readonly [ChildAddressTypeId]?: never }
|
|
|
2284
1672
|
*
|
|
2285
1673
|
* **Details**
|
|
2286
1674
|
*
|
|
2287
|
-
* The descriptor carries the child's address and complete machine type.
|
|
2288
|
-
*
|
|
2289
|
-
*
|
|
2290
|
-
* without separate
|
|
1675
|
+
* The descriptor carries the child's address and complete machine type.
|
|
1676
|
+
* Register it in `make({ children })` to invoke it by `src`, and pass a
|
|
1677
|
+
* descriptor for the same id and machine to `sendTo` and child lookup APIs, so
|
|
1678
|
+
* state, event, error, and output types are inferred without separate
|
|
1679
|
+
* annotations.
|
|
2291
1680
|
*
|
|
2292
1681
|
* @category models
|
|
2293
1682
|
* @since 0.4.0
|
|
@@ -2301,8 +1690,8 @@ export interface ChildMachine<Id extends string, M extends Machine.Any> {
|
|
|
2301
1690
|
/** Complete machine definition carried by this descriptor. */
|
|
2302
1691
|
readonly machine: M
|
|
2303
1692
|
|
|
2304
|
-
/** @internal */
|
|
2305
|
-
readonly [ChildMachineLogicTypeId]:
|
|
1693
|
+
/** @internal Brand of descriptors built by `child` and `childFamily`. */
|
|
1694
|
+
readonly [ChildMachineLogicTypeId]: typeof ChildMachineLogicTypeId
|
|
2306
1695
|
}
|
|
2307
1696
|
|
|
2308
1697
|
/**
|
|
@@ -2401,7 +1790,7 @@ export declare namespace ChildMachine {
|
|
|
2401
1790
|
*/
|
|
2402
1791
|
export type StartRequirements<Child extends Any> = Child extends ChildMachine<string, infer M> ? Exclude<
|
|
2403
1792
|
ExcludeCompatibleRuntime<
|
|
2404
|
-
Exclude<ExecutionServices<Machine.InitialServices<M> | Machine.Services<M>>,
|
|
1793
|
+
Exclude<ExecutionServices<Machine.InitialServices<M> | Machine.Services<M>>, MachineRuntime>,
|
|
2405
1794
|
Machine.Event<M>,
|
|
2406
1795
|
Machine.EmittedEvent<M>
|
|
2407
1796
|
>,
|
|
@@ -2541,16 +1930,6 @@ export interface SpawnOptions {
|
|
|
2541
1930
|
readonly id?: string
|
|
2542
1931
|
}
|
|
2543
1932
|
|
|
2544
|
-
/**
|
|
2545
|
-
* Options for spawning child processes with a parent-local id.
|
|
2546
|
-
*
|
|
2547
|
-
* @category models
|
|
2548
|
-
* @since 0.4.0
|
|
2549
|
-
*/
|
|
2550
|
-
export interface SpawnIdOptions extends SpawnOptions {
|
|
2551
|
-
readonly id: string
|
|
2552
|
-
}
|
|
2553
|
-
|
|
2554
1933
|
/**
|
|
2555
1934
|
* Namespace containing type-level members associated with `Machine`.
|
|
2556
1935
|
*
|
|
@@ -2859,7 +2238,19 @@ export declare namespace Machine {
|
|
|
2859
2238
|
/** Identifies whether an event protocol is accepted publicly or only inside a machine. */
|
|
2860
2239
|
export type EventProtocolKind = "public" | "internal" | "emitted"
|
|
2861
2240
|
|
|
2862
|
-
|
|
2241
|
+
/**
|
|
2242
|
+
* Fields accepted by the constructor of one event in an event protocol.
|
|
2243
|
+
*
|
|
2244
|
+
* **Details**
|
|
2245
|
+
*
|
|
2246
|
+
* The input is the event schema's constructor input without `_tag`, which
|
|
2247
|
+
* the constructor supplies. When every field is optional, so is the
|
|
2248
|
+
* constructor's argument.
|
|
2249
|
+
*
|
|
2250
|
+
* @category utility types
|
|
2251
|
+
* @since 0.23.0
|
|
2252
|
+
*/
|
|
2253
|
+
export type EventConstructorInput<EventSchema extends TaggedSchema> = Omit<EventSchema["~type.make.in"], "_tag">
|
|
2863
2254
|
|
|
2864
2255
|
type EventConstructor<
|
|
2865
2256
|
EventSchema extends TaggedSchema,
|
|
@@ -2931,7 +2322,7 @@ export declare namespace Machine {
|
|
|
2931
2322
|
}
|
|
2932
2323
|
}
|
|
2933
2324
|
|
|
2934
|
-
/** A schema or an existing protocol accepted by
|
|
2325
|
+
/** A schema or an existing protocol accepted by `eventsFromSchemas` and its internal and emitted counterparts. */
|
|
2935
2326
|
export type EventProtocolInput<Kind extends EventProtocolKind> = TaggedSchema | EventProtocol.Any<Kind>
|
|
2936
2327
|
|
|
2937
2328
|
type EventProtocolInputSchemas<
|
|
@@ -3129,8 +2520,8 @@ export declare namespace Machine {
|
|
|
3129
2520
|
* Transient decision pseudo-state resolved immediately when targeted.
|
|
3130
2521
|
*
|
|
3131
2522
|
* Choice nodes have no value and never belong to an active configuration.
|
|
3132
|
-
* Their required `choice`
|
|
3133
|
-
*
|
|
2523
|
+
* Their required `choice` transition selects a typed destination
|
|
2524
|
+
* synchronously.
|
|
3134
2525
|
*
|
|
3135
2526
|
* @category models
|
|
3136
2527
|
* @since 0.4.0
|
|
@@ -3167,30 +2558,14 @@ export declare namespace Machine {
|
|
|
3167
2558
|
export type StateTree = Readonly<Record<string, TaggedSchema | StateNodeConfig>>
|
|
3168
2559
|
|
|
3169
2560
|
/**
|
|
3170
|
-
* State
|
|
2561
|
+
* State tree used as the topology parameter of machine types. A machine's
|
|
2562
|
+
* tree holds its root node under the `""` key.
|
|
3171
2563
|
*
|
|
3172
2564
|
* @category models
|
|
3173
2565
|
* @since 0.4.0
|
|
3174
2566
|
*/
|
|
3175
2567
|
export type StateSchemas = StateTree
|
|
3176
2568
|
|
|
3177
|
-
/**
|
|
3178
|
-
* Builder for initial state snapshots generated by `states`.
|
|
3179
|
-
*
|
|
3180
|
-
* **When to use**
|
|
3181
|
-
*
|
|
3182
|
-
* Use when you need the type of the `initial` property returned by
|
|
3183
|
-
* `states` or want to expose an initial snapshot builder from a helper.
|
|
3184
|
-
*
|
|
3185
|
-
* **Details**
|
|
3186
|
-
*
|
|
3187
|
-
* Initial builders enforce the declared initial child for compound states and
|
|
3188
|
-
* require every direct region for parallel states.
|
|
3189
|
-
*
|
|
3190
|
-
* @category utility types
|
|
3191
|
-
* @since 0.4.0
|
|
3192
|
-
*/
|
|
3193
|
-
|
|
3194
2569
|
/**
|
|
3195
2570
|
* Typed snapshot access shared by state descriptors.
|
|
3196
2571
|
*
|
|
@@ -3467,7 +2842,17 @@ export declare namespace Machine {
|
|
|
3467
2842
|
readonly outcome: "element" | "done" | "failure" | "snapshot"
|
|
3468
2843
|
}
|
|
3469
2844
|
|
|
3470
|
-
/**
|
|
2845
|
+
/**
|
|
2846
|
+
* Static topology selected by a transition branch.
|
|
2847
|
+
*
|
|
2848
|
+
* **Details**
|
|
2849
|
+
*
|
|
2850
|
+
* `kind` is `"state"` or `"choice"` for the path named by `target`,
|
|
2851
|
+
* `"history"` for `history`, `"state"` with the root path `""` for
|
|
2852
|
+
* `initialize`, and `"update"` for an `update` without a destination. A
|
|
2853
|
+
* `{ stay: true }` entry, or a transition with only `reenter: true`, has kind
|
|
2854
|
+
* `"none"` and no path. The machine's initial entry has kind `"initial"`.
|
|
2855
|
+
*/
|
|
3471
2856
|
export interface TransitionTargetSelection<
|
|
3472
2857
|
Path extends string | undefined = string | undefined,
|
|
3473
2858
|
Kind extends Topology.TargetSelectionKind = Topology.TargetSelectionKind,
|
|
@@ -3488,8 +2873,8 @@ export declare namespace Machine {
|
|
|
3488
2873
|
}
|
|
3489
2874
|
| {
|
|
3490
2875
|
readonly type: "branch"
|
|
2876
|
+
/** The entry as written: `target:Paid`, `target:Paid+update:root`, `update:root`, `history:X`, `initialize`, or `stay`. */
|
|
3491
2877
|
readonly key: string
|
|
3492
|
-
readonly title: string
|
|
3493
2878
|
readonly target: Path | undefined
|
|
3494
2879
|
readonly selection: TransitionTargetSelection<Path | undefined>
|
|
3495
2880
|
readonly updates: ReadonlyArray<string>
|
|
@@ -3498,7 +2883,7 @@ export declare namespace Machine {
|
|
|
3498
2883
|
/** The statically selected root entry for machine startup. */
|
|
3499
2884
|
export interface InitialDefinition<Path extends string = string> {
|
|
3500
2885
|
readonly target: Path
|
|
3501
|
-
readonly selection: TransitionTargetSelection<Path, "
|
|
2886
|
+
readonly selection: TransitionTargetSelection<Path, "initial", "initial">
|
|
3502
2887
|
}
|
|
3503
2888
|
|
|
3504
2889
|
/**
|
|
@@ -3507,9 +2892,11 @@ export declare namespace Machine {
|
|
|
3507
2892
|
* **Details**
|
|
3508
2893
|
*
|
|
3509
2894
|
* Every branch exposes its static selection without executing its resolver.
|
|
3510
|
-
*
|
|
3511
|
-
*
|
|
3512
|
-
*
|
|
2895
|
+
* Selecting a compound or parallel state also covers the descendants the
|
|
2896
|
+
* transition enters through it. An `update` selection keeps `target`
|
|
2897
|
+
* undefined and records its value owner in `selection.path`. A
|
|
2898
|
+
* `{ stay: true }` entry keeps `target` undefined and has
|
|
2899
|
+
* `selection.kind` `"none"`.
|
|
3513
2900
|
*
|
|
3514
2901
|
* @category models
|
|
3515
2902
|
* @since 0.4.0
|
|
@@ -3555,7 +2942,7 @@ export declare namespace Machine {
|
|
|
3555
2942
|
readonly reenter: boolean
|
|
3556
2943
|
/** Zero-based index of the selected static branch. */
|
|
3557
2944
|
readonly branchIndex: number
|
|
3558
|
-
/**
|
|
2945
|
+
/** The selected `branches` entry as written, such as `target:Paid`, or `undefined` for a direct transition. */
|
|
3559
2946
|
readonly branchKey: string | undefined
|
|
3560
2947
|
/** Path returned by the handler, including a choice or history pseudo-state. */
|
|
3561
2948
|
readonly target: TargetPath | undefined
|
|
@@ -3569,7 +2956,8 @@ export declare namespace Machine {
|
|
|
3569
2956
|
}
|
|
3570
2957
|
|
|
3571
2958
|
/**
|
|
3572
|
-
*
|
|
2959
|
+
* Startup arguments: the decoded input when the machine declares an input
|
|
2960
|
+
* schema, and none otherwise.
|
|
3573
2961
|
*
|
|
3574
2962
|
* @category utility types
|
|
3575
2963
|
* @since 0.4.0
|
|
@@ -4384,7 +3772,7 @@ export declare namespace Machine {
|
|
|
4384
3772
|
: never)
|
|
4385
3773
|
|
|
4386
3774
|
/**
|
|
4387
|
-
* Opaque state construction returned by a
|
|
3775
|
+
* Opaque state construction returned by a history default's `target`.
|
|
4388
3776
|
*
|
|
4389
3777
|
* The machine resolves the instruction through the selected state schema
|
|
4390
3778
|
* while planning. Its decoded value is intentionally unavailable until
|
|
@@ -4394,7 +3782,7 @@ export declare namespace Machine {
|
|
|
4394
3782
|
* @since 0.4.0
|
|
4395
3783
|
*/
|
|
4396
3784
|
export interface StateConstruction<out Result> {
|
|
4397
|
-
readonly [
|
|
3785
|
+
readonly [StateConstructionTypeId]: Result
|
|
4398
3786
|
}
|
|
4399
3787
|
|
|
4400
3788
|
/**
|
|
@@ -4408,7 +3796,7 @@ export declare namespace Machine {
|
|
|
4408
3796
|
StateId extends StateIdentifier<States>
|
|
4409
3797
|
> {
|
|
4410
3798
|
readonly [Topology.TargetTypeId]: typeof Topology.TargetTypeId
|
|
4411
|
-
readonly [
|
|
3799
|
+
readonly [TargetSnapshotTypeId]?: SnapshotByIdentifier<States, StateId>
|
|
4412
3800
|
readonly path: StateId
|
|
4413
3801
|
readonly value: StateByIdentifier<States, StateId>
|
|
4414
3802
|
readonly values?: Partial<
|
|
@@ -4429,7 +3817,7 @@ export declare namespace Machine {
|
|
|
4429
3817
|
States extends StateSchemas,
|
|
4430
3818
|
StateId extends ValuedStateIdentifier<States>
|
|
4431
3819
|
> {
|
|
4432
|
-
readonly [
|
|
3820
|
+
readonly [StateUpdateTypeId]: {
|
|
4433
3821
|
readonly states: Types.Covariant<States>
|
|
4434
3822
|
readonly owner: Types.Covariant<StateId>
|
|
4435
3823
|
}
|
|
@@ -4447,25 +3835,13 @@ export declare namespace Machine {
|
|
|
4447
3835
|
States extends StateSchemas,
|
|
4448
3836
|
Owner extends ValuedStateIdentifier<States>
|
|
4449
3837
|
> {
|
|
4450
|
-
readonly [
|
|
3838
|
+
readonly [CombinedTargetTypeId]: {
|
|
4451
3839
|
readonly result: Types.Covariant<Result>
|
|
4452
3840
|
readonly states: Types.Covariant<States>
|
|
4453
3841
|
readonly owner: Types.Covariant<Owner>
|
|
4454
3842
|
}
|
|
4455
3843
|
}
|
|
4456
3844
|
|
|
4457
|
-
/** @internal */
|
|
4458
|
-
type StateUpdateBuilder<
|
|
4459
|
-
States extends StateSchemas,
|
|
4460
|
-
StateId extends ValuedStateIdentifier<States>
|
|
4461
|
-
> = {
|
|
4462
|
-
readonly decoded: (value: StateByIdentifier<States, StateId>) => StateUpdate<States, StateId>
|
|
4463
|
-
readonly from: FromCallable<
|
|
4464
|
-
readonly [input: SchemaByIdentifier<States, StateId>["~type.make.in"]],
|
|
4465
|
-
StateUpdate<States, StateId>
|
|
4466
|
-
>
|
|
4467
|
-
}
|
|
4468
|
-
|
|
4469
3845
|
/**
|
|
4470
3846
|
* Opaque result returned by an explicitly targetless transition.
|
|
4471
3847
|
*
|
|
@@ -4476,12 +3852,12 @@ export declare namespace Machine {
|
|
|
4476
3852
|
* @since 0.10.0
|
|
4477
3853
|
*/
|
|
4478
3854
|
export interface NoTarget {
|
|
4479
|
-
readonly [
|
|
3855
|
+
readonly [NoTargetTypeId]: typeof NoTargetTypeId
|
|
4480
3856
|
}
|
|
4481
3857
|
|
|
4482
3858
|
/**
|
|
4483
|
-
* Opaque result
|
|
4484
|
-
* current event
|
|
3859
|
+
* Opaque result of `select.decline()`, when a transition does not accept the
|
|
3860
|
+
* current event.
|
|
4485
3861
|
*
|
|
4486
3862
|
* Declining selects no transition and discards operations enqueued by that
|
|
4487
3863
|
* resolver. Hierarchical event and eventless dispatch continues with the
|
|
@@ -4491,10 +3867,14 @@ export declare namespace Machine {
|
|
|
4491
3867
|
* @since 0.17.0
|
|
4492
3868
|
*/
|
|
4493
3869
|
export interface Declined {
|
|
4494
|
-
readonly [
|
|
3870
|
+
readonly [DeclinedTypeId]: typeof DeclinedTypeId
|
|
4495
3871
|
}
|
|
4496
3872
|
|
|
4497
|
-
/**
|
|
3873
|
+
/**
|
|
3874
|
+
* Static acceptance contract of one transition definition: `"declinable"`
|
|
3875
|
+
* when it has a `guard` or lists `{ decline: true }` in `branches`, so it may
|
|
3876
|
+
* leave the event to the next candidate, and `"required"` otherwise.
|
|
3877
|
+
*/
|
|
4498
3878
|
export type TransitionAcceptance = "required" | "declinable"
|
|
4499
3879
|
|
|
4500
3880
|
/**
|
|
@@ -4511,7 +3891,7 @@ export declare namespace Machine {
|
|
|
4511
3891
|
States extends StateSchemas,
|
|
4512
3892
|
HistoryId extends HistoryIdentifier<States>
|
|
4513
3893
|
> {
|
|
4514
|
-
readonly [
|
|
3894
|
+
readonly [HistoryTargetTypeId]: typeof HistoryTargetTypeId
|
|
4515
3895
|
readonly path: HistoryId
|
|
4516
3896
|
readonly parent: Extract<ParentPath<HistoryId>, StateIdentifier<States>>
|
|
4517
3897
|
}
|
|
@@ -4525,17 +3905,17 @@ export declare namespace Machine {
|
|
|
4525
3905
|
*/
|
|
4526
3906
|
export interface InitialTarget<StateId extends string> {
|
|
4527
3907
|
readonly [Topology.TargetTypeId]: typeof Topology.TargetTypeId
|
|
4528
|
-
readonly [
|
|
4529
|
-
readonly [
|
|
3908
|
+
readonly [TargetSnapshotTypeId]?: never
|
|
3909
|
+
readonly [InitialTargetTypeId]: typeof InitialTargetTypeId
|
|
4530
3910
|
readonly _tag: "InitialTarget"
|
|
4531
3911
|
readonly path: StateId
|
|
4532
3912
|
readonly value: never
|
|
4533
3913
|
readonly values?: never
|
|
4534
3914
|
}
|
|
4535
3915
|
|
|
4536
|
-
/** Branded
|
|
3916
|
+
/** Branded instruction that enters a choice pseudo-state, before its parent is checked against a machine. */
|
|
4537
3917
|
export interface ChoiceTargetInstruction<ChoiceId extends string = string> {
|
|
4538
|
-
readonly [
|
|
3918
|
+
readonly [ChoiceTargetTypeId]: typeof ChoiceTargetTypeId
|
|
4539
3919
|
readonly path: ChoiceId
|
|
4540
3920
|
readonly parent: ParentPath<ChoiceId>
|
|
4541
3921
|
readonly values?: Readonly<Record<string, unknown>>
|
|
@@ -4549,26 +3929,9 @@ export declare namespace Machine {
|
|
|
4549
3929
|
readonly parent: Extract<ParentPath<ChoiceId>, StateIdentifier<States>>
|
|
4550
3930
|
}
|
|
4551
3931
|
|
|
4552
|
-
/** Builder containing only history pseudo-state paths. */
|
|
4553
|
-
export type HistoryTargetBuilder<States extends StateSchemas> = HistoryTargetBuilderWithPrefix<States, States, "">
|
|
4554
|
-
|
|
4555
|
-
/**
|
|
4556
|
-
* Builder for complete transition snapshots.
|
|
4557
|
-
*
|
|
4558
|
-
* **When to use**
|
|
4559
|
-
*
|
|
4560
|
-
* Use when a transition enters an inactive root or otherwise needs to provide
|
|
4561
|
-
* every active child below the selected root.
|
|
4562
|
-
*
|
|
4563
|
-
* @category utility types
|
|
4564
|
-
* @since 0.4.0
|
|
4565
|
-
*/
|
|
4566
|
-
export type FullTargetBuilder<States extends StateSchemas> = [InitialEntryStateKey<States>] extends [never] ?
|
|
4567
|
-
FullSnapshotBuilderWithPrefix<States>
|
|
4568
|
-
: FullSnapshotBuilderWithPrefix<States> & FullInitialTargetBuilder<States>
|
|
4569
|
-
|
|
4570
3932
|
/**
|
|
4571
|
-
*
|
|
3933
|
+
* Function that constructs a complete fallback configuration containing a
|
|
3934
|
+
* history owner, supplied as `target` to a history default.
|
|
4572
3935
|
*
|
|
4573
3936
|
* @category utility types
|
|
4574
3937
|
* @since 0.4.0
|
|
@@ -4580,151 +3943,6 @@ export declare namespace Machine {
|
|
|
4580
3943
|
construction: HistoryConstruction<States[""], Owner>
|
|
4581
3944
|
) => StateConstruction<CompleteSnapshotContaining<States, Owner>>
|
|
4582
3945
|
|
|
4583
|
-
/**
|
|
4584
|
-
* Builder for source-local transition targets.
|
|
4585
|
-
*
|
|
4586
|
-
* **When to use**
|
|
4587
|
-
*
|
|
4588
|
-
* Use when a transition stays inside the nearest active compound ancestor of
|
|
4589
|
-
* the source state and should preserve active ancestor and sibling values.
|
|
4590
|
-
*
|
|
4591
|
-
* @category utility types
|
|
4592
|
-
* @since 0.4.0
|
|
4593
|
-
*/
|
|
4594
|
-
export type LocalTargetBuilder<
|
|
4595
|
-
States extends StateSchemas,
|
|
4596
|
-
Source extends StateNodeIdentifier<States>
|
|
4597
|
-
> = NearestCompoundScope<States, Source> extends infer Scope ? [Scope] extends [never] ? {}
|
|
4598
|
-
: Scope extends StateIdentifier<States> ? LocalTargetBuilderForScope<States, Scope, Source>
|
|
4599
|
-
: {}
|
|
4600
|
-
: {}
|
|
4601
|
-
|
|
4602
|
-
/**
|
|
4603
|
-
* Builder for partial transition targets within the active source root.
|
|
4604
|
-
*
|
|
4605
|
-
* **When to use**
|
|
4606
|
-
*
|
|
4607
|
-
* Use when a transition should replace one descendant of the active source
|
|
4608
|
-
* root while preserving unmentioned active ancestors or parallel regions.
|
|
4609
|
-
*
|
|
4610
|
-
* @category utility types
|
|
4611
|
-
* @since 0.4.0
|
|
4612
|
-
*/
|
|
4613
|
-
export type BranchTargetBuilder<
|
|
4614
|
-
States extends StateSchemas,
|
|
4615
|
-
Source extends StateNodeIdentifier<States>
|
|
4616
|
-
> = BranchTargetBuilderForRoot<
|
|
4617
|
-
States,
|
|
4618
|
-
Extract<"" extends keyof States ? "" : RootStateIdentifier<Source>, ActiveStateKey<States>>,
|
|
4619
|
-
Source
|
|
4620
|
-
>
|
|
4621
|
-
|
|
4622
|
-
/**
|
|
4623
|
-
* Machine-bound target builders available in transition contexts.
|
|
4624
|
-
*
|
|
4625
|
-
* **Details**
|
|
4626
|
-
*
|
|
4627
|
-
* `none()` handles without selecting a destination, `local` targets the
|
|
4628
|
-
* nearest compound scope for the source state, `branch` targets descendants
|
|
4629
|
-
* of the source root, and `full` builds complete snapshots for any root.
|
|
4630
|
-
*
|
|
4631
|
-
* These builders control how the next active configuration is assembled; they
|
|
4632
|
-
* do not directly control state re-entry. Exit and entry paths are derived
|
|
4633
|
-
* from the previous and next active paths. Shared active ancestors remain
|
|
4634
|
-
* entered even when a `full` target supplies their values again. Use an event
|
|
4635
|
-
* transition with `reenter: true` when the source should explicitly exit and
|
|
4636
|
-
* enter again.
|
|
4637
|
-
*
|
|
4638
|
-
* @category models
|
|
4639
|
-
* @since 0.4.0
|
|
4640
|
-
*/
|
|
4641
|
-
export interface TargetBuilder<
|
|
4642
|
-
in out States extends StateSchemas,
|
|
4643
|
-
in out Source extends StateNodeIdentifier<States>
|
|
4644
|
-
> {
|
|
4645
|
-
/**
|
|
4646
|
-
* Selects an explicitly targetless transition.
|
|
4647
|
-
*
|
|
4648
|
-
* The event or lifecycle outcome is handled and queued operations are
|
|
4649
|
-
* retained, while the current state configuration remains the transition
|
|
4650
|
-
* result.
|
|
4651
|
-
*
|
|
4652
|
-
* @since 0.10.0
|
|
4653
|
-
*/
|
|
4654
|
-
readonly none: () => NoTarget
|
|
4655
|
-
|
|
4656
|
-
/**
|
|
4657
|
-
* Moves to another state in the same local group. The value of the state
|
|
4658
|
-
* containing that group, and values in other active branches, are kept.
|
|
4659
|
-
*
|
|
4660
|
-
* @since 0.4.0
|
|
4661
|
-
*/
|
|
4662
|
-
readonly local: LocalTargetBuilder<States, Source>
|
|
4663
|
-
|
|
4664
|
-
/**
|
|
4665
|
-
* Moves to a state elsewhere under the current top-level state. Parent
|
|
4666
|
-
* values change only when their builder methods are explicitly called;
|
|
4667
|
-
* other active branches are kept.
|
|
4668
|
-
*
|
|
4669
|
-
* @since 0.4.0
|
|
4670
|
-
*/
|
|
4671
|
-
readonly branch: BranchTargetBuilder<States, Source>
|
|
4672
|
-
|
|
4673
|
-
/**
|
|
4674
|
-
* Moves to any top-level state by building its complete active state
|
|
4675
|
-
* configuration.
|
|
4676
|
-
*
|
|
4677
|
-
* **Details**
|
|
4678
|
-
*
|
|
4679
|
-
* When the target contains nested states, an active child must be selected.
|
|
4680
|
-
* When it contains parallel states, an active state must be provided for
|
|
4681
|
-
* every region.
|
|
4682
|
-
*
|
|
4683
|
-
* @since 0.4.0
|
|
4684
|
-
*/
|
|
4685
|
-
readonly full: FullTargetBuilder<States>
|
|
4686
|
-
|
|
4687
|
-
/** Restores a declared shallow or deep history pseudo-state. */
|
|
4688
|
-
readonly history: HistoryTargetBuilder<States>
|
|
4689
|
-
}
|
|
4690
|
-
|
|
4691
|
-
/**
|
|
4692
|
-
* Opaque exact destination selected while a machine definition is captured.
|
|
4693
|
-
* The selection contains topology only; state values are constructed later
|
|
4694
|
-
* by the selected branch's resolver.
|
|
4695
|
-
*
|
|
4696
|
-
* @category models
|
|
4697
|
-
* @since 0.14.0
|
|
4698
|
-
*/
|
|
4699
|
-
export interface TargetSelection<
|
|
4700
|
-
out Result,
|
|
4701
|
-
out Path extends string | undefined = string | undefined,
|
|
4702
|
-
out Kind extends Topology.TargetSelectionKind = Topology.TargetSelectionKind,
|
|
4703
|
-
out Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined
|
|
4704
|
-
> {
|
|
4705
|
-
readonly [Topology.TargetSelectionTypeId]: typeof Topology.TargetSelectionTypeId
|
|
4706
|
-
readonly kind: Kind
|
|
4707
|
-
readonly scope: Scope
|
|
4708
|
-
readonly path: Path
|
|
4709
|
-
readonly "~effect/Machine/TargetSelectionResult"?: Types.Covariant<Result>
|
|
4710
|
-
}
|
|
4711
|
-
|
|
4712
|
-
type SelectionValue<
|
|
4713
|
-
Builder,
|
|
4714
|
-
Path extends string,
|
|
4715
|
-
Kind extends Topology.TargetSelectionKind = "state",
|
|
4716
|
-
Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined
|
|
4717
|
-
> = TargetSelection<Builder, Path, Kind, Scope>
|
|
4718
|
-
|
|
4719
|
-
type SelectionMethod<
|
|
4720
|
-
Builder,
|
|
4721
|
-
Path extends string,
|
|
4722
|
-
Kind extends Topology.TargetSelectionKind = "state",
|
|
4723
|
-
Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined
|
|
4724
|
-
> = () => SelectionValue<Builder, Path, Kind, Scope>
|
|
4725
|
-
|
|
4726
|
-
type RootBuilder<Builder> = Builder extends { readonly "": infer Root } ? Root : never
|
|
4727
|
-
|
|
4728
3946
|
/**
|
|
4729
3947
|
* Context passed to a state/event handler.
|
|
4730
3948
|
*
|
|
@@ -5081,7 +4299,7 @@ export declare namespace Machine {
|
|
|
5081
4299
|
export type StateActionResult<E, R> = undefined
|
|
5082
4300
|
|
|
5083
4301
|
/**
|
|
5084
|
-
*
|
|
4302
|
+
* Initial target that a machine resolves at startup.
|
|
5085
4303
|
*
|
|
5086
4304
|
* @category utility types
|
|
5087
4305
|
* @since 0.4.0
|
|
@@ -5089,15 +4307,14 @@ export declare namespace Machine {
|
|
|
5089
4307
|
export type InitialResult<States extends StateSchemas, E, R> = InitialTarget<StateIdentifier<States>>
|
|
5090
4308
|
|
|
5091
4309
|
/**
|
|
5092
|
-
*
|
|
4310
|
+
* Result that a transition declaration resolves to.
|
|
5093
4311
|
*
|
|
5094
4312
|
* **Details**
|
|
5095
4313
|
*
|
|
5096
|
-
*
|
|
5097
|
-
*
|
|
5098
|
-
*
|
|
5099
|
-
*
|
|
5100
|
-
* not accepted as transition targets.
|
|
4314
|
+
* A transition resolves to a complete snapshot, a target, history, or
|
|
4315
|
+
* choice destination, a state-value update, a target combined with an
|
|
4316
|
+
* owner update, or the targetless result of `{ stay: true }`. Raw decoded
|
|
4317
|
+
* state values are not accepted as transition targets.
|
|
5101
4318
|
*
|
|
5102
4319
|
* @category utility types
|
|
5103
4320
|
* @since 0.4.0
|
|
@@ -5122,47 +4339,6 @@ export declare namespace Machine {
|
|
|
5122
4339
|
>
|
|
5123
4340
|
| NoTarget
|
|
5124
4341
|
|
|
5125
|
-
/** A choice resolver must always select a typed target synchronously. */
|
|
5126
|
-
export type ChoiceResult<States extends StateSchemas, E, R> =
|
|
5127
|
-
| Snapshot<States>
|
|
5128
|
-
| Target<States, StateIdentifier<States>>
|
|
5129
|
-
| HistoryTarget<States, HistoryIdentifier<States>>
|
|
5130
|
-
| ChoiceTarget<States, ChoiceIdentifier<States>>
|
|
5131
|
-
| StateConstruction<
|
|
5132
|
-
| Snapshot<States>
|
|
5133
|
-
| Target<States, StateIdentifier<States>>
|
|
5134
|
-
| HistoryTarget<States, HistoryIdentifier<States>>
|
|
5135
|
-
| ChoiceTarget<States, ChoiceIdentifier<States>>
|
|
5136
|
-
>
|
|
5137
|
-
|
|
5138
|
-
/**
|
|
5139
|
-
* Extracts the union of handler return values from a handler map.
|
|
5140
|
-
*
|
|
5141
|
-
* @category utility types
|
|
5142
|
-
* @since 0.4.0
|
|
5143
|
-
*/
|
|
5144
|
-
export type HandlerEffect<Handlers> = Handlers[keyof Handlers]
|
|
5145
|
-
/**
|
|
5146
|
-
* Extracts the error type from a handler return value.
|
|
5147
|
-
*
|
|
5148
|
-
* @category utility types
|
|
5149
|
-
* @since 0.4.0
|
|
5150
|
-
*/
|
|
5151
|
-
export type HandlerError<Handlers> = Effect.Error<HandlerEffect<Handlers>>
|
|
5152
|
-
/**
|
|
5153
|
-
* Extracts the service requirements from a handler return value.
|
|
5154
|
-
*
|
|
5155
|
-
* @category utility types
|
|
5156
|
-
* @since 0.4.0
|
|
5157
|
-
*/
|
|
5158
|
-
export type HandlerServices<Handlers> = Effect.Services<HandlerEffect<Handlers>>
|
|
5159
|
-
/**
|
|
5160
|
-
* Extracts the return value from an initial state function.
|
|
5161
|
-
*
|
|
5162
|
-
* @category utility types
|
|
5163
|
-
* @since 0.4.0
|
|
5164
|
-
*/
|
|
5165
|
-
export type InitialReturn<Initial> = Initial extends (...args: any) => infer Ret ? Ret : never
|
|
5166
4342
|
/**
|
|
5167
4343
|
* Extracts the return value from an entry or exit action.
|
|
5168
4344
|
*
|
|
@@ -5234,7 +4410,7 @@ export declare namespace Machine {
|
|
|
5234
4410
|
EventInput<InputEvent<M>>,
|
|
5235
4411
|
Error<M> | ActionError<Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError,
|
|
5236
4412
|
ExcludeCompatibleRuntime<
|
|
5237
|
-
Exclude<ExecutionServices<InitialServices<M> | Services<M>>,
|
|
4413
|
+
Exclude<ExecutionServices<InitialServices<M> | Services<M>>, MachineRuntime>,
|
|
5238
4414
|
Event<M>,
|
|
5239
4415
|
EmittedEvent<M>
|
|
5240
4416
|
>,
|
|
@@ -5311,17 +4487,6 @@ export declare namespace Machine {
|
|
|
5311
4487
|
readonly [InvokeTypeId]: { readonly requirements: Types.Covariant<infer Requirements> }
|
|
5312
4488
|
} ? Requirements
|
|
5313
4489
|
: LogicServicesOf<InvokeLogic<Invoke>>
|
|
5314
|
-
/**
|
|
5315
|
-
* Extracts events emitted directly by an invoked child.
|
|
5316
|
-
*
|
|
5317
|
-
* @category utility types
|
|
5318
|
-
* @since 0.4.0
|
|
5319
|
-
*/
|
|
5320
|
-
export type InvokeEmits<Invoke> = Invoke extends {
|
|
5321
|
-
readonly [InvokeTypeId]: { readonly emits: Types.Covariant<infer Emitted> }
|
|
5322
|
-
} ? Emitted
|
|
5323
|
-
: Invoke extends { readonly child: ChildMachine<string, infer M> } ? EmittedEvent<M>
|
|
5324
|
-
: never
|
|
5325
4490
|
|
|
5326
4491
|
/** Public parent inputs required by an invoked child machine. */
|
|
5327
4492
|
export type InvokeParentEvents<Invoke> = Invoke extends {
|
|
@@ -5379,7 +4544,7 @@ export declare namespace Machine {
|
|
|
5379
4544
|
*/
|
|
5380
4545
|
export type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never
|
|
5381
4546
|
:
|
|
5382
|
-
|
|
|
4547
|
+
| MachineRuntime
|
|
5383
4548
|
| InvokeServices<InvokeReturn<Config>>
|
|
5384
4549
|
| InvokeOutcomeServices<InvokeReturn<Config>>
|
|
5385
4550
|
/**
|
|
@@ -5400,15 +4565,6 @@ export declare namespace Machine {
|
|
|
5400
4565
|
export type DoneReturn<Config> = Config extends { readonly onDone?: infer OnDone }
|
|
5401
4566
|
? EventTransitionReturn<NonNullable<OnDone>>
|
|
5402
4567
|
: never
|
|
5403
|
-
/**
|
|
5404
|
-
* Extracts the return value from a final state output function.
|
|
5405
|
-
*
|
|
5406
|
-
* @category utility types
|
|
5407
|
-
* @since 0.4.0
|
|
5408
|
-
*/
|
|
5409
|
-
export type FinalOutputReturn<Config> = Config extends { readonly output?: infer Output }
|
|
5410
|
-
? NonNullable<Output> extends (...args: any) => infer Ret ? Ret : never
|
|
5411
|
-
: never
|
|
5412
4568
|
|
|
5413
4569
|
/**
|
|
5414
4570
|
* Extracts all service requirements contributed by a state handler config.
|
|
@@ -5438,167 +4594,30 @@ export declare namespace Machine {
|
|
|
5438
4594
|
Acceptance extends TransitionAcceptance = "required"
|
|
5439
4595
|
> = Transition<States, StateId, Context, Events, Emits, {}, Reenter, Acceptance>
|
|
5440
4596
|
|
|
5441
|
-
|
|
5442
|
-
: never
|
|
5443
|
-
export type SelectionKind<Selection> = Selection extends TargetSelection<any, any, infer Kind, any> ? Kind : never
|
|
5444
|
-
export type SelectionPath<Selection> = Selection extends TargetSelection<any, infer Path, any, any> ? Path : never
|
|
5445
|
-
export type TargetBuilderResult<Builder> =
|
|
5446
|
-
| (Builder extends (...args: any) => infer Result ? Result : never)
|
|
5447
|
-
| (Builder extends { readonly decoded: (...args: any) => infer Result } ? Result : never)
|
|
5448
|
-
| (Builder extends { readonly from: (...args: any) => infer Result } ? Result : never)
|
|
5449
|
-
export type SelectedTargetResult<Selection> = SelectionBuilder<Selection> extends infer Builder ?
|
|
5450
|
-
TargetBuilderResult<Builder>
|
|
5451
|
-
: never
|
|
5452
|
-
|
|
5453
|
-
/**
|
|
5454
|
-
* Destination construction returned when a transition declares one retained
|
|
5455
|
-
* valued owner with a `{ target, update }` declaration.
|
|
5456
|
-
*
|
|
5457
|
-
* @category models
|
|
5458
|
-
* @since 0.22.0
|
|
5459
|
-
*/
|
|
5460
|
-
export interface UpdatingStateConstruction<
|
|
5461
|
-
Result,
|
|
5462
|
-
States extends StateSchemas,
|
|
5463
|
-
Owner extends ValuedStateIdentifier<States>
|
|
5464
|
-
> {
|
|
5465
|
-
/** Combines the selected topology with the required owner replacement. */
|
|
5466
|
-
readonly update: (
|
|
5467
|
-
update: StateUpdate<States, Owner>
|
|
5468
|
-
) => CombinedTarget<UnwrapConstruction<Result>, States, Owner>
|
|
5469
|
-
}
|
|
5470
|
-
|
|
5471
|
-
type UpdatingCallable<
|
|
5472
|
-
Callable,
|
|
5473
|
-
States extends StateSchemas,
|
|
5474
|
-
Owner extends ValuedStateIdentifier<States>
|
|
5475
|
-
> = Callable extends {
|
|
5476
|
-
(...args: infer Arguments1): infer Result1
|
|
5477
|
-
(...args: infer Arguments2): infer Result2
|
|
5478
|
-
} ? {
|
|
5479
|
-
(...args: Arguments1): UpdatingStateConstruction<Result1, States, Owner>
|
|
5480
|
-
(...args: Arguments2): UpdatingStateConstruction<Result2, States, Owner>
|
|
5481
|
-
}
|
|
5482
|
-
: Callable extends (...args: infer Arguments) => infer Result ?
|
|
5483
|
-
(...args: Arguments) => UpdatingStateConstruction<Result, States, Owner>
|
|
5484
|
-
: never
|
|
5485
|
-
|
|
5486
|
-
type UpdatingTargetBuilder<
|
|
5487
|
-
Builder,
|
|
5488
|
-
States extends StateSchemas,
|
|
5489
|
-
Owner extends ValuedStateIdentifier<States>
|
|
5490
|
-
> = {
|
|
5491
|
-
readonly [Key in keyof Builder]: Key extends "from" | "decoded" ? UpdatingCallable<Builder[Key], States, Owner>
|
|
5492
|
-
: Builder[Key]
|
|
5493
|
-
}
|
|
5494
|
-
|
|
5495
|
-
type SelectionSupportsDefaultConstruction<Selection> = SelectionKind<Selection> extends "none" ? true
|
|
5496
|
-
: SelectionBuilder<Selection> extends { readonly from: (...args: infer Args) => any } ? [] extends Args ? true
|
|
5497
|
-
: false
|
|
5498
|
-
: false
|
|
5499
|
-
|
|
5500
|
-
export type TransitionResolveContext<
|
|
5501
|
-
Context,
|
|
5502
|
-
Selection
|
|
5503
|
-
> =
|
|
5504
|
-
& Omit<Context, "target">
|
|
5505
|
-
& (SelectionKind<Selection> extends "none" ? {} : { readonly target: SelectionBuilder<Selection> })
|
|
5506
|
-
|
|
5507
|
-
/** Context capability available only to explicitly declinable resolvers. */
|
|
5508
|
-
export interface DeclineCapability {
|
|
5509
|
-
/** Declines this candidate and continues hierarchical transition selection. */
|
|
5510
|
-
readonly decline: () => Declined
|
|
5511
|
-
}
|
|
5512
|
-
|
|
5513
|
-
/** One named destination declared by a branching transition. */
|
|
5514
|
-
export interface TransitionBranchInput<
|
|
5515
|
-
Selection extends TargetSelection<any, any, any> = TargetSelection<any, any, any>
|
|
5516
|
-
> {
|
|
5517
|
-
/** Exact topology destination available to the branching resolver. */
|
|
5518
|
-
readonly target: Selection
|
|
5519
|
-
/** Optional human-readable branch label used by visualization tooling. */
|
|
5520
|
-
readonly title?: string
|
|
5521
|
-
}
|
|
5522
|
-
|
|
5523
|
-
/** Opaque evidence that a branching resolver selected one declared branch. */
|
|
4597
|
+
/** Opaque evidence that `resolve` selected one declared branch. */
|
|
5524
4598
|
export interface SelectedBranch<out Key extends string, out Result> {
|
|
5525
|
-
readonly [
|
|
4599
|
+
readonly [SelectedBranchTypeId]: {
|
|
5526
4600
|
readonly key: Types.Covariant<Key>
|
|
5527
4601
|
readonly result: Types.Covariant<Result>
|
|
5528
4602
|
}
|
|
5529
4603
|
}
|
|
5530
4604
|
|
|
5531
|
-
type CompletedBranchResult<R> = R extends { readonly update: unknown }
|
|
5532
|
-
? R extends UpdatingStateConstruction<infer Target, infer S, infer Owner>
|
|
5533
|
-
? CombinedTarget<UnwrapConstruction<Target>, S, Owner>
|
|
5534
|
-
: R
|
|
5535
|
-
: R
|
|
5536
|
-
type SelectedConstruction<K extends string, R> = R extends { readonly update: unknown } ?
|
|
5537
|
-
R extends UpdatingStateConstruction<infer Target, infer S, infer Owner> ? {
|
|
5538
|
-
readonly update: SelectedBranchBuilder<StateUpdateBuilder<S, Owner>, K> extends infer B ? {
|
|
5539
|
-
readonly [M in keyof B]:
|
|
5540
|
-
StateUpdateBuilder<S, Owner>[Extract<M, keyof StateUpdateBuilder<S, Owner>>] extends
|
|
5541
|
-
(...args: infer A) => unknown
|
|
5542
|
-
? (...args: A) => SelectedBranch<K, CombinedTarget<UnwrapConstruction<Target>, S, Owner>>
|
|
5543
|
-
: never
|
|
5544
|
-
} :
|
|
5545
|
-
never
|
|
5546
|
-
}
|
|
5547
|
-
: SelectedBranch<K, R> :
|
|
5548
|
-
SelectedBranch<K, R>
|
|
5549
|
-
type SelectedBranchCallable<Callable, Key extends string> = Callable extends {
|
|
5550
|
-
(...args: infer Arguments1): infer Result1
|
|
5551
|
-
(...args: infer Arguments2): infer Result2
|
|
5552
|
-
} ? {
|
|
5553
|
-
(...args: Arguments1): SelectedConstruction<Key, Result1>
|
|
5554
|
-
(...args: Arguments2): SelectedConstruction<Key, Result2>
|
|
5555
|
-
}
|
|
5556
|
-
: Callable extends (...args: infer Arguments) => infer Result ?
|
|
5557
|
-
(...args: Arguments) => SelectedConstruction<Key, Result>
|
|
5558
|
-
: {}
|
|
5559
|
-
|
|
5560
|
-
type SelectedBranchBuilderProperties<Builder, Key extends string> = {
|
|
5561
|
-
readonly [Property in keyof Builder]: Builder[Property] extends (...args: any) => any ?
|
|
5562
|
-
SelectedBranchCallable<Builder[Property], Key>
|
|
5563
|
-
: Builder[Property]
|
|
5564
|
-
}
|
|
5565
|
-
|
|
5566
|
-
/** Target-specific builder that brands every construction with its branch key. */
|
|
5567
|
-
export type SelectedBranchBuilder<Builder, Key extends string> =
|
|
5568
|
-
& SelectedBranchCallable<Builder, Key>
|
|
5569
|
-
& SelectedBranchBuilderProperties<Builder, Key>
|
|
5570
|
-
|
|
5571
|
-
export type BranchSelectors<Branches extends Readonly<Record<string, TransitionBranchInput>>> = {
|
|
5572
|
-
readonly [Key in Extract<keyof Branches, string>]: SelectedBranchBuilder<
|
|
5573
|
-
SelectionBuilder<Branches[Key]["target"]>,
|
|
5574
|
-
Key
|
|
5575
|
-
>
|
|
5576
|
-
}
|
|
5577
|
-
|
|
5578
|
-
export type BranchSelectionResult<Branches extends Readonly<Record<string, TransitionBranchInput>>> = {
|
|
5579
|
-
readonly [Key in Extract<keyof Branches, string>]: SelectedBranch<
|
|
5580
|
-
Key,
|
|
5581
|
-
CompletedBranchResult<SelectedTargetResult<Branches[Key]["target"]>>
|
|
5582
|
-
>
|
|
5583
|
-
}[Extract<keyof Branches, string>]
|
|
5584
|
-
|
|
5585
|
-
export type TransitionBranchesResolveContext<
|
|
5586
|
-
Context,
|
|
5587
|
-
Branches extends Readonly<Record<string, TransitionBranchInput>>
|
|
5588
|
-
> = Omit<Context, "target"> & { readonly select: BranchSelectors<Branches> }
|
|
5589
|
-
|
|
5590
|
-
export type InvokeTransition<
|
|
5591
|
-
States extends StateSchemas,
|
|
5592
|
-
Events extends ReadonlyArray<TaggedSchema>,
|
|
5593
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5594
|
-
StateId extends StateNodeIdentifier<States>,
|
|
5595
|
-
Context
|
|
5596
|
-
> = TransitionConfig<States, Events, Emits, StateId, Context, true, TransitionAcceptance>
|
|
5597
|
-
|
|
5598
4605
|
export type InvokeSource<Value, Context> = Value | ((context: Context) => Value)
|
|
5599
4606
|
|
|
5600
|
-
/**
|
|
5601
|
-
|
|
4607
|
+
/**
|
|
4608
|
+
* State-owned work that runs for the lifetime of its active state.
|
|
4609
|
+
*
|
|
4610
|
+
* **Details**
|
|
4611
|
+
*
|
|
4612
|
+
* Every `invoke` entry carries this type-level marker, which records the
|
|
4613
|
+
* state that owns the entry together with the machine's state schemas and
|
|
4614
|
+
* event protocols. The marker property is optional and is never set at
|
|
4615
|
+
* runtime.
|
|
4616
|
+
*
|
|
4617
|
+
* @category models
|
|
4618
|
+
* @since 0.23.0
|
|
4619
|
+
*/
|
|
4620
|
+
export interface InvokeOwned<
|
|
5602
4621
|
States extends StateSchemas,
|
|
5603
4622
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
5604
4623
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
@@ -5795,7 +4814,7 @@ export declare namespace Machine {
|
|
|
5795
4814
|
> {
|
|
5796
4815
|
/** Lifecycle event that attempted to restore this history node. */
|
|
5797
4816
|
readonly event: LifecycleEvent<Events>
|
|
5798
|
-
/**
|
|
4817
|
+
/** Constructs the complete root configuration that contains the history owner. */
|
|
5799
4818
|
readonly target: HistoryDefaultTargetBuilder<States, ParentId>
|
|
5800
4819
|
/** State path whose child configuration is restored by this history node. */
|
|
5801
4820
|
readonly owner: ParentId
|
|
@@ -5823,9 +4842,16 @@ export declare namespace Machine {
|
|
|
5823
4842
|
/**
|
|
5824
4843
|
* Fallback implementation for one direct history pseudo-state.
|
|
5825
4844
|
*
|
|
4845
|
+
* **Details**
|
|
4846
|
+
*
|
|
4847
|
+
* `default` runs only when the history state is entered before its owner has
|
|
4848
|
+
* recorded a configuration, and returns the complete configuration to enter.
|
|
4849
|
+
*
|
|
5826
4850
|
* @inline
|
|
4851
|
+
* @category models
|
|
4852
|
+
* @since 0.23.0
|
|
5827
4853
|
*/
|
|
5828
|
-
interface HistoryDefaultEntry<
|
|
4854
|
+
export interface HistoryDefaultEntry<
|
|
5829
4855
|
States extends StateSchemas,
|
|
5830
4856
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
5831
4857
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
@@ -5850,8 +4876,18 @@ export declare namespace Machine {
|
|
|
5850
4876
|
readonly [Key in HistoryStateKey<Children>]?: HistoryDefaultEntry<States, Events, Emits, ParentId>
|
|
5851
4877
|
}
|
|
5852
4878
|
|
|
5853
|
-
/**
|
|
5854
|
-
|
|
4879
|
+
/**
|
|
4880
|
+
* Required implementation for a choice pseudo-state.
|
|
4881
|
+
*
|
|
4882
|
+
* **Details**
|
|
4883
|
+
*
|
|
4884
|
+
* A choice state declares only `choice`, the transition that resolves it to
|
|
4885
|
+
* a concrete destination. Every other handler key is rejected.
|
|
4886
|
+
*
|
|
4887
|
+
* @category models
|
|
4888
|
+
* @since 0.23.0
|
|
4889
|
+
*/
|
|
4890
|
+
export interface ChoiceStateConfig<
|
|
5855
4891
|
States extends StateSchemas,
|
|
5856
4892
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
5857
4893
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
@@ -5882,44 +4918,6 @@ export declare namespace Machine {
|
|
|
5882
4918
|
readonly [Key in keyof Config as Key extends "states" | "initial" | "root" ? never : Key]: Config[Key]
|
|
5883
4919
|
}
|
|
5884
4920
|
|
|
5885
|
-
type HandlerNodeChildrenConfig<Config> = "states" extends keyof Config ?
|
|
5886
|
-
Config extends { readonly states?: infer Children } ? NonNullable<Children>
|
|
5887
|
-
: never
|
|
5888
|
-
: never
|
|
5889
|
-
|
|
5890
|
-
type HandlerNodeByPath<States extends StateSchemas, Path extends string> = "" extends keyof States ?
|
|
5891
|
-
Path extends "" ? States[""]
|
|
5892
|
-
: States[""] extends { readonly states: infer Children extends StateSchemas } ? HandlerNodeByPath<Children, Path>
|
|
5893
|
-
: never
|
|
5894
|
-
: Path extends `${infer Head}.${infer Rest}` ? Head extends keyof States ? States[Head] extends {
|
|
5895
|
-
readonly states: infer Children extends StateSchemas
|
|
5896
|
-
} ? HandlerNodeByPath<Children, Rest>
|
|
5897
|
-
: never
|
|
5898
|
-
: never
|
|
5899
|
-
: Path extends keyof States ? States[Path]
|
|
5900
|
-
: never
|
|
5901
|
-
|
|
5902
|
-
// Resolve only the supplied branch for a flattened state-node path. Keeping
|
|
5903
|
-
// this recursion on the finite path avoids recursively expanding an open
|
|
5904
|
-
// generic handler config.
|
|
5905
|
-
type HandlerConfigAtPath<Config, Path extends string> = [Config] extends [never] ? never :
|
|
5906
|
-
"" extends keyof Config ? Path extends "" ? Config[""]
|
|
5907
|
-
: HandlerConfigAtPath<HandlerNodeChildrenConfig<Config[""]>, Path>
|
|
5908
|
-
: Path extends `${infer Head}.${infer Rest}` ?
|
|
5909
|
-
Head extends keyof Config ? HandlerConfigAtPath<HandlerNodeChildrenConfig<Config[Head]>, Rest>
|
|
5910
|
-
: never
|
|
5911
|
-
: Path extends keyof Config ? Config[Path]
|
|
5912
|
-
: never
|
|
5913
|
-
|
|
5914
|
-
// Rebuild the public nested handler shape so branded validation errors stay
|
|
5915
|
-
// attached to the exact property that introduced them.
|
|
5916
|
-
type HandlerValidationAtPath<Path extends string, Validation> = Path extends `${infer Head}.${infer Rest}` ? {
|
|
5917
|
-
readonly [Key in Head]?: {
|
|
5918
|
-
readonly states: HandlerValidationAtPath<Rest, Validation>
|
|
5919
|
-
}
|
|
5920
|
-
}
|
|
5921
|
-
: { readonly [Key in Path]?: Validation }
|
|
5922
|
-
|
|
5923
4921
|
type HandlerNodeConfigKey =
|
|
5924
4922
|
| "always"
|
|
5925
4923
|
| "choice"
|
|
@@ -6034,42 +5032,6 @@ export declare namespace Machine {
|
|
|
6034
5032
|
}
|
|
6035
5033
|
: unknown
|
|
6036
5034
|
|
|
6037
|
-
type TransitionResultInitialTargetPath<Result> = IsAny<Result> extends true ? never
|
|
6038
|
-
: Result extends Effect.Effect<infer Success, any, any> ? TransitionResultInitialTargetPath<Success>
|
|
6039
|
-
: Result extends SelectedBranch<any, infer Selected> ? TransitionResultInitialTargetPath<Selected>
|
|
6040
|
-
: Result extends StateConstruction<infer Constructed> ? TransitionResultInitialTargetPath<Constructed>
|
|
6041
|
-
: Result extends {
|
|
6042
|
-
readonly [Topology.InitialTargetTypeId]: typeof Topology.InitialTargetTypeId
|
|
6043
|
-
readonly _tag: "InitialTarget"
|
|
6044
|
-
} ? Result extends { readonly path: infer Path extends string } ? Path : never
|
|
6045
|
-
: never
|
|
6046
|
-
|
|
6047
|
-
type HandlerConfigInitialTargetPath<Config> = TransitionResultInitialTargetPath<
|
|
6048
|
-
| EventHandlerReturn<Config>
|
|
6049
|
-
| AlwaysReturn<Config>
|
|
6050
|
-
| DoneReturn<Config>
|
|
6051
|
-
| ChoiceReturn<Config>
|
|
6052
|
-
| InvokeOutcomeReturn<InvokeReturn<Config>>
|
|
6053
|
-
>
|
|
6054
|
-
|
|
6055
|
-
type RequiredInitializersForTargetPath<
|
|
6056
|
-
AllStates extends StateSchemas,
|
|
6057
|
-
Path
|
|
6058
|
-
> = string extends Path ? never : Path extends StateIdentifier<AllStates> ? InitializerClosureForNode<
|
|
6059
|
-
AllStates,
|
|
6060
|
-
NodeByIdentifier<AllStates, Path>,
|
|
6061
|
-
Path
|
|
6062
|
-
>
|
|
6063
|
-
: never
|
|
6064
|
-
|
|
6065
|
-
type HandlerTreeInitialTargetPath<Config> = string extends keyof Config ? never
|
|
6066
|
-
: Config extends object ? {
|
|
6067
|
-
readonly [Key in keyof Config]:
|
|
6068
|
-
| HandlerConfigInitialTargetPath<HandlerConfigPart<Config[Key]>>
|
|
6069
|
-
| (Config[Key] extends { readonly states: infer Children } ? HandlerTreeInitialTargetPath<Children> : never)
|
|
6070
|
-
}[keyof Config]
|
|
6071
|
-
: never
|
|
6072
|
-
|
|
6073
5035
|
type HandlerChildrenValidation<
|
|
6074
5036
|
Node,
|
|
6075
5037
|
Prefix extends string,
|
|
@@ -6201,34 +5163,6 @@ export declare namespace Machine {
|
|
|
6201
5163
|
> = [Incompatible] extends [never] ? unknown
|
|
6202
5164
|
: HandlerValidationError<"Handler config requires an incompatible machine runtime", StateId, Incompatible>
|
|
6203
5165
|
|
|
6204
|
-
type RootInitialTargetValidation<States extends StateSchemas, Config> =
|
|
6205
|
-
RequiredInitializersForTargetPath<States, HandlerTreeInitialTargetPath<{ readonly "": Config }>> extends
|
|
6206
|
-
infer Required ? Types.UnionToIntersection<
|
|
6207
|
-
Required extends string ?
|
|
6208
|
-
HandlerConfigAtPath<{ readonly "": Config }, Required> extends infer NodeConfig ?
|
|
6209
|
-
[NodeConfig] extends [never] ? RootInitializeError<Required>
|
|
6210
|
-
: "initial" extends keyof NodeConfig ? never
|
|
6211
|
-
: RootInitializeError<Required>
|
|
6212
|
-
: never :
|
|
6213
|
-
unknown
|
|
6214
|
-
> :
|
|
6215
|
-
unknown
|
|
6216
|
-
|
|
6217
|
-
type RootInitializeError<Path extends string> = Path extends "" ? {
|
|
6218
|
-
readonly initialize: HandlerValidationError<
|
|
6219
|
-
"State requires initialize because a transition enters its declared initial configuration",
|
|
6220
|
-
Path
|
|
6221
|
-
>
|
|
6222
|
-
} :
|
|
6223
|
-
{
|
|
6224
|
-
readonly states: HandlerValidationAtPath<Path, {
|
|
6225
|
-
readonly initialize: HandlerValidationError<
|
|
6226
|
-
"State requires initialize because a transition enters its declared initial configuration",
|
|
6227
|
-
Path
|
|
6228
|
-
>
|
|
6229
|
-
}>
|
|
6230
|
-
}
|
|
6231
|
-
|
|
6232
5166
|
type HandlerTreeValidation<
|
|
6233
5167
|
States extends StateSchemas,
|
|
6234
5168
|
Node,
|
|
@@ -6383,50 +5317,12 @@ export declare namespace Machine {
|
|
|
6383
5317
|
: never)
|
|
6384
5318
|
}[Extract<keyof Config & keyof Nodes, string>]
|
|
6385
5319
|
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
Input extends Schema.Top,
|
|
6391
|
-
UnhandledStates extends StateIdentifier<AllStates>,
|
|
6392
|
-
E,
|
|
6393
|
-
R,
|
|
6394
|
-
InitialE,
|
|
6395
|
-
InitialR,
|
|
6396
|
-
FinalStates extends StateIdentifier<AllStates>,
|
|
6397
|
-
Output,
|
|
6398
|
-
OutputStates extends StateIdentifier<AllStates>,
|
|
6399
|
-
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
6400
|
-
ParentEvents extends ReadonlyArray<TaggedSchema>,
|
|
6401
|
-
Config
|
|
6402
|
-
> = Machine<
|
|
6403
|
-
AllStates,
|
|
6404
|
-
Events,
|
|
6405
|
-
Input,
|
|
6406
|
-
Exclude<UnhandledStates, HandlerTreeEvidence<AllStates, Config>["stateId"]>,
|
|
6407
|
-
E | HandlerTreeEvidence<AllStates, Config>["error"],
|
|
6408
|
-
ExcludeCompatibleRuntime<
|
|
6409
|
-
R | HandlerTreeEvidence<AllStates, Config>["services"],
|
|
6410
|
-
EventOf<Events>,
|
|
6411
|
-
EmittedEventOf<Emits>
|
|
6412
|
-
>,
|
|
6413
|
-
InitialE,
|
|
6414
|
-
InitialR,
|
|
6415
|
-
FinalStates,
|
|
6416
|
-
Output,
|
|
6417
|
-
Emits,
|
|
6418
|
-
OutputStates | Extract<HandlerTreeEvidence<AllStates, Config>["outputState"], StateIdentifier<AllStates>>,
|
|
6419
|
-
InputEvents,
|
|
6420
|
-
ParentEvents
|
|
5320
|
+
// Evaluated once per handled config and read through each machine channel.
|
|
5321
|
+
type HandleEvidence<S extends StateSchemas, C, R> = HandlerTreeEvidence<
|
|
5322
|
+
S,
|
|
5323
|
+
{ readonly "": NormalizeObjectConfig<C, R> }
|
|
6421
5324
|
>
|
|
6422
5325
|
|
|
6423
|
-
type ObjectCompoundPath<S extends StateSchemas> = {
|
|
6424
|
-
readonly [P in StateIdentifier<S>]: NodeByIdentifier<S, P> extends {
|
|
6425
|
-
/** Child handlers nested according to the declared root topology. */
|
|
6426
|
-
readonly states: StateSchemas
|
|
6427
|
-
} ? P :
|
|
6428
|
-
never
|
|
6429
|
-
}[StateIdentifier<S>]
|
|
6430
5326
|
type LazyProgramValue = Effect.Effect<unknown, unknown, unknown> | Stream.Stream<unknown, unknown, unknown>
|
|
6431
5327
|
|
|
6432
5328
|
/** Registered lazy programs and their optional explicit input adapters. */
|
|
@@ -6437,7 +5333,7 @@ export declare namespace Machine {
|
|
|
6437
5333
|
export type LogicSources = Readonly<Record<string, unknown>>
|
|
6438
5334
|
export type ValidateLogicSources<Sources> = {
|
|
6439
5335
|
readonly [K in keyof Sources]: InvokeResolvedSource<Sources[K]> extends {
|
|
6440
|
-
/**
|
|
5336
|
+
/** Produces the first state of the registered logic. */
|
|
6441
5337
|
readonly initial: (...args: never[]) => Effect.Effect<unknown, unknown, unknown>
|
|
6442
5338
|
readonly run: (...args: never[]) => Effect.Effect<unknown, unknown, unknown>
|
|
6443
5339
|
} ? unknown
|
|
@@ -6458,92 +5354,6 @@ export declare namespace Machine {
|
|
|
6458
5354
|
Paths
|
|
6459
5355
|
>
|
|
6460
5356
|
type DestinationPath<S extends StateSchemas> = Exclude<StateNodeIdentifier<S>, "">
|
|
6461
|
-
type RootSchemas<Root extends StateNodeConfig> = { readonly "": Root }
|
|
6462
|
-
|
|
6463
|
-
/** A topology declaration; its state values are constructed by a resolver. */
|
|
6464
|
-
export type BranchDeclaration<Root extends StateNodeConfig, S extends StateSchemas = RootSchemas<Root>> =
|
|
6465
|
-
& {
|
|
6466
|
-
/** Optional presentation label for this named branch. */
|
|
6467
|
-
readonly title?: string
|
|
6468
|
-
}
|
|
6469
|
-
& (
|
|
6470
|
-
| {
|
|
6471
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6472
|
-
readonly target: ReferenceUnion<S, DestinationPath<S>>
|
|
6473
|
-
/**
|
|
6474
|
-
* Replaces the complete value of a retained ancestor of the source and target without replacing its active
|
|
6475
|
-
* children. A choice target resolves after the update, and every branch it can reach must stay below the owner.
|
|
6476
|
-
*/
|
|
6477
|
-
readonly update?: ReferenceUnion<S, ValuedStateIdentifier<S>>
|
|
6478
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
6479
|
-
readonly initial?: never
|
|
6480
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6481
|
-
readonly history?: never
|
|
6482
|
-
/** Accepts the event without selecting a new destination. */
|
|
6483
|
-
readonly none?: never
|
|
6484
|
-
/** Reconstructs root and its initial children from fresh machine input. */
|
|
6485
|
-
readonly initialize?: never
|
|
6486
|
-
}
|
|
6487
|
-
| {
|
|
6488
|
-
/** Reconstructs root and its initial children from fresh machine input supplied by the resolver. */
|
|
6489
|
-
readonly initialize: true
|
|
6490
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6491
|
-
readonly target?: never
|
|
6492
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6493
|
-
readonly update?: never
|
|
6494
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
6495
|
-
readonly initial?: never
|
|
6496
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6497
|
-
readonly history?: never
|
|
6498
|
-
/** Accepts the event without selecting a new destination. */
|
|
6499
|
-
readonly none?: never
|
|
6500
|
-
}
|
|
6501
|
-
| {
|
|
6502
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6503
|
-
readonly update: ReferenceUnion<S, ValuedStateIdentifier<S>>
|
|
6504
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6505
|
-
readonly target?: never
|
|
6506
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
6507
|
-
readonly initial?: never
|
|
6508
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6509
|
-
readonly history?: never
|
|
6510
|
-
/** Accepts the event without selecting a new destination. */
|
|
6511
|
-
readonly none?: never
|
|
6512
|
-
/** Reconstructs root and its initial children from fresh machine input. */
|
|
6513
|
-
readonly initialize?: never
|
|
6514
|
-
}
|
|
6515
|
-
| {
|
|
6516
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6517
|
-
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>
|
|
6518
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6519
|
-
readonly target?: never
|
|
6520
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6521
|
-
readonly update?: never
|
|
6522
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
6523
|
-
readonly initial?: never
|
|
6524
|
-
/** Accepts the event without selecting a new destination. */
|
|
6525
|
-
readonly none?: never
|
|
6526
|
-
/** Reconstructs root and its initial children from fresh machine input. */
|
|
6527
|
-
readonly initialize?: never
|
|
6528
|
-
}
|
|
6529
|
-
| {
|
|
6530
|
-
/** Accepts the event without selecting a new destination. */
|
|
6531
|
-
readonly none: true
|
|
6532
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6533
|
-
readonly target?: never
|
|
6534
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6535
|
-
readonly update?: never
|
|
6536
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
6537
|
-
readonly initial?: never
|
|
6538
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6539
|
-
readonly history?: never
|
|
6540
|
-
/** Reconstructs root and its initial children from fresh machine input. */
|
|
6541
|
-
readonly initialize?: never
|
|
6542
|
-
}
|
|
6543
|
-
)
|
|
6544
|
-
export type BranchDefinitions<Root extends StateNodeConfig> = Readonly<
|
|
6545
|
-
Record<string, Readonly<Record<string, BranchDeclaration<Root>>>>
|
|
6546
|
-
>
|
|
6547
5357
|
/** Source programs and named topology declarations captured by a machine definition. */
|
|
6548
5358
|
export interface Registrations {
|
|
6549
5359
|
/** Lazy Effects or functions with one required input, invoked by registered name. */
|
|
@@ -6556,12 +5366,9 @@ export declare namespace Machine {
|
|
|
6556
5366
|
readonly logic?: LogicSources
|
|
6557
5367
|
/** Child machine descriptors registered for state-owned invocation. */
|
|
6558
5368
|
readonly children?: ChildSources
|
|
6559
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
6560
|
-
readonly branches?: Readonly<Record<string, Readonly<Record<string, unknown>>>>
|
|
6561
5369
|
}
|
|
6562
5370
|
type RegisteredInput<R> = R extends { readonly "~input": infer I extends Schema.Top } ? I : typeof Schema.Void
|
|
6563
5371
|
type Registered<R, Kind extends PropertyKey> = Kind extends keyof R ? NonNullable<R[Kind]> : {}
|
|
6564
|
-
type RefPath<R> = PathOf<R>
|
|
6565
5372
|
type ConstructionData<Node> = [NodeSchema<Node>] extends [never] ? { readonly data?: never; readonly decoded?: never }
|
|
6566
5373
|
:
|
|
6567
5374
|
| (
|
|
@@ -6610,86 +5417,68 @@ export declare namespace Machine {
|
|
|
6610
5417
|
/** Fresh machine input used by root construction and root initial callbacks. */ readonly input:
|
|
6611
5418
|
RegisteredInput<R>["Type"]
|
|
6612
5419
|
})
|
|
6613
|
-
type
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
Target<S, P>
|
|
6626
|
-
>
|
|
6627
|
-
: never
|
|
6628
|
-
type SelectionOf<S extends StateSchemas, Src extends StateNodeIdentifier<S>, D, R = {}> = D extends {
|
|
6629
|
-
readonly initialize: true
|
|
6630
|
-
} ? TargetSelection<ObjectSelection<S, Src, Extract<"", StateNodeIdentifier<S>>, R>, "", "state", "branch">
|
|
6631
|
-
: D extends {
|
|
6632
|
-
readonly target: infer Ref
|
|
6633
|
-
} ?
|
|
6634
|
-
RefPath<Ref> extends infer P extends StateNodeIdentifier<S> ?
|
|
6635
|
-
D extends { readonly update: infer Update }
|
|
6636
|
-
? RefPath<Update> extends
|
|
6637
|
-
infer Owner extends Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>
|
|
6638
|
-
? P extends StateIdentifier<S> ? TargetSelection<
|
|
6639
|
-
ConstructionCall<
|
|
6640
|
-
ConstructionObject<
|
|
6641
|
-
NodeByIdentifier<S, P>,
|
|
6642
|
-
Src extends `${P}.${infer Rest}` ? Rest : Src extends P ? "" : never
|
|
6643
|
-
> & {
|
|
6644
|
-
readonly update: ConstructionData<NodeByIdentifier<S, Owner>>
|
|
6645
|
-
},
|
|
6646
|
-
CombinedTarget<Target<S, P>, S, Owner>
|
|
6647
|
-
>,
|
|
6648
|
-
P,
|
|
6649
|
-
"state",
|
|
6650
|
-
"branch"
|
|
6651
|
-
>
|
|
6652
|
-
: P extends ChoiceIdentifier<S> ? TargetSelection<
|
|
6653
|
-
(construction: {
|
|
6654
|
-
readonly update: ConstructionData<NodeByIdentifier<S, Owner>>
|
|
6655
|
-
}) => CombinedTarget<ChoiceTarget<S, P>, S, Owner>,
|
|
6656
|
-
P,
|
|
6657
|
-
"choice",
|
|
6658
|
-
"branch"
|
|
6659
|
-
> :
|
|
6660
|
-
never
|
|
6661
|
-
: never
|
|
6662
|
-
: TargetSelection<
|
|
6663
|
-
ObjectSelection<S, Src, P, R>,
|
|
6664
|
-
P,
|
|
6665
|
-
P extends ChoiceIdentifier<S> ? "choice" : "state",
|
|
6666
|
-
"branch"
|
|
6667
|
-
>
|
|
6668
|
-
: never
|
|
6669
|
-
: D extends { readonly history: infer Ref }
|
|
6670
|
-
? RefPath<Ref> extends infer P extends HistoryIdentifier<S>
|
|
6671
|
-
? TargetSelection<() => HistoryTarget<S, P>, P, "history", "full"> :
|
|
6672
|
-
never
|
|
6673
|
-
: D extends { readonly update: infer Ref }
|
|
6674
|
-
? RefPath<Ref> extends infer P extends Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>
|
|
6675
|
-
? TargetSelection<
|
|
6676
|
-
ConstructionCall<ConstructionData<NodeByIdentifier<S, P>>, StateUpdate<S, P>>,
|
|
6677
|
-
P,
|
|
6678
|
-
"update",
|
|
6679
|
-
"branch"
|
|
6680
|
-
> :
|
|
6681
|
-
never
|
|
6682
|
-
: D extends { readonly none: true } ? TargetSelection<() => NoTarget, never, "none", "local">
|
|
5420
|
+
type UpdateValue<Node> = OrdinaryData<NodeMakeInput<Node>> | {
|
|
5421
|
+
readonly decoded: true
|
|
5422
|
+
readonly data: NodeValue<Node>
|
|
5423
|
+
}
|
|
5424
|
+
type TargetConstruction<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends DestinationPath<S>> =
|
|
5425
|
+
P extends StateIdentifier<S> ?
|
|
5426
|
+
ConstructionObject<NodeByIdentifier<S, P>, Src extends `${P}.${infer Rest}` ? Rest : Src extends P ? "" : never>
|
|
5427
|
+
: {}
|
|
5428
|
+
type TargetArguments<A> = {} extends A ? [construction?: A & { readonly update?: never }]
|
|
5429
|
+
: [construction: A & { readonly update?: never }]
|
|
5430
|
+
type TargetResult<S extends StateSchemas, P extends string> = P extends ChoiceIdentifier<S> ? ChoiceTarget<S, P>
|
|
5431
|
+
: P extends StateIdentifier<S> ? Target<S, P>
|
|
6683
5432
|
: never
|
|
6684
|
-
type
|
|
6685
|
-
?
|
|
6686
|
-
:
|
|
6687
|
-
type
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
5433
|
+
type OnePath<P extends string> = Types.IsUnion<P> extends true
|
|
5434
|
+
? { readonly [K in `select.target takes one path, got: ${JoinUnion<P>}. Call it once per path`]: never }
|
|
5435
|
+
: unknown
|
|
5436
|
+
type OneOwner<O extends string> = Types.IsUnion<O> extends true ? `update takes one owner, got: ${JoinUnion<O>}`
|
|
5437
|
+
: unknown
|
|
5438
|
+
/**
|
|
5439
|
+
* Selects one entry of a transition's `branches` list. The compiler checks that `resolve` selects exactly the
|
|
5440
|
+
* declared entries, so each call here must match one of them.
|
|
5441
|
+
*
|
|
5442
|
+
* @category models
|
|
5443
|
+
* @since 0.47.0
|
|
5444
|
+
*/
|
|
5445
|
+
export interface BranchSelect<S extends StateSchemas, Src extends StateNodeIdentifier<S>, R> {
|
|
5446
|
+
/** Selects `{ target }`, or `{ target, update }` when the construction has an `update` record. */
|
|
5447
|
+
readonly target: {
|
|
5448
|
+
<P extends DestinationPath<S>, O extends ReferenceUnion<S, TargetOwner<S, Src, P>>>(
|
|
5449
|
+
path: P & OnePath<P>,
|
|
5450
|
+
construction: TargetConstruction<S, Src, P> & {
|
|
5451
|
+
/** The new value of the retained owner named by this branch. */
|
|
5452
|
+
readonly update:
|
|
5453
|
+
& { readonly [Owner in O]: UpdateValue<NodeByIdentifier<S, Extract<PathOf<Owner>, StateIdentifier<S>>>> }
|
|
5454
|
+
& OneOwner<O>
|
|
5455
|
+
}
|
|
5456
|
+
): SelectedBranch<
|
|
5457
|
+
`target:${P}+update:${O}`,
|
|
5458
|
+
CombinedTarget<TargetResult<S, P>, S, Extract<PathOf<O>, ValuedStateIdentifier<S>>>
|
|
5459
|
+
>
|
|
5460
|
+
<P extends DestinationPath<S>>(
|
|
5461
|
+
path: P & OnePath<P>,
|
|
5462
|
+
...construction: TargetArguments<TargetConstruction<S, Src, P>>
|
|
5463
|
+
): SelectedBranch<`target:${P}`, TargetResult<S, P>>
|
|
5464
|
+
}
|
|
5465
|
+
/** Selects `{ update }`, replacing the value of one retained source or ancestor. */
|
|
5466
|
+
readonly update: <O extends ReferenceUnion<S, UpdatableOwner<S, Src>>>(
|
|
5467
|
+
updates:
|
|
5468
|
+
& { readonly [Owner in O]: UpdateValue<NodeByIdentifier<S, Extract<PathOf<Owner>, StateIdentifier<S>>>> }
|
|
5469
|
+
& OneOwner<O>
|
|
5470
|
+
) => SelectedBranch<`update:${O}`, StateUpdate<S, Extract<PathOf<O>, ValuedStateIdentifier<S>>>>
|
|
5471
|
+
/** Selects `{ history }`. */
|
|
5472
|
+
readonly history: <P extends ReferenceUnion<S, HistoryIdentifier<S>>>(
|
|
5473
|
+
path: P
|
|
5474
|
+
) => SelectedBranch<`history:${P}`, HistoryTarget<S, Extract<PathOf<P>, HistoryIdentifier<S>>>>
|
|
5475
|
+
/** Selects `{ initialize: true }`. */
|
|
5476
|
+
readonly initialize: ConstructionCall<RootInput<R>, SelectedBranch<"initialize", InitialTarget<"">>>
|
|
5477
|
+
/** Selects `{ stay: true }`. */
|
|
5478
|
+
readonly stay: () => SelectedBranch<"stay", NoTarget>
|
|
5479
|
+
/** Selects `{ decline: true }`, passing the event on to the next candidate. */
|
|
5480
|
+
readonly decline: () => SelectedBranch<"decline", Declined>
|
|
5481
|
+
}
|
|
6693
5482
|
type ObjectPolicy<C, Reenter extends boolean, Acceptance extends TransitionAcceptance> = {
|
|
6694
5483
|
/** Set to true to exit and reenter the handler source. */
|
|
6695
5484
|
readonly reenter?: Reenter extends true ? boolean : never
|
|
@@ -6720,147 +5509,121 @@ export declare namespace Machine {
|
|
|
6720
5509
|
*/
|
|
6721
5510
|
readonly initialize: RegisteredInput<R> extends typeof Schema.Void ? true
|
|
6722
5511
|
: DataValue<C, RegisteredInput<R>["Type"]>
|
|
5512
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
6723
5513
|
readonly target?: never
|
|
5514
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
6724
5515
|
readonly update?: never
|
|
5516
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
5517
|
+
readonly history?: never
|
|
5518
|
+
/** Accepts the event and stays in the current states. */
|
|
5519
|
+
readonly stay?: never
|
|
5520
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
6725
5521
|
readonly branches?: never
|
|
5522
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
6726
5523
|
readonly resolve?: never
|
|
6727
|
-
readonly history?: never
|
|
6728
|
-
readonly none?: never
|
|
6729
5524
|
}
|
|
5525
|
+
type OwnerUpdates<S extends StateSchemas, Owners extends ValuedStateIdentifier<S>, C> = {
|
|
5526
|
+
readonly [O in Owners as PathName<O>]?: ShortConstruction<C, NodeByIdentifier<S, O>>
|
|
5527
|
+
}
|
|
5528
|
+
type TargetOwner<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string> = Src extends
|
|
5529
|
+
ChoiceIdentifier<S> ? never
|
|
5530
|
+
: Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>
|
|
5531
|
+
type UpdatableOwner<S extends StateSchemas, Src extends StateNodeIdentifier<S>> = Src extends ChoiceIdentifier<S> ?
|
|
5532
|
+
never
|
|
5533
|
+
: Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>
|
|
6730
5534
|
type InlineDestination<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = {
|
|
6731
5535
|
readonly [P in DestinationPath<S>]:
|
|
6732
5536
|
& {
|
|
6733
|
-
/** Selects a declared descendant
|
|
5537
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
6734
5538
|
readonly target: ReferenceAt<S, P>
|
|
6735
|
-
/**
|
|
6736
|
-
|
|
6737
|
-
|
|
6738
|
-
|
|
5539
|
+
/**
|
|
5540
|
+
* Replaces the value of one retained ancestor of the source and target without replacing its active children.
|
|
5541
|
+
* A choice target resolves after the update, and every branch it can reach must stay below the owner.
|
|
5542
|
+
*/
|
|
5543
|
+
readonly update?: OwnerUpdates<S, TargetOwner<S, Src, P>, C>
|
|
5544
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
5545
|
+
readonly initialize?: never
|
|
6739
5546
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6740
5547
|
readonly history?: never
|
|
6741
|
-
/** Accepts the event
|
|
6742
|
-
readonly
|
|
6743
|
-
/**
|
|
5548
|
+
/** Accepts the event and stays in the current states. */
|
|
5549
|
+
readonly stay?: never
|
|
5550
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
6744
5551
|
readonly branches?: never
|
|
6745
5552
|
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
6746
5553
|
readonly resolve?: never
|
|
6747
|
-
/** Set to true when the resolver can explicitly return decline(). */
|
|
6748
|
-
readonly declinable?: never
|
|
6749
5554
|
}
|
|
6750
5555
|
& InlineDestinationConstruction<S, Src, P, C>
|
|
6751
5556
|
}[DestinationPath<S>]
|
|
6752
|
-
|
|
5557
|
+
// A misspelled target matches this member, so validation can name the declared paths instead of `never`.
|
|
5558
|
+
type InlineUnknownTarget<S extends StateSchemas> = {
|
|
5559
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
5560
|
+
readonly target: ReferenceUnion<S, DestinationPath<S>> | (string & {})
|
|
5561
|
+
readonly update?: never
|
|
5562
|
+
readonly initialize?: never
|
|
5563
|
+
readonly history?: never
|
|
5564
|
+
readonly stay?: never
|
|
5565
|
+
readonly branches?: never
|
|
5566
|
+
readonly resolve?: never
|
|
5567
|
+
}
|
|
5568
|
+
type InlineUpdate<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = [UpdatableOwner<S, Src>] extends
|
|
5569
|
+
[never] ? never : {
|
|
5570
|
+
/** Replaces the value of one retained source or ancestor without replacing its active children. */
|
|
5571
|
+
readonly update: OwnerUpdates<S, UpdatableOwner<S, Src>, C>
|
|
5572
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
5573
|
+
readonly target?: never
|
|
5574
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
5575
|
+
readonly initialize?: never
|
|
5576
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
5577
|
+
readonly history?: never
|
|
5578
|
+
/** Accepts the event and stays in the current states. */
|
|
5579
|
+
readonly stay?: never
|
|
5580
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
5581
|
+
readonly branches?: never
|
|
5582
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
5583
|
+
readonly resolve?: never
|
|
5584
|
+
}
|
|
5585
|
+
/**
|
|
5586
|
+
* One destination a `resolve` function can select. Here `update` names the owner as a string, because the value is
|
|
5587
|
+
* passed to the `select` call.
|
|
5588
|
+
*
|
|
5589
|
+
* @category models
|
|
5590
|
+
* @since 0.47.0
|
|
5591
|
+
*/
|
|
5592
|
+
export type BranchEntry<
|
|
6753
5593
|
S extends StateSchemas,
|
|
6754
5594
|
Src extends StateNodeIdentifier<S>,
|
|
6755
|
-
|
|
6756
|
-
|
|
6757
|
-
|
|
6758
|
-
> = P extends StateIdentifier<S> ?
|
|
6759
|
-
| {
|
|
6760
|
-
readonly from: (
|
|
6761
|
-
context: C
|
|
6762
|
-
) => {
|
|
6763
|
-
readonly target: [NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? undefined
|
|
6764
|
-
: NodeMakeInput<NodeByIdentifier<S, P>>
|
|
6765
|
-
readonly update: SchemaByIdentifier<S, Owner>["~type.make.in"]
|
|
6766
|
-
}
|
|
6767
|
-
readonly decoded?: never
|
|
6768
|
-
}
|
|
6769
|
-
| ([NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? never
|
|
6770
|
-
: {
|
|
6771
|
-
readonly decoded: (
|
|
6772
|
-
context: C
|
|
6773
|
-
) => { readonly target: NodeValue<NodeByIdentifier<S, P>>; readonly update: StateByIdentifier<S, Owner> }
|
|
6774
|
-
readonly from?: never
|
|
6775
|
-
})
|
|
6776
|
-
: P extends ChoiceIdentifier<S> ? ObjectConstruction<C, StateUpdateBuilder<S, Owner>>
|
|
6777
|
-
: never
|
|
6778
|
-
type InlineCombined<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = Src extends ChoiceIdentifier<S> ?
|
|
6779
|
-
never :
|
|
6780
|
-
[Extract<ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>] extends [never] ? never :
|
|
6781
|
-
{
|
|
5595
|
+
Acceptance extends TransitionAcceptance
|
|
5596
|
+
> =
|
|
5597
|
+
| {
|
|
6782
5598
|
readonly [P in DestinationPath<S>]: {
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
* Replaces the complete value of a retained ancestor of the source and target without replacing its active
|
|
6789
|
-
* children. A choice target resolves after the update, and every branch it can reach must stay below the
|
|
6790
|
-
* owner; `data` then constructs only the owner value.
|
|
6791
|
-
*/
|
|
6792
|
-
readonly update: ReferenceAt<S, Owner>
|
|
6793
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
6794
|
-
readonly initial?: never
|
|
6795
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6796
|
-
readonly history?: never
|
|
6797
|
-
/** Accepts the event without selecting a new destination. */
|
|
6798
|
-
readonly none?: never
|
|
6799
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
6800
|
-
readonly branches?: never
|
|
6801
|
-
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
6802
|
-
readonly resolve?: never
|
|
6803
|
-
/** Set to true when the resolver can explicitly return decline(). */
|
|
6804
|
-
readonly declinable?: never
|
|
6805
|
-
}
|
|
6806
|
-
& InlinePairConstruction<S, Src, P, Owner, C>
|
|
6807
|
-
}[Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>]
|
|
5599
|
+
/** Selects a declared descendant through `select.target`. */
|
|
5600
|
+
readonly target: ReferenceAt<S, P>
|
|
5601
|
+
/** The retained ancestor that this branch's `select.target` call updates. */
|
|
5602
|
+
readonly update?: ReferenceUnion<S, TargetOwner<S, Src, P>>
|
|
5603
|
+
}
|
|
6808
5604
|
}[DestinationPath<S>]
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
readonly
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
readonly update: ReferenceAt<S, P>
|
|
6818
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6819
|
-
readonly target?: never
|
|
6820
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
6821
|
-
readonly initial?: never
|
|
6822
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6823
|
-
readonly history?: never
|
|
6824
|
-
/** Accepts the event without selecting a new destination. */
|
|
6825
|
-
readonly none?: never
|
|
6826
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
6827
|
-
readonly branches?: never
|
|
6828
|
-
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
6829
|
-
readonly resolve?: never
|
|
6830
|
-
/** Set to true when the resolver can explicitly return decline(). */
|
|
6831
|
-
readonly declinable?: never
|
|
6832
|
-
}
|
|
6833
|
-
& ObjectConstruction<C, StateUpdateBuilder<S, P>>
|
|
6834
|
-
}[Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>]
|
|
6835
|
-
type BranchSelections<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group, R> = {
|
|
6836
|
-
readonly [K in Extract<keyof Group, string>]: {
|
|
6837
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6838
|
-
readonly target: SelectionOf<S, Src, Group[K], R>
|
|
5605
|
+
| ([UpdatableOwner<S, Src>] extends [never] ? never : {
|
|
5606
|
+
/** The retained state updated through `select.update`. */
|
|
5607
|
+
readonly update: ReferenceUnion<S, UpdatableOwner<S, Src>>
|
|
5608
|
+
readonly target?: never
|
|
5609
|
+
})
|
|
5610
|
+
| {
|
|
5611
|
+
/** Restores this history reference through `select.history`. */
|
|
5612
|
+
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>
|
|
6839
5613
|
}
|
|
6840
|
-
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
/** Accepts the event without selecting a new destination. */
|
|
6854
|
-
readonly none: true
|
|
6855
|
-
} | {
|
|
6856
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6857
|
-
readonly update: unknown
|
|
6858
|
-
} ? K
|
|
6859
|
-
: [SelectionBuilder<SelectionOf<S, Src, Group[K], R>>] extends [never] ? K
|
|
6860
|
-
: never
|
|
6861
|
-
: [SelectionBuilder<SelectionOf<S, Src, Group[K], R>>] extends [never] ? K
|
|
6862
|
-
: never
|
|
6863
|
-
}[keyof Group]
|
|
5614
|
+
| {
|
|
5615
|
+
/** Reconstructs root from fresh machine input through `select.initialize`. */
|
|
5616
|
+
readonly initialize: true
|
|
5617
|
+
}
|
|
5618
|
+
| (Src extends ChoiceIdentifier<S> ? never : {
|
|
5619
|
+
/** Accepts the event and stays in the current states through `select.stay`. */
|
|
5620
|
+
readonly stay: true
|
|
5621
|
+
})
|
|
5622
|
+
| (Acceptance extends "declinable" ? {
|
|
5623
|
+
/** Passes the event on to the next candidate through `select.decline`. */
|
|
5624
|
+
readonly decline: true
|
|
5625
|
+
} :
|
|
5626
|
+
never)
|
|
6864
5627
|
type ObjectBranches<
|
|
6865
5628
|
S extends StateSchemas,
|
|
6866
5629
|
Src extends StateNodeIdentifier<S>,
|
|
@@ -6868,41 +5631,40 @@ export declare namespace Machine {
|
|
|
6868
5631
|
Ev extends ReadonlyArray<TaggedSchema>,
|
|
6869
5632
|
Em extends ReadonlyArray<TaggedSchema>,
|
|
6870
5633
|
R,
|
|
5634
|
+
Reenter extends boolean,
|
|
6871
5635
|
Acceptance extends TransitionAcceptance
|
|
6872
5636
|
> = {
|
|
6873
|
-
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
|
|
6878
|
-
/** Selects
|
|
6879
|
-
readonly
|
|
6880
|
-
|
|
6881
|
-
|
|
6882
|
-
|
|
6883
|
-
|
|
6884
|
-
|
|
6885
|
-
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
6889
|
-
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6897
|
-
|
|
6898
|
-
|
|
6899
|
-
|
|
6900
|
-
|
|
6901
|
-
|
|
6902
|
-
|
|
6903
|
-
|
|
6904
|
-
}
|
|
6905
|
-
}[Extract<keyof Registered<R, "branches">, string>]
|
|
5637
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
5638
|
+
readonly branches?: ReadonlyArray<BranchEntry<S, Src, Acceptance>>
|
|
5639
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
5640
|
+
readonly resolve?: (
|
|
5641
|
+
context: C & {
|
|
5642
|
+
/** Selects one of the declared `branches`. */
|
|
5643
|
+
readonly select: BranchSelect<S, Src, R>
|
|
5644
|
+
},
|
|
5645
|
+
enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>
|
|
5646
|
+
) => unknown
|
|
5647
|
+
/** Set to true to exit and reenter the handler source. */
|
|
5648
|
+
readonly reenter?: Reenter extends true ? boolean : never
|
|
5649
|
+
/** Branch on the condition inside `resolve`, returning `select.decline()`. */
|
|
5650
|
+
readonly guard?: never
|
|
5651
|
+
/** Enqueue commands inside `resolve`. */
|
|
5652
|
+
readonly commands?: never
|
|
5653
|
+
/** Constructs values through the `select` calls inside `resolve`. */
|
|
5654
|
+
readonly data?: never
|
|
5655
|
+
/** Constructs values through the `select` calls inside `resolve`. */
|
|
5656
|
+
readonly decoded?: never
|
|
5657
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
5658
|
+
readonly target?: never
|
|
5659
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
5660
|
+
readonly update?: never
|
|
5661
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
5662
|
+
readonly initialize?: never
|
|
5663
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
5664
|
+
readonly history?: never
|
|
5665
|
+
/** Accepts the event and stays in the current states. */
|
|
5666
|
+
readonly stay?: never
|
|
5667
|
+
}
|
|
6906
5668
|
type DataValue<C, A> = A | ((context: C) => A)
|
|
6907
5669
|
type DeclarationData<T> = T extends { readonly from: (context: infer C) => infer A }
|
|
6908
5670
|
? Omit<T, "from" | "decoded"> & { readonly data: DataValue<C, A>; readonly decoded?: false }
|
|
@@ -6926,63 +5688,71 @@ export declare namespace Machine {
|
|
|
6926
5688
|
Reenter extends boolean = false,
|
|
6927
5689
|
Acceptance extends TransitionAcceptance = "required"
|
|
6928
5690
|
> =
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
5691
|
+
| (
|
|
5692
|
+
& ObjectPolicy<C, Reenter, Acceptance>
|
|
5693
|
+
& {
|
|
5694
|
+
/** Enqueues synchronous commands when this transition is selected. */
|
|
5695
|
+
readonly commands?: (context: C, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => void
|
|
5696
|
+
}
|
|
5697
|
+
& DeclarationData<
|
|
6932
5698
|
| InlineDestination<S, Src, C>
|
|
5699
|
+
| InlineUnknownTarget<S>
|
|
6933
5700
|
| InlineUpdate<S, Src, C>
|
|
6934
|
-
| InlineCombined<S, Src, C>
|
|
6935
5701
|
| InlineRoot<C, R>
|
|
6936
5702
|
| {
|
|
6937
5703
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6938
5704
|
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>
|
|
6939
|
-
/** Selects a declared descendant
|
|
5705
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
6940
5706
|
readonly target?: never
|
|
6941
|
-
/** Replaces the
|
|
5707
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
6942
5708
|
readonly update?: never
|
|
6943
|
-
/**
|
|
6944
|
-
readonly
|
|
6945
|
-
/** Accepts the event
|
|
6946
|
-
readonly
|
|
6947
|
-
/**
|
|
5709
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
5710
|
+
readonly initialize?: never
|
|
5711
|
+
/** Accepts the event and stays in the current states. */
|
|
5712
|
+
readonly stay?: never
|
|
5713
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
6948
5714
|
readonly branches?: never
|
|
6949
5715
|
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
6950
5716
|
readonly resolve?: never
|
|
6951
|
-
/** Constructs schema make input from the typed source context. */
|
|
6952
|
-
readonly from?: never
|
|
6953
|
-
/** Supplies an already decoded schema value from the typed source context. */
|
|
6954
|
-
readonly decoded?: never
|
|
6955
|
-
/** Set to true when the resolver can explicitly return decline(). */
|
|
6956
|
-
readonly declinable?: never
|
|
6957
5717
|
}
|
|
6958
5718
|
| (Src extends ChoiceIdentifier<S> ? never : {
|
|
6959
|
-
/** Accepts the event
|
|
6960
|
-
readonly
|
|
6961
|
-
/** Selects a declared descendant
|
|
5719
|
+
/** Accepts the event and stays in the current states. */
|
|
5720
|
+
readonly stay: true
|
|
5721
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
6962
5722
|
readonly target?: never
|
|
6963
|
-
/** Replaces the
|
|
5723
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
6964
5724
|
readonly update?: never
|
|
6965
|
-
/**
|
|
6966
|
-
readonly
|
|
5725
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
5726
|
+
readonly initialize?: never
|
|
6967
5727
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6968
5728
|
readonly history?: never
|
|
6969
|
-
/**
|
|
5729
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
6970
5730
|
readonly branches?: never
|
|
6971
|
-
/** Constructs schema make input from the typed source context. */
|
|
6972
|
-
readonly from?: never
|
|
6973
|
-
/** Supplies an already decoded schema value from the typed source context. */
|
|
6974
|
-
readonly decoded?: never
|
|
6975
|
-
/** Set to true when the resolver can explicitly return decline(). */
|
|
6976
|
-
readonly declinable?: "declinable" extends Acceptance ? boolean : false
|
|
6977
5731
|
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
6978
|
-
readonly resolve?:
|
|
6979
|
-
context: C & DeclineCapability,
|
|
6980
|
-
enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>
|
|
6981
|
-
) => undefined | Declined
|
|
5732
|
+
readonly resolve?: never
|
|
6982
5733
|
})
|
|
6983
|
-
|
|
|
6984
|
-
|
|
6985
|
-
|
|
5734
|
+
| (Src extends ChoiceIdentifier<S> ? never : Reenter extends true ? {
|
|
5735
|
+
/** Exits and reenters the source. */
|
|
5736
|
+
readonly reenter: true
|
|
5737
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
5738
|
+
readonly target?: never
|
|
5739
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
5740
|
+
readonly update?: never
|
|
5741
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
5742
|
+
readonly initialize?: never
|
|
5743
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
5744
|
+
readonly history?: never
|
|
5745
|
+
/** Accepts the event and stays in the current states. */
|
|
5746
|
+
readonly stay?: never
|
|
5747
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
5748
|
+
readonly branches?: never
|
|
5749
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
5750
|
+
readonly resolve?: never
|
|
5751
|
+
} :
|
|
5752
|
+
never)
|
|
5753
|
+
>
|
|
5754
|
+
)
|
|
5755
|
+
| ObjectBranches<S, Src, C, Ev, Em, R, Reenter, Acceptance>
|
|
6986
5756
|
type SourceValue<R, K extends PropertyKey> = {
|
|
6987
5757
|
readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: K extends keyof Registered<R, Kind>
|
|
6988
5758
|
? Registered<R, Kind>[K]
|
|
@@ -7056,7 +5826,7 @@ export declare namespace Machine {
|
|
|
7056
5826
|
Em,
|
|
7057
5827
|
R,
|
|
7058
5828
|
true,
|
|
7059
|
-
|
|
5829
|
+
"required"
|
|
7060
5830
|
>
|
|
7061
5831
|
} :
|
|
7062
5832
|
Channel extends "onFailure" ? {
|
|
@@ -7069,7 +5839,7 @@ export declare namespace Machine {
|
|
|
7069
5839
|
Em,
|
|
7070
5840
|
R,
|
|
7071
5841
|
true,
|
|
7072
|
-
|
|
5842
|
+
"required"
|
|
7073
5843
|
>
|
|
7074
5844
|
} :
|
|
7075
5845
|
Channel extends "onElement" ? {
|
|
@@ -7082,7 +5852,7 @@ export declare namespace Machine {
|
|
|
7082
5852
|
Em,
|
|
7083
5853
|
R,
|
|
7084
5854
|
true,
|
|
7085
|
-
|
|
5855
|
+
"required"
|
|
7086
5856
|
>
|
|
7087
5857
|
} :
|
|
7088
5858
|
{
|
|
@@ -7095,7 +5865,7 @@ export declare namespace Machine {
|
|
|
7095
5865
|
Em,
|
|
7096
5866
|
R,
|
|
7097
5867
|
true,
|
|
7098
|
-
|
|
5868
|
+
"required"
|
|
7099
5869
|
>
|
|
7100
5870
|
}
|
|
7101
5871
|
type RegisteredInvokeError<R, K extends PropertyKey> = SourceKind<R, K> extends "children"
|
|
@@ -7319,6 +6089,8 @@ export declare namespace Machine {
|
|
|
7319
6089
|
readonly exit?: never /** Constructs the decoded output declared by the state schema. */
|
|
7320
6090
|
readonly output?: never
|
|
7321
6091
|
}
|
|
6092
|
+
type StateFieldError<Kind extends string, Src extends string, Field extends string, Fix extends string> =
|
|
6093
|
+
`${Kind} state "${PathName<Src>}" cannot declare ${Field}. ${Fix}`
|
|
7322
6094
|
/**
|
|
7323
6095
|
* Handlers for a node of the declared root tree.
|
|
7324
6096
|
*
|
|
@@ -7355,13 +6127,13 @@ export declare namespace Machine {
|
|
|
7355
6127
|
/** Required total transition for a transient choice state. */
|
|
7356
6128
|
readonly choice: Transition<S, Src, ChoiceContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R>
|
|
7357
6129
|
/** Event handlers keyed by the public or internal event tag. */
|
|
7358
|
-
readonly on?:
|
|
6130
|
+
readonly on?: StateFieldError<"Choice", Src, "on", "Declare one transition in choice">
|
|
7359
6131
|
/** Eventless transition evaluated during stabilization. */
|
|
7360
|
-
readonly always?:
|
|
6132
|
+
readonly always?: StateFieldError<"Choice", Src, "always", "Declare one transition in choice">
|
|
7361
6133
|
/** Handles successful invocation or state completion with its exact output type. */
|
|
7362
|
-
readonly onDone?:
|
|
6134
|
+
readonly onDone?: StateFieldError<"Choice", Src, "onDone", "Declare one transition in choice">
|
|
7363
6135
|
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
7364
|
-
readonly invoke?:
|
|
6136
|
+
readonly invoke?: StateFieldError<"Choice", Src, "invoke", "Declare one transition in choice">
|
|
7365
6137
|
/** Child handlers nested according to the declared root topology. */
|
|
7366
6138
|
readonly states?: never
|
|
7367
6139
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
@@ -7369,15 +6141,15 @@ export declare namespace Machine {
|
|
|
7369
6141
|
}
|
|
7370
6142
|
: Src extends StateIdentifier<S> ? Node extends { readonly type: "final" } ? {
|
|
7371
6143
|
/** Event handlers keyed by the public or internal event tag. */
|
|
7372
|
-
readonly on?:
|
|
6144
|
+
readonly on?: StateFieldError<"Final", Src, "on", "A final state has no outgoing work">
|
|
7373
6145
|
/** Eventless transition evaluated during stabilization. */
|
|
7374
|
-
readonly always?:
|
|
6146
|
+
readonly always?: StateFieldError<"Final", Src, "always", "A final state has no outgoing work">
|
|
7375
6147
|
/** Handles successful invocation or state completion with its exact output type. */
|
|
7376
|
-
readonly onDone?:
|
|
6148
|
+
readonly onDone?: StateFieldError<"Final", Src, "onDone", "A final state has no outgoing work">
|
|
7377
6149
|
/** Required total transition for a transient choice state. */
|
|
7378
6150
|
readonly choice?: never
|
|
7379
6151
|
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
7380
|
-
readonly invoke?:
|
|
6152
|
+
readonly invoke?: StateFieldError<"Final", Src, "invoke", "A final state has no outgoing work">
|
|
7381
6153
|
/** Child handlers nested according to the declared root topology. */
|
|
7382
6154
|
readonly states?: never
|
|
7383
6155
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
@@ -7395,7 +6167,7 @@ export declare namespace Machine {
|
|
|
7395
6167
|
Em,
|
|
7396
6168
|
R,
|
|
7397
6169
|
true,
|
|
7398
|
-
|
|
6170
|
+
"declinable"
|
|
7399
6171
|
>
|
|
7400
6172
|
}
|
|
7401
6173
|
/** Eventless transition evaluated during stabilization. */
|
|
@@ -7407,7 +6179,7 @@ export declare namespace Machine {
|
|
|
7407
6179
|
Em,
|
|
7408
6180
|
R,
|
|
7409
6181
|
false,
|
|
7410
|
-
|
|
6182
|
+
"declinable"
|
|
7411
6183
|
>
|
|
7412
6184
|
/** Handles successful invocation or state completion with its exact output type. */
|
|
7413
6185
|
readonly onDone?: Transition<
|
|
@@ -7418,7 +6190,7 @@ export declare namespace Machine {
|
|
|
7418
6190
|
Em,
|
|
7419
6191
|
R,
|
|
7420
6192
|
false,
|
|
7421
|
-
|
|
6193
|
+
"required"
|
|
7422
6194
|
>
|
|
7423
6195
|
/** Required total transition for a transient choice state. */
|
|
7424
6196
|
readonly choice?: never
|
|
@@ -7444,9 +6216,163 @@ export declare namespace Machine {
|
|
|
7444
6216
|
readonly history?: never
|
|
7445
6217
|
}) :
|
|
7446
6218
|
never)
|
|
7447
|
-
type
|
|
6219
|
+
type LastOfUnion<U> = Types.UnionToIntersection<U extends unknown ? () => U : never> extends () => infer Last ? Last
|
|
6220
|
+
: never
|
|
6221
|
+
type JoinUnion<U extends string> = [U] extends [never] ? ""
|
|
6222
|
+
: LastOfUnion<U> extends infer Last extends string
|
|
6223
|
+
? [Exclude<U, Last>] extends [never] ? Last : `${JoinUnion<Exclude<U, Last>>}, ${Last}`
|
|
6224
|
+
: never
|
|
6225
|
+
type BranchEntryKey<Entry> = Entry extends
|
|
6226
|
+
{ readonly target: infer P extends string; readonly update: infer O extends string } ? `target:${P}+update:${O}`
|
|
6227
|
+
: Entry extends { readonly target: infer P extends string } ? `target:${P}`
|
|
6228
|
+
: Entry extends { readonly update: infer O extends string } ? `update:${O}`
|
|
6229
|
+
: Entry extends { readonly history: infer P extends string } ? `history:${P}`
|
|
6230
|
+
: Entry extends { readonly initialize: true } ? "initialize"
|
|
6231
|
+
: Entry extends { readonly stay: true } ? "stay"
|
|
6232
|
+
: Entry extends { readonly decline: true } ? "decline"
|
|
6233
|
+
: never
|
|
6234
|
+
type BranchLabel<Key extends string> = Key extends `target:${infer P}+update:${infer O}`
|
|
6235
|
+
? `{ target: "${P}", update: "${O}" }`
|
|
6236
|
+
: Key extends `target:${infer P}` ? `{ target: "${P}" }`
|
|
6237
|
+
: Key extends `update:${infer O}` ? `{ update: "${O}" }`
|
|
6238
|
+
: Key extends `history:${infer P}` ? `{ history: "${P}" }`
|
|
6239
|
+
: Key extends "initialize" | "stay" | "decline" ? `{ ${Key}: true }`
|
|
6240
|
+
: never
|
|
6241
|
+
type BranchEntryKeyAt<B extends ReadonlyArray<unknown>, K> = K extends keyof B ? BranchEntryKey<B[K]> : never
|
|
6242
|
+
type DuplicateBranchKey<B extends ReadonlyArray<unknown>, Indices extends keyof B = Extract<keyof B, `${number}`>> = {
|
|
6243
|
+
readonly [K in Indices]: BranchEntryKeyAt<B, K> extends BranchEntryKeyAt<B, Exclude<Indices, K>>
|
|
6244
|
+
? BranchEntryKeyAt<B, K>
|
|
6245
|
+
: never
|
|
6246
|
+
}[Indices]
|
|
6247
|
+
type SelectedBranchKey<Result> = Result extends SelectedBranch<infer Key, any> ? Key : never
|
|
6248
|
+
type ValidateBranchSelection<B extends ReadonlyArray<unknown>, Result> = number extends B["length"] ?
|
|
6249
|
+
{ readonly branches: "branches must list its entries inline" }
|
|
6250
|
+
: B["length"] extends 0 ? { readonly branches: "branches needs at least one entry" }
|
|
6251
|
+
: [DuplicateBranchKey<B>] extends [never] ?
|
|
6252
|
+
0 extends 1 & Result ? { readonly resolve: "resolve must return a select call, got any" }
|
|
6253
|
+
: unknown extends Result ? { readonly resolve: "resolve must return a select call, got unknown" }
|
|
6254
|
+
: [Exclude<Result, SelectedBranch<any, any>>] extends [never] ?
|
|
6255
|
+
[Exclude<SelectedBranchKey<Result>, BranchEntryKey<B[number]>>] extends [never] ?
|
|
6256
|
+
[Exclude<BranchEntryKey<B[number]>, SelectedBranchKey<Result>>] extends [never] ? unknown : {
|
|
6257
|
+
readonly branches: `Declared branch ${BranchLabel<
|
|
6258
|
+
Exclude<BranchEntryKey<B[number]>, SelectedBranchKey<Result>>
|
|
6259
|
+
> extends infer Label extends string ? JoinUnion<Label>
|
|
6260
|
+
: never} is never selected by resolve`
|
|
6261
|
+
}
|
|
6262
|
+
: {
|
|
6263
|
+
readonly resolve: `resolve selects undeclared ${BranchLabel<
|
|
6264
|
+
Exclude<SelectedBranchKey<Result>, BranchEntryKey<B[number]>>
|
|
6265
|
+
> extends infer Label extends string ? JoinUnion<Label>
|
|
6266
|
+
: never}. Add it to branches`
|
|
6267
|
+
}
|
|
6268
|
+
: { readonly resolve: "resolve must return a select call on every path" }
|
|
6269
|
+
: {
|
|
6270
|
+
readonly branches: `Declared branch ${BranchLabel<DuplicateBranchKey<B>> extends infer Label extends string
|
|
6271
|
+
? JoinUnion<Label>
|
|
6272
|
+
: never} appears more than once`
|
|
6273
|
+
}
|
|
6274
|
+
type ValidateBranches<T> = T extends { readonly branches: infer B extends ReadonlyArray<unknown> } ?
|
|
6275
|
+
T extends { readonly resolve: (...args: any[]) => infer Result } ? ValidateBranchSelection<B, Result>
|
|
6276
|
+
: { readonly branches: "branches needs a resolve that selects one of them" }
|
|
6277
|
+
: T extends { readonly resolve: unknown } ?
|
|
6278
|
+
{ readonly resolve: "resolve needs a branches list. Add: branches: [...]" }
|
|
6279
|
+
: unknown
|
|
6280
|
+
type UpdatableNames<S extends StateSchemas, Src extends string, T> = T extends {
|
|
6281
|
+
readonly target: infer Target extends string
|
|
6282
|
+
} ? PathName<TargetOwner<S, Extract<Src, StateNodeIdentifier<S>>, PathOf<Target>>>
|
|
6283
|
+
: PathName<UpdatableOwner<S, Extract<Src, StateNodeIdentifier<S>>>>
|
|
6284
|
+
type ValidateOwnerNames<U, Allowed extends string> = [Exclude<keyof U, Allowed>] extends [never] ? unknown : {
|
|
6285
|
+
readonly update: `Cannot update "${JoinUnion<Extract<Exclude<keyof U, Allowed>, string>>}". ${[Allowed] extends
|
|
6286
|
+
[never] ? "No retained state can be updated here"
|
|
6287
|
+
: `Updatable here: ${JoinUnion<Allowed>}`}`
|
|
6288
|
+
}
|
|
6289
|
+
type ValidateUpdateOwners<T, S extends StateSchemas, Src extends string> = T extends { readonly update: infer U } ?
|
|
6290
|
+
Types.IsUnion<keyof U> extends true ?
|
|
6291
|
+
{ readonly update: `update takes one owner, got: ${JoinUnion<Extract<keyof U, string>>}` }
|
|
6292
|
+
: [keyof U] extends [never] ? { readonly update: "update takes one owner, got none" }
|
|
6293
|
+
:
|
|
6294
|
+
& ValidateOwnerNames<U, UpdatableNames<S, Src, T>>
|
|
6295
|
+
& (T extends { readonly reenter: true } ? keyof U extends PathName<Src> ? {
|
|
6296
|
+
readonly reenter: `Cannot reenter "${PathName<Src>}" while updating it. Update it or reenter it`
|
|
6297
|
+
} :
|
|
6298
|
+
unknown :
|
|
6299
|
+
unknown)
|
|
6300
|
+
: unknown
|
|
6301
|
+
type ValidateCommands<T> = T extends { readonly commands: (...args: any[]) => infer Result } ?
|
|
6302
|
+
[Result] extends [void | undefined] ? unknown
|
|
6303
|
+
: { readonly commands: "commands must not return a value. Enqueue work with its second argument" }
|
|
6304
|
+
: unknown
|
|
6305
|
+
type DestinationNames<S extends StateSchemas> = ReferenceUnion<S, Exclude<DestinationPath<S>, HistoryIdentifier<S>>>
|
|
6306
|
+
type UnknownTargetMessage<P extends string, S extends StateSchemas> = P extends "root"
|
|
6307
|
+
? `Cannot target "root". Reconstruct it with initialize, or update it with update: { root: ... }`
|
|
6308
|
+
: P extends ReferenceUnion<S, HistoryIdentifier<S>> ?
|
|
6309
|
+
`"${P}" is a history state. Restore it with: { history: "${P}" }`
|
|
6310
|
+
: `Unknown target "${P}". Declared: ${JoinUnion<DestinationNames<S>>}`
|
|
6311
|
+
// A property-level message would collapse with the declared literal to `never`, so these replace the whole value.
|
|
6312
|
+
type ValidateTarget<T, S extends StateSchemas, Src extends string> = T extends {
|
|
6313
|
+
readonly target: infer P extends string
|
|
6314
|
+
} ? string extends P ? unknown
|
|
6315
|
+
: P extends DestinationNames<S> ? ValidateTargetAncestors<S, Src, P> & ValidateTargetData<T, S, P>
|
|
6316
|
+
: UnknownTargetMessage<P, S>
|
|
6317
|
+
: unknown
|
|
6318
|
+
// A known target also matches the misspelled-target member, which cannot require its values.
|
|
6319
|
+
type ValidateTargetData<T, S extends StateSchemas, P extends string> = "data" extends keyof T ? unknown
|
|
6320
|
+
: PathOf<P> extends infer Id extends StateIdentifier<S> ?
|
|
6321
|
+
[NodeSchema<NodeByIdentifier<S, Id>>] extends [never] ? unknown
|
|
6322
|
+
: {} extends NodeMakeInput<NodeByIdentifier<S, Id>> ? unknown
|
|
6323
|
+
: `Target "${P}" requires data`
|
|
6324
|
+
: unknown
|
|
6325
|
+
// Entering below an inactive valued state has no value for it, so that state must be the target. Anything below the
|
|
6326
|
+
// source or a parallel state may already be active, so only a state that is certainly inactive is reported here.
|
|
6327
|
+
type HasParallelAncestor<S extends StateSchemas, Id extends string> = true extends {
|
|
6328
|
+
[A in Extract<ParentStateIdentifier<Id>, StateIdentifier<S>>]: NodeByIdentifier<S, A> extends
|
|
6329
|
+
{ readonly type: "parallel" } ? true : false
|
|
6330
|
+
}[Extract<ParentStateIdentifier<Id>, StateIdentifier<S>>] ? true :
|
|
6331
|
+
false
|
|
6332
|
+
type InactiveValuedAncestor<S extends StateSchemas, Src extends string, P extends string> = {
|
|
6333
|
+
[
|
|
6334
|
+
A in Exclude<
|
|
6335
|
+
Extract<ParentStateIdentifier<PathOf<P>>, ValuedStateIdentifier<S>>,
|
|
6336
|
+
Src | ParentStateIdentifier<Src> | JoinPath<Src, string>
|
|
6337
|
+
>
|
|
6338
|
+
]: HasParallelAncestor<S, A> extends true ? never : A
|
|
6339
|
+
}[
|
|
6340
|
+
Exclude<
|
|
6341
|
+
Extract<ParentStateIdentifier<PathOf<P>>, ValuedStateIdentifier<S>>,
|
|
6342
|
+
Src | ParentStateIdentifier<Src> | JoinPath<Src, string>
|
|
6343
|
+
>
|
|
6344
|
+
]
|
|
6345
|
+
type ValidateTargetAncestors<S extends StateSchemas, Src extends string, P extends string> =
|
|
6346
|
+
[InactiveValuedAncestor<S, Src, P>] extends [never] ? unknown :
|
|
6347
|
+
`Target "${P}" enters "${JoinUnion<
|
|
6348
|
+
PathName<InactiveValuedAncestor<S, Src, P>>
|
|
6349
|
+
>}", which needs a value. Target that state and construct "${P}" with states`
|
|
6350
|
+
type ValidateBranchEntries<T, S extends StateSchemas, Src extends string> = T extends {
|
|
6351
|
+
readonly branches: infer B extends ReadonlyArray<unknown>
|
|
6352
|
+
} ? {
|
|
6353
|
+
readonly branches: {
|
|
6354
|
+
readonly [K in keyof B]:
|
|
6355
|
+
& (B[K] extends { readonly target: infer P extends string } ?
|
|
6356
|
+
P extends DestinationNames<S> ? ValidateTargetAncestors<S, Src, P> : UnknownTargetMessage<P, S>
|
|
6357
|
+
: unknown)
|
|
6358
|
+
& (B[K] extends { readonly update: infer O extends string } ? O extends UpdatableNames<S, Src, B[K]> ? unknown
|
|
6359
|
+
: `Cannot update "${O}". ${[UpdatableNames<S, Src, B[K]>] extends [never] ?
|
|
6360
|
+
"No retained state can be updated here"
|
|
6361
|
+
: `Updatable here: ${JoinUnion<UpdatableNames<S, Src, B[K]>>}`}` :
|
|
6362
|
+
unknown)
|
|
6363
|
+
}
|
|
6364
|
+
}
|
|
6365
|
+
: unknown
|
|
6366
|
+
type ValidateDestination<T> = Extract<
|
|
6367
|
+
keyof T,
|
|
6368
|
+
"target" | "update" | "initialize" | "history" | "stay" | "branches" | "resolve"
|
|
6369
|
+
> extends never ? T extends { readonly reenter: true } ? unknown : {
|
|
6370
|
+
readonly target: "A transition needs one of: target, update, initialize, history, stay, reenter: true, branches"
|
|
6371
|
+
}
|
|
6372
|
+
: unknown
|
|
6373
|
+
type ValidateObjectTransition<T, S extends StateSchemas, Src extends string> =
|
|
7448
6374
|
& ("initialize" extends keyof T ? {
|
|
7449
|
-
readonly [K in Exclude<keyof T, "initialize" | "guard" | "reenter">]: never
|
|
6375
|
+
readonly [K in Exclude<keyof T, "initialize" | "guard" | "reenter" | "commands">]: never
|
|
7450
6376
|
}
|
|
7451
6377
|
: unknown)
|
|
7452
6378
|
& {
|
|
@@ -7457,38 +6383,23 @@ export declare namespace Machine {
|
|
|
7457
6383
|
| "update"
|
|
7458
6384
|
| "initialize"
|
|
7459
6385
|
| "history"
|
|
7460
|
-
| "
|
|
6386
|
+
| "stay"
|
|
7461
6387
|
| "branches"
|
|
7462
6388
|
| "data"
|
|
7463
6389
|
| "decoded"
|
|
7464
6390
|
| "resolve"
|
|
7465
6391
|
| "guard"
|
|
7466
6392
|
| "reenter"
|
|
7467
|
-
| "
|
|
6393
|
+
| "commands"
|
|
7468
6394
|
>
|
|
7469
6395
|
]: never
|
|
7470
6396
|
}
|
|
7471
|
-
&
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
} :
|
|
7478
|
-
unknown
|
|
7479
|
-
: unknown)
|
|
7480
|
-
& (T extends {
|
|
7481
|
-
/** Set to true when the resolver can explicitly return decline(). */
|
|
7482
|
-
readonly declinable: true
|
|
7483
|
-
} ? unknown
|
|
7484
|
-
: T extends {
|
|
7485
|
-
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
7486
|
-
readonly resolve: (...args: any[]) => infer Result
|
|
7487
|
-
} ? [Extract<Result, Declined>] extends [never] ? unknown : {
|
|
7488
|
-
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
7489
|
-
readonly resolve: never
|
|
7490
|
-
}
|
|
7491
|
-
: unknown)
|
|
6397
|
+
& ValidateDestination<T>
|
|
6398
|
+
& ValidateTarget<T, S, Src>
|
|
6399
|
+
& ValidateBranches<T>
|
|
6400
|
+
& ValidateBranchEntries<T, S, Src>
|
|
6401
|
+
& ValidateUpdateOwners<T, S, Src>
|
|
6402
|
+
& ValidateCommands<T>
|
|
7492
6403
|
type AllowedInvokeChannels<R, K extends PropertyKey> =
|
|
7493
6404
|
| ([InvokeOutput<ResolvedInvoke<R, K>>] extends [never] ? never : "onDone")
|
|
7494
6405
|
| ([RegisteredInvokeError<R, K>] extends [never] ? never : "onFailure")
|
|
@@ -7519,28 +6430,43 @@ export declare namespace Machine {
|
|
|
7519
6430
|
[Id] extends [never] ? never
|
|
7520
6431
|
: Id extends LiteralInvokeIdAt<I, Exclude<Extract<keyof I, `${number}`>, K>, R> ? Id
|
|
7521
6432
|
: never
|
|
7522
|
-
: never
|
|
7523
|
-
type ValidateInvokeEntry<I, R, Duplicate extends string, Root
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7531
|
-
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
6433
|
+
: never
|
|
6434
|
+
type ValidateInvokeEntry<I, R, Duplicate extends string, Root, S extends StateSchemas, Path extends string> =
|
|
6435
|
+
I extends {
|
|
6436
|
+
/** Name of the source registered in make. */
|
|
6437
|
+
readonly src: infer Src extends PropertyKey
|
|
6438
|
+
} ? Src extends SourceKeys<R> ? {
|
|
6439
|
+
readonly [K in keyof I]: [Duplicate] extends [never] ?
|
|
6440
|
+
ValidateInvokeField<I, K, R, Extract<Src, string>, Root, S, Path>
|
|
6441
|
+
: K extends ("id" extends keyof I ? "id" : "src") ? InvocationDefinitionError<
|
|
6442
|
+
`Invocation id '${Duplicate}' is declared more than once in this state`,
|
|
6443
|
+
Extract<Src, string>,
|
|
6444
|
+
K
|
|
6445
|
+
>
|
|
6446
|
+
: ValidateInvokeField<I, K, R, Extract<Src, string>, Root, S, Path>
|
|
6447
|
+
}
|
|
6448
|
+
: UnknownSourceMessage<R>
|
|
6449
|
+
: never
|
|
6450
|
+
type ValidateInvokeField<
|
|
6451
|
+
I,
|
|
6452
|
+
K extends keyof I,
|
|
6453
|
+
R,
|
|
6454
|
+
Src extends string,
|
|
6455
|
+
Root,
|
|
6456
|
+
S extends StateSchemas,
|
|
6457
|
+
Path extends string
|
|
6458
|
+
> = K extends AllowedInvokeChannels<R, Src> ?
|
|
6459
|
+
ValidateObjectTransition<I[K], S, Path> & ValidateChoiceUpdate<I[K], Root>
|
|
7538
6460
|
: K extends "src" | "id" | "address" | "input" ? unknown
|
|
7539
6461
|
: InvokeFieldError<K, Src>
|
|
7540
|
-
type
|
|
7541
|
-
|
|
7542
|
-
:
|
|
7543
|
-
|
|
6462
|
+
type UnknownSourceMessage<R> = [Extract<SourceKeys<R>, string>] extends [never]
|
|
6463
|
+
? "Unknown source. Register it in make with effects, streams, timers, logic, or children"
|
|
6464
|
+
: `Unknown source. Registered: ${JoinUnion<Extract<SourceKeys<R>, string>>}`
|
|
6465
|
+
type ValidateObjectInvoke<I, R, Root, S extends StateSchemas, Path extends string> = I extends
|
|
6466
|
+
ReadonlyArray<unknown> ?
|
|
6467
|
+
number extends I["length"] ? { readonly [K in keyof I]: ValidateInvokeEntry<I[K], R, never, Root, S, Path> }
|
|
6468
|
+
: { readonly [K in keyof I]: ValidateInvokeEntry<I[K], R, DuplicateInvokeId<I, K, R>, Root, S, Path> } :
|
|
6469
|
+
ValidateInvokeEntry<I, R, never, Root, S, Path>
|
|
7544
6470
|
// Handler config of a dotted state path, read from the root handler config.
|
|
7545
6471
|
type HandlerConfigAt<Config, Path extends string> = Config extends { readonly states: infer Children } ?
|
|
7546
6472
|
Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Children ? HandlerConfigAt<Children[Head], Rest>
|
|
@@ -7553,15 +6479,15 @@ export declare namespace Machine {
|
|
|
7553
6479
|
readonly choice: infer Choice
|
|
7554
6480
|
} ? Choice
|
|
7555
6481
|
: never
|
|
7556
|
-
type ChoiceBranchDeclaration<Choice
|
|
7557
|
-
/**
|
|
7558
|
-
readonly branches: infer
|
|
7559
|
-
} ? {
|
|
7560
|
-
|
|
7561
|
-
|
|
7562
|
-
|
|
7563
|
-
|
|
7564
|
-
|
|
6482
|
+
type ChoiceBranchDeclaration<Choice> = Choice extends {
|
|
6483
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
6484
|
+
readonly branches: infer B extends ReadonlyArray<unknown>
|
|
6485
|
+
} ? B[number] extends infer Entry ? Entry extends unknown ? {
|
|
6486
|
+
readonly label: `branch ${BranchLabel<BranchEntryKey<Entry>>}`
|
|
6487
|
+
readonly declaration: Entry
|
|
6488
|
+
}
|
|
6489
|
+
: never
|
|
6490
|
+
: never
|
|
7565
6491
|
: { readonly label: "transition"; readonly declaration: Choice }
|
|
7566
6492
|
type IsBelowOwner<Path extends string, Owner extends string> = Owner extends "" ? Path extends "" ? false : true
|
|
7567
6493
|
: Path extends `${Owner}.${string}` ? true
|
|
@@ -7573,15 +6499,15 @@ export declare namespace Machine {
|
|
|
7573
6499
|
PathName<Path>
|
|
7574
6500
|
>
|
|
7575
6501
|
// Every branch reachable from a choice entered with an owner update must stay below that owner.
|
|
7576
|
-
type ChoiceUpdateEscape<Root,
|
|
6502
|
+
type ChoiceUpdateEscape<Root, Choice extends string, Owner extends string, Visited extends string = never> =
|
|
7577
6503
|
Choice extends Visited ? never
|
|
7578
|
-
: ChoiceBranchDeclaration<ChoiceConfigAt<Root, Choice
|
|
6504
|
+
: ChoiceBranchDeclaration<ChoiceConfigAt<Root, Choice>> extends infer Branch ?
|
|
7579
6505
|
Branch extends { readonly label: infer Label extends string; readonly declaration: infer D } ? D extends {
|
|
7580
|
-
/** Selects a declared descendant
|
|
6506
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
7581
6507
|
readonly target: infer Ref extends string
|
|
7582
6508
|
} ?
|
|
7583
6509
|
[ChoiceConfigAt<Root, PathOf<Ref>>] extends [never] ? ChoiceBranchEscape<PathOf<Ref>, Owner, Choice, Label>
|
|
7584
|
-
: ChoiceUpdateEscape<Root,
|
|
6510
|
+
: ChoiceUpdateEscape<Root, PathOf<Ref>, Owner, Visited | Choice>
|
|
7585
6511
|
: D extends {
|
|
7586
6512
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
7587
6513
|
readonly history: infer Ref extends string
|
|
@@ -7593,26 +6519,25 @@ export declare namespace Machine {
|
|
|
7593
6519
|
: never
|
|
7594
6520
|
: never
|
|
7595
6521
|
: never
|
|
7596
|
-
type
|
|
7597
|
-
|
|
6522
|
+
type OwnerNameOf<Update> = Update extends string ? Update : Extract<keyof Update, string>
|
|
6523
|
+
type ChoiceUpdateEscapeOf<D, Root> = D extends {
|
|
6524
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
7598
6525
|
readonly target: infer Ref extends string
|
|
7599
|
-
/** Replaces the
|
|
7600
|
-
readonly update: infer
|
|
6526
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
6527
|
+
readonly update: infer Update
|
|
7601
6528
|
} ? [ChoiceConfigAt<Root, PathOf<Ref>>] extends [never] ? never
|
|
7602
|
-
: ChoiceUpdateEscape<Root,
|
|
6529
|
+
: ChoiceUpdateEscape<Root, PathOf<Ref>, PathOf<OwnerNameOf<Update>>>
|
|
7603
6530
|
: never
|
|
7604
|
-
type ValidateChoiceUpdate<T,
|
|
7605
|
-
/**
|
|
7606
|
-
readonly branches: infer
|
|
7607
|
-
} ? {
|
|
7608
|
-
|
|
7609
|
-
}[keyof Registered<R, "branches">[G]] extends infer Escape ? [Escape] extends [never] ? unknown : {
|
|
7610
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
6531
|
+
type ValidateChoiceUpdate<T, Root> = T extends {
|
|
6532
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
6533
|
+
readonly branches: infer B extends ReadonlyArray<unknown>
|
|
6534
|
+
} ? ChoiceUpdateEscapeOf<B[number], Root> extends infer Escape ? [Escape] extends [never] ? unknown : {
|
|
6535
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
7611
6536
|
readonly branches: Escape
|
|
7612
6537
|
}
|
|
7613
6538
|
: never
|
|
7614
|
-
: ChoiceUpdateEscapeOf<T,
|
|
7615
|
-
/** Replaces the
|
|
6539
|
+
: ChoiceUpdateEscapeOf<T, Root> extends infer Escape ? [Escape] extends [never] ? unknown : {
|
|
6540
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
7616
6541
|
readonly update: Escape
|
|
7617
6542
|
}
|
|
7618
6543
|
: never
|
|
@@ -7621,16 +6546,21 @@ export declare namespace Machine {
|
|
|
7621
6546
|
| (C extends { readonly states: infer Children }
|
|
7622
6547
|
? { readonly [K in keyof Children]: ObjectDeclarations<Children[K]> }[keyof Children]
|
|
7623
6548
|
: never)
|
|
7624
|
-
type ValidateObjectConfig<C, R,
|
|
7625
|
-
|
|
7626
|
-
: K extends "
|
|
7627
|
-
readonly [P in keyof C[K]]:
|
|
6549
|
+
type ValidateObjectConfig<C, R, S extends StateSchemas, Path extends string = "", Root = C> =
|
|
6550
|
+
[ObjectDeclarations<C>] extends [never] ? unknown : {
|
|
6551
|
+
readonly [K in keyof C]: K extends "states" ? {
|
|
6552
|
+
readonly [P in keyof C[K]]: ValidateObjectConfig<C[K][P], R, S, JoinPath<Path, Extract<P, string>>, Root>
|
|
7628
6553
|
}
|
|
7629
|
-
|
|
7630
|
-
|
|
7631
|
-
|
|
7632
|
-
|
|
7633
|
-
|
|
6554
|
+
: K extends "on" ? {
|
|
6555
|
+
readonly [P in keyof C[K]]:
|
|
6556
|
+
& ValidateObjectTransition<C[K][P], S, Path>
|
|
6557
|
+
& ValidateChoiceUpdate<C[K][P], Root>
|
|
6558
|
+
}
|
|
6559
|
+
: K extends "always" | "onDone" ? ValidateObjectTransition<C[K], S, Path> & ValidateChoiceUpdate<C[K], Root>
|
|
6560
|
+
: K extends "choice" ? ValidateObjectTransition<C[K], S, Path>
|
|
6561
|
+
: K extends "invoke" ? ValidateObjectInvoke<C[K], R, Root, S, Path>
|
|
6562
|
+
: unknown
|
|
6563
|
+
}
|
|
7634
6564
|
type NormalizeObjectInvoke<I, R> = I extends ReadonlyArray<unknown> ?
|
|
7635
6565
|
{ readonly [K in keyof I]: NormalizeObjectInvoke<I[K], R> }
|
|
7636
6566
|
: I extends {
|
|
@@ -7645,13 +6575,19 @@ export declare namespace Machine {
|
|
|
7645
6575
|
}
|
|
7646
6576
|
// Reverse-map authored fields to avoid expanding every possible transition.
|
|
7647
6577
|
// Retain missing fields from H for required handlers and editor completion.
|
|
7648
|
-
|
|
6578
|
+
// Intersecting a misspelled `src` with its declared literals is `never`, so that invocation takes the message instead.
|
|
6579
|
+
type InvokeShape<I, H, R> = I extends ReadonlyArray<{ readonly src: infer Src }> ?
|
|
6580
|
+
[Exclude<Src, SourceKeys<R>>] extends [never] ? H : UnknownSourceMessage<R>
|
|
6581
|
+
: I extends { readonly src: infer Src } ? [Src] extends [SourceKeys<R>] ? H : UnknownSourceMessage<R>
|
|
6582
|
+
: H
|
|
6583
|
+
type HandlerShape<C, H, R> =
|
|
7649
6584
|
& {
|
|
7650
6585
|
readonly [K in keyof C]: K extends keyof H ? K extends "states" ? {
|
|
7651
6586
|
readonly [P in keyof C[K]]: P extends keyof NonNullable<H[K]>
|
|
7652
|
-
? HandlerShape<C[K][P], NonNullable<NonNullable<H[K]>[P]
|
|
6587
|
+
? HandlerShape<C[K][P], NonNullable<NonNullable<H[K]>[P]>, R>
|
|
7653
6588
|
: never
|
|
7654
6589
|
}
|
|
6590
|
+
: K extends "invoke" ? InvokeShape<C[K], H[K], R>
|
|
7655
6591
|
: H[K]
|
|
7656
6592
|
: never
|
|
7657
6593
|
}
|
|
@@ -7675,17 +6611,21 @@ export declare namespace Machine {
|
|
|
7675
6611
|
Pa extends ReadonlyArray<TaggedSchema>,
|
|
7676
6612
|
R
|
|
7677
6613
|
> {
|
|
6614
|
+
// Returns Machine itself: an alias would keep the handler config as a type
|
|
6615
|
+
// argument, so exported declarations would print every handler's context.
|
|
7678
6616
|
<const C>(
|
|
7679
6617
|
config:
|
|
7680
6618
|
& C
|
|
7681
6619
|
& (C extends (...args: never[]) => unknown ? never : unknown)
|
|
6620
|
+
// Checked first, so an invalid declaration reports the message that names its fix.
|
|
6621
|
+
& ValidateObjectConfig<NoInfer<C>, R, S>
|
|
7682
6622
|
& HandlerShape<
|
|
7683
6623
|
C,
|
|
7684
6624
|
& StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R & { readonly "~input": I }>
|
|
7685
|
-
& RootConstruction<S[""], I["Type"]
|
|
6625
|
+
& RootConstruction<S[""], I["Type"]>,
|
|
6626
|
+
R
|
|
7686
6627
|
>
|
|
7687
6628
|
& RootConstruction<S[""], I["Type"]>
|
|
7688
|
-
& ValidateObjectConfig<NoInfer<C>, R>
|
|
7689
6629
|
& RootHandlerValidation<
|
|
7690
6630
|
S,
|
|
7691
6631
|
Ev,
|
|
@@ -7697,22 +6637,25 @@ export declare namespace Machine {
|
|
|
7697
6637
|
StateIdentifier<S>
|
|
7698
6638
|
>
|
|
7699
6639
|
>
|
|
7700
|
-
):
|
|
6640
|
+
): Machine<
|
|
7701
6641
|
S,
|
|
7702
6642
|
Ev,
|
|
7703
|
-
Em,
|
|
7704
6643
|
I,
|
|
7705
|
-
StateIdentifier<S>,
|
|
7706
|
-
|
|
7707
|
-
|
|
6644
|
+
Exclude<StateIdentifier<S>, HandleEvidence<S, C, R>["stateId"]>,
|
|
6645
|
+
HandleEvidence<S, C, R>["error"],
|
|
6646
|
+
ExcludeCompatibleRuntime<
|
|
6647
|
+
HandleEvidence<S, C, R>["services"],
|
|
6648
|
+
EventOf<Ev>,
|
|
6649
|
+
EmittedEventOf<Em>
|
|
6650
|
+
>,
|
|
7708
6651
|
IE,
|
|
7709
6652
|
IR,
|
|
7710
6653
|
Final,
|
|
7711
6654
|
Out,
|
|
7712
|
-
|
|
6655
|
+
Em,
|
|
6656
|
+
Extract<HandleEvidence<S, C, R>["outputState"], StateIdentifier<S>>,
|
|
7713
6657
|
In,
|
|
7714
|
-
Pa
|
|
7715
|
-
{ readonly "": NormalizeObjectConfig<C, R> }
|
|
6658
|
+
Pa
|
|
7716
6659
|
>
|
|
7717
6660
|
}
|
|
7718
6661
|
|
|
@@ -7810,27 +6753,9 @@ export declare namespace Machine {
|
|
|
7810
6753
|
readonly on?: EventHandlerMap<States, Events, Emits, StateId, EventTag, E, R>
|
|
7811
6754
|
}
|
|
7812
6755
|
|
|
7813
|
-
|
|
7814
|
-
|
|
7815
|
-
|
|
7816
|
-
* @category models
|
|
7817
|
-
* @since 0.4.0
|
|
7818
|
-
*/
|
|
7819
|
-
export type StateConfigs<
|
|
7820
|
-
States extends StateSchemas,
|
|
7821
|
-
Events extends ReadonlyArray<TaggedSchema>,
|
|
7822
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
7823
|
-
StateId extends StateIdentifier<States>,
|
|
7824
|
-
EventTag extends TagOf<Events[number]>,
|
|
7825
|
-
E,
|
|
7826
|
-
R
|
|
7827
|
-
> = Readonly<
|
|
7828
|
-
Record<
|
|
7829
|
-
PropertyKey,
|
|
7830
|
-
| StateConfig<States, Events, Emits, StateId, EventTag, E, R>
|
|
7831
|
-
| ChoiceStateConfig<States, Events, Emits, ChoiceIdentifier<States>>
|
|
7832
|
-
>
|
|
7833
|
-
>
|
|
6756
|
+
// An explicit export makes this ambient namespace export only the members marked `export`; the rest stay private.
|
|
6757
|
+
// oxlint-disable-next-line typescript/no-useless-empty-export -- the rule assumes module scope.
|
|
6758
|
+
export {}
|
|
7834
6759
|
}
|
|
7835
6760
|
|
|
7836
6761
|
type StateSource = State<any> | Machine.Any
|
|
@@ -7877,8 +6802,8 @@ export declare namespace Snapshot {
|
|
|
7877
6802
|
/**
|
|
7878
6803
|
* Extracts the decoded value owned by a schema-backed state path.
|
|
7879
6804
|
*
|
|
7880
|
-
* The source may be
|
|
7881
|
-
*
|
|
6805
|
+
* The source may be a descriptor returned by {@link state} or a machine.
|
|
6806
|
+
* Control-only state paths are intentionally excluded.
|
|
7882
6807
|
*
|
|
7883
6808
|
* @category utility types
|
|
7884
6809
|
* @since 0.18.0
|
|
@@ -7891,9 +6816,8 @@ export type Value<
|
|
|
7891
6816
|
/**
|
|
7892
6817
|
* Extracts the logical snapshot rooted at a state path.
|
|
7893
6818
|
*
|
|
7894
|
-
* The source may be
|
|
7895
|
-
*
|
|
7896
|
-
* `State.getSnapshot`.
|
|
6819
|
+
* The source may be a descriptor returned by {@link state} or a machine.
|
|
6820
|
+
* This is the type-level counterpart of a descriptor's `getSnapshot`.
|
|
7897
6821
|
*
|
|
7898
6822
|
* @category utility types
|
|
7899
6823
|
* @since 0.18.0
|
|
@@ -7959,16 +6883,13 @@ export const isFinal: <
|
|
|
7959
6883
|
* can be declared inline or reused by mounting a descriptor in multiple places.
|
|
7960
6884
|
* Initial edges and value constructors belong in the handler tree.
|
|
7961
6885
|
*
|
|
7962
|
-
* **Example** (
|
|
6886
|
+
* **Example** (Reusing one subtree in two parallel regions)
|
|
7963
6887
|
*
|
|
7964
|
-
* ```ts
|
|
6888
|
+
* ```ts import.meta.vitest
|
|
7965
6889
|
* import { Machine } from "@typeonce/effect-machine"
|
|
7966
|
-
* import { Schema } from "effect"
|
|
6890
|
+
* import { Effect, Schema } from "effect"
|
|
7967
6891
|
*
|
|
7968
|
-
* const TradingState = Schema.TaggedUnion({
|
|
7969
|
-
* InSession: {},
|
|
7970
|
-
* Applying: {}
|
|
7971
|
-
* })
|
|
6892
|
+
* const TradingState = Schema.TaggedUnion({ InSession: {}, Applying: {} })
|
|
7972
6893
|
* const TradingSlot = Machine.state({
|
|
7973
6894
|
* states: {
|
|
7974
6895
|
* Idle: {},
|
|
@@ -7976,13 +6897,21 @@ export const isFinal: <
|
|
|
7976
6897
|
* Applying: TradingState.cases.Applying
|
|
7977
6898
|
* }
|
|
7978
6899
|
* })
|
|
6900
|
+
* const States = Machine.state({ type: "parallel", states: { slot1: TradingSlot, slot2: TradingSlot } })
|
|
7979
6901
|
*
|
|
7980
|
-
* const
|
|
6902
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
7981
6903
|
* states: {
|
|
7982
|
-
* slot1:
|
|
7983
|
-
* slot2:
|
|
6904
|
+
* slot1: { initial: { target: "slot1.Idle" } },
|
|
6905
|
+
* slot2: { initial: { target: "slot2.Idle" } }
|
|
7984
6906
|
* }
|
|
7985
6907
|
* })
|
|
6908
|
+
*
|
|
6909
|
+
* const paths = Effect.map(Machine.planInitial(machine), ({ state }) => [
|
|
6910
|
+
* state.states.slot1.state.path,
|
|
6911
|
+
* state.states.slot2.state.path
|
|
6912
|
+
* ])
|
|
6913
|
+
*
|
|
6914
|
+
* await Effect.runPromise(paths) // => ["slot1.Idle", "slot2.Idle"]
|
|
7986
6915
|
* ```
|
|
7987
6916
|
*
|
|
7988
6917
|
* @category constructors
|
|
@@ -8014,8 +6943,7 @@ type MakeConfig<
|
|
|
8014
6943
|
Streams extends Machine.StreamSources,
|
|
8015
6944
|
Timers extends Machine.TimerSources,
|
|
8016
6945
|
Logics extends Machine.LogicSources,
|
|
8017
|
-
Children extends Machine.ChildSources
|
|
8018
|
-
Branches extends Machine.BranchDefinitions<Root>
|
|
6946
|
+
Children extends Machine.ChildSources
|
|
8019
6947
|
> = {
|
|
8020
6948
|
/** Lazy Effects or functions with one required input, invoked by registered name. */
|
|
8021
6949
|
readonly effects?: Effects & Machine.ValidatePrograms<Effects>
|
|
@@ -8027,10 +6955,6 @@ type MakeConfig<
|
|
|
8027
6955
|
readonly logic?: Logics & Machine.ValidatePrograms<Logics> & Machine.ValidateLogicSources<NoInfer<Logics>>
|
|
8028
6956
|
/** Child machine descriptors registered for state-owned invocation. */
|
|
8029
6957
|
readonly children?: Children
|
|
8030
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
8031
|
-
readonly branches?:
|
|
8032
|
-
& Branches
|
|
8033
|
-
& { readonly [K in keyof Branches]: ValidateTransitionBranchRecord<NoInfer<Branches[K]>> }
|
|
8034
6958
|
/** Stable definition identifier used by inspection and visualization. */
|
|
8035
6959
|
readonly id?: string
|
|
8036
6960
|
/** State topology and value schemas, captured by a `Machine.state` descriptor. */
|
|
@@ -8069,8 +6993,7 @@ type MakeResult<
|
|
|
8069
6993
|
Streams extends Machine.StreamSources,
|
|
8070
6994
|
Timers extends Machine.TimerSources,
|
|
8071
6995
|
Logics extends Machine.LogicSources,
|
|
8072
|
-
Children extends Machine.ChildSources
|
|
8073
|
-
Branches extends Readonly<Record<string, Readonly<Record<string, unknown>>>>
|
|
6996
|
+
Children extends Machine.ChildSources
|
|
8074
6997
|
> = Definition<
|
|
8075
6998
|
{ readonly "": Root },
|
|
8076
6999
|
readonly [...InputEvents, ...InternalEvents],
|
|
@@ -8093,13 +7016,11 @@ type MakeResult<
|
|
|
8093
7016
|
readonly logic: Logics
|
|
8094
7017
|
/** Child machine descriptors registered for state-owned invocation. */
|
|
8095
7018
|
readonly children: Children
|
|
8096
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
8097
|
-
readonly branches: Branches
|
|
8098
7019
|
}
|
|
8099
7020
|
>
|
|
8100
7021
|
|
|
8101
7022
|
/** @inline */
|
|
8102
|
-
|
|
7023
|
+
type Make = {
|
|
8103
7024
|
/** @param config Complete schema-first machine definition. */
|
|
8104
7025
|
<
|
|
8105
7026
|
const Root extends Machine.StateNodeConfig,
|
|
@@ -8114,8 +7035,7 @@ interface Make {
|
|
|
8114
7035
|
const Streams extends Machine.StreamSources = {},
|
|
8115
7036
|
const Timers extends Machine.TimerSources = {},
|
|
8116
7037
|
const Logics extends Machine.LogicSources = {},
|
|
8117
|
-
const Children extends Machine.ChildSources = {}
|
|
8118
|
-
const Branches extends Machine.BranchDefinitions<NoInfer<Root>> = {}
|
|
7038
|
+
const Children extends Machine.ChildSources = {}
|
|
8119
7039
|
>(
|
|
8120
7040
|
config:
|
|
8121
7041
|
& MakeConfig<
|
|
@@ -8131,8 +7051,7 @@ interface Make {
|
|
|
8131
7051
|
Streams,
|
|
8132
7052
|
Timers,
|
|
8133
7053
|
Logics,
|
|
8134
|
-
Children
|
|
8135
|
-
Branches
|
|
7054
|
+
Children
|
|
8136
7055
|
>
|
|
8137
7056
|
& UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>>
|
|
8138
7057
|
): MakeResult<
|
|
@@ -8148,8 +7067,7 @@ interface Make {
|
|
|
8148
7067
|
Streams,
|
|
8149
7068
|
Timers,
|
|
8150
7069
|
Logics,
|
|
8151
|
-
Children
|
|
8152
|
-
Branches
|
|
7070
|
+
Children
|
|
8153
7071
|
>
|
|
8154
7072
|
}
|
|
8155
7073
|
|
|
@@ -8158,16 +7076,16 @@ interface Make {
|
|
|
8158
7076
|
*
|
|
8159
7077
|
* **Details**
|
|
8160
7078
|
*
|
|
8161
|
-
*
|
|
8162
|
-
*
|
|
8163
|
-
*
|
|
8164
|
-
* `
|
|
8165
|
-
*
|
|
7079
|
+
* `root` is the `Machine.state` descriptor of the complete state tree. State
|
|
7080
|
+
* and event schemas provide runtime boundary validation while their decoded
|
|
7081
|
+
* types drive handler, state, event, target, error, and service inference.
|
|
7082
|
+
* Call `handle` on the returned {@link Definition} to declare the initial
|
|
7083
|
+
* target and the behavior of each state.
|
|
8166
7084
|
*
|
|
8167
|
-
*
|
|
8168
|
-
*
|
|
8169
|
-
*
|
|
8170
|
-
*
|
|
7085
|
+
* Register Effects, Streams, timers, logic, and child machines under
|
|
7086
|
+
* `effects`, `streams`, `timers`, `logic`, and `children`. A state invokes a
|
|
7087
|
+
* registered source by name with `invoke: { src }`, and only invoked sources
|
|
7088
|
+
* add to the machine's requirements.
|
|
8171
7089
|
*
|
|
8172
7090
|
* `Machine.events` defines the public input protocol. `Machine.internalEvents`
|
|
8173
7091
|
* adds raised events and other machine-local deliveries.
|
|
@@ -8178,42 +7096,82 @@ interface Make {
|
|
|
8178
7096
|
* schemas opaquely for runtime validation. Public and internal tags must be
|
|
8179
7097
|
* disjoint.
|
|
8180
7098
|
*
|
|
8181
|
-
* **
|
|
7099
|
+
* **Gotchas**
|
|
7100
|
+
*
|
|
7101
|
+
* Source names must be unique across all five registries. A top-level state
|
|
7102
|
+
* cannot be named `root`, because `root` names the root state.
|
|
7103
|
+
*
|
|
7104
|
+
* **Example** (Invoking a registered Effect)
|
|
8182
7105
|
*
|
|
8183
|
-
* ```ts
|
|
7106
|
+
* ```ts import.meta.vitest
|
|
8184
7107
|
* import { Machine } from "@typeonce/effect-machine"
|
|
8185
|
-
* import { Schema } from "effect"
|
|
8186
|
-
*
|
|
8187
|
-
*
|
|
8188
|
-
* })
|
|
8189
|
-
* }
|
|
8190
|
-
*
|
|
8191
|
-
*
|
|
8192
|
-
*
|
|
8193
|
-
*
|
|
7108
|
+
* import { Effect, Option, Schema } from "effect"
|
|
7109
|
+
*
|
|
7110
|
+
* const Lookup = Schema.TaggedUnion({ Loading: { id: Schema.String }, Ready: { name: Schema.String } })
|
|
7111
|
+
* const States = Machine.state({ states: { Idle: {}, Loading: Lookup.cases.Loading, Ready: Lookup.cases.Ready } })
|
|
7112
|
+
* const Events = Machine.events({ Load: { id: Schema.String } })
|
|
7113
|
+
*
|
|
7114
|
+
* const machine = Machine.make({
|
|
7115
|
+
* root: States,
|
|
7116
|
+
* events: Events,
|
|
7117
|
+
* effects: { findName: (id: string) => Effect.succeed(`User ${id}`) }
|
|
7118
|
+
* }).handle({
|
|
7119
|
+
* initial: { target: "Idle" },
|
|
7120
|
+
* states: {
|
|
7121
|
+
* Idle: { on: { Load: { target: "Loading", data: ({ event }) => ({ id: event.id }) } } },
|
|
7122
|
+
* Loading: {
|
|
7123
|
+
* invoke: {
|
|
7124
|
+
* src: "findName",
|
|
7125
|
+
* input: ({ state }) => state.id,
|
|
7126
|
+
* onDone: { target: "Ready", data: ({ output }) => ({ name: output }) }
|
|
7127
|
+
* }
|
|
7128
|
+
* }
|
|
7129
|
+
* }
|
|
7130
|
+
* })
|
|
7131
|
+
*
|
|
7132
|
+
* const name = Effect.scoped(Effect.gen(function*() {
|
|
7133
|
+
* const ref = yield* Machine.start(machine)
|
|
7134
|
+
* yield* ref.send(Events.Load({ id: "1" }))
|
|
7135
|
+
* const ready = yield* Machine.waitFor(ref, ({ state }) => state.state.path === "Ready").pipe(Effect.timeout("5 seconds"))
|
|
7136
|
+
* return States.get(ready.state, "Ready").pipe(Option.map((state) => state.name))
|
|
7137
|
+
* }))
|
|
7138
|
+
*
|
|
7139
|
+
* await Effect.runPromise(name) // => Option.some("User 1")
|
|
7140
|
+
* ```
|
|
7141
|
+
*
|
|
7142
|
+
* **Example** (Counting with schema classes)
|
|
7143
|
+
*
|
|
7144
|
+
* ```ts import.meta.vitest
|
|
7145
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
7146
|
+
* import { Effect, Option, Schema } from "effect"
|
|
7147
|
+
*
|
|
7148
|
+
* class Count extends Schema.TaggedClass<Count>("Count")("Count", { value: Schema.Number }) {}
|
|
7149
|
+
* class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", { by: Schema.Number }) {}
|
|
7150
|
+
*
|
|
8194
7151
|
* const States = Machine.state({ states: { Count } })
|
|
8195
|
-
* const Events = Machine.eventsFromSchemas(Increment)
|
|
8196
7152
|
* const counter = Machine.make({
|
|
8197
7153
|
* root: States,
|
|
8198
|
-
* events:
|
|
7154
|
+
* events: Machine.eventsFromSchemas(Increment)
|
|
8199
7155
|
* }).handle({
|
|
8200
|
-
* initial: {
|
|
8201
|
-
* target: "Count",
|
|
8202
|
-
* decoded: true,
|
|
8203
|
-
* data: new Count({ value: 0 })
|
|
8204
|
-
* },
|
|
7156
|
+
* initial: { target: "Count", decoded: true, data: new Count({ value: 0 }) },
|
|
8205
7157
|
* states: {
|
|
8206
7158
|
* Count: {
|
|
8207
7159
|
* on: {
|
|
8208
7160
|
* Increment: {
|
|
8209
|
-
* update:
|
|
8210
|
-
* decoded: true,
|
|
8211
|
-
* data: ({ event, state }) => new Count({ value: state.value + event.by })
|
|
7161
|
+
* update: { Count: { decoded: true, data: ({ event, state }) => new Count({ value: state.value + event.by }) } }
|
|
8212
7162
|
* }
|
|
8213
7163
|
* }
|
|
8214
7164
|
* }
|
|
8215
7165
|
* }
|
|
8216
7166
|
* })
|
|
7167
|
+
*
|
|
7168
|
+
* const value = Effect.gen(function*() {
|
|
7169
|
+
* const initial = yield* Machine.planInitial(counter)
|
|
7170
|
+
* const planned = yield* Machine.plan(counter, initial.state, new Increment({ by: 2 }))
|
|
7171
|
+
* return States.get(planned.next, "Count").pipe(Option.map((count) => count.value))
|
|
7172
|
+
* })
|
|
7173
|
+
*
|
|
7174
|
+
* await Effect.runPromise(value) // => Option.some(2)
|
|
8217
7175
|
* ```
|
|
8218
7176
|
*
|
|
8219
7177
|
* @see {@link state} for typed state-tree helpers.
|
|
@@ -8233,31 +7191,6 @@ export type EventOf<Protocol extends Machine.EventProtocol.Any> = Machine.EventO
|
|
|
8233
7191
|
Machine.EventProtocolSchemas<Protocol>
|
|
8234
7192
|
>
|
|
8235
7193
|
|
|
8236
|
-
/**
|
|
8237
|
-
* Defines a public event protocol and returns deferred constructors for every
|
|
8238
|
-
* statically finite configured event tag.
|
|
8239
|
-
*
|
|
8240
|
-
* Constructor inputs retain their schema-derived required fields, defaults,
|
|
8241
|
-
* and transformations. Construction is deferred until delivery so failures
|
|
8242
|
-
* enter the machine's `MachineSchemaDecodeError` channel rather than throwing
|
|
8243
|
-
* at the call site.
|
|
8244
|
-
*
|
|
8245
|
-
* **Example**
|
|
8246
|
-
*
|
|
8247
|
-
* ```ts
|
|
8248
|
-
* export const Event = Machine.eventsFromSchemas(
|
|
8249
|
-
* Schema.TaggedUnion({
|
|
8250
|
-
* Increment: { by: Schema.Number },
|
|
8251
|
-
* Reset: {}
|
|
8252
|
-
* })
|
|
8253
|
-
* )
|
|
8254
|
-
* const machine = Machine.make({ events: Event, ... })
|
|
8255
|
-
* yield* ref.send(Event.Increment({ by: 1 }))
|
|
8256
|
-
* ```
|
|
8257
|
-
*
|
|
8258
|
-
* @category constructors
|
|
8259
|
-
* @since 0.10.0
|
|
8260
|
-
*/
|
|
8261
7194
|
type EventFieldsSchemas<Cases extends Readonly<Record<string, Schema.Struct.Fields>>> = keyof Cases extends never
|
|
8262
7195
|
? readonly []
|
|
8263
7196
|
: readonly [
|
|
@@ -8272,15 +7205,25 @@ type ValidateEventFields<Cases> = {
|
|
|
8272
7205
|
: unknown
|
|
8273
7206
|
}
|
|
8274
7207
|
|
|
8275
|
-
/**
|
|
7208
|
+
/**
|
|
7209
|
+
* Defines a public event protocol from tagged field records.
|
|
7210
|
+
*
|
|
7211
|
+
* Constructors defer schema validation until delivery. Use
|
|
7212
|
+
* {@link eventsFromSchemas} when importing existing tagged schemas or protocol
|
|
7213
|
+
* descriptors.
|
|
7214
|
+
*
|
|
7215
|
+
* **Example** (Defining events from fields)
|
|
7216
|
+
*
|
|
7217
|
+
* ```ts import.meta.vitest
|
|
7218
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
7219
|
+
* import { Schema } from "effect"
|
|
8276
7220
|
*
|
|
8277
|
-
* ```ts
|
|
8278
7221
|
* const Events = Machine.events({ Increment: { by: Schema.Number }, Reset: {} })
|
|
8279
|
-
*
|
|
7222
|
+
*
|
|
7223
|
+
* Events.Increment({ by: 1 })._tag // => "Increment"
|
|
7224
|
+
* Events.Reset()._tag // => "Reset"
|
|
8280
7225
|
* ```
|
|
8281
7226
|
*
|
|
8282
|
-
* Constructors defer schema validation until delivery. Use eventsFromSchemas
|
|
8283
|
-
* when importing existing tagged schemas or protocol descriptors.
|
|
8284
7227
|
* @category constructors
|
|
8285
7228
|
* @since 0.32.0
|
|
8286
7229
|
*/
|
|
@@ -8288,7 +7231,45 @@ export const events: <const Cases extends Readonly<Record<string, Schema.Struct.
|
|
|
8288
7231
|
cases: Cases & ValidateEventFields<NoInfer<Cases>> & ValidateEventProtocolBuilder<"public", EventFieldsSchemas<Cases>>
|
|
8289
7232
|
) => Machine.EventProtocol<"public", EventFieldsSchemas<Cases>> = internal.eventsFromFields
|
|
8290
7233
|
|
|
8291
|
-
/**
|
|
7234
|
+
/**
|
|
7235
|
+
* Defines a public event protocol from existing tagged schemas or protocol
|
|
7236
|
+
* descriptors, without rebuilding their contracts, and returns deferred
|
|
7237
|
+
* constructors for every statically finite configured event tag.
|
|
7238
|
+
*
|
|
7239
|
+
* Constructor inputs retain their schema-derived required fields, defaults,
|
|
7240
|
+
* and transformations. Construction is deferred until delivery so failures
|
|
7241
|
+
* enter the machine's `MachineSchemaDecodeError` channel rather than throwing
|
|
7242
|
+
* at the call site.
|
|
7243
|
+
*
|
|
7244
|
+
* **Example** (Reusing a tagged union as the event protocol)
|
|
7245
|
+
*
|
|
7246
|
+
* ```ts import.meta.vitest
|
|
7247
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
7248
|
+
* import { Effect, Schema } from "effect"
|
|
7249
|
+
*
|
|
7250
|
+
* const Event = Machine.eventsFromSchemas(
|
|
7251
|
+
* Schema.TaggedUnion({
|
|
7252
|
+
* Increment: { by: Schema.Number },
|
|
7253
|
+
* Reset: {}
|
|
7254
|
+
* })
|
|
7255
|
+
* )
|
|
7256
|
+
* const machine = Machine.make({ root: Machine.state({ fields: { count: Schema.Number } }), events: Event }).handle({
|
|
7257
|
+
* root: { count: 0 },
|
|
7258
|
+
* on: {
|
|
7259
|
+
* Increment: { update: { root: ({ root, event }) => ({ count: root.count + event.by }) } },
|
|
7260
|
+
* Reset: { update: { root: { count: 0 } } }
|
|
7261
|
+
* }
|
|
7262
|
+
* })
|
|
7263
|
+
*
|
|
7264
|
+
* const count = Effect.scoped(Effect.gen(function*() {
|
|
7265
|
+
* const ref = yield* Machine.start(machine)
|
|
7266
|
+
* yield* ref.send(Event.Increment({ by: 1 }))
|
|
7267
|
+
* return (yield* ref.state).value.count
|
|
7268
|
+
* }))
|
|
7269
|
+
*
|
|
7270
|
+
* await Effect.runPromise(count) // => 1
|
|
7271
|
+
* ```
|
|
7272
|
+
*
|
|
8292
7273
|
* @category constructors
|
|
8293
7274
|
* @since 0.32.0
|
|
8294
7275
|
*/
|
|
@@ -8331,21 +7312,38 @@ export const optionalParent: <const Events extends ReadonlyArray<Machine.TaggedS
|
|
|
8331
7312
|
*
|
|
8332
7313
|
* Use these constructors for raised events and other machine-local deliveries.
|
|
8333
7314
|
* Construction failures are reported through the
|
|
8334
|
-
* owning machine's `MachineSchemaDecodeError` channel.
|
|
7315
|
+
* owning machine's `MachineSchemaDecodeError` channel. Use
|
|
7316
|
+
* {@link internalEventsFromSchemas} when importing existing tagged schemas or
|
|
7317
|
+
* protocol descriptors.
|
|
8335
7318
|
*
|
|
8336
|
-
* **Example**
|
|
7319
|
+
* **Example** (Raising an internal event)
|
|
8337
7320
|
*
|
|
8338
|
-
* ```ts
|
|
8339
|
-
*
|
|
8340
|
-
*
|
|
8341
|
-
*
|
|
8342
|
-
*
|
|
8343
|
-
*
|
|
8344
|
-
*
|
|
8345
|
-
*
|
|
7321
|
+
* ```ts import.meta.vitest
|
|
7322
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
7323
|
+
* import { Effect, Schema } from "effect"
|
|
7324
|
+
*
|
|
7325
|
+
* const Events = Machine.events({ Load: { value: Schema.String } })
|
|
7326
|
+
* const Internal = Machine.internalEvents({ Loaded: { value: Schema.String }, Failed: { message: Schema.String } })
|
|
7327
|
+
* const machine = Machine.make({
|
|
7328
|
+
* root: Machine.state({ fields: { value: Schema.String } }),
|
|
7329
|
+
* events: Events,
|
|
7330
|
+
* internalEvents: Internal
|
|
7331
|
+
* }).handle({
|
|
7332
|
+
* root: { value: "" },
|
|
7333
|
+
* on: {
|
|
7334
|
+
* Load: { stay: true, commands: ({ event }, enqueue) => enqueue.raise(Internal.Loaded({ value: event.value })) },
|
|
7335
|
+
* Loaded: { update: { root: ({ event }) => ({ value: event.value }) } },
|
|
7336
|
+
* Failed: { stay: true }
|
|
7337
|
+
* }
|
|
7338
|
+
* })
|
|
8346
7339
|
*
|
|
8347
|
-
*
|
|
8348
|
-
*
|
|
7340
|
+
* const value = Effect.gen(function*() {
|
|
7341
|
+
* const initial = yield* Machine.planInitial(machine)
|
|
7342
|
+
* const planned = yield* Machine.plan(machine, initial.state, Events.Load({ value: "ready" }))
|
|
7343
|
+
* return planned.next.value.value
|
|
7344
|
+
* })
|
|
7345
|
+
*
|
|
7346
|
+
* await Effect.runPromise(value) // => "ready"
|
|
8349
7347
|
* ```
|
|
8350
7348
|
*
|
|
8351
7349
|
* @category constructors
|
|
@@ -8358,7 +7356,10 @@ export const internalEvents: <const Cases extends Readonly<Record<string, Schema
|
|
|
8358
7356
|
& ValidateEventProtocolBuilder<"internal", EventFieldsSchemas<Cases>>
|
|
8359
7357
|
) => Machine.EventProtocol<"internal", EventFieldsSchemas<Cases>> = internal.internalEventsFromFields
|
|
8360
7358
|
|
|
8361
|
-
/**
|
|
7359
|
+
/**
|
|
7360
|
+
* Defines an internal event protocol from existing tagged schemas or protocol
|
|
7361
|
+
* descriptors, without rebuilding their contracts.
|
|
7362
|
+
*
|
|
8362
7363
|
* @category constructors
|
|
8363
7364
|
* @since 0.32.0
|
|
8364
7365
|
*/
|
|
@@ -8372,17 +7373,37 @@ export const internalEventsFromSchemas: {
|
|
|
8372
7373
|
* Defines the ephemeral notifications a machine may publish to external
|
|
8373
7374
|
* observers. Emitted events are separate from machine input and are never sent
|
|
8374
7375
|
* implicitly to a parent machine. Observe them through `MachineRef.emissions` or
|
|
8375
|
-
* the AtomMachine emission stream adapters.
|
|
7376
|
+
* the AtomMachine emission stream adapters. Use {@link emittedEventsFromSchemas}
|
|
7377
|
+
* when importing existing tagged schemas or protocol descriptors.
|
|
8376
7378
|
*
|
|
8377
|
-
* **Example**
|
|
7379
|
+
* **Example** (Emitting an event to observers)
|
|
8378
7380
|
*
|
|
8379
|
-
* ```ts
|
|
8380
|
-
*
|
|
8381
|
-
*
|
|
8382
|
-
*
|
|
8383
|
-
*
|
|
8384
|
-
* )
|
|
8385
|
-
* const machine = Machine.make({
|
|
7381
|
+
* ```ts import.meta.vitest
|
|
7382
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
7383
|
+
* import { Effect, Schema } from "effect"
|
|
7384
|
+
*
|
|
7385
|
+
* const Events = Machine.events({ Save: { id: Schema.String } })
|
|
7386
|
+
* const Emitted = Machine.emittedEvents({ Saved: { id: Schema.String } })
|
|
7387
|
+
* const machine = Machine.make({
|
|
7388
|
+
* root: Machine.state({ states: { Idle: {} } }),
|
|
7389
|
+
* events: Events,
|
|
7390
|
+
* emittedEvents: Emitted
|
|
7391
|
+
* }).handle({
|
|
7392
|
+
* initial: { target: "Idle" },
|
|
7393
|
+
* states: {
|
|
7394
|
+
* Idle: {
|
|
7395
|
+
* on: { Save: { stay: true, commands: ({ event }, enqueue) => enqueue.emit(Emitted.Saved({ id: event.id })) } }
|
|
7396
|
+
* }
|
|
7397
|
+
* }
|
|
7398
|
+
* })
|
|
7399
|
+
*
|
|
7400
|
+
* const emitted = Effect.gen(function*() {
|
|
7401
|
+
* const initial = yield* Machine.planInitial(machine)
|
|
7402
|
+
* const planned = yield* Machine.plan(machine, initial.state, Events.Save({ id: "a" }))
|
|
7403
|
+
* return planned.emittedEvents.length
|
|
7404
|
+
* })
|
|
7405
|
+
*
|
|
7406
|
+
* await Effect.runPromise(emitted) // => 1
|
|
8386
7407
|
* ```
|
|
8387
7408
|
*
|
|
8388
7409
|
* @category constructors
|
|
@@ -8395,7 +7416,10 @@ export const emittedEvents: <const Cases extends Readonly<Record<string, Schema.
|
|
|
8395
7416
|
& ValidateEventProtocolBuilder<"emitted", EventFieldsSchemas<Cases>>
|
|
8396
7417
|
) => Machine.EventProtocol<"emitted", EventFieldsSchemas<Cases>> = internal.emittedEventsFromFields
|
|
8397
7418
|
|
|
8398
|
-
/**
|
|
7419
|
+
/**
|
|
7420
|
+
* Defines an emitted event protocol from existing tagged schemas or protocol
|
|
7421
|
+
* descriptors, without rebuilding their contracts.
|
|
7422
|
+
*
|
|
8399
7423
|
* @category constructors
|
|
8400
7424
|
* @since 0.32.0
|
|
8401
7425
|
*/
|
|
@@ -8431,29 +7455,24 @@ export const emittedEventsFromSchemas: {
|
|
|
8431
7455
|
* Define an explicit JSON codec or keep process-local capabilities outside the
|
|
8432
7456
|
* logical snapshot.
|
|
8433
7457
|
*
|
|
8434
|
-
* **Example**
|
|
7458
|
+
* **Example** (Encoding a snapshot for storage)
|
|
8435
7459
|
*
|
|
8436
|
-
* ```ts
|
|
7460
|
+
* ```ts import.meta.vitest
|
|
8437
7461
|
* import { Machine } from "@typeonce/effect-machine"
|
|
8438
|
-
* import { Effect
|
|
8439
|
-
*
|
|
8440
|
-
* }
|
|
8441
|
-
* const
|
|
8442
|
-
*
|
|
8443
|
-
* root: States,
|
|
8444
|
-
* events: Machine.eventsFromSchemas()
|
|
8445
|
-
* }).handle({
|
|
8446
|
-
* initial: {
|
|
8447
|
-
* target: "Idle"
|
|
8448
|
-
* },
|
|
8449
|
-
* states: {
|
|
8450
|
-
* Idle: {}
|
|
8451
|
-
* }
|
|
7462
|
+
* import { Effect } from "effect"
|
|
7463
|
+
*
|
|
7464
|
+
* const States = Machine.state({ states: { Idle: {} } })
|
|
7465
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
7466
|
+
* initial: { target: "Idle" }
|
|
8452
7467
|
* })
|
|
7468
|
+
*
|
|
8453
7469
|
* const encoded = Effect.gen(function*() {
|
|
8454
7470
|
* const initial = yield* Machine.planInitial(machine)
|
|
8455
|
-
*
|
|
7471
|
+
* const snapshot = yield* Machine.encodeSnapshot(machine, initial.state)
|
|
7472
|
+
* return typeof snapshot
|
|
8456
7473
|
* })
|
|
7474
|
+
*
|
|
7475
|
+
* await Effect.runPromise(encoded) // => "object"
|
|
8457
7476
|
* ```
|
|
8458
7477
|
*
|
|
8459
7478
|
* @see {@link decodeSnapshot} for restoring an encoded snapshot.
|
|
@@ -8518,30 +7537,25 @@ export const encodeSnapshot: <
|
|
|
8518
7537
|
* Decoding restores logical statechart data only. It does not restart invoked
|
|
8519
7538
|
* processes, recreate spawned children, or restore a previous `MachineRef`.
|
|
8520
7539
|
*
|
|
8521
|
-
* **Example**
|
|
7540
|
+
* **Example** (Restoring an encoded snapshot)
|
|
8522
7541
|
*
|
|
8523
|
-
* ```ts
|
|
7542
|
+
* ```ts import.meta.vitest
|
|
8524
7543
|
* import { Machine } from "@typeonce/effect-machine"
|
|
8525
|
-
* import { Effect
|
|
8526
|
-
*
|
|
8527
|
-
* }
|
|
8528
|
-
* const
|
|
8529
|
-
*
|
|
8530
|
-
* root: States,
|
|
8531
|
-
* events: Machine.eventsFromSchemas()
|
|
8532
|
-
* }).handle({
|
|
8533
|
-
* initial: {
|
|
8534
|
-
* target: "Idle"
|
|
8535
|
-
* },
|
|
8536
|
-
* states: {
|
|
8537
|
-
* Idle: {}
|
|
8538
|
-
* }
|
|
7544
|
+
* import { Effect } from "effect"
|
|
7545
|
+
*
|
|
7546
|
+
* const States = Machine.state({ states: { Idle: {} } })
|
|
7547
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
7548
|
+
* initial: { target: "Idle" }
|
|
8539
7549
|
* })
|
|
8540
|
-
*
|
|
7550
|
+
*
|
|
7551
|
+
* const path = Effect.gen(function*() {
|
|
8541
7552
|
* const initial = yield* Machine.planInitial(machine)
|
|
8542
7553
|
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|
|
8543
|
-
*
|
|
7554
|
+
* const decoded = yield* Machine.decodeSnapshot(machine, encoded)
|
|
7555
|
+
* return decoded.state.path
|
|
8544
7556
|
* })
|
|
7557
|
+
*
|
|
7558
|
+
* await Effect.runPromise(path) // => "Idle"
|
|
8545
7559
|
* ```
|
|
8546
7560
|
*
|
|
8547
7561
|
* @see {@link encodeSnapshot} for creating the normalized representation.
|
|
@@ -8587,35 +7601,6 @@ export const decodeSnapshot: <
|
|
|
8587
7601
|
Machine.SnapshotDecodingServices<States>
|
|
8588
7602
|
> = internal.decodeSnapshot
|
|
8589
7603
|
|
|
8590
|
-
type TransitionBranchRecordError<Message extends string, Key extends PropertyKey = never> = {
|
|
8591
|
-
readonly "~effect/Machine/TransitionBranchRecordError": Message
|
|
8592
|
-
readonly key: Key
|
|
8593
|
-
}
|
|
8594
|
-
|
|
8595
|
-
type InvalidStaticTransitionBranchKey<Branches> = Extract<
|
|
8596
|
-
keyof Branches,
|
|
8597
|
-
"" | number | symbol | `${number}` | "NaN" | "Infinity" | "-Infinity"
|
|
8598
|
-
>
|
|
8599
|
-
|
|
8600
|
-
type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never] ?
|
|
8601
|
-
TransitionBranchRecordError<"Branch records must contain at least one branch">
|
|
8602
|
-
: [InvalidStaticTransitionBranchKey<Branches>] extends [never] ? {
|
|
8603
|
-
readonly [K in keyof Branches]:
|
|
8604
|
-
& {
|
|
8605
|
-
readonly [
|
|
8606
|
-
Extra in Exclude<
|
|
8607
|
-
keyof Branches[K],
|
|
8608
|
-
"target" | "update" | "initialize" | "initial" | "history" | "none" | "title"
|
|
8609
|
-
>
|
|
8610
|
-
]: never
|
|
8611
|
-
}
|
|
8612
|
-
& (Branches[K] extends { readonly title: "" } ? { readonly title: never } : unknown)
|
|
8613
|
-
} :
|
|
8614
|
-
TransitionBranchRecordError<
|
|
8615
|
-
"Branch keys must be non-empty, non-numeric strings",
|
|
8616
|
-
InvalidStaticTransitionBranchKey<Branches>
|
|
8617
|
-
>
|
|
8618
|
-
|
|
8619
7604
|
/**
|
|
8620
7605
|
* Plans the initial state for a machine without executing machine commands.
|
|
8621
7606
|
*
|
|
@@ -8634,26 +7619,20 @@ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never]
|
|
|
8634
7619
|
* protocol. Manual planners may inspect commands but need running machine targets
|
|
8635
7620
|
* to execute child-addressed operations.
|
|
8636
7621
|
*
|
|
8637
|
-
* **Example**
|
|
7622
|
+
* **Example** (Planning startup without running the machine)
|
|
8638
7623
|
*
|
|
8639
|
-
* ```ts
|
|
7624
|
+
* ```ts import.meta.vitest
|
|
8640
7625
|
* import { Machine } from "@typeonce/effect-machine"
|
|
8641
|
-
* import { Effect
|
|
8642
|
-
*
|
|
8643
|
-
* }
|
|
8644
|
-
* const
|
|
8645
|
-
*
|
|
8646
|
-
* root: States,
|
|
8647
|
-
* events: Machine.eventsFromSchemas()
|
|
8648
|
-
* }).handle({
|
|
8649
|
-
* initial: {
|
|
8650
|
-
* target: "Idle"
|
|
8651
|
-
* },
|
|
8652
|
-
* states: {
|
|
8653
|
-
* Idle: {}
|
|
8654
|
-
* }
|
|
7626
|
+
* import { Effect } from "effect"
|
|
7627
|
+
*
|
|
7628
|
+
* const States = Machine.state({ states: { Idle: {} } })
|
|
7629
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
7630
|
+
* initial: { target: "Idle" }
|
|
8655
7631
|
* })
|
|
8656
|
-
*
|
|
7632
|
+
*
|
|
7633
|
+
* const path = Effect.map(Machine.planInitial(machine), (plan) => plan.state.state.path)
|
|
7634
|
+
*
|
|
7635
|
+
* await Effect.runPromise(path) // => "Idle"
|
|
8657
7636
|
* ```
|
|
8658
7637
|
*
|
|
8659
7638
|
* @see {@link plan} for planning a received event.
|
|
@@ -8763,9 +7742,9 @@ export const stateNodes: <M extends Machine.Any>(machine: M) => ReadonlyArray<
|
|
|
8763
7742
|
/**
|
|
8764
7743
|
* Returns the statically selected root entry used during machine startup.
|
|
8765
7744
|
*
|
|
8766
|
-
* This function does not
|
|
8767
|
-
* input. `kind: "initial"` means that the
|
|
8768
|
-
*
|
|
7745
|
+
* This function does not construct initial state values or require machine
|
|
7746
|
+
* input. `kind: "initial"` means that the root enters its declared initial
|
|
7747
|
+
* configuration.
|
|
8769
7748
|
*
|
|
8770
7749
|
* @category getters
|
|
8771
7750
|
* @since 0.14.0
|
|
@@ -8779,7 +7758,8 @@ export const initialDefinition: <M extends Machine.Any>(machine: M) => Machine.I
|
|
|
8779
7758
|
*
|
|
8780
7759
|
* **Details**
|
|
8781
7760
|
*
|
|
8782
|
-
* The returned tuple retains the schemas supplied to {@link events}
|
|
7761
|
+
* The returned tuple retains the schemas supplied to {@link events} or
|
|
7762
|
+
* {@link eventsFromSchemas}, including
|
|
8783
7763
|
* grouped tagged unions. Internal and emitted event schemas are excluded. This
|
|
8784
7764
|
* getter is intended for tooling that needs to describe or construct valid
|
|
8785
7765
|
* external inputs without reaching into the opaque event protocol.
|
|
@@ -8791,16 +7771,16 @@ export const inputEventSchemas: <M extends Machine.Any>(machine: M) => Machine.I
|
|
|
8791
7771
|
internal.inputEventSchemas
|
|
8792
7772
|
|
|
8793
7773
|
/**
|
|
8794
|
-
* Returns every
|
|
7774
|
+
* Returns every declared transition in state definition order.
|
|
8795
7775
|
*
|
|
8796
7776
|
* **Details**
|
|
8797
7777
|
*
|
|
8798
|
-
* Event
|
|
8799
|
-
*
|
|
7778
|
+
* Event transitions retain their key order within each source state and are
|
|
7779
|
+
* followed by eventless and completion transitions. This function does not
|
|
8800
7780
|
* execute resolvers. Every branch exposes its static selection. State updates
|
|
8801
7781
|
* retain the updated owner in `selection.path` while leaving `target`
|
|
8802
7782
|
* undefined because they do not change topology. `acceptance` reports whether
|
|
8803
|
-
* the
|
|
7783
|
+
* the transition may decline the event.
|
|
8804
7784
|
*
|
|
8805
7785
|
* @category getters
|
|
8806
7786
|
* @since 0.4.0
|
|
@@ -8818,7 +7798,7 @@ export const transitionDefinitions: <M extends Machine.Any>(machine: M) => Reado
|
|
|
8818
7798
|
*
|
|
8819
7799
|
* **Details**
|
|
8820
7800
|
*
|
|
8821
|
-
* Static
|
|
7801
|
+
* Static invocation definitions expose stable ownership and lifecycle
|
|
8822
7802
|
* metadata without serializing runtime values. Function-valued sources are
|
|
8823
7803
|
* represented as dynamic and are never evaluated during inspection.
|
|
8824
7804
|
*
|
|
@@ -8856,7 +7836,7 @@ export const configuration: <M extends Machine.Any>(
|
|
|
8856
7836
|
* Returns event tags with at least one structurally eligible handler in the
|
|
8857
7837
|
* current state snapshot.
|
|
8858
7838
|
*
|
|
8859
|
-
* A `
|
|
7839
|
+
* A handler with `guard` or `{ decline: true }` may still reject a concrete event at planning time,
|
|
8860
7840
|
* so this is a static candidate query rather than a guarantee that every value
|
|
8861
7841
|
* with the returned tag will be handled.
|
|
8862
7842
|
*
|
|
@@ -8904,9 +7884,10 @@ export const enabled: <
|
|
|
8904
7884
|
*
|
|
8905
7885
|
* **Details**
|
|
8906
7886
|
*
|
|
8907
|
-
* Required
|
|
8908
|
-
* Declinable
|
|
8909
|
-
*
|
|
7887
|
+
* Required transitions are accepted from their structural eligibility.
|
|
7888
|
+
* Declinable transitions, which have a `guard` or a `{ decline: true }` entry,
|
|
7889
|
+
* run their guard or resolver only far enough to decide whether they accept
|
|
7890
|
+
* the event. Any commands, emissions, or raised events collected
|
|
8910
7891
|
* during that check are discarded.
|
|
8911
7892
|
*
|
|
8912
7893
|
* Event input is decoded through the machine's public and internal event protocols.
|
|
@@ -8924,9 +7905,9 @@ export const enabled: <
|
|
|
8924
7905
|
* Synchronous transition resolvers cannot execute it. Querying an internal event
|
|
8925
7906
|
* does not make that event available to `MachineRef.send`.
|
|
8926
7907
|
*
|
|
8927
|
-
* **Example**
|
|
7908
|
+
* **Example** (Checking an event against the current state)
|
|
8928
7909
|
*
|
|
8929
|
-
* ```ts
|
|
7910
|
+
* ```ts import.meta.vitest
|
|
8930
7911
|
* import { Machine } from "@typeonce/effect-machine"
|
|
8931
7912
|
* import { Effect, Schema } from "effect"
|
|
8932
7913
|
*
|
|
@@ -8938,13 +7919,15 @@ export const enabled: <
|
|
|
8938
7919
|
* internalEvents
|
|
8939
7920
|
* }).handle({
|
|
8940
7921
|
* initial: { target: "Idle" },
|
|
8941
|
-
* states: { Idle: { on: { Loaded: {
|
|
7922
|
+
* states: { Idle: { on: { Loaded: { stay: true } } } }
|
|
8942
7923
|
* })
|
|
8943
7924
|
*
|
|
8944
|
-
*
|
|
7925
|
+
* const canLoad = Effect.gen(function*() {
|
|
8945
7926
|
* const initial = yield* Machine.planInitial(machine)
|
|
8946
7927
|
* return yield* Machine.can(machine, initial.state, internalEvents.Loaded())
|
|
8947
7928
|
* })
|
|
7929
|
+
*
|
|
7930
|
+
* await Effect.runPromise(canLoad) // => true
|
|
8948
7931
|
* ```
|
|
8949
7932
|
*
|
|
8950
7933
|
* @category getters
|
|
@@ -9047,38 +8030,30 @@ export const can: {
|
|
|
9047
8030
|
* `emittedEvents`. Events with no enabled transition are ignored and produce
|
|
9048
8031
|
* an unchanged plan.
|
|
9049
8032
|
*
|
|
9050
|
-
* **Example**
|
|
8033
|
+
* **Example** (Planning one event without running the machine)
|
|
9051
8034
|
*
|
|
9052
|
-
* ```ts
|
|
8035
|
+
* ```ts import.meta.vitest
|
|
9053
8036
|
* import { Machine } from "@typeonce/effect-machine"
|
|
9054
|
-
* import { Effect
|
|
9055
|
-
*
|
|
9056
|
-
* }
|
|
9057
|
-
* class On extends Schema.TaggedClass<On>("On")("On", {}) {
|
|
9058
|
-
* }
|
|
9059
|
-
* class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {
|
|
9060
|
-
* }
|
|
9061
|
-
* const States = Machine.state({ states: { Off, On } })
|
|
8037
|
+
* import { Effect } from "effect"
|
|
8038
|
+
*
|
|
8039
|
+
* const Events = Machine.events({ Toggle: {} })
|
|
9062
8040
|
* const machine = Machine.make({
|
|
9063
|
-
* root:
|
|
9064
|
-
* events:
|
|
8041
|
+
* root: Machine.state({ states: { Off: {}, On: {} } }),
|
|
8042
|
+
* events: Events
|
|
9065
8043
|
* }).handle({
|
|
9066
|
-
* initial: {
|
|
9067
|
-
* target: "Off"
|
|
9068
|
-
* },
|
|
8044
|
+
* initial: { target: "Off" },
|
|
9069
8045
|
* states: {
|
|
9070
|
-
* Off: {
|
|
9071
|
-
* on: {
|
|
9072
|
-
* Toggle: { target: "On" }
|
|
9073
|
-
* }
|
|
9074
|
-
* },
|
|
9075
|
-
* On: {}
|
|
8046
|
+
* Off: { on: { Toggle: { target: "On" } } }
|
|
9076
8047
|
* }
|
|
9077
8048
|
* })
|
|
9078
|
-
*
|
|
8049
|
+
*
|
|
8050
|
+
* const path = Effect.gen(function*() {
|
|
9079
8051
|
* const initial = yield* Machine.planInitial(machine)
|
|
9080
|
-
*
|
|
8052
|
+
* const planned = yield* Machine.plan(machine, initial.state, Events.Toggle())
|
|
8053
|
+
* return planned.next.state.path
|
|
9081
8054
|
* })
|
|
8055
|
+
*
|
|
8056
|
+
* await Effect.runPromise(path) // => "On"
|
|
9082
8057
|
* ```
|
|
9083
8058
|
*
|
|
9084
8059
|
* @see {@link planInitial} for planning machine startup.
|
|
@@ -9186,8 +8161,11 @@ export const plan: <
|
|
|
9186
8161
|
* which machine will eventually own it. Prefer typed output, typed child
|
|
9187
8162
|
* addresses, or invocation lifecycle transitions when possible.
|
|
9188
8163
|
*
|
|
9189
|
-
*
|
|
9190
|
-
*
|
|
8164
|
+
* For one-shot work, register an Effect in `make({ effects })` and invoke it
|
|
8165
|
+
* with `invoke: { src }` instead. Register logic in `make({ logic })` to run it
|
|
8166
|
+
* for the lifetime of one state.
|
|
8167
|
+
*
|
|
8168
|
+
* @see {@link make} for registering sources that states invoke by name.
|
|
9191
8169
|
* @category constructors
|
|
9192
8170
|
* @since 0.4.0
|
|
9193
8171
|
*/
|
|
@@ -9200,7 +8178,7 @@ export const logic: <
|
|
|
9200
8178
|
InitialError = never,
|
|
9201
8179
|
InitialRequirements = never
|
|
9202
8180
|
>(options: {
|
|
9203
|
-
/**
|
|
8181
|
+
/** The first state, or an Effect that produces it from the process scope before `run` starts. */
|
|
9204
8182
|
readonly initial:
|
|
9205
8183
|
| State
|
|
9206
8184
|
| ((
|
|
@@ -9315,11 +8293,11 @@ export const sendTo: {
|
|
|
9315
8293
|
<Child extends ChildMachine.Any>(
|
|
9316
8294
|
child: Child,
|
|
9317
8295
|
event: ChildMachine.Event<Child>
|
|
9318
|
-
): Effect.Effect<void, StoppedError,
|
|
8296
|
+
): Effect.Effect<void, StoppedError, MachineRuntime>
|
|
9319
8297
|
<Address extends ChildAddress<never>>(
|
|
9320
8298
|
id: Address,
|
|
9321
8299
|
event: ChildAddress.Event<Address>
|
|
9322
|
-
): Effect.Effect<void, StoppedError,
|
|
8300
|
+
): Effect.Effect<void, StoppedError, MachineRuntime>
|
|
9323
8301
|
} = internal.sendTo
|
|
9324
8302
|
|
|
9325
8303
|
/**
|
|
@@ -9329,8 +8307,8 @@ export const sendTo: {
|
|
|
9329
8307
|
* @since 0.4.0
|
|
9330
8308
|
*/
|
|
9331
8309
|
export const stopChild: {
|
|
9332
|
-
<Event>(child: ChildAddress<Event>): Effect.Effect<void, never,
|
|
9333
|
-
<Child extends ChildMachine.Any>(child: Child): Effect.Effect<void, never,
|
|
8310
|
+
<Event>(child: ChildAddress<Event>): Effect.Effect<void, never, MachineRuntime>
|
|
8311
|
+
<Child extends ChildMachine.Any>(child: Child): Effect.Effect<void, never, MachineRuntime>
|
|
9334
8312
|
} = internal.stopChild
|
|
9335
8313
|
|
|
9336
8314
|
/**
|
|
@@ -9360,9 +8338,31 @@ export const watch: <State, Event, Error = never, Output = never>(
|
|
|
9360
8338
|
* Type predicates narrow the returned snapshot. Intermediate microsteps and
|
|
9361
8339
|
* historical snapshots are not observed.
|
|
9362
8340
|
*
|
|
9363
|
-
*
|
|
9364
|
-
*
|
|
9365
|
-
*
|
|
8341
|
+
* **Example** (Waiting for a state with a timeout)
|
|
8342
|
+
*
|
|
8343
|
+
* ```ts import.meta.vitest
|
|
8344
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
8345
|
+
* import { Effect } from "effect"
|
|
8346
|
+
*
|
|
8347
|
+
* const Events = Machine.events({ Finish: {} })
|
|
8348
|
+
* const machine = Machine.make({
|
|
8349
|
+
* root: Machine.state({ states: { Working: {}, Ready: {} } }),
|
|
8350
|
+
* events: Events
|
|
8351
|
+
* }).handle({
|
|
8352
|
+
* initial: { target: "Working" },
|
|
8353
|
+
* states: {
|
|
8354
|
+
* Working: { on: { Finish: { target: "Ready" } } }
|
|
8355
|
+
* }
|
|
8356
|
+
* })
|
|
8357
|
+
*
|
|
8358
|
+
* const path = Effect.scoped(Effect.gen(function*() {
|
|
8359
|
+
* const ref = yield* Machine.start(machine)
|
|
8360
|
+
* yield* ref.send(Events.Finish())
|
|
8361
|
+
* const ready = yield* Machine.waitFor(ref, ({ state }) => state.state.path === "Ready").pipe(Effect.timeout("5 seconds"))
|
|
8362
|
+
* return ready.state.state.path
|
|
8363
|
+
* }))
|
|
8364
|
+
*
|
|
8365
|
+
* await Effect.runPromise(path) // => "Ready"
|
|
9366
8366
|
* ```
|
|
9367
8367
|
* @category combinators
|
|
9368
8368
|
* @since 0.37.0
|
|
@@ -9401,15 +8401,41 @@ export const waitFor: {
|
|
|
9401
8401
|
* `prepared.start` is one-shot and scoped: the `Scope` that first evaluates it
|
|
9402
8402
|
* owns the machine, and closing that `Scope` is equivalent to `ref.stop`.
|
|
9403
8403
|
*
|
|
9404
|
-
*
|
|
9405
|
-
* const prepared = yield* Machine.prepare(machine)
|
|
8404
|
+
* **Example** (Observing emissions before startup)
|
|
9406
8405
|
*
|
|
9407
|
-
*
|
|
9408
|
-
*
|
|
9409
|
-
*
|
|
9410
|
-
*
|
|
8406
|
+
* ```ts import.meta.vitest
|
|
8407
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
8408
|
+
* import { Effect, Stream } from "effect"
|
|
8409
|
+
*
|
|
8410
|
+
* const Emitted = Machine.emittedEvents({ Started: {} })
|
|
8411
|
+
* const machine = Machine.make({
|
|
8412
|
+
* root: Machine.state({ states: { Idle: {} } }),
|
|
8413
|
+
* events: Machine.events({}),
|
|
8414
|
+
* emittedEvents: Emitted
|
|
8415
|
+
* }).handle({
|
|
8416
|
+
* initial: { target: "Idle" },
|
|
8417
|
+
* states: {
|
|
8418
|
+
* Idle: {
|
|
8419
|
+
* entry: (_, enqueue) => {
|
|
8420
|
+
* enqueue.emit(Emitted.Started())
|
|
8421
|
+
* }
|
|
8422
|
+
* }
|
|
8423
|
+
* }
|
|
8424
|
+
* })
|
|
9411
8425
|
*
|
|
9412
|
-
* const
|
|
8426
|
+
* const emitted = Effect.scoped(Effect.gen(function*() {
|
|
8427
|
+
* const prepared = yield* Machine.prepare(machine)
|
|
8428
|
+
* const seen: Array<string> = []
|
|
8429
|
+
* yield* prepared.emissions.pipe(
|
|
8430
|
+
* Stream.runForEach((event) => Effect.sync(() => seen.push(event._tag))),
|
|
8431
|
+
* Effect.forkScoped({ startImmediately: true })
|
|
8432
|
+
* )
|
|
8433
|
+
* yield* prepared.start
|
|
8434
|
+
* yield* Effect.yieldNow
|
|
8435
|
+
* return seen
|
|
8436
|
+
* }))
|
|
8437
|
+
*
|
|
8438
|
+
* await Effect.runPromise(emitted) // => ["Started"]
|
|
9413
8439
|
* ```
|
|
9414
8440
|
*
|
|
9415
8441
|
* @category constructors
|
|
@@ -9507,29 +8533,23 @@ export const prepare: <
|
|
|
9507
8533
|
* rather than being returned by `send`. Sending after the machine reaches any
|
|
9508
8534
|
* terminal state fails immediately with `StoppedError`.
|
|
9509
8535
|
*
|
|
9510
|
-
* **Example**
|
|
8536
|
+
* **Example** (Starting a machine in a scope)
|
|
9511
8537
|
*
|
|
9512
|
-
* ```ts
|
|
8538
|
+
* ```ts import.meta.vitest
|
|
9513
8539
|
* import { Machine } from "@typeonce/effect-machine"
|
|
9514
|
-
* import { Effect
|
|
9515
|
-
*
|
|
9516
|
-
* }
|
|
9517
|
-
* const
|
|
9518
|
-
*
|
|
9519
|
-
* root: States,
|
|
9520
|
-
* events: Machine.eventsFromSchemas()
|
|
9521
|
-
* }).handle({
|
|
9522
|
-
* initial: {
|
|
9523
|
-
* target: "Idle"
|
|
9524
|
-
* },
|
|
9525
|
-
* states: {
|
|
9526
|
-
* Idle: {}
|
|
9527
|
-
* }
|
|
8540
|
+
* import { Effect } from "effect"
|
|
8541
|
+
*
|
|
8542
|
+
* const States = Machine.state({ states: { Idle: {} } })
|
|
8543
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
8544
|
+
* initial: { target: "Idle" }
|
|
9528
8545
|
* })
|
|
9529
|
-
*
|
|
8546
|
+
*
|
|
8547
|
+
* const path = Effect.scoped(Effect.gen(function*() {
|
|
9530
8548
|
* const ref = yield* Machine.start(machine)
|
|
9531
|
-
* return yield* ref.state
|
|
8549
|
+
* return (yield* ref.state).state.path
|
|
9532
8550
|
* }))
|
|
8551
|
+
*
|
|
8552
|
+
* await Effect.runPromise(path) // => "Idle"
|
|
9533
8553
|
* ```
|
|
9534
8554
|
*
|
|
9535
8555
|
* @see {@link plan} for inspecting the same transition plan without executing it.
|
|
@@ -9610,7 +8630,7 @@ export const start: <
|
|
|
9610
8630
|
* the `Scope` is equivalent to `ref.stop`.
|
|
9611
8631
|
*
|
|
9612
8632
|
* `resume` validates and normalizes the supplied snapshot before publishing it
|
|
9613
|
-
* as the first state. It does not
|
|
8633
|
+
* as the first state. It does not construct the declared initial state, replay
|
|
9614
8634
|
* entry or transition actions, re-deliver raised or emitted events, or
|
|
9615
8635
|
* re-evaluate historical completion and eventless transitions. Active-state
|
|
9616
8636
|
* invokes start once in ancestor and document order with {@link InitialEvent};
|
|
@@ -9628,31 +8648,26 @@ export const start: <
|
|
|
9628
8648
|
* evaluated merely because the runtime was resumed; only ordinary subsequent
|
|
9629
8649
|
* transition planning can enter and stabilize states.
|
|
9630
8650
|
*
|
|
9631
|
-
* **Example**
|
|
8651
|
+
* **Example** (Resuming from a decoded snapshot)
|
|
9632
8652
|
*
|
|
9633
|
-
* ```ts
|
|
8653
|
+
* ```ts import.meta.vitest
|
|
9634
8654
|
* import { Machine } from "@typeonce/effect-machine"
|
|
9635
|
-
* import { Effect
|
|
9636
|
-
*
|
|
9637
|
-
* }
|
|
9638
|
-
* const
|
|
9639
|
-
*
|
|
9640
|
-
* root: States,
|
|
9641
|
-
* events: Machine.eventsFromSchemas()
|
|
9642
|
-
* }).handle({
|
|
9643
|
-
* initial: {
|
|
9644
|
-
* target: "Idle"
|
|
9645
|
-
* },
|
|
9646
|
-
* states: {
|
|
9647
|
-
* Idle: {}
|
|
9648
|
-
* }
|
|
8655
|
+
* import { Effect } from "effect"
|
|
8656
|
+
*
|
|
8657
|
+
* const States = Machine.state({ states: { Idle: {} } })
|
|
8658
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
8659
|
+
* initial: { target: "Idle" }
|
|
9649
8660
|
* })
|
|
9650
|
-
*
|
|
8661
|
+
*
|
|
8662
|
+
* const path = Effect.scoped(Effect.gen(function*() {
|
|
9651
8663
|
* const initial = yield* Machine.planInitial(machine)
|
|
9652
8664
|
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|
|
9653
8665
|
* const snapshot = yield* Machine.decodeSnapshot(machine, encoded)
|
|
9654
|
-
*
|
|
8666
|
+
* const ref = yield* Machine.resume(machine, snapshot)
|
|
8667
|
+
* return (yield* ref.state).state.path
|
|
9655
8668
|
* }))
|
|
8669
|
+
*
|
|
8670
|
+
* await Effect.runPromise(path) // => "Idle"
|
|
9656
8671
|
* ```
|
|
9657
8672
|
*
|
|
9658
8673
|
* @see {@link decodeSnapshot} for the schema and transport boundary.
|