@typeonce/effect-machine 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +216 -635
- package/dist/Machine.d.ts +814 -545
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +20 -8
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/childRegistry.d.ts +1 -1
- package/dist/internal/machine/childRegistry.d.ts.map +1 -1
- package/dist/internal/machine/cluster.d.ts +2 -50
- package/dist/internal/machine/cluster.d.ts.map +1 -1
- package/dist/internal/machine/cluster.js +4 -27
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/clusterProtocol.d.ts +35 -0
- package/dist/internal/machine/clusterProtocol.d.ts.map +1 -0
- package/dist/internal/machine/clusterProtocol.js +28 -0
- package/dist/internal/machine/clusterProtocol.js.map +1 -0
- package/dist/internal/machine/commandRuntime.d.ts +1 -1
- package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
- package/dist/internal/machine/configuration.d.ts +2 -1
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +38 -45
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/declaration.d.ts +17 -0
- package/dist/internal/machine/declaration.d.ts.map +1 -0
- package/dist/internal/machine/declaration.js +120 -0
- package/dist/internal/machine/declaration.js.map +1 -0
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +5 -4
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/implementation.d.ts +34 -0
- package/dist/internal/machine/implementation.d.ts.map +1 -0
- package/dist/internal/machine/implementation.js +3 -0
- package/dist/internal/machine/implementation.js.map +1 -0
- package/dist/internal/machine/invocation.d.ts +1 -1
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +1 -1
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/invocationDefinition.d.ts +1 -1
- package/dist/internal/machine/invocationDefinition.d.ts.map +1 -1
- package/dist/internal/machine/machine.d.ts +13 -2
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +149 -280
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +12 -11
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts +8 -7
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +16 -12
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/runtime.d.ts +2 -230
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js +8 -1857
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/runtimeCompiled.d.ts +5 -0
- package/dist/internal/machine/runtimeCompiled.d.ts.map +1 -0
- package/dist/internal/machine/runtimeCompiled.js +867 -0
- package/dist/internal/machine/runtimeCompiled.js.map +1 -0
- package/dist/internal/machine/runtimeGeneric.d.ts +3 -0
- package/dist/internal/machine/runtimeGeneric.d.ts.map +1 -0
- package/dist/internal/machine/runtimeGeneric.js +471 -0
- package/dist/internal/machine/runtimeGeneric.js.map +1 -0
- package/dist/internal/machine/runtimeProtocol.d.ts +312 -0
- package/dist/internal/machine/runtimeProtocol.d.ts.map +1 -0
- package/dist/internal/machine/runtimeProtocol.js +561 -0
- package/dist/internal/machine/runtimeProtocol.js.map +1 -0
- package/dist/internal/machine/targetReference.d.ts +15 -0
- package/dist/internal/machine/targetReference.d.ts.map +1 -0
- package/dist/internal/machine/targetReference.js +31 -0
- package/dist/internal/machine/targetReference.js.map +1 -0
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +2 -1
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +38 -40
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/probe.js +1 -1
- package/dist/internal/testing/machine/probe.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +5 -5
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +5 -17
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/docs/agent-guide.md +66 -91
- package/docs/machine-review.md +19 -49
- package/docs/root-api.md +68 -23
- package/package.json +1 -1
- package/src/Machine.ts +1387 -2011
- package/src/internal/machine/childRegistry.ts +1 -1
- package/src/internal/machine/cluster.ts +7 -73
- package/src/internal/machine/clusterProtocol.ts +56 -0
- package/src/internal/machine/commandRuntime.ts +1 -1
- package/src/internal/machine/configuration.ts +53 -45
- package/src/internal/machine/declaration.ts +140 -0
- package/src/internal/machine/executionPlan.ts +6 -5
- package/src/internal/machine/implementation.ts +41 -0
- package/src/internal/machine/invocation.ts +3 -3
- package/src/internal/machine/invocationDefinition.ts +1 -1
- package/src/internal/machine/machine.ts +210 -389
- package/src/internal/machine/planner.ts +54 -35
- package/src/internal/machine/process.ts +40 -33
- package/src/internal/machine/runtime.ts +20 -3037
- package/src/internal/machine/runtimeCompiled.ts +1166 -0
- package/src/internal/machine/runtimeGeneric.ts +799 -0
- package/src/internal/machine/runtimeProtocol.ts +1213 -0
- package/src/internal/machine/targetReference.ts +40 -0
- package/src/internal/machine/topology.ts +2 -1
- package/src/internal/testing/machine/finiteModel.ts +42 -43
- package/src/internal/testing/machine/probe.ts +1 -1
- package/src/unstable/cluster/ClusterMachine.ts +9 -17
package/dist/Machine.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ import * as internal from "./internal/machine/machine.js";
|
|
|
19
19
|
import { InitialEventTypeId } from "./internal/machine/machine.js";
|
|
20
20
|
import type { EnsureExecutable } from "./internal/machine/readiness.js";
|
|
21
21
|
import type { ExcludeCompatibleRuntime } from "./internal/machine/requirements.js";
|
|
22
|
-
import type * as internalRuntime from "./internal/machine/
|
|
22
|
+
import type * as internalRuntime from "./internal/machine/runtimeProtocol.js";
|
|
23
23
|
import type * as StateDefinition from "./internal/machine/stateDefinition.js";
|
|
24
24
|
import type * as Topology from "./internal/machine/topology.js";
|
|
25
25
|
/**
|
|
@@ -91,9 +91,33 @@ type IsAny<A> = 0 extends (1 & A) ? true : false;
|
|
|
91
91
|
*
|
|
92
92
|
* **Gotchas**
|
|
93
93
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
94
|
+
* Use `guard` to decline a transition before constructing its next state.
|
|
95
|
+
* Use `declinable: true` when a named branch resolver may return `decline()`.
|
|
96
|
+
* Register cancellable state-scoped delays in `make({ timers })`.
|
|
97
|
+
*
|
|
98
|
+
* **Example**
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
102
|
+
* import { Schema } from "effect"
|
|
103
|
+
*
|
|
104
|
+
* const events = Machine.events({ Add: { by: Schema.Number } })
|
|
105
|
+
* const Root = Machine.state({ fields: { count: Schema.Number } })
|
|
106
|
+
* const targets = Machine.targets(Root)
|
|
107
|
+
* export const counter = Machine.make({
|
|
108
|
+
* root: Root,
|
|
109
|
+
* events,
|
|
110
|
+
* initial: (root) => root.from(() => ({ count: 0 }))
|
|
111
|
+
* }).handle({
|
|
112
|
+
* on: {
|
|
113
|
+
* Add: {
|
|
114
|
+
* update: targets.root,
|
|
115
|
+
* guard: ({ event }) => event.by > 0,
|
|
116
|
+
* from: ({ root, event }) => ({ count: root.count + event.by })
|
|
117
|
+
* }
|
|
118
|
+
* }
|
|
119
|
+
* })
|
|
120
|
+
* ```
|
|
97
121
|
*
|
|
98
122
|
* @category models
|
|
99
123
|
* @since 0.4.0
|
|
@@ -159,7 +183,7 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
159
183
|
/** @internal */
|
|
160
184
|
readonly makeTargetBuilder: <Source extends Machine.StateNodeIdentifier<States>>(source: Source) => Machine.TargetBuilder<States, Source>;
|
|
161
185
|
/** @internal */
|
|
162
|
-
readonly handlers:
|
|
186
|
+
readonly handlers: Readonly<Record<string, unknown>>;
|
|
163
187
|
/** @internal */
|
|
164
188
|
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>;
|
|
165
189
|
/** @internal */
|
|
@@ -179,7 +203,7 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
179
203
|
* @category models
|
|
180
204
|
* @since 0.15.0
|
|
181
205
|
*/
|
|
182
|
-
export interface Definition<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []> extends Machine<States, Events, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, Emits, never, InputEvents, ParentEvents> {
|
|
206
|
+
export interface Definition<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], Registrations extends Machine.Registrations = {}> extends Machine<States, Events, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, Emits, never, InputEvents, ParentEvents> {
|
|
183
207
|
/**
|
|
184
208
|
* Adds typed state handlers and returns an independent machine
|
|
185
209
|
* implementation. Event dispatch maps and transition descriptors are
|
|
@@ -189,12 +213,14 @@ export interface Definition<States extends Machine.StateSchemas, Events extends
|
|
|
189
213
|
* **Example**
|
|
190
214
|
*
|
|
191
215
|
* ```ts
|
|
216
|
+
* const targets = Machine.targets(States)
|
|
192
217
|
* const counter = definition.handle({ states: {
|
|
193
218
|
* Count: {
|
|
194
219
|
* on: {
|
|
195
|
-
* Increment:
|
|
196
|
-
*
|
|
197
|
-
*
|
|
220
|
+
* Increment: {
|
|
221
|
+
* update: targets.root.Count,
|
|
222
|
+
* decoded: ({ event, state }) => new Count({ value: state.value + event.by })
|
|
223
|
+
* }
|
|
198
224
|
* }
|
|
199
225
|
* }
|
|
200
226
|
* } })
|
|
@@ -202,7 +228,7 @@ export interface Definition<States extends Machine.StateSchemas, Events extends
|
|
|
202
228
|
*
|
|
203
229
|
* @since 0.4.0
|
|
204
230
|
*/
|
|
205
|
-
readonly handle: Machine.Handler<States, Events, Emits, Input,
|
|
231
|
+
readonly handle: Machine.Handler<States, Events, Emits, Input, InitialE, InitialR, FinalStates, Output, InputEvents, ParentEvents, Registrations>;
|
|
206
232
|
}
|
|
207
233
|
/**
|
|
208
234
|
* Namespace containing type-level members associated with {@link Definition}.
|
|
@@ -490,9 +516,6 @@ export declare namespace Runtime {
|
|
|
490
516
|
}
|
|
491
517
|
type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<infer RequiredEvents, infer RequiredEmits> ? IsAny<Requirements> extends true ? never : [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements : Requirements : never;
|
|
492
518
|
declare const InvokeTypeId: typeof internal.InvokeTypeId;
|
|
493
|
-
declare const TransitionTypeId: typeof internal.TransitionTypeId;
|
|
494
|
-
declare const TransitionBuilderTypeId: unique symbol;
|
|
495
|
-
declare const InvokeBuilderTypeId: unique symbol;
|
|
496
519
|
declare const InitialBuilderTypeId: unique symbol;
|
|
497
520
|
type StateDefinitionError<Message extends string, Path extends PropertyKey = never, Details extends PropertyKey = never> = {
|
|
498
521
|
readonly "~effect/Machine/DefinitionError": Message;
|
|
@@ -3117,81 +3140,9 @@ export declare namespace Machine {
|
|
|
3117
3140
|
}
|
|
3118
3141
|
type SelectionValue<Builder, Path extends string, Kind extends Topology.TargetSelectionKind = "state", Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined> = TargetSelection<Builder, Path, Kind, Scope>;
|
|
3119
3142
|
type SelectionMethod<Builder, Path extends string, Kind extends Topology.TargetSelectionKind = "state", Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined> = () => SelectionValue<Builder, Path, Kind, Scope>;
|
|
3120
|
-
type InitialSelectionMethod<Builder, Path extends string, Scope extends Topology.TargetSelectionScope> = Builder extends {
|
|
3121
|
-
readonly initial: infer Initial;
|
|
3122
|
-
} ? {
|
|
3123
|
-
readonly initial: SelectionValue<Initial, Path, "initial", Scope>;
|
|
3124
|
-
} : {};
|
|
3125
|
-
type SelectionTreeWithPrefix<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Scope extends "local" | "branch", Builder> = {
|
|
3126
|
-
readonly [Key in Extract<ActiveStateKey<States> | ChoiceStateKey<States>, keyof Builder>]: SelectionNode<AllStates, States[Key], JoinPath<Prefix, Key>, Scope, Builder[Key]>;
|
|
3127
|
-
};
|
|
3128
|
-
type SelectionNode<AllStates extends StateSchemas, Node, Path extends string, Scope extends "local" | "branch", Builder> = Node extends ChoiceStateNodeConfig ? SelectionMethod<Builder, Path, "choice", Scope> : Node extends {
|
|
3129
|
-
readonly states: infer Children extends StateSchemas;
|
|
3130
|
-
} ? SelectionMethod<Builder, Path, "state", Scope> & InitialSelectionMethod<Builder, Path, Scope> & SelectionTreeWithPrefix<AllStates, Children, Path, Scope, Builder> : SelectionMethod<Builder, Path, "state", Scope>;
|
|
3131
|
-
/** @internal */
|
|
3132
|
-
type StateUpdateSelectionForNode<AllStates extends StateSchemas, Node, Path extends string, Scope extends "local" | "branch"> = Node extends {
|
|
3133
|
-
readonly type: "final";
|
|
3134
|
-
} ? {} : NodeSchema<Node> extends never ? {} : {
|
|
3135
|
-
readonly update: SelectionValue<StateUpdateBuilder<AllStates, Extract<Path, ValuedStateIdentifier<AllStates>>>, Path, "update", Scope>;
|
|
3136
|
-
};
|
|
3137
|
-
/** @internal */
|
|
3138
|
-
type BranchUpdateSelectionPath<AllStates extends StateSchemas, Node, Path extends string, Rest extends string, Scope extends "local" | "branch" = "branch"> = StateUpdateSelectionForNode<AllStates, Node, Path, Scope> & (Node extends {
|
|
3139
|
-
readonly states: infer Children extends StateSchemas;
|
|
3140
|
-
} ? Rest extends `${infer Head}.${infer Tail}` ? Head extends keyof Children ? {
|
|
3141
|
-
readonly [Key in Head]: BranchUpdateSelectionPath<AllStates, Children[Head], JoinPath<Path, Head>, Tail, Scope>;
|
|
3142
|
-
} : {} : Rest extends keyof Children ? {
|
|
3143
|
-
readonly [Key in Rest]: StateUpdateSelectionForNode<AllStates, Children[Rest], JoinPath<Path, Rest>, Scope>;
|
|
3144
|
-
} : {} : {});
|
|
3145
|
-
type FullSelectionNode<AllStates extends StateSchemas, Node, Path extends StateIdentifier<AllStates>, Builder> = Node extends {
|
|
3146
|
-
readonly states: StateSchemas;
|
|
3147
|
-
} ? SelectionMethod<Builder, Path, "state", "full"> & InitialSelectionMethod<Builder, Path, "full"> : SelectionMethod<Builder, Path, "state", "full">;
|
|
3148
3143
|
type RootBuilder<Builder> = Builder extends {
|
|
3149
3144
|
readonly "": infer Root;
|
|
3150
3145
|
} ? Root : never;
|
|
3151
|
-
type FullTargetSelector<States extends StateSchemas> = SelectionValue<RootBuilder<FullTargetBuilder<States>>, "", "state", "full"> & InitialSelectionMethod<RootBuilder<FullTargetBuilder<States>>, "", "full">;
|
|
3152
|
-
type BranchTargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = States[""] extends {
|
|
3153
|
-
readonly states: infer Children extends StateSchemas;
|
|
3154
|
-
} ? SelectionTreeWithPrefix<States, Children, "", "branch", RootBuilder<BranchTargetBuilder<States, Source>>> & (Source extends ChoiceIdentifier<States> ? {} : Omit<BranchUpdateSelectionPath<States, States[""], "", Source>, "update">) : {};
|
|
3155
|
-
type LocalTargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = NearestCompoundScope<States, Source> extends infer Scope ? [Scope] extends [never] ? {} : Scope extends StateIdentifier<States> ? ChildrenOf<States, Scope> extends infer Children extends StateSchemas ? LocalTargetBuilder<States, Source> extends infer Builder ? SelectionTreeWithPrefix<States, Children, Scope, "local", Builder> & ("with" extends keyof Builder ? {
|
|
3156
|
-
readonly with: SelectionValue<Builder["with"], Scope, "state", "local">;
|
|
3157
|
-
} : {}) & (Source extends ChoiceIdentifier<States> ? {} : Scope extends ValuedStateIdentifier<States> ? {
|
|
3158
|
-
readonly update: SelectionValue<StateUpdateBuilder<States, Scope>, Scope, "update", "local">;
|
|
3159
|
-
} : {}) : {} : {} : {} : {};
|
|
3160
|
-
type HistorySelectionTree<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Builder> = {
|
|
3161
|
-
readonly [Key in Extract<HistoryContainingKey<States>, keyof Builder>]: States[Key] extends HistoryStateNodeConfig ? SelectionValue<Builder[Key], JoinPath<Prefix, Key>, "history", "full"> : States[Key] extends {
|
|
3162
|
-
readonly states: infer Children extends StateSchemas;
|
|
3163
|
-
} ? HistorySelectionTree<AllStates, Children, JoinPath<Prefix, Key>, Builder[Key]> : never;
|
|
3164
|
-
};
|
|
3165
|
-
/**
|
|
3166
|
-
* Definition-time topology selector available to an ordinary transition.
|
|
3167
|
-
*
|
|
3168
|
-
* Topology-only instructions (`none`, declared `initial` and history
|
|
3169
|
-
* selections, and `local.with`) are values.
|
|
3170
|
-
*
|
|
3171
|
-
* State and choice destinations remain callable selection methods so their
|
|
3172
|
-
* target-specific resolver APIs retain exact inference.
|
|
3173
|
-
*/
|
|
3174
|
-
interface TargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> {
|
|
3175
|
-
/** Replaces this handler owner's value without reentry. */
|
|
3176
|
-
/** Selects the current handler owner for a value update without reentry. */
|
|
3177
|
-
readonly self: Source extends ValuedStateIdentifier<States> ? StateUpdateSelectionForNode<States, NodeByIdentifier<States, Source>, Source, "branch"> : {};
|
|
3178
|
-
/** Addresses the root and its retained value from any active descendant. */
|
|
3179
|
-
readonly root: "" extends ActiveStateKey<States> ? SelectionNode<States, States[""], "", "branch", (BranchTargetBuilder<States, Source> extends {
|
|
3180
|
-
readonly "": infer Builder;
|
|
3181
|
-
} ? Builder : never)> & StateUpdateSelectionForNode<States, States[""], "", "branch"> : never;
|
|
3182
|
-
/** Handles the trigger without selecting a destination. */
|
|
3183
|
-
readonly none: SelectionValue<TargetBuilder<States, Source>["none"], never, "none", "local">;
|
|
3184
|
-
/** Selects a destination or updates the nearest active compound scope. */
|
|
3185
|
-
readonly local: LocalTargetSelector<States, Source>;
|
|
3186
|
-
/** Selects a destination or updates a valued active ancestor under the current root. */
|
|
3187
|
-
readonly branch: BranchTargetSelector<States, Source>;
|
|
3188
|
-
/** Selects a complete destination under any top-level state. */
|
|
3189
|
-
readonly full: FullTargetSelector<States>;
|
|
3190
|
-
/** Restores a shallow or deep history pseudo-state. */
|
|
3191
|
-
readonly history: States[""] extends {
|
|
3192
|
-
readonly states: infer Children extends StateSchemas;
|
|
3193
|
-
} ? HistorySelectionTree<States, Children, "", RootBuilder<HistoryTargetBuilder<States>>> : {};
|
|
3194
|
-
}
|
|
3195
3146
|
/** Definition-time selector that can choose only a valid top-level initial entry. */
|
|
3196
3147
|
type InitialTargetSelector<States extends StateSchemas> = {
|
|
3197
3148
|
readonly [Key in Extract<ActiveStateKey<States>, keyof InitialBuilder<States>>]: States[Key] extends {
|
|
@@ -3217,13 +3168,8 @@ export declare namespace Machine {
|
|
|
3217
3168
|
readonly snapshot: Snapshot<States>;
|
|
3218
3169
|
/** Event that selected this handler, narrowed by its `_tag`. */
|
|
3219
3170
|
readonly event: EventByTag<Events, EventTag>;
|
|
3220
|
-
/**
|
|
3221
|
-
|
|
3222
|
-
* handler. Each builder documents which existing state values it keeps.
|
|
3223
|
-
*
|
|
3224
|
-
* @since 0.4.0
|
|
3225
|
-
*/
|
|
3226
|
-
readonly target: TargetBuilder<States, StateId>;
|
|
3171
|
+
/** Value owned by the logical root. */
|
|
3172
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3227
3173
|
};
|
|
3228
3174
|
/**
|
|
3229
3175
|
* Context passed to an entry or exit state handler.
|
|
@@ -3252,6 +3198,8 @@ export declare namespace Machine {
|
|
|
3252
3198
|
readonly children: ChildOwner<EventOf<InputEvents>>;
|
|
3253
3199
|
/** Value owned by the state that owns this invocation. */
|
|
3254
3200
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3201
|
+
/** Value owned by the logical root. */
|
|
3202
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3255
3203
|
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
3256
3204
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3257
3205
|
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
@@ -3274,8 +3222,8 @@ export declare namespace Machine {
|
|
|
3274
3222
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3275
3223
|
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
3276
3224
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3277
|
-
/**
|
|
3278
|
-
readonly
|
|
3225
|
+
/** Value owned by the logical root. */
|
|
3226
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3279
3227
|
/** Latest active lifecycle snapshot published by the invoked logic or child. */
|
|
3280
3228
|
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, {
|
|
3281
3229
|
readonly status: "active";
|
|
@@ -3298,8 +3246,8 @@ export declare namespace Machine {
|
|
|
3298
3246
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3299
3247
|
/** Complete owning-machine configuration captured for this transition. */
|
|
3300
3248
|
readonly snapshot: Snapshot<States>;
|
|
3301
|
-
/**
|
|
3302
|
-
readonly
|
|
3249
|
+
/** Value owned by the logical root. */
|
|
3250
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3303
3251
|
/** Successful output produced by the invocation. */
|
|
3304
3252
|
readonly output: Output;
|
|
3305
3253
|
};
|
|
@@ -3315,8 +3263,8 @@ export declare namespace Machine {
|
|
|
3315
3263
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3316
3264
|
/** Complete owning-machine configuration captured for this transition. */
|
|
3317
3265
|
readonly snapshot: Snapshot<States>;
|
|
3318
|
-
/**
|
|
3319
|
-
readonly
|
|
3266
|
+
/** Value owned by the logical root. */
|
|
3267
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3320
3268
|
/** Next element emitted by the invoked Stream. */
|
|
3321
3269
|
readonly element: Element;
|
|
3322
3270
|
};
|
|
@@ -3332,8 +3280,8 @@ export declare namespace Machine {
|
|
|
3332
3280
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3333
3281
|
/** Complete owning-machine configuration captured for this transition. */
|
|
3334
3282
|
readonly snapshot: Snapshot<States>;
|
|
3335
|
-
/**
|
|
3336
|
-
readonly
|
|
3283
|
+
/** Value owned by the logical root. */
|
|
3284
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3337
3285
|
/** Typed failure produced by the invocation. */
|
|
3338
3286
|
readonly error: Error;
|
|
3339
3287
|
};
|
|
@@ -3354,14 +3302,8 @@ export declare namespace Machine {
|
|
|
3354
3302
|
readonly snapshot: Snapshot<States>;
|
|
3355
3303
|
/** Lifecycle event retained while the eventless transition is evaluated. */
|
|
3356
3304
|
readonly event: LifecycleEvent<Events>;
|
|
3357
|
-
/**
|
|
3358
|
-
|
|
3359
|
-
* eventless handler. Each builder documents which existing state values it
|
|
3360
|
-
* keeps.
|
|
3361
|
-
*
|
|
3362
|
-
* @since 0.4.0
|
|
3363
|
-
*/
|
|
3364
|
-
readonly target: TargetBuilder<States, StateId>;
|
|
3305
|
+
/** Value owned by the logical root. */
|
|
3306
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3365
3307
|
};
|
|
3366
3308
|
/**
|
|
3367
3309
|
* Context passed to a state completion transition handler.
|
|
@@ -3382,14 +3324,8 @@ export declare namespace Machine {
|
|
|
3382
3324
|
readonly event: LifecycleEvent<Events>;
|
|
3383
3325
|
/** Output produced by the completed final child or parallel regions. */
|
|
3384
3326
|
readonly output: CompletionOutputByIdentifier<States, StateId>;
|
|
3385
|
-
/**
|
|
3386
|
-
|
|
3387
|
-
* state completes. Each builder documents which existing state values it
|
|
3388
|
-
* keeps.
|
|
3389
|
-
*
|
|
3390
|
-
* @since 0.4.0
|
|
3391
|
-
*/
|
|
3392
|
-
readonly target: TargetBuilder<States, StateId>;
|
|
3327
|
+
/** Value owned by the logical root. */
|
|
3328
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3393
3329
|
};
|
|
3394
3330
|
/** Context passed to a transient choice resolver. There is no `state` value. */
|
|
3395
3331
|
type ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
@@ -3401,8 +3337,8 @@ export declare namespace Machine {
|
|
|
3401
3337
|
};
|
|
3402
3338
|
/** Lifecycle event that led to the transient choice. */
|
|
3403
3339
|
readonly event: LifecycleEvent<Events>;
|
|
3404
|
-
/**
|
|
3405
|
-
readonly
|
|
3340
|
+
/** Value owned by the logical root. */
|
|
3341
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3406
3342
|
};
|
|
3407
3343
|
/**
|
|
3408
3344
|
* Context passed to a final state output function.
|
|
@@ -3475,7 +3411,7 @@ export declare namespace Machine {
|
|
|
3475
3411
|
*
|
|
3476
3412
|
* Handlers return snapshots for complete state replacement, target builder
|
|
3477
3413
|
* results for path-safe partial transitions, state-value updates, or
|
|
3478
|
-
* an explicit targetless result. In a machine definition, select `
|
|
3414
|
+
* an explicit targetless result. In a machine definition, select `{ none: true }`;
|
|
3479
3415
|
* its optional resolver returns `undefined`. Raw decoded state values are
|
|
3480
3416
|
* not accepted as transition targets.
|
|
3481
3417
|
*
|
|
@@ -3542,7 +3478,9 @@ export declare namespace Machine {
|
|
|
3542
3478
|
* @category utility types
|
|
3543
3479
|
* @since 0.4.0
|
|
3544
3480
|
*/
|
|
3545
|
-
type EventTransitionReturn<Transition> = Transition extends
|
|
3481
|
+
type EventTransitionReturn<Transition> = Transition extends {
|
|
3482
|
+
readonly initial: TargetReference<any, infer P, any>;
|
|
3483
|
+
} ? InitialTarget<P> : Transition extends {
|
|
3546
3484
|
readonly resolve?: infer Resolve;
|
|
3547
3485
|
} ? NonNullable<Resolve> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
3548
3486
|
/**
|
|
@@ -3571,7 +3509,7 @@ export declare namespace Machine {
|
|
|
3571
3509
|
* @category utility types
|
|
3572
3510
|
* @since 0.4.0
|
|
3573
3511
|
*/
|
|
3574
|
-
type InvokeResolvedSource<Source> = Source extends (...args: any) => infer Resolved ? Resolved : Source;
|
|
3512
|
+
type InvokeResolvedSource<Source> = Source extends LazyProgramValue ? Source : Source extends (...args: any) => infer Resolved ? Resolved : Source;
|
|
3575
3513
|
type InvokeFactoryResult<Source> = Source extends (...args: any) => infer Resolved ? Resolved : never;
|
|
3576
3514
|
type ChildMachineLogic<Child> = Child extends ChildMachine<string, infer M> ? Logic<Snapshot<States<M>>, EventInput<InputEvent<M>>, Error<M> | ActionError<Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialServices<M> | Services<M>>, internalRuntime.MachineRuntime>, Event<M>, EmittedEvent<M>>, Output<M>, InitialError<M> | Error<M> | ActionError<InitialServices<M> | Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError> : never;
|
|
3577
3515
|
type InvokeLogic<Invoke> = Invoke extends {
|
|
@@ -3595,7 +3533,7 @@ export declare namespace Machine {
|
|
|
3595
3533
|
readonly [InvokeTypeId]: {
|
|
3596
3534
|
readonly initialError: Types.Covariant<infer InitialError>;
|
|
3597
3535
|
};
|
|
3598
|
-
} ? InitialError : InvokeLogic<Invoke
|
|
3536
|
+
} ? InitialError : LogicInitialErrorOf<InvokeLogic<Invoke>>;
|
|
3599
3537
|
/**
|
|
3600
3538
|
* Extracts the runtime error from an invoked child process.
|
|
3601
3539
|
*
|
|
@@ -3606,7 +3544,7 @@ export declare namespace Machine {
|
|
|
3606
3544
|
readonly [InvokeTypeId]: {
|
|
3607
3545
|
readonly error: Types.Covariant<infer Error>;
|
|
3608
3546
|
};
|
|
3609
|
-
} ? Error : InvokeLogic<Invoke
|
|
3547
|
+
} ? Error : LogicErrorOf<InvokeLogic<Invoke>>;
|
|
3610
3548
|
/**
|
|
3611
3549
|
* Extracts the output from an invoked child process.
|
|
3612
3550
|
*
|
|
@@ -3617,7 +3555,7 @@ export declare namespace Machine {
|
|
|
3617
3555
|
readonly [InvokeTypeId]: {
|
|
3618
3556
|
readonly output: Types.Covariant<infer Output>;
|
|
3619
3557
|
};
|
|
3620
|
-
} ? Output : InvokeLogic<Invoke
|
|
3558
|
+
} ? Output : LogicOutputOf<InvokeLogic<Invoke>>;
|
|
3621
3559
|
/**
|
|
3622
3560
|
* Extracts the service requirements from an invoke source child process logic.
|
|
3623
3561
|
*
|
|
@@ -3628,7 +3566,7 @@ export declare namespace Machine {
|
|
|
3628
3566
|
readonly [InvokeTypeId]: {
|
|
3629
3567
|
readonly requirements: Types.Covariant<infer Requirements>;
|
|
3630
3568
|
};
|
|
3631
|
-
} ? Requirements : InvokeLogic<Invoke
|
|
3569
|
+
} ? Requirements : LogicServicesOf<InvokeLogic<Invoke>>;
|
|
3632
3570
|
/**
|
|
3633
3571
|
* Extracts events emitted directly by an invoked child.
|
|
3634
3572
|
*
|
|
@@ -3714,30 +3652,20 @@ export declare namespace Machine {
|
|
|
3714
3652
|
* @since 0.4.0
|
|
3715
3653
|
*/
|
|
3716
3654
|
type ConfigServices<Config> = Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | Effect.Services<HistoryDefaultReturn<Config>> | Effect.Services<ChoiceReturn<Config>> | InvokeRequirements<Config>;
|
|
3717
|
-
/** Type evidence retained by an authored transition without affecting runtime data. */
|
|
3718
|
-
interface TransitionTyped<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance = "required"> {
|
|
3719
|
-
readonly [TransitionTypeId]: {
|
|
3720
|
-
readonly owner: Types.Covariant<readonly [States, Events, Emits, StateId, Context]>;
|
|
3721
|
-
readonly acceptance: Types.Covariant<Acceptance>;
|
|
3722
|
-
};
|
|
3723
|
-
}
|
|
3724
3655
|
/** The only transition value accepted by machine handler APIs. */
|
|
3725
|
-
type TransitionConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> =
|
|
3656
|
+
type TransitionConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = Transition<States, StateId, Context, Events, Emits, {}, Reenter, Acceptance>;
|
|
3726
3657
|
type SelectionBuilder<Selection> = Selection extends TargetSelection<infer Builder, any, any, any> ? Builder : never;
|
|
3727
3658
|
type SelectionKind<Selection> = Selection extends TargetSelection<any, any, infer Kind, any> ? Kind : never;
|
|
3728
3659
|
type SelectionPath<Selection> = Selection extends TargetSelection<any, infer Path, any, any> ? Path : never;
|
|
3729
|
-
type SelectionScope<Selection> = Selection extends TargetSelection<any, any, any, infer Scope> ? Scope : never;
|
|
3730
3660
|
type TargetBuilderResult<Builder> = (Builder extends (...args: any) => infer Result ? Result : never) | (Builder extends {
|
|
3731
3661
|
readonly decoded: (...args: any) => infer Result;
|
|
3732
3662
|
} ? Result : never) | (Builder extends {
|
|
3733
3663
|
readonly from: (...args: any) => infer Result;
|
|
3734
3664
|
} ? Result : never);
|
|
3735
3665
|
type SelectedTargetResult<Selection> = SelectionBuilder<Selection> extends infer Builder ? TargetBuilderResult<Builder> : never;
|
|
3736
|
-
type RetainedUpdateOwner<States extends StateSchemas, Source extends StateNodeIdentifier<States>, Selection> = Extract<ParentStateIdentifier<Source>, ParentStateIdentifier<Extract<SelectionPath<Selection>, string>> & ValuedStateIdentifier<States>>;
|
|
3737
|
-
type RetainedOwnerSelector<Owner extends string> = () => TargetSelection<any, Owner, "state", "branch">;
|
|
3738
3666
|
/**
|
|
3739
3667
|
* Destination construction returned when a transition declares one retained
|
|
3740
|
-
* valued owner with
|
|
3668
|
+
* valued owner with a `{ target, update }` declaration.
|
|
3741
3669
|
*
|
|
3742
3670
|
* @category models
|
|
3743
3671
|
* @since 0.22.0
|
|
@@ -3762,31 +3690,11 @@ export declare namespace Machine {
|
|
|
3762
3690
|
type TransitionResolveContext<Context, Selection> = Omit<Context, "target"> & (SelectionKind<Selection> extends "none" ? {} : {
|
|
3763
3691
|
readonly target: SelectionBuilder<Selection>;
|
|
3764
3692
|
});
|
|
3765
|
-
type StateUpdateResolveContext<States extends StateSchemas, Context, Owner extends ValuedStateIdentifier<States>> = Omit<Context, "target"> & {
|
|
3766
|
-
/** Decoded owner value from the pre-transition snapshot. */
|
|
3767
|
-
readonly current: StateByIdentifier<States, Owner>;
|
|
3768
|
-
/** Constructs the complete replacement for the selected owner. */
|
|
3769
|
-
readonly owner: StateUpdateBuilder<States, Owner>;
|
|
3770
|
-
};
|
|
3771
|
-
type UpdatingTransitionResolveContext<States extends StateSchemas, Context, Selection, Owner extends ValuedStateIdentifier<States>> = Omit<Context, "target"> & {
|
|
3772
|
-
/** Decoded owner value from the pre-transition snapshot. */
|
|
3773
|
-
readonly current: StateByIdentifier<States, Owner>;
|
|
3774
|
-
/** Constructs the selected topology and requires `.update(...)`. */
|
|
3775
|
-
readonly target: UpdatingTargetBuilder<SelectionBuilder<Selection>, States, Owner>;
|
|
3776
|
-
/** Constructs the complete replacement for the retained owner. */
|
|
3777
|
-
readonly owner: StateUpdateBuilder<States, Owner>;
|
|
3778
|
-
};
|
|
3779
3693
|
/** Context capability available only to explicitly declinable resolvers. */
|
|
3780
3694
|
interface DeclineCapability {
|
|
3781
3695
|
/** Declines this candidate and continues hierarchical transition selection. */
|
|
3782
3696
|
readonly decline: () => Declined;
|
|
3783
3697
|
}
|
|
3784
|
-
type TransitionResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Selection> = (context: TransitionResolveContext<Context, Selection>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined;
|
|
3785
|
-
type DeclinableTransitionResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Selection> = (context: TransitionResolveContext<Context, Selection> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined) | Declined;
|
|
3786
|
-
/** @internal */
|
|
3787
|
-
type StateUpdateResolver<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Owner extends ValuedStateIdentifier<States>> = (context: StateUpdateResolveContext<States, Context, Owner>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateUpdate<States, Owner>;
|
|
3788
|
-
/** @internal */
|
|
3789
|
-
type DeclinableStateUpdateResolver<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Owner extends ValuedStateIdentifier<States>> = (context: StateUpdateResolveContext<States, Context, Owner> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateUpdate<States, Owner> | Declined;
|
|
3790
3698
|
/** One named destination declared by a branching transition. */
|
|
3791
3699
|
interface TransitionBranchInput<Selection extends TargetSelection<any, any, any> = TargetSelection<any, any, any>> {
|
|
3792
3700
|
/** Exact topology destination available to the branching resolver. */
|
|
@@ -3801,13 +3709,23 @@ export declare namespace Machine {
|
|
|
3801
3709
|
readonly result: Types.Covariant<Result>;
|
|
3802
3710
|
};
|
|
3803
3711
|
}
|
|
3712
|
+
type CompletedBranchResult<R> = R extends {
|
|
3713
|
+
readonly update: unknown;
|
|
3714
|
+
} ? R extends UpdatingStateConstruction<infer Target, infer S, infer Owner> ? CombinedTarget<UnwrapConstruction<Target>, S, Owner> : R : R;
|
|
3715
|
+
type SelectedConstruction<K extends string, R> = R extends {
|
|
3716
|
+
readonly update: unknown;
|
|
3717
|
+
} ? R extends UpdatingStateConstruction<infer Target, infer S, infer Owner> ? {
|
|
3718
|
+
readonly update: SelectedBranchBuilder<StateUpdateBuilder<S, Owner>, K> extends infer B ? {
|
|
3719
|
+
readonly [M in keyof B]: StateUpdateBuilder<S, Owner>[Extract<M, keyof StateUpdateBuilder<S, Owner>>] extends (...args: infer A) => unknown ? (...args: A) => SelectedBranch<K, CombinedTarget<UnwrapConstruction<Target>, S, Owner>> : never;
|
|
3720
|
+
} : never;
|
|
3721
|
+
} : SelectedBranch<K, R> : SelectedBranch<K, R>;
|
|
3804
3722
|
type SelectedBranchCallable<Callable, Key extends string> = Callable extends {
|
|
3805
3723
|
(...args: infer Arguments1): infer Result1;
|
|
3806
3724
|
(...args: infer Arguments2): infer Result2;
|
|
3807
3725
|
} ? {
|
|
3808
|
-
(...args: Arguments1):
|
|
3809
|
-
(...args: Arguments2):
|
|
3810
|
-
} : Callable extends (...args: infer Arguments) => infer Result ? (...args: Arguments) =>
|
|
3726
|
+
(...args: Arguments1): SelectedConstruction<Key, Result1>;
|
|
3727
|
+
(...args: Arguments2): SelectedConstruction<Key, Result2>;
|
|
3728
|
+
} : Callable extends (...args: infer Arguments) => infer Result ? (...args: Arguments) => SelectedConstruction<Key, Result> : {};
|
|
3811
3729
|
type SelectedBranchBuilderProperties<Builder, Key extends string> = {
|
|
3812
3730
|
readonly [Property in keyof Builder]: Builder[Property] extends (...args: any) => any ? SelectedBranchCallable<Builder[Property], Key> : Builder[Property];
|
|
3813
3731
|
};
|
|
@@ -3817,97 +3735,14 @@ export declare namespace Machine {
|
|
|
3817
3735
|
readonly [Key in Extract<keyof Branches, string>]: SelectedBranchBuilder<SelectionBuilder<Branches[Key]["target"]>, Key>;
|
|
3818
3736
|
};
|
|
3819
3737
|
type BranchSelectionResult<Branches extends Readonly<Record<string, TransitionBranchInput>>> = {
|
|
3820
|
-
readonly [Key in Extract<keyof Branches, string>]: SelectedBranch<Key, SelectedTargetResult<Branches[Key]["target"]
|
|
3738
|
+
readonly [Key in Extract<keyof Branches, string>]: SelectedBranch<Key, CompletedBranchResult<SelectedTargetResult<Branches[Key]["target"]>>>;
|
|
3821
3739
|
}[Extract<keyof Branches, string>];
|
|
3822
3740
|
type TransitionBranchesResolveContext<Context, Branches extends Readonly<Record<string, TransitionBranchInput>>> = Omit<Context, "target"> & {
|
|
3823
3741
|
readonly select: BranchSelectors<Branches>;
|
|
3824
3742
|
};
|
|
3825
|
-
type TransitionBranchesResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Branches extends Readonly<Record<string, TransitionBranchInput>>> = (context: TransitionBranchesResolveContext<Context, Branches>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => BranchSelectionResult<Branches>;
|
|
3826
|
-
type DeclinableTransitionBranchesResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Branches extends Readonly<Record<string, TransitionBranchInput>>> = (context: TransitionBranchesResolveContext<Context, Branches> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => BranchSelectionResult<Branches> | Declined;
|
|
3827
|
-
/** @internal Type evidence retained by a transition authored through its bound selector. */
|
|
3828
|
-
interface TransitionBuilderEvidence<out Result, out Acceptance extends TransitionAcceptance> {
|
|
3829
|
-
readonly [TransitionBuilderTypeId]: {
|
|
3830
|
-
readonly result: Types.Covariant<Result>;
|
|
3831
|
-
readonly acceptance: Types.Covariant<Acceptance>;
|
|
3832
|
-
};
|
|
3833
|
-
}
|
|
3834
|
-
type TransitionReenterOption<Reenter extends boolean> = [Reenter] extends [true] ? {
|
|
3835
|
-
/** Forces the source state to exit and enter even when active paths remain unchanged. */
|
|
3836
|
-
readonly reenter?: boolean;
|
|
3837
|
-
} : {
|
|
3838
|
-
readonly reenter?: never;
|
|
3839
|
-
};
|
|
3840
|
-
type TransitionRequiredOptions<Reenter extends boolean> = TransitionReenterOption<Reenter> & {
|
|
3841
|
-
/** Keeps the transition required. The resolver cannot return `decline()`. */
|
|
3842
|
-
readonly declinable?: false;
|
|
3843
|
-
};
|
|
3844
|
-
type TransitionDeclinableOptions<Reenter extends boolean> = TransitionReenterOption<Reenter> & {
|
|
3845
|
-
/** Adds `decline()` to the resolver context and permits declining this candidate. */
|
|
3846
|
-
readonly declinable: true;
|
|
3847
|
-
};
|
|
3848
|
-
type BuiltTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Result, Acceptance extends TransitionAcceptance> = TransitionTyped<States, Events, Emits, StateId, Context, Reenter, Acceptance> & TransitionBuilderEvidence<Result, Acceptance>;
|
|
3849
|
-
interface TransitionResolveRequired<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, any>> {
|
|
3850
|
-
(resolve: TransitionResolver<Events, Emits, Context, Selection>, options?: TransitionRequiredOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required">;
|
|
3851
|
-
}
|
|
3852
|
-
interface TransitionResolveDeclinable<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, any>> {
|
|
3853
|
-
(resolve: DeclinableTransitionResolver<Events, Emits, Context, Selection>, options: TransitionDeclinableOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined) | Declined, "declinable">;
|
|
3854
|
-
}
|
|
3855
3743
|
type ConstructionCallbacks<Context, Builder, Result> = {
|
|
3856
3744
|
readonly [Method in Extract<keyof Builder, "from" | "decoded"> as Builder[Method] extends (...args: infer Args) => unknown ? Args extends readonly [unknown?] ? Method : never : never]: Builder[Method] extends (...args: infer Args) => unknown ? (value: (context: Context) => Args[0]) => Result : never;
|
|
3857
3745
|
};
|
|
3858
|
-
type GuardedTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, any>> = ConstructionCallbacks<Omit<Context, "target">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">> & (SelectionSupportsDefaultConstruction<Selection> extends true ? BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable"> : {}) & {
|
|
3859
|
-
readonly resolve: (resolve: TransitionResolver<Events, Emits, Context, Selection>, options?: TransitionRequiredOptions<Reenter>) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
|
|
3860
|
-
};
|
|
3861
|
-
/**
|
|
3862
|
-
* A selected transition target with target-specific resolver operations.
|
|
3863
|
-
*
|
|
3864
|
-
* **Example** (Updating state while reentering)
|
|
3865
|
-
*
|
|
3866
|
-
* ```ts
|
|
3867
|
-
* Reset: (to) =>
|
|
3868
|
-
* to.branch.Ready().resolve(
|
|
3869
|
-
* ({ target }) => target.from(),
|
|
3870
|
-
* { reenter: true }
|
|
3871
|
-
* )
|
|
3872
|
-
* ```
|
|
3873
|
-
*
|
|
3874
|
-
* @inlineType TransitionRequiredOptions
|
|
3875
|
-
* @inlineType TransitionDeclinableOptions
|
|
3876
|
-
* @inlineType TransitionReenterOption
|
|
3877
|
-
*/
|
|
3878
|
-
type TransitionTarget<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Selection extends TargetSelection<any, any, any>> = Selection & ("declinable" extends Acceptance ? {
|
|
3879
|
-
/** Declines this candidate before construction when the predicate is false. */
|
|
3880
|
-
readonly guard: (predicate: (context: Omit<Context, "target">) => boolean) => GuardedTransition<States, Events, Emits, StateId, Context, Reenter, Selection>;
|
|
3881
|
-
} : {}) & ConstructionCallbacks<Omit<Context, "target">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">> & (SelectionSupportsDefaultConstruction<Selection> extends true ? BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required"> : {}) & {
|
|
3882
|
-
/** Evaluates state construction after this transition is selected. */
|
|
3883
|
-
readonly resolve: TransitionResolveRequired<States, Events, Emits, StateId, Context, Reenter, Selection> & ("declinable" extends Acceptance ? TransitionResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Selection> : {});
|
|
3884
|
-
} & ([Reenter] extends [true] ? SelectionSupportsDefaultConstruction<Selection> extends true ? {
|
|
3885
|
-
/** Reenters the source using the selected target's default construction. */
|
|
3886
|
-
readonly reenter: () => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required">;
|
|
3887
|
-
} : {} : {}) & (SelectionKind<Selection> extends "state" ? SelectionScope<Selection> extends "local" | "branch" ? RetainedUpdateOwner<States, StateId, Selection> extends infer Owner extends ValuedStateIdentifier<States> ? [
|
|
3888
|
-
Owner
|
|
3889
|
-
] extends [never] ? {} : {
|
|
3890
|
-
/** Declares one valued owner retained by the selected topology. */
|
|
3891
|
-
readonly updating: <SelectedOwner extends Owner>(owner: RetainedOwnerSelector<SelectedOwner>) => UpdatingTransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection, SelectedOwner>;
|
|
3892
|
-
} : {} : {} : {});
|
|
3893
|
-
/** A topology selection that requires one retained owner replacement. */
|
|
3894
|
-
type UpdatingTransitionTarget<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Selection extends TargetSelection<any, any, "state">, Owner extends ValuedStateIdentifier<States>> = Selection & {
|
|
3895
|
-
/** @internal */
|
|
3896
|
-
readonly "~effect/Machine/UpdatingTransitionTarget": Owner;
|
|
3897
|
-
readonly resolve: ((resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, options?: TransitionRequiredOptions<Reenter>) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, "required">) & ("declinable" extends Acceptance ? (resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, options: TransitionDeclinableOptions<Reenter>) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, "declinable"> : {});
|
|
3898
|
-
};
|
|
3899
|
-
/** @internal */
|
|
3900
|
-
interface StateUpdateTransitionRequired<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "update">> {
|
|
3901
|
-
(resolve: StateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options?: TransitionRequiredOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">;
|
|
3902
|
-
}
|
|
3903
|
-
/** @internal */
|
|
3904
|
-
interface StateUpdateTransitionDeclinable<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "update">> {
|
|
3905
|
-
(resolve: DeclinableStateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options: TransitionDeclinableOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
|
|
3906
|
-
}
|
|
3907
|
-
/** @internal */
|
|
3908
|
-
type StateUpdateTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Selection extends TargetSelection<any, any, "update">> = Selection & ConstructionCallbacks<Omit<StateUpdateResolveContext<States, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, "owner">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">> & {
|
|
3909
|
-
readonly resolve: StateUpdateTransitionRequired<States, Events, Emits, StateId, Context, Reenter, Selection> & ("declinable" extends Acceptance ? StateUpdateTransitionDeclinable<States, Events, Emits, StateId, Context, Reenter, Selection> : {});
|
|
3910
|
-
};
|
|
3911
3746
|
/** @internal Type evidence retained by a machine initial-entry declaration. */
|
|
3912
3747
|
interface InitialBuilderEvidence<out Selection> {
|
|
3913
3748
|
readonly [InitialBuilderTypeId]: Types.Covariant<Selection>;
|
|
@@ -3955,48 +3790,12 @@ export declare namespace Machine {
|
|
|
3955
3790
|
readonly "": Root;
|
|
3956
3791
|
}>>) => InitialBuilderEvidence<RootConfigurationSelection<Root>>;
|
|
3957
3792
|
}) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
|
|
3958
|
-
type TransitionSelectorNode<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Node> = Node extends TargetSelection<any, any, "update"> ? StateUpdateTransition<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node> : Node extends (...args: infer Args) => infer Selection ? Selection extends TargetSelection<any, any, any> ? ((...args: Args) => TransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection>) & {
|
|
3959
|
-
readonly [Key in keyof Node]: TransitionSelectorNode<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node[Key]>;
|
|
3960
|
-
} : never : Node extends TargetSelection<any, any, any> ? TransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node> : {
|
|
3961
|
-
readonly [Key in keyof Node]: TransitionSelectorNode<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node[Key]>;
|
|
3962
|
-
};
|
|
3963
|
-
interface TransitionBranchesResolveRequired<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Branches extends Readonly<Record<string, TransitionBranchInput>>> {
|
|
3964
|
-
(resolve: TransitionBranchesResolver<Events, Emits, Context, Branches>, options?: TransitionRequiredOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, BranchSelectionResult<Branches>, "required">;
|
|
3965
|
-
}
|
|
3966
|
-
interface TransitionBranchesResolveDeclinable<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Branches extends Readonly<Record<string, TransitionBranchInput>>> {
|
|
3967
|
-
(resolve: DeclinableTransitionBranchesResolver<Events, Emits, Context, Branches>, options: TransitionDeclinableOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, BranchSelectionResult<Branches> | Declined, "declinable">;
|
|
3968
|
-
}
|
|
3969
|
-
type TransitionSelectorTargets<in out States extends StateSchemas, in out Events extends ReadonlyArray<TaggedSchema>, in out Emits extends ReadonlyArray<TaggedSchema>, in out StateId extends StateNodeIdentifier<States>, in out Context, in out Reenter extends boolean, in out Acceptance extends TransitionAcceptance> = {
|
|
3970
|
-
readonly [Key in keyof TargetSelector<States, StateId>]: TransitionSelectorNode<States, Events, Emits, StateId, Context, Key extends "self" ? false : Reenter, Acceptance, TargetSelector<States, StateId>[Key]>;
|
|
3971
|
-
};
|
|
3972
|
-
/** Selector supplied to inline transition declarations. */
|
|
3973
|
-
interface TransitionSelector<in out States extends StateSchemas, in out Events extends ReadonlyArray<TaggedSchema>, in out Emits extends ReadonlyArray<TaggedSchema>, in out StateId extends StateNodeIdentifier<States>, in out Context, in out Reenter extends boolean, in out Acceptance extends TransitionAcceptance> extends TransitionSelectorTargets<States, Events, Emits, StateId, Context, Reenter, Acceptance> {
|
|
3974
|
-
/** Declares a closed set of named destinations for one resolver. */
|
|
3975
|
-
readonly branches: <const Branches extends Readonly<Record<string, TransitionBranchInput>>>(branches: Branches & ValidateTransitionBranchRecord<NoInfer<Branches>>) => {
|
|
3976
|
-
/** Resolves exactly one declared branch after this transition is selected. */
|
|
3977
|
-
readonly resolve: TransitionBranchesResolveRequired<States, Events, Emits, StateId, Context, Reenter, Branches> & ("declinable" extends Acceptance ? TransitionBranchesResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Branches> : {});
|
|
3978
|
-
};
|
|
3979
|
-
}
|
|
3980
|
-
/** Inline transition declaration accepted by state and invocation handlers. */
|
|
3981
|
-
type TransitionBuilderInput<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance> = (to: TransitionSelector<States, Events, Emits, StateId, Context, Reenter, Acceptance>) => TransitionTyped<States, Events, Emits, StateId, Context, Reenter, Acceptance> & TransitionBuilderEvidence<any, Acceptance>;
|
|
3982
3793
|
type InvokeTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context> = TransitionConfig<States, Events, Emits, StateId, Context, true, TransitionAcceptance>;
|
|
3983
3794
|
type InvokeSource<Value, Context> = Value | ((context: Context) => Value);
|
|
3984
3795
|
/** Inline state-owned work that runs for the lifetime of its active state. */
|
|
3985
3796
|
interface InvokeOwned<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
|
|
3986
3797
|
readonly "~effect/Machine/InvokeOwner"?: Types.Covariant<readonly [States, Events, Emits, StateId, InputEvents, ParentEvents]>;
|
|
3987
3798
|
}
|
|
3988
|
-
/** Type evidence retained by a completed state-owned invocation. */
|
|
3989
|
-
interface InvokeTyped<Output, Error, Requirements, InitialError, Emits = never, ParentEvent = never, Outcomes = never> {
|
|
3990
|
-
readonly [InvokeTypeId]: {
|
|
3991
|
-
readonly output: Types.Covariant<Output>;
|
|
3992
|
-
readonly error: Types.Covariant<Error>;
|
|
3993
|
-
readonly requirements: Types.Covariant<Requirements>;
|
|
3994
|
-
readonly initialError: Types.Covariant<InitialError>;
|
|
3995
|
-
readonly emits: Types.Covariant<Emits>;
|
|
3996
|
-
readonly parentEvents: Types.Covariant<ParentEvent>;
|
|
3997
|
-
readonly outcomes: Types.Covariant<Outcomes>;
|
|
3998
|
-
};
|
|
3999
|
-
}
|
|
4000
3799
|
type StoredInvokeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & ({
|
|
4001
3800
|
readonly id: string;
|
|
4002
3801
|
readonly effect: (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<any, any, any>;
|
|
@@ -4074,137 +3873,6 @@ export declare namespace Machine {
|
|
|
4074
3873
|
type LogicServicesOf<Value> = Effect.Services<LogicInitialEffectOf<Value> | LogicRunEffectOf<Value>>;
|
|
4075
3874
|
type LogicOutputOf<Value> = Effect.Success<LogicRunEffectOf<Value>>;
|
|
4076
3875
|
type LogicInitialErrorOf<Value> = Effect.Error<LogicInitialEffectOf<Value>>;
|
|
4077
|
-
type RequiredInvokeChannel<Value, Channel extends string> = IsAny<Value> extends true ? Channel : [Value] extends [never] ? never : Channel;
|
|
4078
|
-
type InvokeBuilderResult<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes> = InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & InvokeTyped<Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes> & {
|
|
4079
|
-
readonly [InvokeBuilderTypeId]: true;
|
|
4080
|
-
};
|
|
4081
|
-
/** Lifecycle handlers exposed according to the selected invocation source. */
|
|
4082
|
-
type InvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Pending extends string, SnapshotHandler, Outcomes = never> = ([Pending] extends [never] ? InvokeBuilderResult<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes> : {}) & ("done" extends Pending ? {
|
|
4083
|
-
/** Handles successful completion and exposes the invocation output. */
|
|
4084
|
-
readonly onDone: <const Handler extends InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, Output, InputEvents, ParentEvents>>>(handler: Handler & InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, Output, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Exclude<Pending, "done">, SnapshotHandler, Outcomes | Handler>;
|
|
4085
|
-
} : {}) & ("failure" extends Pending ? {
|
|
4086
|
-
/** Handles typed failure and exposes the invocation error. */
|
|
4087
|
-
readonly onFailure: <const Handler extends InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, Error, InputEvents, ParentEvents>>>(handler: Handler & InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, Error, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Exclude<Pending, "failure">, SnapshotHandler, Outcomes | Handler>;
|
|
4088
|
-
} : {}) & ("element" extends Pending ? {
|
|
4089
|
-
/** Handles each backpressured element emitted by an invoked Stream. */
|
|
4090
|
-
readonly onElement: <const Handler extends InvokeTransition<States, Events, Emits, StateId, InvokeElementContext<States, Events, Emits, StateId, Element, InputEvents, ParentEvents>>>(handler: Handler & InvokeTransition<States, Events, Emits, StateId, InvokeElementContext<States, Events, Emits, StateId, Element, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Exclude<Pending, "element">, SnapshotHandler, Outcomes | Handler>;
|
|
4091
|
-
} : {}) & ([SnapshotHandler] extends [never] ? {} : {
|
|
4092
|
-
/** Handles each active snapshot published by invoked logic or a child machine. */
|
|
4093
|
-
readonly onSnapshot: <const Handler extends SnapshotHandler>(handler: Handler & SnapshotHandler) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Pending, never, Outcomes | Handler>;
|
|
4094
|
-
});
|
|
4095
|
-
type EffectInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Source extends (...args: ReadonlyArray<any>) => Effect.Effect<any, any, any>> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Effect.Success<ReturnType<Source>>, Effect.Error<ReturnType<Source>>, Effect.Services<ReturnType<Source>>, never, never, never, never, RequiredInvokeChannel<Effect.Success<ReturnType<Source>>, "done"> | RequiredInvokeChannel<Effect.Error<ReturnType<Source>>, "failure">, never>;
|
|
4096
|
-
type StreamInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Source extends (...args: ReadonlyArray<any>) => Stream.Stream<any, any, any>> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, void, Stream.Error<ReturnType<Source>>, Stream.Services<ReturnType<Source>>, never, never, never, Stream.Success<ReturnType<Source>>, "done" | RequiredInvokeChannel<Stream.Success<ReturnType<Source>>, "element"> | RequiredInvokeChannel<Stream.Error<ReturnType<Source>>, "failure">, never>;
|
|
4097
|
-
type LogicInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, ChildLogic> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, LogicOutputOf<ChildLogic>, LogicErrorOf<ChildLogic>, LogicServicesOf<ChildLogic>, LogicInitialErrorOf<ChildLogic>, never, never, never, RequiredInvokeChannel<LogicOutputOf<ChildLogic>, "done"> | RequiredInvokeChannel<LogicErrorOf<ChildLogic>, "failure">, InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, LogicStateOf<ChildLogic>, LogicErrorOf<ChildLogic>, LogicOutputOf<ChildLogic>, InputEvents, ParentEvents>>>;
|
|
4098
|
-
type ChildInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Child extends ChildMachine.Any, ChildDefinition extends Machine.Any = Child["machine"]> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output<ChildDefinition>, Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, Services<ChildDefinition>, InitialError<ChildDefinition>, EmittedEvent<ChildDefinition>, EventOf<Machine.ParentEvents<ChildDefinition>>, never, RequiredInvokeChannel<Output<ChildDefinition>, "done"> | RequiredInvokeChannel<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, "failure">, InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, Snapshot<Machine.States<ChildDefinition>>, Error<ChildDefinition>, Output<ChildDefinition>, InputEvents, ParentEvents>>>;
|
|
4099
|
-
/**
|
|
4100
|
-
* Selects state-owned work and begins its lifecycle-handler chain.
|
|
4101
|
-
*
|
|
4102
|
-
* Each source exposes exactly the lifecycle methods that it can produce. A
|
|
4103
|
-
* chain becomes returnable from `invoke` only after every reachable required
|
|
4104
|
-
* channel has been handled.
|
|
4105
|
-
*
|
|
4106
|
-
* **Example** (Invoking an Effect)
|
|
4107
|
-
*
|
|
4108
|
-
* ```ts
|
|
4109
|
-
* invoke: (from) =>
|
|
4110
|
-
* from.effect("load-user", () => loadUser).onDone((to) =>
|
|
4111
|
-
* to.branch.Ready().resolve(({ output, target }) => target.from({ user: output }))
|
|
4112
|
-
* ).onFailure((to) =>
|
|
4113
|
-
* to.branch.Failed().resolve(({ error, target }) => target.from({ error }))
|
|
4114
|
-
* )
|
|
4115
|
-
* ```
|
|
4116
|
-
*
|
|
4117
|
-
* @inlineType EffectInvokeBuilder
|
|
4118
|
-
* @inlineType StreamInvokeBuilder
|
|
4119
|
-
* @inlineType LogicInvokeBuilder
|
|
4120
|
-
* @inlineType ChildInvokeBuilder
|
|
4121
|
-
* @inlineType InvokeBuilder
|
|
4122
|
-
*
|
|
4123
|
-
* @category models
|
|
4124
|
-
* @since 0.18.0
|
|
4125
|
-
*/
|
|
4126
|
-
interface InvokeSelector<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
|
|
4127
|
-
/**
|
|
4128
|
-
* Starts a fresh Effect each time the owning state is entered.
|
|
4129
|
-
*
|
|
4130
|
-
* @param id Parent-local lifecycle identifier.
|
|
4131
|
-
* @param source Lazy Effect factory evaluated on every entry.
|
|
4132
|
-
*/
|
|
4133
|
-
readonly effect: <const Source extends (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, unknown, unknown>>(id: InvokeLifecycleId, source: Source) => EffectInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>;
|
|
4134
|
-
/**
|
|
4135
|
-
* Starts a fresh, backpressured Stream each time the owning state is entered.
|
|
4136
|
-
*
|
|
4137
|
-
* @param id Parent-local lifecycle identifier.
|
|
4138
|
-
* @param source Lazy Stream factory evaluated on every entry.
|
|
4139
|
-
*/
|
|
4140
|
-
readonly stream: <const Source extends (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Stream.Stream<unknown, unknown, any>>(id: InvokeLifecycleId, source: Source) => StreamInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>;
|
|
4141
|
-
/**
|
|
4142
|
-
* Starts a cancellable state-scoped timer.
|
|
4143
|
-
*
|
|
4144
|
-
* @param id Parent-local lifecycle identifier.
|
|
4145
|
-
* @param duration Duration input or context-dependent duration factory.
|
|
4146
|
-
*/
|
|
4147
|
-
readonly timer: (id: InvokeLifecycleId, duration: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, void, never, never, never, never, never, never, "done", never>;
|
|
4148
|
-
/**
|
|
4149
|
-
* Starts reusable process logic at a typed parent-local address.
|
|
4150
|
-
*
|
|
4151
|
-
* @param id Parent-local lifecycle identifier.
|
|
4152
|
-
* @param options Address and reusable logic value or factory.
|
|
4153
|
-
*/
|
|
4154
|
-
readonly logic: {
|
|
4155
|
-
<const Source extends (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => unknown, Address extends ChildAddress<never>>(id: InvokeLifecycleId, options: {
|
|
4156
|
-
/** Typed parent-local address used to send events to this logic. */
|
|
4157
|
-
readonly address: Address & ChildAddress.Compatibility<Address, LogicEventOf<ReturnType<NoInfer<Source>>>>;
|
|
4158
|
-
/** Context-dependent factory that returns reusable process logic. */
|
|
4159
|
-
readonly logic: Source;
|
|
4160
|
-
}, ..._validation: ReturnType<Source> extends {
|
|
4161
|
-
readonly initial: unknown;
|
|
4162
|
-
readonly run: unknown;
|
|
4163
|
-
} ? [] : [
|
|
4164
|
-
"logic factory must return Machine.Logic"
|
|
4165
|
-
]): LogicInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, ReturnType<Source>>;
|
|
4166
|
-
<const Source, Address extends ChildAddress<never>>(id: InvokeLifecycleId, options: {
|
|
4167
|
-
/** Typed parent-local address used to send events to this logic. */
|
|
4168
|
-
readonly address: Address & ChildAddress.Compatibility<Address, LogicEventOf<NoInfer<Source>>>;
|
|
4169
|
-
/** Reusable process logic started when the owning state enters. */
|
|
4170
|
-
readonly logic: Source;
|
|
4171
|
-
}, ..._validation: Source extends {
|
|
4172
|
-
readonly initial: unknown;
|
|
4173
|
-
readonly run: unknown;
|
|
4174
|
-
} ? [] : [
|
|
4175
|
-
"logic must implement Machine.Logic"
|
|
4176
|
-
]): LogicInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>;
|
|
4177
|
-
};
|
|
4178
|
-
/**
|
|
4179
|
-
* Starts a complete child statechart represented by a reusable descriptor.
|
|
4180
|
-
*
|
|
4181
|
-
* @param child Reusable descriptor created with `Machine.child`.
|
|
4182
|
-
* @param options Input construction for a child with a non-void input schema.
|
|
4183
|
-
*/
|
|
4184
|
-
readonly child: <const Child extends ChildMachine.Any>(child: Child & (Child["machine"] extends EnsureExecutable<Machine.States<Child["machine"]>, Machine.UnhandledStates<Child["machine"]>, Machine.OutputStates<Child["machine"]>> ? unknown : never), ...options: InputSchema<Child["machine"]> extends typeof Schema.Void ? [options?: {
|
|
4185
|
-
readonly input?: never;
|
|
4186
|
-
}] : [
|
|
4187
|
-
options: {
|
|
4188
|
-
/** Child input value or factory evaluated from the owning state context. */
|
|
4189
|
-
readonly input: InvokeSource<Input<Child["machine"]>, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
4190
|
-
}
|
|
4191
|
-
]) => ChildInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Child>;
|
|
4192
|
-
}
|
|
4193
|
-
/**
|
|
4194
|
-
* Inline invocation declaration accepted by an active state handler.
|
|
4195
|
-
*
|
|
4196
|
-
* Return one completed source chain or an array of completed chains. Source
|
|
4197
|
-
* computations and child descriptors may be extracted, but the chain stays
|
|
4198
|
-
* local to preserve the owning state and machine protocols.
|
|
4199
|
-
*
|
|
4200
|
-
* @category models
|
|
4201
|
-
* @since 0.18.0
|
|
4202
|
-
*/
|
|
4203
|
-
type InvokeBuilderInput<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = (from: InvokeSelector<States, Events, Emits, StateId, InputEvents, ParentEvents>) => (InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
|
|
4204
|
-
readonly [InvokeBuilderTypeId]: true;
|
|
4205
|
-
}) | ReadonlyArray<InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
|
|
4206
|
-
readonly [InvokeBuilderTypeId]: true;
|
|
4207
|
-
}>;
|
|
4208
3876
|
/** Output construction available to final and output-producing parallel states. */
|
|
4209
3877
|
type OutputHandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Context> = NodeByIdentifier<States, StateId> extends {
|
|
4210
3878
|
readonly output: Schema.Top;
|
|
@@ -4219,46 +3887,6 @@ export declare namespace Machine {
|
|
|
4219
3887
|
} ? OutputHandlerConfig<States, Events, StateId, ParallelOutputContext<States, Events, StateId>> : {
|
|
4220
3888
|
readonly output?: never;
|
|
4221
3889
|
};
|
|
4222
|
-
/**
|
|
4223
|
-
* Configuration accepted for a non-final state.
|
|
4224
|
-
*
|
|
4225
|
-
* **Example** (State actions, events, and invocation)
|
|
4226
|
-
*
|
|
4227
|
-
* ```ts
|
|
4228
|
-
* machine.handle({ states: {
|
|
4229
|
-
* Loading: {
|
|
4230
|
-
* entry: (_, enqueue) => enqueue.emit({ _tag: "Started" }),
|
|
4231
|
-
* invoke: (from) =>
|
|
4232
|
-
* from.effect("load", () => load).onDone((to) => to.branch.Ready()),
|
|
4233
|
-
* on: { Cancel: (to) => to.branch.Idle() }
|
|
4234
|
-
* }
|
|
4235
|
-
* } })
|
|
4236
|
-
* ```
|
|
4237
|
-
*
|
|
4238
|
-
* @inlineType ActiveOutputHandlerConfig
|
|
4239
|
-
* @inlineType OutputHandlerConfig
|
|
4240
|
-
*
|
|
4241
|
-
* @category models
|
|
4242
|
-
* @since 0.4.0
|
|
4243
|
-
*/
|
|
4244
|
-
type ActiveStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
|
|
4245
|
-
/** Runs synchronously when the state is entered and may enqueue commands. */
|
|
4246
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<any, any>;
|
|
4247
|
-
/** Runs synchronously before the state is exited and may enqueue commands. */
|
|
4248
|
-
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<any, any>;
|
|
4249
|
-
/** Starts state-owned Effect, Stream, timer, logic, or child lifecycles. */
|
|
4250
|
-
readonly invoke?: InvokeBuilderInput<States, Events, Emits, StateId, InputEvents, ParentEvents>;
|
|
4251
|
-
/** Eventless transition evaluated after the state becomes stable. */
|
|
4252
|
-
readonly always?: TransitionConfig<States, Events, Emits, StateId, AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, false, TransitionAcceptance>;
|
|
4253
|
-
/** Transition evaluated after this compound or parallel state completes. */
|
|
4254
|
-
readonly onDone?: TransitionConfig<States, Events, Emits, StateId, DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, false, TransitionAcceptance>;
|
|
4255
|
-
/** Event handlers keyed by the `_tag` of the machine's public or internal events. */
|
|
4256
|
-
readonly on?: {
|
|
4257
|
-
readonly [EventTag in TagOf<Events[number]>]?: TransitionConfig<States, Events, Emits, StateId, HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>, true, TransitionAcceptance>;
|
|
4258
|
-
};
|
|
4259
|
-
/** Supplies missing direct initial-child values required by implicit entry and shallow history. */
|
|
4260
|
-
readonly initialize?: StateInitializeHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>;
|
|
4261
|
-
} & ActiveOutputHandlerConfig<States, Events, StateId>;
|
|
4262
3890
|
/**
|
|
4263
3891
|
* Values constructed for a state's schema-valued direct initial children.
|
|
4264
3892
|
*
|
|
@@ -4367,36 +3995,9 @@ export declare namespace Machine {
|
|
|
4367
3995
|
readonly output?: never;
|
|
4368
3996
|
readonly initialize?: never;
|
|
4369
3997
|
}
|
|
4370
|
-
/**
|
|
4371
|
-
* Configuration accepted for a final state.
|
|
4372
|
-
*
|
|
4373
|
-
* @inlineType OutputHandlerConfig
|
|
4374
|
-
*
|
|
4375
|
-
* @category models
|
|
4376
|
-
* @since 0.4.0
|
|
4377
|
-
*/
|
|
4378
|
-
type FinalStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
|
|
4379
|
-
/** Runs synchronously when the final state is entered and may enqueue commands. */
|
|
4380
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<any, any>;
|
|
4381
|
-
readonly exit?: never;
|
|
4382
|
-
readonly always?: never;
|
|
4383
|
-
readonly onDone?: never;
|
|
4384
|
-
readonly on?: never;
|
|
4385
|
-
} & OutputHandlerConfig<States, Events, StateId, FinalOutputContext<States, Events, StateId>>;
|
|
4386
|
-
/**
|
|
4387
|
-
* Configuration accepted by `handle` for a state tag.
|
|
4388
|
-
*
|
|
4389
|
-
* @category models
|
|
4390
|
-
* @since 0.4.0
|
|
4391
|
-
*/
|
|
4392
|
-
type HandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = NodeByIdentifier<States, StateId> extends {
|
|
4393
|
-
readonly type: "final";
|
|
4394
|
-
} ? FinalStateConfig<States, Events, Emits, StateId, InputEvents, ParentEvents> : ActiveStateConfig<States, Events, Emits, StateId, E, R, InputEvents, ParentEvents>;
|
|
4395
|
-
type HandlerNodeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Path extends StateNodeIdentifier<States>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>> = Path extends ChoiceIdentifier<States> ? ChoiceStateConfig<States, Events, Emits, Path, InputEvents, ParentEvents> : Path extends StateIdentifier<States> ? HandlerConfig<States, Events, Emits, Path, E, R, InputEvents, ParentEvents> : never;
|
|
4396
3998
|
type HandlerChildren<Node> = Node extends {
|
|
4397
3999
|
readonly states: infer Children extends StateSchemas;
|
|
4398
4000
|
} ? Children : never;
|
|
4399
|
-
type HandlerNodeId<States extends StateSchemas, Path extends string> = Extract<Path, StateNodeIdentifier<States>>;
|
|
4400
4001
|
type HandlerConfigPart<Config> = {
|
|
4401
4002
|
readonly [Key in keyof Config as Key extends "states" ? never : Key]: Config[Key];
|
|
4402
4003
|
};
|
|
@@ -4416,25 +4017,6 @@ export declare namespace Machine {
|
|
|
4416
4017
|
} : {
|
|
4417
4018
|
readonly [Key in Path]?: Validation;
|
|
4418
4019
|
};
|
|
4419
|
-
/** Nested handler-tree structure shared by active and final state configs. */
|
|
4420
|
-
type HandlerNode<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<AllStates>> = HandlerNodeConfig<AllStates, Events, Emits, StateId, E, R, InputEvents, ParentEvents> & (StateId extends ChoiceIdentifier<AllStates> ? {
|
|
4421
|
-
readonly states?: never;
|
|
4422
|
-
readonly history?: never;
|
|
4423
|
-
} : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
|
|
4424
|
-
readonly states?: never;
|
|
4425
|
-
readonly history?: never;
|
|
4426
|
-
} : {
|
|
4427
|
-
/** Child-state handlers nested according to the declared state topology. */
|
|
4428
|
-
readonly states?: HandlerTree<AllStates, Children, Events, Emits, E, R, InputEvents, ParentEvents, Extract<StateId, StateIdentifier<AllStates>>>;
|
|
4429
|
-
/** First-use defaults keyed by direct history pseudo-state. */
|
|
4430
|
-
readonly history?: HistoryDefaultConfig<AllStates, Events, Emits, Extract<StateId, StateIdentifier<AllStates>>, Children>;
|
|
4431
|
-
} : {
|
|
4432
|
-
readonly states?: never;
|
|
4433
|
-
readonly history?: never;
|
|
4434
|
-
});
|
|
4435
|
-
type HandlerTree<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Prefix extends string> = {
|
|
4436
|
-
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]?: HandlerNode<AllStates, States[Key], Events, Emits, E, R, InputEvents, ParentEvents, HandlerNodeId<AllStates, JoinPath<Prefix, Key>>>;
|
|
4437
|
-
};
|
|
4438
4020
|
type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "initialize" | "invoke" | "on" | "onDone" | "output" | "states";
|
|
4439
4021
|
type HandlerValidationError<Message extends string, Path extends string, Detail = unknown> = {
|
|
4440
4022
|
readonly "~effect/Machine/HandlerError": readonly [message: Message, path: Path, detail: Detail];
|
|
@@ -4481,18 +4063,11 @@ export declare namespace Machine {
|
|
|
4481
4063
|
} ? Path : never : never;
|
|
4482
4064
|
type HandlerConfigInitialTargetPath<Config> = TransitionResultInitialTargetPath<EventHandlerReturn<Config> | AlwaysReturn<Config> | DoneReturn<Config> | ChoiceReturn<Config> | InvokeOutcomeReturn<InvokeReturn<Config>>>;
|
|
4483
4065
|
type RequiredInitializersForTargetPath<AllStates extends StateSchemas, Path> = string extends Path ? never : Path extends StateIdentifier<AllStates> ? InitializerClosureForNode<AllStates, NodeByIdentifier<AllStates, Path>, Path> : never;
|
|
4484
|
-
type HandlerInitializeValidationAtPath<Config, Path extends string> = HandlerConfigAtPath<Config, Path> extends infer StateConfig ? [StateConfig] extends [never] ? HandlerValidationAtPath<Path, {
|
|
4485
|
-
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
4486
|
-
}> : "initialize" extends keyof StateConfig ? never : HandlerValidationAtPath<Path, {
|
|
4487
|
-
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
4488
|
-
}> : never;
|
|
4489
|
-
type HandlerInitialTargetValidationForPaths<AllStates extends StateSchemas, Config, Required> = Types.UnionToIntersection<Required extends string ? HandlerInitializeValidationAtPath<Config, Required> : unknown>;
|
|
4490
4066
|
type HandlerTreeInitialTargetPath<Config> = string extends keyof Config ? never : Config extends object ? {
|
|
4491
4067
|
readonly [Key in keyof Config]: HandlerConfigInitialTargetPath<HandlerConfigPart<Config[Key]>> | (Config[Key] extends {
|
|
4492
4068
|
readonly states: infer Children;
|
|
4493
4069
|
} ? HandlerTreeInitialTargetPath<Children> : never);
|
|
4494
4070
|
}[keyof Config] : never;
|
|
4495
|
-
type HandlerInitialTargetValidation<AllStates extends StateSchemas, Config> = HandlerTreeInitialTargetPath<Config> extends infer TargetPath ? HandlerInitialTargetValidationForPaths<AllStates, Config, RequiredInitializersForTargetPath<AllStates, TargetPath>> : unknown;
|
|
4496
4071
|
type HandlerChildrenValidation<Node, Prefix extends string, Config> = "states" extends keyof Config ? Config extends {
|
|
4497
4072
|
readonly states?: infer ChildrenConfig;
|
|
4498
4073
|
} ? HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
|
|
@@ -4524,15 +4099,6 @@ export declare namespace Machine {
|
|
|
4524
4099
|
readonly invoke: HandlerValidationError<"Invoked child expects parent events not accepted by this machine", StateId, Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>>;
|
|
4525
4100
|
};
|
|
4526
4101
|
type HandlerRuntimeValidation<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends string, Config, Incompatible = keyof Config extends never ? never : IncompatibleRuntime<ConfigServices<HandlerConfigPart<Config>>, EventOf<Events>, EmittedEventOf<Emits>>> = [Incompatible] extends [never] ? unknown : HandlerValidationError<"Handler config requires an incompatible machine runtime", StateId, Incompatible>;
|
|
4527
|
-
type HandlerNodeValidationAtPath<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = [NodeConfig] extends [never] ? never : HandlerNodeValidation<AllStates, HandlerNodeByPath<AllStates, StateId>, Events, InputEvents, Emits, StateId, NodeConfig, AvailableOutputStates> extends infer Validation ? unknown extends Validation ? never : "" extends keyof AllStates ? StateId extends "" ? {
|
|
4528
|
-
readonly ""?: Validation;
|
|
4529
|
-
} : {
|
|
4530
|
-
readonly ""?: {
|
|
4531
|
-
readonly states: HandlerValidationAtPath<StateId, Validation>;
|
|
4532
|
-
};
|
|
4533
|
-
} : HandlerValidationAtPath<StateId, Validation> : never;
|
|
4534
|
-
type HandlerTreeNodeValidations<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = Types.UnionToIntersection<StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeValidationAtPath<AllStates, Events, InputEvents, Emits, Config, AvailableOutputStates, StateId> : never : never>;
|
|
4535
|
-
type HandlerTreeValidation<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = HandlerUnknownStateKeyValidation<AllStates, "", Config> & HandlerTreeNodeValidations<AllStates, Events, InputEvents, Emits, Config, AvailableOutputStates>;
|
|
4536
4102
|
type RootInitialTargetValidation<States extends StateSchemas, Config> = RequiredInitializersForTargetPath<States, HandlerTreeInitialTargetPath<{
|
|
4537
4103
|
readonly "": Config;
|
|
4538
4104
|
}>> extends infer Required ? Types.UnionToIntersection<Required extends string ? HandlerConfigAtPath<{
|
|
@@ -4579,17 +4145,626 @@ export declare namespace Machine {
|
|
|
4579
4145
|
};
|
|
4580
4146
|
type HandlerTreeEvidence<AllStates extends StateSchemas, Config> = StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeEvidence<AllStates, Config, StateId> : never : never;
|
|
4581
4147
|
type HandleTreeResult<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<AllStates>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<AllStates>, Output, OutputStates extends StateIdentifier<AllStates>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Config> = Machine<AllStates, Events, Input, Exclude<UnhandledStates, HandlerTreeEvidence<AllStates, Config>["stateId"]>, E | HandlerTreeEvidence<AllStates, Config>["error"], ExcludeCompatibleRuntime<R | HandlerTreeEvidence<AllStates, Config>["services"], EventOf<Events>, EmittedEventOf<Emits>>, InitialE, InitialR, FinalStates, Output, Emits, OutputStates | Extract<HandlerTreeEvidence<AllStates, Config>["outputState"], StateIdentifier<AllStates>>, InputEvents, ParentEvents>;
|
|
4148
|
+
type ObjectCompoundPath<S extends StateSchemas> = {
|
|
4149
|
+
readonly [P in StateIdentifier<S>]: NodeByIdentifier<S, P> extends {
|
|
4150
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4151
|
+
readonly states: StateSchemas;
|
|
4152
|
+
} ? P : never;
|
|
4153
|
+
}[StateIdentifier<S>];
|
|
4154
|
+
type LazyProgramValue = Effect.Effect<unknown, unknown, unknown> | Stream.Stream<unknown, unknown, unknown>;
|
|
4155
|
+
/** Registered lazy programs and their optional explicit input adapters. */
|
|
4156
|
+
type Program<Value> = Value | ((...args: never[]) => Value);
|
|
4157
|
+
type EffectSources = Readonly<Record<string, Program<Effect.Effect<unknown, unknown, unknown>>>>;
|
|
4158
|
+
type StreamSources = Readonly<Record<string, Program<Stream.Stream<unknown, unknown, unknown>>>>;
|
|
4159
|
+
type TimerSources = Readonly<Record<string, Program<Duration.Input>>>;
|
|
4160
|
+
type LogicSources = Readonly<Record<string, unknown>>;
|
|
4161
|
+
type ValidateLogicSources<Sources> = {
|
|
4162
|
+
readonly [K in keyof Sources]: InvokeResolvedSource<Sources[K]> extends {
|
|
4163
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4164
|
+
readonly initial: (...args: never[]) => Effect.Effect<unknown, unknown, unknown>;
|
|
4165
|
+
readonly run: (...args: never[]) => Effect.Effect<unknown, unknown, unknown>;
|
|
4166
|
+
} ? unknown : never;
|
|
4167
|
+
};
|
|
4168
|
+
type ChildSources = Readonly<Record<string, ChildMachine.Any>>;
|
|
4169
|
+
type ValidatePrograms<Sources> = {
|
|
4170
|
+
readonly [K in keyof Sources]: Sources[K] extends LazyProgramValue ? unknown : Sources[K] extends (...args: never[]) => unknown ? Parameters<Sources[K]>["length"] extends 1 ? unknown : never : unknown;
|
|
4171
|
+
};
|
|
4172
|
+
type ReferenceRoot<S extends StateSchemas> = "~effect/Machine/ExplicitInitial" extends keyof S[""] ? Extract<Omit<S[""], "~effect/Machine/ExplicitInitial">, StateNodeConfig> : Extract<S[""], StateNodeConfig>;
|
|
4173
|
+
type ReferenceAt<S extends StateSchemas, P extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = TargetReference<ReferenceRoot<S>, P, P extends HistoryIdentifier<S> ? "history" : P extends ChoiceIdentifier<S> ? "choice" : "state">;
|
|
4174
|
+
type ReferenceUnion<S extends StateSchemas, Paths extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = {
|
|
4175
|
+
readonly [P in Paths]: ReferenceAt<S, P>;
|
|
4176
|
+
}[Paths];
|
|
4177
|
+
type DestinationPath<S extends StateSchemas> = Exclude<StateNodeIdentifier<S>, "">;
|
|
4178
|
+
type RootSchemas<Root extends StateNodeConfig> = {
|
|
4179
|
+
readonly "": Root;
|
|
4180
|
+
};
|
|
4181
|
+
/** A topology declaration; its state values are constructed by a resolver. */
|
|
4182
|
+
type BranchDeclaration<Root extends StateNodeConfig, S extends StateSchemas = RootSchemas<Root>> = {
|
|
4183
|
+
/** Optional presentation label for this named branch. */
|
|
4184
|
+
readonly title?: string;
|
|
4185
|
+
} & ({
|
|
4186
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4187
|
+
readonly target: ReferenceUnion<S, DestinationPath<S>>;
|
|
4188
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4189
|
+
readonly update?: ReferenceUnion<S, ValuedStateIdentifier<S>>;
|
|
4190
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4191
|
+
readonly initial?: never;
|
|
4192
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4193
|
+
readonly history?: never;
|
|
4194
|
+
/** Accepts the event without selecting a new destination. */
|
|
4195
|
+
readonly none?: never;
|
|
4196
|
+
} | {
|
|
4197
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4198
|
+
readonly update: ReferenceUnion<S, ValuedStateIdentifier<S>>;
|
|
4199
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4200
|
+
readonly target?: never;
|
|
4201
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4202
|
+
readonly initial?: never;
|
|
4203
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4204
|
+
readonly history?: never;
|
|
4205
|
+
/** Accepts the event without selecting a new destination. */
|
|
4206
|
+
readonly none?: never;
|
|
4207
|
+
} | {
|
|
4208
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4209
|
+
readonly initial: ReferenceUnion<S, Exclude<ObjectCompoundPath<S>, "">>;
|
|
4210
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4211
|
+
readonly target?: never;
|
|
4212
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4213
|
+
readonly update?: never;
|
|
4214
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4215
|
+
readonly history?: never;
|
|
4216
|
+
/** Accepts the event without selecting a new destination. */
|
|
4217
|
+
readonly none?: never;
|
|
4218
|
+
} | {
|
|
4219
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4220
|
+
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
|
|
4221
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4222
|
+
readonly target?: never;
|
|
4223
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4224
|
+
readonly update?: never;
|
|
4225
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4226
|
+
readonly initial?: never;
|
|
4227
|
+
/** Accepts the event without selecting a new destination. */
|
|
4228
|
+
readonly none?: never;
|
|
4229
|
+
} | {
|
|
4230
|
+
/** Accepts the event without selecting a new destination. */
|
|
4231
|
+
readonly none: true;
|
|
4232
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4233
|
+
readonly target?: never;
|
|
4234
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4235
|
+
readonly update?: never;
|
|
4236
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4237
|
+
readonly initial?: never;
|
|
4238
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4239
|
+
readonly history?: never;
|
|
4240
|
+
});
|
|
4241
|
+
type BranchDefinitions<Root extends StateNodeConfig> = Readonly<Record<string, Readonly<Record<string, BranchDeclaration<Root>>>>>;
|
|
4242
|
+
/** Source programs and named topology declarations captured by a machine definition. */
|
|
4243
|
+
interface Registrations {
|
|
4244
|
+
/** Lazy Effects or functions with one required input, invoked by registered name. */
|
|
4245
|
+
readonly effects?: EffectSources;
|
|
4246
|
+
/** Lazy Streams or functions with one required input, invoked by registered name. */
|
|
4247
|
+
readonly streams?: StreamSources;
|
|
4248
|
+
/** Cancellable delays, supplied as durations or functions of one required input. */
|
|
4249
|
+
readonly timers?: TimerSources;
|
|
4250
|
+
/** Logic values or functions of one required input; their Effect channels remain inferred. */
|
|
4251
|
+
readonly logic?: LogicSources;
|
|
4252
|
+
/** Child machine descriptors registered for state-owned invocation. */
|
|
4253
|
+
readonly children?: ChildSources;
|
|
4254
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4255
|
+
readonly branches?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
4256
|
+
}
|
|
4257
|
+
type Registered<R, Kind extends PropertyKey> = Kind extends keyof R ? NonNullable<R[Kind]> : {};
|
|
4258
|
+
type AtBuilder<T, P extends string> = P extends "" ? T : P extends `${infer H}.${infer Rest}` ? H extends keyof T ? AtBuilder<T[H], Rest> : never : P extends keyof T ? T[P] : never;
|
|
4259
|
+
type BranchBuilderAt<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string> = AtBuilder<RootBuilder<BranchTargetBuilder<S, Src>>, P>;
|
|
4260
|
+
type RefPath<R> = R extends TargetReference<any, infer P, any> ? P : never;
|
|
4261
|
+
type SelectionOf<S extends StateSchemas, Src extends StateNodeIdentifier<S>, D> = D extends {
|
|
4262
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4263
|
+
readonly target: infer Ref;
|
|
4264
|
+
} ? RefPath<Ref> extends infer P extends StateNodeIdentifier<S> ? D extends {
|
|
4265
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4266
|
+
readonly update: infer Update;
|
|
4267
|
+
} ? RefPath<Update> extends infer Owner extends Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>> ? TargetSelection<UpdatingTargetBuilder<BranchBuilderAt<S, Src, P>, S, Owner>, P, "state", "branch"> : never : TargetSelection<BranchBuilderAt<S, Src, P>, P, P extends ChoiceIdentifier<S> ? "choice" : "state", "branch"> : never : D extends {
|
|
4268
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4269
|
+
readonly initial: infer Ref;
|
|
4270
|
+
} ? RefPath<Ref> extends infer P extends string ? BranchBuilderAt<S, Src, P> extends {
|
|
4271
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4272
|
+
readonly initial: infer B;
|
|
4273
|
+
} ? TargetSelection<B, P, "initial", "branch"> : never : never : D extends {
|
|
4274
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4275
|
+
readonly history: infer Ref;
|
|
4276
|
+
} ? RefPath<Ref> extends infer P extends string ? TargetSelection<AtBuilder<RootBuilder<HistoryTargetBuilder<S>>, P>, P, "history", "full"> : never : D extends {
|
|
4277
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4278
|
+
readonly update: infer Ref;
|
|
4279
|
+
} ? RefPath<Ref> extends infer P extends Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>> ? TargetSelection<StateUpdateBuilder<S, P>, P, "update", "branch"> : never : D extends {
|
|
4280
|
+
/** Accepts the event without selecting a new destination. */
|
|
4281
|
+
readonly none: true;
|
|
4282
|
+
} ? TargetSelection<() => NoTarget, never, "none", "local"> : never;
|
|
4283
|
+
type BuilderArgs<B, K extends PropertyKey> = K extends keyof B ? B[K] extends (...args: infer A) => unknown ? A : never : never;
|
|
4284
|
+
type ObjectConstruction<C, B> = {
|
|
4285
|
+
readonly [M in Extract<keyof B, "from" | "decoded">]: BuilderArgs<B, M> extends readonly [unknown?] ? {
|
|
4286
|
+
readonly [K in M]: (context: C) => BuilderArgs<B, M>[0];
|
|
4287
|
+
} & {
|
|
4288
|
+
readonly [K in Exclude<"from" | "decoded", M>]?: never;
|
|
4289
|
+
} : never;
|
|
4290
|
+
}[Extract<keyof B, "from" | "decoded">];
|
|
4291
|
+
type ObjectDefault<B> = B extends {
|
|
4292
|
+
/** Constructs schema make input from the typed source context. */
|
|
4293
|
+
readonly from: () => unknown;
|
|
4294
|
+
} | (() => unknown) ? {
|
|
4295
|
+
/** Constructs schema make input from the typed source context. */
|
|
4296
|
+
readonly from?: never; /** Supplies an already decoded schema value from the typed source context. */
|
|
4297
|
+
readonly decoded?: never;
|
|
4298
|
+
} : never;
|
|
4299
|
+
type ObjectPolicy<C, Reenter extends boolean, Acceptance extends TransitionAcceptance> = {
|
|
4300
|
+
/** Set to true to exit and reenter the handler source. */
|
|
4301
|
+
readonly reenter?: Reenter extends true ? boolean : never;
|
|
4302
|
+
/** Declines the transition before construction when the predicate returns false. */
|
|
4303
|
+
readonly guard?: "declinable" extends Acceptance ? ((context: C) => boolean) | undefined : never;
|
|
4304
|
+
};
|
|
4305
|
+
type InlineNodeConstruction<C, Node> = [NodeSchema<Node>] extends [never] ? {
|
|
4306
|
+
readonly from?: (context: C) => undefined;
|
|
4307
|
+
readonly decoded?: never;
|
|
4308
|
+
} : {
|
|
4309
|
+
readonly from: (context: C) => NodeMakeInput<Node>;
|
|
4310
|
+
readonly decoded?: never;
|
|
4311
|
+
} | {
|
|
4312
|
+
readonly decoded: (context: C) => NodeValue<Node>;
|
|
4313
|
+
readonly from?: never;
|
|
4314
|
+
} | ({} extends NodeMakeInput<Node> ? {
|
|
4315
|
+
readonly from?: never;
|
|
4316
|
+
readonly decoded?: never;
|
|
4317
|
+
} : never);
|
|
4318
|
+
type InlineDestinationConstruction<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends DestinationPath<S>, C> = P extends ChoiceIdentifier<S> ? {
|
|
4319
|
+
readonly from?: never;
|
|
4320
|
+
readonly decoded?: never;
|
|
4321
|
+
} : P extends StateIdentifier<S> ? NodeByIdentifier<S, P> extends {
|
|
4322
|
+
readonly states: StateSchemas;
|
|
4323
|
+
} ? [NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? ObjectConstruction<C, BranchBuilderAt<S, Src, P>> | ObjectDefault<BranchBuilderAt<S, Src, P>> : never : InlineNodeConstruction<C, NodeByIdentifier<S, P>> : never;
|
|
4324
|
+
type InlineDestination<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = {
|
|
4325
|
+
readonly [P in DestinationPath<S>]: {
|
|
4326
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4327
|
+
readonly target: ReferenceAt<S, P>;
|
|
4328
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4329
|
+
readonly update?: never;
|
|
4330
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4331
|
+
readonly initial?: never;
|
|
4332
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4333
|
+
readonly history?: never;
|
|
4334
|
+
/** Accepts the event without selecting a new destination. */
|
|
4335
|
+
readonly none?: never;
|
|
4336
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4337
|
+
readonly branches?: never;
|
|
4338
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4339
|
+
readonly resolve?: never;
|
|
4340
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4341
|
+
readonly declinable?: never;
|
|
4342
|
+
} & InlineDestinationConstruction<S, Src, P, C>;
|
|
4343
|
+
}[DestinationPath<S>];
|
|
4344
|
+
type InlinePairConstruction<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string, Owner extends ValuedStateIdentifier<S>, C> = P extends StateIdentifier<S> ? NodeByIdentifier<S, P> extends {
|
|
4345
|
+
readonly states: StateSchemas;
|
|
4346
|
+
} ? {
|
|
4347
|
+
readonly [M in Extract<keyof BranchBuilderAt<S, Src, P> & keyof StateUpdateBuilder<S, Owner>, "from" | "decoded">]: BuilderArgs<BranchBuilderAt<S, Src, P>, M> extends readonly [unknown?] ? {
|
|
4348
|
+
readonly [K in M]: (context: C) => {
|
|
4349
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4350
|
+
readonly target: BuilderArgs<BranchBuilderAt<S, Src, P>, M>[0];
|
|
4351
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4352
|
+
readonly update: BuilderArgs<StateUpdateBuilder<S, Owner>, M>[0];
|
|
4353
|
+
};
|
|
4354
|
+
} & {
|
|
4355
|
+
readonly [K in Exclude<"from" | "decoded", M>]?: never;
|
|
4356
|
+
} : never;
|
|
4357
|
+
}[Extract<keyof BranchBuilderAt<S, Src, P> & keyof StateUpdateBuilder<S, Owner>, "from" | "decoded">] : {
|
|
4358
|
+
readonly from: (context: C) => {
|
|
4359
|
+
readonly target: [NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? undefined : NodeMakeInput<NodeByIdentifier<S, P>>;
|
|
4360
|
+
readonly update: SchemaByIdentifier<S, Owner>["~type.make.in"];
|
|
4361
|
+
};
|
|
4362
|
+
readonly decoded?: never;
|
|
4363
|
+
} | ([NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? never : {
|
|
4364
|
+
readonly decoded: (context: C) => {
|
|
4365
|
+
readonly target: NodeValue<NodeByIdentifier<S, P>>;
|
|
4366
|
+
readonly update: StateByIdentifier<S, Owner>;
|
|
4367
|
+
};
|
|
4368
|
+
readonly from?: never;
|
|
4369
|
+
}) : never;
|
|
4370
|
+
type InlineCombined<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = Src extends ChoiceIdentifier<S> ? never : [
|
|
4371
|
+
Extract<ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>
|
|
4372
|
+
] extends [never] ? never : {
|
|
4373
|
+
readonly [P in DestinationPath<S>]: {
|
|
4374
|
+
readonly [Owner in Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>]: {
|
|
4375
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4376
|
+
readonly target: ReferenceAt<S, P>;
|
|
4377
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4378
|
+
readonly update: ReferenceAt<S, Owner>;
|
|
4379
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4380
|
+
readonly initial?: never;
|
|
4381
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4382
|
+
readonly history?: never;
|
|
4383
|
+
/** Accepts the event without selecting a new destination. */
|
|
4384
|
+
readonly none?: never;
|
|
4385
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4386
|
+
readonly branches?: never;
|
|
4387
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4388
|
+
readonly resolve?: never;
|
|
4389
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4390
|
+
readonly declinable?: never;
|
|
4391
|
+
} & InlinePairConstruction<S, Src, P, Owner, C>;
|
|
4392
|
+
}[Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>];
|
|
4393
|
+
}[DestinationPath<S>];
|
|
4394
|
+
type InlineUpdate<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = Src extends ChoiceIdentifier<S> ? never : {
|
|
4395
|
+
readonly [P in Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>]: {
|
|
4396
|
+
/** Set to true to exit and reenter the handler source. */
|
|
4397
|
+
readonly reenter?: P extends Src ? never : boolean;
|
|
4398
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4399
|
+
readonly update: ReferenceAt<S, P>;
|
|
4400
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4401
|
+
readonly target?: never;
|
|
4402
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4403
|
+
readonly initial?: never;
|
|
4404
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4405
|
+
readonly history?: never;
|
|
4406
|
+
/** Accepts the event without selecting a new destination. */
|
|
4407
|
+
readonly none?: never;
|
|
4408
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4409
|
+
readonly branches?: never;
|
|
4410
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4411
|
+
readonly resolve?: never;
|
|
4412
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4413
|
+
readonly declinable?: never;
|
|
4414
|
+
} & ObjectConstruction<C, StateUpdateBuilder<S, P>>;
|
|
4415
|
+
}[Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>];
|
|
4416
|
+
type InlineInitial<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = [
|
|
4417
|
+
Exclude<ObjectCompoundPath<S>, "">
|
|
4418
|
+
] extends [never] ? never : {
|
|
4419
|
+
readonly [P in Exclude<ObjectCompoundPath<S>, "">]: InitialTargetFactory<NodeByIdentifier<S, P>, P> extends infer B ? {
|
|
4420
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4421
|
+
readonly initial: ReferenceAt<S, P>;
|
|
4422
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4423
|
+
readonly target?: never;
|
|
4424
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4425
|
+
readonly update?: never;
|
|
4426
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4427
|
+
readonly history?: never;
|
|
4428
|
+
/** Accepts the event without selecting a new destination. */
|
|
4429
|
+
readonly none?: never;
|
|
4430
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4431
|
+
readonly branches?: never;
|
|
4432
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4433
|
+
readonly resolve?: never;
|
|
4434
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4435
|
+
readonly declinable?: never;
|
|
4436
|
+
} & (ObjectConstruction<C, B> | ObjectDefault<B>) : never;
|
|
4437
|
+
}[Exclude<ObjectCompoundPath<S>, "">];
|
|
4438
|
+
type BranchSelections<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
|
|
4439
|
+
readonly [K in Extract<keyof Group, string>]: {
|
|
4440
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4441
|
+
readonly target: SelectionOf<S, Src, Group[K]>;
|
|
4442
|
+
};
|
|
4443
|
+
};
|
|
4444
|
+
type ObjectBranchResolver<Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, C, B extends Readonly<Record<string, TransitionBranchInput>>, Declinable extends boolean> = (context: C & {
|
|
4445
|
+
readonly select: BranchSelectors<B>;
|
|
4446
|
+
} & DeclineCapability, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => BranchSelectionResult<B> | (Declinable extends true ? Declined : never);
|
|
4447
|
+
type InvalidBranchSelection<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
|
|
4448
|
+
readonly [K in keyof Group]: Src extends ChoiceIdentifier<S> ? Group[K] extends {
|
|
4449
|
+
/** Accepts the event without selecting a new destination. */
|
|
4450
|
+
readonly none: true;
|
|
4451
|
+
} | {
|
|
4452
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4453
|
+
readonly update: unknown;
|
|
4454
|
+
} ? K : [SelectionBuilder<SelectionOf<S, Src, Group[K]>>] extends [never] ? K : never : [SelectionBuilder<SelectionOf<S, Src, Group[K]>>] extends [never] ? K : never;
|
|
4455
|
+
}[keyof Group];
|
|
4456
|
+
type ObjectBranches<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Acceptance extends TransitionAcceptance> = {
|
|
4457
|
+
readonly [K in Extract<keyof Registered<R, "branches">, string>]: ([InvalidBranchSelection<S, Src, Registered<R, "branches">[K]>] extends [never] ? unknown : never) & {
|
|
4458
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4459
|
+
readonly branches: K;
|
|
4460
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4461
|
+
readonly target?: never;
|
|
4462
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4463
|
+
readonly update?: never;
|
|
4464
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4465
|
+
readonly initial?: never;
|
|
4466
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4467
|
+
readonly history?: never;
|
|
4468
|
+
/** Accepts the event without selecting a new destination. */
|
|
4469
|
+
readonly none?: never;
|
|
4470
|
+
/** Constructs schema make input from the typed source context. */
|
|
4471
|
+
readonly from?: never;
|
|
4472
|
+
/** Supplies an already decoded schema value from the typed source context. */
|
|
4473
|
+
readonly decoded?: never;
|
|
4474
|
+
} & {
|
|
4475
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4476
|
+
readonly declinable?: "declinable" extends Acceptance ? boolean : false;
|
|
4477
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4478
|
+
readonly resolve: ObjectBranchResolver<Ev, Em, C, BranchSelections<S, Src, Registered<R, "branches">[K]>, true>;
|
|
4479
|
+
};
|
|
4480
|
+
}[Extract<keyof Registered<R, "branches">, string>];
|
|
4582
4481
|
/**
|
|
4583
|
-
*
|
|
4482
|
+
* A transition with an inspectable destination and source-specific construction.
|
|
4483
|
+
*
|
|
4484
|
+
* @category models
|
|
4485
|
+
* @since 0.34.0
|
|
4486
|
+
*/
|
|
4487
|
+
type Transition<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = ObjectPolicy<C, Reenter, Acceptance> & (InlineDestination<S, Src, C> | InlineUpdate<S, Src, C> | InlineCombined<S, Src, C> | InlineInitial<S, Src, C> | {
|
|
4488
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4489
|
+
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
|
|
4490
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4491
|
+
readonly target?: never;
|
|
4492
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4493
|
+
readonly update?: never;
|
|
4494
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4495
|
+
readonly initial?: never;
|
|
4496
|
+
/** Accepts the event without selecting a new destination. */
|
|
4497
|
+
readonly none?: never;
|
|
4498
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4499
|
+
readonly branches?: never;
|
|
4500
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4501
|
+
readonly resolve?: never;
|
|
4502
|
+
/** Constructs schema make input from the typed source context. */
|
|
4503
|
+
readonly from?: never;
|
|
4504
|
+
/** Supplies an already decoded schema value from the typed source context. */
|
|
4505
|
+
readonly decoded?: never;
|
|
4506
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4507
|
+
readonly declinable?: never;
|
|
4508
|
+
} | (Src extends ChoiceIdentifier<S> ? never : {
|
|
4509
|
+
/** Accepts the event without selecting a new destination. */
|
|
4510
|
+
readonly none: true;
|
|
4511
|
+
/** Selects the declared descendant destination. Supply required values with from or decoded. */
|
|
4512
|
+
readonly target?: never;
|
|
4513
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4514
|
+
readonly update?: never;
|
|
4515
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4516
|
+
readonly initial?: never;
|
|
4517
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4518
|
+
readonly history?: never;
|
|
4519
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4520
|
+
readonly branches?: never;
|
|
4521
|
+
/** Constructs schema make input from the typed source context. */
|
|
4522
|
+
readonly from?: never;
|
|
4523
|
+
/** Supplies an already decoded schema value from the typed source context. */
|
|
4524
|
+
readonly decoded?: never;
|
|
4525
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4526
|
+
readonly declinable?: "declinable" extends Acceptance ? boolean : false;
|
|
4527
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4528
|
+
readonly resolve?: (context: C & DeclineCapability, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => undefined | Declined;
|
|
4529
|
+
}) | ObjectBranches<S, Src, C, Ev, Em, R, Acceptance>);
|
|
4530
|
+
type SourceValue<R, K extends PropertyKey> = {
|
|
4531
|
+
readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: K extends keyof Registered<R, Kind> ? Registered<R, Kind>[K] : never;
|
|
4532
|
+
}["effects" | "streams" | "timers" | "logic" | "children"];
|
|
4533
|
+
type SourceKind<R, K extends PropertyKey> = {
|
|
4534
|
+
readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: K extends keyof Registered<R, Kind> ? Kind : never;
|
|
4535
|
+
}["effects" | "streams" | "timers" | "logic" | "children"];
|
|
4536
|
+
type SourceKeys<R> = {
|
|
4537
|
+
readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: keyof Registered<R, Kind>;
|
|
4538
|
+
}["effects" | "streams" | "timers" | "logic" | "children"];
|
|
4539
|
+
type SourceInput<F, C> = F extends LazyProgramValue ? {
|
|
4540
|
+
readonly input?: never;
|
|
4541
|
+
} : F extends (...args: never[]) => unknown ? Parameters<F>["length"] extends 1 ? {
|
|
4542
|
+
/** Maps the owning state context to the registered source input. */
|
|
4543
|
+
readonly input: (context: C) => Parameters<F>[0];
|
|
4544
|
+
} : never : {
|
|
4545
|
+
/** Maps the owning state context to the registered source input. */
|
|
4546
|
+
readonly input?: never;
|
|
4547
|
+
};
|
|
4548
|
+
type ResolvedInvoke<R, K extends PropertyKey> = SourceKind<R, K> extends "effects" ? {
|
|
4549
|
+
readonly effect: () => InvokeResolvedSource<SourceValue<R, K>>;
|
|
4550
|
+
} : SourceKind<R, K> extends "streams" ? {
|
|
4551
|
+
readonly stream: () => InvokeResolvedSource<SourceValue<R, K>>;
|
|
4552
|
+
} : SourceKind<R, K> extends "timers" ? {
|
|
4553
|
+
readonly after: Duration.Input;
|
|
4554
|
+
} : SourceKind<R, K> extends "logic" ? {
|
|
4555
|
+
/** Logic values or functions of one required input; their Effect channels remain inferred. */
|
|
4556
|
+
readonly logic: InvokeResolvedSource<SourceValue<R, K>>;
|
|
4557
|
+
} : SourceKind<R, K> extends "children" ? {
|
|
4558
|
+
readonly child: SourceValue<R, K>;
|
|
4559
|
+
} & (SourceValue<R, K> extends ChildMachine<string, infer M> ? {
|
|
4560
|
+
readonly [InvokeTypeId]: {
|
|
4561
|
+
readonly error: Types.Covariant<Error<M> | ActionError<Services<M>>>;
|
|
4562
|
+
readonly initialError: Types.Covariant<InitialError<M>>;
|
|
4563
|
+
readonly requirements: Types.Covariant<Services<M>>;
|
|
4564
|
+
};
|
|
4565
|
+
} : never) : never;
|
|
4566
|
+
type RegisteredInvocationInput<R, K extends PropertyKey, C> = SourceKind<R, K> extends "children" ? SourceValue<R, K> extends ChildMachine<string, infer M> ? InputSchema<M> extends typeof Schema.Void ? {
|
|
4567
|
+
/** Maps the owning state context to the registered source input. */
|
|
4568
|
+
readonly input?: never;
|
|
4569
|
+
} : {
|
|
4570
|
+
/** Maps the owning state context to the registered source input. */
|
|
4571
|
+
readonly input: (context: C) => Input<M>;
|
|
4572
|
+
} : never : SourceInput<SourceValue<R, K>, C>;
|
|
4573
|
+
type ObjectOutcome<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R, V, Channel extends "onDone" | "onFailure" | "onElement" | "onSnapshot"> = [V] extends [never] ? {} : Channel extends "onDone" ? {
|
|
4574
|
+
/** Handles successful invocation or state completion with its exact output type. */
|
|
4575
|
+
readonly onDone: Transition<S, Src, InvokeDoneContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
|
|
4576
|
+
} : Channel extends "onFailure" ? {
|
|
4577
|
+
/** Handles the typed failure of the invoked source; required exactly when that channel is reachable. */
|
|
4578
|
+
readonly onFailure: Transition<S, Src, InvokeFailureContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
|
|
4579
|
+
} : Channel extends "onElement" ? {
|
|
4580
|
+
/** Handles each Stream element; required when the element type is reachable. */
|
|
4581
|
+
readonly onElement: Transition<S, Src, InvokeElementContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
|
|
4582
|
+
} : {
|
|
4583
|
+
/** Optionally handles active snapshots of invoked logic or a child machine. */
|
|
4584
|
+
readonly onSnapshot: Transition<S, Src, InvokeSnapshotContext<S, Ev, Em, Src, V, never, never, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
|
|
4585
|
+
};
|
|
4586
|
+
type RegisteredInvokeError<R, K extends PropertyKey> = SourceKind<R, K> extends "children" ? SourceValue<R, K> extends ChildMachine<string, infer M> ? Error<M> | ActionError<Services<M>> : never : InvokeRuntimeError<ResolvedInvoke<R, K>>;
|
|
4587
|
+
/**
|
|
4588
|
+
* A registered source invocation with its required input and reachable outcomes.
|
|
4589
|
+
*
|
|
4590
|
+
* @category models
|
|
4591
|
+
* @since 0.34.0
|
|
4592
|
+
*/
|
|
4593
|
+
type Invocation<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = {
|
|
4594
|
+
readonly [K in Extract<SourceKeys<R>, string>]: Types.Simplify<{
|
|
4595
|
+
/** Name of the source registered in make. */
|
|
4596
|
+
readonly src: K;
|
|
4597
|
+
} & (SourceKind<R, K> extends "children" ? {
|
|
4598
|
+
/** Lifecycle identifier; Effects, Streams, and timers default to their registered source name. */
|
|
4599
|
+
readonly id?: never; /** Typed runtime address required for invoked logic; child descriptors carry their own address. */
|
|
4600
|
+
readonly address?: never;
|
|
4601
|
+
} : SourceKind<R, K> extends "logic" ? {
|
|
4602
|
+
/** Lifecycle identifier; Effects, Streams, and timers default to their registered source name. */
|
|
4603
|
+
readonly id: InvokeLifecycleId;
|
|
4604
|
+
/** Typed runtime address required for invoked logic; child descriptors carry their own address. */
|
|
4605
|
+
readonly address: ChildAddress<LogicEventOf<InvokeResolvedSource<SourceValue<R, K>>>>;
|
|
4606
|
+
} : {
|
|
4607
|
+
/** Lifecycle identifier; Effects, Streams, and timers default to their registered source name. */
|
|
4608
|
+
readonly id?: InvokeLifecycleId; /** Typed runtime address required for invoked logic; child descriptors carry their own address. */
|
|
4609
|
+
readonly address?: never;
|
|
4610
|
+
}) & (SourceKind<R, K> extends "children" ? SourceValue<R, K> extends ChildMachine<string, infer M> ? M extends EnsureExecutable<States<M>, UnhandledStates<M>, OutputStates<M>> ? unknown : never : never : unknown) & RegisteredInvocationInput<R, K, InvokeContext<S, Ev, Em, Src, In, Pa>> & ObjectOutcome<S, Ev, Em, Src, In, Pa, R, InvokeOutput<ResolvedInvoke<R, K>>, "onDone"> & ObjectOutcome<S, Ev, Em, Src, In, Pa, R, RegisteredInvokeError<R, K>, "onFailure"> & ObjectOutcome<S, Ev, Em, Src, In, Pa, R, SourceKind<R, K> extends "streams" ? Stream.Success<Extract<InvokeResolvedSource<SourceValue<R, K>>, Stream.Stream<any, any, any>>> : never, "onElement"> & (SourceKind<R, K> extends "logic" | "children" ? Partial<ObjectOutcome<S, Ev, Em, Src, In, Pa, R, LogicStateOf<InvokeLogic<ResolvedInvoke<R, K>>>, "onSnapshot">> : {})>;
|
|
4611
|
+
}[Extract<SourceKeys<R>, string>];
|
|
4612
|
+
type ObjectLifecycle<S extends StateSchemas, Node, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>> = Src extends StateIdentifier<S> ? {
|
|
4613
|
+
/** Runs synchronously on entry and may enqueue commands. */
|
|
4614
|
+
readonly entry?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => StateActionResult<any, any>;
|
|
4615
|
+
} & (Node extends {
|
|
4616
|
+
readonly type: "final";
|
|
4617
|
+
} ? {
|
|
4618
|
+
/** Runs synchronously on exit and may enqueue commands. */
|
|
4619
|
+
readonly exit?: never; /** Constructs required values for the declared initial child or parallel regions. */
|
|
4620
|
+
readonly initialize?: never;
|
|
4621
|
+
} & OutputHandlerConfig<S, Ev, Src, FinalOutputContext<S, Ev, Src>> : {
|
|
4622
|
+
/** Runs synchronously on exit and may enqueue commands. */
|
|
4623
|
+
readonly exit?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => StateActionResult<any, any>;
|
|
4624
|
+
/** Constructs required values for the declared initial child or parallel regions. */
|
|
4625
|
+
readonly initialize?: StateInitializeHandler<S, Ev, Em, Src, In, Pa>;
|
|
4626
|
+
} & ActiveOutputHandlerConfig<S, Ev, Src>) : {
|
|
4627
|
+
/** Runs synchronously on entry and may enqueue commands. */
|
|
4628
|
+
readonly entry?: never; /** Runs synchronously on exit and may enqueue commands. */
|
|
4629
|
+
readonly exit?: never; /** Constructs required values for the declared initial child or parallel regions. */
|
|
4630
|
+
readonly initialize?: never; /** Constructs the decoded output declared by the state schema. */
|
|
4631
|
+
readonly output?: never;
|
|
4632
|
+
};
|
|
4633
|
+
/**
|
|
4634
|
+
* Handlers for a node of the declared root tree.
|
|
4635
|
+
*
|
|
4636
|
+
* @category models
|
|
4637
|
+
* @since 0.34.0
|
|
4638
|
+
*/
|
|
4639
|
+
type StateHandler<S extends StateSchemas, Node, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = ObjectLifecycle<S, Node, Ev, Em, Src, In, Pa> & (Src extends ChoiceIdentifier<S> ? {
|
|
4640
|
+
/** Required total transition for a transient choice state. */
|
|
4641
|
+
readonly choice: Transition<S, Src, ChoiceContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R>;
|
|
4642
|
+
/** Event handlers keyed by the public or internal event tag. */
|
|
4643
|
+
readonly on?: never;
|
|
4644
|
+
/** Eventless transition evaluated during stabilization. */
|
|
4645
|
+
readonly always?: never;
|
|
4646
|
+
/** Handles successful invocation or state completion with its exact output type. */
|
|
4647
|
+
readonly onDone?: never;
|
|
4648
|
+
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
4649
|
+
readonly invoke?: never;
|
|
4650
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4651
|
+
readonly states?: never;
|
|
4652
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4653
|
+
readonly history?: never;
|
|
4654
|
+
} : Src extends StateIdentifier<S> ? Node extends {
|
|
4655
|
+
readonly type: "final";
|
|
4656
|
+
} ? {
|
|
4657
|
+
/** Event handlers keyed by the public or internal event tag. */
|
|
4658
|
+
readonly on?: never;
|
|
4659
|
+
/** Eventless transition evaluated during stabilization. */
|
|
4660
|
+
readonly always?: never;
|
|
4661
|
+
/** Handles successful invocation or state completion with its exact output type. */
|
|
4662
|
+
readonly onDone?: never;
|
|
4663
|
+
/** Required total transition for a transient choice state. */
|
|
4664
|
+
readonly choice?: never;
|
|
4665
|
+
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
4666
|
+
readonly invoke?: never;
|
|
4667
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4668
|
+
readonly states?: never;
|
|
4669
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4670
|
+
readonly history?: never;
|
|
4671
|
+
} : {
|
|
4672
|
+
/** Event handlers keyed by the public or internal event tag. */
|
|
4673
|
+
readonly on?: {
|
|
4674
|
+
readonly [Tag in TagOf<Ev[number]>]?: Transition<S, Src, HandlerContext<S, Ev, Em, Src, Tag, never, never, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
|
|
4675
|
+
};
|
|
4676
|
+
/** Eventless transition evaluated during stabilization. */
|
|
4677
|
+
readonly always?: Transition<S, Src, AlwaysContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R, false, TransitionAcceptance>;
|
|
4678
|
+
/** Handles successful invocation or state completion with its exact output type. */
|
|
4679
|
+
readonly onDone?: Transition<S, Src, DoneContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R, false, TransitionAcceptance>;
|
|
4680
|
+
/** Required total transition for a transient choice state. */
|
|
4681
|
+
readonly choice?: never;
|
|
4682
|
+
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
4683
|
+
readonly invoke?: Invocation<S, Ev, Em, Src, In, Pa, R> | (ReadonlyArray<Invocation<S, Ev, Em, Src, In, Pa, R>> & {
|
|
4684
|
+
/** Name of the source registered in make. */
|
|
4685
|
+
readonly src?: never;
|
|
4686
|
+
});
|
|
4687
|
+
} & (Node extends {
|
|
4688
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4689
|
+
readonly states: infer Children extends StateSchemas;
|
|
4690
|
+
} ? {
|
|
4691
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4692
|
+
readonly states?: {
|
|
4693
|
+
readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]?: StateHandler<S, Children[K], Ev, Em, Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>, In, Pa, R>;
|
|
4694
|
+
};
|
|
4695
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4696
|
+
readonly history?: HistoryDefaultConfig<S, Ev, Em, Src, Children>;
|
|
4697
|
+
} : {
|
|
4698
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4699
|
+
readonly states?: never; /** Restores the declared history reference, using its fallback on first entry. */
|
|
4700
|
+
readonly history?: never;
|
|
4701
|
+
}) : never);
|
|
4702
|
+
type ValidateObjectTransition<T> = {
|
|
4703
|
+
readonly [K in Exclude<keyof T, "target" | "update" | "initial" | "history" | "none" | "branches" | "from" | "decoded" | "resolve" | "guard" | "reenter" | "declinable">]: never;
|
|
4704
|
+
} & (T extends {
|
|
4705
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4706
|
+
readonly declinable: infer D;
|
|
4707
|
+
} ? boolean extends D ? {
|
|
4708
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4709
|
+
readonly declinable: never;
|
|
4710
|
+
} : unknown : unknown) & (T extends {
|
|
4711
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4712
|
+
readonly declinable: true;
|
|
4713
|
+
} ? unknown : T extends {
|
|
4714
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4715
|
+
readonly resolve: (...args: any[]) => infer Result;
|
|
4716
|
+
} ? [Extract<Result, Declined>] extends [never] ? unknown : {
|
|
4717
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4718
|
+
readonly resolve: never;
|
|
4719
|
+
} : unknown);
|
|
4720
|
+
type AllowedInvokeChannels<R, K extends PropertyKey> = ([InvokeOutput<ResolvedInvoke<R, K>>] extends [never] ? never : "onDone") | ([RegisteredInvokeError<R, K>] extends [never] ? never : "onFailure") | (SourceKind<R, K> extends "streams" ? [Stream.Success<Extract<InvokeResolvedSource<SourceValue<R, K>>, Stream.Stream<any, any, any>>>] extends [never] ? never : "onElement" : never) | (SourceKind<R, K> extends "logic" | "children" ? "onSnapshot" : never);
|
|
4721
|
+
type ValidateObjectInvoke<I, R> = I extends ReadonlyArray<unknown> ? {
|
|
4722
|
+
readonly [K in keyof I]: ValidateObjectInvoke<I[K], R>;
|
|
4723
|
+
} : I extends {
|
|
4724
|
+
/** Name of the source registered in make. */
|
|
4725
|
+
readonly src: infer Src extends PropertyKey;
|
|
4726
|
+
} ? {
|
|
4727
|
+
readonly [K in keyof I]: K extends AllowedInvokeChannels<R, Src> ? ValidateObjectTransition<I[K]> : K extends "src" | "id" | "address" | "input" ? unknown : never;
|
|
4728
|
+
} : never;
|
|
4729
|
+
type ObjectDeclarations<C> = Extract<keyof C, "on" | "always" | "onDone" | "choice" | "invoke"> | (C extends {
|
|
4730
|
+
readonly states: infer Children;
|
|
4731
|
+
} ? {
|
|
4732
|
+
readonly [K in keyof Children]: ObjectDeclarations<Children[K]>;
|
|
4733
|
+
}[keyof Children] : never);
|
|
4734
|
+
type ValidateObjectConfig<C, R> = [ObjectDeclarations<C>] extends [never] ? unknown : {
|
|
4735
|
+
readonly [K in keyof C]: K extends "states" ? {
|
|
4736
|
+
readonly [P in keyof C[K]]: ValidateObjectConfig<C[K][P], R>;
|
|
4737
|
+
} : K extends "on" ? {
|
|
4738
|
+
readonly [P in keyof C[K]]: ValidateObjectTransition<C[K][P]>;
|
|
4739
|
+
} : K extends "always" | "onDone" | "choice" ? ValidateObjectTransition<C[K]> : K extends "invoke" ? ValidateObjectInvoke<C[K], R> : unknown;
|
|
4740
|
+
};
|
|
4741
|
+
type NormalizeObjectInvoke<I, R> = I extends ReadonlyArray<unknown> ? {
|
|
4742
|
+
readonly [K in keyof I]: NormalizeObjectInvoke<I[K], R>;
|
|
4743
|
+
} : I extends {
|
|
4744
|
+
/** Name of the source registered in make. */
|
|
4745
|
+
readonly src: infer K extends PropertyKey;
|
|
4746
|
+
} ? Omit<I, "src"> & ResolvedInvoke<R, K> : I;
|
|
4747
|
+
type NormalizeObjectConfig<C, R> = [SourceKeys<R>] extends [never] ? C : {
|
|
4748
|
+
readonly [K in keyof C]: K extends "states" ? {
|
|
4749
|
+
readonly [P in keyof C[K]]: NormalizeObjectConfig<C[K][P], R>;
|
|
4750
|
+
} : K extends "invoke" ? NormalizeObjectInvoke<C[K], R> : C[K];
|
|
4751
|
+
};
|
|
4752
|
+
type HandlerShape<C, H> = {
|
|
4753
|
+
readonly [K in keyof C]: K extends keyof H ? K extends "states" ? {
|
|
4754
|
+
readonly [P in keyof C[K]]: P extends keyof NonNullable<H[K]> ? HandlerShape<C[K][P], NonNullable<NonNullable<H[K]>[P]>> : never;
|
|
4755
|
+
} : H[K] : never;
|
|
4756
|
+
} & Omit<H, keyof C>;
|
|
4757
|
+
/**
|
|
4758
|
+
* Adds object handlers while checking topology, protocols, invocation outcomes, and readiness.
|
|
4584
4759
|
*
|
|
4585
4760
|
* @category combinators
|
|
4586
|
-
* @since 0.
|
|
4761
|
+
* @since 0.34.0
|
|
4587
4762
|
*/
|
|
4588
|
-
interface Handler<
|
|
4589
|
-
<const
|
|
4590
|
-
readonly "": NoInfer<
|
|
4591
|
-
}>["outputState"], StateIdentifier<
|
|
4592
|
-
readonly "":
|
|
4763
|
+
interface Handler<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, I extends Schema.Top, IE, IR, Final extends StateIdentifier<S>, Out, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> {
|
|
4764
|
+
<const C>(config: C & (C extends (...args: never[]) => unknown ? never : unknown) & ([Ev[number] | keyof Registered<R, "branches"> | SourceKeys<R>] extends [never] ? StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R> : HandlerShape<C, StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R>>) & ValidateObjectConfig<NoInfer<C>, R> & RootHandlerValidation<S, Ev, In, Em, NormalizeObjectConfig<NoInfer<C>, R>, Extract<HandlerTreeEvidence<S, {
|
|
4765
|
+
readonly "": NormalizeObjectConfig<NoInfer<C>, R>;
|
|
4766
|
+
}>["outputState"], StateIdentifier<S>>>): HandleTreeResult<S, Ev, Em, I, StateIdentifier<S>, never, never, IE, IR, Final, Out, never, In, Pa, {
|
|
4767
|
+
readonly "": NormalizeObjectConfig<C, R>;
|
|
4593
4768
|
}>;
|
|
4594
4769
|
}
|
|
4595
4770
|
/**
|
|
@@ -4613,12 +4788,19 @@ export declare namespace Machine {
|
|
|
4613
4788
|
* @since 0.4.0
|
|
4614
4789
|
*/
|
|
4615
4790
|
interface StateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
|
|
4791
|
+
/** Runs synchronously on entry and may enqueue commands. */
|
|
4616
4792
|
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<E, R>;
|
|
4793
|
+
/** Runs synchronously on exit and may enqueue commands. */
|
|
4617
4794
|
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<E, R>;
|
|
4795
|
+
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
4618
4796
|
readonly invoke?: StoredInvokeDefinition<States, Events, Emits, StateId>;
|
|
4797
|
+
/** Eventless transition evaluated during stabilization. */
|
|
4619
4798
|
readonly always?: TransitionConfig<States, Events, Emits, StateId, AlwaysContext<States, Events, Emits, StateId>, false, TransitionAcceptance>;
|
|
4799
|
+
/** Handles successful invocation or state completion with its exact output type. */
|
|
4620
4800
|
readonly onDone?: TransitionConfig<States, Events, Emits, StateId, DoneContext<States, Events, Emits, StateId>, false, TransitionAcceptance>;
|
|
4801
|
+
/** Constructs the decoded output declared by the state schema. */
|
|
4621
4802
|
readonly output?: ((context: FinalOutputContext<States, Events, StateId>) => unknown) | ((context: ParallelOutputContext<States, Events, StateId>) => unknown);
|
|
4803
|
+
/** Event handlers keyed by the public or internal event tag. */
|
|
4622
4804
|
readonly on?: EventHandlerMap<States, Events, Emits, StateId, EventTag, E, R>;
|
|
4623
4805
|
}
|
|
4624
4806
|
/**
|
|
@@ -4654,6 +4836,7 @@ export declare namespace Snapshot {
|
|
|
4654
4836
|
} ? State | (State extends {
|
|
4655
4837
|
readonly state: infer Child;
|
|
4656
4838
|
} ? Node<Child> : State extends {
|
|
4839
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4657
4840
|
readonly states: infer Regions;
|
|
4658
4841
|
} ? Node<Regions[keyof Regions]> : never) : never;
|
|
4659
4842
|
/** Every valid absolute path in a logical snapshot type. */
|
|
@@ -4736,7 +4919,71 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
4736
4919
|
* @since 0.15.0
|
|
4737
4920
|
*/
|
|
4738
4921
|
export declare const state: StateConstructor;
|
|
4739
|
-
|
|
4922
|
+
/**
|
|
4923
|
+
* An opaque reference to one node in a declared state tree.
|
|
4924
|
+
*
|
|
4925
|
+
* @category models
|
|
4926
|
+
* @since 0.34.0
|
|
4927
|
+
*/
|
|
4928
|
+
export interface TargetReference<Root extends Machine.StateNodeConfig, Path extends string, Kind extends "state" | "choice" | "history"> {
|
|
4929
|
+
readonly [internal.TargetReferenceTypeId]: {
|
|
4930
|
+
readonly root: {
|
|
4931
|
+
readonly node: Root;
|
|
4932
|
+
};
|
|
4933
|
+
readonly path: Path;
|
|
4934
|
+
readonly kind: Kind;
|
|
4935
|
+
};
|
|
4936
|
+
}
|
|
4937
|
+
type TargetReferenceTree<Root extends Machine.StateNodeConfig, Node, Path extends string> = TargetReference<Root, Path, Node extends {
|
|
4938
|
+
readonly type: "history";
|
|
4939
|
+
} ? "history" : Node extends {
|
|
4940
|
+
readonly type: "choice";
|
|
4941
|
+
} ? "choice" : "state"> & (Node extends {
|
|
4942
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4943
|
+
readonly states: infer Children;
|
|
4944
|
+
} ? {
|
|
4945
|
+
readonly [Key in Extract<keyof Children, string>]: TargetReferenceTree<Root, Children[Key], Machine.JoinPath<Path, Key>>;
|
|
4946
|
+
} : {});
|
|
4947
|
+
/**
|
|
4948
|
+
* References for every path in a declared root tree.
|
|
4949
|
+
*
|
|
4950
|
+
* @category models
|
|
4951
|
+
* @since 0.34.0
|
|
4952
|
+
*/
|
|
4953
|
+
export interface Targets<Root extends Machine.StateNodeConfig> {
|
|
4954
|
+
/** Root data owner and the starting point for descendant state references. */
|
|
4955
|
+
readonly root: TargetReferenceTree<Root, Root, "">;
|
|
4956
|
+
}
|
|
4957
|
+
/**
|
|
4958
|
+
* Derives immutable state references from a root descriptor.
|
|
4959
|
+
*
|
|
4960
|
+
* References follow the declared tree: `targets.root.Checkout.Review`.
|
|
4961
|
+
* Creating references does not construct state values or start machine work.
|
|
4962
|
+
*
|
|
4963
|
+
* @category constructors
|
|
4964
|
+
* @since 0.34.0
|
|
4965
|
+
*/
|
|
4966
|
+
export declare const targets: <const Root extends Machine.StateNodeConfig>(root: State<Root>) => Targets<Root>;
|
|
4967
|
+
type UniqueSourceNames<F, S, T, L, C> = [
|
|
4968
|
+
Extract<keyof F, keyof S | keyof T | keyof L | keyof C> | Extract<keyof S, keyof T | keyof L | keyof C> | Extract<keyof T, keyof L | keyof C> | Extract<keyof L, keyof C>
|
|
4969
|
+
] extends [never] ? unknown : {
|
|
4970
|
+
readonly "~effect/Machine/DuplicateSourceName": never;
|
|
4971
|
+
};
|
|
4972
|
+
type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined, Effects extends Machine.EffectSources, Streams extends Machine.StreamSources, Timers extends Machine.TimerSources, Logics extends Machine.LogicSources, Children extends Machine.ChildSources, Branches extends Machine.BranchDefinitions<Root>> = {
|
|
4973
|
+
/** Lazy Effects or functions with one required input, invoked by registered name. */
|
|
4974
|
+
readonly effects?: Effects & Machine.ValidatePrograms<Effects>;
|
|
4975
|
+
/** Lazy Streams or functions with one required input, invoked by registered name. */
|
|
4976
|
+
readonly streams?: Streams & Machine.ValidatePrograms<Streams>;
|
|
4977
|
+
/** Cancellable delays, supplied as durations or functions of one required input. */
|
|
4978
|
+
readonly timers?: Timers & Machine.ValidatePrograms<Timers>;
|
|
4979
|
+
/** Logic values or functions of one required input; their Effect channels remain inferred. */
|
|
4980
|
+
readonly logic?: Logics & Machine.ValidatePrograms<Logics> & Machine.ValidateLogicSources<NoInfer<Logics>>;
|
|
4981
|
+
/** Child machine descriptors registered for state-owned invocation. */
|
|
4982
|
+
readonly children?: Children;
|
|
4983
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4984
|
+
readonly branches?: Branches & {
|
|
4985
|
+
readonly [K in keyof Branches]: ValidateTransitionBranchRecord<NoInfer<Branches[K]>>;
|
|
4986
|
+
};
|
|
4740
4987
|
/** Stable definition identifier used by inspection and visualization. */
|
|
4741
4988
|
readonly id?: string;
|
|
4742
4989
|
/** State topology and value schemas, captured by a `Machine.state` descriptor. */
|
|
@@ -4755,37 +5002,53 @@ type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends Readon
|
|
|
4755
5002
|
/** Schema used to decode input before initial-state construction. */
|
|
4756
5003
|
readonly input?: Input;
|
|
4757
5004
|
};
|
|
4758
|
-
type MakeResult<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined
|
|
5005
|
+
type MakeResult<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined, Effects extends Machine.EffectSources, Streams extends Machine.StreamSources, Timers extends Machine.TimerSources, Logics extends Machine.LogicSources, Children extends Machine.ChildSources, Branches extends Readonly<Record<string, Readonly<Record<string, unknown>>>>> = Definition<{
|
|
4759
5006
|
readonly "": Root;
|
|
4760
5007
|
}, readonly [...InputEvents, ...InternalEvents], Input, InitialE, InitialR, Machine.FinalStateFromDefinition<{
|
|
4761
5008
|
readonly "": Root;
|
|
4762
5009
|
}>, Machine.TerminalOutput<{
|
|
4763
5010
|
readonly "": Root;
|
|
4764
|
-
}>, Emits, InputEvents, Machine.ParentEventsOf<ParentDeclaration
|
|
5011
|
+
}>, Emits, InputEvents, Machine.ParentEventsOf<ParentDeclaration>, {
|
|
5012
|
+
/** Lazy Effects or functions with one required input, invoked by registered name. */
|
|
5013
|
+
readonly effects: Effects;
|
|
5014
|
+
/** Lazy Streams or functions with one required input, invoked by registered name. */
|
|
5015
|
+
readonly streams: Streams;
|
|
5016
|
+
/** Cancellable delays, supplied as durations or functions of one required input. */
|
|
5017
|
+
readonly timers: Timers;
|
|
5018
|
+
/** Logic values or functions of one required input; their Effect channels remain inferred. */
|
|
5019
|
+
readonly logic: Logics;
|
|
5020
|
+
/** Child machine descriptors registered for state-owned invocation. */
|
|
5021
|
+
readonly children: Children;
|
|
5022
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
5023
|
+
readonly branches: Branches;
|
|
5024
|
+
}>;
|
|
4765
5025
|
type RootInitialization<Root extends Machine.StateNodeConfig, Input> = {
|
|
4766
5026
|
readonly initialConfiguration?: never;
|
|
4767
5027
|
} & (Machine.NodeSchema<Root> extends never ? {
|
|
5028
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4768
5029
|
readonly initial?: Machine.RootInitialBuilderInput<Root, Input>;
|
|
4769
5030
|
} : {} extends NodeMakeInput<Root> ? {
|
|
5031
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4770
5032
|
readonly initial?: Machine.RootInitialBuilderInput<Root, Input>;
|
|
4771
5033
|
} : {
|
|
5034
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4772
5035
|
readonly initial: Machine.RootInitialBuilderInput<Root, Input>;
|
|
4773
5036
|
});
|
|
4774
5037
|
/** @inline */
|
|
4775
5038
|
interface Make {
|
|
4776
5039
|
/** @param config Complete starting configuration, including root and descendant values. */
|
|
4777
|
-
<const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration> & {
|
|
5040
|
+
<const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined, const Effects extends Machine.EffectSources = {}, const Streams extends Machine.StreamSources = {}, const Timers extends Machine.TimerSources = {}, const Logics extends Machine.LogicSources = {}, const Children extends Machine.ChildSources = {}, const Branches extends Machine.BranchDefinitions<NoInfer<Root>> = {}>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches> & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>> & {
|
|
4778
5041
|
/** Mutually exclusive with a complete initial configuration. */
|
|
4779
5042
|
readonly initial?: never;
|
|
4780
5043
|
/** Constructs the complete initial root configuration, overriding child defaults. */
|
|
4781
5044
|
readonly initialConfiguration: Machine.RootConfigurationBuilderInput<NoInfer<Root>, Input["Type"]>;
|
|
4782
5045
|
}): MakeResult<Root & {
|
|
4783
5046
|
readonly "~effect/Machine/ExplicitInitial": true;
|
|
4784
|
-
}, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>;
|
|
5047
|
+
}, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches>;
|
|
4785
5048
|
/** @param config Complete schema-first machine definition. */
|
|
4786
|
-
<const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration> & Exclude<RootInitialization<NoInfer<Root>, Input["Type"]>, {
|
|
5049
|
+
<const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined, const Effects extends Machine.EffectSources = {}, const Streams extends Machine.StreamSources = {}, const Timers extends Machine.TimerSources = {}, const Logics extends Machine.LogicSources = {}, const Children extends Machine.ChildSources = {}, const Branches extends Machine.BranchDefinitions<NoInfer<Root>> = {}>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches> & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>> & Exclude<RootInitialization<NoInfer<Root>, Input["Type"]>, {
|
|
4787
5050
|
readonly initialConfiguration: unknown;
|
|
4788
|
-
}>): MakeResult<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>;
|
|
5051
|
+
}>): MakeResult<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches>;
|
|
4789
5052
|
}
|
|
4790
5053
|
/**
|
|
4791
5054
|
* Creates a schema-first machine definition.
|
|
@@ -4828,6 +5091,7 @@ interface Make {
|
|
|
4828
5091
|
*
|
|
4829
5092
|
* const States = Machine.state({ initial: "Count", states: { Count } })
|
|
4830
5093
|
* const Events = Machine.eventsFromSchemas(Increment)
|
|
5094
|
+
* const targets = Machine.targets(States)
|
|
4831
5095
|
*
|
|
4832
5096
|
* const counter = Machine.make({
|
|
4833
5097
|
* root: States,
|
|
@@ -4836,9 +5100,10 @@ interface Make {
|
|
|
4836
5100
|
* }).handle({ states: {
|
|
4837
5101
|
* Count: {
|
|
4838
5102
|
* on: {
|
|
4839
|
-
* Increment:
|
|
4840
|
-
*
|
|
4841
|
-
*
|
|
5103
|
+
* Increment: {
|
|
5104
|
+
* update: targets.root.Count,
|
|
5105
|
+
* decoded: ({ event, state }) => new Count({ value: state.value + event.by })
|
|
5106
|
+
* }
|
|
4842
5107
|
* }
|
|
4843
5108
|
* }
|
|
4844
5109
|
* } })
|
|
@@ -5093,17 +5358,16 @@ type TransitionBranchRecordError<Message extends string, Key extends PropertyKey
|
|
|
5093
5358
|
readonly "~effect/Machine/TransitionBranchRecordError": Message;
|
|
5094
5359
|
readonly key: Key;
|
|
5095
5360
|
};
|
|
5096
|
-
type InvalidStaticTransitionBranchKey<Branches> = Extract<keyof Branches, "" | number | symbol>;
|
|
5097
|
-
type
|
|
5098
|
-
readonly [
|
|
5099
|
-
readonly target:
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
} ?
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
] extends [never] ? unknown : TransitionBranchRecordError<"Updating targets require a direct resolver", InvalidUpdatingTransitionBranchKey<Branches>> : TransitionBranchRecordError<"Branch keys must be non-empty, non-index strings", InvalidStaticTransitionBranchKey<Branches>>;
|
|
5361
|
+
type InvalidStaticTransitionBranchKey<Branches> = Extract<keyof Branches, "" | number | symbol | `${number}` | "NaN" | "Infinity" | "-Infinity">;
|
|
5362
|
+
type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never] ? TransitionBranchRecordError<"Branch records must contain at least one branch"> : [InvalidStaticTransitionBranchKey<Branches>] extends [never] ? {
|
|
5363
|
+
readonly [K in keyof Branches]: {
|
|
5364
|
+
readonly [Extra in Exclude<keyof Branches[K], "target" | "update" | "initial" | "history" | "none" | "title">]: never;
|
|
5365
|
+
} & (Branches[K] extends {
|
|
5366
|
+
readonly title: "";
|
|
5367
|
+
} ? {
|
|
5368
|
+
readonly title: never;
|
|
5369
|
+
} : unknown);
|
|
5370
|
+
} : TransitionBranchRecordError<"Branch keys must be non-empty, non-numeric strings", InvalidStaticTransitionBranchKey<Branches>>;
|
|
5107
5371
|
/**
|
|
5108
5372
|
* Plans the initial state for a machine without executing machine commands.
|
|
5109
5373
|
*
|
|
@@ -5163,9 +5427,11 @@ export declare const planInitial: <const States extends Machine.StateSchemas, co
|
|
|
5163
5427
|
}>;
|
|
5164
5428
|
} & ({
|
|
5165
5429
|
readonly done: true;
|
|
5430
|
+
/** Constructs the decoded output declared by the state schema. */
|
|
5166
5431
|
readonly output: Output;
|
|
5167
5432
|
} | {
|
|
5168
5433
|
readonly done: false;
|
|
5434
|
+
/** Constructs the decoded output declared by the state schema. */
|
|
5169
5435
|
readonly output: undefined;
|
|
5170
5436
|
}), InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError, never>;
|
|
5171
5437
|
/**
|
|
@@ -5300,7 +5566,7 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
5300
5566
|
* events: Machine.eventsFromSchemas(),
|
|
5301
5567
|
* internalEvents,
|
|
5302
5568
|
* initialConfiguration: (root) => root.resolve(({ target }) => target.from((to) => to.Idle.from()))
|
|
5303
|
-
* }).handle({ states: { Idle: { on: { Loaded:
|
|
5569
|
+
* }).handle({ states: { Idle: { on: { Loaded: { none: true } } } } })
|
|
5304
5570
|
*
|
|
5305
5571
|
* export const canLoad = Effect.gen(function*() {
|
|
5306
5572
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -5342,6 +5608,7 @@ export declare const can: {
|
|
|
5342
5608
|
* class On extends Schema.TaggedClass<On>("On")("On", {}) {}
|
|
5343
5609
|
* class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {}
|
|
5344
5610
|
* const States = Machine.state({ initial: "Off", states: { Off, On } })
|
|
5611
|
+
* const targets = Machine.targets(States)
|
|
5345
5612
|
* const machine = Machine.make({
|
|
5346
5613
|
* root: States,
|
|
5347
5614
|
* events: Machine.eventsFromSchemas(Toggle),
|
|
@@ -5349,8 +5616,7 @@ export declare const can: {
|
|
|
5349
5616
|
* }).handle({ states: {
|
|
5350
5617
|
* Off: {
|
|
5351
5618
|
* on: {
|
|
5352
|
-
* Toggle:
|
|
5353
|
-
* to.branch.On().resolve(({ target }) => target.from())
|
|
5619
|
+
* Toggle: { target: targets.root.On }
|
|
5354
5620
|
* }
|
|
5355
5621
|
* },
|
|
5356
5622
|
* On: {}
|
|
@@ -5385,9 +5651,11 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
5385
5651
|
}>;
|
|
5386
5652
|
} & ({
|
|
5387
5653
|
readonly done: true;
|
|
5654
|
+
/** Constructs the decoded output declared by the state schema. */
|
|
5388
5655
|
readonly output: Output;
|
|
5389
5656
|
} | {
|
|
5390
5657
|
readonly done: false;
|
|
5658
|
+
/** Constructs the decoded output declared by the state schema. */
|
|
5391
5659
|
readonly output: undefined;
|
|
5392
5660
|
}), E | InfiniteTransitionError | MachineSchemaDecodeError, never>;
|
|
5393
5661
|
/**
|
|
@@ -5419,6 +5687,7 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
5419
5687
|
* @since 0.4.0
|
|
5420
5688
|
*/
|
|
5421
5689
|
export declare const logic: <State, Event = never, Output = void, Error = never, Requirements = never, InitialError = never, InitialRequirements = never>(options: {
|
|
5690
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
5422
5691
|
readonly initial: State | ((scope: Logic.Scope<Event>) => Effect.Effect<State, InitialError, InitialRequirements>);
|
|
5423
5692
|
readonly run: (context: Logic.Context<State, Event>) => Effect.Effect<Output, Error, Requirements>;
|
|
5424
5693
|
}) => Logic<State, Event, Error, Requirements | InitialRequirements, Output, InitialError>;
|
|
@@ -5466,7 +5735,7 @@ export declare const childAddress: <Event = never>(id: string) => ChildAddress<E
|
|
|
5466
5735
|
* This Effect requires a managed process runtime. A named child id must be
|
|
5467
5736
|
* unique for the current parent until that child stops.
|
|
5468
5737
|
*
|
|
5469
|
-
*
|
|
5738
|
+
* Register logic in `make({ logic })` and use `invoke: { src, id, address, ...outcomes }` for children
|
|
5470
5739
|
* that start and stop with that state.
|
|
5471
5740
|
* @see {@link sendTo} for sending events to named children.
|
|
5472
5741
|
* @category runtime
|