@typeonce/effect-machine 0.9.0 → 0.10.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 +128 -28
- package/dist/Machine.d.ts +334 -238
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +45 -76
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/atom.d.ts +6 -2
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js +5 -0
- 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 -1
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/command.js +2 -2
- package/dist/internal/machine/command.js.map +1 -1
- package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
- package/dist/internal/machine/commandRuntime.js +6 -3
- package/dist/internal/machine/commandRuntime.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts +8 -1
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +9 -4
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/errors.d.ts +1 -1
- package/dist/internal/machine/errors.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts +3 -3
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +50 -25
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +3 -2
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/machine.d.ts +14 -19
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +12 -10
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +2 -1
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +61 -24
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +8 -8
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/protocol.d.ts +7 -13
- package/dist/internal/machine/protocol.d.ts.map +1 -1
- package/dist/internal/machine/protocol.js +128 -50
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/runtime.d.ts +8 -2
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js +86 -8
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/topology.d.ts +7 -0
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +6 -0
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +1 -1
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
- package/dist/internal/testing/machine/runtime.js +2 -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 +5 -3
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +7 -7
- package/dist/testing/MachineTest.js +7 -7
- package/dist/unstable/cluster/ClusterMachine.d.ts +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +25 -8
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +18 -3
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/docs/agent-guide.md +143 -48
- package/package.json +1 -1
- package/src/Machine.ts +559 -307
- package/src/internal/machine/atom.ts +35 -10
- package/src/internal/machine/cluster.ts +2 -1
- package/src/internal/machine/command.ts +2 -2
- package/src/internal/machine/commandRuntime.ts +9 -4
- package/src/internal/machine/configuration.ts +23 -5
- package/src/internal/machine/errors.ts +1 -1
- package/src/internal/machine/executionPlan.ts +74 -29
- package/src/internal/machine/invocation.ts +3 -2
- package/src/internal/machine/machine.ts +68 -49
- package/src/internal/machine/planner.ts +68 -24
- package/src/internal/machine/process.ts +18 -8
- package/src/internal/machine/protocol.ts +207 -68
- package/src/internal/machine/runtime.ts +135 -9
- package/src/internal/machine/topology.ts +15 -0
- package/src/internal/testing/machine/finiteModel.ts +1 -1
- package/src/internal/testing/machine/runtime.ts +2 -1
- package/src/internal/testing/machine/verification.ts +5 -3
- package/src/testing/MachineTest.ts +7 -7
- package/src/unstable/cluster/ClusterMachine.ts +1 -1
- package/src/unstable/reactivity/AtomMachine.ts +42 -10
package/src/Machine.ts
CHANGED
|
@@ -50,6 +50,8 @@ export const TypeId: TypeId = "~effect/Machine"
|
|
|
50
50
|
declare const MachineOutputStatesTypeId: unique symbol
|
|
51
51
|
declare const MachineTypeId: unique symbol
|
|
52
52
|
declare const EventConstructionTypeId: unique symbol
|
|
53
|
+
declare const EmittedEventConstructionTypeId: unique symbol
|
|
54
|
+
declare const EventProtocolTypeId: unique symbol
|
|
53
55
|
|
|
54
56
|
const ChildMachineLogicTypeId: typeof internal.ChildMachineLogicTypeId = internal.ChildMachineLogicTypeId
|
|
55
57
|
|
|
@@ -124,7 +126,8 @@ export interface Machine<
|
|
|
124
126
|
Output = never,
|
|
125
127
|
Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
126
128
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
127
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
|
|
129
|
+
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
|
|
130
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
128
131
|
> extends Pipeable {
|
|
129
132
|
readonly [TypeId]: TypeId
|
|
130
133
|
/** @internal Stable type-level carrier for machine protocol extraction. */
|
|
@@ -141,7 +144,8 @@ export interface Machine<
|
|
|
141
144
|
Output,
|
|
142
145
|
Emits,
|
|
143
146
|
OutputStates,
|
|
144
|
-
InputEvents
|
|
147
|
+
InputEvents,
|
|
148
|
+
ParentEvents
|
|
145
149
|
>
|
|
146
150
|
/** @internal Prevents output implementation evidence from being widened. */
|
|
147
151
|
readonly [MachineOutputStatesTypeId]: Readonly<Record<OutputStates, true>>
|
|
@@ -158,22 +162,37 @@ export interface Machine<
|
|
|
158
162
|
*
|
|
159
163
|
* @since 0.4.0
|
|
160
164
|
*/
|
|
161
|
-
readonly events: InputEvents
|
|
165
|
+
readonly events: Machine.EventProtocol<"public", InputEvents>
|
|
162
166
|
|
|
163
167
|
/**
|
|
164
|
-
* Events reserved for raised events
|
|
165
|
-
* work.
|
|
168
|
+
* Events reserved for raised events and other machine-local work.
|
|
166
169
|
*
|
|
167
170
|
* @since 0.4.0
|
|
168
171
|
*/
|
|
169
|
-
readonly internalEvents:
|
|
172
|
+
readonly internalEvents: Machine.EventProtocol<
|
|
173
|
+
"internal",
|
|
174
|
+
Machine.InternalEventSchemas<Events, InputEvents>
|
|
175
|
+
>
|
|
170
176
|
|
|
171
177
|
/**
|
|
172
|
-
*
|
|
178
|
+
* Ephemeral outward notifications published to this actor's observers.
|
|
179
|
+
* Emissions are never delivered implicitly to an owning actor.
|
|
173
180
|
*
|
|
174
181
|
* @since 0.4.0
|
|
175
182
|
*/
|
|
176
|
-
readonly
|
|
183
|
+
readonly emittedEvents: Machine.EventProtocol<"emitted", Emits>
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Public input events accepted by an owning actor when this machine is
|
|
187
|
+
* running as a child.
|
|
188
|
+
*
|
|
189
|
+
* The protocol types the optional `parent` actor reference exposed to
|
|
190
|
+
* handlers and is checked against a concrete parent's public events at
|
|
191
|
+
* composition boundaries.
|
|
192
|
+
*
|
|
193
|
+
* @since 0.10.0
|
|
194
|
+
*/
|
|
195
|
+
readonly parentEvents: Machine.EventProtocol<"public", ParentEvents>
|
|
177
196
|
|
|
178
197
|
/**
|
|
179
198
|
* Optional schema used to decode the machine input before initialization.
|
|
@@ -223,7 +242,8 @@ export interface Machine<
|
|
|
223
242
|
FinalStates,
|
|
224
243
|
Output,
|
|
225
244
|
OutputStates,
|
|
226
|
-
InputEvents
|
|
245
|
+
InputEvents,
|
|
246
|
+
ParentEvents
|
|
227
247
|
>
|
|
228
248
|
|
|
229
249
|
/** @internal */
|
|
@@ -343,7 +363,8 @@ export type ExecutionServices<Requirements> =
|
|
|
343
363
|
| Exclude<ActionServices<Requirements>, MachineRuntimeRequirement>
|
|
344
364
|
|
|
345
365
|
/**
|
|
346
|
-
* Managed runtime capability used to deliver raised and
|
|
366
|
+
* Managed runtime capability used to deliver raised events and publish
|
|
367
|
+
* emitted notifications.
|
|
347
368
|
*
|
|
348
369
|
* @category models
|
|
349
370
|
* @since 0.4.0
|
|
@@ -357,11 +378,42 @@ export interface Runtime<in Events, in Emits> {
|
|
|
357
378
|
readonly raise: (event: Machine.EventInput<Events>) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>
|
|
358
379
|
|
|
359
380
|
/**
|
|
360
|
-
*
|
|
381
|
+
* Publishes an ephemeral notification to the running actor's observers.
|
|
361
382
|
*
|
|
362
383
|
* @since 0.4.0
|
|
363
384
|
*/
|
|
364
|
-
readonly
|
|
385
|
+
readonly emit: (
|
|
386
|
+
event: Machine.EmittedEventInput<Emits>
|
|
387
|
+
) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Minimal typed reference accepted by targeted actor commands.
|
|
392
|
+
*
|
|
393
|
+
* @category models
|
|
394
|
+
* @since 0.10.0
|
|
395
|
+
*/
|
|
396
|
+
export interface ActorRef<in Event> {
|
|
397
|
+
readonly id: string
|
|
398
|
+
readonly sessionId: string
|
|
399
|
+
readonly send: (event: Event) => Effect.Effect<void, StoppedError>
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Actor references available while evaluating machine behavior.
|
|
404
|
+
*
|
|
405
|
+
* @category models
|
|
406
|
+
* @since 0.10.0
|
|
407
|
+
*/
|
|
408
|
+
export interface ActorContext<
|
|
409
|
+
InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
410
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema>
|
|
411
|
+
> {
|
|
412
|
+
/** Reference to the current actor. Sending queues a later mailbox event. */
|
|
413
|
+
readonly self: ActorRef<Machine.EventInputOf<InputEvents>>
|
|
414
|
+
|
|
415
|
+
/** Reference to the owning actor, or `undefined` when running as a root. */
|
|
416
|
+
readonly parent: ActorRef<Machine.EventInputOf<ParentEvents>> | undefined
|
|
365
417
|
}
|
|
366
418
|
|
|
367
419
|
/**
|
|
@@ -376,11 +428,12 @@ export interface Enqueue<in Events, in Emits> {
|
|
|
376
428
|
/** Raises an event inside the current macrostep. */
|
|
377
429
|
readonly raise: (event: Machine.EventInput<Events>) => void
|
|
378
430
|
|
|
379
|
-
/**
|
|
380
|
-
readonly emit: (event: Emits) => void
|
|
431
|
+
/** Publishes an ephemeral notification to this actor's observers. */
|
|
432
|
+
readonly emit: (event: Machine.EmittedEventInput<Emits>) => void
|
|
381
433
|
|
|
382
434
|
/** Sends an event to an invoked child after the transition is selected. */
|
|
383
435
|
readonly sendTo: {
|
|
436
|
+
<Event>(target: ActorRef<Event>, event: Event): void
|
|
384
437
|
<Child extends ChildMachine.Any>(child: Child, event: ChildMachine.Event<Child>): void
|
|
385
438
|
<Address extends ChildAddress<never>>(child: Address, event: ChildAddress.Event<Address>): void
|
|
386
439
|
}
|
|
@@ -401,7 +454,7 @@ export interface Enqueue<in Events, in Emits> {
|
|
|
401
454
|
export type Command =
|
|
402
455
|
| {
|
|
403
456
|
readonly _tag: "SendTo"
|
|
404
|
-
readonly
|
|
457
|
+
readonly target: ActorRef<unknown> | ChildMachine.Any | ChildAddress<never>
|
|
405
458
|
readonly event: unknown
|
|
406
459
|
}
|
|
407
460
|
| {
|
|
@@ -676,8 +729,9 @@ type DuplicateEventTag<
|
|
|
676
729
|
: Events extends readonly [
|
|
677
730
|
infer Head extends Machine.TaggedSchema,
|
|
678
731
|
...infer Tail extends ReadonlyArray<Machine.TaggedSchema>
|
|
679
|
-
] ? Machine.TagOf<Head> extends infer Tag extends PropertyKey ?
|
|
680
|
-
|
|
732
|
+
] ? Machine.TagOf<Head> extends infer Tag extends PropertyKey ?
|
|
733
|
+
| Extract<Tag, Seen>
|
|
734
|
+
| DuplicateEventTag<Tail, Seen | Tag>
|
|
681
735
|
: never
|
|
682
736
|
: never
|
|
683
737
|
|
|
@@ -687,6 +741,12 @@ type ValidateInputEventProtocol<
|
|
|
687
741
|
> = [DuplicateInput] extends [never] ? unknown
|
|
688
742
|
: EventProtocolError<"Public event tags must be unique", DuplicateInput>
|
|
689
743
|
|
|
744
|
+
type ValidateEmittedEventProtocol<
|
|
745
|
+
EmittedEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
746
|
+
DuplicateEmitted extends PropertyKey = DuplicateEventTag<EmittedEvents>
|
|
747
|
+
> = [DuplicateEmitted] extends [never] ? unknown
|
|
748
|
+
: EventProtocolError<"Emitted event tags must be unique", DuplicateEmitted>
|
|
749
|
+
|
|
690
750
|
type ValidateInternalEventProtocol<
|
|
691
751
|
InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
692
752
|
InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
@@ -699,6 +759,14 @@ type ValidateInternalEventProtocol<
|
|
|
699
759
|
: EventProtocolError<"Public and internal event tags must be disjoint", Overlap>
|
|
700
760
|
: EventProtocolError<"Internal event tags must be unique", DuplicateInternal>
|
|
701
761
|
|
|
762
|
+
type ValidateEventProtocolBuilder<
|
|
763
|
+
Kind extends Machine.EventProtocolKind,
|
|
764
|
+
Inputs extends ReadonlyArray<Machine.EventProtocolInput<Kind>>,
|
|
765
|
+
Schemas extends ReadonlyArray<Machine.TaggedSchema> = Machine.EventProtocolInputSchemasOf<Kind, Inputs>,
|
|
766
|
+
Duplicate extends PropertyKey = DuplicateEventTag<Schemas>
|
|
767
|
+
> = [Duplicate] extends [never] ? unknown
|
|
768
|
+
: EventProtocolError<"Event protocol tags must be unique", Duplicate>
|
|
769
|
+
|
|
702
770
|
const SnapshotBuilderStateTypeId: typeof internal.SnapshotBuilderStateTypeId = internal.SnapshotBuilderStateTypeId
|
|
703
771
|
const SnapshotBuilderConstructionTypeId: unique symbol = Symbol("effect/Machine/SnapshotBuilderConstruction")
|
|
704
772
|
|
|
@@ -1640,7 +1708,9 @@ export type RuntimeOutcome<State, Error = never, Output = never> =
|
|
|
1640
1708
|
* @category models
|
|
1641
1709
|
* @since 0.4.0
|
|
1642
1710
|
*/
|
|
1643
|
-
export interface MachineRef<out State, in Event, out Error = never, out Output = never>
|
|
1711
|
+
export interface MachineRef<out State, in Event, out Error = never, out Output = never, out Emitted = never>
|
|
1712
|
+
extends ActorRef<Event>
|
|
1713
|
+
{
|
|
1644
1714
|
/** Stable machine definition id, or a generated fallback when none was declared. */
|
|
1645
1715
|
readonly id: string
|
|
1646
1716
|
|
|
@@ -1653,9 +1723,15 @@ export interface MachineRef<out State, in Event, out Error = never, out Output =
|
|
|
1653
1723
|
/** Reads the latest lifecycle snapshot. */
|
|
1654
1724
|
readonly snapshot: Effect.Effect<RuntimeSnapshot<State, Error, Output>>
|
|
1655
1725
|
|
|
1656
|
-
/** Streams lifecycle
|
|
1726
|
+
/** Streams the current lifecycle snapshot followed by later changes. */
|
|
1657
1727
|
readonly changes: Stream.Stream<RuntimeSnapshot<State, Error, Output>>
|
|
1658
1728
|
|
|
1729
|
+
/**
|
|
1730
|
+
* Streams ephemeral notifications published after subscription. Emissions
|
|
1731
|
+
* are not retained or replayed; the stream completes when the actor stops.
|
|
1732
|
+
*/
|
|
1733
|
+
readonly emissions: Stream.Stream<Emitted>
|
|
1734
|
+
|
|
1659
1735
|
/** Waits for machine output or fails when execution fails or is stopped. */
|
|
1660
1736
|
readonly join: Effect.Effect<Output, Error | StoppedError>
|
|
1661
1737
|
|
|
@@ -1767,13 +1843,6 @@ export declare namespace Logic {
|
|
|
1767
1843
|
/**
|
|
1768
1844
|
* Machine-local capabilities available while process logic initializes.
|
|
1769
1845
|
*
|
|
1770
|
-
* **Gotchas**
|
|
1771
|
-
*
|
|
1772
|
-
* `sendParent` accepts `unknown` because process logic is independent from
|
|
1773
|
-
* the parent that eventually owns it. Prefer typed process output or an
|
|
1774
|
-
* invocation lifecycle transition when either can represent the
|
|
1775
|
-
* communication.
|
|
1776
|
-
*
|
|
1777
1846
|
* @category models
|
|
1778
1847
|
* @since 0.4.0
|
|
1779
1848
|
*/
|
|
@@ -1787,14 +1856,14 @@ export declare namespace Logic {
|
|
|
1787
1856
|
/** Starts a child process owned by this scope. */
|
|
1788
1857
|
readonly spawn: Spawn
|
|
1789
1858
|
|
|
1790
|
-
/** Sends an
|
|
1791
|
-
readonly
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1859
|
+
/** Sends an event to an actor reference or typed parent-local child address. */
|
|
1860
|
+
readonly sendTo: {
|
|
1861
|
+
<TargetEvent>(target: ActorRef<TargetEvent>, event: TargetEvent): Effect.Effect<void, StoppedError>
|
|
1862
|
+
<Address extends ChildAddress<never>>(
|
|
1863
|
+
id: Address,
|
|
1864
|
+
event: ChildAddress.Event<Address>
|
|
1865
|
+
): Effect.Effect<void, StoppedError>
|
|
1866
|
+
}
|
|
1798
1867
|
|
|
1799
1868
|
/** Stops a child process selected by its parent-local address. */
|
|
1800
1869
|
readonly stopChild: <Event>(id: ChildAddress<Event>) => Effect.Effect<void>
|
|
@@ -1883,7 +1952,8 @@ export declare namespace ChildMachine {
|
|
|
1883
1952
|
| InfiniteTransitionError
|
|
1884
1953
|
| MachineSchemaDecodeError
|
|
1885
1954
|
| StoppedError,
|
|
1886
|
-
Machine.Output<M
|
|
1955
|
+
Machine.Output<M>,
|
|
1956
|
+
Machine.EmittedEvent<M>
|
|
1887
1957
|
>
|
|
1888
1958
|
: never
|
|
1889
1959
|
|
|
@@ -1893,7 +1963,8 @@ export declare namespace ChildMachine {
|
|
|
1893
1963
|
* @category utility types
|
|
1894
1964
|
* @since 0.4.0
|
|
1895
1965
|
*/
|
|
1896
|
-
export type Event<Child> =
|
|
1966
|
+
export type Event<Child> = Child extends ChildMachine<string, infer M> ? Machine.EventInput<Machine.InputEvent<M>>
|
|
1967
|
+
: never
|
|
1897
1968
|
}
|
|
1898
1969
|
|
|
1899
1970
|
/**
|
|
@@ -2006,7 +2077,8 @@ export declare namespace Machine {
|
|
|
2006
2077
|
Output,
|
|
2007
2078
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
2008
2079
|
OutputStates extends StateIdentifier<States>,
|
|
2009
|
-
InputEvents extends ReadonlyArray<TaggedSchema
|
|
2080
|
+
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
2081
|
+
ParentEvents extends ReadonlyArray<TaggedSchema>
|
|
2010
2082
|
> {
|
|
2011
2083
|
readonly states: States
|
|
2012
2084
|
readonly events: Events
|
|
@@ -2018,9 +2090,10 @@ export declare namespace Machine {
|
|
|
2018
2090
|
readonly initialServices: InitialR
|
|
2019
2091
|
readonly finalStates: FinalStates
|
|
2020
2092
|
readonly output: Output
|
|
2021
|
-
readonly
|
|
2093
|
+
readonly emittedEvents: Emits
|
|
2022
2094
|
readonly outputStates: OutputStates
|
|
2023
2095
|
readonly inputEvents: InputEvents
|
|
2096
|
+
readonly parentEvents: ParentEvents
|
|
2024
2097
|
}
|
|
2025
2098
|
|
|
2026
2099
|
/**
|
|
@@ -2038,11 +2111,12 @@ export declare namespace Machine {
|
|
|
2038
2111
|
export interface Any extends Pipeable {
|
|
2039
2112
|
readonly [TypeId]: TypeId
|
|
2040
2113
|
/** @internal */
|
|
2041
|
-
readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any, any>
|
|
2114
|
+
readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any, any, any>
|
|
2042
2115
|
readonly states: StateSchemas
|
|
2043
|
-
readonly events:
|
|
2044
|
-
readonly internalEvents:
|
|
2045
|
-
readonly
|
|
2116
|
+
readonly events: EventProtocol.Any<"public">
|
|
2117
|
+
readonly internalEvents: EventProtocol.Any<"internal">
|
|
2118
|
+
readonly emittedEvents: EventProtocol.Any<"emitted">
|
|
2119
|
+
readonly parentEvents: EventProtocol.Any<"public">
|
|
2046
2120
|
readonly input: Schema.Top | undefined
|
|
2047
2121
|
readonly id: string | undefined
|
|
2048
2122
|
/** @internal */
|
|
@@ -2143,7 +2217,10 @@ export declare namespace Machine {
|
|
|
2143
2217
|
* @category utility types
|
|
2144
2218
|
* @since 0.4.0
|
|
2145
2219
|
*/
|
|
2146
|
-
export type
|
|
2220
|
+
export type EmittedEvents<M extends Any> = M[typeof MachineTypeId]["emittedEvents"]
|
|
2221
|
+
|
|
2222
|
+
/** @deprecated Use {@link EmittedEvents}. */
|
|
2223
|
+
export type Emits<M extends Any> = EmittedEvents<M>
|
|
2147
2224
|
|
|
2148
2225
|
/**
|
|
2149
2226
|
* Extracts state paths with implemented output handlers.
|
|
@@ -2161,13 +2238,22 @@ export declare namespace Machine {
|
|
|
2161
2238
|
*/
|
|
2162
2239
|
export type InputEvents<M extends Any> = M[typeof MachineTypeId]["inputEvents"]
|
|
2163
2240
|
|
|
2164
|
-
/** Extracts the
|
|
2165
|
-
export type
|
|
2166
|
-
|
|
2241
|
+
/** Extracts the public input protocol required from an owning actor. */
|
|
2242
|
+
export type ParentEvents<M extends Any> = M[typeof MachineTypeId]["parentEvents"]
|
|
2243
|
+
|
|
2244
|
+
/** Extracts an internal event schema tuple from the complete and public protocols. */
|
|
2245
|
+
export type InternalEventSchemas<
|
|
2246
|
+
Events extends ReadonlyArray<TaggedSchema>,
|
|
2247
|
+
InputEvents extends ReadonlyArray<TaggedSchema>
|
|
2248
|
+
> = Events extends readonly [
|
|
2249
|
+
...InputEvents,
|
|
2167
2250
|
...infer Internal extends ReadonlyArray<TaggedSchema>
|
|
2168
|
-
] ? Internal
|
|
2251
|
+
] ? readonly [...Internal]
|
|
2169
2252
|
: readonly []
|
|
2170
2253
|
|
|
2254
|
+
/** Extracts the internal event schema tuple carried by a machine definition. */
|
|
2255
|
+
export type InternalEvents<M extends Any> = InternalEventSchemas<Events<M>, InputEvents<M>>
|
|
2256
|
+
|
|
2171
2257
|
/**
|
|
2172
2258
|
* Extracts the complete event protocol handled inside a machine.
|
|
2173
2259
|
*
|
|
@@ -2196,48 +2282,133 @@ export declare namespace Machine {
|
|
|
2196
2282
|
readonly _tag: Event["_tag"]
|
|
2197
2283
|
}
|
|
2198
2284
|
|
|
2285
|
+
/** Opaque construction returned by {@link emittedEvents}. */
|
|
2286
|
+
export interface EmittedEventConstruction<out Event extends { readonly _tag: PropertyKey }> {
|
|
2287
|
+
readonly [EmittedEventConstructionTypeId]: Event
|
|
2288
|
+
readonly _tag: Event["_tag"]
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2199
2291
|
/** A decoded event or a deferred machine-bound construction of that event. */
|
|
2200
2292
|
export type EventInput<Event> =
|
|
2201
2293
|
| Event
|
|
2202
2294
|
| (Event extends { readonly _tag: PropertyKey } ? EventConstruction<Event> : never)
|
|
2203
2295
|
|
|
2296
|
+
/** A decoded emitted event or a deferred emitted-event construction. */
|
|
2297
|
+
export type EmittedEventInput<Event> =
|
|
2298
|
+
| Event
|
|
2299
|
+
| (Event extends { readonly _tag: PropertyKey } ? EmittedEventConstruction<Event> : never)
|
|
2300
|
+
|
|
2204
2301
|
/** Event inputs accepted for a schema tuple at machine delivery boundaries. */
|
|
2205
2302
|
export type EventInputOf<Events extends ReadonlyArray<TaggedSchema>> = EventInput<EventOf<Events>>
|
|
2206
2303
|
|
|
2304
|
+
/** Identifies whether an event protocol is accepted publicly or only inside a machine. */
|
|
2305
|
+
export type EventProtocolKind = "public" | "internal" | "emitted"
|
|
2306
|
+
|
|
2207
2307
|
type EventConstructorInput<EventSchema extends TaggedSchema> = Omit<EventSchema["~type.make.in"], "_tag">
|
|
2208
2308
|
|
|
2209
2309
|
type EventConstructor<
|
|
2210
2310
|
EventSchema extends TaggedSchema,
|
|
2211
|
-
Tag extends EventSchema["Type"]["_tag"]
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2311
|
+
Tag extends EventSchema["Type"]["_tag"],
|
|
2312
|
+
Kind extends EventProtocolKind
|
|
2313
|
+
> = {} extends EventConstructorInput<EventSchema> ? (
|
|
2314
|
+
input?: EventConstructorInput<EventSchema>
|
|
2315
|
+
) => Kind extends "emitted" ? EmittedEventConstruction<EventByTag<readonly [EventSchema], Tag>>
|
|
2316
|
+
: EventConstruction<EventByTag<readonly [EventSchema], Tag>>
|
|
2317
|
+
: (
|
|
2318
|
+
input: EventConstructorInput<EventSchema>
|
|
2319
|
+
) => Kind extends "emitted" ? EmittedEventConstruction<EventByTag<readonly [EventSchema], Tag>>
|
|
2320
|
+
: EventConstruction<EventByTag<readonly [EventSchema], Tag>>
|
|
2321
|
+
|
|
2322
|
+
type FiniteEventTag<Tag extends PropertyKey> = string extends Tag ? never
|
|
2323
|
+
: number extends Tag ? never
|
|
2324
|
+
: symbol extends Tag ? never
|
|
2325
|
+
: Tag
|
|
2326
|
+
|
|
2327
|
+
type EventConstructorsForSchema<
|
|
2328
|
+
EventSchema extends TaggedSchema,
|
|
2329
|
+
Kind extends EventProtocolKind
|
|
2330
|
+
> = EventSchema extends {
|
|
2217
2331
|
readonly cases: infer Cases extends Readonly<Record<PropertyKey, TaggedSchema>>
|
|
2218
2332
|
} ? {
|
|
2219
|
-
readonly [Tag in keyof Cases]: Tag extends Cases[Tag]["Type"]["_tag"] ? EventConstructor<Cases[Tag], Tag>
|
|
2333
|
+
readonly [Tag in keyof Cases]: Tag extends Cases[Tag]["Type"]["_tag"] ? EventConstructor<Cases[Tag], Tag, Kind>
|
|
2220
2334
|
: never
|
|
2221
2335
|
}
|
|
2222
2336
|
: EventSchema extends { readonly members: infer Members extends ReadonlyArray<TaggedSchema> } ?
|
|
2223
|
-
Types.UnionToIntersection<EventConstructorsForSchema<Members[number]>>
|
|
2337
|
+
Types.UnionToIntersection<EventConstructorsForSchema<Members[number], Kind>>
|
|
2224
2338
|
: {
|
|
2225
|
-
readonly [Tag in EventSchema["Type"]["_tag"]]: EventConstructor<EventSchema, Tag>
|
|
2339
|
+
readonly [Tag in FiniteEventTag<EventSchema["Type"]["_tag"]>]: EventConstructor<EventSchema, Tag, Kind>
|
|
2226
2340
|
}
|
|
2227
2341
|
|
|
2228
2342
|
/** Protocol-bound constructors keyed by each configured event tag. */
|
|
2229
|
-
export type EventConstructors<
|
|
2230
|
-
|
|
2231
|
-
|
|
2343
|
+
export type EventConstructors<
|
|
2344
|
+
Events extends ReadonlyArray<TaggedSchema>,
|
|
2345
|
+
Kind extends EventProtocolKind = "public"
|
|
2346
|
+
> = {
|
|
2347
|
+
readonly [Tag in keyof Types.UnionToIntersection<EventConstructorsForSchema<Events[number], Kind>>]:
|
|
2348
|
+
Types.UnionToIntersection<EventConstructorsForSchema<Events[number], Kind>>[Tag]
|
|
2232
2349
|
}
|
|
2233
2350
|
|
|
2351
|
+
/**
|
|
2352
|
+
* A schema-backed event protocol exposing only deferred event constructors.
|
|
2353
|
+
*
|
|
2354
|
+
* The schema tuple is retained opaquely for machine runtime validation and
|
|
2355
|
+
* type inference. It is not exposed as a runtime property.
|
|
2356
|
+
*
|
|
2357
|
+
* @since 0.10.0
|
|
2358
|
+
*/
|
|
2359
|
+
export type EventProtocol<
|
|
2360
|
+
Kind extends EventProtocolKind,
|
|
2361
|
+
Schemas extends ReadonlyArray<TaggedSchema>
|
|
2362
|
+
> = EventConstructors<Schemas, Kind> & {
|
|
2363
|
+
readonly [EventProtocolTypeId]: {
|
|
2364
|
+
readonly kind: Kind
|
|
2365
|
+
readonly schemas: Schemas
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
export namespace EventProtocol {
|
|
2370
|
+
/** An erased event protocol descriptor retaining its kind and schema carrier. */
|
|
2371
|
+
export interface Any<Kind extends EventProtocolKind = EventProtocolKind> {
|
|
2372
|
+
readonly [EventProtocolTypeId]: {
|
|
2373
|
+
readonly kind: Kind
|
|
2374
|
+
readonly schemas: ReadonlyArray<TaggedSchema>
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
/** A schema or an existing protocol accepted by an event builder. */
|
|
2380
|
+
export type EventProtocolInput<Kind extends EventProtocolKind> = TaggedSchema | EventProtocol.Any<Kind>
|
|
2381
|
+
|
|
2382
|
+
type EventProtocolInputSchemas<
|
|
2383
|
+
Kind extends EventProtocolKind,
|
|
2384
|
+
Input extends EventProtocolInput<Kind>
|
|
2385
|
+
> = Input extends EventProtocol<Kind, infer Schemas> ? Schemas
|
|
2386
|
+
: Input extends TaggedSchema ? readonly [Input]
|
|
2387
|
+
: readonly []
|
|
2388
|
+
|
|
2389
|
+
/** Flattens schema and protocol inputs into one owned schema tuple. */
|
|
2390
|
+
export type EventProtocolInputSchemasOf<
|
|
2391
|
+
Kind extends EventProtocolKind,
|
|
2392
|
+
Inputs extends ReadonlyArray<EventProtocolInput<Kind>>
|
|
2393
|
+
> = Inputs extends readonly [
|
|
2394
|
+
infer Head extends EventProtocolInput<Kind>,
|
|
2395
|
+
...infer Tail extends ReadonlyArray<EventProtocolInput<Kind>>
|
|
2396
|
+
] ? readonly [...EventProtocolInputSchemas<Kind, Head>, ...EventProtocolInputSchemasOf<Kind, Tail>]
|
|
2397
|
+
: readonly []
|
|
2398
|
+
|
|
2399
|
+
/** @internal Extracts the schema tuple carried opaquely by an event protocol. */
|
|
2400
|
+
export type EventProtocolSchemas<Protocol extends EventProtocol.Any> = Protocol[typeof EventProtocolTypeId]["schemas"]
|
|
2401
|
+
|
|
2234
2402
|
/**
|
|
2235
2403
|
* Extracts the event protocol emitted by a machine.
|
|
2236
2404
|
*
|
|
2237
2405
|
* @category utility types
|
|
2238
2406
|
* @since 0.4.0
|
|
2239
2407
|
*/
|
|
2240
|
-
export type
|
|
2408
|
+
export type EmittedEvent<M extends Any> = EmittedEventOf<Emits<M>>
|
|
2409
|
+
|
|
2410
|
+
/** @deprecated Use {@link EmittedEvent}. */
|
|
2411
|
+
export type Emit<M extends Any> = EmittedEvent<M>
|
|
2241
2412
|
|
|
2242
2413
|
/**
|
|
2243
2414
|
* A schema whose decoded value contains a `_tag` discriminator.
|
|
@@ -3025,7 +3196,10 @@ export declare namespace Machine {
|
|
|
3025
3196
|
* @category utility types
|
|
3026
3197
|
* @since 0.4.0
|
|
3027
3198
|
*/
|
|
3028
|
-
export type
|
|
3199
|
+
export type EmittedEventOf<Emits extends ReadonlyArray<TaggedSchema>> = Emits[number]["Type"]
|
|
3200
|
+
|
|
3201
|
+
/** @deprecated Use {@link EmittedEventOf}. */
|
|
3202
|
+
export type EmitOf<Emits extends ReadonlyArray<TaggedSchema>> = EmittedEventOf<Emits>
|
|
3029
3203
|
|
|
3030
3204
|
/**
|
|
3031
3205
|
* Event values received by lifecycle callbacks.
|
|
@@ -3597,6 +3771,21 @@ export declare namespace Machine {
|
|
|
3597
3771
|
>
|
|
3598
3772
|
}
|
|
3599
3773
|
|
|
3774
|
+
/**
|
|
3775
|
+
* Opaque result returned by an explicitly targetless transition.
|
|
3776
|
+
*
|
|
3777
|
+
* The transition remains handled and retains its queued commands, raised
|
|
3778
|
+
* events, and emitted events, but selects no concrete destination. Declared
|
|
3779
|
+
* `targets` constrain only concrete destinations, so this result is always
|
|
3780
|
+
* permitted from ordinary transition handlers.
|
|
3781
|
+
*
|
|
3782
|
+
* @category models
|
|
3783
|
+
* @since 0.10.0
|
|
3784
|
+
*/
|
|
3785
|
+
export interface NoTarget {
|
|
3786
|
+
readonly [Topology.NoTargetTypeId]: typeof Topology.NoTargetTypeId
|
|
3787
|
+
}
|
|
3788
|
+
|
|
3600
3789
|
/**
|
|
3601
3790
|
* Transition instruction that restores a history pseudo-state's parent.
|
|
3602
3791
|
*
|
|
@@ -3703,9 +3892,9 @@ export declare namespace Machine {
|
|
|
3703
3892
|
*
|
|
3704
3893
|
* **Details**
|
|
3705
3894
|
*
|
|
3706
|
-
* `
|
|
3707
|
-
*
|
|
3708
|
-
* snapshots for any root.
|
|
3895
|
+
* `none()` handles without selecting a destination, `local` targets the
|
|
3896
|
+
* nearest compound scope for the source state, `branch` targets descendants
|
|
3897
|
+
* of the source root, and `full` builds complete snapshots for any root.
|
|
3709
3898
|
*
|
|
3710
3899
|
* These builders control how the next active configuration is assembled; they
|
|
3711
3900
|
* do not directly control state re-entry. Exit and entry paths are derived
|
|
@@ -3721,6 +3910,18 @@ export declare namespace Machine {
|
|
|
3721
3910
|
States extends StateSchemas,
|
|
3722
3911
|
Source extends StateNodeIdentifier<States>
|
|
3723
3912
|
> {
|
|
3913
|
+
/**
|
|
3914
|
+
* Selects an explicitly targetless transition.
|
|
3915
|
+
*
|
|
3916
|
+
* The event or lifecycle outcome is handled and queued operations are
|
|
3917
|
+
* retained, while the current state configuration remains the transition
|
|
3918
|
+
* result. This remains valid when the handler declares concrete `targets`,
|
|
3919
|
+
* because those paths are an upper bound rather than an exhaustive result.
|
|
3920
|
+
*
|
|
3921
|
+
* @since 0.10.0
|
|
3922
|
+
*/
|
|
3923
|
+
readonly none: () => NoTarget
|
|
3924
|
+
|
|
3724
3925
|
/**
|
|
3725
3926
|
* Moves to another state in the same local group. The value of the state
|
|
3726
3927
|
* containing that group, and values in other active branches, are kept.
|
|
@@ -3769,11 +3970,13 @@ export declare namespace Machine {
|
|
|
3769
3970
|
StateId extends StateIdentifier<States>,
|
|
3770
3971
|
EventTag extends TagOf<Events[number]>,
|
|
3771
3972
|
E,
|
|
3772
|
-
R
|
|
3773
|
-
|
|
3973
|
+
R,
|
|
3974
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
3975
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
3976
|
+
> extends ActorContext<InputEvents, ParentEvents> {
|
|
3774
3977
|
readonly state: StateByIdentifier<States, StateId>
|
|
3775
|
-
readonly
|
|
3776
|
-
readonly
|
|
3978
|
+
readonly containingState: ParentStateValue<States, StateId>
|
|
3979
|
+
readonly ancestors: ParentStateValues<States, StateId>
|
|
3777
3980
|
/** Complete logical configuration captured at the start of this microstep. */
|
|
3778
3981
|
readonly snapshot: Snapshot<States>
|
|
3779
3982
|
readonly event: EventByTag<Events, EventTag>
|
|
@@ -3797,11 +4000,13 @@ export declare namespace Machine {
|
|
|
3797
4000
|
States extends StateSchemas,
|
|
3798
4001
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
3799
4002
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
3800
|
-
StateId extends StateIdentifier<States
|
|
3801
|
-
|
|
4003
|
+
StateId extends StateIdentifier<States>,
|
|
4004
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
4005
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4006
|
+
> extends ActorContext<InputEvents, ParentEvents> {
|
|
3802
4007
|
readonly state: StateByIdentifier<States, StateId>
|
|
3803
|
-
readonly
|
|
3804
|
-
readonly
|
|
4008
|
+
readonly containingState: ParentStateValue<States, StateId>
|
|
4009
|
+
readonly ancestors: ParentStateValues<States, StateId>
|
|
3805
4010
|
readonly event: LifecycleEvent<Events>
|
|
3806
4011
|
}
|
|
3807
4012
|
|
|
@@ -3815,11 +4020,13 @@ export declare namespace Machine {
|
|
|
3815
4020
|
States extends StateSchemas,
|
|
3816
4021
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
3817
4022
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
3818
|
-
StateId extends StateIdentifier<States
|
|
3819
|
-
|
|
4023
|
+
StateId extends StateIdentifier<States>,
|
|
4024
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
4025
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4026
|
+
> extends ActorContext<InputEvents, ParentEvents> {
|
|
3820
4027
|
readonly state: StateByIdentifier<States, StateId>
|
|
3821
|
-
readonly
|
|
3822
|
-
readonly
|
|
4028
|
+
readonly containingState: ParentStateValue<States, StateId>
|
|
4029
|
+
readonly ancestors: ParentStateValues<States, StateId>
|
|
3823
4030
|
readonly event: LifecycleEvent<Events>
|
|
3824
4031
|
}
|
|
3825
4032
|
|
|
@@ -3836,12 +4043,14 @@ export declare namespace Machine {
|
|
|
3836
4043
|
StateId extends StateIdentifier<States>,
|
|
3837
4044
|
State,
|
|
3838
4045
|
Error,
|
|
3839
|
-
Output
|
|
3840
|
-
|
|
4046
|
+
Output,
|
|
4047
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
4048
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4049
|
+
> extends ActorContext<InputEvents, ParentEvents> {
|
|
3841
4050
|
readonly id: string
|
|
3842
4051
|
readonly state: StateByIdentifier<States, StateId>
|
|
3843
|
-
readonly
|
|
3844
|
-
readonly
|
|
4052
|
+
readonly containingState: ParentStateValue<States, StateId>
|
|
4053
|
+
readonly ancestors: ParentStateValues<States, StateId>
|
|
3845
4054
|
readonly target: TargetBuilder<States, StateId>
|
|
3846
4055
|
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "active" }>
|
|
3847
4056
|
}
|
|
@@ -3857,12 +4066,14 @@ export declare namespace Machine {
|
|
|
3857
4066
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
3858
4067
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
3859
4068
|
StateId extends StateIdentifier<States>,
|
|
3860
|
-
Output
|
|
3861
|
-
|
|
4069
|
+
Output,
|
|
4070
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
4071
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4072
|
+
> extends ActorContext<InputEvents, ParentEvents> {
|
|
3862
4073
|
readonly id: string
|
|
3863
4074
|
readonly state: StateByIdentifier<States, StateId>
|
|
3864
|
-
readonly
|
|
3865
|
-
readonly
|
|
4075
|
+
readonly containingState: ParentStateValue<States, StateId>
|
|
4076
|
+
readonly ancestors: ParentStateValues<States, StateId>
|
|
3866
4077
|
readonly snapshot: Snapshot<States>
|
|
3867
4078
|
readonly target: TargetBuilder<States, StateId>
|
|
3868
4079
|
readonly output: Output
|
|
@@ -3874,12 +4085,14 @@ export declare namespace Machine {
|
|
|
3874
4085
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
3875
4086
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
3876
4087
|
StateId extends StateIdentifier<States>,
|
|
3877
|
-
Error
|
|
3878
|
-
|
|
4088
|
+
Error,
|
|
4089
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
4090
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4091
|
+
> extends ActorContext<InputEvents, ParentEvents> {
|
|
3879
4092
|
readonly id: string
|
|
3880
4093
|
readonly state: StateByIdentifier<States, StateId>
|
|
3881
|
-
readonly
|
|
3882
|
-
readonly
|
|
4094
|
+
readonly containingState: ParentStateValue<States, StateId>
|
|
4095
|
+
readonly ancestors: ParentStateValues<States, StateId>
|
|
3883
4096
|
readonly snapshot: Snapshot<States>
|
|
3884
4097
|
readonly target: TargetBuilder<States, StateId>
|
|
3885
4098
|
readonly error: Error
|
|
@@ -3895,11 +4108,13 @@ export declare namespace Machine {
|
|
|
3895
4108
|
States extends StateSchemas,
|
|
3896
4109
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
3897
4110
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
3898
|
-
StateId extends StateIdentifier<States
|
|
3899
|
-
|
|
4111
|
+
StateId extends StateIdentifier<States>,
|
|
4112
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
4113
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4114
|
+
> extends ActorContext<InputEvents, ParentEvents> {
|
|
3900
4115
|
readonly state: StateByIdentifier<States, StateId>
|
|
3901
|
-
readonly
|
|
3902
|
-
readonly
|
|
4116
|
+
readonly containingState: ParentStateValue<States, StateId>
|
|
4117
|
+
readonly ancestors: ParentStateValues<States, StateId>
|
|
3903
4118
|
/** Complete logical configuration captured at the start of this microstep. */
|
|
3904
4119
|
readonly snapshot: Snapshot<States>
|
|
3905
4120
|
readonly event: LifecycleEvent<Events>
|
|
@@ -3924,11 +4139,13 @@ export declare namespace Machine {
|
|
|
3924
4139
|
States extends StateSchemas,
|
|
3925
4140
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
3926
4141
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
3927
|
-
StateId extends StateIdentifier<States
|
|
3928
|
-
|
|
4142
|
+
StateId extends StateIdentifier<States>,
|
|
4143
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
4144
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4145
|
+
> extends ActorContext<InputEvents, ParentEvents> {
|
|
3929
4146
|
readonly state: StateByIdentifier<States, StateId>
|
|
3930
|
-
readonly
|
|
3931
|
-
readonly
|
|
4147
|
+
readonly containingState: ParentStateValue<States, StateId>
|
|
4148
|
+
readonly ancestors: ParentStateValues<States, StateId>
|
|
3932
4149
|
/** Complete logical configuration captured at the start of this microstep. */
|
|
3933
4150
|
readonly snapshot: Snapshot<States>
|
|
3934
4151
|
readonly event: LifecycleEvent<Events>
|
|
@@ -3949,13 +4166,15 @@ export declare namespace Machine {
|
|
|
3949
4166
|
States extends StateSchemas,
|
|
3950
4167
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
3951
4168
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
3952
|
-
ChoiceId extends ChoiceIdentifier<States
|
|
3953
|
-
|
|
3954
|
-
|
|
4169
|
+
ChoiceId extends ChoiceIdentifier<States>,
|
|
4170
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
4171
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4172
|
+
> extends ActorContext<InputEvents, ParentEvents> {
|
|
4173
|
+
readonly containingState: StateByIdentifier<
|
|
3955
4174
|
States,
|
|
3956
4175
|
Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>
|
|
3957
4176
|
>
|
|
3958
|
-
readonly
|
|
4177
|
+
readonly ancestors: {
|
|
3959
4178
|
readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, ValuedStateIdentifier<States>>]: StateByIdentifier<
|
|
3960
4179
|
States,
|
|
3961
4180
|
Parent
|
|
@@ -3977,8 +4196,8 @@ export declare namespace Machine {
|
|
|
3977
4196
|
StateId extends StateIdentifier<States>
|
|
3978
4197
|
> {
|
|
3979
4198
|
readonly state: StateByIdentifier<States, StateId>
|
|
3980
|
-
readonly
|
|
3981
|
-
readonly
|
|
4199
|
+
readonly containingState: ParentStateValue<States, StateId>
|
|
4200
|
+
readonly ancestors: ParentStateValues<States, StateId>
|
|
3982
4201
|
readonly event: LifecycleEvent<Events>
|
|
3983
4202
|
}
|
|
3984
4203
|
|
|
@@ -4012,8 +4231,8 @@ export declare namespace Machine {
|
|
|
4012
4231
|
StateId extends StateIdentifier<States>
|
|
4013
4232
|
> {
|
|
4014
4233
|
readonly state: StateByIdentifier<States, StateId>
|
|
4015
|
-
readonly
|
|
4016
|
-
readonly
|
|
4234
|
+
readonly containingState: ParentStateValue<States, StateId>
|
|
4235
|
+
readonly ancestors: ParentStateValues<States, StateId>
|
|
4017
4236
|
readonly event: LifecycleEvent<Events>
|
|
4018
4237
|
readonly outputs: ParallelOutputRegions<States, StateId>
|
|
4019
4238
|
}
|
|
@@ -4047,9 +4266,10 @@ export declare namespace Machine {
|
|
|
4047
4266
|
*
|
|
4048
4267
|
* **Details**
|
|
4049
4268
|
*
|
|
4050
|
-
* Handlers return snapshots for complete state replacement
|
|
4051
|
-
* results for path-safe partial transitions
|
|
4052
|
-
*
|
|
4269
|
+
* Handlers return snapshots for complete state replacement, target builder
|
|
4270
|
+
* results for path-safe partial transitions, or `target.none()` for an
|
|
4271
|
+
* explicitly targetless transition. Raw decoded state values and `void` are
|
|
4272
|
+
* not accepted at transition boundaries.
|
|
4053
4273
|
*
|
|
4054
4274
|
* @category utility types
|
|
4055
4275
|
* @since 0.4.0
|
|
@@ -4065,7 +4285,7 @@ export declare namespace Machine {
|
|
|
4065
4285
|
| HistoryTarget<States, HistoryIdentifier<States>>
|
|
4066
4286
|
| ChoiceTarget<States, ChoiceIdentifier<States>>
|
|
4067
4287
|
>
|
|
4068
|
-
|
|
|
4288
|
+
| NoTarget
|
|
4069
4289
|
|
|
4070
4290
|
/** A choice resolver must always select a typed target synchronously. */
|
|
4071
4291
|
export type ChoiceResult<States extends StateSchemas, E, R> =
|
|
@@ -4264,6 +4484,14 @@ export declare namespace Machine {
|
|
|
4264
4484
|
} ? Emitted
|
|
4265
4485
|
: Invoke extends { readonly child: ChildMachine<string, infer M> } ? Emit<M>
|
|
4266
4486
|
: never
|
|
4487
|
+
|
|
4488
|
+
/** Public parent inputs required by an invoked child machine. */
|
|
4489
|
+
export type InvokeParentEvents<Invoke> = Invoke extends {
|
|
4490
|
+
readonly [InvokeTypeId]: { readonly parentEvents: Types.Covariant<infer ParentEvent> }
|
|
4491
|
+
} ? ParentEvent
|
|
4492
|
+
: IsAny<Invoke> extends true ? never
|
|
4493
|
+
: Invoke extends { readonly child: ChildMachine<string, infer M> } ? EventOf<ParentEvents<M>>
|
|
4494
|
+
: never
|
|
4267
4495
|
/** Extracts transition results returned by invocation lifecycle handlers. */
|
|
4268
4496
|
export type InvokeOutcomeReturn<Invoke> = Invoke extends unknown ?
|
|
4269
4497
|
| (Invoke extends { readonly onDone?: infer Handler } ? EventTransitionReturn<NonNullable<Handler>> : never)
|
|
@@ -4373,13 +4601,14 @@ export declare namespace Machine {
|
|
|
4373
4601
|
}
|
|
4374
4602
|
|
|
4375
4603
|
/** Type evidence retained by {@link invoke} without affecting runtime data. */
|
|
4376
|
-
export interface InvokeTyped<Output, Error, Requirements, InitialError, Emits = never> {
|
|
4604
|
+
export interface InvokeTyped<Output, Error, Requirements, InitialError, Emits = never, ParentEvent = never> {
|
|
4377
4605
|
readonly [InvokeTypeId]: {
|
|
4378
4606
|
readonly output: Types.Covariant<Output>
|
|
4379
4607
|
readonly error: Types.Covariant<Error>
|
|
4380
4608
|
readonly requirements: Types.Covariant<Requirements>
|
|
4381
4609
|
readonly initialError: Types.Covariant<InitialError>
|
|
4382
4610
|
readonly emits: Types.Covariant<Emits>
|
|
4611
|
+
readonly parentEvents: Types.Covariant<ParentEvent>
|
|
4383
4612
|
}
|
|
4384
4613
|
}
|
|
4385
4614
|
|
|
@@ -4808,64 +5037,66 @@ export declare namespace Machine {
|
|
|
4808
5037
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
4809
5038
|
StateId extends StateIdentifier<States>,
|
|
4810
5039
|
E,
|
|
4811
|
-
R
|
|
5040
|
+
R,
|
|
5041
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
5042
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4812
5043
|
> = {
|
|
4813
5044
|
readonly entry?: (
|
|
4814
|
-
context: StateActionContext<States, Events, Emits, StateId>,
|
|
5045
|
+
context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
4815
5046
|
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
4816
5047
|
) => StateActionResult<any, any>
|
|
4817
5048
|
readonly exit?: (
|
|
4818
|
-
context: StateActionContext<States, Events, Emits, StateId>,
|
|
5049
|
+
context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
4819
5050
|
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
4820
5051
|
) => StateActionResult<any, any>
|
|
4821
5052
|
readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>
|
|
4822
5053
|
readonly always?:
|
|
4823
5054
|
| ((
|
|
4824
|
-
context: AlwaysContext<States, Events, Emits, StateId>,
|
|
5055
|
+
context: AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
4825
5056
|
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
4826
5057
|
) => HandlerResult<States, any, any>)
|
|
4827
5058
|
| {
|
|
4828
5059
|
/** Statically declared upper bound of possible target paths. */
|
|
4829
5060
|
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>
|
|
4830
5061
|
readonly transition: (
|
|
4831
|
-
context: AlwaysContext<States, Events, Emits, StateId>,
|
|
5062
|
+
context: AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
4832
5063
|
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
4833
5064
|
) => HandlerResult<States, any, any>
|
|
4834
5065
|
}
|
|
4835
5066
|
readonly onDone?:
|
|
4836
5067
|
| ((
|
|
4837
|
-
context: DoneContext<States, Events, Emits, StateId>,
|
|
5068
|
+
context: DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
4838
5069
|
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
4839
5070
|
) => HandlerResult<States, any, any>)
|
|
4840
5071
|
| {
|
|
4841
5072
|
/** Statically declared upper bound of possible target paths. */
|
|
4842
5073
|
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>
|
|
4843
5074
|
readonly transition: (
|
|
4844
|
-
context: DoneContext<States, Events, Emits, StateId>,
|
|
5075
|
+
context: DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
4845
5076
|
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
4846
5077
|
) => HandlerResult<States, any, any>
|
|
4847
5078
|
}
|
|
4848
5079
|
readonly on?: {
|
|
4849
5080
|
readonly [EventTag in TagOf<Events[number]>]?:
|
|
4850
5081
|
| ((
|
|
4851
|
-
context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>,
|
|
5082
|
+
context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>,
|
|
4852
5083
|
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
4853
5084
|
) => HandlerResult<States, any, any>)
|
|
4854
5085
|
| {
|
|
4855
5086
|
readonly reenter?: boolean
|
|
4856
5087
|
/**
|
|
4857
5088
|
* Upper bound of state or history paths this handler may target.
|
|
4858
|
-
* Returning `
|
|
5089
|
+
* Returning `target.none()` is always permitted. Declaring a parent state also
|
|
4859
5090
|
* permits concrete descendant targets below it.
|
|
4860
5091
|
*/
|
|
4861
5092
|
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>
|
|
4862
5093
|
readonly transition: (
|
|
4863
|
-
context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>,
|
|
5094
|
+
context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>,
|
|
4864
5095
|
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
4865
5096
|
) => HandlerResult<States, any, any>
|
|
4866
5097
|
}
|
|
4867
5098
|
}
|
|
4868
|
-
readonly initial?: StateInitialHandler<States, Events, Emits, StateId>
|
|
5099
|
+
readonly initial?: StateInitialHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
4869
5100
|
} & ActiveOutputHandlerConfig<States, Events, StateId>
|
|
4870
5101
|
|
|
4871
5102
|
/** Values supplied when a statechart implicitly enters a state's initial children. */
|
|
@@ -4890,17 +5121,21 @@ export declare namespace Machine {
|
|
|
4890
5121
|
States extends StateSchemas,
|
|
4891
5122
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
4892
5123
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
4893
|
-
StateId extends StateIdentifier<States
|
|
4894
|
-
|
|
5124
|
+
StateId extends StateIdentifier<States>,
|
|
5125
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
5126
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
5127
|
+
> = StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
4895
5128
|
|
|
4896
5129
|
/** Initial child value implementation for a compound or parallel state. */
|
|
4897
5130
|
export type StateInitialHandler<
|
|
4898
5131
|
States extends StateSchemas,
|
|
4899
5132
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
4900
5133
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
4901
|
-
StateId extends StateIdentifier<States
|
|
5134
|
+
StateId extends StateIdentifier<States>,
|
|
5135
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
5136
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4902
5137
|
> = (
|
|
4903
|
-
context: StateInitialContext<States, Events, Emits, StateId>,
|
|
5138
|
+
context: StateInitialContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
4904
5139
|
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
4905
5140
|
) => StateInitialValue<States, StateId>
|
|
4906
5141
|
|
|
@@ -4913,7 +5148,7 @@ export declare namespace Machine {
|
|
|
4913
5148
|
> {
|
|
4914
5149
|
readonly event: LifecycleEvent<Events>
|
|
4915
5150
|
readonly target: HistoryDefaultTargetBuilder<States, ParentId>
|
|
4916
|
-
readonly
|
|
5151
|
+
readonly owner: ParentId
|
|
4917
5152
|
}
|
|
4918
5153
|
|
|
4919
5154
|
/**
|
|
@@ -4953,13 +5188,15 @@ export declare namespace Machine {
|
|
|
4953
5188
|
States extends StateSchemas,
|
|
4954
5189
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
4955
5190
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
4956
|
-
ChoiceId extends ChoiceIdentifier<States
|
|
5191
|
+
ChoiceId extends ChoiceIdentifier<States>,
|
|
5192
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
5193
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4957
5194
|
> {
|
|
4958
5195
|
readonly choice: {
|
|
4959
5196
|
/** Statically inspectable upper bound of every possible target. */
|
|
4960
5197
|
readonly targets: readonly [StateNodeIdentifier<States>, ...ReadonlyArray<StateNodeIdentifier<States>>]
|
|
4961
5198
|
readonly transition: (
|
|
4962
|
-
context: ChoiceContext<States, Events, Emits, ChoiceId>,
|
|
5199
|
+
context: ChoiceContext<States, Events, Emits, ChoiceId, InputEvents, ParentEvents>,
|
|
4963
5200
|
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
4964
5201
|
) => ChoiceResult<States, any, any>
|
|
4965
5202
|
}
|
|
@@ -4983,10 +5220,12 @@ export declare namespace Machine {
|
|
|
4983
5220
|
States extends StateSchemas,
|
|
4984
5221
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
4985
5222
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
4986
|
-
StateId extends StateIdentifier<States
|
|
5223
|
+
StateId extends StateIdentifier<States>,
|
|
5224
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
5225
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4987
5226
|
> = {
|
|
4988
5227
|
readonly entry?: (
|
|
4989
|
-
context: StateActionContext<States, Events, Emits, StateId>,
|
|
5228
|
+
context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
|
|
4990
5229
|
enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
|
|
4991
5230
|
) => StateActionResult<any, any>
|
|
4992
5231
|
readonly exit?: never
|
|
@@ -5007,10 +5246,12 @@ export declare namespace Machine {
|
|
|
5007
5246
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5008
5247
|
StateId extends StateIdentifier<States>,
|
|
5009
5248
|
E,
|
|
5010
|
-
R
|
|
5249
|
+
R,
|
|
5250
|
+
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
5251
|
+
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
5011
5252
|
> = NodeByIdentifier<States, StateId> extends { readonly type: "final" } ?
|
|
5012
|
-
FinalStateConfig<States, Events, Emits, StateId>
|
|
5013
|
-
: ActiveStateConfig<States, Events, Emits, StateId, E, R>
|
|
5253
|
+
FinalStateConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
5254
|
+
: ActiveStateConfig<States, Events, Emits, StateId, E, R, InputEvents, ParentEvents>
|
|
5014
5255
|
|
|
5015
5256
|
type HandlerNodeConfig<
|
|
5016
5257
|
States extends StateSchemas,
|
|
@@ -5018,9 +5259,11 @@ export declare namespace Machine {
|
|
|
5018
5259
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5019
5260
|
Path extends StateNodeIdentifier<States>,
|
|
5020
5261
|
E,
|
|
5021
|
-
R
|
|
5022
|
-
|
|
5023
|
-
|
|
5262
|
+
R,
|
|
5263
|
+
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
5264
|
+
ParentEvents extends ReadonlyArray<TaggedSchema>
|
|
5265
|
+
> = Path extends ChoiceIdentifier<States> ? ChoiceStateConfig<States, Events, Emits, Path, InputEvents, ParentEvents>
|
|
5266
|
+
: Path extends StateIdentifier<States> ? HandlerConfig<States, Events, Emits, Path, E, R, InputEvents, ParentEvents>
|
|
5024
5267
|
: never
|
|
5025
5268
|
|
|
5026
5269
|
type HandlerChildren<Node> = Node extends { readonly states: infer Children extends StateSchemas } ? Children : never
|
|
@@ -5103,9 +5346,11 @@ export declare namespace Machine {
|
|
|
5103
5346
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5104
5347
|
E,
|
|
5105
5348
|
R,
|
|
5349
|
+
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
5350
|
+
ParentEvents extends ReadonlyArray<TaggedSchema>,
|
|
5106
5351
|
StateId extends StateNodeIdentifier<AllStates>
|
|
5107
5352
|
> =
|
|
5108
|
-
& HandlerNodeConfig<AllStates, Events, Emits, StateId, E, R>
|
|
5353
|
+
& HandlerNodeConfig<AllStates, Events, Emits, StateId, E, R, InputEvents, ParentEvents>
|
|
5109
5354
|
& (StateId extends ChoiceIdentifier<AllStates> ? {
|
|
5110
5355
|
readonly states?: never
|
|
5111
5356
|
readonly history?: never
|
|
@@ -5122,6 +5367,8 @@ export declare namespace Machine {
|
|
|
5122
5367
|
Emits,
|
|
5123
5368
|
E,
|
|
5124
5369
|
R,
|
|
5370
|
+
InputEvents,
|
|
5371
|
+
ParentEvents,
|
|
5125
5372
|
Extract<StateId, StateIdentifier<AllStates>>
|
|
5126
5373
|
>
|
|
5127
5374
|
readonly history?: HistoryDefaultConfig<
|
|
@@ -5144,6 +5391,8 @@ export declare namespace Machine {
|
|
|
5144
5391
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5145
5392
|
E,
|
|
5146
5393
|
R,
|
|
5394
|
+
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
5395
|
+
ParentEvents extends ReadonlyArray<TaggedSchema>,
|
|
5147
5396
|
Prefix extends string
|
|
5148
5397
|
> = {
|
|
5149
5398
|
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]?: HandlerNode<
|
|
@@ -5153,6 +5402,8 @@ export declare namespace Machine {
|
|
|
5153
5402
|
Emits,
|
|
5154
5403
|
E,
|
|
5155
5404
|
R,
|
|
5405
|
+
InputEvents,
|
|
5406
|
+
ParentEvents,
|
|
5156
5407
|
HandlerNodeId<AllStates, JoinPath<Prefix, Key>>
|
|
5157
5408
|
>
|
|
5158
5409
|
}
|
|
@@ -5387,6 +5638,7 @@ export declare namespace Machine {
|
|
|
5387
5638
|
AllStates extends StateSchemas,
|
|
5388
5639
|
Node,
|
|
5389
5640
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
5641
|
+
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
5390
5642
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5391
5643
|
StateId extends StateNodeIdentifier<AllStates>,
|
|
5392
5644
|
Config,
|
|
@@ -5401,7 +5653,7 @@ export declare namespace Machine {
|
|
|
5401
5653
|
& HandlerOnTargetValidation<StateId, Config>
|
|
5402
5654
|
& HandlerDirectTargetValidation<StateId, Config, "always">
|
|
5403
5655
|
& HandlerDirectTargetValidation<StateId, Config, "onDone">
|
|
5404
|
-
&
|
|
5656
|
+
& HandlerInvokeParentEventsValidation<InputEvents, StateId, Config>
|
|
5405
5657
|
& HandlerChildrenValidation<Node, StateId, Config>
|
|
5406
5658
|
& HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config>
|
|
5407
5659
|
& HandlerRuntimeValidation<Events, Emits, StateId, Config>
|
|
@@ -5430,17 +5682,17 @@ export declare namespace Machine {
|
|
|
5430
5682
|
}
|
|
5431
5683
|
: unknown
|
|
5432
5684
|
|
|
5433
|
-
type
|
|
5685
|
+
type HandlerInvokeParentEventsValidation<
|
|
5434
5686
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
5435
5687
|
StateId extends string,
|
|
5436
5688
|
Config
|
|
5437
5689
|
> = [InvokeReturn<Config>] extends [never] ? unknown
|
|
5438
|
-
: [Exclude<
|
|
5690
|
+
: [Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>] extends [never] ? unknown
|
|
5439
5691
|
: {
|
|
5440
5692
|
readonly invoke: HandlerValidationError<
|
|
5441
|
-
"Invoked child
|
|
5693
|
+
"Invoked child expects parent events not accepted by this machine",
|
|
5442
5694
|
StateId,
|
|
5443
|
-
Exclude<
|
|
5695
|
+
Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>
|
|
5444
5696
|
>
|
|
5445
5697
|
}
|
|
5446
5698
|
|
|
@@ -5460,6 +5712,7 @@ export declare namespace Machine {
|
|
|
5460
5712
|
type HandlerNodeValidationAtPath<
|
|
5461
5713
|
AllStates extends StateSchemas,
|
|
5462
5714
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
5715
|
+
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
5463
5716
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5464
5717
|
Config,
|
|
5465
5718
|
AvailableOutputStates extends StateIdentifier<AllStates>,
|
|
@@ -5470,6 +5723,7 @@ export declare namespace Machine {
|
|
|
5470
5723
|
AllStates,
|
|
5471
5724
|
HandlerNodeByPath<AllStates, StateId>,
|
|
5472
5725
|
Events,
|
|
5726
|
+
InputEvents,
|
|
5473
5727
|
Emits,
|
|
5474
5728
|
StateId,
|
|
5475
5729
|
NodeConfig,
|
|
@@ -5481,6 +5735,7 @@ export declare namespace Machine {
|
|
|
5481
5735
|
type HandlerTreeNodeValidations<
|
|
5482
5736
|
AllStates extends StateSchemas,
|
|
5483
5737
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
5738
|
+
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
5484
5739
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5485
5740
|
Config,
|
|
5486
5741
|
AvailableOutputStates extends StateIdentifier<AllStates>
|
|
@@ -5489,6 +5744,7 @@ export declare namespace Machine {
|
|
|
5489
5744
|
StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeValidationAtPath<
|
|
5490
5745
|
AllStates,
|
|
5491
5746
|
Events,
|
|
5747
|
+
InputEvents,
|
|
5492
5748
|
Emits,
|
|
5493
5749
|
Config,
|
|
5494
5750
|
AvailableOutputStates,
|
|
@@ -5501,12 +5757,13 @@ export declare namespace Machine {
|
|
|
5501
5757
|
type HandlerTreeValidation<
|
|
5502
5758
|
AllStates extends StateSchemas,
|
|
5503
5759
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
5760
|
+
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
5504
5761
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5505
5762
|
Config,
|
|
5506
5763
|
AvailableOutputStates extends StateIdentifier<AllStates>
|
|
5507
5764
|
> =
|
|
5508
5765
|
& HandlerUnknownStateKeyValidation<AllStates, "", Config>
|
|
5509
|
-
& HandlerTreeNodeValidations<AllStates, Events, Emits, Config, AvailableOutputStates>
|
|
5766
|
+
& HandlerTreeNodeValidations<AllStates, Events, InputEvents, Emits, Config, AvailableOutputStates>
|
|
5510
5767
|
|
|
5511
5768
|
type HandlerHasRequiredInitial<
|
|
5512
5769
|
AllStates extends StateSchemas,
|
|
@@ -5602,6 +5859,7 @@ export declare namespace Machine {
|
|
|
5602
5859
|
Output,
|
|
5603
5860
|
OutputStates extends StateIdentifier<AllStates>,
|
|
5604
5861
|
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
5862
|
+
ParentEvents extends ReadonlyArray<TaggedSchema>,
|
|
5605
5863
|
Config
|
|
5606
5864
|
> = Machine<
|
|
5607
5865
|
AllStates,
|
|
@@ -5620,7 +5878,8 @@ export declare namespace Machine {
|
|
|
5620
5878
|
Output,
|
|
5621
5879
|
Emits,
|
|
5622
5880
|
OutputStates | Extract<HandlerTreeEvidence<AllStates, Config>["outputState"], StateIdentifier<AllStates>>,
|
|
5623
|
-
InputEvents
|
|
5881
|
+
InputEvents,
|
|
5882
|
+
ParentEvents
|
|
5624
5883
|
>
|
|
5625
5884
|
|
|
5626
5885
|
/**
|
|
@@ -5642,15 +5901,29 @@ export declare namespace Machine {
|
|
|
5642
5901
|
FinalStates extends StateIdentifier<States>,
|
|
5643
5902
|
Output,
|
|
5644
5903
|
OutputStates extends StateIdentifier<States>,
|
|
5645
|
-
InputEvents extends ReadonlyArray<TaggedSchema
|
|
5904
|
+
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
5905
|
+
ParentEvents extends ReadonlyArray<TaggedSchema>
|
|
5646
5906
|
> {
|
|
5647
|
-
<
|
|
5907
|
+
<
|
|
5908
|
+
const Config extends HandlerTree<
|
|
5909
|
+
States,
|
|
5910
|
+
States,
|
|
5911
|
+
Events,
|
|
5912
|
+
Emits,
|
|
5913
|
+
E,
|
|
5914
|
+
R,
|
|
5915
|
+
InputEvents,
|
|
5916
|
+
ParentEvents,
|
|
5917
|
+
""
|
|
5918
|
+
>
|
|
5919
|
+
>(
|
|
5648
5920
|
config:
|
|
5649
5921
|
& Config
|
|
5650
5922
|
& HandlerInvokeContexts<States, Events, Emits, NoInfer<Config>>
|
|
5651
5923
|
& HandlerTreeValidation<
|
|
5652
5924
|
States,
|
|
5653
5925
|
Events,
|
|
5926
|
+
InputEvents,
|
|
5654
5927
|
Emits,
|
|
5655
5928
|
NoInfer<Config>,
|
|
5656
5929
|
| OutputStates
|
|
@@ -5673,6 +5946,7 @@ export declare namespace Machine {
|
|
|
5673
5946
|
Output,
|
|
5674
5947
|
OutputStates,
|
|
5675
5948
|
InputEvents,
|
|
5949
|
+
ParentEvents,
|
|
5676
5950
|
Config
|
|
5677
5951
|
>
|
|
5678
5952
|
}
|
|
@@ -5824,7 +6098,8 @@ export const isFinal: <
|
|
|
5824
6098
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
5825
6099
|
Output = never,
|
|
5826
6100
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
5827
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
|
|
6101
|
+
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
|
|
6102
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
5828
6103
|
>(
|
|
5829
6104
|
machine: Machine<
|
|
5830
6105
|
States,
|
|
@@ -5839,10 +6114,11 @@ export const isFinal: <
|
|
|
5839
6114
|
Output,
|
|
5840
6115
|
Emits,
|
|
5841
6116
|
OutputStates,
|
|
5842
|
-
InputEvents
|
|
6117
|
+
InputEvents,
|
|
6118
|
+
ParentEvents
|
|
5843
6119
|
>,
|
|
5844
6120
|
state: Machine.Snapshot<States>
|
|
5845
|
-
) => state is Machine.SnapshotContainingFinal<States, FinalStates> = internal.isFinal
|
|
6121
|
+
) => state is Machine.SnapshotContainingFinal<States, FinalStates> = internal.isFinal as any
|
|
5846
6122
|
|
|
5847
6123
|
/**
|
|
5848
6124
|
* Defines a state tree while preserving literal state paths.
|
|
@@ -5872,7 +6148,7 @@ export const isFinal: <
|
|
|
5872
6148
|
*
|
|
5873
6149
|
* Machine.make({
|
|
5874
6150
|
* states: States.states,
|
|
5875
|
-
* events:
|
|
6151
|
+
* events: Machine.events(),
|
|
5876
6152
|
* initial: () => States.initial.idle.from()
|
|
5877
6153
|
* })
|
|
5878
6154
|
* ```
|
|
@@ -5889,18 +6165,22 @@ type MakeConfig<
|
|
|
5889
6165
|
Input extends Schema.Top,
|
|
5890
6166
|
InitialE,
|
|
5891
6167
|
InitialR,
|
|
5892
|
-
InternalEvents extends ReadonlyArray<Machine.TaggedSchema
|
|
6168
|
+
InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
6169
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema>
|
|
5893
6170
|
> = {
|
|
5894
6171
|
readonly id?: string
|
|
5895
6172
|
readonly states: States & DefineStateTreeInput<NoInfer<States>>
|
|
5896
|
-
readonly events:
|
|
6173
|
+
readonly events:
|
|
6174
|
+
& Machine.EventProtocol<"public", InputEvents>
|
|
6175
|
+
& ValidateInputEventProtocol<NoInfer<InputEvents>>
|
|
5897
6176
|
readonly internalEvents?:
|
|
5898
|
-
& InternalEvents
|
|
6177
|
+
& Machine.EventProtocol<"internal", InternalEvents>
|
|
5899
6178
|
& ValidateInternalEventProtocol<
|
|
5900
6179
|
NoInfer<InputEvents>,
|
|
5901
6180
|
NoInfer<InternalEvents>
|
|
5902
6181
|
>
|
|
5903
|
-
readonly
|
|
6182
|
+
readonly emittedEvents?: Machine.EventProtocol<"emitted", Emits>
|
|
6183
|
+
readonly parentEvents?: Machine.EventProtocol<"public", ParentEvents>
|
|
5904
6184
|
readonly input?: Input
|
|
5905
6185
|
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>
|
|
5906
6186
|
}
|
|
@@ -5912,7 +6192,8 @@ type MakeResult<
|
|
|
5912
6192
|
Input extends Schema.Top,
|
|
5913
6193
|
InitialE,
|
|
5914
6194
|
InitialR,
|
|
5915
|
-
InternalEvents extends ReadonlyArray<Machine.TaggedSchema
|
|
6195
|
+
InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
6196
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema>
|
|
5916
6197
|
> = Machine<
|
|
5917
6198
|
States,
|
|
5918
6199
|
readonly [...InputEvents, ...InternalEvents],
|
|
@@ -5926,7 +6207,8 @@ type MakeResult<
|
|
|
5926
6207
|
Machine.TerminalOutput<States>,
|
|
5927
6208
|
Emits,
|
|
5928
6209
|
never,
|
|
5929
|
-
InputEvents
|
|
6210
|
+
InputEvents,
|
|
6211
|
+
ParentEvents
|
|
5930
6212
|
>
|
|
5931
6213
|
|
|
5932
6214
|
interface Make {
|
|
@@ -5937,11 +6219,12 @@ interface Make {
|
|
|
5937
6219
|
const Input extends Schema.Top = typeof Schema.Void,
|
|
5938
6220
|
InitialE = never,
|
|
5939
6221
|
InitialR = never,
|
|
5940
|
-
const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
6222
|
+
const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
6223
|
+
const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
5941
6224
|
>(
|
|
5942
|
-
config: MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents>,
|
|
6225
|
+
config: MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>,
|
|
5943
6226
|
..._validation: ValidateDefinedStates<NoInfer<States>>
|
|
5944
|
-
): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents>
|
|
6227
|
+
): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>
|
|
5945
6228
|
<
|
|
5946
6229
|
const States extends Machine.StateSchemas,
|
|
5947
6230
|
const InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
@@ -5949,10 +6232,11 @@ interface Make {
|
|
|
5949
6232
|
const Input extends Schema.Top = typeof Schema.Void,
|
|
5950
6233
|
InitialE = never,
|
|
5951
6234
|
InitialR = never,
|
|
5952
|
-
const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
6235
|
+
const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
6236
|
+
const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
5953
6237
|
>(
|
|
5954
6238
|
config:
|
|
5955
|
-
& Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents>, "states">
|
|
6239
|
+
& Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>, "states">
|
|
5956
6240
|
& { readonly states: InvalidDefinedStateTreeInput<States> }
|
|
5957
6241
|
): never
|
|
5958
6242
|
}
|
|
@@ -5968,10 +6252,13 @@ interface Make {
|
|
|
5968
6252
|
* `defineStates` or is passed inline. Call `handle` on the returned definition
|
|
5969
6253
|
* to implement state behavior with ordinary TypeScript control flow.
|
|
5970
6254
|
*
|
|
5971
|
-
*
|
|
5972
|
-
*
|
|
5973
|
-
*
|
|
5974
|
-
*
|
|
6255
|
+
* `Machine.events` defines the public input protocol. `Machine.internalEvents`
|
|
6256
|
+
* adds raised events and other machine-local deliveries.
|
|
6257
|
+
* `Machine.emittedEvents` defines outward ephemeral notifications, while
|
|
6258
|
+
* `parentEvents` declares the inputs a child may explicitly send to its owning
|
|
6259
|
+
* actor. All descriptors expose deferred constructors while retaining their
|
|
6260
|
+
* schemas opaquely for runtime validation. Public and internal tags must be
|
|
6261
|
+
* disjoint.
|
|
5975
6262
|
*
|
|
5976
6263
|
* **Example** (Typed counter machine)
|
|
5977
6264
|
*
|
|
@@ -5988,10 +6275,11 @@ interface Make {
|
|
|
5988
6275
|
* }) {}
|
|
5989
6276
|
*
|
|
5990
6277
|
* const States = Machine.defineStates({ Count })
|
|
6278
|
+
* const Events = Machine.events(Increment)
|
|
5991
6279
|
*
|
|
5992
6280
|
* const counter = Machine.make({
|
|
5993
6281
|
* states: States.states,
|
|
5994
|
-
* events:
|
|
6282
|
+
* events: Events,
|
|
5995
6283
|
* initial: () => States.initial.Count(new Count({ value: 0 }))
|
|
5996
6284
|
* }).handle({
|
|
5997
6285
|
* Count: {
|
|
@@ -6009,60 +6297,19 @@ interface Make {
|
|
|
6009
6297
|
*/
|
|
6010
6298
|
export const make: Make = internal.make
|
|
6011
6299
|
|
|
6012
|
-
type EventConstructorArgs<EventSchema extends Machine.TaggedSchema> = {} extends EventSchema["~type.make.in"] ?
|
|
6013
|
-
[input?: EventSchema["~type.make.in"]]
|
|
6014
|
-
: [input: EventSchema["~type.make.in"]]
|
|
6015
|
-
|
|
6016
6300
|
/**
|
|
6017
|
-
*
|
|
6018
|
-
*
|
|
6019
|
-
* **Details**
|
|
6301
|
+
* Extracts the decoded event union carried by an event protocol descriptor.
|
|
6020
6302
|
*
|
|
6021
|
-
*
|
|
6022
|
-
*
|
|
6023
|
-
* repeated delivery does not decode the same already-constructed value again.
|
|
6024
|
-
* Events supplied through ordinary `send` and `plan` calls remain untrusted
|
|
6025
|
-
* and continue through full runtime schema validation.
|
|
6026
|
-
* Treat the returned event as immutable after construction.
|
|
6027
|
-
* This eager low-level constructor throws `MachineSchemaDecodeError` when
|
|
6028
|
-
* construction fails. Prefer {@link events} and {@link internalEvents} for
|
|
6029
|
-
* ordinary delivery so construction remains inside the machine error channel.
|
|
6030
|
-
*
|
|
6031
|
-
* The schema must be one of the machine's configured public or internal event
|
|
6032
|
-
* schemas, or a case schema belonging to a configured `Schema.TaggedUnion`.
|
|
6033
|
-
*
|
|
6034
|
-
* **Example**
|
|
6035
|
-
*
|
|
6036
|
-
* ```ts
|
|
6037
|
-
* import { Schema } from "effect"
|
|
6038
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
6039
|
-
*
|
|
6040
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
6041
|
-
* class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", {
|
|
6042
|
-
* by: Schema.Number
|
|
6043
|
-
* }) {}
|
|
6044
|
-
*
|
|
6045
|
-
* const States = Machine.defineStates({ Idle })
|
|
6046
|
-
* const counter = Machine.make({
|
|
6047
|
-
* states: States.states,
|
|
6048
|
-
* events: [Increment],
|
|
6049
|
-
* initial: () => States.initial.Idle.from()
|
|
6050
|
-
* }).handle({ Idle: { on: { Increment: () => States.initial.Idle.from() } } })
|
|
6051
|
-
*
|
|
6052
|
-
* const increment = Machine.event(counter, Increment, { by: 1 })
|
|
6053
|
-
* ```
|
|
6054
|
-
*
|
|
6055
|
-
* @category constructors
|
|
6056
|
-
* @since 0.4.0
|
|
6303
|
+
* @category utility types
|
|
6304
|
+
* @since 0.10.0
|
|
6057
6305
|
*/
|
|
6058
|
-
export
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
...args: EventConstructorArgs<EventSchema>
|
|
6062
|
-
) => EventSchema["Type"] = internal.event
|
|
6306
|
+
export type EventOf<Protocol extends Machine.EventProtocol.Any> = Machine.EventOf<
|
|
6307
|
+
Machine.EventProtocolSchemas<Protocol>
|
|
6308
|
+
>
|
|
6063
6309
|
|
|
6064
6310
|
/**
|
|
6065
|
-
*
|
|
6311
|
+
* Defines a public event protocol and returns deferred constructors for every
|
|
6312
|
+
* statically finite configured event tag.
|
|
6066
6313
|
*
|
|
6067
6314
|
* Constructor inputs retain their schema-derived required fields, defaults,
|
|
6068
6315
|
* and transformations. Construction is deferred until delivery so failures
|
|
@@ -6072,31 +6319,70 @@ export const event: <const M extends Machine.Any, const EventSchema extends Mach
|
|
|
6072
6319
|
* **Example**
|
|
6073
6320
|
*
|
|
6074
6321
|
* ```ts
|
|
6075
|
-
* const
|
|
6076
|
-
*
|
|
6322
|
+
* const Events = Machine.events(Increment, Reset)
|
|
6323
|
+
* const machine = Machine.make({ events: Events, ... })
|
|
6324
|
+
* yield* ref.send(Events.Increment({ by: 1 }))
|
|
6077
6325
|
* ```
|
|
6078
6326
|
*
|
|
6079
6327
|
* @category constructors
|
|
6080
|
-
* @since 0.
|
|
6328
|
+
* @since 0.10.0
|
|
6081
6329
|
*/
|
|
6082
|
-
export const events:
|
|
6083
|
-
|
|
6084
|
-
|
|
6330
|
+
export const events: {
|
|
6331
|
+
<const Schemas extends ReadonlyArray<Machine.TaggedSchema>>(
|
|
6332
|
+
...schemas: Schemas & ValidateInputEventProtocol<NoInfer<Schemas>>
|
|
6333
|
+
): Machine.EventProtocol<"public", readonly [...Schemas]>
|
|
6334
|
+
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"public">>>(
|
|
6335
|
+
...inputs: Inputs & ValidateEventProtocolBuilder<"public", Inputs>
|
|
6336
|
+
): Machine.EventProtocol<"public", Machine.EventProtocolInputSchemasOf<"public", Inputs>>
|
|
6337
|
+
} = internal.events as any
|
|
6085
6338
|
|
|
6086
6339
|
/**
|
|
6087
|
-
*
|
|
6088
|
-
*
|
|
6340
|
+
* Defines an internal event protocol and returns deferred constructors for
|
|
6341
|
+
* every statically finite configured event tag.
|
|
6089
6342
|
*
|
|
6090
6343
|
* Use these constructors for raised events and other machine-local deliveries.
|
|
6091
6344
|
* Construction failures are reported through the
|
|
6092
6345
|
* owning machine's `MachineSchemaDecodeError` channel.
|
|
6093
6346
|
*
|
|
6347
|
+
* **Example**
|
|
6348
|
+
*
|
|
6349
|
+
* ```ts
|
|
6350
|
+
* const InternalEvents = Machine.internalEvents(Loaded, Failed)
|
|
6351
|
+
* const machine = Machine.make({ internalEvents: InternalEvents, ... })
|
|
6352
|
+
*
|
|
6353
|
+
* // Inside a transition callback:
|
|
6354
|
+
* enqueue.raise(InternalEvents.Loaded({ value }))
|
|
6355
|
+
* ```
|
|
6356
|
+
*
|
|
6094
6357
|
* @category constructors
|
|
6095
|
-
* @since 0.
|
|
6358
|
+
* @since 0.10.0
|
|
6096
6359
|
*/
|
|
6097
|
-
export const internalEvents:
|
|
6098
|
-
|
|
6099
|
-
|
|
6360
|
+
export const internalEvents: {
|
|
6361
|
+
<const Schemas extends ReadonlyArray<Machine.TaggedSchema>>(
|
|
6362
|
+
...schemas: Schemas & ValidateInternalEventProtocol<readonly [], NoInfer<Schemas>>
|
|
6363
|
+
): Machine.EventProtocol<"internal", readonly [...Schemas]>
|
|
6364
|
+
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"internal">>>(
|
|
6365
|
+
...inputs: Inputs & ValidateEventProtocolBuilder<"internal", Inputs>
|
|
6366
|
+
): Machine.EventProtocol<"internal", Machine.EventProtocolInputSchemasOf<"internal", Inputs>>
|
|
6367
|
+
} = internal.internalEvents as any
|
|
6368
|
+
|
|
6369
|
+
/**
|
|
6370
|
+
* Defines the ephemeral notifications a machine may publish to external
|
|
6371
|
+
* observers. Emitted events are separate from actor input and are never sent
|
|
6372
|
+
* implicitly to a parent actor. Observe them through `MachineRef.emissions` or
|
|
6373
|
+
* the AtomMachine emission stream adapters.
|
|
6374
|
+
*
|
|
6375
|
+
* @category constructors
|
|
6376
|
+
* @since 0.10.0
|
|
6377
|
+
*/
|
|
6378
|
+
export const emittedEvents: {
|
|
6379
|
+
<const Schemas extends ReadonlyArray<Machine.TaggedSchema>>(
|
|
6380
|
+
...schemas: Schemas & ValidateEmittedEventProtocol<NoInfer<Schemas>>
|
|
6381
|
+
): Machine.EventProtocol<"emitted", readonly [...Schemas]>
|
|
6382
|
+
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"emitted">>>(
|
|
6383
|
+
...inputs: Inputs & ValidateEventProtocolBuilder<"emitted", Inputs>
|
|
6384
|
+
): Machine.EventProtocol<"emitted", Machine.EventProtocolInputSchemasOf<"emitted", Inputs>>
|
|
6385
|
+
} = internal.emittedEvents as any
|
|
6100
6386
|
|
|
6101
6387
|
/**
|
|
6102
6388
|
* Encodes a decoded machine snapshot into a normalized data representation.
|
|
@@ -6131,7 +6417,7 @@ export const internalEvents: <const M extends Machine.Any>(
|
|
|
6131
6417
|
* const States = Machine.defineStates({ Idle })
|
|
6132
6418
|
* const machine = Machine.make({
|
|
6133
6419
|
* states: States.states,
|
|
6134
|
-
* events:
|
|
6420
|
+
* events: Machine.events(),
|
|
6135
6421
|
* initial: () => States.initial.Idle.from()
|
|
6136
6422
|
* }).handle({ Idle: {} })
|
|
6137
6423
|
*
|
|
@@ -6158,7 +6444,8 @@ export const encodeSnapshot: <
|
|
|
6158
6444
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
6159
6445
|
Output = never,
|
|
6160
6446
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
6161
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
|
|
6447
|
+
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
|
|
6448
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
6162
6449
|
>(
|
|
6163
6450
|
machine: Machine<
|
|
6164
6451
|
States,
|
|
@@ -6173,14 +6460,15 @@ export const encodeSnapshot: <
|
|
|
6173
6460
|
Output,
|
|
6174
6461
|
Emits,
|
|
6175
6462
|
OutputStates,
|
|
6176
|
-
InputEvents
|
|
6463
|
+
InputEvents,
|
|
6464
|
+
ParentEvents
|
|
6177
6465
|
>,
|
|
6178
6466
|
snapshot: Machine.Snapshot<States>
|
|
6179
6467
|
) => Effect.Effect<
|
|
6180
6468
|
Machine.EncodedSnapshot,
|
|
6181
6469
|
MachineSchemaEncodeError,
|
|
6182
6470
|
Machine.SnapshotEncodingServices<States>
|
|
6183
|
-
> = internal.encodeSnapshot
|
|
6471
|
+
> = internal.encodeSnapshot as any
|
|
6184
6472
|
|
|
6185
6473
|
/**
|
|
6186
6474
|
* Decodes a normalized data representation into a validated machine snapshot.
|
|
@@ -6211,7 +6499,7 @@ export const encodeSnapshot: <
|
|
|
6211
6499
|
* const States = Machine.defineStates({ Idle })
|
|
6212
6500
|
* const machine = Machine.make({
|
|
6213
6501
|
* states: States.states,
|
|
6214
|
-
* events:
|
|
6502
|
+
* events: Machine.events(),
|
|
6215
6503
|
* initial: () => States.initial.Idle.from()
|
|
6216
6504
|
* }).handle({ Idle: {} })
|
|
6217
6505
|
*
|
|
@@ -6239,7 +6527,8 @@ export const decodeSnapshot: <
|
|
|
6239
6527
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
6240
6528
|
Output = never,
|
|
6241
6529
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
6242
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
|
|
6530
|
+
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
|
|
6531
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
6243
6532
|
>(
|
|
6244
6533
|
machine: Machine<
|
|
6245
6534
|
States,
|
|
@@ -6254,14 +6543,15 @@ export const decodeSnapshot: <
|
|
|
6254
6543
|
Output,
|
|
6255
6544
|
Emits,
|
|
6256
6545
|
OutputStates,
|
|
6257
|
-
InputEvents
|
|
6546
|
+
InputEvents,
|
|
6547
|
+
ParentEvents
|
|
6258
6548
|
>,
|
|
6259
6549
|
encoded: unknown
|
|
6260
6550
|
) => Effect.Effect<
|
|
6261
6551
|
Machine.Snapshot<States>,
|
|
6262
6552
|
MachineSchemaDecodeError,
|
|
6263
6553
|
Machine.SnapshotDecodingServices<States>
|
|
6264
|
-
> = internal.decodeSnapshot
|
|
6554
|
+
> = internal.decodeSnapshot as any
|
|
6265
6555
|
|
|
6266
6556
|
type DynamicEffectInvokeSource<
|
|
6267
6557
|
States extends Machine.StateSchemas,
|
|
@@ -6559,60 +6849,10 @@ export const invoke: {
|
|
|
6559
6849
|
Machine.Error<Child["machine"]> | ActionError<Machine.Services<Child["machine"]>>,
|
|
6560
6850
|
Machine.Services<Child["machine"]>,
|
|
6561
6851
|
Machine.InitialError<Child["machine"]>,
|
|
6562
|
-
Machine.Emit<Child["machine"]
|
|
6852
|
+
Machine.Emit<Child["machine"]>,
|
|
6853
|
+
Machine.EventOf<Machine.ParentEvents<Child["machine"]>>
|
|
6563
6854
|
>
|
|
6564
6855
|
} = ((config: unknown) => config) as any
|
|
6565
|
-
type RetagFields<Target extends Machine.TaggedSchema> = Omit<Target["~type.make.in"], "_tag">
|
|
6566
|
-
|
|
6567
|
-
type RetagTargetCompatibility<Target extends Machine.TaggedSchema> = Target extends {
|
|
6568
|
-
readonly fields: Schema.Struct.Fields
|
|
6569
|
-
} ? "_tag" extends keyof Target["~type.make.in"] ? {} extends Pick<Target["~type.make.in"], "_tag"> ? unknown : {
|
|
6570
|
-
readonly "~effect/Machine/RetagTargetError": "Target schema must supply its discriminator when make is called"
|
|
6571
|
-
}
|
|
6572
|
-
: unknown
|
|
6573
|
-
: {
|
|
6574
|
-
readonly "~effect/Machine/RetagTargetError": "Target schema must be one tagged struct or tagged class"
|
|
6575
|
-
}
|
|
6576
|
-
|
|
6577
|
-
type RequiredKeys<A> = {
|
|
6578
|
-
readonly [Key in keyof A]-?: {} extends Pick<A, Key> ? never : Key
|
|
6579
|
-
}[keyof A]
|
|
6580
|
-
|
|
6581
|
-
type CompatibleSourceKeys<Fields, Source> = {
|
|
6582
|
-
readonly [Key in Extract<keyof Fields, keyof Source>]: Source[Key] extends Fields[Key] ? Key : never
|
|
6583
|
-
}[Extract<keyof Fields, keyof Source>]
|
|
6584
|
-
|
|
6585
|
-
type RetagPatch<Target extends Machine.TaggedSchema, Source> =
|
|
6586
|
-
& Partial<RetagFields<Target>>
|
|
6587
|
-
& Pick<
|
|
6588
|
-
RetagFields<Target>,
|
|
6589
|
-
Exclude<RequiredKeys<RetagFields<Target>>, CompatibleSourceKeys<RetagFields<Target>, Source>>
|
|
6590
|
-
>
|
|
6591
|
-
|
|
6592
|
-
type RetagArgs<Target extends Machine.TaggedSchema, Source> = [
|
|
6593
|
-
Exclude<RequiredKeys<RetagFields<Target>>, CompatibleSourceKeys<RetagFields<Target>, Source>>
|
|
6594
|
-
] extends [never] ? [patch?: RetagPatch<Target, Source>]
|
|
6595
|
-
: [patch: RetagPatch<Target, Source>]
|
|
6596
|
-
|
|
6597
|
-
/**
|
|
6598
|
-
* Constructs another tagged case from compatible source fields.
|
|
6599
|
-
*
|
|
6600
|
-
* The target must be one tagged struct or tagged class whose discriminator is
|
|
6601
|
-
* supplied by its constructor. Union wrappers are rejected because their
|
|
6602
|
-
* `make` operation cannot select a member after the source discriminator has
|
|
6603
|
-
* been discarded. Missing or incompatible required target fields must be
|
|
6604
|
-
* supplied by the patch, and the target schema's normal `make` validation
|
|
6605
|
-
* remains authoritative at runtime.
|
|
6606
|
-
*
|
|
6607
|
-
* @category constructors
|
|
6608
|
-
* @since 0.4.0
|
|
6609
|
-
*/
|
|
6610
|
-
export const retag: <const Target extends Machine.TaggedSchema, const Source extends { readonly _tag: PropertyKey }>(
|
|
6611
|
-
target: Target & RetagTargetCompatibility<Target>,
|
|
6612
|
-
source: Source,
|
|
6613
|
-
...args: RetagArgs<Target, Source>
|
|
6614
|
-
) => Target["Type"] = internal.retag
|
|
6615
|
-
|
|
6616
6856
|
/**
|
|
6617
6857
|
* Plans the initial state for a machine without executing actor commands.
|
|
6618
6858
|
*
|
|
@@ -6641,7 +6881,7 @@ export const retag: <const Target extends Machine.TaggedSchema, const Source ext
|
|
|
6641
6881
|
* const States = Machine.defineStates({ Idle })
|
|
6642
6882
|
* const machine = Machine.make({
|
|
6643
6883
|
* states: States.states,
|
|
6644
|
-
* events:
|
|
6884
|
+
* events: Machine.events(),
|
|
6645
6885
|
* initial: () => States.initial.Idle.from()
|
|
6646
6886
|
* }).handle({ Idle: {} })
|
|
6647
6887
|
*
|
|
@@ -6666,7 +6906,8 @@ export const planInitial: <
|
|
|
6666
6906
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
6667
6907
|
Output = never,
|
|
6668
6908
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
6669
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
|
|
6909
|
+
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
|
|
6910
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
6670
6911
|
>(
|
|
6671
6912
|
machine:
|
|
6672
6913
|
& Machine<
|
|
@@ -6682,7 +6923,8 @@ export const planInitial: <
|
|
|
6682
6923
|
Output,
|
|
6683
6924
|
Emits,
|
|
6684
6925
|
OutputStates,
|
|
6685
|
-
InputEvents
|
|
6926
|
+
InputEvents,
|
|
6927
|
+
ParentEvents
|
|
6686
6928
|
>
|
|
6687
6929
|
& EnsureExecutable<States, UnhandledStates, OutputStates>,
|
|
6688
6930
|
...args: [...Machine.InputArgs<Input>]
|
|
@@ -6723,7 +6965,7 @@ export const planInitial: <
|
|
|
6723
6965
|
),
|
|
6724
6966
|
InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError,
|
|
6725
6967
|
never
|
|
6726
|
-
> = internal.planInitial
|
|
6968
|
+
> = internal.planInitial as any
|
|
6727
6969
|
|
|
6728
6970
|
/**
|
|
6729
6971
|
* Returns every compiled state node in definition order.
|
|
@@ -6827,7 +7069,8 @@ export const enabled: <
|
|
|
6827
7069
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
6828
7070
|
Output = never,
|
|
6829
7071
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
6830
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
|
|
7072
|
+
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
|
|
7073
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
6831
7074
|
>(
|
|
6832
7075
|
machine: Machine<
|
|
6833
7076
|
States,
|
|
@@ -6842,10 +7085,11 @@ export const enabled: <
|
|
|
6842
7085
|
Output,
|
|
6843
7086
|
Emits,
|
|
6844
7087
|
OutputStates,
|
|
6845
|
-
InputEvents
|
|
7088
|
+
InputEvents,
|
|
7089
|
+
ParentEvents
|
|
6846
7090
|
>,
|
|
6847
7091
|
state: Machine.Snapshot<States>
|
|
6848
|
-
) => ReadonlyArray<Machine.TagOf<Events[number]>> = internal.enabled
|
|
7092
|
+
) => ReadonlyArray<Machine.TagOf<Events[number]>> = internal.enabled as any
|
|
6849
7093
|
|
|
6850
7094
|
/**
|
|
6851
7095
|
* Plans the next state snapshot synchronously.
|
|
@@ -6876,7 +7120,7 @@ export const enabled: <
|
|
|
6876
7120
|
* const States = Machine.defineStates({ Off, On })
|
|
6877
7121
|
* const machine = Machine.make({
|
|
6878
7122
|
* states: States.states,
|
|
6879
|
-
* events:
|
|
7123
|
+
* events: Machine.events(Toggle),
|
|
6880
7124
|
* initial: () => States.initial.Off.from()
|
|
6881
7125
|
* }).handle({ Off: { on: { Toggle: () => States.initial.On.from() } }, On: {} })
|
|
6882
7126
|
*
|
|
@@ -6904,7 +7148,8 @@ export const plan: <
|
|
|
6904
7148
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
6905
7149
|
Output = never,
|
|
6906
7150
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
6907
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
|
|
7151
|
+
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
|
|
7152
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
6908
7153
|
>(
|
|
6909
7154
|
machine:
|
|
6910
7155
|
& Machine<
|
|
@@ -6920,7 +7165,8 @@ export const plan: <
|
|
|
6920
7165
|
Output,
|
|
6921
7166
|
Emits,
|
|
6922
7167
|
OutputStates,
|
|
6923
|
-
InputEvents
|
|
7168
|
+
InputEvents,
|
|
7169
|
+
ParentEvents
|
|
6924
7170
|
>
|
|
6925
7171
|
& EnsureExecutable<States, UnhandledStates, OutputStates>,
|
|
6926
7172
|
state: Machine.Snapshot<States>,
|
|
@@ -6960,7 +7206,7 @@ export const plan: <
|
|
|
6960
7206
|
),
|
|
6961
7207
|
E | InfiniteTransitionError | MachineSchemaDecodeError,
|
|
6962
7208
|
never
|
|
6963
|
-
> = internal.plan
|
|
7209
|
+
> = internal.plan as any
|
|
6964
7210
|
|
|
6965
7211
|
/**
|
|
6966
7212
|
* Creates advanced stateful process logic from explicit initialization and
|
|
@@ -7196,7 +7442,7 @@ export const watch: <State, Event, Error = never, Output = never>(
|
|
|
7196
7442
|
* const States = Machine.defineStates({ Idle })
|
|
7197
7443
|
* const machine = Machine.make({
|
|
7198
7444
|
* states: States.states,
|
|
7199
|
-
* events:
|
|
7445
|
+
* events: Machine.events(),
|
|
7200
7446
|
* initial: () => States.initial.Idle.from()
|
|
7201
7447
|
* }).handle({ Idle: {} })
|
|
7202
7448
|
*
|
|
@@ -7224,7 +7470,8 @@ export const start: <
|
|
|
7224
7470
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
7225
7471
|
Output = never,
|
|
7226
7472
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
7227
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
|
|
7473
|
+
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
|
|
7474
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
7228
7475
|
>(
|
|
7229
7476
|
machine:
|
|
7230
7477
|
& Machine<
|
|
@@ -7240,7 +7487,8 @@ export const start: <
|
|
|
7240
7487
|
Output,
|
|
7241
7488
|
Emits,
|
|
7242
7489
|
OutputStates,
|
|
7243
|
-
InputEvents
|
|
7490
|
+
InputEvents,
|
|
7491
|
+
ParentEvents
|
|
7244
7492
|
>
|
|
7245
7493
|
& EnsureExecutable<States, UnhandledStates, OutputStates>,
|
|
7246
7494
|
...args: [...Machine.InputArgs<Input>]
|
|
@@ -7253,7 +7501,8 @@ export const start: <
|
|
|
7253
7501
|
| InfiniteTransitionError
|
|
7254
7502
|
| MachineSchemaDecodeError
|
|
7255
7503
|
| StoppedError,
|
|
7256
|
-
Output
|
|
7504
|
+
Output,
|
|
7505
|
+
Machine.EmittedEventOf<Emits>
|
|
7257
7506
|
>,
|
|
7258
7507
|
| InitialE
|
|
7259
7508
|
| E
|
|
@@ -7267,7 +7516,7 @@ export const start: <
|
|
|
7267
7516
|
Machine.EventOf<Events>,
|
|
7268
7517
|
Machine.EmitOf<Emits>
|
|
7269
7518
|
>
|
|
7270
|
-
> = internal.start
|
|
7519
|
+
> = internal.start as any
|
|
7271
7520
|
|
|
7272
7521
|
/**
|
|
7273
7522
|
* Starts a fresh managed runtime from a decoded logical snapshot.
|
|
@@ -7303,7 +7552,7 @@ export const start: <
|
|
|
7303
7552
|
* const States = Machine.defineStates({ Idle })
|
|
7304
7553
|
* const machine = Machine.make({
|
|
7305
7554
|
* states: States.states,
|
|
7306
|
-
* events:
|
|
7555
|
+
* events: Machine.events(),
|
|
7307
7556
|
* initial: () => States.initial.Idle.from()
|
|
7308
7557
|
* }).handle({ Idle: {} })
|
|
7309
7558
|
*
|
|
@@ -7333,7 +7582,8 @@ export const resume: <
|
|
|
7333
7582
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
7334
7583
|
Output = never,
|
|
7335
7584
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
7336
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
|
|
7585
|
+
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
|
|
7586
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
7337
7587
|
>(
|
|
7338
7588
|
machine:
|
|
7339
7589
|
& Machine<
|
|
@@ -7349,7 +7599,8 @@ export const resume: <
|
|
|
7349
7599
|
Output,
|
|
7350
7600
|
Emits,
|
|
7351
7601
|
OutputStates,
|
|
7352
|
-
InputEvents
|
|
7602
|
+
InputEvents,
|
|
7603
|
+
ParentEvents
|
|
7353
7604
|
>
|
|
7354
7605
|
& EnsureExecutable<States, UnhandledStates, OutputStates>,
|
|
7355
7606
|
snapshot: Machine.Snapshot<States>
|
|
@@ -7362,7 +7613,8 @@ export const resume: <
|
|
|
7362
7613
|
| InfiniteTransitionError
|
|
7363
7614
|
| MachineSchemaDecodeError
|
|
7364
7615
|
| StoppedError,
|
|
7365
|
-
Output
|
|
7616
|
+
Output,
|
|
7617
|
+
Machine.EmittedEventOf<Emits>
|
|
7366
7618
|
>,
|
|
7367
7619
|
MachineSchemaDecodeError,
|
|
7368
7620
|
ExcludeCompatibleRuntime<
|
|
@@ -7370,4 +7622,4 @@ export const resume: <
|
|
|
7370
7622
|
Machine.EventOf<Events>,
|
|
7371
7623
|
Machine.EmitOf<Emits>
|
|
7372
7624
|
>
|
|
7373
|
-
> = internal.resume
|
|
7625
|
+
> = internal.resume as any
|