@typeonce/effect-machine 0.17.0 → 0.19.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 +133 -80
- package/dist/Machine.d.ts +434 -297
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +13 -55
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/cluster.d.ts +2 -2
- 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/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +1 -1
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +48 -10
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/serialization.d.ts.map +1 -1
- package/dist/internal/machine/serialization.js +75 -18
- package/dist/internal/machine/serialization.js.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +9 -6
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +13 -10
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +5 -3
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +22 -2
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +4 -0
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/docs/agent-guide.md +189 -83
- package/package.json +4 -4
- package/src/Machine.ts +845 -1051
- package/src/internal/machine/cluster.ts +4 -1
- package/src/internal/machine/invocation.ts +1 -1
- package/src/internal/machine/machine.ts +64 -8
- package/src/internal/machine/serialization.ts +100 -25
- package/src/internal/testing/machine/exploration.ts +1 -1
- package/src/internal/testing/machine/trace.ts +1 -1
- package/src/internal/testing/machine/verification.ts +16 -11
- package/src/testing/MachineTest.ts +13 -10
- package/src/unstable/cluster/ClusterMachine.ts +51 -1
- package/src/unstable/reactivity/AtomMachine.ts +1 -1
package/dist/Machine.d.ts
CHANGED
|
@@ -183,6 +183,20 @@ export interface Definition<States extends Machine.StateSchemas, Events extends
|
|
|
183
183
|
* captured by value, so later mutation of the supplied objects cannot alter
|
|
184
184
|
* the resulting machine.
|
|
185
185
|
*
|
|
186
|
+
* **Example**
|
|
187
|
+
*
|
|
188
|
+
* ```ts
|
|
189
|
+
* const counter = definition.handle({
|
|
190
|
+
* Count: {
|
|
191
|
+
* on: {
|
|
192
|
+
* Increment: (to) =>
|
|
193
|
+
* to.full.Count().resolve(({ event, state, target }) =>
|
|
194
|
+
* target(new Count({ value: state.value + event.by })))
|
|
195
|
+
* }
|
|
196
|
+
* }
|
|
197
|
+
* })
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
186
200
|
* @since 0.4.0
|
|
187
201
|
*/
|
|
188
202
|
readonly handle: Machine.Handler<States, Events, Emits, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, never, InputEvents, ParentEvents>;
|
|
@@ -384,8 +398,10 @@ export type MachineReferences<InputEvents extends ReadonlyArray<Machine.TaggedSc
|
|
|
384
398
|
} : {});
|
|
385
399
|
/**
|
|
386
400
|
* Synchronous commands available while a machine transition is being
|
|
387
|
-
* selected.
|
|
388
|
-
*
|
|
401
|
+
* selected.
|
|
402
|
+
*
|
|
403
|
+
* Enqueuing records statechart and machine operations for the selected
|
|
404
|
+
* transition. It never executes an Effect while the transition is evaluated.
|
|
389
405
|
*
|
|
390
406
|
* @category models
|
|
391
407
|
* @since 0.4.0
|
|
@@ -474,6 +490,7 @@ type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Run
|
|
|
474
490
|
declare const InvokeTypeId: typeof internal.InvokeTypeId;
|
|
475
491
|
declare const TransitionTypeId: typeof internal.TransitionTypeId;
|
|
476
492
|
declare const TransitionBuilderTypeId: unique symbol;
|
|
493
|
+
declare const InvokeBuilderTypeId: unique symbol;
|
|
477
494
|
declare const InitialBuilderTypeId: unique symbol;
|
|
478
495
|
type StateDefinitionError<Message extends string, Path extends PropertyKey = never, Details extends PropertyKey = never> = {
|
|
479
496
|
readonly "~effect/Machine/DefinitionError": Message;
|
|
@@ -924,6 +941,9 @@ export type RuntimeSnapshot<State, Error = never, Output = never> = {
|
|
|
924
941
|
* one stream may contain unrelated root, child-machine, and `Logic` protocols.
|
|
925
942
|
* The record structure remains a closed discriminated union, while typed
|
|
926
943
|
* application observation continues through `changes` and `emissions`.
|
|
944
|
+
* Records retain decoded local events and snapshots and are not themselves a
|
|
945
|
+
* stable JSON export format. Telemetry exporters must project process-local
|
|
946
|
+
* values into an explicit portable representation.
|
|
927
947
|
*
|
|
928
948
|
* @category models
|
|
929
949
|
* @since 0.13.0
|
|
@@ -1198,7 +1218,7 @@ export interface MachineRef<out State, in Event, out Error = never, out Output =
|
|
|
1198
1218
|
readonly childChanges: <Child extends ChildMachine.Any>(child: Child) => Stream.Stream<Option.Option<ChildMachine.Ref<Child>>>;
|
|
1199
1219
|
}
|
|
1200
1220
|
/**
|
|
1201
|
-
* Machine-specific process logic used by `spawn` and
|
|
1221
|
+
* Machine-specific process logic used by `spawn` and state-owned invocations.
|
|
1202
1222
|
*
|
|
1203
1223
|
* @category models
|
|
1204
1224
|
* @since 0.4.0
|
|
@@ -1504,12 +1524,22 @@ export declare namespace Machine {
|
|
|
1504
1524
|
*/
|
|
1505
1525
|
type Events<M extends Any> = M[typeof MachineTypeId]["events"];
|
|
1506
1526
|
/**
|
|
1507
|
-
* Extracts the input schema carried by a machine definition.
|
|
1527
|
+
* Extracts the startup input schema carried by a machine definition.
|
|
1508
1528
|
*
|
|
1509
1529
|
* @category utility types
|
|
1510
|
-
* @since 0.
|
|
1530
|
+
* @since 0.18.0
|
|
1531
|
+
*/
|
|
1532
|
+
type InputSchema<M extends Any> = M[typeof MachineTypeId]["input"];
|
|
1533
|
+
/**
|
|
1534
|
+
* Extracts the decoded startup input accepted by a machine definition.
|
|
1535
|
+
*
|
|
1536
|
+
* Machines declared with `Schema.Void` do not accept a startup input, so
|
|
1537
|
+
* their extracted input type is `never`.
|
|
1538
|
+
*
|
|
1539
|
+
* @category utility types
|
|
1540
|
+
* @since 0.18.0
|
|
1511
1541
|
*/
|
|
1512
|
-
type Input<M extends Any> = M
|
|
1542
|
+
type Input<M extends Any> = InputSchema<M> extends infer Input extends Schema.Top ? Input extends typeof Schema.Void ? never : Input["Type"] : never;
|
|
1513
1543
|
/**
|
|
1514
1544
|
* Extracts state paths that do not yet have handlers.
|
|
1515
1545
|
*
|
|
@@ -1724,8 +1754,11 @@ export declare namespace Machine {
|
|
|
1724
1754
|
* @since 0.4.0
|
|
1725
1755
|
*/
|
|
1726
1756
|
interface StateNodeAnnotations extends Schema.Annotations.Annotations {
|
|
1757
|
+
/** Human-readable label used by visualization and documentation tooling. */
|
|
1727
1758
|
readonly title?: string | undefined;
|
|
1759
|
+
/** Short explanation of the state node's domain meaning. */
|
|
1728
1760
|
readonly description?: string | undefined;
|
|
1761
|
+
/** Longer documentation text associated with the state node. */
|
|
1729
1762
|
readonly documentation?: string | undefined;
|
|
1730
1763
|
}
|
|
1731
1764
|
/** Descriptive annotations accepted by schema-less active and pseudo-states. */
|
|
@@ -1733,31 +1766,41 @@ export declare namespace Machine {
|
|
|
1733
1766
|
/** @deprecated Use {@link SchemaLessStateAnnotations}. */
|
|
1734
1767
|
type PseudoStateAnnotations = SchemaLessStateAnnotations;
|
|
1735
1768
|
/**
|
|
1736
|
-
* Configuration accepted for an atomic object state node.
|
|
1737
|
-
*
|
|
1769
|
+
* Configuration accepted for an atomic object state node.
|
|
1770
|
+
*
|
|
1771
|
+
* Omit `schema` when the state owns no value. A schema-less final may still
|
|
1772
|
+
* declare `output`.
|
|
1738
1773
|
*
|
|
1739
1774
|
* @category models
|
|
1740
1775
|
* @since 0.4.0
|
|
1741
1776
|
*/
|
|
1742
1777
|
type AtomicStateNodeConfig = {
|
|
1778
|
+
/** Tagged schema that owns the state's decoded value. */
|
|
1743
1779
|
readonly schema: TaggedSchema;
|
|
1780
|
+
/** Declares an ordinary active state. Omitted values default to `"active"`. */
|
|
1744
1781
|
readonly type?: "active";
|
|
1782
|
+
/** Atomic active states cannot declare terminal output. */
|
|
1745
1783
|
readonly output?: never;
|
|
1784
|
+
/** Schema-backed states take their annotations from the schema. */
|
|
1746
1785
|
readonly annotations?: never;
|
|
1747
1786
|
} | {
|
|
1748
1787
|
readonly schema: TaggedSchema;
|
|
1749
1788
|
readonly type: "final";
|
|
1789
|
+
/** Optional schema describing the terminal value produced by this final state. */
|
|
1750
1790
|
readonly output?: Schema.Top;
|
|
1751
1791
|
readonly annotations?: never;
|
|
1752
1792
|
} | {
|
|
1753
1793
|
readonly schema?: never;
|
|
1754
1794
|
readonly type?: "active";
|
|
1755
1795
|
readonly output?: never;
|
|
1796
|
+
/** Descriptive metadata for a schema-less state. */
|
|
1756
1797
|
readonly annotations?: SchemaLessStateAnnotations;
|
|
1757
1798
|
} | {
|
|
1758
1799
|
readonly schema?: never;
|
|
1759
1800
|
readonly type: "final";
|
|
1801
|
+
/** Optional schema describing the terminal value produced by this final state. */
|
|
1760
1802
|
readonly output?: Schema.Top;
|
|
1803
|
+
/** Descriptive metadata for a schema-less state. */
|
|
1761
1804
|
readonly annotations?: SchemaLessStateAnnotations;
|
|
1762
1805
|
};
|
|
1763
1806
|
/**
|
|
@@ -1768,16 +1811,22 @@ export declare namespace Machine {
|
|
|
1768
1811
|
* @since 0.4.0
|
|
1769
1812
|
*/
|
|
1770
1813
|
type CompoundStateNodeConfig = {
|
|
1814
|
+
/** Tagged schema that owns the compound state's decoded value. */
|
|
1771
1815
|
readonly schema: TaggedSchema;
|
|
1816
|
+
/** Compound states are ordinary active states. */
|
|
1772
1817
|
readonly type?: "active";
|
|
1818
|
+
/** Direct child selected when the compound state is entered initially. */
|
|
1773
1819
|
readonly initial: string;
|
|
1820
|
+
/** Nested state nodes owned by this compound state. */
|
|
1774
1821
|
readonly states: StateTree;
|
|
1822
|
+
/** Schema-backed states take their annotations from the schema. */
|
|
1775
1823
|
readonly annotations?: never;
|
|
1776
1824
|
} | {
|
|
1777
1825
|
readonly schema?: never;
|
|
1778
1826
|
readonly type?: "active";
|
|
1779
1827
|
readonly initial: string;
|
|
1780
1828
|
readonly states: StateTree;
|
|
1829
|
+
/** Descriptive metadata for a schema-less state. */
|
|
1781
1830
|
readonly annotations?: SchemaLessStateAnnotations;
|
|
1782
1831
|
};
|
|
1783
1832
|
/**
|
|
@@ -1788,16 +1837,22 @@ export declare namespace Machine {
|
|
|
1788
1837
|
* @since 0.4.0
|
|
1789
1838
|
*/
|
|
1790
1839
|
type ParallelStateNodeConfig = {
|
|
1840
|
+
/** Tagged schema that owns the parallel state's decoded value. */
|
|
1791
1841
|
readonly schema: TaggedSchema;
|
|
1842
|
+
/** Selects parallel-region semantics for the node. */
|
|
1792
1843
|
readonly type: "parallel";
|
|
1844
|
+
/** Optional schema describing the value produced after every region completes. */
|
|
1793
1845
|
readonly output?: Schema.Top;
|
|
1846
|
+
/** Child regions that are entered and remain active simultaneously. */
|
|
1794
1847
|
readonly states: StateTree;
|
|
1848
|
+
/** Schema-backed states take their annotations from the schema. */
|
|
1795
1849
|
readonly annotations?: never;
|
|
1796
1850
|
} | {
|
|
1797
1851
|
readonly schema?: never;
|
|
1798
1852
|
readonly type: "parallel";
|
|
1799
1853
|
readonly output?: Schema.Top;
|
|
1800
1854
|
readonly states: StateTree;
|
|
1855
|
+
/** Descriptive metadata for a schema-less state. */
|
|
1801
1856
|
readonly annotations?: SchemaLessStateAnnotations;
|
|
1802
1857
|
};
|
|
1803
1858
|
/**
|
|
@@ -1813,9 +1868,16 @@ export declare namespace Machine {
|
|
|
1813
1868
|
* @since 0.4.0
|
|
1814
1869
|
*/
|
|
1815
1870
|
interface HistoryStateNodeConfig {
|
|
1871
|
+
/** Selects history pseudo-state semantics. */
|
|
1816
1872
|
readonly type: "history";
|
|
1817
|
-
/**
|
|
1873
|
+
/**
|
|
1874
|
+
* Restores only the direct child for shallow history or the complete
|
|
1875
|
+
* descendant configuration for deep history.
|
|
1876
|
+
*
|
|
1877
|
+
* @defaultValue `"shallow"`
|
|
1878
|
+
*/
|
|
1818
1879
|
readonly history?: "shallow" | "deep";
|
|
1880
|
+
/** Descriptive metadata used by visualization and documentation tooling. */
|
|
1819
1881
|
readonly annotations?: SchemaLessStateAnnotations;
|
|
1820
1882
|
}
|
|
1821
1883
|
/**
|
|
@@ -1829,7 +1891,9 @@ export declare namespace Machine {
|
|
|
1829
1891
|
* @since 0.4.0
|
|
1830
1892
|
*/
|
|
1831
1893
|
interface ChoiceStateNodeConfig {
|
|
1894
|
+
/** Selects transient choice pseudo-state semantics. */
|
|
1832
1895
|
readonly type: "choice";
|
|
1896
|
+
/** Descriptive metadata used by visualization and documentation tooling. */
|
|
1833
1897
|
readonly annotations?: SchemaLessStateAnnotations;
|
|
1834
1898
|
}
|
|
1835
1899
|
/**
|
|
@@ -2456,33 +2520,36 @@ export declare namespace Machine {
|
|
|
2456
2520
|
*/
|
|
2457
2521
|
interface EncodedSnapshotState {
|
|
2458
2522
|
readonly path: string;
|
|
2459
|
-
readonly value?:
|
|
2523
|
+
readonly value?: Schema.Json;
|
|
2460
2524
|
}
|
|
2461
2525
|
/**
|
|
2462
2526
|
* Encoded output for one completed state path in a normalized machine
|
|
2463
|
-
* snapshot. An omitted output
|
|
2527
|
+
* snapshot. An omitted output means the final state declares no output
|
|
2528
|
+
* schema; a declared `Schema.Void` or `Schema.Undefined` output encodes as
|
|
2529
|
+
* canonical JSON `null`.
|
|
2464
2530
|
*
|
|
2465
2531
|
* @category models
|
|
2466
2532
|
* @since 0.4.0
|
|
2467
2533
|
*/
|
|
2468
2534
|
interface EncodedSnapshotCompletion {
|
|
2469
2535
|
readonly path: string;
|
|
2470
|
-
readonly output?:
|
|
2536
|
+
readonly output?: Schema.Json;
|
|
2471
2537
|
}
|
|
2472
2538
|
/** Encoded values and paths retained by one history pseudo-state. */
|
|
2473
2539
|
interface EncodedSnapshotHistoryEntry {
|
|
2474
2540
|
readonly mode: "shallow" | "deep";
|
|
2475
2541
|
readonly active: ReadonlyArray<string>;
|
|
2476
|
-
readonly values: Readonly<Record<string,
|
|
2542
|
+
readonly values: Readonly<Record<string, Schema.Json>>;
|
|
2477
2543
|
}
|
|
2478
2544
|
/**
|
|
2479
2545
|
* Normalized data representation of a machine snapshot.
|
|
2480
2546
|
*
|
|
2481
2547
|
* **Details**
|
|
2482
2548
|
*
|
|
2483
|
-
* Active state and completion values use the
|
|
2484
|
-
* their declared schemas.
|
|
2485
|
-
*
|
|
2549
|
+
* Active state and completion values use the canonical JSON representations
|
|
2550
|
+
* derived from their declared schemas. A successfully encoded snapshot is
|
|
2551
|
+
* safe to pass to JSON-backed persistence and transport. Runtime process state
|
|
2552
|
+
* such as children, fibers, scopes, queues, and subscriptions is not included.
|
|
2486
2553
|
*
|
|
2487
2554
|
* @category models
|
|
2488
2555
|
* @since 0.4.0
|
|
@@ -2918,15 +2985,23 @@ export declare namespace Machine {
|
|
|
2918
2985
|
};
|
|
2919
2986
|
/**
|
|
2920
2987
|
* Definition-time topology selector available to an ordinary transition.
|
|
2988
|
+
*
|
|
2921
2989
|
* Topology-only instructions (`none`, declared `initial` and history
|
|
2922
|
-
* selections, and `local.with`) are values.
|
|
2923
|
-
*
|
|
2990
|
+
* selections, and `local.with`) are values.
|
|
2991
|
+
*
|
|
2992
|
+
* State and choice destinations remain callable selection methods so their
|
|
2993
|
+
* target-specific resolver APIs retain exact inference.
|
|
2924
2994
|
*/
|
|
2925
2995
|
interface TargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> {
|
|
2996
|
+
/** Handles the trigger without selecting a destination. */
|
|
2926
2997
|
readonly none: SelectionValue<TargetBuilder<States, Source>["none"], never, "none">;
|
|
2998
|
+
/** Selects a destination inside the nearest active compound scope. */
|
|
2927
2999
|
readonly local: LocalTargetSelector<States, Source>;
|
|
3000
|
+
/** Selects a destination elsewhere under the currently active root. */
|
|
2928
3001
|
readonly branch: BranchTargetSelector<States, Source>;
|
|
3002
|
+
/** Selects a complete destination under any top-level state. */
|
|
2929
3003
|
readonly full: FullTargetSelector<States>;
|
|
3004
|
+
/** Restores a shallow or deep history pseudo-state. */
|
|
2930
3005
|
readonly history: HistorySelectionTree<States, States, "", HistoryTargetBuilder<States>>;
|
|
2931
3006
|
}
|
|
2932
3007
|
/** Definition-time selector that can choose only a valid top-level initial entry. */
|
|
@@ -2944,11 +3019,15 @@ export declare namespace Machine {
|
|
|
2944
3019
|
* @since 0.4.0
|
|
2945
3020
|
*/
|
|
2946
3021
|
type HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3022
|
+
/** Value owned by the state whose handler is running. */
|
|
2947
3023
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3024
|
+
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
2948
3025
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3026
|
+
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
2949
3027
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
2950
3028
|
/** Complete logical configuration captured at the start of this microstep. */
|
|
2951
3029
|
readonly snapshot: Snapshot<States>;
|
|
3030
|
+
/** Event that selected this handler, narrowed by its `_tag`. */
|
|
2952
3031
|
readonly event: EventByTag<Events, EventTag>;
|
|
2953
3032
|
/**
|
|
2954
3033
|
* Provides typed builders for choosing the next active state from this
|
|
@@ -2965,9 +3044,13 @@ export declare namespace Machine {
|
|
|
2965
3044
|
* @since 0.4.0
|
|
2966
3045
|
*/
|
|
2967
3046
|
type StateActionContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3047
|
+
/** Value owned by the state entering or exiting. */
|
|
2968
3048
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3049
|
+
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
2969
3050
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3051
|
+
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
2970
3052
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3053
|
+
/** Event or initial-entry marker responsible for the lifecycle action. */
|
|
2971
3054
|
readonly event: LifecycleEvent<Events>;
|
|
2972
3055
|
};
|
|
2973
3056
|
/**
|
|
@@ -2977,9 +3060,13 @@ export declare namespace Machine {
|
|
|
2977
3060
|
* @since 0.4.0
|
|
2978
3061
|
*/
|
|
2979
3062
|
type InvokeContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3063
|
+
/** Value owned by the state that owns this invocation. */
|
|
2980
3064
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3065
|
+
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
2981
3066
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3067
|
+
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
2982
3068
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3069
|
+
/** Event or initial-entry marker responsible for starting the invocation. */
|
|
2983
3070
|
readonly event: LifecycleEvent<Events>;
|
|
2984
3071
|
};
|
|
2985
3072
|
/**
|
|
@@ -2989,11 +3076,17 @@ export declare namespace Machine {
|
|
|
2989
3076
|
* @since 0.4.0
|
|
2990
3077
|
*/
|
|
2991
3078
|
type InvokeSnapshotContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, State, Error, Output, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3079
|
+
/** Parent-local invocation identifier. */
|
|
2992
3080
|
readonly id: string;
|
|
3081
|
+
/** Current value of the state that owns the invocation. */
|
|
2993
3082
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3083
|
+
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
2994
3084
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3085
|
+
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
2995
3086
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3087
|
+
/** Builders for selecting the owning machine's next state. */
|
|
2996
3088
|
readonly target: TargetBuilder<States, StateId>;
|
|
3089
|
+
/** Latest active lifecycle snapshot published by the invoked logic or child. */
|
|
2997
3090
|
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, {
|
|
2998
3091
|
readonly status: "active";
|
|
2999
3092
|
}>;
|
|
@@ -3005,32 +3098,53 @@ export declare namespace Machine {
|
|
|
3005
3098
|
* @since 0.4.0
|
|
3006
3099
|
*/
|
|
3007
3100
|
type InvokeDoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Output, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3101
|
+
/** Parent-local invocation identifier. */
|
|
3008
3102
|
readonly id: string;
|
|
3103
|
+
/** Current value of the state that owns the invocation. */
|
|
3009
3104
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3105
|
+
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
3010
3106
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3107
|
+
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
3011
3108
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3109
|
+
/** Complete owning-machine configuration captured for this transition. */
|
|
3012
3110
|
readonly snapshot: Snapshot<States>;
|
|
3111
|
+
/** Builders for selecting the owning machine's next state. */
|
|
3013
3112
|
readonly target: TargetBuilder<States, StateId>;
|
|
3113
|
+
/** Successful output produced by the invocation. */
|
|
3014
3114
|
readonly output: Output;
|
|
3015
3115
|
};
|
|
3016
3116
|
/** Context passed to a Stream invocation's element transition. */
|
|
3017
3117
|
type InvokeElementContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Element, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3118
|
+
/** Parent-local invocation identifier. */
|
|
3018
3119
|
readonly id: string;
|
|
3120
|
+
/** Current value of the state that owns the Stream invocation. */
|
|
3019
3121
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3122
|
+
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
3020
3123
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3124
|
+
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
3021
3125
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3126
|
+
/** Complete owning-machine configuration captured for this transition. */
|
|
3022
3127
|
readonly snapshot: Snapshot<States>;
|
|
3128
|
+
/** Builders for selecting the owning machine's next state. */
|
|
3023
3129
|
readonly target: TargetBuilder<States, StateId>;
|
|
3130
|
+
/** Next element emitted by the invoked Stream. */
|
|
3024
3131
|
readonly element: Element;
|
|
3025
3132
|
};
|
|
3026
3133
|
/** Context passed to an invocation typed-failure transition. */
|
|
3027
3134
|
type InvokeFailureContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Error, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3135
|
+
/** Parent-local invocation identifier. */
|
|
3028
3136
|
readonly id: string;
|
|
3137
|
+
/** Current value of the state that owns the invocation. */
|
|
3029
3138
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3139
|
+
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
3030
3140
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3141
|
+
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
3031
3142
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3143
|
+
/** Complete owning-machine configuration captured for this transition. */
|
|
3032
3144
|
readonly snapshot: Snapshot<States>;
|
|
3145
|
+
/** Builders for selecting the owning machine's next state. */
|
|
3033
3146
|
readonly target: TargetBuilder<States, StateId>;
|
|
3147
|
+
/** Typed failure produced by the invocation. */
|
|
3034
3148
|
readonly error: Error;
|
|
3035
3149
|
};
|
|
3036
3150
|
/**
|
|
@@ -3040,11 +3154,15 @@ export declare namespace Machine {
|
|
|
3040
3154
|
* @since 0.4.0
|
|
3041
3155
|
*/
|
|
3042
3156
|
type AlwaysContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3157
|
+
/** Current value of the state evaluating the eventless transition. */
|
|
3043
3158
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3159
|
+
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
3044
3160
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3161
|
+
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
3045
3162
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3046
3163
|
/** Complete logical configuration captured at the start of this microstep. */
|
|
3047
3164
|
readonly snapshot: Snapshot<States>;
|
|
3165
|
+
/** Lifecycle event retained while the eventless transition is evaluated. */
|
|
3048
3166
|
readonly event: LifecycleEvent<Events>;
|
|
3049
3167
|
/**
|
|
3050
3168
|
* Provides typed builders for choosing the next active state from this
|
|
@@ -3062,12 +3180,17 @@ export declare namespace Machine {
|
|
|
3062
3180
|
* @since 0.4.0
|
|
3063
3181
|
*/
|
|
3064
3182
|
type DoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3183
|
+
/** Current value of the state whose child configuration completed. */
|
|
3065
3184
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3185
|
+
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
3066
3186
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3187
|
+
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
3067
3188
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3068
3189
|
/** Complete logical configuration captured at the start of this microstep. */
|
|
3069
3190
|
readonly snapshot: Snapshot<States>;
|
|
3191
|
+
/** Lifecycle event retained while state completion is processed. */
|
|
3070
3192
|
readonly event: LifecycleEvent<Events>;
|
|
3193
|
+
/** Output produced by the completed final child or parallel regions. */
|
|
3071
3194
|
readonly output: CompletionOutputByIdentifier<States, StateId>;
|
|
3072
3195
|
/**
|
|
3073
3196
|
* Provides typed builders for choosing the next active state after this
|
|
@@ -3080,11 +3203,15 @@ export declare namespace Machine {
|
|
|
3080
3203
|
};
|
|
3081
3204
|
/** Context passed to a transient choice resolver. There is no `state` value. */
|
|
3082
3205
|
type ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3206
|
+
/** Value owned by the choice node's immediate schema-backed parent. */
|
|
3083
3207
|
readonly containingState: StateByIdentifier<States, Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>>;
|
|
3208
|
+
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
3084
3209
|
readonly ancestors: {
|
|
3085
3210
|
readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, ValuedStateIdentifier<States>>]: StateByIdentifier<States, Parent>;
|
|
3086
3211
|
};
|
|
3212
|
+
/** Lifecycle event that led to the transient choice. */
|
|
3087
3213
|
readonly event: LifecycleEvent<Events>;
|
|
3214
|
+
/** Builders for selecting the concrete destination of this choice. */
|
|
3088
3215
|
readonly target: TargetBuilder<States, ChoiceId>;
|
|
3089
3216
|
};
|
|
3090
3217
|
/**
|
|
@@ -3094,9 +3221,13 @@ export declare namespace Machine {
|
|
|
3094
3221
|
* @since 0.4.0
|
|
3095
3222
|
*/
|
|
3096
3223
|
interface FinalOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
3224
|
+
/** Decoded value owned by the final state. */
|
|
3097
3225
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3226
|
+
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
3098
3227
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3228
|
+
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
3099
3229
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3230
|
+
/** Lifecycle event responsible for entering the final state. */
|
|
3100
3231
|
readonly event: LifecycleEvent<Events>;
|
|
3101
3232
|
}
|
|
3102
3233
|
/**
|
|
@@ -3118,10 +3249,15 @@ export declare namespace Machine {
|
|
|
3118
3249
|
* @since 0.4.0
|
|
3119
3250
|
*/
|
|
3120
3251
|
interface ParallelOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
3252
|
+
/** Decoded value owned by the completed parallel state. */
|
|
3121
3253
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3254
|
+
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
3122
3255
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3256
|
+
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
3123
3257
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3258
|
+
/** Lifecycle event retained while parallel completion is processed. */
|
|
3124
3259
|
readonly event: LifecycleEvent<Events>;
|
|
3260
|
+
/** Completion output from every direct parallel region. */
|
|
3125
3261
|
readonly outputs: ParallelOutputRegions<States, StateId>;
|
|
3126
3262
|
}
|
|
3127
3263
|
/**
|
|
@@ -3325,6 +3461,10 @@ export declare namespace Machine {
|
|
|
3325
3461
|
} ? EventOf<ParentEvents<M>> : never;
|
|
3326
3462
|
/** Extracts transition results returned by invocation lifecycle handlers. */
|
|
3327
3463
|
type InvokeOutcomeReturn<Invoke> = Invoke extends unknown ? (Invoke extends {
|
|
3464
|
+
readonly [InvokeTypeId]: {
|
|
3465
|
+
readonly outcomes: Types.Covariant<infer Outcomes>;
|
|
3466
|
+
};
|
|
3467
|
+
} ? EventTransitionReturn<Outcomes> : never) | (Invoke extends {
|
|
3328
3468
|
readonly onDone?: infer Handler;
|
|
3329
3469
|
} ? EventTransitionReturn<NonNullable<Handler>> : never) | (Invoke extends {
|
|
3330
3470
|
readonly onFailure?: infer Handler;
|
|
@@ -3333,20 +3473,22 @@ export declare namespace Machine {
|
|
|
3333
3473
|
} ? EventTransitionReturn<NonNullable<Handler>> : never) | (Invoke extends {
|
|
3334
3474
|
readonly onSnapshot?: infer Handler;
|
|
3335
3475
|
} ? EventTransitionReturn<NonNullable<Handler>> : never) : never;
|
|
3476
|
+
type InvokeOutcomeError<Invoke> = IsAny<InvokeOutcomeReturn<Invoke>> extends true ? never : Effect.Error<InvokeOutcomeReturn<Invoke>>;
|
|
3477
|
+
type InvokeOutcomeServices<Invoke> = IsAny<InvokeOutcomeReturn<Invoke>> extends true ? never : Effect.Services<InvokeOutcomeReturn<Invoke>>;
|
|
3336
3478
|
/**
|
|
3337
3479
|
* Extracts the parent transition error contribution from invoked children.
|
|
3338
3480
|
*
|
|
3339
3481
|
* @category utility types
|
|
3340
3482
|
* @since 0.4.0
|
|
3341
3483
|
*/
|
|
3342
|
-
type InvokeError<Config> = [InvokeReturn<Config>] extends [never] ? never : ChildAlreadyExistsError | InvokeInitialError<InvokeReturn<Config>> |
|
|
3484
|
+
type InvokeError<Config> = [InvokeReturn<Config>] extends [never] ? never : ChildAlreadyExistsError | InvokeInitialError<InvokeReturn<Config>> | InvokeOutcomeError<InvokeReturn<Config>>;
|
|
3343
3485
|
/**
|
|
3344
3486
|
* Extracts the parent service requirement contribution from invoked children.
|
|
3345
3487
|
*
|
|
3346
3488
|
* @category utility types
|
|
3347
3489
|
* @since 0.4.0
|
|
3348
3490
|
*/
|
|
3349
|
-
type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never : MachineRuntimeRequirement | InvokeServices<InvokeReturn<Config>> |
|
|
3491
|
+
type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never : MachineRuntimeRequirement | InvokeServices<InvokeReturn<Config>> | InvokeOutcomeServices<InvokeReturn<Config>>;
|
|
3350
3492
|
/**
|
|
3351
3493
|
* Extracts the return value from an eventless transition.
|
|
3352
3494
|
*
|
|
@@ -3405,13 +3547,16 @@ export declare namespace Machine {
|
|
|
3405
3547
|
});
|
|
3406
3548
|
/** Context capability available only to explicitly declinable resolvers. */
|
|
3407
3549
|
interface DeclineCapability {
|
|
3550
|
+
/** Declines this candidate and continues hierarchical transition selection. */
|
|
3408
3551
|
readonly decline: () => Declined;
|
|
3409
3552
|
}
|
|
3410
3553
|
type TransitionResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Selection> = (context: TransitionResolveContext<Context, Selection>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined;
|
|
3411
3554
|
type DeclinableTransitionResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Selection> = (context: TransitionResolveContext<Context, Selection> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined) | Declined;
|
|
3412
3555
|
/** One named destination declared by a branching transition. */
|
|
3413
3556
|
interface TransitionBranchInput<Selection extends TargetSelection<any, any, any> = TargetSelection<any, any, any>> {
|
|
3557
|
+
/** Exact topology destination available to the branching resolver. */
|
|
3414
3558
|
readonly target: Selection;
|
|
3559
|
+
/** Optional human-readable branch label used by visualization tooling. */
|
|
3415
3560
|
readonly title?: string;
|
|
3416
3561
|
}
|
|
3417
3562
|
/** Opaque evidence that a branching resolver selected one declared branch. */
|
|
@@ -3452,14 +3597,17 @@ export declare namespace Machine {
|
|
|
3452
3597
|
};
|
|
3453
3598
|
}
|
|
3454
3599
|
type TransitionReenterOption<Reenter extends boolean> = [Reenter] extends [true] ? {
|
|
3600
|
+
/** Forces the source state to exit and enter even when active paths remain unchanged. */
|
|
3455
3601
|
readonly reenter?: boolean;
|
|
3456
3602
|
} : {
|
|
3457
3603
|
readonly reenter?: never;
|
|
3458
3604
|
};
|
|
3459
3605
|
type TransitionRequiredOptions<Reenter extends boolean> = TransitionReenterOption<Reenter> & {
|
|
3606
|
+
/** Keeps the transition required. The resolver cannot return `decline()`. */
|
|
3460
3607
|
readonly declinable?: false;
|
|
3461
3608
|
};
|
|
3462
3609
|
type TransitionDeclinableOptions<Reenter extends boolean> = TransitionReenterOption<Reenter> & {
|
|
3610
|
+
/** Adds `decline()` to the resolver context and permits declining this candidate. */
|
|
3463
3611
|
readonly declinable: true;
|
|
3464
3612
|
};
|
|
3465
3613
|
type BuiltTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Result, Acceptance extends TransitionAcceptance> = TransitionTyped<States, Events, Emits, StateId, Context, Reenter, Acceptance> & TransitionBuilderEvidence<Result, Acceptance>;
|
|
@@ -3469,10 +3617,31 @@ export declare namespace Machine {
|
|
|
3469
3617
|
interface TransitionResolveDeclinable<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, any>> {
|
|
3470
3618
|
(resolve: DeclinableTransitionResolver<Events, Emits, Context, Selection>, options: TransitionDeclinableOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined) | Declined, "declinable">;
|
|
3471
3619
|
}
|
|
3472
|
-
/**
|
|
3620
|
+
/**
|
|
3621
|
+
* A selected transition target with target-specific resolver operations.
|
|
3622
|
+
*
|
|
3623
|
+
* **Example** (Updating state while reentering)
|
|
3624
|
+
*
|
|
3625
|
+
* ```ts
|
|
3626
|
+
* Reset: (to) =>
|
|
3627
|
+
* to.full.Ready().resolve(
|
|
3628
|
+
* ({ target }) => target.from(),
|
|
3629
|
+
* { reenter: true }
|
|
3630
|
+
* )
|
|
3631
|
+
* ```
|
|
3632
|
+
*
|
|
3633
|
+
* @inlineType TransitionRequiredOptions
|
|
3634
|
+
* @inlineType TransitionDeclinableOptions
|
|
3635
|
+
* @inlineType TransitionReenterOption
|
|
3636
|
+
*/
|
|
3473
3637
|
type TransitionTarget<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Selection extends TargetSelection<any, any, any>> = Selection & (SelectionSupportsDefaultConstruction<Selection> extends true ? BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required"> : {}) & {
|
|
3638
|
+
/**
|
|
3639
|
+
* Evaluates state construction and queued commands only after this
|
|
3640
|
+
* transition has been selected.
|
|
3641
|
+
*/
|
|
3474
3642
|
readonly resolve: TransitionResolveRequired<States, Events, Emits, StateId, Context, Reenter, Selection> & ("declinable" extends Acceptance ? TransitionResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Selection> : {});
|
|
3475
3643
|
} & ([Reenter] extends [true] ? SelectionSupportsDefaultConstruction<Selection> extends true ? {
|
|
3644
|
+
/** Reenters the source using the selected target's default construction. */
|
|
3476
3645
|
readonly reenter: () => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required">;
|
|
3477
3646
|
} : {} : {});
|
|
3478
3647
|
/** @internal Type evidence retained by a machine initial-entry declaration. */
|
|
@@ -3481,8 +3650,11 @@ export declare namespace Machine {
|
|
|
3481
3650
|
}
|
|
3482
3651
|
/** A selected machine initial entry with its exact resolver target. */
|
|
3483
3652
|
type InitialTransitionTarget<Input, Selection extends TargetSelection<any, any, any>> = Selection & (SelectionSupportsDefaultConstruction<Selection> extends true ? InitialBuilderEvidence<Selection> : {}) & {
|
|
3653
|
+
/** Lazily constructs the selected initial state from decoded machine input. */
|
|
3484
3654
|
readonly resolve: (resolve: (context: {
|
|
3655
|
+
/** Decoded value supplied when the machine is started. */
|
|
3485
3656
|
readonly input: Input;
|
|
3657
|
+
/** Builder specialized to the selected initial destination. */
|
|
3486
3658
|
readonly target: SelectionBuilder<Selection>;
|
|
3487
3659
|
}) => SelectedTargetResult<Selection>) => InitialBuilderEvidence<Selection>;
|
|
3488
3660
|
};
|
|
@@ -3508,7 +3680,9 @@ export declare namespace Machine {
|
|
|
3508
3680
|
}
|
|
3509
3681
|
/** Selector supplied to inline transition declarations. */
|
|
3510
3682
|
type TransitionSelector<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance> = TransitionSelectorNode<States, Events, Emits, StateId, Context, Reenter, Acceptance, TargetSelector<States, StateId>> & {
|
|
3683
|
+
/** Declares a closed set of named destinations for one resolver. */
|
|
3511
3684
|
readonly branches: <const Branches extends Readonly<Record<string, TransitionBranchInput>>>(branches: Branches & ValidateTransitionBranchRecord<NoInfer<Branches>>) => {
|
|
3685
|
+
/** Resolves exactly one declared branch after this transition is selected. */
|
|
3512
3686
|
readonly resolve: TransitionBranchesResolveRequired<States, Events, Emits, StateId, Context, Reenter, Branches> & ("declinable" extends Acceptance ? TransitionBranchesResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Branches> : {});
|
|
3513
3687
|
};
|
|
3514
3688
|
};
|
|
@@ -3520,8 +3694,8 @@ export declare namespace Machine {
|
|
|
3520
3694
|
interface InvokeOwned<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
|
|
3521
3695
|
readonly "~effect/Machine/InvokeOwner"?: Types.Covariant<readonly [States, Events, Emits, StateId, InputEvents, ParentEvents]>;
|
|
3522
3696
|
}
|
|
3523
|
-
/** Type evidence retained by
|
|
3524
|
-
interface InvokeTyped<Output, Error, Requirements, InitialError, Emits = never, ParentEvent = never> {
|
|
3697
|
+
/** Type evidence retained by a completed state-owned invocation. */
|
|
3698
|
+
interface InvokeTyped<Output, Error, Requirements, InitialError, Emits = never, ParentEvent = never, Outcomes = never> {
|
|
3525
3699
|
readonly [InvokeTypeId]: {
|
|
3526
3700
|
readonly output: Types.Covariant<Output>;
|
|
3527
3701
|
readonly error: Types.Covariant<Error>;
|
|
@@ -3529,9 +3703,10 @@ export declare namespace Machine {
|
|
|
3529
3703
|
readonly initialError: Types.Covariant<InitialError>;
|
|
3530
3704
|
readonly emits: Types.Covariant<Emits>;
|
|
3531
3705
|
readonly parentEvents: Types.Covariant<ParentEvent>;
|
|
3706
|
+
readonly outcomes: Types.Covariant<Outcomes>;
|
|
3532
3707
|
};
|
|
3533
3708
|
}
|
|
3534
|
-
type
|
|
3709
|
+
type StoredInvokeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & ({
|
|
3535
3710
|
readonly id: string;
|
|
3536
3711
|
readonly effect: (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<any, any, any>;
|
|
3537
3712
|
readonly stream?: never;
|
|
@@ -3593,76 +3768,7 @@ export declare namespace Machine {
|
|
|
3593
3768
|
readonly onElement?: never;
|
|
3594
3769
|
readonly onSnapshot?: unknown;
|
|
3595
3770
|
});
|
|
3596
|
-
|
|
3597
|
-
type InvokeDefinition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents> | ReadonlyArray<InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
3598
|
-
type TypedInvokeDefinition = InvokeTyped<any, any, any, any, any, any> | ReadonlyArray<InvokeTyped<any, any, any, any, any, any>>;
|
|
3599
|
-
type InvokeHandlerRequirement<Value, Handler> = IsAny<Value> extends true ? {
|
|
3600
|
-
readonly handler: Handler;
|
|
3601
|
-
} : [Value] extends [never] ? {
|
|
3602
|
-
readonly handler?: never;
|
|
3603
|
-
} : {
|
|
3604
|
-
readonly handler: Handler;
|
|
3605
|
-
};
|
|
3606
|
-
type InvokeDoneRequirement<Value, Handler> = InvokeHandlerRequirement<Value, Handler> extends infer Requirement ? Requirement extends {
|
|
3607
|
-
readonly handler: infer Required;
|
|
3608
|
-
} ? {
|
|
3609
|
-
readonly onDone: Required;
|
|
3610
|
-
} : {
|
|
3611
|
-
readonly onDone?: never;
|
|
3612
|
-
} : never;
|
|
3613
|
-
type InvokeFailureRequirement<Value, Handler> = InvokeHandlerRequirement<Value, Handler> extends infer Requirement ? Requirement extends {
|
|
3614
|
-
readonly handler: infer Required;
|
|
3615
|
-
} ? {
|
|
3616
|
-
readonly onFailure: Required;
|
|
3617
|
-
} : {
|
|
3618
|
-
readonly onFailure?: never;
|
|
3619
|
-
} : never;
|
|
3620
|
-
type InvokeElementRequirement<Value, Handler> = InvokeHandlerRequirement<Value, Handler> extends infer Requirement ? Requirement extends {
|
|
3621
|
-
readonly handler: infer Required;
|
|
3622
|
-
} ? {
|
|
3623
|
-
readonly onElement: Required;
|
|
3624
|
-
} : {
|
|
3625
|
-
readonly onElement?: never;
|
|
3626
|
-
} : never;
|
|
3627
|
-
type TimerInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
|
|
3628
|
-
readonly id: InvokeLifecycleId;
|
|
3629
|
-
readonly after: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
3630
|
-
readonly effect?: never;
|
|
3631
|
-
readonly stream?: never;
|
|
3632
|
-
readonly logic?: never;
|
|
3633
|
-
readonly child?: never;
|
|
3634
|
-
readonly address?: never;
|
|
3635
|
-
readonly onFailure?: never;
|
|
3636
|
-
readonly onElement?: never;
|
|
3637
|
-
readonly onSnapshot?: never;
|
|
3638
|
-
readonly onDone: InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>>;
|
|
3639
|
-
};
|
|
3640
|
-
type LogicInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>, Source = Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
|
|
3641
|
-
readonly id: InvokeLifecycleId;
|
|
3642
|
-
readonly address: Address & ChildAddress.Compatibility<Address, ChildEvent>;
|
|
3643
|
-
readonly logic: Source;
|
|
3644
|
-
readonly effect?: never;
|
|
3645
|
-
readonly stream?: never;
|
|
3646
|
-
readonly after?: never;
|
|
3647
|
-
readonly child?: never;
|
|
3648
|
-
readonly onElement?: never;
|
|
3649
|
-
readonly onSnapshot?: InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, NoInfer<ChildState>, NoInfer<ChildError>, NoInfer<ChildOutput>, InputEvents, ParentEvents>>;
|
|
3650
|
-
} & InvokeDoneRequirement<NoInfer<ChildOutput>, InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, NoInfer<ChildOutput>, InputEvents, ParentEvents>>> & InvokeFailureRequirement<NoInfer<ChildError>, InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, NoInfer<ChildError>, InputEvents, ParentEvents>>>;
|
|
3651
|
-
type ChildInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, ChildDefinition extends Machine.Any, Child extends ChildMachine<string, ChildDefinition>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
|
|
3652
|
-
readonly child: Child & (ChildDefinition extends EnsureExecutable<Machine.States<ChildDefinition>, Machine.UnhandledStates<ChildDefinition>, Machine.OutputStates<ChildDefinition>> ? unknown : never);
|
|
3653
|
-
readonly id?: never;
|
|
3654
|
-
readonly address?: never;
|
|
3655
|
-
readonly effect?: never;
|
|
3656
|
-
readonly stream?: never;
|
|
3657
|
-
readonly after?: never;
|
|
3658
|
-
readonly logic?: never;
|
|
3659
|
-
readonly onElement?: never;
|
|
3660
|
-
readonly onSnapshot?: InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, Snapshot<Machine.States<ChildDefinition>>, Error<ChildDefinition>, Output<ChildDefinition>, InputEvents, ParentEvents>>;
|
|
3661
|
-
} & (Input<ChildDefinition> extends typeof Schema.Void ? {
|
|
3662
|
-
readonly input?: never;
|
|
3663
|
-
} : {
|
|
3664
|
-
readonly input: InvokeSource<Input<ChildDefinition>["Type"], InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
3665
|
-
}) & InvokeDoneRequirement<Output<ChildDefinition>, InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, Output<ChildDefinition>, InputEvents, ParentEvents>>> & InvokeFailureRequirement<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InputEvents, ParentEvents>>>;
|
|
3771
|
+
type StoredInvokeDefinition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = StoredInvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents> | ReadonlyArray<StoredInvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
3666
3772
|
type LogicInitialEffectOf<Value> = Value extends {
|
|
3667
3773
|
readonly initial: infer Initial;
|
|
3668
3774
|
} ? Initial extends (...args: ReadonlyArray<any>) => infer Result ? Result : never : never;
|
|
@@ -3677,43 +3783,142 @@ export declare namespace Machine {
|
|
|
3677
3783
|
type LogicServicesOf<Value> = Effect.Services<LogicInitialEffectOf<Value> | LogicRunEffectOf<Value>>;
|
|
3678
3784
|
type LogicOutputOf<Value> = Effect.Success<LogicRunEffectOf<Value>>;
|
|
3679
3785
|
type LogicInitialErrorOf<Value> = Effect.Error<LogicInitialEffectOf<Value>>;
|
|
3680
|
-
type
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
readonly onDone: InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId,
|
|
3688
|
-
}
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
readonly
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3786
|
+
type RequiredInvokeChannel<Value, Channel extends string> = IsAny<Value> extends true ? Channel : [Value] extends [never] ? never : Channel;
|
|
3787
|
+
type InvokeBuilderResult<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes> = InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & InvokeTyped<Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes> & {
|
|
3788
|
+
readonly [InvokeBuilderTypeId]: true;
|
|
3789
|
+
};
|
|
3790
|
+
/** Lifecycle handlers exposed according to the selected invocation source. */
|
|
3791
|
+
type InvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Pending extends string, SnapshotHandler, Outcomes = never> = ([Pending] extends [never] ? InvokeBuilderResult<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes> : {}) & ("done" extends Pending ? {
|
|
3792
|
+
/** Handles successful completion and exposes the invocation output. */
|
|
3793
|
+
readonly onDone: <const Handler extends InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, Output, InputEvents, ParentEvents>>>(handler: Handler & InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, Output, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Exclude<Pending, "done">, SnapshotHandler, Outcomes | Handler>;
|
|
3794
|
+
} : {}) & ("failure" extends Pending ? {
|
|
3795
|
+
/** Handles typed failure and exposes the invocation error. */
|
|
3796
|
+
readonly onFailure: <const Handler extends InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, Error, InputEvents, ParentEvents>>>(handler: Handler & InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, Error, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Exclude<Pending, "failure">, SnapshotHandler, Outcomes | Handler>;
|
|
3797
|
+
} : {}) & ("element" extends Pending ? {
|
|
3798
|
+
/** Handles each backpressured element emitted by an invoked Stream. */
|
|
3799
|
+
readonly onElement: <const Handler extends InvokeTransition<States, Events, Emits, StateId, InvokeElementContext<States, Events, Emits, StateId, Element, InputEvents, ParentEvents>>>(handler: Handler & InvokeTransition<States, Events, Emits, StateId, InvokeElementContext<States, Events, Emits, StateId, Element, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Exclude<Pending, "element">, SnapshotHandler, Outcomes | Handler>;
|
|
3800
|
+
} : {}) & ([SnapshotHandler] extends [never] ? {} : {
|
|
3801
|
+
/** Handles each active snapshot published by invoked logic or a child machine. */
|
|
3802
|
+
readonly onSnapshot: <const Handler extends SnapshotHandler>(handler: Handler & SnapshotHandler) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Pending, never, Outcomes | Handler>;
|
|
3803
|
+
});
|
|
3804
|
+
type EffectInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Source extends (...args: ReadonlyArray<any>) => Effect.Effect<any, any, any>> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Effect.Success<ReturnType<Source>>, Effect.Error<ReturnType<Source>>, Effect.Services<ReturnType<Source>>, never, never, never, never, RequiredInvokeChannel<Effect.Success<ReturnType<Source>>, "done"> | RequiredInvokeChannel<Effect.Error<ReturnType<Source>>, "failure">, never>;
|
|
3805
|
+
type StreamInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Source extends (...args: ReadonlyArray<any>) => Stream.Stream<any, any, any>> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, void, Stream.Error<ReturnType<Source>>, Stream.Services<ReturnType<Source>>, never, never, never, Stream.Success<ReturnType<Source>>, "done" | RequiredInvokeChannel<Stream.Success<ReturnType<Source>>, "element"> | RequiredInvokeChannel<Stream.Error<ReturnType<Source>>, "failure">, never>;
|
|
3806
|
+
type LogicInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, ChildLogic> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, LogicOutputOf<ChildLogic>, LogicErrorOf<ChildLogic>, LogicServicesOf<ChildLogic>, LogicInitialErrorOf<ChildLogic>, never, never, never, RequiredInvokeChannel<LogicOutputOf<ChildLogic>, "done"> | RequiredInvokeChannel<LogicErrorOf<ChildLogic>, "failure">, InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, LogicStateOf<ChildLogic>, LogicErrorOf<ChildLogic>, LogicOutputOf<ChildLogic>, InputEvents, ParentEvents>>>;
|
|
3807
|
+
type ChildInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Child extends ChildMachine.Any, ChildDefinition extends Machine.Any = Child["machine"]> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output<ChildDefinition>, Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, Services<ChildDefinition>, InitialError<ChildDefinition>, Emit<ChildDefinition>, EventOf<Machine.ParentEvents<ChildDefinition>>, never, RequiredInvokeChannel<Output<ChildDefinition>, "done"> | RequiredInvokeChannel<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, "failure">, InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, Snapshot<Machine.States<ChildDefinition>>, Error<ChildDefinition>, Output<ChildDefinition>, InputEvents, ParentEvents>>>;
|
|
3808
|
+
/**
|
|
3809
|
+
* Selects state-owned work and begins its lifecycle-handler chain.
|
|
3810
|
+
*
|
|
3811
|
+
* Each source exposes exactly the lifecycle methods that it can produce. A
|
|
3812
|
+
* chain becomes returnable from `invoke` only after every reachable required
|
|
3813
|
+
* channel has been handled.
|
|
3814
|
+
*
|
|
3815
|
+
* **Example** (Invoking an Effect)
|
|
3816
|
+
*
|
|
3817
|
+
* ```ts
|
|
3818
|
+
* invoke: (from) =>
|
|
3819
|
+
* from.effect("load-user", () => loadUser).onDone((to) =>
|
|
3820
|
+
* to.full.Ready().resolve(({ output, target }) => target.from({ user: output }))
|
|
3821
|
+
* ).onFailure((to) =>
|
|
3822
|
+
* to.full.Failed().resolve(({ error, target }) => target.from({ error }))
|
|
3823
|
+
* )
|
|
3824
|
+
* ```
|
|
3825
|
+
*
|
|
3826
|
+
* @inlineType EffectInvokeBuilder
|
|
3827
|
+
* @inlineType StreamInvokeBuilder
|
|
3828
|
+
* @inlineType LogicInvokeBuilder
|
|
3829
|
+
* @inlineType ChildInvokeBuilder
|
|
3830
|
+
* @inlineType InvokeBuilder
|
|
3831
|
+
*
|
|
3832
|
+
* @category models
|
|
3833
|
+
* @since 0.18.0
|
|
3834
|
+
*/
|
|
3835
|
+
interface InvokeSelector<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
|
|
3836
|
+
/**
|
|
3837
|
+
* Starts a fresh Effect each time the owning state is entered.
|
|
3838
|
+
*
|
|
3839
|
+
* @param id Parent-local lifecycle identifier.
|
|
3840
|
+
* @param source Lazy Effect factory evaluated on every entry.
|
|
3841
|
+
*/
|
|
3842
|
+
readonly effect: <const Source extends (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, unknown, unknown>>(id: InvokeLifecycleId, source: Source) => EffectInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>;
|
|
3843
|
+
/**
|
|
3844
|
+
* Starts a fresh, backpressured Stream each time the owning state is entered.
|
|
3845
|
+
*
|
|
3846
|
+
* @param id Parent-local lifecycle identifier.
|
|
3847
|
+
* @param source Lazy Stream factory evaluated on every entry.
|
|
3848
|
+
*/
|
|
3849
|
+
readonly stream: <const Source extends (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Stream.Stream<unknown, unknown, any>>(id: InvokeLifecycleId, source: Source) => StreamInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>;
|
|
3850
|
+
/**
|
|
3851
|
+
* Starts a cancellable state-scoped timer.
|
|
3852
|
+
*
|
|
3853
|
+
* @param id Parent-local lifecycle identifier.
|
|
3854
|
+
* @param duration Duration input or context-dependent duration factory.
|
|
3855
|
+
*/
|
|
3856
|
+
readonly timer: (id: InvokeLifecycleId, duration: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, void, never, never, never, never, never, never, "done", never>;
|
|
3857
|
+
/**
|
|
3858
|
+
* Starts reusable process logic at a typed parent-local address.
|
|
3859
|
+
*
|
|
3860
|
+
* @param id Parent-local lifecycle identifier.
|
|
3861
|
+
* @param options Address and reusable logic value or factory.
|
|
3862
|
+
*/
|
|
3863
|
+
readonly logic: {
|
|
3864
|
+
<const Source extends (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => unknown, Address extends ChildAddress<never>>(id: InvokeLifecycleId, options: {
|
|
3865
|
+
/** Typed parent-local address used to send events to this logic. */
|
|
3866
|
+
readonly address: Address & ChildAddress.Compatibility<Address, LogicEventOf<ReturnType<NoInfer<Source>>>>;
|
|
3867
|
+
/** Context-dependent factory that returns reusable process logic. */
|
|
3868
|
+
readonly logic: Source;
|
|
3869
|
+
}, ..._validation: ReturnType<Source> extends {
|
|
3870
|
+
readonly initial: unknown;
|
|
3871
|
+
readonly run: unknown;
|
|
3872
|
+
} ? [] : [
|
|
3873
|
+
"logic factory must return Machine.Logic"
|
|
3874
|
+
]): LogicInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, ReturnType<Source>>;
|
|
3875
|
+
<const Source, Address extends ChildAddress<never>>(id: InvokeLifecycleId, options: {
|
|
3876
|
+
/** Typed parent-local address used to send events to this logic. */
|
|
3877
|
+
readonly address: Address & ChildAddress.Compatibility<Address, LogicEventOf<NoInfer<Source>>>;
|
|
3878
|
+
/** Reusable process logic started when the owning state enters. */
|
|
3879
|
+
readonly logic: Source;
|
|
3880
|
+
}, ..._validation: Source extends {
|
|
3881
|
+
readonly initial: unknown;
|
|
3882
|
+
readonly run: unknown;
|
|
3883
|
+
} ? [] : [
|
|
3884
|
+
"logic must implement Machine.Logic"
|
|
3885
|
+
]): LogicInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>;
|
|
3886
|
+
};
|
|
3887
|
+
/**
|
|
3888
|
+
* Starts a complete child statechart represented by a reusable descriptor.
|
|
3889
|
+
*
|
|
3890
|
+
* @param child Reusable descriptor created with `Machine.child`.
|
|
3891
|
+
* @param options Input construction for a child with a non-void input schema.
|
|
3892
|
+
*/
|
|
3893
|
+
readonly child: <const Child extends ChildMachine.Any>(child: Child & (Child["machine"] extends EnsureExecutable<Machine.States<Child["machine"]>, Machine.UnhandledStates<Child["machine"]>, Machine.OutputStates<Child["machine"]>> ? unknown : never), ...options: InputSchema<Child["machine"]> extends typeof Schema.Void ? [options?: {
|
|
3894
|
+
readonly input?: never;
|
|
3895
|
+
}] : [
|
|
3896
|
+
options: {
|
|
3897
|
+
/** Child input value or factory evaluated from the owning state context. */
|
|
3898
|
+
readonly input: InvokeSource<Input<Child["machine"]>, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
3899
|
+
}
|
|
3900
|
+
]) => ChildInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Child>;
|
|
3901
|
+
}
|
|
3902
|
+
/**
|
|
3903
|
+
* Inline invocation declaration accepted by an active state handler.
|
|
3904
|
+
*
|
|
3905
|
+
* Return one completed source chain or an array of completed chains. Source
|
|
3906
|
+
* computations and child descriptors may be extracted, but the chain stays
|
|
3907
|
+
* local to preserve the owning state and machine protocols.
|
|
3908
|
+
*
|
|
3909
|
+
* @category models
|
|
3910
|
+
* @since 0.18.0
|
|
3911
|
+
*/
|
|
3912
|
+
type InvokeBuilderInput<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = (from: InvokeSelector<States, Events, Emits, StateId, InputEvents, ParentEvents>) => (InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
|
|
3913
|
+
readonly [InvokeBuilderTypeId]: true;
|
|
3914
|
+
}) | ReadonlyArray<InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
|
|
3915
|
+
readonly [InvokeBuilderTypeId]: true;
|
|
3916
|
+
}>;
|
|
3917
|
+
/** Output construction available to final and output-producing parallel states. */
|
|
3714
3918
|
type OutputHandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Context> = NodeByIdentifier<States, StateId> extends {
|
|
3715
3919
|
readonly output: Schema.Top;
|
|
3716
3920
|
} ? {
|
|
3921
|
+
/** Constructs the decoded output declared by the state's `output` schema. */
|
|
3717
3922
|
readonly output: (context: Context) => OutputByIdentifier<States, StateId>;
|
|
3718
3923
|
} : {
|
|
3719
3924
|
readonly output?: never;
|
|
@@ -3726,18 +3931,41 @@ export declare namespace Machine {
|
|
|
3726
3931
|
/**
|
|
3727
3932
|
* Configuration accepted for a non-final state.
|
|
3728
3933
|
*
|
|
3934
|
+
* **Example** (State actions, events, and invocation)
|
|
3935
|
+
*
|
|
3936
|
+
* ```ts
|
|
3937
|
+
* machine.handle({
|
|
3938
|
+
* Loading: {
|
|
3939
|
+
* entry: (_, enqueue) => enqueue.emit({ _tag: "Started" }),
|
|
3940
|
+
* invoke: (from) =>
|
|
3941
|
+
* from.effect("load", () => load).onDone((to) => to.full.Ready()),
|
|
3942
|
+
* on: { Cancel: (to) => to.full.Idle() }
|
|
3943
|
+
* }
|
|
3944
|
+
* })
|
|
3945
|
+
* ```
|
|
3946
|
+
*
|
|
3947
|
+
* @inlineType ActiveOutputHandlerConfig
|
|
3948
|
+
* @inlineType OutputHandlerConfig
|
|
3949
|
+
*
|
|
3729
3950
|
* @category models
|
|
3730
3951
|
* @since 0.4.0
|
|
3731
3952
|
*/
|
|
3732
3953
|
type ActiveStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
|
|
3954
|
+
/** Runs synchronously when the state is entered and may enqueue commands. */
|
|
3733
3955
|
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
3956
|
+
/** Runs synchronously before the state is exited and may enqueue commands. */
|
|
3734
3957
|
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
3735
|
-
|
|
3958
|
+
/** Starts state-owned Effect, Stream, timer, logic, or child lifecycles. */
|
|
3959
|
+
readonly invoke?: InvokeBuilderInput<States, Events, Emits, StateId, InputEvents, ParentEvents>;
|
|
3960
|
+
/** Eventless transition evaluated after the state becomes stable. */
|
|
3736
3961
|
readonly always?: TransitionConfig<States, Events, Emits, StateId, AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, false, TransitionAcceptance>;
|
|
3962
|
+
/** Transition evaluated after this compound or parallel state completes. */
|
|
3737
3963
|
readonly onDone?: TransitionConfig<States, Events, Emits, StateId, DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, false, TransitionAcceptance>;
|
|
3964
|
+
/** Event handlers keyed by the `_tag` of the machine's public or internal events. */
|
|
3738
3965
|
readonly on?: {
|
|
3739
3966
|
readonly [EventTag in TagOf<Events[number]>]?: TransitionConfig<States, Events, Emits, StateId, HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>, true, TransitionAcceptance>;
|
|
3740
3967
|
};
|
|
3968
|
+
/** Supplies missing direct initial-child values required by implicit entry and shallow history. */
|
|
3741
3969
|
readonly initialize?: StateInitializeHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>;
|
|
3742
3970
|
} & ActiveOutputHandlerConfig<States, Events, StateId>;
|
|
3743
3971
|
/**
|
|
@@ -3803,8 +4031,11 @@ export declare namespace Machine {
|
|
|
3803
4031
|
type StateInitializeHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = (context: StateInitializeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => SnapshotBuilderComplete<StateInitializeValue<States, StateId>, boolean>;
|
|
3804
4032
|
/** Context used only when a history node has no previously captured record. */
|
|
3805
4033
|
interface HistoryDefaultContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> {
|
|
4034
|
+
/** Lifecycle event that attempted to restore this history node. */
|
|
3806
4035
|
readonly event: LifecycleEvent<Events>;
|
|
4036
|
+
/** Complete target builder rooted at the history owner. */
|
|
3807
4037
|
readonly target: HistoryDefaultTargetBuilder<States, ParentId>;
|
|
4038
|
+
/** State path whose child configuration is restored by this history node. */
|
|
3808
4039
|
readonly owner: ParentId;
|
|
3809
4040
|
}
|
|
3810
4041
|
/**
|
|
@@ -3815,14 +4046,26 @@ export declare namespace Machine {
|
|
|
3815
4046
|
* and provides every inactive ancestor and required parallel region.
|
|
3816
4047
|
*/
|
|
3817
4048
|
type HistoryDefaultHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> = (context: HistoryDefaultContext<States, Events, Emits, ParentId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => CompleteSnapshotContaining<States, ParentId> | StateConstruction<CompleteSnapshotContaining<States, ParentId>>;
|
|
3818
|
-
/**
|
|
4049
|
+
/**
|
|
4050
|
+
* Fallback implementation for one direct history pseudo-state.
|
|
4051
|
+
*
|
|
4052
|
+
* @inline
|
|
4053
|
+
*/
|
|
4054
|
+
interface HistoryDefaultEntry<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> {
|
|
4055
|
+
/** Builds the complete fallback configuration used before history is first captured. */
|
|
4056
|
+
readonly default: HistoryDefaultHandler<States, Events, Emits, ParentId>;
|
|
4057
|
+
}
|
|
4058
|
+
/**
|
|
4059
|
+
* Default implementations keyed by direct history child.
|
|
4060
|
+
*
|
|
4061
|
+
* @inlineType HistoryDefaultEntry
|
|
4062
|
+
*/
|
|
3819
4063
|
type HistoryDefaultConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>, Children extends StateSchemas> = {
|
|
3820
|
-
readonly [Key in HistoryStateKey<Children>]?:
|
|
3821
|
-
readonly default: HistoryDefaultHandler<States, Events, Emits, ParentId>;
|
|
3822
|
-
};
|
|
4064
|
+
readonly [Key in HistoryStateKey<Children>]?: HistoryDefaultEntry<States, Events, Emits, ParentId>;
|
|
3823
4065
|
};
|
|
3824
4066
|
/** Required implementation for a choice pseudo-state. */
|
|
3825
4067
|
interface ChoiceStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
|
|
4068
|
+
/** Required transition that resolves this transient choice to a concrete destination. */
|
|
3826
4069
|
readonly choice: TransitionConfig<States, Events, Emits, ChoiceId, ChoiceContext<States, Events, Emits, ChoiceId, InputEvents, ParentEvents>>;
|
|
3827
4070
|
readonly entry?: never;
|
|
3828
4071
|
readonly exit?: never;
|
|
@@ -3836,10 +4079,13 @@ export declare namespace Machine {
|
|
|
3836
4079
|
/**
|
|
3837
4080
|
* Configuration accepted for a final state.
|
|
3838
4081
|
*
|
|
4082
|
+
* @inlineType OutputHandlerConfig
|
|
4083
|
+
*
|
|
3839
4084
|
* @category models
|
|
3840
4085
|
* @since 0.4.0
|
|
3841
4086
|
*/
|
|
3842
4087
|
type FinalStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
|
|
4088
|
+
/** Runs synchronously when the final state is entered and may enqueue commands. */
|
|
3843
4089
|
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
3844
4090
|
readonly exit?: never;
|
|
3845
4091
|
readonly always?: never;
|
|
@@ -3870,12 +4116,6 @@ export declare namespace Machine {
|
|
|
3870
4116
|
readonly states: infer Children extends StateSchemas;
|
|
3871
4117
|
} ? HandlerNodeByPath<Children, Rest> : never : never : Path extends keyof States ? States[Path] : never;
|
|
3872
4118
|
type HandlerConfigAtPath<Config, Path extends string> = Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Config ? HandlerConfigAtPath<HandlerNodeChildrenConfig<Config[Head]>, Rest> : never : Path extends keyof Config ? Config[Path] : never;
|
|
3873
|
-
type HandlerInvokeContextAtPath<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Config, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = StateId extends StateIdentifier<AllStates> ? NodeConfig extends {
|
|
3874
|
-
readonly invoke: infer Invoke;
|
|
3875
|
-
} ? HandlerValidationAtPath<StateId, {
|
|
3876
|
-
readonly invoke: ContextualInvokeDefinition<AllStates, Events, Emits, StateId, InputEvents, ParentEvents, Invoke>;
|
|
3877
|
-
}> : unknown : unknown;
|
|
3878
|
-
type HandlerInvokeContexts<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Config> = Types.UnionToIntersection<StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerInvokeContextAtPath<AllStates, Events, InputEvents, Emits, ParentEvents, Config, StateId> : never : never>;
|
|
3879
4119
|
type HandlerValidationAtPath<Path extends string, Validation> = Path extends `${infer Head}.${infer Rest}` ? {
|
|
3880
4120
|
readonly [Key in Head]?: {
|
|
3881
4121
|
readonly states: HandlerValidationAtPath<Rest, Validation>;
|
|
@@ -3883,6 +4123,7 @@ export declare namespace Machine {
|
|
|
3883
4123
|
} : {
|
|
3884
4124
|
readonly [Key in Path]?: Validation;
|
|
3885
4125
|
};
|
|
4126
|
+
/** Nested handler-tree structure shared by active and final state configs. */
|
|
3886
4127
|
type HandlerNode<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<AllStates>> = HandlerNodeConfig<AllStates, Events, Emits, StateId, E, R, InputEvents, ParentEvents> & (StateId extends ChoiceIdentifier<AllStates> ? {
|
|
3887
4128
|
readonly states?: never;
|
|
3888
4129
|
readonly history?: never;
|
|
@@ -3890,7 +4131,9 @@ export declare namespace Machine {
|
|
|
3890
4131
|
readonly states?: never;
|
|
3891
4132
|
readonly history?: never;
|
|
3892
4133
|
} : {
|
|
4134
|
+
/** Child-state handlers nested according to the declared state topology. */
|
|
3893
4135
|
readonly states?: HandlerTree<AllStates, Children, Events, Emits, E, R, InputEvents, ParentEvents, Extract<StateId, StateIdentifier<AllStates>>>;
|
|
4136
|
+
/** First-use defaults keyed by direct history pseudo-state. */
|
|
3894
4137
|
readonly history?: HistoryDefaultConfig<AllStates, Events, Emits, Extract<StateId, StateIdentifier<AllStates>>, Children>;
|
|
3895
4138
|
} : {
|
|
3896
4139
|
readonly states?: never;
|
|
@@ -4023,7 +4266,7 @@ export declare namespace Machine {
|
|
|
4023
4266
|
* @since 0.4.0
|
|
4024
4267
|
*/
|
|
4025
4268
|
interface Handler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<States>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<States>, Output, OutputStates extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>> {
|
|
4026
|
-
<const Config extends HandlerTree<States, States, Events, Emits, E, R, InputEvents, ParentEvents, "">>(config: Config &
|
|
4269
|
+
<const Config extends HandlerTree<States, States, Events, Emits, E, R, InputEvents, ParentEvents, "">>(config: Config & HandlerTreeValidation<States, Events, InputEvents, Emits, NoInfer<Config>, OutputStates | Extract<HandlerTreeEvidence<States, NoInfer<Config>>["outputState"], StateIdentifier<States>>> & ([StateIdentifier<States>] extends [UnhandledStates] ? HandlerInitialTargetValidation<States, NoInfer<Config>> : unknown)): HandleTreeResult<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, ParentEvents, Config>;
|
|
4027
4270
|
}
|
|
4028
4271
|
/**
|
|
4029
4272
|
* Any state config.
|
|
@@ -4048,7 +4291,7 @@ export declare namespace Machine {
|
|
|
4048
4291
|
interface StateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
|
|
4049
4292
|
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<E, R>;
|
|
4050
4293
|
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<E, R>;
|
|
4051
|
-
readonly invoke?:
|
|
4294
|
+
readonly invoke?: StoredInvokeDefinition<States, Events, Emits, StateId>;
|
|
4052
4295
|
readonly always?: TransitionConfig<States, Events, Emits, StateId, AlwaysContext<States, Events, Emits, StateId>, false, TransitionAcceptance>;
|
|
4053
4296
|
readonly onDone?: TransitionConfig<States, Events, Emits, StateId, DoneContext<States, Events, Emits, StateId>, false, TransitionAcceptance>;
|
|
4054
4297
|
readonly output?: ((context: FinalOutputContext<States, Events, StateId>) => unknown) | ((context: ParallelOutputContext<States, Events, StateId>) => unknown);
|
|
@@ -4062,13 +4305,37 @@ export declare namespace Machine {
|
|
|
4062
4305
|
*/
|
|
4063
4306
|
type StateConfigs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey, StateConfig<States, Events, Emits, StateId, EventTag, E, R> | ChoiceStateConfig<States, Events, Emits, ChoiceIdentifier<States>>>>;
|
|
4064
4307
|
}
|
|
4308
|
+
type StateSource = Machine.DefinedStates<any> | Machine.Any;
|
|
4309
|
+
type StateSchemasOf<Source extends StateSource> = Source extends Machine.DefinedStates<infer States> ? States : Source extends Machine.Any ? Machine.States<Source> : never;
|
|
4065
4310
|
/**
|
|
4066
|
-
* Extracts the complete logical snapshot represented by a state definition
|
|
4311
|
+
* Extracts the complete logical snapshot represented by a state definition or
|
|
4312
|
+
* machine.
|
|
4067
4313
|
*
|
|
4068
4314
|
* @category utility types
|
|
4069
4315
|
* @since 0.15.0
|
|
4070
4316
|
*/
|
|
4071
|
-
export type Snapshot<
|
|
4317
|
+
export type Snapshot<Source extends StateSource> = Machine.Snapshot<StateSchemasOf<Source>>;
|
|
4318
|
+
/**
|
|
4319
|
+
* Extracts the decoded value owned by a schema-backed state path.
|
|
4320
|
+
*
|
|
4321
|
+
* The source may be the object returned by {@link states} or a machine
|
|
4322
|
+
* definition. Control-only state paths are intentionally excluded.
|
|
4323
|
+
*
|
|
4324
|
+
* @category utility types
|
|
4325
|
+
* @since 0.18.0
|
|
4326
|
+
*/
|
|
4327
|
+
export type Value<Source extends StateSource, Path extends Machine.ValuedStateIdentifier<StateSchemasOf<Source>>> = Machine.StateByIdentifier<StateSchemasOf<Source>, Path>;
|
|
4328
|
+
/**
|
|
4329
|
+
* Extracts the logical snapshot rooted at a state path.
|
|
4330
|
+
*
|
|
4331
|
+
* The source may be the object returned by {@link states} or a machine
|
|
4332
|
+
* definition. This is the type-level counterpart of
|
|
4333
|
+
* `DefinedStates.getSnapshot`.
|
|
4334
|
+
*
|
|
4335
|
+
* @category utility types
|
|
4336
|
+
* @since 0.18.0
|
|
4337
|
+
*/
|
|
4338
|
+
export type SnapshotAt<Source extends StateSource, Path extends Machine.StateIdentifier<StateSchemasOf<Source>>> = Machine.SnapshotByIdentifier<StateSchemasOf<Source>, Path>;
|
|
4072
4339
|
/**
|
|
4073
4340
|
* Returns `true` if a value is a `Machine`.
|
|
4074
4341
|
*
|
|
@@ -4158,20 +4425,31 @@ export declare const state: StateConstructor;
|
|
|
4158
4425
|
*/
|
|
4159
4426
|
export declare const states: StatesConstructor;
|
|
4160
4427
|
type MakeConfig<States extends Machine.StateSchemas, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined> = {
|
|
4428
|
+
/** Stable definition identifier used by inspection and visualization. */
|
|
4161
4429
|
readonly id?: string;
|
|
4430
|
+
/** State topology and value schemas, normally supplied by `Machine.states`. */
|
|
4162
4431
|
readonly states: States & DefineStateTreeInput<NoInfer<States>>;
|
|
4432
|
+
/** Public events accepted by independently running machine references. */
|
|
4163
4433
|
readonly events: Machine.EventProtocol<"public", InputEvents> & ValidateInputEventProtocol<NoInfer<InputEvents>>;
|
|
4434
|
+
/** Machine-local events used by raised events and other internal deliveries. */
|
|
4164
4435
|
readonly internalEvents?: Machine.EventProtocol<"internal", InternalEvents> & ValidateInternalEventProtocol<NoInfer<InputEvents>, NoInfer<InternalEvents>>;
|
|
4436
|
+
/** Ephemeral notifications that handlers may publish to observers. */
|
|
4165
4437
|
readonly emittedEvents?: Machine.EventProtocol<"emitted", Emits>;
|
|
4438
|
+
/** Required or optional owning-machine protocol for this definition. */
|
|
4166
4439
|
readonly parent?: ParentDeclaration;
|
|
4440
|
+
/** Schema used to decode input before initial-state construction. */
|
|
4167
4441
|
readonly input?: Input;
|
|
4442
|
+
/** Target-first declaration that constructs the initial active configuration. */
|
|
4168
4443
|
readonly initial: unknown;
|
|
4169
4444
|
};
|
|
4170
4445
|
type MakeResult<States extends Machine.StateSchemas, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined> = Definition<States, readonly [...InputEvents, ...InternalEvents], Input, InitialE, InitialR, Machine.FinalStateFromDefinition<States>, Machine.TerminalOutput<States>, Emits, InputEvents, Machine.ParentEventsOf<ParentDeclaration>>;
|
|
4446
|
+
/** @inline */
|
|
4171
4447
|
interface Make {
|
|
4448
|
+
/** @param config Complete schema-first machine definition. */
|
|
4172
4449
|
<const States extends Machine.StateSchemas, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined>(config: Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>, "initial"> & {
|
|
4173
4450
|
readonly initial: Machine.InitialBuilderInput<States, Input["Type"]>;
|
|
4174
4451
|
}, ..._validation: ValidateDefinedStates<NoInfer<States>>): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>;
|
|
4452
|
+
/** @param config Invalid state tree retained only to report its validation error at the call site. */
|
|
4175
4453
|
<const States extends Machine.StateSchemas, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined>(config: Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>, "states"> & {
|
|
4176
4454
|
readonly states: InvalidDefinedStateTreeInput<States>;
|
|
4177
4455
|
}): never;
|
|
@@ -4234,6 +4512,7 @@ interface Make {
|
|
|
4234
4512
|
* ```
|
|
4235
4513
|
*
|
|
4236
4514
|
* @see {@link states} for typed state-tree helpers.
|
|
4515
|
+
* @inlineType MakeConfig
|
|
4237
4516
|
* @category constructors
|
|
4238
4517
|
* @since 0.4.0
|
|
4239
4518
|
*/
|
|
@@ -4359,18 +4638,21 @@ export declare const emittedEvents: {
|
|
|
4359
4638
|
*
|
|
4360
4639
|
* **Details**
|
|
4361
4640
|
*
|
|
4362
|
-
* Each active state value and completed output is encoded with the
|
|
4363
|
-
* declared for its state path.
|
|
4364
|
-
* state.
|
|
4641
|
+
* Each active state value and completed output is encoded with the canonical
|
|
4642
|
+
* JSON codec derived from the schema declared for its state path. Success
|
|
4643
|
+
* guarantees that every state, output, and history value is `Schema.Json`.
|
|
4644
|
+
* Non-JSON values, including cyclic process-local capabilities, fail with
|
|
4645
|
+
* {@link MachineSchemaEncodeError} at their declared boundary.
|
|
4365
4646
|
*
|
|
4366
4647
|
* **Gotchas**
|
|
4367
4648
|
*
|
|
4368
4649
|
* The encoded snapshot does not contain the machine definition, machine
|
|
4369
4650
|
* version, running children, invoked process state, services, or subscriptions.
|
|
4370
4651
|
* Store machine identity and migration metadata alongside the result when the
|
|
4371
|
-
* snapshot crosses deployment versions.
|
|
4372
|
-
*
|
|
4373
|
-
*
|
|
4652
|
+
* snapshot crosses deployment versions. Opaque declarations without a JSON
|
|
4653
|
+
* codec can encode only when their current value is already JSON-compatible.
|
|
4654
|
+
* Define an explicit JSON codec or keep process-local capabilities outside the
|
|
4655
|
+
* logical snapshot.
|
|
4374
4656
|
*
|
|
4375
4657
|
* **Example**
|
|
4376
4658
|
*
|
|
@@ -4442,158 +4724,12 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
4442
4724
|
* @since 0.4.0
|
|
4443
4725
|
*/
|
|
4444
4726
|
export declare const decodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, encoded: unknown) => Effect.Effect<Machine.Snapshot<States>, MachineSchemaDecodeError, Machine.SnapshotDecodingServices<States>>;
|
|
4445
|
-
type EffectInvokeSource<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, unknown, unknown>> = {
|
|
4446
|
-
readonly id: InvokeLifecycleId;
|
|
4447
|
-
readonly effect: Source;
|
|
4448
|
-
readonly stream?: never;
|
|
4449
|
-
readonly after?: never;
|
|
4450
|
-
readonly logic?: never;
|
|
4451
|
-
readonly child?: never;
|
|
4452
|
-
readonly address?: never;
|
|
4453
|
-
readonly onElement?: never;
|
|
4454
|
-
readonly onSnapshot?: never;
|
|
4455
|
-
};
|
|
4456
|
-
type EffectDoneHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, StateId, Machine.InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<ReturnType<NoInfer<Source>>>, InputEvents, ParentEvents>>;
|
|
4457
|
-
type EffectFailureHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, StateId, Machine.InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<ReturnType<NoInfer<Source>>>, InputEvents, ParentEvents>>;
|
|
4458
|
-
type EffectInvokeResult<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & Machine.InvokeTyped<Effect.Success<ReturnType<Source>>, Effect.Error<ReturnType<Source>>, Effect.Services<ReturnType<Source>>, never>;
|
|
4459
|
-
type StreamInvokeSource<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<any>) => unknown> = {
|
|
4460
|
-
readonly id: InvokeLifecycleId;
|
|
4461
|
-
readonly stream: Source & ((context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => unknown);
|
|
4462
|
-
readonly effect?: never;
|
|
4463
|
-
readonly after?: never;
|
|
4464
|
-
readonly logic?: never;
|
|
4465
|
-
readonly child?: never;
|
|
4466
|
-
readonly address?: never;
|
|
4467
|
-
readonly onSnapshot?: never;
|
|
4468
|
-
};
|
|
4469
|
-
type StreamSourceResult<Source extends (...args: ReadonlyArray<any>) => unknown> = ReturnType<Source> extends infer Result extends Stream.Stream<any, any, any> ? Result : never;
|
|
4470
|
-
type StreamElementHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<any>) => unknown> = Machine.InvokeTransition<States, Events, Emits, StateId, Machine.InvokeElementContext<States, Events, Emits, StateId, Stream.Success<StreamSourceResult<NoInfer<Source>>>, InputEvents, ParentEvents>>;
|
|
4471
|
-
type StreamDoneHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>> = Machine.InvokeTransition<States, Events, Emits, StateId, Machine.InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>>;
|
|
4472
|
-
type StreamFailureHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<any>) => unknown> = Machine.InvokeTransition<States, Events, Emits, StateId, Machine.InvokeFailureContext<States, Events, Emits, StateId, Stream.Error<StreamSourceResult<NoInfer<Source>>>, InputEvents, ParentEvents>>;
|
|
4473
|
-
type StreamInvokeResult<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<any>) => unknown> = Machine.InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & Machine.InvokeTyped<void, Stream.Error<StreamSourceResult<Source>>, Stream.Services<StreamSourceResult<Source>>, never>;
|
|
4474
|
-
type InvokeChannelIsNever<Value> = IsAny<Value> extends true ? false : [Value] extends [never] ? true : false;
|
|
4475
4727
|
type TransitionBranchRecordError<Message extends string, Key extends PropertyKey = never> = {
|
|
4476
4728
|
readonly "~effect/Machine/TransitionBranchRecordError": Message;
|
|
4477
4729
|
readonly key: Key;
|
|
4478
4730
|
};
|
|
4479
4731
|
type InvalidStaticTransitionBranchKey<Branches> = Extract<keyof Branches, "" | number | symbol>;
|
|
4480
4732
|
type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never] ? TransitionBranchRecordError<"Branch records must contain at least one branch"> : [InvalidStaticTransitionBranchKey<Branches>] extends [never] ? unknown : TransitionBranchRecordError<"Branch keys must be non-empty, non-index strings", InvalidStaticTransitionBranchKey<Branches>>;
|
|
4481
|
-
/**
|
|
4482
|
-
* Preserves inference for a state-owned invocation configuration.
|
|
4483
|
-
*
|
|
4484
|
-
* Use `effect` for one-shot work, `stream` for repeated values, `after` for a
|
|
4485
|
-
* cancellable timer, `logic` for reusable process logic, or `child` for a
|
|
4486
|
-
* complete child machine. Stream elements are handled by `onElement` before
|
|
4487
|
-
* the next element is pulled. `onDone` is required whenever the source can
|
|
4488
|
-
* complete, while `onFailure` is required only when the source has a typed
|
|
4489
|
-
* failure channel.
|
|
4490
|
-
*
|
|
4491
|
-
* This constructor is an identity at runtime, but preserves lifecycle callback
|
|
4492
|
-
* inference through published declarations. Effect and Stream factories run
|
|
4493
|
-
* when their owning state is entered and infer the owner context, value,
|
|
4494
|
-
* output, error, and service channels together without a return annotation.
|
|
4495
|
-
* Durations may be
|
|
4496
|
-
* supplied directly or derived from the owning state's entry context. Logic
|
|
4497
|
-
* invocations require both a lifecycle `id` and a typed communication
|
|
4498
|
-
* `address`. Child descriptors already own their identity, so `id` and
|
|
4499
|
-
* `address` must not be repeated.
|
|
4500
|
-
*
|
|
4501
|
-
* Inside `handle(...)`, the owning definition contextually supplies its public
|
|
4502
|
-
* input and declared parent protocols. Invocation sources and lifecycle handlers
|
|
4503
|
-
* can therefore send through `self` and `parent` without naming the definition.
|
|
4504
|
-
* The standard `Machine.invoke(...)` constructor preserves these contexts
|
|
4505
|
-
* directly; no intermediate definition method is required.
|
|
4506
|
-
*
|
|
4507
|
-
* ```ts
|
|
4508
|
-
* invoke: Machine.invoke({
|
|
4509
|
-
* id: "load",
|
|
4510
|
-
* effect: () =>
|
|
4511
|
-
* Effect.tryPromise({
|
|
4512
|
-
* try: () => fetch("/api/data").then((response) => response.json()),
|
|
4513
|
-
* catch: (cause) => new LoadError({ cause })
|
|
4514
|
-
* }),
|
|
4515
|
-
* onDone: (to) =>
|
|
4516
|
-
* to.full.Ready().resolve(({ output, target }) =>
|
|
4517
|
-
* target.from({ data: output })),
|
|
4518
|
-
* onFailure: (to) =>
|
|
4519
|
-
* to.full.Failed().resolve(({ error, target }) =>
|
|
4520
|
-
* target.from({ error }))
|
|
4521
|
-
* })
|
|
4522
|
-
* ```
|
|
4523
|
-
*
|
|
4524
|
-
* @category constructors
|
|
4525
|
-
* @since 0.9.0
|
|
4526
|
-
*/
|
|
4527
|
-
export declare const invoke: {
|
|
4528
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, unknown, unknown>, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
|
|
4529
|
-
readonly onDone: EffectDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4530
|
-
readonly onFailure: EffectFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4531
|
-
}, ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
|
|
4532
|
-
"onDone must be omitted when the Effect output is never"
|
|
4533
|
-
] : InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
|
|
4534
|
-
"onFailure must be omitted when the Effect error is never"
|
|
4535
|
-
] : []): NoInfer<Config> & EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4536
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, never, unknown>, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
|
|
4537
|
-
readonly onDone: EffectDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4538
|
-
readonly onFailure?: never;
|
|
4539
|
-
}, ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
|
|
4540
|
-
"onDone must be omitted when the Effect output is never"
|
|
4541
|
-
] : []): NoInfer<Config> & EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4542
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<never, unknown, unknown>, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
|
|
4543
|
-
readonly onDone?: never;
|
|
4544
|
-
readonly onFailure: EffectFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4545
|
-
}, ..._validation: InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
|
|
4546
|
-
"onFailure must be omitted when the Effect error is never"
|
|
4547
|
-
] : []): NoInfer<Config> & EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4548
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<never, never, unknown>, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
|
|
4549
|
-
readonly onDone?: never;
|
|
4550
|
-
readonly onFailure?: never;
|
|
4551
|
-
}): NoInfer<Config> & EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4552
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Stream.Stream<unknown, unknown, any>, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & StreamInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
|
|
4553
|
-
readonly onElement: StreamElementHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4554
|
-
readonly onDone: StreamDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId>;
|
|
4555
|
-
readonly onFailure: StreamFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4556
|
-
}, ..._validation: InvokeChannelIsNever<Stream.Success<ReturnType<Source>>> extends true ? [
|
|
4557
|
-
"onElement must be omitted when the Stream element is never"
|
|
4558
|
-
] : InvokeChannelIsNever<Stream.Error<ReturnType<Source>>> extends true ? [
|
|
4559
|
-
"onFailure must be omitted when the Stream error is never"
|
|
4560
|
-
] : []): NoInfer<Config> & StreamInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4561
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Stream.Stream<never, unknown, any>, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & StreamInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
|
|
4562
|
-
readonly onElement?: never;
|
|
4563
|
-
readonly onDone: StreamDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId>;
|
|
4564
|
-
readonly onFailure: StreamFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4565
|
-
}, ..._validation: InvokeChannelIsNever<Stream.Error<ReturnType<Source>>> extends true ? [
|
|
4566
|
-
"onFailure must be omitted when the Stream error is never"
|
|
4567
|
-
] : []): NoInfer<Config> & StreamInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4568
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Stream.Stream<never, never, any>, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & StreamInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
|
|
4569
|
-
readonly onElement?: never;
|
|
4570
|
-
readonly onDone: StreamDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId>;
|
|
4571
|
-
readonly onFailure?: never;
|
|
4572
|
-
}): NoInfer<Config> & StreamInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4573
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Stream.Stream<unknown, never, any>, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & StreamInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
|
|
4574
|
-
readonly onElement: StreamElementHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4575
|
-
readonly onDone: StreamDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId>;
|
|
4576
|
-
readonly onFailure?: never;
|
|
4577
|
-
}): NoInfer<Config> & StreamInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4578
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId, InputEvents, ParentEvents>): NoInfer<Config> & Machine.InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & Machine.InvokeTyped<void, never, never, never>;
|
|
4579
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => unknown, Address extends ChildAddress<never>, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & {
|
|
4580
|
-
readonly logic: Source;
|
|
4581
|
-
} & Machine.LogicInvokeArgs<States, Events, Emits, StateId, Machine.LogicStateOf<ReturnType<Source>>, Machine.LogicEventOf<ReturnType<Source>>, Machine.LogicErrorOf<ReturnType<Source>>, Machine.LogicServicesOf<ReturnType<Source>>, Machine.LogicOutputOf<ReturnType<Source>>, Machine.LogicInitialErrorOf<ReturnType<Source>>, Address, Source, InputEvents, ParentEvents>, ..._validation: ReturnType<Source> extends {
|
|
4582
|
-
readonly initial: unknown;
|
|
4583
|
-
readonly run: unknown;
|
|
4584
|
-
} ? [] : [
|
|
4585
|
-
"logic factory must return Machine.Logic"
|
|
4586
|
-
]): NoInfer<Config> & Machine.InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & Machine.InvokeTyped<Machine.LogicOutputOf<ReturnType<Source>>, Machine.LogicErrorOf<ReturnType<Source>>, Machine.LogicServicesOf<ReturnType<Source>>, Machine.LogicInitialErrorOf<ReturnType<Source>>>;
|
|
4587
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source, Address extends ChildAddress<never>, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & {
|
|
4588
|
-
readonly logic: Source;
|
|
4589
|
-
} & Machine.LogicInvokeArgs<States, Events, Emits, StateId, Machine.LogicStateOf<Source>, Machine.LogicEventOf<Source>, Machine.LogicErrorOf<Source>, Machine.LogicServicesOf<Source>, Machine.LogicOutputOf<Source>, Machine.LogicInitialErrorOf<Source>, Address, Source, InputEvents, ParentEvents>, ..._validation: Source extends {
|
|
4590
|
-
readonly initial: unknown;
|
|
4591
|
-
readonly run: unknown;
|
|
4592
|
-
} ? [] : [
|
|
4593
|
-
"logic must implement Machine.Logic"
|
|
4594
|
-
]): NoInfer<Config> & Machine.InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & Machine.InvokeTyped<Machine.LogicOutputOf<Source>, Machine.LogicErrorOf<Source>, Machine.LogicServicesOf<Source>, Machine.LogicInitialErrorOf<Source>>;
|
|
4595
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Child extends ChildMachine.Any, const Config extends object, const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Config & Machine.ChildInvokeArgs<States, Events, Emits, StateId, Child["machine"], Child, InputEvents, ParentEvents>): Config & Machine.InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & Machine.InvokeTyped<Machine.Output<Child["machine"]>, Machine.Error<Child["machine"]> | ActionError<Machine.Services<Child["machine"]>>, Machine.Services<Child["machine"]>, Machine.InitialError<Child["machine"]>, Machine.Emit<Child["machine"]>, Machine.EventOf<Machine.ParentEvents<Child["machine"]>>>;
|
|
4596
|
-
};
|
|
4597
4733
|
/**
|
|
4598
4734
|
* Plans the initial state for a machine without executing machine commands.
|
|
4599
4735
|
*
|
|
@@ -4857,7 +4993,7 @@ export declare const child: <const Id extends string, M extends Machine.Any>(id:
|
|
|
4857
4993
|
* Creates a typed parent-local address for lower-level child process logic.
|
|
4858
4994
|
*
|
|
4859
4995
|
* The default event protocol is `never`; provide an event type before using
|
|
4860
|
-
* the address with `spawn`,
|
|
4996
|
+
* the address with `spawn`, a state-owned logic invocation, or `sendTo`.
|
|
4861
4997
|
*
|
|
4862
4998
|
* @category constructors
|
|
4863
4999
|
* @since 0.4.0
|
|
@@ -4877,7 +5013,8 @@ export declare const childAddress: <Event = never>(id: string) => ChildAddress<E
|
|
|
4877
5013
|
* This Effect requires a managed process runtime. A named child id must be
|
|
4878
5014
|
* unique for the current parent until that child stops.
|
|
4879
5015
|
*
|
|
4880
|
-
*
|
|
5016
|
+
* Use a state's `invoke: (from) => from.logic(...)` declaration for children
|
|
5017
|
+
* that start and stop with that state.
|
|
4881
5018
|
* @see {@link sendTo} for sending events to named children.
|
|
4882
5019
|
* @category runtime
|
|
4883
5020
|
* @since 0.4.0
|