@typeonce/effect-machine 0.38.1 → 0.40.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 +52 -41
- package/dist/Machine.d.ts +62 -88
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +11 -24
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/atom.d.ts +1 -1
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js +1 -1
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/cluster.d.ts.map +1 -1
- package/dist/internal/machine/cluster.js +2 -2
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/clusterProtocol.d.ts +1 -1
- package/dist/internal/machine/clusterProtocol.d.ts.map +1 -1
- package/dist/internal/machine/clusterProtocol.js +0 -1
- package/dist/internal/machine/clusterProtocol.js.map +1 -1
- package/dist/internal/machine/declaration.d.ts +10 -3
- package/dist/internal/machine/declaration.d.ts.map +1 -1
- package/dist/internal/machine/declaration.js +47 -16
- package/dist/internal/machine/declaration.js.map +1 -1
- package/dist/internal/machine/errors.d.ts +15 -1
- package/dist/internal/machine/errors.d.ts.map +1 -1
- package/dist/internal/machine/errors.js +10 -0
- package/dist/internal/machine/errors.js.map +1 -1
- package/dist/internal/machine/initialDeclaration.d.ts +2 -2
- package/dist/internal/machine/initialDeclaration.d.ts.map +1 -1
- package/dist/internal/machine/initialDeclaration.js +8 -9
- package/dist/internal/machine/initialDeclaration.js.map +1 -1
- package/dist/internal/machine/machine.d.ts +26 -76
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +21 -16
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +216 -31
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +6 -12
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts +5 -9
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +19 -32
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/testing/machine/arbitrary.d.ts +1 -1
- package/dist/internal/testing/machine/arbitrary.d.ts.map +1 -1
- package/dist/internal/testing/machine/arbitrary.js +1 -1
- package/dist/internal/testing/machine/arbitrary.js.map +1 -1
- package/dist/internal/testing/machine/finiteModel.d.ts +1 -1
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +10 -13
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/runtime.d.ts +1 -1
- package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
- package/dist/internal/testing/machine/runtime.js +1 -1
- package/dist/internal/testing/machine/runtime.js.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +1 -1
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +8 -8
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +7 -7
- package/dist/unstable/cluster/ClusterMachine.d.ts +3 -3
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +4 -4
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +3 -3
- package/docs/agent-guide.md +23 -30
- package/docs/effect-atom-react.md +2 -2
- package/docs/machine-review.md +5 -6
- package/docs/root-api.md +27 -19
- package/package.json +4 -4
- package/src/Machine.ts +125 -163
- package/src/internal/machine/atom.ts +5 -8
- package/src/internal/machine/cluster.ts +3 -3
- package/src/internal/machine/clusterProtocol.ts +1 -1
- package/src/internal/machine/declaration.ts +56 -17
- package/src/internal/machine/errors.ts +22 -1
- package/src/internal/machine/initialDeclaration.ts +10 -12
- package/src/internal/machine/machine.ts +85 -465
- package/src/internal/machine/planner.ts +84 -190
- package/src/internal/machine/process.ts +80 -279
- package/src/internal/testing/machine/arbitrary.ts +1 -1
- package/src/internal/testing/machine/finiteModel.ts +8 -12
- package/src/internal/testing/machine/runtime.ts +1 -1
- package/src/internal/testing/machine/verification.ts +1 -1
- package/src/testing/MachineTest.ts +8 -8
- package/src/unstable/cluster/ClusterMachine.ts +3 -3
- package/src/unstable/reactivity/AtomMachine.ts +4 -4
- package/dist/internal/machine/targetReference.d.ts +0 -15
- package/dist/internal/machine/targetReference.d.ts.map +0 -1
- package/dist/internal/machine/targetReference.js +0 -41
- package/dist/internal/machine/targetReference.js.map +0 -1
- package/src/internal/machine/targetReference.ts +0 -55
package/src/Machine.ts
CHANGED
|
@@ -122,7 +122,6 @@ type IsAny<A> = 0 extends (1 & A) ? true : false
|
|
|
122
122
|
* import { Schema } from "effect"
|
|
123
123
|
* const events = Machine.events({ Add: { by: Schema.Number } })
|
|
124
124
|
* const Root = Machine.state({ fields: { count: Schema.Number } })
|
|
125
|
-
* const targets = Machine.targets(Root)
|
|
126
125
|
* export const counter = Machine.make({
|
|
127
126
|
* root: Root,
|
|
128
127
|
* events
|
|
@@ -130,7 +129,7 @@ type IsAny<A> = 0 extends (1 & A) ? true : false
|
|
|
130
129
|
* root: () => ({ count: 0 }),
|
|
131
130
|
* on: {
|
|
132
131
|
* Add: {
|
|
133
|
-
* update:
|
|
132
|
+
* update: "root",
|
|
134
133
|
* guard: ({ event }) => event.by > 0,
|
|
135
134
|
* data: ({ root, event }) => ({ count: root.count + event.by })
|
|
136
135
|
* }
|
|
@@ -307,12 +306,11 @@ export interface Definition<
|
|
|
307
306
|
* **Example**
|
|
308
307
|
*
|
|
309
308
|
* ```ts
|
|
310
|
-
* const targets = Machine.targets(States)
|
|
311
309
|
* const counter = definition.handle({ states: {
|
|
312
310
|
* Count: {
|
|
313
311
|
* on: {
|
|
314
312
|
* Increment: {
|
|
315
|
-
* update:
|
|
313
|
+
* update: "Count",
|
|
316
314
|
* decoded: ({ event, state }) => new Count({ value: state.value + event.by })
|
|
317
315
|
* }
|
|
318
316
|
* }
|
|
@@ -2613,7 +2611,6 @@ export declare namespace Machine {
|
|
|
2613
2611
|
/** @internal */
|
|
2614
2612
|
readonly stateNodes: StateNodes
|
|
2615
2613
|
/** @internal */
|
|
2616
|
-
/** @internal */
|
|
2617
2614
|
readonly handlers: any
|
|
2618
2615
|
/** @internal */
|
|
2619
2616
|
readonly initial: any
|
|
@@ -5138,10 +5135,8 @@ export declare namespace Machine {
|
|
|
5138
5135
|
* @category utility types
|
|
5139
5136
|
* @since 0.4.0
|
|
5140
5137
|
*/
|
|
5141
|
-
export type EventTransitionReturn<Transition> = Transition extends
|
|
5142
|
-
|
|
5143
|
-
: Transition extends { readonly resolve?: infer Resolve } ?
|
|
5144
|
-
NonNullable<Resolve> extends (...args: any) => infer Ret ? Ret : never
|
|
5138
|
+
export type EventTransitionReturn<Transition> = Transition extends { readonly resolve?: infer Resolve } ?
|
|
5139
|
+
NonNullable<Resolve> extends (...args: any) => infer Ret ? Ret : never
|
|
5145
5140
|
: never
|
|
5146
5141
|
/**
|
|
5147
5142
|
* Extracts the return value from a state's event handlers.
|
|
@@ -6386,15 +6381,13 @@ export declare namespace Machine {
|
|
|
6386
6381
|
Sources[K] extends (...args: never[]) => unknown ? Parameters<Sources[K]>["length"] extends 1 ? unknown : never
|
|
6387
6382
|
: unknown
|
|
6388
6383
|
}
|
|
6389
|
-
|
|
6390
|
-
type
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6384
|
+
// Declarations spell descendants as dotted paths and the root node as "root".
|
|
6385
|
+
type PathName<P extends string> = P extends "" ? "root" : P
|
|
6386
|
+
type PathOf<Name> = Name extends "root" ? "" : Name extends string ? Name : never
|
|
6387
|
+
type ReferenceAt<S extends StateSchemas, P extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = PathName<P>
|
|
6388
|
+
type ReferenceUnion<S extends StateSchemas, Paths extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = PathName<
|
|
6389
|
+
Paths
|
|
6394
6390
|
>
|
|
6395
|
-
type ReferenceUnion<S extends StateSchemas, Paths extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = {
|
|
6396
|
-
readonly [P in Paths]: ReferenceAt<S, P>
|
|
6397
|
-
}[Paths]
|
|
6398
6391
|
type DestinationPath<S extends StateSchemas> = Exclude<StateNodeIdentifier<S>, "">
|
|
6399
6392
|
type RootSchemas<Root extends StateNodeConfig> = { readonly "": Root }
|
|
6400
6393
|
|
|
@@ -6407,7 +6400,7 @@ export declare namespace Machine {
|
|
|
6407
6400
|
& (
|
|
6408
6401
|
| {
|
|
6409
6402
|
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6410
|
-
readonly target: ReferenceUnion<S, DestinationPath<S>>
|
|
6403
|
+
readonly target: ReferenceUnion<S, DestinationPath<S>>
|
|
6411
6404
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6412
6405
|
readonly update?: ReferenceUnion<S, ValuedStateIdentifier<S>>
|
|
6413
6406
|
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
@@ -6416,6 +6409,22 @@ export declare namespace Machine {
|
|
|
6416
6409
|
readonly history?: never
|
|
6417
6410
|
/** Accepts the event without selecting a new destination. */
|
|
6418
6411
|
readonly none?: never
|
|
6412
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
6413
|
+
readonly initialize?: never
|
|
6414
|
+
}
|
|
6415
|
+
| {
|
|
6416
|
+
/** Reconstructs root and its initial children from fresh machine input supplied by the resolver. */
|
|
6417
|
+
readonly initialize: true
|
|
6418
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
6419
|
+
readonly target?: never
|
|
6420
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
6421
|
+
readonly update?: never
|
|
6422
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
6423
|
+
readonly initial?: never
|
|
6424
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6425
|
+
readonly history?: never
|
|
6426
|
+
/** Accepts the event without selecting a new destination. */
|
|
6427
|
+
readonly none?: never
|
|
6419
6428
|
}
|
|
6420
6429
|
| {
|
|
6421
6430
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
@@ -6428,6 +6437,8 @@ export declare namespace Machine {
|
|
|
6428
6437
|
readonly history?: never
|
|
6429
6438
|
/** Accepts the event without selecting a new destination. */
|
|
6430
6439
|
readonly none?: never
|
|
6440
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
6441
|
+
readonly initialize?: never
|
|
6431
6442
|
}
|
|
6432
6443
|
| {
|
|
6433
6444
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
@@ -6440,6 +6451,8 @@ export declare namespace Machine {
|
|
|
6440
6451
|
readonly initial?: never
|
|
6441
6452
|
/** Accepts the event without selecting a new destination. */
|
|
6442
6453
|
readonly none?: never
|
|
6454
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
6455
|
+
readonly initialize?: never
|
|
6443
6456
|
}
|
|
6444
6457
|
| {
|
|
6445
6458
|
/** Accepts the event without selecting a new destination. */
|
|
@@ -6452,6 +6465,8 @@ export declare namespace Machine {
|
|
|
6452
6465
|
readonly initial?: never
|
|
6453
6466
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6454
6467
|
readonly history?: never
|
|
6468
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
6469
|
+
readonly initialize?: never
|
|
6455
6470
|
}
|
|
6456
6471
|
)
|
|
6457
6472
|
export type BranchDefinitions<Root extends StateNodeConfig> = Readonly<
|
|
@@ -6474,7 +6489,7 @@ export declare namespace Machine {
|
|
|
6474
6489
|
}
|
|
6475
6490
|
type RegisteredInput<R> = R extends { readonly "~input": infer I extends Schema.Top } ? I : typeof Schema.Void
|
|
6476
6491
|
type Registered<R, Kind extends PropertyKey> = Kind extends keyof R ? NonNullable<R[Kind]> : {}
|
|
6477
|
-
type RefPath<R> = R
|
|
6492
|
+
type RefPath<R> = PathOf<R>
|
|
6478
6493
|
type ConstructionData<Node> = [NodeSchema<Node>] extends [never] ? { readonly data?: never; readonly decoded?: never }
|
|
6479
6494
|
:
|
|
6480
6495
|
| (
|
|
@@ -6539,30 +6554,38 @@ export declare namespace Machine {
|
|
|
6539
6554
|
>
|
|
6540
6555
|
: never
|
|
6541
6556
|
type SelectionOf<S extends StateSchemas, Src extends StateNodeIdentifier<S>, D, R = {}> = D extends {
|
|
6542
|
-
readonly
|
|
6543
|
-
} ?
|
|
6544
|
-
|
|
6545
|
-
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6557
|
+
readonly initialize: true
|
|
6558
|
+
} ? TargetSelection<ObjectSelection<S, Src, Extract<"", StateNodeIdentifier<S>>, R>, "", "state", "branch">
|
|
6559
|
+
: D extends {
|
|
6560
|
+
readonly target: infer Ref
|
|
6561
|
+
} ?
|
|
6562
|
+
RefPath<Ref> extends infer P extends StateNodeIdentifier<S> ?
|
|
6563
|
+
D extends { readonly update: infer Update }
|
|
6564
|
+
? RefPath<Update> extends
|
|
6565
|
+
infer Owner extends Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>
|
|
6566
|
+
? P extends StateIdentifier<S> ? TargetSelection<
|
|
6567
|
+
ConstructionCall<
|
|
6568
|
+
ConstructionObject<
|
|
6569
|
+
NodeByIdentifier<S, P>,
|
|
6570
|
+
Src extends `${P}.${infer Rest}` ? Rest : Src extends P ? "" : never
|
|
6571
|
+
> & {
|
|
6572
|
+
readonly update: ConstructionData<NodeByIdentifier<S, Owner>>
|
|
6573
|
+
},
|
|
6574
|
+
CombinedTarget<Target<S, P>, S, Owner>
|
|
6575
|
+
>,
|
|
6576
|
+
P,
|
|
6577
|
+
"state",
|
|
6578
|
+
"branch"
|
|
6579
|
+
> :
|
|
6580
|
+
never
|
|
6581
|
+
: never
|
|
6582
|
+
: TargetSelection<
|
|
6583
|
+
ObjectSelection<S, Src, P, R>,
|
|
6584
|
+
P,
|
|
6585
|
+
P extends ChoiceIdentifier<S> ? "choice" : "state",
|
|
6586
|
+
"branch"
|
|
6587
|
+
>
|
|
6588
|
+
: never
|
|
6566
6589
|
: D extends { readonly history: infer Ref }
|
|
6567
6590
|
? RefPath<Ref> extends infer P extends HistoryIdentifier<S>
|
|
6568
6591
|
? TargetSelection<() => HistoryTarget<S, P>, P, "history", "full"> :
|
|
@@ -6610,22 +6633,20 @@ export declare namespace Machine {
|
|
|
6610
6633
|
> = P extends ChoiceIdentifier<S> ? { readonly from?: never; readonly decoded?: never }
|
|
6611
6634
|
: P extends StateIdentifier<S> ? InlineNodeConstruction<C, NodeByIdentifier<S, P>>
|
|
6612
6635
|
: never
|
|
6613
|
-
type InlineRoot<
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
>
|
|
6628
|
-
})
|
|
6636
|
+
type InlineRoot<C, R> = {
|
|
6637
|
+
/**
|
|
6638
|
+
* Reconstructs root and its initial children from fresh machine input.
|
|
6639
|
+
* Machines without an input schema use `true`.
|
|
6640
|
+
*/
|
|
6641
|
+
readonly initialize: RegisteredInput<R> extends typeof Schema.Void ? true
|
|
6642
|
+
: DataValue<C, RegisteredInput<R>["Type"]>
|
|
6643
|
+
readonly target?: never
|
|
6644
|
+
readonly update?: never
|
|
6645
|
+
readonly branches?: never
|
|
6646
|
+
readonly resolve?: never
|
|
6647
|
+
readonly history?: never
|
|
6648
|
+
readonly none?: never
|
|
6649
|
+
}
|
|
6629
6650
|
type InlineDestination<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = {
|
|
6630
6651
|
readonly [P in DestinationPath<S>]:
|
|
6631
6652
|
& {
|
|
@@ -6826,7 +6847,7 @@ export declare namespace Machine {
|
|
|
6826
6847
|
| InlineDestination<S, Src, C>
|
|
6827
6848
|
| InlineUpdate<S, Src, C>
|
|
6828
6849
|
| InlineCombined<S, Src, C>
|
|
6829
|
-
| InlineRoot<
|
|
6850
|
+
| InlineRoot<C, R>
|
|
6830
6851
|
| {
|
|
6831
6852
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
6832
6853
|
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>
|
|
@@ -7084,11 +7105,7 @@ export declare namespace Machine {
|
|
|
7084
7105
|
{ readonly states: infer Children extends StateSchemas } ? {
|
|
7085
7106
|
readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]:
|
|
7086
7107
|
& {
|
|
7087
|
-
readonly target:
|
|
7088
|
-
ReferenceRoot<S>,
|
|
7089
|
-
JoinPath<Src, K>,
|
|
7090
|
-
Children[K] extends ChoiceStateNodeConfig ? "choice" : "state"
|
|
7091
|
-
>
|
|
7108
|
+
readonly target: JoinPath<Src, K>
|
|
7092
7109
|
}
|
|
7093
7110
|
& InitialData<C, Children[K]>
|
|
7094
7111
|
}[ActiveStateKey<Children> | ChoiceStateKey<Children>]
|
|
@@ -7343,8 +7360,9 @@ export declare namespace Machine {
|
|
|
7343
7360
|
}) :
|
|
7344
7361
|
never)
|
|
7345
7362
|
type ValidateObjectTransition<T> =
|
|
7346
|
-
& ("
|
|
7347
|
-
|
|
7363
|
+
& ("initialize" extends keyof T ? {
|
|
7364
|
+
readonly [K in Exclude<keyof T, "initialize" | "guard" | "reenter">]: never
|
|
7365
|
+
}
|
|
7348
7366
|
: unknown)
|
|
7349
7367
|
& {
|
|
7350
7368
|
readonly [
|
|
@@ -7352,7 +7370,7 @@ export declare namespace Machine {
|
|
|
7352
7370
|
keyof T,
|
|
7353
7371
|
| "target"
|
|
7354
7372
|
| "update"
|
|
7355
|
-
| "
|
|
7373
|
+
| "initialize"
|
|
7356
7374
|
| "history"
|
|
7357
7375
|
| "none"
|
|
7358
7376
|
| "branches"
|
|
@@ -7737,12 +7755,12 @@ export const isFinal: <
|
|
|
7737
7755
|
ParentEvents
|
|
7738
7756
|
>,
|
|
7739
7757
|
state: Machine.Snapshot<States>
|
|
7740
|
-
) => state is Machine.SnapshotContainingFinal<States, FinalStates> = internal.isFinal
|
|
7758
|
+
) => state is Machine.SnapshotContainingFinal<States, FinalStates> = internal.isFinal
|
|
7741
7759
|
|
|
7742
7760
|
/**
|
|
7743
7761
|
* Defines root or nested state schemas while preserving the exact child topology.
|
|
7744
7762
|
*
|
|
7745
|
-
* Pass the root descriptor to {@link make}
|
|
7763
|
+
* Pass the root descriptor to {@link make}. Nested states
|
|
7746
7764
|
* can be declared inline or reused by mounting a descriptor in multiple places.
|
|
7747
7765
|
* Initial edges and value constructors belong in the handler tree.
|
|
7748
7766
|
*
|
|
@@ -7777,69 +7795,6 @@ export const isFinal: <
|
|
|
7777
7795
|
*/
|
|
7778
7796
|
export const state: StateConstructor = internal.state as StateConstructor
|
|
7779
7797
|
|
|
7780
|
-
/**
|
|
7781
|
-
* An opaque reference to one node in a declared state tree.
|
|
7782
|
-
*
|
|
7783
|
-
* @category models
|
|
7784
|
-
* @since 0.34.0
|
|
7785
|
-
*/
|
|
7786
|
-
export interface TargetReference<
|
|
7787
|
-
Root extends Machine.StateNodeConfig,
|
|
7788
|
-
Path extends string,
|
|
7789
|
-
Kind extends "state" | "choice" | "history"
|
|
7790
|
-
> {
|
|
7791
|
-
readonly [internal.TargetReferenceTypeId]: {
|
|
7792
|
-
readonly root: { readonly node: Root }
|
|
7793
|
-
readonly path: Path
|
|
7794
|
-
readonly kind: Kind
|
|
7795
|
-
}
|
|
7796
|
-
}
|
|
7797
|
-
|
|
7798
|
-
type TargetReferenceTree<Root extends Machine.StateNodeConfig, Node, Path extends string> =
|
|
7799
|
-
& TargetReference<
|
|
7800
|
-
Root,
|
|
7801
|
-
Path,
|
|
7802
|
-
Node extends { readonly type: "history" } ? "history"
|
|
7803
|
-
: Node extends { readonly type: "choice" } ? "choice"
|
|
7804
|
-
: "state"
|
|
7805
|
-
>
|
|
7806
|
-
& (Node extends {
|
|
7807
|
-
/** Child handlers nested according to the declared root topology. */
|
|
7808
|
-
readonly states: infer Children
|
|
7809
|
-
} ? {
|
|
7810
|
-
readonly [Key in Extract<keyof Children, string>]: TargetReferenceTree<
|
|
7811
|
-
Root,
|
|
7812
|
-
Children[Key],
|
|
7813
|
-
Machine.JoinPath<Path, Key>
|
|
7814
|
-
>
|
|
7815
|
-
} :
|
|
7816
|
-
{})
|
|
7817
|
-
|
|
7818
|
-
/**
|
|
7819
|
-
* References for every path in a declared root tree.
|
|
7820
|
-
*
|
|
7821
|
-
* @category models
|
|
7822
|
-
* @since 0.34.0
|
|
7823
|
-
*/
|
|
7824
|
-
export interface Targets<Root extends Machine.StateNodeConfig> {
|
|
7825
|
-
/** Root data owner and the starting point for descendant state references. */
|
|
7826
|
-
readonly root: TargetReferenceTree<Root, Root, "">
|
|
7827
|
-
}
|
|
7828
|
-
|
|
7829
|
-
/**
|
|
7830
|
-
* Derives immutable state references from a root descriptor.
|
|
7831
|
-
*
|
|
7832
|
-
* References follow the declared tree: `targets.root.Checkout.Review`.
|
|
7833
|
-
* Creating references does not construct state values or start machine work.
|
|
7834
|
-
*
|
|
7835
|
-
* @category constructors
|
|
7836
|
-
* @since 0.34.0
|
|
7837
|
-
*/
|
|
7838
|
-
export const targets: <const Root extends Machine.StateNodeConfig>(root: State<Root>) => Targets<Root> = internal
|
|
7839
|
-
.targets as unknown as <const Root extends Machine.StateNodeConfig>(
|
|
7840
|
-
root: State<Root>
|
|
7841
|
-
) => Targets<Root>
|
|
7842
|
-
|
|
7843
7798
|
type UniqueSourceNames<F, S, T, L, C> = [
|
|
7844
7799
|
| Extract<keyof F, keyof S | keyof T | keyof L | keyof C>
|
|
7845
7800
|
| Extract<keyof S, keyof T | keyof L | keyof C>
|
|
@@ -7847,6 +7802,10 @@ type UniqueSourceNames<F, S, T, L, C> = [
|
|
|
7847
7802
|
| Extract<keyof L, keyof C>
|
|
7848
7803
|
] extends [never] ? unknown : { readonly "~effect/Machine/DuplicateSourceName": never }
|
|
7849
7804
|
|
|
7805
|
+
type ReservedRootName<Root> = Root extends { readonly states: infer Children }
|
|
7806
|
+
? "root" extends keyof Children ? { readonly "~effect/Machine/ReservedRootStateName": never } : unknown
|
|
7807
|
+
: unknown
|
|
7808
|
+
|
|
7850
7809
|
type MakeConfig<
|
|
7851
7810
|
Root extends Machine.StateNodeConfig,
|
|
7852
7811
|
InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
@@ -7880,7 +7839,9 @@ type MakeConfig<
|
|
|
7880
7839
|
/** Stable definition identifier used by inspection and visualization. */
|
|
7881
7840
|
readonly id?: string
|
|
7882
7841
|
/** State topology and value schemas, captured by a `Machine.state` descriptor. */
|
|
7883
|
-
readonly root:
|
|
7842
|
+
readonly root:
|
|
7843
|
+
& { readonly [StateTypeId]: typeof StateTypeId; readonly node: Root }
|
|
7844
|
+
& ReservedRootName<NoInfer<Root>>
|
|
7884
7845
|
/** Public events accepted by independently running machine references. */
|
|
7885
7846
|
readonly events:
|
|
7886
7847
|
& Machine.EventProtocol<"public", InputEvents>
|
|
@@ -8037,13 +7998,12 @@ interface Make {
|
|
|
8037
7998
|
* }
|
|
8038
7999
|
* const States = Machine.state({ states: { Count } })
|
|
8039
8000
|
* const Events = Machine.eventsFromSchemas(Increment)
|
|
8040
|
-
* const targets = Machine.targets(States)
|
|
8041
8001
|
* const counter = Machine.make({
|
|
8042
8002
|
* root: States,
|
|
8043
8003
|
* events: Events
|
|
8044
8004
|
* }).handle({
|
|
8045
8005
|
* initial: {
|
|
8046
|
-
* target:
|
|
8006
|
+
* target: "Count",
|
|
8047
8007
|
* decoded: true,
|
|
8048
8008
|
* data: new Count({ value: 0 })
|
|
8049
8009
|
* },
|
|
@@ -8051,7 +8011,7 @@ interface Make {
|
|
|
8051
8011
|
* Count: {
|
|
8052
8012
|
* on: {
|
|
8053
8013
|
* Increment: {
|
|
8054
|
-
* update:
|
|
8014
|
+
* update: "Count",
|
|
8055
8015
|
* decoded: true,
|
|
8056
8016
|
* data: ({ event, state }) => new Count({ value: state.value + event.by })
|
|
8057
8017
|
* }
|
|
@@ -8066,7 +8026,7 @@ interface Make {
|
|
|
8066
8026
|
* @category constructors
|
|
8067
8027
|
* @since 0.4.0
|
|
8068
8028
|
*/
|
|
8069
|
-
export const make: Make = internal.make
|
|
8029
|
+
export const make: Make = internal.make
|
|
8070
8030
|
|
|
8071
8031
|
/**
|
|
8072
8032
|
* Extracts the decoded event union carried by an event protocol descriptor.
|
|
@@ -8131,7 +8091,7 @@ type ValidateEventFields<Cases> = {
|
|
|
8131
8091
|
*/
|
|
8132
8092
|
export const events: <const Cases extends Readonly<Record<string, Schema.Struct.Fields>>>(
|
|
8133
8093
|
cases: Cases & ValidateEventFields<NoInfer<Cases>> & ValidateEventProtocolBuilder<"public", EventFieldsSchemas<Cases>>
|
|
8134
|
-
) => Machine.EventProtocol<"public", EventFieldsSchemas<Cases>> = internal.eventsFromFields
|
|
8094
|
+
) => Machine.EventProtocol<"public", EventFieldsSchemas<Cases>> = internal.eventsFromFields
|
|
8135
8095
|
|
|
8136
8096
|
/** Imports existing schemas and protocols without rebuilding their contracts.
|
|
8137
8097
|
* @category constructors
|
|
@@ -8141,7 +8101,7 @@ export const eventsFromSchemas: {
|
|
|
8141
8101
|
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"public">>>(
|
|
8142
8102
|
...inputs: Inputs & ValidateEventProtocolBuilder<"public", Inputs>
|
|
8143
8103
|
): Machine.EventProtocol<"public", Machine.EventProtocolInputSchemasOf<"public", Inputs>>
|
|
8144
|
-
} = internal.events
|
|
8104
|
+
} = internal.events
|
|
8145
8105
|
|
|
8146
8106
|
/**
|
|
8147
8107
|
* Requires the machine to run as an owned child whose parent accepts the
|
|
@@ -8201,7 +8161,7 @@ export const internalEvents: <const Cases extends Readonly<Record<string, Schema
|
|
|
8201
8161
|
& Cases
|
|
8202
8162
|
& ValidateEventFields<NoInfer<Cases>>
|
|
8203
8163
|
& ValidateEventProtocolBuilder<"internal", EventFieldsSchemas<Cases>>
|
|
8204
|
-
) => Machine.EventProtocol<"internal", EventFieldsSchemas<Cases>> = internal.internalEventsFromFields
|
|
8164
|
+
) => Machine.EventProtocol<"internal", EventFieldsSchemas<Cases>> = internal.internalEventsFromFields
|
|
8205
8165
|
|
|
8206
8166
|
/** Imports existing schemas and protocols without rebuilding their contracts.
|
|
8207
8167
|
* @category constructors
|
|
@@ -8211,7 +8171,7 @@ export const internalEventsFromSchemas: {
|
|
|
8211
8171
|
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"internal">>>(
|
|
8212
8172
|
...inputs: Inputs & ValidateEventProtocolBuilder<"internal", Inputs>
|
|
8213
8173
|
): Machine.EventProtocol<"internal", Machine.EventProtocolInputSchemasOf<"internal", Inputs>>
|
|
8214
|
-
} = internal.internalEvents
|
|
8174
|
+
} = internal.internalEvents
|
|
8215
8175
|
|
|
8216
8176
|
/**
|
|
8217
8177
|
* Defines the ephemeral notifications a machine may publish to external
|
|
@@ -8238,7 +8198,7 @@ export const emittedEvents: <const Cases extends Readonly<Record<string, Schema.
|
|
|
8238
8198
|
& Cases
|
|
8239
8199
|
& ValidateEventFields<NoInfer<Cases>>
|
|
8240
8200
|
& ValidateEventProtocolBuilder<"emitted", EventFieldsSchemas<Cases>>
|
|
8241
|
-
) => Machine.EventProtocol<"emitted", EventFieldsSchemas<Cases>> = internal.emittedEventsFromFields
|
|
8201
|
+
) => Machine.EventProtocol<"emitted", EventFieldsSchemas<Cases>> = internal.emittedEventsFromFields
|
|
8242
8202
|
|
|
8243
8203
|
/** Imports existing schemas and protocols without rebuilding their contracts.
|
|
8244
8204
|
* @category constructors
|
|
@@ -8248,7 +8208,7 @@ export const emittedEventsFromSchemas: {
|
|
|
8248
8208
|
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"emitted">>>(
|
|
8249
8209
|
...inputs: Inputs & ValidateEventProtocolBuilder<"emitted", Inputs>
|
|
8250
8210
|
): Machine.EventProtocol<"emitted", Machine.EventProtocolInputSchemasOf<"emitted", Inputs>>
|
|
8251
|
-
} = internal.emittedEvents
|
|
8211
|
+
} = internal.emittedEvents
|
|
8252
8212
|
|
|
8253
8213
|
/**
|
|
8254
8214
|
* Encodes a decoded machine snapshot into a normalized data representation.
|
|
@@ -8289,7 +8249,7 @@ export const emittedEventsFromSchemas: {
|
|
|
8289
8249
|
* events: Machine.eventsFromSchemas()
|
|
8290
8250
|
* }).handle({
|
|
8291
8251
|
* initial: {
|
|
8292
|
-
* target:
|
|
8252
|
+
* target: "Idle"
|
|
8293
8253
|
* },
|
|
8294
8254
|
* states: {
|
|
8295
8255
|
* Idle: {}
|
|
@@ -8342,7 +8302,7 @@ export const encodeSnapshot: <
|
|
|
8342
8302
|
Machine.EncodedSnapshot,
|
|
8343
8303
|
MachineSchemaEncodeError,
|
|
8344
8304
|
Machine.SnapshotEncodingServices<States>
|
|
8345
|
-
> = internal.encodeSnapshot
|
|
8305
|
+
> = internal.encodeSnapshot
|
|
8346
8306
|
|
|
8347
8307
|
/**
|
|
8348
8308
|
* Decodes a normalized data representation into a validated machine snapshot.
|
|
@@ -8376,7 +8336,7 @@ export const encodeSnapshot: <
|
|
|
8376
8336
|
* events: Machine.eventsFromSchemas()
|
|
8377
8337
|
* }).handle({
|
|
8378
8338
|
* initial: {
|
|
8379
|
-
* target:
|
|
8339
|
+
* target: "Idle"
|
|
8380
8340
|
* },
|
|
8381
8341
|
* states: {
|
|
8382
8342
|
* Idle: {}
|
|
@@ -8430,7 +8390,7 @@ export const decodeSnapshot: <
|
|
|
8430
8390
|
Machine.Snapshot<States>,
|
|
8431
8391
|
MachineSchemaDecodeError,
|
|
8432
8392
|
Machine.SnapshotDecodingServices<States>
|
|
8433
|
-
> = internal.decodeSnapshot
|
|
8393
|
+
> = internal.decodeSnapshot
|
|
8434
8394
|
|
|
8435
8395
|
type TransitionBranchRecordError<Message extends string, Key extends PropertyKey = never> = {
|
|
8436
8396
|
readonly "~effect/Machine/TransitionBranchRecordError": Message
|
|
@@ -8448,7 +8408,10 @@ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never]
|
|
|
8448
8408
|
readonly [K in keyof Branches]:
|
|
8449
8409
|
& {
|
|
8450
8410
|
readonly [
|
|
8451
|
-
Extra in Exclude<
|
|
8411
|
+
Extra in Exclude<
|
|
8412
|
+
keyof Branches[K],
|
|
8413
|
+
"target" | "update" | "initialize" | "initial" | "history" | "none" | "title"
|
|
8414
|
+
>
|
|
8452
8415
|
]: never
|
|
8453
8416
|
}
|
|
8454
8417
|
& (Branches[K] extends { readonly title: "" } ? { readonly title: never } : unknown)
|
|
@@ -8489,7 +8452,7 @@ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never]
|
|
|
8489
8452
|
* events: Machine.eventsFromSchemas()
|
|
8490
8453
|
* }).handle({
|
|
8491
8454
|
* initial: {
|
|
8492
|
-
* target:
|
|
8455
|
+
* target: "Idle"
|
|
8493
8456
|
* },
|
|
8494
8457
|
* states: {
|
|
8495
8458
|
* Idle: {}
|
|
@@ -8578,7 +8541,7 @@ export const planInitial: <
|
|
|
8578
8541
|
),
|
|
8579
8542
|
InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError,
|
|
8580
8543
|
never
|
|
8581
|
-
> = internal.planInitial
|
|
8544
|
+
> = internal.planInitial
|
|
8582
8545
|
|
|
8583
8546
|
/**
|
|
8584
8547
|
* Returns every compiled state node in definition order.
|
|
@@ -8738,7 +8701,7 @@ export const enabled: <
|
|
|
8738
8701
|
ParentEvents
|
|
8739
8702
|
>,
|
|
8740
8703
|
state: Machine.Snapshot<States>
|
|
8741
|
-
) => ReadonlyArray<Machine.TagOf<Events[number]>> = internal.enabled
|
|
8704
|
+
) => ReadonlyArray<Machine.TagOf<Events[number]>> = internal.enabled
|
|
8742
8705
|
|
|
8743
8706
|
/**
|
|
8744
8707
|
* Tests whether a concrete event would select at least one transition from a
|
|
@@ -8779,7 +8742,7 @@ export const enabled: <
|
|
|
8779
8742
|
* events: Machine.eventsFromSchemas(),
|
|
8780
8743
|
* internalEvents
|
|
8781
8744
|
* }).handle({
|
|
8782
|
-
* initial: { target:
|
|
8745
|
+
* initial: { target: "Idle" },
|
|
8783
8746
|
* states: { Idle: { on: { Loaded: { none: true } } } }
|
|
8784
8747
|
* })
|
|
8785
8748
|
*
|
|
@@ -8870,7 +8833,7 @@ export const can: {
|
|
|
8870
8833
|
state: Machine.Snapshot<States>,
|
|
8871
8834
|
event: Machine.EventInputOf<Events>
|
|
8872
8835
|
): Effect.Effect<boolean, MachineSchemaDecodeError>
|
|
8873
|
-
} = internal.can
|
|
8836
|
+
} = internal.can
|
|
8874
8837
|
|
|
8875
8838
|
/**
|
|
8876
8839
|
* Returns an Effect that plans the next state snapshot without running command effects.
|
|
@@ -8901,18 +8864,17 @@ export const can: {
|
|
|
8901
8864
|
* class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {
|
|
8902
8865
|
* }
|
|
8903
8866
|
* const States = Machine.state({ states: { Off, On } })
|
|
8904
|
-
* const targets = Machine.targets(States)
|
|
8905
8867
|
* const machine = Machine.make({
|
|
8906
8868
|
* root: States,
|
|
8907
8869
|
* events: Machine.eventsFromSchemas(Toggle)
|
|
8908
8870
|
* }).handle({
|
|
8909
8871
|
* initial: {
|
|
8910
|
-
* target:
|
|
8872
|
+
* target: "Off"
|
|
8911
8873
|
* },
|
|
8912
8874
|
* states: {
|
|
8913
8875
|
* Off: {
|
|
8914
8876
|
* on: {
|
|
8915
|
-
* Toggle: { target:
|
|
8877
|
+
* Toggle: { target: "On" }
|
|
8916
8878
|
* }
|
|
8917
8879
|
* },
|
|
8918
8880
|
* On: {}
|
|
@@ -9004,7 +8966,7 @@ export const plan: <
|
|
|
9004
8966
|
),
|
|
9005
8967
|
E | InfiniteTransitionError | MachineSchemaDecodeError,
|
|
9006
8968
|
never
|
|
9007
|
-
> = internal.plan
|
|
8969
|
+
> = internal.plan
|
|
9008
8970
|
|
|
9009
8971
|
/**
|
|
9010
8972
|
* Creates advanced stateful process logic from explicit initialization and
|
|
@@ -9315,7 +9277,7 @@ export const prepare: <
|
|
|
9315
9277
|
Machine.EmittedEventOf<Emits>
|
|
9316
9278
|
>
|
|
9317
9279
|
>
|
|
9318
|
-
> = internal.prepare
|
|
9280
|
+
> = internal.prepare
|
|
9319
9281
|
|
|
9320
9282
|
/**
|
|
9321
9283
|
* Starts a machine.
|
|
@@ -9352,7 +9314,7 @@ export const prepare: <
|
|
|
9352
9314
|
* events: Machine.eventsFromSchemas()
|
|
9353
9315
|
* }).handle({
|
|
9354
9316
|
* initial: {
|
|
9355
|
-
* target:
|
|
9317
|
+
* target: "Idle"
|
|
9356
9318
|
* },
|
|
9357
9319
|
* states: {
|
|
9358
9320
|
* Idle: {}
|
|
@@ -9429,7 +9391,7 @@ export const start: <
|
|
|
9429
9391
|
Machine.EventOf<Events>,
|
|
9430
9392
|
Machine.EmittedEventOf<Emits>
|
|
9431
9393
|
>
|
|
9432
|
-
> = internal.start
|
|
9394
|
+
> = internal.start
|
|
9433
9395
|
|
|
9434
9396
|
/**
|
|
9435
9397
|
* Starts a fresh managed runtime from a decoded logical snapshot.
|
|
@@ -9468,7 +9430,7 @@ export const start: <
|
|
|
9468
9430
|
* events: Machine.eventsFromSchemas()
|
|
9469
9431
|
* }).handle({
|
|
9470
9432
|
* initial: {
|
|
9471
|
-
* target:
|
|
9433
|
+
* target: "Idle"
|
|
9472
9434
|
* },
|
|
9473
9435
|
* states: {
|
|
9474
9436
|
* Idle: {}
|
|
@@ -9541,4 +9503,4 @@ export const resume: <
|
|
|
9541
9503
|
Machine.EventOf<Events>,
|
|
9542
9504
|
Machine.EmittedEventOf<Emits>
|
|
9543
9505
|
>
|
|
9544
|
-
> = internal.resume
|
|
9506
|
+
> = internal.resume
|