@typeonce/effect-machine 0.13.0 → 0.14.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 +74 -26
- package/dist/Machine.d.ts +379 -188
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +119 -53
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +14 -6
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/machine.d.ts +3 -1
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +306 -26
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +13 -0
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +15 -7
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/topology.d.ts +12 -0
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +17 -10
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/exploration.d.ts.map +1 -1
- package/dist/internal/testing/machine/exploration.js +11 -2
- package/dist/internal/testing/machine/exploration.js.map +1 -1
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +72 -66
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/transitionCoverage.d.ts +20 -0
- package/dist/internal/testing/machine/transitionCoverage.d.ts.map +1 -0
- package/dist/internal/testing/machine/transitionCoverage.js +80 -0
- package/dist/internal/testing/machine/transitionCoverage.js.map +1 -0
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +171 -33
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +97 -22
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +58 -16
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +4 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +4 -1
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +12 -3
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +12 -3
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/docs/agent-guide.md +139 -57
- package/package.json +1 -1
- package/src/Machine.ts +750 -336
- package/src/internal/machine/executionPlan.ts +22 -7
- package/src/internal/machine/machine.ts +407 -33
- package/src/internal/machine/planner.ts +44 -13
- package/src/internal/machine/topology.ts +38 -12
- package/src/internal/testing/machine/exploration.ts +10 -2
- package/src/internal/testing/machine/finiteModel.ts +106 -73
- package/src/internal/testing/machine/transitionCoverage.ts +116 -0
- package/src/internal/testing/machine/verification.ts +216 -58
- package/src/testing/MachineTest.ts +118 -28
- package/src/unstable/cluster/ClusterMachine.ts +4 -1
- package/src/unstable/reactivity/AtomMachine.ts +12 -3
package/src/Machine.ts
CHANGED
|
@@ -53,6 +53,7 @@ declare const MachineTypeId: unique symbol
|
|
|
53
53
|
declare const EventConstructionTypeId: unique symbol
|
|
54
54
|
declare const EmittedEventConstructionTypeId: unique symbol
|
|
55
55
|
declare const EventProtocolTypeId: unique symbol
|
|
56
|
+
declare const TransitionCaseTypeId: unique symbol
|
|
56
57
|
|
|
57
58
|
const ChildMachineLogicTypeId: typeof internal.ChildMachineLogicTypeId = internal.ChildMachineLogicTypeId
|
|
58
59
|
|
|
@@ -258,6 +259,8 @@ export interface Machine<
|
|
|
258
259
|
|
|
259
260
|
/** @internal */
|
|
260
261
|
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>
|
|
262
|
+
/** @internal */
|
|
263
|
+
readonly initialDefinition: Machine.InitialDefinition
|
|
261
264
|
}
|
|
262
265
|
|
|
263
266
|
export {
|
|
@@ -537,6 +540,7 @@ type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Run
|
|
|
537
540
|
: never
|
|
538
541
|
|
|
539
542
|
const InvokeTypeId: typeof internal.InvokeTypeId = internal.InvokeTypeId
|
|
543
|
+
const TransitionTypeId: typeof internal.TransitionTypeId = internal.TransitionTypeId
|
|
540
544
|
|
|
541
545
|
type StateDefinitionError<
|
|
542
546
|
Message extends string,
|
|
@@ -2411,6 +2415,8 @@ export declare namespace Machine {
|
|
|
2411
2415
|
readonly invoke: any
|
|
2412
2416
|
/** @internal */
|
|
2413
2417
|
readonly initial: any
|
|
2418
|
+
/** @internal */
|
|
2419
|
+
readonly initialDefinition: InitialDefinition
|
|
2414
2420
|
}
|
|
2415
2421
|
|
|
2416
2422
|
/**
|
|
@@ -2891,15 +2897,15 @@ export declare namespace Machine {
|
|
|
2891
2897
|
* @category utility types
|
|
2892
2898
|
* @since 0.4.0
|
|
2893
2899
|
*/
|
|
2894
|
-
|
|
2900
|
+
type InitialBuilder<States extends StateSchemas> = InitialSnapshotBuilderWithPrefix<States>
|
|
2895
2901
|
|
|
2896
2902
|
/**
|
|
2897
|
-
* State definitions and snapshot
|
|
2903
|
+
* State definitions and snapshot access helpers returned by `defineStates`.
|
|
2898
2904
|
*
|
|
2899
2905
|
* **Details**
|
|
2900
2906
|
*
|
|
2901
2907
|
* The `states` property is the original state tree and can be passed directly
|
|
2902
|
-
* to `make`. The
|
|
2908
|
+
* to `make`. The remaining helpers match and read snapshots for the same
|
|
2903
2909
|
* state tree.
|
|
2904
2910
|
*
|
|
2905
2911
|
* @category models
|
|
@@ -2909,9 +2915,6 @@ export declare namespace Machine {
|
|
|
2909
2915
|
/** Original state tree supplied to {@link defineStates}. */
|
|
2910
2916
|
readonly states: States
|
|
2911
2917
|
|
|
2912
|
-
/** Type-safe builders for constructing valid initial snapshots. */
|
|
2913
|
-
readonly initial: InitialBuilder<States>
|
|
2914
|
-
|
|
2915
2918
|
/**
|
|
2916
2919
|
* Returns the decoded value for an active state path. The supplied
|
|
2917
2920
|
* snapshot may be a complete root snapshot or a snapshot previously
|
|
@@ -3158,31 +3161,50 @@ export declare namespace Machine {
|
|
|
3158
3161
|
readonly outcome: "done" | "failure" | "snapshot"
|
|
3159
3162
|
}
|
|
3160
3163
|
|
|
3161
|
-
/**
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3164
|
+
/** Static topology selected by a transition branch. */
|
|
3165
|
+
export interface TransitionTargetSelection<
|
|
3166
|
+
Path extends string | undefined = string | undefined,
|
|
3167
|
+
Kind extends Topology.TargetSelectionKind = Topology.TargetSelectionKind,
|
|
3168
|
+
Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined
|
|
3169
|
+
> {
|
|
3170
|
+
readonly path: Path
|
|
3171
|
+
readonly kind: Kind
|
|
3172
|
+
readonly scope: Scope
|
|
3173
|
+
}
|
|
3174
|
+
|
|
3175
|
+
/** One statically captured branch of a transition definition. */
|
|
3176
|
+
export type TransitionBranch<Path extends string = string> =
|
|
3177
|
+
| {
|
|
3178
|
+
readonly type: "direct"
|
|
3179
|
+
readonly target: Path | undefined
|
|
3180
|
+
readonly selection: TransitionTargetSelection<Path | undefined>
|
|
3181
|
+
}
|
|
3169
3182
|
| {
|
|
3170
|
-
readonly type: "
|
|
3183
|
+
readonly type: "case"
|
|
3184
|
+
readonly title: string
|
|
3185
|
+
readonly target: Path | undefined
|
|
3186
|
+
readonly selection: TransitionTargetSelection<Path | undefined>
|
|
3171
3187
|
}
|
|
3172
3188
|
| {
|
|
3173
|
-
readonly type: "
|
|
3174
|
-
readonly
|
|
3189
|
+
readonly type: "otherwise"
|
|
3190
|
+
readonly target: Path | undefined
|
|
3191
|
+
readonly selection: TransitionTargetSelection<Path | undefined>
|
|
3175
3192
|
}
|
|
3176
3193
|
|
|
3194
|
+
/** The statically selected root entry for machine startup. */
|
|
3195
|
+
export interface InitialDefinition<Path extends string = string> {
|
|
3196
|
+
readonly target: Path
|
|
3197
|
+
readonly selection: TransitionTargetSelection<Path, "state" | "initial", "initial">
|
|
3198
|
+
}
|
|
3199
|
+
|
|
3177
3200
|
/**
|
|
3178
3201
|
* Inspectable registration for a transition handler.
|
|
3179
3202
|
*
|
|
3180
3203
|
* **Details**
|
|
3181
3204
|
*
|
|
3182
|
-
*
|
|
3183
|
-
*
|
|
3184
|
-
*
|
|
3185
|
-
* reentry behavior are available without executing the handler.
|
|
3205
|
+
* Every branch exposes its selected target without executing its predicate
|
|
3206
|
+
* or resolver. A compound local or branch target covers its descendants;
|
|
3207
|
+
* `undefined` identifies an explicitly targetless branch.
|
|
3186
3208
|
*
|
|
3187
3209
|
* @category models
|
|
3188
3210
|
* @since 0.4.0
|
|
@@ -3195,7 +3217,7 @@ export declare namespace Machine {
|
|
|
3195
3217
|
readonly source: SourcePath
|
|
3196
3218
|
readonly trigger: TransitionTrigger<EventTag>
|
|
3197
3219
|
readonly reenter: boolean
|
|
3198
|
-
readonly
|
|
3220
|
+
readonly branches: ReadonlyArray<TransitionBranch<TargetPath>>
|
|
3199
3221
|
}
|
|
3200
3222
|
|
|
3201
3223
|
/**
|
|
@@ -3225,9 +3247,14 @@ export declare namespace Machine {
|
|
|
3225
3247
|
readonly source: SourcePath
|
|
3226
3248
|
readonly trigger: TransitionTrigger<EventTag>
|
|
3227
3249
|
readonly reenter: boolean
|
|
3228
|
-
/**
|
|
3250
|
+
/** Zero-based index of the selected static branch. */
|
|
3251
|
+
readonly branchIndex: number
|
|
3252
|
+
/** Path returned by the handler, including a choice or history pseudo-state. */
|
|
3229
3253
|
readonly target: TargetPath | undefined
|
|
3230
|
-
/**
|
|
3254
|
+
/**
|
|
3255
|
+
* Concrete path used after resolving choice, initial, or history routing.
|
|
3256
|
+
* Choice microsteps retain each intermediate pseudo-state edge separately.
|
|
3257
|
+
*/
|
|
3231
3258
|
readonly resolvedTarget: TargetPath | undefined
|
|
3232
3259
|
}
|
|
3233
3260
|
|
|
@@ -4057,9 +4084,7 @@ export declare namespace Machine {
|
|
|
4057
4084
|
* Opaque result returned by an explicitly targetless transition.
|
|
4058
4085
|
*
|
|
4059
4086
|
* The transition remains handled and retains its queued commands, raised
|
|
4060
|
-
* events, and emitted events, but selects no concrete destination.
|
|
4061
|
-
* `targets` constrain only concrete destinations, so this result is always
|
|
4062
|
-
* permitted from ordinary transition handlers.
|
|
4087
|
+
* events, and emitted events, but selects no concrete destination.
|
|
4063
4088
|
*
|
|
4064
4089
|
* @category models
|
|
4065
4090
|
* @since 0.10.0
|
|
@@ -4216,8 +4241,7 @@ export declare namespace Machine {
|
|
|
4216
4241
|
*
|
|
4217
4242
|
* The event or lifecycle outcome is handled and queued operations are
|
|
4218
4243
|
* retained, while the current state configuration remains the transition
|
|
4219
|
-
* result.
|
|
4220
|
-
* because those paths are an upper bound rather than an exhaustive result.
|
|
4244
|
+
* result.
|
|
4221
4245
|
*
|
|
4222
4246
|
* @since 0.10.0
|
|
4223
4247
|
*/
|
|
@@ -4258,6 +4282,159 @@ export declare namespace Machine {
|
|
|
4258
4282
|
readonly history: HistoryTargetBuilder<States>
|
|
4259
4283
|
}
|
|
4260
4284
|
|
|
4285
|
+
/**
|
|
4286
|
+
* Opaque exact destination selected while a machine definition is captured.
|
|
4287
|
+
* The selection contains topology only; state values are constructed later
|
|
4288
|
+
* by the selected branch's resolver.
|
|
4289
|
+
*
|
|
4290
|
+
* @category models
|
|
4291
|
+
* @since 0.14.0
|
|
4292
|
+
*/
|
|
4293
|
+
export interface TargetSelection<
|
|
4294
|
+
out Result,
|
|
4295
|
+
out Path extends string | undefined = string | undefined,
|
|
4296
|
+
out Kind extends Topology.TargetSelectionKind = Topology.TargetSelectionKind
|
|
4297
|
+
> {
|
|
4298
|
+
readonly [Topology.TargetSelectionTypeId]: typeof Topology.TargetSelectionTypeId
|
|
4299
|
+
readonly kind: Kind
|
|
4300
|
+
readonly scope: Topology.TargetSelectionScope | undefined
|
|
4301
|
+
readonly path: Path
|
|
4302
|
+
readonly "~effect/Machine/TargetSelectionResult"?: Types.Covariant<Result>
|
|
4303
|
+
}
|
|
4304
|
+
|
|
4305
|
+
type SelectionMethod<Builder, Path extends string, Kind extends Topology.TargetSelectionKind = "state"> = () =>
|
|
4306
|
+
TargetSelection<Builder, Path, Kind>
|
|
4307
|
+
|
|
4308
|
+
type InitialSelectionMethod<Builder, Path extends string> = Builder extends { readonly initial: infer Initial } ? {
|
|
4309
|
+
readonly initial: SelectionMethod<Initial, Path, "initial">
|
|
4310
|
+
}
|
|
4311
|
+
: {}
|
|
4312
|
+
|
|
4313
|
+
type SelectionTreeWithPrefix<
|
|
4314
|
+
AllStates extends StateSchemas,
|
|
4315
|
+
States extends StateSchemas,
|
|
4316
|
+
Prefix extends string,
|
|
4317
|
+
Scope extends "local" | "branch",
|
|
4318
|
+
Builder
|
|
4319
|
+
> = {
|
|
4320
|
+
readonly [Key in Extract<ActiveStateKey<States> | ChoiceStateKey<States>, keyof Builder>]: SelectionNode<
|
|
4321
|
+
AllStates,
|
|
4322
|
+
States[Key],
|
|
4323
|
+
JoinPath<Prefix, Key>,
|
|
4324
|
+
Scope,
|
|
4325
|
+
Builder[Key]
|
|
4326
|
+
>
|
|
4327
|
+
}
|
|
4328
|
+
|
|
4329
|
+
type SelectionNode<
|
|
4330
|
+
AllStates extends StateSchemas,
|
|
4331
|
+
Node,
|
|
4332
|
+
Path extends string,
|
|
4333
|
+
Scope extends "local" | "branch",
|
|
4334
|
+
Builder
|
|
4335
|
+
> = Node extends ChoiceStateNodeConfig ? SelectionMethod<
|
|
4336
|
+
Builder,
|
|
4337
|
+
Path,
|
|
4338
|
+
"choice"
|
|
4339
|
+
>
|
|
4340
|
+
: Node extends { readonly states: infer Children extends StateSchemas } ?
|
|
4341
|
+
& SelectionMethod<Builder, Path>
|
|
4342
|
+
& InitialSelectionMethod<Builder, Path>
|
|
4343
|
+
& SelectionTreeWithPrefix<AllStates, Children, Path, Scope, Builder>
|
|
4344
|
+
: SelectionMethod<Builder, Path>
|
|
4345
|
+
|
|
4346
|
+
type FullSelectionNode<
|
|
4347
|
+
AllStates extends StateSchemas,
|
|
4348
|
+
Node,
|
|
4349
|
+
Path extends StateIdentifier<AllStates>,
|
|
4350
|
+
Builder
|
|
4351
|
+
> = Node extends { readonly states: StateSchemas } ?
|
|
4352
|
+
& SelectionMethod<Builder, Path>
|
|
4353
|
+
& InitialSelectionMethod<Builder, Path>
|
|
4354
|
+
: SelectionMethod<Builder, Path>
|
|
4355
|
+
|
|
4356
|
+
type FullTargetSelector<States extends StateSchemas> = {
|
|
4357
|
+
readonly [Key in Extract<ActiveStateKey<States>, keyof FullTargetBuilder<States>>]: FullSelectionNode<
|
|
4358
|
+
States,
|
|
4359
|
+
States[Key],
|
|
4360
|
+
Extract<Key, StateIdentifier<States>>,
|
|
4361
|
+
FullTargetBuilder<States>[Key]
|
|
4362
|
+
>
|
|
4363
|
+
}
|
|
4364
|
+
|
|
4365
|
+
type BranchTargetSelector<
|
|
4366
|
+
States extends StateSchemas,
|
|
4367
|
+
Source extends StateNodeIdentifier<States>,
|
|
4368
|
+
Root extends string = Source extends `${infer Head}.${string}` ? Head : Source
|
|
4369
|
+
> = Root extends ActiveStateKey<States> ? Root extends keyof BranchTargetBuilder<States, Source> ? {
|
|
4370
|
+
readonly [Key in Root]: SelectionNode<
|
|
4371
|
+
States,
|
|
4372
|
+
States[Key],
|
|
4373
|
+
Key,
|
|
4374
|
+
"branch",
|
|
4375
|
+
BranchTargetBuilder<States, Source>[Key]
|
|
4376
|
+
>
|
|
4377
|
+
}
|
|
4378
|
+
: {}
|
|
4379
|
+
: {}
|
|
4380
|
+
|
|
4381
|
+
type LocalTargetSelector<
|
|
4382
|
+
States extends StateSchemas,
|
|
4383
|
+
Source extends StateNodeIdentifier<States>
|
|
4384
|
+
> = NearestCompoundScope<States, Source> extends infer Scope extends StateIdentifier<States> ?
|
|
4385
|
+
ChildrenOf<States, Scope> extends infer Children extends StateSchemas ?
|
|
4386
|
+
LocalTargetBuilder<States, Source> extends infer Builder ?
|
|
4387
|
+
& SelectionTreeWithPrefix<States, Children, Scope, "local", Builder>
|
|
4388
|
+
& ("with" extends keyof Builder ? {
|
|
4389
|
+
readonly with: SelectionMethod<Builder["with"], Scope>
|
|
4390
|
+
}
|
|
4391
|
+
: {})
|
|
4392
|
+
: {}
|
|
4393
|
+
: {}
|
|
4394
|
+
: {}
|
|
4395
|
+
|
|
4396
|
+
type HistorySelectionTree<
|
|
4397
|
+
AllStates extends StateSchemas,
|
|
4398
|
+
States extends StateSchemas,
|
|
4399
|
+
Prefix extends string,
|
|
4400
|
+
Builder
|
|
4401
|
+
> = {
|
|
4402
|
+
readonly [Key in Extract<HistoryContainingKey<States>, keyof Builder>]: States[Key] extends HistoryStateNodeConfig ?
|
|
4403
|
+
SelectionMethod<
|
|
4404
|
+
Builder[Key],
|
|
4405
|
+
JoinPath<Prefix, Key>,
|
|
4406
|
+
"history"
|
|
4407
|
+
>
|
|
4408
|
+
: States[Key] extends { readonly states: infer Children extends StateSchemas } ? HistorySelectionTree<
|
|
4409
|
+
AllStates,
|
|
4410
|
+
Children,
|
|
4411
|
+
JoinPath<Prefix, Key>,
|
|
4412
|
+
Builder[Key]
|
|
4413
|
+
>
|
|
4414
|
+
: never
|
|
4415
|
+
}
|
|
4416
|
+
|
|
4417
|
+
/** Definition-time topology selector available to an ordinary transition. */
|
|
4418
|
+
export interface TargetSelector<
|
|
4419
|
+
States extends StateSchemas,
|
|
4420
|
+
Source extends StateNodeIdentifier<States>
|
|
4421
|
+
> {
|
|
4422
|
+
readonly none: SelectionMethod<TargetBuilder<States, Source>["none"], never, "none">
|
|
4423
|
+
readonly local: LocalTargetSelector<States, Source>
|
|
4424
|
+
readonly branch: BranchTargetSelector<States, Source>
|
|
4425
|
+
readonly full: FullTargetSelector<States>
|
|
4426
|
+
readonly history: HistorySelectionTree<States, States, "", HistoryTargetBuilder<States>>
|
|
4427
|
+
}
|
|
4428
|
+
|
|
4429
|
+
/** Definition-time selector that can choose only a valid top-level initial entry. */
|
|
4430
|
+
export type InitialSelector<States extends StateSchemas> = {
|
|
4431
|
+
readonly [Key in Extract<ActiveStateKey<States>, keyof InitialBuilder<States>>]: States[Key] extends
|
|
4432
|
+
{ readonly states: StateSchemas } ? {
|
|
4433
|
+
readonly initial: SelectionMethod<InitialBuilder<States>[Key], Key, "initial">
|
|
4434
|
+
}
|
|
4435
|
+
: SelectionMethod<InitialBuilder<States>[Key], Key>
|
|
4436
|
+
}
|
|
4437
|
+
|
|
4261
4438
|
/**
|
|
4262
4439
|
* Context passed to a state/event handler.
|
|
4263
4440
|
*
|
|
@@ -4555,7 +4732,8 @@ export declare namespace Machine {
|
|
|
4555
4732
|
export type InitialResult<States extends StateSchemas, E, R> =
|
|
4556
4733
|
| Snapshot<States>
|
|
4557
4734
|
| InitialSnapshot<States>
|
|
4558
|
-
|
|
|
4735
|
+
| InitialTarget<StateIdentifier<States>>
|
|
4736
|
+
| StateConstruction<Snapshot<States> | InitialSnapshot<States> | InitialTarget<StateIdentifier<States>>>
|
|
4559
4737
|
|
|
4560
4738
|
/** Initial snapshots may transiently terminate in a declared choice node. */
|
|
4561
4739
|
export type InitialSnapshot<States extends StateSchemas> = {
|
|
@@ -4651,19 +4829,22 @@ export declare namespace Machine {
|
|
|
4651
4829
|
}[keyof NonNullable<History>]
|
|
4652
4830
|
: never
|
|
4653
4831
|
/** Extracts the return value from a choice resolver. */
|
|
4654
|
-
export type ChoiceReturn<Config> = Config extends {
|
|
4655
|
-
|
|
4656
|
-
} ? Ret :
|
|
4657
|
-
never
|
|
4832
|
+
export type ChoiceReturn<Config> = Config extends { readonly choice: infer Choice } ? EventTransitionReturn<Choice>
|
|
4833
|
+
: never
|
|
4658
4834
|
/**
|
|
4659
4835
|
* Extracts the return value from an event transition config.
|
|
4660
4836
|
*
|
|
4661
4837
|
* @category utility types
|
|
4662
4838
|
* @since 0.4.0
|
|
4663
4839
|
*/
|
|
4664
|
-
export type EventTransitionReturn<Transition> =
|
|
4665
|
-
|
|
4666
|
-
|
|
4840
|
+
export type EventTransitionReturn<Transition> =
|
|
4841
|
+
| (Transition extends { readonly resolve?: infer Resolve } ?
|
|
4842
|
+
NonNullable<Resolve> extends (...args: any) => infer Ret ? Ret : never
|
|
4843
|
+
: never)
|
|
4844
|
+
| (Transition extends { readonly cases: infer Cases extends ReadonlyArray<unknown> } ?
|
|
4845
|
+
EventTransitionReturn<Cases[number]>
|
|
4846
|
+
: never)
|
|
4847
|
+
| (Transition extends { readonly otherwise: infer Otherwise } ? EventTransitionReturn<Otherwise> : never)
|
|
4667
4848
|
/**
|
|
4668
4849
|
* Extracts the return value from a state's event handlers.
|
|
4669
4850
|
*
|
|
@@ -4869,29 +5050,142 @@ export declare namespace Machine {
|
|
|
4869
5050
|
| Effect.Services<ChoiceReturn<Config>>
|
|
4870
5051
|
| InvokeRequirements<Config>
|
|
4871
5052
|
|
|
4872
|
-
|
|
5053
|
+
type TransitionWhenContext<Context> = Omit<Context, "target">
|
|
5054
|
+
|
|
5055
|
+
/** Type evidence retained by {@link transition} without affecting runtime data. */
|
|
5056
|
+
export interface TransitionTyped<
|
|
4873
5057
|
States extends StateSchemas,
|
|
4874
5058
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
4875
5059
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
4876
|
-
|
|
5060
|
+
StateId extends StateNodeIdentifier<States>,
|
|
5061
|
+
Context,
|
|
5062
|
+
Reenter extends boolean
|
|
5063
|
+
> {
|
|
5064
|
+
readonly [TransitionTypeId]: {
|
|
5065
|
+
readonly owner: Types.Covariant<readonly [States, Events, Emits, StateId, Context]>
|
|
5066
|
+
}
|
|
5067
|
+
}
|
|
5068
|
+
|
|
5069
|
+
/** Type evidence for a targetless transition reusable in every owning context. */
|
|
5070
|
+
export interface TargetlessTransitionTyped {
|
|
5071
|
+
readonly [TransitionTypeId]: {
|
|
5072
|
+
readonly targetless: true
|
|
5073
|
+
}
|
|
5074
|
+
}
|
|
5075
|
+
|
|
5076
|
+
/** The only transition value accepted by machine handler APIs. */
|
|
5077
|
+
export type TransitionConfig<
|
|
5078
|
+
States extends StateSchemas,
|
|
5079
|
+
Events extends ReadonlyArray<TaggedSchema>,
|
|
5080
|
+
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5081
|
+
StateId extends StateNodeIdentifier<States>,
|
|
5082
|
+
Context,
|
|
5083
|
+
Reenter extends boolean = false
|
|
4877
5084
|
> =
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
readonly reenter?: boolean
|
|
4881
|
-
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>
|
|
4882
|
-
readonly transition: (
|
|
4883
|
-
context: NoInfer<Context>,
|
|
4884
|
-
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
4885
|
-
) => HandlerResult<States, any, any>
|
|
5085
|
+
& (TransitionTyped<States, Events, Emits, StateId, Context, Reenter> | TargetlessTransitionTyped)
|
|
5086
|
+
& {
|
|
5087
|
+
readonly reenter?: [Reenter] extends [true] ? boolean : never
|
|
4886
5088
|
}
|
|
4887
5089
|
|
|
4888
|
-
export type
|
|
5090
|
+
export type SelectionBuilder<Selection> = Selection extends TargetSelection<infer Builder, any, any> ? Builder : never
|
|
5091
|
+
export type SelectionKind<Selection> = Selection extends TargetSelection<any, any, infer Kind> ? Kind : never
|
|
5092
|
+
export type SelectionPath<Selection> = Selection extends TargetSelection<any, infer Path, any> ? Path : never
|
|
5093
|
+
export type TargetBuilderResult<Builder> =
|
|
5094
|
+
| (Builder extends (...args: any) => infer Result ? Result : never)
|
|
5095
|
+
| (Builder extends { readonly from: (...args: any) => infer Result } ? Result : never)
|
|
5096
|
+
export type SelectedTargetResult<Selection> = SelectionBuilder<Selection> extends infer Builder ?
|
|
5097
|
+
TargetBuilderResult<Builder>
|
|
5098
|
+
: never
|
|
4889
5099
|
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
5100
|
+
export type TransitionResolveContext<
|
|
5101
|
+
Context,
|
|
5102
|
+
Selection,
|
|
5103
|
+
Match = never
|
|
5104
|
+
> =
|
|
5105
|
+
& Omit<Context, "target">
|
|
5106
|
+
& ([Match] extends [never] ? {} : { readonly match: Match })
|
|
5107
|
+
& (SelectionKind<Selection> extends "none" ? {} : { readonly target: SelectionBuilder<Selection> })
|
|
5108
|
+
|
|
5109
|
+
export type TransitionResolver<
|
|
5110
|
+
Events extends ReadonlyArray<TaggedSchema>,
|
|
5111
|
+
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5112
|
+
Context,
|
|
5113
|
+
Selection,
|
|
5114
|
+
Match = never
|
|
5115
|
+
> = (
|
|
5116
|
+
context: TransitionResolveContext<Context, Selection, Match>,
|
|
5117
|
+
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
5118
|
+
) => SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined
|
|
5119
|
+
|
|
5120
|
+
export type TransitionDirectInput<
|
|
5121
|
+
States extends StateSchemas,
|
|
5122
|
+
Events extends ReadonlyArray<TaggedSchema>,
|
|
5123
|
+
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5124
|
+
StateId extends StateNodeIdentifier<States>,
|
|
5125
|
+
Context,
|
|
5126
|
+
Reenter extends boolean,
|
|
5127
|
+
Selection extends TargetSelection<any, any, any>
|
|
5128
|
+
> = {
|
|
5129
|
+
readonly target: (to: TargetSelector<States, StateId>) => Selection
|
|
5130
|
+
readonly resolve?: TransitionResolver<Events, Emits, Context, Selection>
|
|
5131
|
+
readonly cases?: never
|
|
5132
|
+
readonly otherwise?: never
|
|
5133
|
+
readonly reenter?: Reenter
|
|
5134
|
+
}
|
|
5135
|
+
|
|
5136
|
+
export type TransitionCaseInput<
|
|
5137
|
+
States extends StateSchemas,
|
|
5138
|
+
Events extends ReadonlyArray<TaggedSchema>,
|
|
5139
|
+
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5140
|
+
StateId extends StateNodeIdentifier<States>,
|
|
5141
|
+
Context,
|
|
5142
|
+
Selection extends TargetSelection<any, any, any>,
|
|
5143
|
+
Match
|
|
5144
|
+
> = {
|
|
5145
|
+
readonly title: string
|
|
5146
|
+
readonly when: (context: TransitionWhenContext<Context>) => Option.Option<Match>
|
|
5147
|
+
readonly target: (to: TargetSelector<States, StateId>) => Selection
|
|
5148
|
+
readonly resolve?: TransitionResolver<Events, Emits, Context, Selection, NoInfer<Match>>
|
|
5149
|
+
readonly cases?: never
|
|
5150
|
+
readonly otherwise?: never
|
|
5151
|
+
readonly reenter?: never
|
|
5152
|
+
}
|
|
5153
|
+
|
|
5154
|
+
export type TransitionConditionalInput<
|
|
5155
|
+
States extends StateSchemas,
|
|
5156
|
+
Events extends ReadonlyArray<TaggedSchema>,
|
|
5157
|
+
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5158
|
+
StateId extends StateNodeIdentifier<States>,
|
|
5159
|
+
Context,
|
|
5160
|
+
Reenter extends boolean,
|
|
5161
|
+
Cases extends readonly [TransitionCaseTyped, ...ReadonlyArray<TransitionCaseTyped>],
|
|
5162
|
+
OtherwiseSelection extends TargetSelection<any, any, any>
|
|
5163
|
+
> = {
|
|
5164
|
+
readonly target?: never
|
|
5165
|
+
readonly resolve?: never
|
|
5166
|
+
readonly cases: (branch: TransitionCaseConstructor<States, Events, Emits, StateId, Context>) => Cases
|
|
5167
|
+
readonly otherwise: TransitionDirectInput<
|
|
5168
|
+
States,
|
|
5169
|
+
Events,
|
|
5170
|
+
Emits,
|
|
5171
|
+
StateId,
|
|
5172
|
+
Context,
|
|
5173
|
+
never,
|
|
5174
|
+
OtherwiseSelection
|
|
5175
|
+
>
|
|
5176
|
+
readonly reenter?: Reenter
|
|
4893
5177
|
}
|
|
4894
5178
|
|
|
5179
|
+
export type InvokeTransition<
|
|
5180
|
+
States extends StateSchemas,
|
|
5181
|
+
Events extends ReadonlyArray<TaggedSchema>,
|
|
5182
|
+
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5183
|
+
StateId extends StateNodeIdentifier<States>,
|
|
5184
|
+
Context
|
|
5185
|
+
> = TransitionConfig<States, Events, Emits, StateId, Context, true>
|
|
5186
|
+
|
|
5187
|
+
export type InvokeSource<Value, Context> = Value | ((context: Context) => Value)
|
|
5188
|
+
|
|
4895
5189
|
/** Inline state-owned work that runs for the lifetime of its active state. */
|
|
4896
5190
|
export interface InvokeOwned<
|
|
4897
5191
|
States extends StateSchemas,
|
|
@@ -4955,7 +5249,7 @@ export declare namespace Machine {
|
|
|
4955
5249
|
readonly id: string
|
|
4956
5250
|
readonly address: string
|
|
4957
5251
|
readonly logic: InvokeSource<
|
|
4958
|
-
|
|
5252
|
+
Logic<any, any, any, any, any, any>,
|
|
4959
5253
|
InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
4960
5254
|
>
|
|
4961
5255
|
readonly effect?: never
|
|
@@ -5035,6 +5329,7 @@ export declare namespace Machine {
|
|
|
5035
5329
|
States,
|
|
5036
5330
|
Events,
|
|
5037
5331
|
Emits,
|
|
5332
|
+
StateId,
|
|
5038
5333
|
InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>
|
|
5039
5334
|
>
|
|
5040
5335
|
}
|
|
@@ -5066,35 +5361,38 @@ export declare namespace Machine {
|
|
|
5066
5361
|
States,
|
|
5067
5362
|
Events,
|
|
5068
5363
|
Emits,
|
|
5364
|
+
StateId,
|
|
5069
5365
|
InvokeSnapshotContext<
|
|
5070
5366
|
States,
|
|
5071
5367
|
Events,
|
|
5072
5368
|
Emits,
|
|
5073
5369
|
StateId,
|
|
5074
|
-
ChildState
|
|
5075
|
-
ChildError
|
|
5076
|
-
ChildOutput
|
|
5370
|
+
NoInfer<ChildState>,
|
|
5371
|
+
NoInfer<ChildError>,
|
|
5372
|
+
NoInfer<ChildOutput>,
|
|
5077
5373
|
InputEvents,
|
|
5078
5374
|
ParentEvents
|
|
5079
5375
|
>
|
|
5080
5376
|
>
|
|
5081
5377
|
}
|
|
5082
5378
|
& InvokeDoneRequirement<
|
|
5083
|
-
ChildOutput
|
|
5379
|
+
NoInfer<ChildOutput>,
|
|
5084
5380
|
InvokeTransition<
|
|
5085
5381
|
States,
|
|
5086
5382
|
Events,
|
|
5087
5383
|
Emits,
|
|
5088
|
-
|
|
5384
|
+
StateId,
|
|
5385
|
+
InvokeDoneContext<States, Events, Emits, StateId, NoInfer<ChildOutput>, InputEvents, ParentEvents>
|
|
5089
5386
|
>
|
|
5090
5387
|
>
|
|
5091
5388
|
& InvokeFailureRequirement<
|
|
5092
|
-
ChildError
|
|
5389
|
+
NoInfer<ChildError>,
|
|
5093
5390
|
InvokeTransition<
|
|
5094
5391
|
States,
|
|
5095
5392
|
Events,
|
|
5096
5393
|
Emits,
|
|
5097
|
-
|
|
5394
|
+
StateId,
|
|
5395
|
+
InvokeFailureContext<States, Events, Emits, StateId, NoInfer<ChildError>, InputEvents, ParentEvents>
|
|
5098
5396
|
>
|
|
5099
5397
|
>
|
|
5100
5398
|
|
|
@@ -5126,6 +5424,7 @@ export declare namespace Machine {
|
|
|
5126
5424
|
States,
|
|
5127
5425
|
Events,
|
|
5128
5426
|
Emits,
|
|
5427
|
+
StateId,
|
|
5129
5428
|
InvokeSnapshotContext<
|
|
5130
5429
|
States,
|
|
5131
5430
|
Events,
|
|
@@ -5151,6 +5450,7 @@ export declare namespace Machine {
|
|
|
5151
5450
|
States,
|
|
5152
5451
|
Events,
|
|
5153
5452
|
Emits,
|
|
5453
|
+
StateId,
|
|
5154
5454
|
InvokeDoneContext<
|
|
5155
5455
|
States,
|
|
5156
5456
|
Events,
|
|
@@ -5168,6 +5468,7 @@ export declare namespace Machine {
|
|
|
5168
5468
|
States,
|
|
5169
5469
|
Events,
|
|
5170
5470
|
Emits,
|
|
5471
|
+
StateId,
|
|
5171
5472
|
InvokeFailureContext<
|
|
5172
5473
|
States,
|
|
5173
5474
|
Events,
|
|
@@ -5180,12 +5481,24 @@ export declare namespace Machine {
|
|
|
5180
5481
|
>
|
|
5181
5482
|
>
|
|
5182
5483
|
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5484
|
+
type LogicInitialEffectOf<Value> = Value extends { readonly initial: infer Initial } ?
|
|
5485
|
+
Initial extends (...args: ReadonlyArray<any>) => infer Result ? Result : never
|
|
5486
|
+
: never
|
|
5487
|
+
|
|
5488
|
+
type LogicRunEffectOf<Value> = Value extends { readonly run: infer Run } ?
|
|
5489
|
+
Run extends (...args: ReadonlyArray<any>) => infer Result ? Result : never
|
|
5490
|
+
: never
|
|
5491
|
+
|
|
5492
|
+
export type LogicStateOf<Value> = Effect.Success<LogicInitialEffectOf<Value>>
|
|
5493
|
+
export type LogicEventOf<Value> = Value extends { readonly initial: infer Initial } ?
|
|
5494
|
+
Initial extends (scope: infer LogicScope, ...args: ReadonlyArray<any>) => any ?
|
|
5495
|
+
LogicScope extends Logic.Scope<infer Event> ? Event : never
|
|
5496
|
+
: never
|
|
5497
|
+
: never
|
|
5498
|
+
export type LogicErrorOf<Value> = Effect.Error<LogicRunEffectOf<Value>>
|
|
5499
|
+
export type LogicServicesOf<Value> = Effect.Services<LogicInitialEffectOf<Value> | LogicRunEffectOf<Value>>
|
|
5500
|
+
export type LogicOutputOf<Value> = Effect.Success<LogicRunEffectOf<Value>>
|
|
5501
|
+
export type LogicInitialErrorOf<Value> = Effect.Error<LogicInitialEffectOf<Value>>
|
|
5189
5502
|
|
|
5190
5503
|
type ContextualInvokeConfig<
|
|
5191
5504
|
States extends StateSchemas,
|
|
@@ -5204,6 +5517,7 @@ export declare namespace Machine {
|
|
|
5204
5517
|
States,
|
|
5205
5518
|
Events,
|
|
5206
5519
|
Emits,
|
|
5520
|
+
StateId,
|
|
5207
5521
|
InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<Fx>, InputEvents, ParentEvents>
|
|
5208
5522
|
>
|
|
5209
5523
|
>
|
|
@@ -5213,6 +5527,7 @@ export declare namespace Machine {
|
|
|
5213
5527
|
States,
|
|
5214
5528
|
Events,
|
|
5215
5529
|
Emits,
|
|
5530
|
+
StateId,
|
|
5216
5531
|
InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<Fx>, InputEvents, ParentEvents>
|
|
5217
5532
|
>
|
|
5218
5533
|
>
|
|
@@ -5223,6 +5538,7 @@ export declare namespace Machine {
|
|
|
5223
5538
|
States,
|
|
5224
5539
|
Events,
|
|
5225
5540
|
Emits,
|
|
5541
|
+
StateId,
|
|
5226
5542
|
InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>
|
|
5227
5543
|
>
|
|
5228
5544
|
readonly onFailure?: never
|
|
@@ -5236,6 +5552,7 @@ export declare namespace Machine {
|
|
|
5236
5552
|
States,
|
|
5237
5553
|
Events,
|
|
5238
5554
|
Emits,
|
|
5555
|
+
StateId,
|
|
5239
5556
|
InvokeDoneContext<States, Events, Emits, StateId, InvokeOutput<Raw>, InputEvents, ParentEvents>
|
|
5240
5557
|
>
|
|
5241
5558
|
>
|
|
@@ -5245,6 +5562,7 @@ export declare namespace Machine {
|
|
|
5245
5562
|
States,
|
|
5246
5563
|
Events,
|
|
5247
5564
|
Emits,
|
|
5565
|
+
StateId,
|
|
5248
5566
|
InvokeFailureContext<
|
|
5249
5567
|
States,
|
|
5250
5568
|
Events,
|
|
@@ -5267,6 +5585,7 @@ export declare namespace Machine {
|
|
|
5267
5585
|
States,
|
|
5268
5586
|
Events,
|
|
5269
5587
|
Emits,
|
|
5588
|
+
StateId,
|
|
5270
5589
|
InvokeSnapshotContext<
|
|
5271
5590
|
States,
|
|
5272
5591
|
Events,
|
|
@@ -5289,6 +5608,7 @@ export declare namespace Machine {
|
|
|
5289
5608
|
States,
|
|
5290
5609
|
Events,
|
|
5291
5610
|
Emits,
|
|
5611
|
+
StateId,
|
|
5292
5612
|
InvokeDoneContext<
|
|
5293
5613
|
States,
|
|
5294
5614
|
Events,
|
|
@@ -5306,6 +5626,7 @@ export declare namespace Machine {
|
|
|
5306
5626
|
States,
|
|
5307
5627
|
Events,
|
|
5308
5628
|
Emits,
|
|
5629
|
+
StateId,
|
|
5309
5630
|
InvokeFailureContext<
|
|
5310
5631
|
States,
|
|
5311
5632
|
Events,
|
|
@@ -5328,6 +5649,7 @@ export declare namespace Machine {
|
|
|
5328
5649
|
States,
|
|
5329
5650
|
Events,
|
|
5330
5651
|
Emits,
|
|
5652
|
+
StateId,
|
|
5331
5653
|
InvokeSnapshotContext<
|
|
5332
5654
|
States,
|
|
5333
5655
|
Events,
|
|
@@ -5418,51 +5740,29 @@ export declare namespace Machine {
|
|
|
5418
5740
|
readonly invoke?:
|
|
5419
5741
|
| InvokeDefinition<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
5420
5742
|
| TypedInvokeDefinition
|
|
5421
|
-
readonly always?:
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
| ((
|
|
5436
|
-
context: DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
5437
|
-
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
5438
|
-
) => HandlerResult<States, any, any>)
|
|
5439
|
-
| {
|
|
5440
|
-
/** Statically declared upper bound of possible target paths. */
|
|
5441
|
-
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>
|
|
5442
|
-
readonly transition: (
|
|
5443
|
-
context: DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
5444
|
-
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
5445
|
-
) => HandlerResult<States, any, any>
|
|
5446
|
-
}
|
|
5743
|
+
readonly always?: TransitionConfig<
|
|
5744
|
+
States,
|
|
5745
|
+
Events,
|
|
5746
|
+
Emits,
|
|
5747
|
+
StateId,
|
|
5748
|
+
AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
5749
|
+
>
|
|
5750
|
+
readonly onDone?: TransitionConfig<
|
|
5751
|
+
States,
|
|
5752
|
+
Events,
|
|
5753
|
+
Emits,
|
|
5754
|
+
StateId,
|
|
5755
|
+
DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
5756
|
+
>
|
|
5447
5757
|
readonly on?: {
|
|
5448
|
-
readonly [EventTag in TagOf<Events[number]>]?:
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
5453
|
-
|
|
5454
|
-
|
|
5455
|
-
|
|
5456
|
-
* Upper bound of state or history paths this handler may target.
|
|
5457
|
-
* Returning `target.none()` is always permitted. Declaring a parent state also
|
|
5458
|
-
* permits concrete descendant targets below it.
|
|
5459
|
-
*/
|
|
5460
|
-
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>
|
|
5461
|
-
readonly transition: (
|
|
5462
|
-
context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>,
|
|
5463
|
-
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
5464
|
-
) => HandlerResult<States, any, any>
|
|
5465
|
-
}
|
|
5758
|
+
readonly [EventTag in TagOf<Events[number]>]?: TransitionConfig<
|
|
5759
|
+
States,
|
|
5760
|
+
Events,
|
|
5761
|
+
Emits,
|
|
5762
|
+
StateId,
|
|
5763
|
+
HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>,
|
|
5764
|
+
true
|
|
5765
|
+
>
|
|
5466
5766
|
}
|
|
5467
5767
|
readonly initialize?: StateInitializeHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
5468
5768
|
} & ActiveOutputHandlerConfig<States, Events, StateId>
|
|
@@ -5634,14 +5934,13 @@ export declare namespace Machine {
|
|
|
5634
5934
|
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
5635
5935
|
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
5636
5936
|
> {
|
|
5637
|
-
readonly choice:
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
5643
|
-
|
|
5644
|
-
}
|
|
5937
|
+
readonly choice: TransitionConfig<
|
|
5938
|
+
States,
|
|
5939
|
+
Events,
|
|
5940
|
+
Emits,
|
|
5941
|
+
ChoiceId,
|
|
5942
|
+
ChoiceContext<States, Events, Emits, ChoiceId, InputEvents, ParentEvents>
|
|
5943
|
+
>
|
|
5645
5944
|
readonly entry?: never
|
|
5646
5945
|
readonly exit?: never
|
|
5647
5946
|
readonly invoke?: never
|
|
@@ -5979,12 +6278,6 @@ export declare namespace Machine {
|
|
|
5979
6278
|
}
|
|
5980
6279
|
: unknown
|
|
5981
6280
|
|
|
5982
|
-
type TransitionResultTargetPath<Result> = IsAny<Result> extends true ? never
|
|
5983
|
-
: Result extends Effect.Effect<infer Success, any, any> ? TransitionResultTargetPath<Success>
|
|
5984
|
-
: Result extends StateConstruction<infer Constructed> ? TransitionResultTargetPath<Constructed>
|
|
5985
|
-
: Result extends { readonly path: infer Path extends string } ? Path
|
|
5986
|
-
: never
|
|
5987
|
-
|
|
5988
6281
|
type TransitionResultInitialTargetPath<Result> = IsAny<Result> extends true ? never
|
|
5989
6282
|
: Result extends Effect.Effect<infer Success, any, any> ? TransitionResultInitialTargetPath<Success>
|
|
5990
6283
|
: Result extends StateConstruction<infer Constructed> ? TransitionResultInitialTargetPath<Constructed>
|
|
@@ -6054,58 +6347,6 @@ export declare namespace Machine {
|
|
|
6054
6347
|
>
|
|
6055
6348
|
: unknown
|
|
6056
6349
|
|
|
6057
|
-
type DeclaredTransitionTarget<Transition> = Transition extends {
|
|
6058
|
-
readonly targets: infer Targets extends ReadonlyArray<string>
|
|
6059
|
-
} ? Targets[number]
|
|
6060
|
-
: never
|
|
6061
|
-
|
|
6062
|
-
type ExcludeDeclaredTransitionTarget<Returned, Declared extends string> = Returned extends string ?
|
|
6063
|
-
Returned extends Declared | `${Declared}.${string}` ? never : Returned
|
|
6064
|
-
: never
|
|
6065
|
-
|
|
6066
|
-
type UndeclaredTransitionTarget<Transition> = "targets" extends keyof Transition ? ExcludeDeclaredTransitionTarget<
|
|
6067
|
-
TransitionResultTargetPath<EventTransitionReturn<Transition>>,
|
|
6068
|
-
DeclaredTransitionTarget<Transition>
|
|
6069
|
-
>
|
|
6070
|
-
: never
|
|
6071
|
-
|
|
6072
|
-
type HandlerOnTargetValidationErrors<StateId extends string, On> = {
|
|
6073
|
-
readonly [
|
|
6074
|
-
EventTag in keyof On as [UndeclaredTransitionTarget<On[EventTag]>] extends [never] ? never
|
|
6075
|
-
: EventTag
|
|
6076
|
-
]: HandlerValidationError<
|
|
6077
|
-
"Transition returns a target not listed in targets",
|
|
6078
|
-
StateId,
|
|
6079
|
-
readonly [event: EventTag, target: UndeclaredTransitionTarget<On[EventTag]>]
|
|
6080
|
-
>
|
|
6081
|
-
}
|
|
6082
|
-
|
|
6083
|
-
type HandlerOnTargetValidation<StateId extends string, Config> = "on" extends keyof Config ?
|
|
6084
|
-
Config extends { readonly on?: infer On } ? HandlerOnTargetValidationErrors<
|
|
6085
|
-
StateId,
|
|
6086
|
-
NonNullable<On>
|
|
6087
|
-
> extends infer Errors ? keyof Errors extends never ? unknown
|
|
6088
|
-
: { readonly on: Errors }
|
|
6089
|
-
: never
|
|
6090
|
-
: unknown
|
|
6091
|
-
: unknown
|
|
6092
|
-
|
|
6093
|
-
type HandlerDirectTargetValidation<
|
|
6094
|
-
StateId extends string,
|
|
6095
|
-
Config,
|
|
6096
|
-
Trigger extends "always" | "onDone",
|
|
6097
|
-
Transition = Config extends { readonly [Key in Trigger]?: infer Value } ? NonNullable<Value> : never,
|
|
6098
|
-
Undeclared extends string = UndeclaredTransitionTarget<Transition>
|
|
6099
|
-
> = Trigger extends keyof Config ? [Undeclared] extends [never] ? unknown
|
|
6100
|
-
: {
|
|
6101
|
-
readonly [Key in Trigger]: HandlerValidationError<
|
|
6102
|
-
"Transition returns a target not listed in targets",
|
|
6103
|
-
StateId,
|
|
6104
|
-
readonly [trigger: Trigger, target: Undeclared]
|
|
6105
|
-
>
|
|
6106
|
-
}
|
|
6107
|
-
: unknown
|
|
6108
|
-
|
|
6109
6350
|
type HandlerChildrenValidation<
|
|
6110
6351
|
Node,
|
|
6111
6352
|
Prefix extends string,
|
|
@@ -6185,14 +6426,10 @@ export declare namespace Machine {
|
|
|
6185
6426
|
AvailableOutputStates extends StateIdentifier<AllStates>
|
|
6186
6427
|
> = StateId extends ChoiceIdentifier<AllStates> ?
|
|
6187
6428
|
& HandlerChoiceUnknownConfigKeyValidation<StateId, Config>
|
|
6188
|
-
& HandlerChoiceTargetValidation<StateId, Config>
|
|
6189
6429
|
& HandlerRuntimeValidation<Events, Emits, StateId, Config>
|
|
6190
6430
|
: StateId extends StateIdentifier<AllStates> ?
|
|
6191
6431
|
& HandlerUnknownConfigKeyValidation<StateId, Config>
|
|
6192
6432
|
& HandlerOnKeyValidation<Events, StateId, Config>
|
|
6193
|
-
& HandlerOnTargetValidation<StateId, Config>
|
|
6194
|
-
& HandlerDirectTargetValidation<StateId, Config, "always">
|
|
6195
|
-
& HandlerDirectTargetValidation<StateId, Config, "onDone">
|
|
6196
6433
|
& HandlerInvokeParentEventsValidation<InputEvents, StateId, Config>
|
|
6197
6434
|
& HandlerChildrenValidation<Node, StateId, Config>
|
|
6198
6435
|
& HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config>
|
|
@@ -6212,17 +6449,6 @@ export declare namespace Machine {
|
|
|
6212
6449
|
>
|
|
6213
6450
|
}
|
|
6214
6451
|
|
|
6215
|
-
type HandlerChoiceTargetValidation<StateId extends string, Config> = Config extends {
|
|
6216
|
-
readonly choice: infer Choice
|
|
6217
|
-
} ? [UndeclaredTransitionTarget<Choice>] extends [never] ? unknown : {
|
|
6218
|
-
readonly choice: HandlerValidationError<
|
|
6219
|
-
"Choice resolver returns a target not listed in targets",
|
|
6220
|
-
StateId,
|
|
6221
|
-
UndeclaredTransitionTarget<Choice>
|
|
6222
|
-
>
|
|
6223
|
-
}
|
|
6224
|
-
: unknown
|
|
6225
|
-
|
|
6226
6452
|
type HandlerInvokeParentEventsValidation<
|
|
6227
6453
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
6228
6454
|
StateId extends string,
|
|
@@ -6523,19 +6749,14 @@ export declare namespace Machine {
|
|
|
6523
6749
|
> = Readonly<
|
|
6524
6750
|
Record<
|
|
6525
6751
|
PropertyKey,
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
readonly transition: (
|
|
6535
|
-
context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>,
|
|
6536
|
-
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
6537
|
-
) => HandlerResult<States, E, R>
|
|
6538
|
-
}
|
|
6752
|
+
TransitionConfig<
|
|
6753
|
+
States,
|
|
6754
|
+
Events,
|
|
6755
|
+
Emits,
|
|
6756
|
+
StateId,
|
|
6757
|
+
HandlerContext<States, Events, Emits, StateId, EventTag, E, R>,
|
|
6758
|
+
true
|
|
6759
|
+
>
|
|
6539
6760
|
>
|
|
6540
6761
|
>
|
|
6541
6762
|
|
|
@@ -6563,30 +6784,20 @@ export declare namespace Machine {
|
|
|
6563
6784
|
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
6564
6785
|
) => StateActionResult<E, R>
|
|
6565
6786
|
readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>
|
|
6566
|
-
readonly always?:
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
context: DoneContext<States, Events, Emits, StateId>,
|
|
6581
|
-
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
6582
|
-
) => HandlerResult<States, E, R>)
|
|
6583
|
-
| {
|
|
6584
|
-
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>
|
|
6585
|
-
readonly transition: (
|
|
6586
|
-
context: DoneContext<States, Events, Emits, StateId>,
|
|
6587
|
-
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
6588
|
-
) => HandlerResult<States, E, R>
|
|
6589
|
-
}
|
|
6787
|
+
readonly always?: TransitionConfig<
|
|
6788
|
+
States,
|
|
6789
|
+
Events,
|
|
6790
|
+
Emits,
|
|
6791
|
+
StateId,
|
|
6792
|
+
AlwaysContext<States, Events, Emits, StateId>
|
|
6793
|
+
>
|
|
6794
|
+
readonly onDone?: TransitionConfig<
|
|
6795
|
+
States,
|
|
6796
|
+
Events,
|
|
6797
|
+
Emits,
|
|
6798
|
+
StateId,
|
|
6799
|
+
DoneContext<States, Events, Emits, StateId>
|
|
6800
|
+
>
|
|
6590
6801
|
readonly output?:
|
|
6591
6802
|
| ((context: FinalOutputContext<States, Events, StateId>) => unknown)
|
|
6592
6803
|
| ((context: ParallelOutputContext<States, Events, StateId>) => unknown)
|
|
@@ -6671,15 +6882,15 @@ export const isFinal: <
|
|
|
6671
6882
|
* **When to use**
|
|
6672
6883
|
*
|
|
6673
6884
|
* Use when you want to pass a state tree to `make` and also get typed
|
|
6674
|
-
* snapshot
|
|
6885
|
+
* snapshot matching and access helpers.
|
|
6675
6886
|
*
|
|
6676
6887
|
* **Details**
|
|
6677
6888
|
*
|
|
6678
6889
|
* The returned `states` property is the same object passed to `defineStates`.
|
|
6679
|
-
*
|
|
6680
|
-
*
|
|
6681
|
-
*
|
|
6682
|
-
*
|
|
6890
|
+
* `Machine.make` derives its initial target selector from that tree and
|
|
6891
|
+
* enforces compound and parallel initial-state rules. Active nodes may omit
|
|
6892
|
+
* `schema` when they own no value and still participate fully in targeting,
|
|
6893
|
+
* matching, and snapshots.
|
|
6683
6894
|
*
|
|
6684
6895
|
* **Example** (Atomic initial snapshot)
|
|
6685
6896
|
*
|
|
@@ -6694,7 +6905,10 @@ export const isFinal: <
|
|
|
6694
6905
|
* Machine.make({
|
|
6695
6906
|
* states: States.states,
|
|
6696
6907
|
* events: Machine.events(),
|
|
6697
|
-
* initial:
|
|
6908
|
+
* initial: {
|
|
6909
|
+
* target: (to) => to.idle(),
|
|
6910
|
+
* resolve: ({ target }) => target.from()
|
|
6911
|
+
* }
|
|
6698
6912
|
* })
|
|
6699
6913
|
* ```
|
|
6700
6914
|
*
|
|
@@ -6703,6 +6917,20 @@ export const isFinal: <
|
|
|
6703
6917
|
*/
|
|
6704
6918
|
export const defineStates: DefineStates = internal.defineStates
|
|
6705
6919
|
|
|
6920
|
+
type InitialDirectInput<
|
|
6921
|
+
States extends Machine.StateSchemas,
|
|
6922
|
+
Input,
|
|
6923
|
+
Selection extends Machine.TargetSelection<any, any, any>
|
|
6924
|
+
> = {
|
|
6925
|
+
readonly target: (to: Machine.InitialSelector<States>) => Selection
|
|
6926
|
+
readonly resolve?: (context: {
|
|
6927
|
+
readonly input: Input
|
|
6928
|
+
readonly target: Machine.SelectionBuilder<Selection>
|
|
6929
|
+
}) => Machine.SelectedTargetResult<Selection>
|
|
6930
|
+
readonly cases?: never
|
|
6931
|
+
readonly otherwise?: never
|
|
6932
|
+
}
|
|
6933
|
+
|
|
6706
6934
|
type MakeConfig<
|
|
6707
6935
|
States extends Machine.StateSchemas,
|
|
6708
6936
|
InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
@@ -6727,7 +6955,7 @@ type MakeConfig<
|
|
|
6727
6955
|
readonly emittedEvents?: Machine.EventProtocol<"emitted", Emits>
|
|
6728
6956
|
readonly parentEvents?: Machine.EventProtocol<"public", ParentEvents>
|
|
6729
6957
|
readonly input?: Input
|
|
6730
|
-
readonly initial:
|
|
6958
|
+
readonly initial: unknown
|
|
6731
6959
|
}
|
|
6732
6960
|
|
|
6733
6961
|
type MakeResult<
|
|
@@ -6765,9 +6993,15 @@ interface Make {
|
|
|
6765
6993
|
InitialE = never,
|
|
6766
6994
|
InitialR = never,
|
|
6767
6995
|
const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
6768
|
-
const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
6996
|
+
const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
6997
|
+
const InitialSelection extends Machine.TargetSelection<any, any, any> = Machine.TargetSelection<any, any, any>
|
|
6769
6998
|
>(
|
|
6770
|
-
config:
|
|
6999
|
+
config:
|
|
7000
|
+
& Omit<
|
|
7001
|
+
MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>,
|
|
7002
|
+
"initial"
|
|
7003
|
+
>
|
|
7004
|
+
& { readonly initial: InitialDirectInput<States, Input["Type"], InitialSelection> },
|
|
6771
7005
|
..._validation: ValidateDefinedStates<NoInfer<States>>
|
|
6772
7006
|
): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>
|
|
6773
7007
|
<
|
|
@@ -6825,18 +7059,24 @@ interface Make {
|
|
|
6825
7059
|
* const counter = Machine.make({
|
|
6826
7060
|
* states: States.states,
|
|
6827
7061
|
* events: Events,
|
|
6828
|
-
* initial:
|
|
7062
|
+
* initial: {
|
|
7063
|
+
* target: (to) => to.Count(),
|
|
7064
|
+
* resolve: ({ target }) => target(new Count({ value: 0 }))
|
|
7065
|
+
* }
|
|
6829
7066
|
* }).handle({
|
|
6830
7067
|
* Count: {
|
|
6831
7068
|
* on: {
|
|
6832
|
-
* Increment: ({
|
|
6833
|
-
*
|
|
7069
|
+
* Increment: Machine.transition({
|
|
7070
|
+
* target: (to) => to.full.Count(),
|
|
7071
|
+
* resolve: ({ event, state, target }) =>
|
|
7072
|
+
* target(new Count({ value: state.value + event.by }))
|
|
7073
|
+
* })
|
|
6834
7074
|
* }
|
|
6835
7075
|
* }
|
|
6836
7076
|
* })
|
|
6837
7077
|
* ```
|
|
6838
7078
|
*
|
|
6839
|
-
* @see {@link defineStates} for typed
|
|
7079
|
+
* @see {@link defineStates} for typed state-tree helpers.
|
|
6840
7080
|
* @category constructors
|
|
6841
7081
|
* @since 0.4.0
|
|
6842
7082
|
*/
|
|
@@ -6963,7 +7203,10 @@ export const emittedEvents: {
|
|
|
6963
7203
|
* const machine = Machine.make({
|
|
6964
7204
|
* states: States.states,
|
|
6965
7205
|
* events: Machine.events(),
|
|
6966
|
-
* initial:
|
|
7206
|
+
* initial: {
|
|
7207
|
+
* target: (to) => to.Idle(),
|
|
7208
|
+
* resolve: ({ target }) => target.from()
|
|
7209
|
+
* }
|
|
6967
7210
|
* }).handle({ Idle: {} })
|
|
6968
7211
|
*
|
|
6969
7212
|
* const encoded = Effect.gen(function*() {
|
|
@@ -7045,7 +7288,10 @@ export const encodeSnapshot: <
|
|
|
7045
7288
|
* const machine = Machine.make({
|
|
7046
7289
|
* states: States.states,
|
|
7047
7290
|
* events: Machine.events(),
|
|
7048
|
-
* initial:
|
|
7291
|
+
* initial: {
|
|
7292
|
+
* target: (to) => to.Idle(),
|
|
7293
|
+
* resolve: ({ target }) => target.from()
|
|
7294
|
+
* }
|
|
7049
7295
|
* }).handle({ Idle: {} })
|
|
7050
7296
|
*
|
|
7051
7297
|
* const roundTrip = Effect.gen(function*() {
|
|
@@ -7126,6 +7372,7 @@ type EffectDoneHandler<
|
|
|
7126
7372
|
States,
|
|
7127
7373
|
Events,
|
|
7128
7374
|
Emits,
|
|
7375
|
+
StateId,
|
|
7129
7376
|
Machine.InvokeDoneContext<
|
|
7130
7377
|
States,
|
|
7131
7378
|
Events,
|
|
@@ -7147,6 +7394,7 @@ type EffectFailureHandler<
|
|
|
7147
7394
|
States,
|
|
7148
7395
|
Events,
|
|
7149
7396
|
Emits,
|
|
7397
|
+
StateId,
|
|
7150
7398
|
Machine.InvokeFailureContext<
|
|
7151
7399
|
States,
|
|
7152
7400
|
Events,
|
|
@@ -7207,6 +7455,7 @@ type BoundEffectDoneHandler<
|
|
|
7207
7455
|
States,
|
|
7208
7456
|
Events,
|
|
7209
7457
|
Emits,
|
|
7458
|
+
StateId,
|
|
7210
7459
|
Machine.InvokeDoneContext<
|
|
7211
7460
|
States,
|
|
7212
7461
|
Events,
|
|
@@ -7230,6 +7479,7 @@ type BoundEffectFailureHandler<
|
|
|
7230
7479
|
States,
|
|
7231
7480
|
Events,
|
|
7232
7481
|
Emits,
|
|
7482
|
+
StateId,
|
|
7233
7483
|
Machine.InvokeFailureContext<
|
|
7234
7484
|
States,
|
|
7235
7485
|
Events,
|
|
@@ -7258,6 +7508,162 @@ type BoundEffectInvokeResult<
|
|
|
7258
7508
|
never
|
|
7259
7509
|
>
|
|
7260
7510
|
|
|
7511
|
+
/** Type evidence retained for a case created by a conditional transition's local builder. */
|
|
7512
|
+
interface TransitionCaseTyped {
|
|
7513
|
+
readonly [TransitionCaseTypeId]: true
|
|
7514
|
+
}
|
|
7515
|
+
|
|
7516
|
+
/** Locally bound constructor that preserves each conditional transition case independently. */
|
|
7517
|
+
interface TransitionCaseConstructor<
|
|
7518
|
+
States extends Machine.StateSchemas,
|
|
7519
|
+
Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
7520
|
+
Emits extends ReadonlyArray<Machine.TaggedSchema>,
|
|
7521
|
+
StateId extends Machine.StateNodeIdentifier<States>,
|
|
7522
|
+
Context
|
|
7523
|
+
> {
|
|
7524
|
+
<
|
|
7525
|
+
const Selection extends Machine.TargetSelection<any, any, any>,
|
|
7526
|
+
const Match
|
|
7527
|
+
>(
|
|
7528
|
+
config: Machine.TransitionCaseInput<States, Events, Emits, StateId, Context, Selection, Match>
|
|
7529
|
+
):
|
|
7530
|
+
& Machine.TransitionCaseInput<States, Events, Emits, StateId, Context, Selection, Match>
|
|
7531
|
+
& TransitionCaseTyped
|
|
7532
|
+
}
|
|
7533
|
+
|
|
7534
|
+
/**
|
|
7535
|
+
* Captures one exact transition topology while preserving handler inference.
|
|
7536
|
+
*
|
|
7537
|
+
* @category constructors
|
|
7538
|
+
* @since 0.14.0
|
|
7539
|
+
*/
|
|
7540
|
+
type ConditionalTransitionResult<
|
|
7541
|
+
States extends Machine.StateSchemas,
|
|
7542
|
+
Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
7543
|
+
Emits extends ReadonlyArray<Machine.TaggedSchema>,
|
|
7544
|
+
StateId extends Machine.StateNodeIdentifier<States>,
|
|
7545
|
+
Context,
|
|
7546
|
+
Reenter extends boolean,
|
|
7547
|
+
Cases extends readonly [
|
|
7548
|
+
TransitionCaseTyped,
|
|
7549
|
+
...ReadonlyArray<TransitionCaseTyped>
|
|
7550
|
+
],
|
|
7551
|
+
OtherwiseSelection extends Machine.TargetSelection<any, any, any>
|
|
7552
|
+
> =
|
|
7553
|
+
& Omit<
|
|
7554
|
+
Machine.TransitionConditionalInput<
|
|
7555
|
+
States,
|
|
7556
|
+
Events,
|
|
7557
|
+
Emits,
|
|
7558
|
+
StateId,
|
|
7559
|
+
Context,
|
|
7560
|
+
Reenter,
|
|
7561
|
+
Cases,
|
|
7562
|
+
OtherwiseSelection
|
|
7563
|
+
>,
|
|
7564
|
+
"cases"
|
|
7565
|
+
>
|
|
7566
|
+
& { readonly cases: Cases }
|
|
7567
|
+
& Machine.TransitionTyped<States, Events, Emits, StateId, Context, Reenter>
|
|
7568
|
+
|
|
7569
|
+
/**
|
|
7570
|
+
* Contextually types direct and conditional transition definitions.
|
|
7571
|
+
*
|
|
7572
|
+
* @category constructors
|
|
7573
|
+
* @since 0.14.0
|
|
7574
|
+
*/
|
|
7575
|
+
export interface TransitionConstructor {
|
|
7576
|
+
<
|
|
7577
|
+
const States extends Machine.StateSchemas,
|
|
7578
|
+
const Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
7579
|
+
const Emits extends ReadonlyArray<Machine.TaggedSchema>,
|
|
7580
|
+
StateId extends Machine.StateNodeIdentifier<States>,
|
|
7581
|
+
Context,
|
|
7582
|
+
const Selection extends Machine.TargetSelection<any, any, any>,
|
|
7583
|
+
Reenter extends boolean = never
|
|
7584
|
+
>(
|
|
7585
|
+
config: Machine.TransitionDirectInput<States, Events, Emits, StateId, Context, Reenter, Selection>
|
|
7586
|
+
):
|
|
7587
|
+
& Machine.TransitionDirectInput<States, Events, Emits, StateId, Context, Reenter, Selection>
|
|
7588
|
+
& (Machine.SelectionKind<Selection> extends "none" ? Machine.TargetlessTransitionTyped
|
|
7589
|
+
: Machine.TransitionTyped<States, Events, Emits, StateId, Context, Reenter>)
|
|
7590
|
+
<
|
|
7591
|
+
const States extends Machine.StateSchemas,
|
|
7592
|
+
const Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
7593
|
+
const Emits extends ReadonlyArray<Machine.TaggedSchema>,
|
|
7594
|
+
StateId extends Machine.StateNodeIdentifier<States>,
|
|
7595
|
+
Context,
|
|
7596
|
+
const Cases extends readonly [
|
|
7597
|
+
TransitionCaseTyped,
|
|
7598
|
+
...ReadonlyArray<TransitionCaseTyped>
|
|
7599
|
+
],
|
|
7600
|
+
const OtherwiseSelection extends Machine.TargetSelection<any, any, any>,
|
|
7601
|
+
Reenter extends boolean = never
|
|
7602
|
+
>(
|
|
7603
|
+
config: Machine.TransitionConditionalInput<
|
|
7604
|
+
States,
|
|
7605
|
+
Events,
|
|
7606
|
+
Emits,
|
|
7607
|
+
StateId,
|
|
7608
|
+
Context,
|
|
7609
|
+
Reenter,
|
|
7610
|
+
Cases,
|
|
7611
|
+
OtherwiseSelection
|
|
7612
|
+
>
|
|
7613
|
+
): ConditionalTransitionResult<
|
|
7614
|
+
States,
|
|
7615
|
+
Events,
|
|
7616
|
+
Emits,
|
|
7617
|
+
StateId,
|
|
7618
|
+
Context,
|
|
7619
|
+
Reenter,
|
|
7620
|
+
Cases,
|
|
7621
|
+
OtherwiseSelection
|
|
7622
|
+
>
|
|
7623
|
+
}
|
|
7624
|
+
|
|
7625
|
+
/**
|
|
7626
|
+
* Defines a statically inspectable transition.
|
|
7627
|
+
*
|
|
7628
|
+
* It is required for every event, lifecycle, choice, and invocation transition
|
|
7629
|
+
* so the destination selected by `target` can contextually type the
|
|
7630
|
+
* corresponding resolver. Conditional transitions use the locally bound
|
|
7631
|
+
* `branch` constructor so every case independently infers its matched value and
|
|
7632
|
+
* selected destination, with no limit on the number of cases.
|
|
7633
|
+
*
|
|
7634
|
+
* ```ts
|
|
7635
|
+
* Machine.transition({
|
|
7636
|
+
* target: (to) => to.full.Ready(),
|
|
7637
|
+
* resolve: ({ target }) => target.from()
|
|
7638
|
+
* })
|
|
7639
|
+
*
|
|
7640
|
+
* Machine.transition({
|
|
7641
|
+
* cases: (branch) => [
|
|
7642
|
+
* branch({
|
|
7643
|
+
* title: "has cached data",
|
|
7644
|
+
* when: ({ event }) => event.cached,
|
|
7645
|
+
* target: (to) => to.full.Ready(),
|
|
7646
|
+
* resolve: ({ match, target }) => target.from({ data: match })
|
|
7647
|
+
* })
|
|
7648
|
+
* ],
|
|
7649
|
+
* otherwise: {
|
|
7650
|
+
* target: (to) => to.full.Loading(),
|
|
7651
|
+
* resolve: ({ target }) => target.from()
|
|
7652
|
+
* }
|
|
7653
|
+
* })
|
|
7654
|
+
* ```
|
|
7655
|
+
*
|
|
7656
|
+
* @category constructors
|
|
7657
|
+
* @since 0.14.0
|
|
7658
|
+
*/
|
|
7659
|
+
export const transition: TransitionConstructor = ((config: unknown) => {
|
|
7660
|
+
if (!hasProperty(config, "cases") || typeof config.cases !== "function") return config
|
|
7661
|
+
return {
|
|
7662
|
+
...config,
|
|
7663
|
+
cases: config.cases(<Case extends object>(branch: Case): Case => branch)
|
|
7664
|
+
}
|
|
7665
|
+
}) as TransitionConstructor
|
|
7666
|
+
|
|
7261
7667
|
/**
|
|
7262
7668
|
* Machine-bound invocation constructor that preserves the owning machine's
|
|
7263
7669
|
* public input and parent protocols in every invocation callback.
|
|
@@ -7376,73 +7782,74 @@ export interface Invoker<
|
|
|
7376
7782
|
): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<void, never, never, never>
|
|
7377
7783
|
<
|
|
7378
7784
|
StateId extends Machine.StateIdentifier<States>,
|
|
7379
|
-
|
|
7380
|
-
|
|
7381
|
-
|
|
7382
|
-
ChildRequirements,
|
|
7383
|
-
ChildOutput,
|
|
7384
|
-
ChildInitialError,
|
|
7785
|
+
const Source extends (
|
|
7786
|
+
context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
7787
|
+
) => unknown,
|
|
7385
7788
|
Address extends ChildAddress<never>
|
|
7386
7789
|
>(
|
|
7387
|
-
config:
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7404
|
-
ChildOutput,
|
|
7405
|
-
ChildInitialError
|
|
7790
|
+
config:
|
|
7791
|
+
& { readonly logic: Source }
|
|
7792
|
+
& Machine.LogicInvokeArgs<
|
|
7793
|
+
States,
|
|
7794
|
+
Events,
|
|
7795
|
+
Emits,
|
|
7796
|
+
StateId,
|
|
7797
|
+
Machine.LogicStateOf<ReturnType<Source>>,
|
|
7798
|
+
Machine.LogicEventOf<ReturnType<Source>>,
|
|
7799
|
+
Machine.LogicErrorOf<ReturnType<Source>>,
|
|
7800
|
+
Machine.LogicServicesOf<ReturnType<Source>>,
|
|
7801
|
+
Machine.LogicOutputOf<ReturnType<Source>>,
|
|
7802
|
+
Machine.LogicInitialErrorOf<ReturnType<Source>>,
|
|
7803
|
+
Address,
|
|
7804
|
+
Source,
|
|
7805
|
+
InputEvents,
|
|
7806
|
+
ParentEvents
|
|
7406
7807
|
>,
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
|
|
7808
|
+
..._validation: ReturnType<Source> extends { readonly initial: unknown; readonly run: unknown } ? [] : [
|
|
7809
|
+
"logic factory must return Machine.Logic"
|
|
7810
|
+
]
|
|
7410
7811
|
):
|
|
7411
7812
|
& Machine.InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
7412
|
-
& Machine.InvokeTyped<
|
|
7813
|
+
& Machine.InvokeTyped<
|
|
7814
|
+
Machine.LogicOutputOf<ReturnType<Source>>,
|
|
7815
|
+
Machine.LogicErrorOf<ReturnType<Source>>,
|
|
7816
|
+
Machine.LogicServicesOf<ReturnType<Source>>,
|
|
7817
|
+
Machine.LogicInitialErrorOf<ReturnType<Source>>
|
|
7818
|
+
>
|
|
7413
7819
|
<
|
|
7414
7820
|
StateId extends Machine.StateIdentifier<States>,
|
|
7415
|
-
|
|
7416
|
-
|
|
7417
|
-
ChildError,
|
|
7418
|
-
ChildRequirements,
|
|
7419
|
-
ChildOutput,
|
|
7420
|
-
ChildInitialError,
|
|
7421
|
-
Address extends ChildAddress<never>,
|
|
7422
|
-
const Config extends object
|
|
7821
|
+
const Source,
|
|
7822
|
+
Address extends ChildAddress<never>
|
|
7423
7823
|
>(
|
|
7424
7824
|
config:
|
|
7425
|
-
&
|
|
7825
|
+
& { readonly logic: Source }
|
|
7426
7826
|
& Machine.LogicInvokeArgs<
|
|
7427
7827
|
States,
|
|
7428
7828
|
Events,
|
|
7429
7829
|
Emits,
|
|
7430
7830
|
StateId,
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
|
|
7831
|
+
Machine.LogicStateOf<Source>,
|
|
7832
|
+
Machine.LogicEventOf<Source>,
|
|
7833
|
+
Machine.LogicErrorOf<Source>,
|
|
7834
|
+
Machine.LogicServicesOf<Source>,
|
|
7835
|
+
Machine.LogicOutputOf<Source>,
|
|
7836
|
+
Machine.LogicInitialErrorOf<Source>,
|
|
7437
7837
|
Address,
|
|
7438
|
-
|
|
7838
|
+
Source,
|
|
7439
7839
|
InputEvents,
|
|
7440
7840
|
ParentEvents
|
|
7441
|
-
|
|
7841
|
+
>,
|
|
7842
|
+
..._validation: Source extends { readonly initial: unknown; readonly run: unknown } ? [] : [
|
|
7843
|
+
"logic must implement Machine.Logic"
|
|
7844
|
+
]
|
|
7442
7845
|
):
|
|
7443
|
-
&
|
|
7444
|
-
& Machine.
|
|
7445
|
-
|
|
7846
|
+
& Machine.InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
7847
|
+
& Machine.InvokeTyped<
|
|
7848
|
+
Machine.LogicOutputOf<Source>,
|
|
7849
|
+
Machine.LogicErrorOf<Source>,
|
|
7850
|
+
Machine.LogicServicesOf<Source>,
|
|
7851
|
+
Machine.LogicInitialErrorOf<Source>
|
|
7852
|
+
>
|
|
7446
7853
|
<
|
|
7447
7854
|
StateId extends Machine.StateIdentifier<States>,
|
|
7448
7855
|
const Child extends ChildMachine.Any,
|
|
@@ -7504,8 +7911,14 @@ export interface Invoker<
|
|
|
7504
7911
|
* try: () => fetch("/api/data").then((response) => response.json()),
|
|
7505
7912
|
* catch: (cause) => new LoadError({ cause })
|
|
7506
7913
|
* }),
|
|
7507
|
-
* onDone:
|
|
7508
|
-
*
|
|
7914
|
+
* onDone: Machine.transition({
|
|
7915
|
+
* target: (to) => to.full.Ready(),
|
|
7916
|
+
* resolve: ({ output, target }) => target.from({ data: output })
|
|
7917
|
+
* }),
|
|
7918
|
+
* onFailure: Machine.transition({
|
|
7919
|
+
* target: (to) => to.full.Failed(),
|
|
7920
|
+
* resolve: ({ error, target }) => target.from({ error })
|
|
7921
|
+
* })
|
|
7509
7922
|
* })
|
|
7510
7923
|
* ```
|
|
7511
7924
|
*
|
|
@@ -7738,7 +8151,10 @@ export const invoke: {
|
|
|
7738
8151
|
* const machine = Machine.make({
|
|
7739
8152
|
* states: States.states,
|
|
7740
8153
|
* events: Machine.events(),
|
|
7741
|
-
* initial:
|
|
8154
|
+
* initial: {
|
|
8155
|
+
* target: (to) => to.Idle(),
|
|
8156
|
+
* resolve: ({ target }) => target.from()
|
|
8157
|
+
* }
|
|
7742
8158
|
* }).handle({ Idle: {} })
|
|
7743
8159
|
*
|
|
7744
8160
|
* const initialState = Effect.map(Machine.planInitial(machine), (plan) => plan.state)
|
|
@@ -7845,6 +8261,20 @@ export const stateNodes: <M extends Machine.Any>(machine: M) => ReadonlyArray<
|
|
|
7845
8261
|
>
|
|
7846
8262
|
> = internal.stateNodes
|
|
7847
8263
|
|
|
8264
|
+
/**
|
|
8265
|
+
* Returns the statically selected root entry used during machine startup.
|
|
8266
|
+
*
|
|
8267
|
+
* This function does not execute the initial resolver or require machine
|
|
8268
|
+
* input. `kind: "initial"` means that the selected root enters its declared
|
|
8269
|
+
* initial configuration.
|
|
8270
|
+
*
|
|
8271
|
+
* @category getters
|
|
8272
|
+
* @since 0.14.0
|
|
8273
|
+
*/
|
|
8274
|
+
export const initialDefinition: <M extends Machine.Any>(machine: M) => Machine.InitialDefinition<
|
|
8275
|
+
Machine.RootStateIdentifier<Machine.StateIdentifier<Machine.States<M>>>
|
|
8276
|
+
> = internal.initialDefinition
|
|
8277
|
+
|
|
7848
8278
|
/**
|
|
7849
8279
|
* Returns every registered transition handler in state definition order.
|
|
7850
8280
|
*
|
|
@@ -7852,9 +8282,9 @@ export const stateNodes: <M extends Machine.Any>(machine: M) => ReadonlyArray<
|
|
|
7852
8282
|
*
|
|
7853
8283
|
* Event handlers retain their handler-key order within each source state and
|
|
7854
8284
|
* are followed by eventless and completion handlers. This function does not
|
|
7855
|
-
* execute
|
|
7856
|
-
*
|
|
7857
|
-
*
|
|
8285
|
+
* execute predicates or resolvers. Every direct, conditional, fallback, and
|
|
8286
|
+
* targetless branch exposes the destination selected by its required static
|
|
8287
|
+
* `target` declaration.
|
|
7858
8288
|
*
|
|
7859
8289
|
* @category getters
|
|
7860
8290
|
* @since 0.4.0
|
|
@@ -7977,8 +8407,21 @@ export const enabled: <
|
|
|
7977
8407
|
* const machine = Machine.make({
|
|
7978
8408
|
* states: States.states,
|
|
7979
8409
|
* events: Machine.events(Toggle),
|
|
7980
|
-
* initial:
|
|
7981
|
-
*
|
|
8410
|
+
* initial: {
|
|
8411
|
+
* target: (to) => to.Off(),
|
|
8412
|
+
* resolve: ({ target }) => target.from()
|
|
8413
|
+
* }
|
|
8414
|
+
* }).handle({
|
|
8415
|
+
* Off: {
|
|
8416
|
+
* on: {
|
|
8417
|
+
* Toggle: Machine.transition({
|
|
8418
|
+
* target: (to) => to.full.On(),
|
|
8419
|
+
* resolve: ({ target }) => target.from()
|
|
8420
|
+
* })
|
|
8421
|
+
* }
|
|
8422
|
+
* },
|
|
8423
|
+
* On: {}
|
|
8424
|
+
* })
|
|
7982
8425
|
*
|
|
7983
8426
|
* const nextState = Effect.gen(function*() {
|
|
7984
8427
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -8111,41 +8554,6 @@ export const logic: <
|
|
|
8111
8554
|
) => Effect.Effect<Output, Error, Requirements>
|
|
8112
8555
|
}) => Logic<State, Event, Error, Requirements | InitialRequirements, Output, InitialError> = internal.logic
|
|
8113
8556
|
|
|
8114
|
-
/**
|
|
8115
|
-
* Creates child process logic from an initial state and a transition function.
|
|
8116
|
-
*
|
|
8117
|
-
* **When to use**
|
|
8118
|
-
*
|
|
8119
|
-
* Use when a child process only needs sequential event-driven state updates and
|
|
8120
|
-
* does not need direct control over intermediate snapshots or child ownership.
|
|
8121
|
-
*
|
|
8122
|
-
* **Details**
|
|
8123
|
-
*
|
|
8124
|
-
* Each received event runs the transition Effect against the latest state. The
|
|
8125
|
-
* resulting state is published before the next queued event is processed.
|
|
8126
|
-
*
|
|
8127
|
-
* **Example**
|
|
8128
|
-
*
|
|
8129
|
-
* ```ts
|
|
8130
|
-
* import { Effect } from "effect"
|
|
8131
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
8132
|
-
*
|
|
8133
|
-
* const counter = Machine.transition(
|
|
8134
|
-
* 0,
|
|
8135
|
-
* (count, event: { readonly by: number }) => Effect.succeed(count + event.by)
|
|
8136
|
-
* )
|
|
8137
|
-
* ```
|
|
8138
|
-
*
|
|
8139
|
-
* Use an inline `invoke` with an `effect` source for one-shot work.
|
|
8140
|
-
* @see {@link logic} for direct process lifecycle control.
|
|
8141
|
-
* @category constructors
|
|
8142
|
-
* @since 0.4.0
|
|
8143
|
-
*/
|
|
8144
|
-
export const transition: <State, Event, Error = never, Requirements = never>(
|
|
8145
|
-
initial: State,
|
|
8146
|
-
transition: (state: State, event: Event) => Effect.Effect<State, Error, Requirements>
|
|
8147
|
-
) => Logic<State, Event, Error, Requirements, never> = internal.transition
|
|
8148
|
-
|
|
8149
8557
|
/**
|
|
8150
8558
|
* Creates a typed descriptor for a complete child machine.
|
|
8151
8559
|
*
|
|
@@ -8382,7 +8790,10 @@ export const prepare: <
|
|
|
8382
8790
|
* const machine = Machine.make({
|
|
8383
8791
|
* states: States.states,
|
|
8384
8792
|
* events: Machine.events(),
|
|
8385
|
-
* initial:
|
|
8793
|
+
* initial: {
|
|
8794
|
+
* target: (to) => to.Idle(),
|
|
8795
|
+
* resolve: ({ target }) => target.from()
|
|
8796
|
+
* }
|
|
8386
8797
|
* }).handle({ Idle: {} })
|
|
8387
8798
|
*
|
|
8388
8799
|
* const state = Effect.gen(function*() {
|
|
@@ -8492,7 +8903,10 @@ export const start: <
|
|
|
8492
8903
|
* const machine = Machine.make({
|
|
8493
8904
|
* states: States.states,
|
|
8494
8905
|
* events: Machine.events(),
|
|
8495
|
-
* initial:
|
|
8906
|
+
* initial: {
|
|
8907
|
+
* target: (to) => to.Idle(),
|
|
8908
|
+
* resolve: ({ target }) => target.from()
|
|
8909
|
+
* }
|
|
8496
8910
|
* }).handle({ Idle: {} })
|
|
8497
8911
|
*
|
|
8498
8912
|
* const resumed = Effect.gen(function*() {
|