xstate 5.32.0 → 6.0.0-alpha.1
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 +7 -8
- package/dist/StateMachine-47e60715.esm.js +720 -0
- package/dist/StateMachine-48dcad8f.cjs.js +723 -0
- package/dist/StateMachine-6e063ac1.development.cjs.js +740 -0
- package/dist/StateMachine-6ec50e21.development.esm.js +737 -0
- package/dist/declarations/src/State.d.ts +11 -13
- package/dist/declarations/src/StateMachine.d.ts +27 -21
- package/dist/declarations/src/StateNode.d.ts +18 -54
- package/dist/declarations/src/actions.d.ts +14 -9
- package/dist/declarations/src/actors/callback.d.ts +42 -16
- package/dist/declarations/src/actors/index.d.ts +9 -6
- package/dist/declarations/src/actors/listener.d.ts +18 -0
- package/dist/declarations/src/actors/logic.d.ts +105 -0
- package/dist/declarations/src/actors/observable.d.ts +72 -27
- package/dist/declarations/src/actors/promise.d.ts +133 -48
- package/dist/declarations/src/actors/subscription.d.ts +22 -0
- package/dist/declarations/src/atom.d.ts +81 -0
- package/dist/declarations/src/createActor.d.ts +31 -33
- package/dist/declarations/src/createMachine.d.ts +35 -7
- package/dist/declarations/src/createMachineFromConfig.d.ts +176 -0
- package/dist/declarations/src/graph/graph.d.ts +4 -2
- package/dist/declarations/src/index.d.ts +12 -8
- package/dist/declarations/src/inspection.d.ts +84 -30
- package/dist/declarations/src/mapState.d.ts +4 -2
- package/dist/declarations/src/schema.types.d.ts +90 -0
- package/dist/declarations/src/serialize.d.ts +44 -0
- package/dist/declarations/src/setup.d.ts +251 -123
- package/dist/declarations/src/spawn.d.ts +6 -31
- package/dist/declarations/src/stateUtils.d.ts +21 -19
- package/dist/declarations/src/system.d.ts +8 -7
- package/dist/declarations/src/transition.d.ts +5 -5
- package/dist/declarations/src/types.d.ts +407 -406
- package/dist/declarations/src/types.v6.d.ts +392 -0
- package/dist/declarations/src/utils.d.ts +4 -3
- package/dist/index-39259ea4.development.esm.js +4948 -0
- package/dist/index-688701ed.esm.js +4909 -0
- package/dist/index-c35824b4.development.cjs.js +5007 -0
- package/dist/index-f0d7107d.cjs.js +4968 -0
- package/dist/xstate-actors.cjs.js +12 -838
- package/dist/xstate-actors.cjs.mjs +10 -5
- package/dist/xstate-actors.development.cjs.js +12 -838
- package/dist/xstate-actors.development.cjs.mjs +10 -5
- package/dist/xstate-actors.development.esm.js +1 -836
- package/dist/xstate-actors.esm.js +1 -836
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +18 -29
- package/dist/xstate-graph.development.cjs.js +18 -29
- package/dist/xstate-graph.development.esm.js +15 -26
- package/dist/xstate-graph.esm.js +15 -26
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +1316 -108
- package/dist/xstate.cjs.mjs +22 -22
- package/dist/xstate.development.cjs.js +1316 -108
- package/dist/xstate.development.cjs.mjs +22 -22
- package/dist/xstate.development.esm.js +1278 -72
- package/dist/xstate.esm.js +1278 -72
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +3 -47
- package/dist/StateMachine-45e79c35.esm.js +0 -560
- package/dist/StateMachine-be2e51a3.development.cjs.js +0 -569
- package/dist/StateMachine-e0178d48.development.esm.js +0 -566
- package/dist/StateMachine-e6732977.cjs.js +0 -563
- package/dist/assign-2aa58daa.esm.js +0 -127
- package/dist/assign-927227d6.development.cjs.js +0 -135
- package/dist/assign-e8f2bd75.cjs.js +0 -129
- package/dist/assign-f338cee3.development.esm.js +0 -133
- package/dist/declarations/src/actions/assign.d.ts +0 -45
- package/dist/declarations/src/actions/cancel.d.ts +0 -39
- package/dist/declarations/src/actions/emit.d.ts +0 -44
- package/dist/declarations/src/actions/enqueueActions.d.ts +0 -57
- package/dist/declarations/src/actions/log.d.ts +0 -16
- package/dist/declarations/src/actions/raise.d.ts +0 -21
- package/dist/declarations/src/actions/send.d.ts +0 -42
- package/dist/declarations/src/actions/spawnChild.d.ts +0 -34
- package/dist/declarations/src/actions/stopChild.d.ts +0 -19
- package/dist/declarations/src/actors/transition.d.ts +0 -143
- package/dist/declarations/src/dev/index.d.ts +0 -14
- package/dist/declarations/src/guards.d.ts +0 -128
- package/dist/log-029f180b.development.cjs.js +0 -433
- package/dist/log-5a37e0ee.development.esm.js +0 -425
- package/dist/log-605ef461.esm.js +0 -397
- package/dist/log-fedf0966.cjs.js +0 -405
- package/dist/raise-74097812.development.esm.js +0 -2823
- package/dist/raise-7c948725.cjs.js +0 -2816
- package/dist/raise-964cd4e9.development.cjs.js +0 -2878
- package/dist/raise-e974d1c9.esm.js +0 -2761
- package/dist/xstate-actions.cjs.d.mts +0 -2
- package/dist/xstate-actions.cjs.d.ts +0 -2
- package/dist/xstate-actions.cjs.js +0 -23
- package/dist/xstate-actions.cjs.mjs +0 -14
- package/dist/xstate-actions.development.cjs.js +0 -23
- package/dist/xstate-actions.development.cjs.mjs +0 -14
- package/dist/xstate-actions.development.esm.js +0 -4
- package/dist/xstate-actions.esm.js +0 -4
- package/dist/xstate-actions.umd.min.js +0 -2
- package/dist/xstate-actions.umd.min.js.map +0 -1
- package/dist/xstate-dev.cjs.d.mts +0 -2
- package/dist/xstate-dev.cjs.d.ts +0 -2
- package/dist/xstate-dev.cjs.js +0 -48
- package/dist/xstate-dev.cjs.mjs +0 -5
- package/dist/xstate-dev.development.cjs.js +0 -51
- package/dist/xstate-dev.development.cjs.mjs +0 -5
- package/dist/xstate-dev.development.esm.js +0 -45
- package/dist/xstate-dev.esm.js +0 -42
- package/dist/xstate-dev.umd.min.js +0 -2
- package/dist/xstate-dev.umd.min.js.map +0 -1
- package/dist/xstate-guards.cjs.d.mts +0 -2
- package/dist/xstate-guards.cjs.d.ts +0 -2
- package/dist/xstate-guards.cjs.js +0 -14
- package/dist/xstate-guards.cjs.mjs +0 -7
- package/dist/xstate-guards.development.cjs.js +0 -14
- package/dist/xstate-guards.development.cjs.mjs +0 -7
- package/dist/xstate-guards.development.esm.js +0 -2
- package/dist/xstate-guards.esm.js +0 -2
- package/dist/xstate-guards.umd.min.js +0 -2
- package/dist/xstate-guards.umd.min.js.map +0 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { MachineSnapshot } from "./State.js";
|
|
2
2
|
import type { StateMachine } from "./StateMachine.js";
|
|
3
3
|
import type { StateNode } from "./StateNode.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ExecutableSendToAction } from "./actions/send.js";
|
|
7
|
-
import { PromiseActorLogic } from "./actors/promise.js";
|
|
4
|
+
import { AsyncActorLogic } from "./actors/promise.js";
|
|
5
|
+
import type { BaseAtom } from "./atom.js";
|
|
8
6
|
import type { Actor } from "./createActor.js";
|
|
9
|
-
import { Guard, GuardPredicate, UnknownGuard } from "./guards.js";
|
|
10
7
|
import { InspectionEvent } from "./inspection.js";
|
|
11
8
|
import { Spawner } from "./spawn.js";
|
|
12
9
|
import { AnyActorSystem, Clock } from "./system.js";
|
|
10
|
+
import { Implementations, Next_StateNodeConfig } from "./types.v6.js";
|
|
11
|
+
import { StandardSchemaV1 } from "./schema.types.js";
|
|
12
|
+
import { builtInActions } from "./actions.js";
|
|
13
13
|
export type Identity<T> = {
|
|
14
14
|
[K in keyof T]: T[K];
|
|
15
15
|
};
|
|
@@ -57,6 +57,7 @@ export type IndexByProp<T extends Record<P, string>, P extends keyof T> = {
|
|
|
57
57
|
export type IndexByType<T extends {
|
|
58
58
|
type: string;
|
|
59
59
|
}> = IndexByProp<T, 'type'>;
|
|
60
|
+
export type IsEmptyObject<T> = keyof T extends never ? true : false;
|
|
60
61
|
export type Equals<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
|
|
61
62
|
export type IsAny<T> = Equals<T, any>;
|
|
62
63
|
export type Cast<A, B> = A extends B ? A : B;
|
|
@@ -82,29 +83,21 @@ export interface ParameterizedObject {
|
|
|
82
83
|
export interface UnifiedArg<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> {
|
|
83
84
|
context: TContext;
|
|
84
85
|
event: TExpressionEvent;
|
|
85
|
-
self:
|
|
86
|
+
self: ActorSelf<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>, // TODO: this should be replaced with `TChildren`
|
|
86
87
|
StateValue, string, unknown, TODO, // TMeta
|
|
87
88
|
TODO>, TEvent, AnyEventObject>;
|
|
88
89
|
system: AnyActorSystem;
|
|
89
90
|
}
|
|
90
91
|
export type MachineContext = Record<string, any>;
|
|
91
92
|
export interface ActionArgs<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> extends UnifiedArg<TContext, TExpressionEvent, TEvent> {
|
|
93
|
+
children: Record<string, AnyActor>;
|
|
92
94
|
}
|
|
93
|
-
export type InputFrom<T> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer
|
|
95
|
+
export type InputFrom<T> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TStateSchema, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TInput : T extends ActorLogic<infer _TSnapshot, infer _TEvent, infer TInput, infer _TSystem, infer _TEmitted> ? TInput : never;
|
|
94
96
|
export type OutputFrom<T> = T extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? (TSnapshot & {
|
|
95
97
|
status: 'done';
|
|
96
98
|
})['output'] : T extends ActorRef<infer TSnapshot, infer _TEvent, infer _TEmitted> ? (TSnapshot & {
|
|
97
99
|
status: 'done';
|
|
98
100
|
})['output'] : never;
|
|
99
|
-
export type ActionFunction<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> = {
|
|
100
|
-
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
101
|
-
_out_TEvent?: TEvent;
|
|
102
|
-
_out_TActor?: TActor;
|
|
103
|
-
_out_TAction?: TAction;
|
|
104
|
-
_out_TGuard?: TGuard;
|
|
105
|
-
_out_TDelay?: TDelay;
|
|
106
|
-
_out_TEmitted?: TEmitted;
|
|
107
|
-
};
|
|
108
101
|
export type NoRequiredParams<T extends ParameterizedObject> = T extends any ? undefined extends T['params'] ? T['type'] : never : never;
|
|
109
102
|
export type ConditionalRequired<T, Condition extends boolean> = Condition extends true ? Required<T> : T;
|
|
110
103
|
export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent extends EventObject, T extends ParameterizedObject> = T extends any ? ConditionalRequired<{
|
|
@@ -114,9 +107,6 @@ export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent
|
|
|
114
107
|
event: TExpressionEvent;
|
|
115
108
|
}) => T['params']);
|
|
116
109
|
}, undefined extends T['params'] ? false : true> : never;
|
|
117
|
-
export type Action<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> = NoRequiredParams<TAction> | WithDynamicParams<TContext, TExpressionEvent, TAction> | ActionFunction<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
118
|
-
export type UnknownAction = Action<MachineContext, EventObject, EventObject, ParameterizedObject['params'] | undefined, ProvidedActor, ParameterizedObject, ParameterizedObject, string, EventObject>;
|
|
119
|
-
export type Actions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> = SingleOrArray<Action<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay, TEmitted>>;
|
|
120
110
|
export type StateKey = string | AnyMachineSnapshot;
|
|
121
111
|
export interface StateValueMap {
|
|
122
112
|
[key: string]: StateValue | undefined;
|
|
@@ -132,30 +122,36 @@ export interface StateValueMap {
|
|
|
132
122
|
*/
|
|
133
123
|
export type StateValue = string | StateValueMap;
|
|
134
124
|
export type TransitionTarget = SingleOrArray<string>;
|
|
135
|
-
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject,
|
|
136
|
-
|
|
137
|
-
|
|
125
|
+
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
126
|
+
actions?: never;
|
|
127
|
+
guard?: unknown;
|
|
138
128
|
reenter?: boolean;
|
|
139
129
|
target?: TransitionTarget | undefined;
|
|
130
|
+
to?: TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
140
131
|
meta?: TMeta;
|
|
141
132
|
description?: string;
|
|
142
133
|
}
|
|
143
|
-
export interface InitialTransitionConfig<TContext extends MachineContext, TEvent extends EventObject,
|
|
144
|
-
TODO> {
|
|
134
|
+
export interface InitialTransitionConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> extends TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> {
|
|
145
135
|
target: string;
|
|
146
136
|
}
|
|
147
137
|
export type AnyTransitionConfig = TransitionConfig<any, // TContext
|
|
148
138
|
any, // TExpressionEvent
|
|
149
139
|
any, // TEvent
|
|
150
|
-
any, // TActor
|
|
151
|
-
any, // TAction
|
|
152
|
-
any, // TGuard
|
|
153
|
-
any, // TDelay
|
|
154
140
|
any, // TEmitted
|
|
141
|
+
any, // TMeta
|
|
142
|
+
any, // TActionMap
|
|
143
|
+
any, // TActorMap
|
|
144
|
+
any, // TGuardMap
|
|
155
145
|
any>;
|
|
156
|
-
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject,
|
|
146
|
+
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
157
147
|
id: string;
|
|
158
148
|
systemId: string | undefined;
|
|
149
|
+
logic: string | AnyActorLogic | (({ actors, context, event, self }: {
|
|
150
|
+
actors: TActorMap;
|
|
151
|
+
context: TContext;
|
|
152
|
+
event: TEvent;
|
|
153
|
+
self: AnyActorRef;
|
|
154
|
+
}) => string | AnyActorLogic);
|
|
159
155
|
/** The source of the actor logic to be invoked */
|
|
160
156
|
src: AnyActorLogic | string;
|
|
161
157
|
input?: Mapper<TContext, TEvent, NonReducibleUnknown, TEvent> | NonReducibleUnknown;
|
|
@@ -163,46 +159,78 @@ export interface InvokeDefinition<TContext extends MachineContext, TEvent extend
|
|
|
163
159
|
* The transition to take upon the invoked child machine reaching its final
|
|
164
160
|
* top-level state.
|
|
165
161
|
*/
|
|
166
|
-
onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneActorEvent<unknown>, TEvent,
|
|
162
|
+
onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneActorEvent<unknown>, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>>;
|
|
167
163
|
/**
|
|
168
164
|
* The transition to take upon the invoked child machine sending an error
|
|
169
165
|
* event.
|
|
170
166
|
*/
|
|
171
|
-
onError?: string | SingleOrArray<TransitionConfig<TContext, ErrorActorEvent, TEvent,
|
|
172
|
-
onSnapshot?: string | SingleOrArray<TransitionConfig<TContext, SnapshotEvent, TEvent,
|
|
173
|
-
|
|
167
|
+
onError?: string | SingleOrArray<TransitionConfig<TContext, ErrorActorEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>>;
|
|
168
|
+
onSnapshot?: string | SingleOrArray<TransitionConfig<TContext, SnapshotEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>>;
|
|
169
|
+
/**
|
|
170
|
+
* The duration (in ms) after which this invocation times out if it has not
|
|
171
|
+
* completed.
|
|
172
|
+
*/
|
|
173
|
+
timeout?: number | ((args: {
|
|
174
|
+
context: TContext;
|
|
175
|
+
event: TEvent;
|
|
176
|
+
}) => number);
|
|
177
|
+
/** The transition to take when the invoke-level `timeout` expires. */
|
|
178
|
+
onTimeout?: string | SingleOrArray<TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>>;
|
|
174
179
|
}
|
|
180
|
+
export type AnyInvokeDefinition = InvokeDefinition<MachineContext, EventObject, EventObject, MetaObject, Implementations['actions'], Implementations['actors'], Implementations['guards'], Implementations['delays']>;
|
|
175
181
|
type Delay<TDelay extends string> = TDelay | number;
|
|
176
|
-
export type DelayedTransitions<TContext extends MachineContext, TEvent extends EventObject,
|
|
177
|
-
[K in Delay<
|
|
178
|
-
TODO>>;
|
|
182
|
+
export type DelayedTransitions<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
183
|
+
[K in Delay<keyof TDelayMap & string>]?: string | SingleOrArray<TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>> | TransitionConfigFunction<TContext, TEvent, TEvent, TODO, any, any, any, any, any>;
|
|
179
184
|
};
|
|
180
|
-
export type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | ({} & string);
|
|
185
|
+
export type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'choice' | 'history' | ({} & string);
|
|
181
186
|
export type SingleOrArray<T> = readonly T[] | T;
|
|
182
187
|
export type StateNodesConfig<TContext extends MachineContext, TEvent extends EventObject> = {
|
|
183
188
|
[K in string]: StateNode<TContext, TEvent>;
|
|
184
189
|
};
|
|
185
|
-
export type StatesConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TOutput, TEmitted extends EventObject, TMeta extends MetaObject> = {
|
|
186
|
-
[K in string]: StateNodeConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TOutput, TEmitted, TMeta>;
|
|
187
|
-
};
|
|
188
|
-
export type StatesDefinition<TContext extends MachineContext, TEvent extends EventObject> = {
|
|
189
|
-
[K in string]: StateNodeDefinition<TContext, TEvent>;
|
|
190
|
-
};
|
|
191
190
|
export type TransitionConfigTarget = string | undefined;
|
|
192
|
-
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject,
|
|
193
|
-
export type
|
|
194
|
-
|
|
191
|
+
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = SingleOrArray<TransitionConfigTarget | TransitionConfig<TContext, TExpressionEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> | TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>>;
|
|
192
|
+
export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, _TCtx = [TContext] extends [never] ? any : TContext> = ({ context, event, self, parent, value, children, actions }: {
|
|
193
|
+
context: _TCtx;
|
|
194
|
+
event: TCurrentEvent;
|
|
195
|
+
self: ActorSelf<MachineSnapshot<_TCtx & MachineContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO>, TEvent>;
|
|
196
|
+
parent: UnknownActorRef | undefined;
|
|
197
|
+
value: StateValue;
|
|
198
|
+
children: Record<string, AnyActor>;
|
|
199
|
+
actions: TActionMap;
|
|
200
|
+
actors: TActorMap;
|
|
201
|
+
guards: TGuardMap;
|
|
202
|
+
delays: TDelayMap;
|
|
203
|
+
}, enq: EnqueueObject<TEvent, TEmitted>) => {
|
|
204
|
+
target?: string | string[];
|
|
205
|
+
context?: _TCtx;
|
|
206
|
+
reenter?: boolean;
|
|
207
|
+
meta?: TMeta;
|
|
208
|
+
} | void;
|
|
209
|
+
export type AnyTransitionConfigFunction = TransitionConfigFunction<any, any, any, any, any, any, any, any, any>;
|
|
210
|
+
export type TransitionsConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
211
|
+
[K in EventDescriptor<TEvent>]?: TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
195
212
|
};
|
|
196
213
|
type PartialEventDescriptor<TEventType extends string> = TEventType extends `${infer TLeading}.${infer TTail}` ? `${TLeading}.*` | `${TLeading}.${PartialEventDescriptor<TTail>}` : never;
|
|
197
214
|
export type EventDescriptor<TEvent extends EventObject> = TEvent['type'] | PartialEventDescriptor<TEvent['type']> | '*';
|
|
198
|
-
type NormalizeDescriptor<TDescriptor extends string> = TDescriptor extends '*' ? string : TDescriptor extends `${infer TLeading}.*` ? `${TLeading}.${string}` : TDescriptor;
|
|
215
|
+
export type NormalizeDescriptor<TDescriptor extends string> = TDescriptor extends '*' ? string : TDescriptor extends `${infer TLeading}.*` ? `${TLeading}.${string}` : TDescriptor;
|
|
216
|
+
type EventTypeMatchesDescriptor<TEventType extends string, TDescriptor extends string> = TEventType extends NormalizeDescriptor<TDescriptor> ? true : false;
|
|
217
|
+
type IsInternalEventType<TEventType extends string, TDescriptors extends string> = true extends (TDescriptors extends any ? EventTypeMatchesDescriptor<TEventType, TDescriptors> : never) ? true : false;
|
|
218
|
+
type ExcludeInternalEvents<TEvent extends EventObject, TDescriptors extends string> = TEvent extends any ? IsInternalEventType<TEvent['type'], TDescriptors> extends true ? never : TEvent : never;
|
|
199
219
|
export type IsLiteralString<T extends string> = string extends T ? false : true;
|
|
200
|
-
type
|
|
220
|
+
type ActorImplementationsBySrc<TActor extends ProvidedActor> = {
|
|
221
|
+
[A in TActor as A['src']]: A['logic'];
|
|
222
|
+
};
|
|
223
|
+
type DistributeActors<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, _TAction extends ParameterizedObject, _TGuard extends ParameterizedObject, _TDelay extends string, TEmitted extends EventObject, TMeta extends MetaObject, TSpecificActor extends ProvidedActor> = TSpecificActor extends {
|
|
201
224
|
src: infer TSrc;
|
|
202
225
|
} ? Compute<{
|
|
203
226
|
systemId?: string;
|
|
204
227
|
/** The source of the machine to be invoked, or the machine itself. */
|
|
205
|
-
src: TSrc
|
|
228
|
+
src: TSrc | (({ actors, context, event, self }: {
|
|
229
|
+
actors: ActorImplementationsBySrc<TActor>;
|
|
230
|
+
context: TContext;
|
|
231
|
+
event: TEvent;
|
|
232
|
+
self: AnyActorRef;
|
|
233
|
+
}) => TSrc | TSpecificActor['logic']);
|
|
206
234
|
/**
|
|
207
235
|
* The unique identifier for the invoked machine. If not specified,
|
|
208
236
|
* this will be the machine's own `id`, or the URL (from `src`).
|
|
@@ -213,23 +241,38 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
213
241
|
* The transition to take upon the invoked child machine reaching
|
|
214
242
|
* its final top-level state.
|
|
215
243
|
*/
|
|
216
|
-
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<OutputFrom<TSpecificActor['logic']>>, TEvent,
|
|
244
|
+
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<OutputFrom<TSpecificActor['logic']>>, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
217
245
|
/**
|
|
218
246
|
* The transition to take upon the invoked child machine sending an
|
|
219
247
|
* error event.
|
|
220
248
|
*/
|
|
221
|
-
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent,
|
|
222
|
-
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent<SnapshotFrom<TSpecificActor['logic']>>, TEvent,
|
|
249
|
+
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
250
|
+
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent<SnapshotFrom<TSpecificActor['logic']>>, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
251
|
+
timeout?: number | ((args: {
|
|
252
|
+
context: TContext;
|
|
253
|
+
event: TEvent;
|
|
254
|
+
}) => number);
|
|
255
|
+
onTimeout?: string | SingleOrArray<TransitionConfigOrTarget<TContext, TEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
223
256
|
} & {
|
|
224
257
|
[K in RequiredActorOptions<TSpecificActor>]: unknown;
|
|
225
258
|
}> | {
|
|
226
259
|
id?: never;
|
|
227
260
|
systemId?: string;
|
|
228
|
-
src: AnyActorLogic
|
|
261
|
+
src: string | AnyActorLogic | (({ actors, context, event, self }: {
|
|
262
|
+
actors: ActorImplementationsBySrc<TActor>;
|
|
263
|
+
context: TContext;
|
|
264
|
+
event: TEvent;
|
|
265
|
+
self: AnyActorRef;
|
|
266
|
+
}) => string | AnyActorLogic);
|
|
229
267
|
input?: Mapper<TContext, TEvent, NonReducibleUnknown, TEvent> | NonReducibleUnknown;
|
|
230
|
-
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<unknown>, TEvent,
|
|
231
|
-
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent,
|
|
232
|
-
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent,
|
|
268
|
+
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<unknown>, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
269
|
+
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
270
|
+
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
271
|
+
timeout?: number | ((args: {
|
|
272
|
+
context: TContext;
|
|
273
|
+
event: TEvent;
|
|
274
|
+
}) => number);
|
|
275
|
+
onTimeout?: string | SingleOrArray<TransitionConfigOrTarget<TContext, TEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
233
276
|
} : never;
|
|
234
277
|
export type InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject, TMeta extends MetaObject> = IsLiteralString<TActor['src']> extends true ? DistributeActors<TContext, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta, TActor> : {
|
|
235
278
|
/**
|
|
@@ -239,260 +282,61 @@ export type InvokeConfig<TContext extends MachineContext, TEvent extends EventOb
|
|
|
239
282
|
id?: string;
|
|
240
283
|
systemId?: string;
|
|
241
284
|
/** The source of the machine to be invoked, or the machine itself. */
|
|
242
|
-
src: AnyActorLogic |
|
|
285
|
+
src: string | AnyActorLogic | (({ actors, context, event, self }: {
|
|
286
|
+
actors: ActorImplementationsBySrc<TActor>;
|
|
287
|
+
context: TContext;
|
|
288
|
+
event: TEvent;
|
|
289
|
+
self: AnyActorRef;
|
|
290
|
+
}) => string | AnyActorLogic);
|
|
243
291
|
input?: Mapper<TContext, TEvent, NonReducibleUnknown, TEvent> | NonReducibleUnknown;
|
|
244
292
|
/**
|
|
245
293
|
* The transition to take upon the invoked child machine reaching its
|
|
246
294
|
* final top-level state.
|
|
247
295
|
*/
|
|
248
|
-
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<
|
|
249
|
-
TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
296
|
+
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<unknown>, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
250
297
|
/**
|
|
251
298
|
* The transition to take upon the invoked child machine sending an
|
|
252
299
|
* error event.
|
|
253
300
|
*/
|
|
254
|
-
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent,
|
|
255
|
-
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent,
|
|
301
|
+
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
302
|
+
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
303
|
+
timeout?: number | ((args: {
|
|
304
|
+
context: TContext;
|
|
305
|
+
event: TEvent;
|
|
306
|
+
}) => number);
|
|
307
|
+
onTimeout?: string | SingleOrArray<TransitionConfigOrTarget<TContext, TEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
256
308
|
};
|
|
257
309
|
export type AnyInvokeConfig = InvokeConfig<any, any, any, any, any, any, any, any>;
|
|
258
|
-
export
|
|
259
|
-
|
|
260
|
-
initial?: InitialTransitionConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay> | string | undefined;
|
|
261
|
-
/**
|
|
262
|
-
* The type of this state node:
|
|
263
|
-
*
|
|
264
|
-
* - `'atomic'` - no child state nodes
|
|
265
|
-
* - `'compound'` - nested child state nodes (XOR)
|
|
266
|
-
* - `'parallel'` - orthogonal nested child state nodes (AND)
|
|
267
|
-
* - `'history'` - history state node
|
|
268
|
-
* - `'final'` - final state node
|
|
269
|
-
*/
|
|
270
|
-
type?: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
|
|
271
|
-
/**
|
|
272
|
-
* Indicates whether the state node is a history state node, and what type of
|
|
273
|
-
* history: shallow, deep, true (shallow), false (none), undefined (none)
|
|
274
|
-
*/
|
|
275
|
-
history?: 'shallow' | 'deep' | boolean | undefined;
|
|
276
|
-
/**
|
|
277
|
-
* The mapping of state node keys to their state node configurations
|
|
278
|
-
* (recursive).
|
|
279
|
-
*/
|
|
280
|
-
states?: StatesConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, NonReducibleUnknown, TEmitted, TMeta> | undefined;
|
|
281
|
-
/**
|
|
282
|
-
* The services to invoke upon entering this state node. These services will
|
|
283
|
-
* be stopped upon exiting this state node.
|
|
284
|
-
*/
|
|
285
|
-
invoke?: SingleOrArray<InvokeConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
286
|
-
/** The mapping of event types to their potential transition(s). */
|
|
287
|
-
on?: TransitionsConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>;
|
|
288
|
-
/** The action(s) to be executed upon entering the state node. */
|
|
289
|
-
entry?: Actions<TContext, TEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
290
|
-
/** The action(s) to be executed upon exiting the state node. */
|
|
291
|
-
exit?: Actions<TContext, TEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
292
|
-
/**
|
|
293
|
-
* The potential transition(s) to be taken upon reaching a final child state
|
|
294
|
-
* node.
|
|
295
|
-
*
|
|
296
|
-
* This is equivalent to defining a `[done(id)]` transition on this state
|
|
297
|
-
* node's `on` property.
|
|
298
|
-
*/
|
|
299
|
-
onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneStateEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>> | undefined;
|
|
300
|
-
/**
|
|
301
|
-
* The mapping (or array) of delays (in milliseconds) to their potential
|
|
302
|
-
* transition(s). The delayed transitions are taken after the specified delay
|
|
303
|
-
* in an interpreter.
|
|
304
|
-
*/
|
|
305
|
-
after?: DelayedTransitions<TContext, TEvent, TActor, TAction, TGuard, TDelay>;
|
|
306
|
-
/**
|
|
307
|
-
* An eventless transition that is always taken when this state node is
|
|
308
|
-
* active.
|
|
309
|
-
*/
|
|
310
|
-
always?: TransitionConfigOrTarget<TContext, TEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>;
|
|
311
|
-
parent?: StateNode<TContext, TEvent>;
|
|
312
|
-
/**
|
|
313
|
-
* The meta data associated with this state node, which will be returned in
|
|
314
|
-
* State instances.
|
|
315
|
-
*/
|
|
316
|
-
meta?: TMeta;
|
|
317
|
-
/**
|
|
318
|
-
* The output data sent with the "xstate.done.state._id_" event if this is a
|
|
319
|
-
* final state node.
|
|
320
|
-
*
|
|
321
|
-
* The output data will be evaluated with the current `context` and placed on
|
|
322
|
-
* the `.data` property of the event.
|
|
323
|
-
*/
|
|
324
|
-
output?: Mapper<TContext, TEvent, unknown, TEvent> | NonReducibleUnknown;
|
|
325
|
-
/**
|
|
326
|
-
* The unique ID of the state node, which can be referenced as a transition
|
|
327
|
-
* target via the `#id` syntax.
|
|
328
|
-
*/
|
|
329
|
-
id?: string | undefined;
|
|
330
|
-
/**
|
|
331
|
-
* The order this state node appears. Corresponds to the implicit document
|
|
332
|
-
* order.
|
|
333
|
-
*/
|
|
334
|
-
order?: number;
|
|
335
|
-
/**
|
|
336
|
-
* The tags for this state node, which are accumulated into the `state.tags`
|
|
337
|
-
* property.
|
|
338
|
-
*/
|
|
339
|
-
tags?: SingleOrArray<TTag>;
|
|
340
|
-
/** A text description of the state node */
|
|
341
|
-
description?: string;
|
|
342
|
-
/** A default target for a history state */
|
|
343
|
-
target?: string | undefined;
|
|
344
|
-
route?: RouteTransitionConfig<TContext, TEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
345
|
-
}
|
|
346
|
-
export interface RouteTransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject> {
|
|
347
|
-
guard?: Guard<TContext, TExpressionEvent, undefined, TGuard>;
|
|
348
|
-
actions?: Actions<TContext, TExpressionEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
349
|
-
meta?: Record<string, any>;
|
|
350
|
-
description?: string;
|
|
351
|
-
}
|
|
352
|
-
export type AnyStateNodeConfig = StateNodeConfig<any, any, any, any, any, any, any, any, any, // emitted
|
|
353
|
-
any>;
|
|
354
|
-
export interface StateNodeDefinition<TContext extends MachineContext, TEvent extends EventObject> {
|
|
355
|
-
id: string;
|
|
356
|
-
version?: string | undefined;
|
|
357
|
-
key: string;
|
|
358
|
-
type: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
|
|
359
|
-
initial: InitialTransitionDefinition<TContext, TEvent> | undefined;
|
|
360
|
-
history: boolean | 'shallow' | 'deep' | undefined;
|
|
361
|
-
states: StatesDefinition<TContext, TEvent>;
|
|
362
|
-
on: TransitionDefinitionMap<TContext, TEvent>;
|
|
363
|
-
transitions: Array<TransitionDefinition<TContext, TEvent>>;
|
|
364
|
-
entry: UnknownAction[];
|
|
365
|
-
exit: UnknownAction[];
|
|
366
|
-
meta: any;
|
|
367
|
-
order: number;
|
|
368
|
-
output?: StateNodeConfig<TContext, TEvent, ProvidedActor, ParameterizedObject, ParameterizedObject, string, string, unknown, EventObject, // TEmitted
|
|
369
|
-
any>['output'];
|
|
370
|
-
invoke: Array<InvokeDefinition<TContext, TEvent, TODO, TODO, TODO, TODO, TODO, // TEmitted
|
|
371
|
-
TODO>>;
|
|
372
|
-
description?: string;
|
|
373
|
-
tags: string[];
|
|
374
|
-
}
|
|
375
|
-
export interface StateMachineDefinition<TContext extends MachineContext, TEvent extends EventObject> extends StateNodeDefinition<TContext, TEvent> {
|
|
376
|
-
}
|
|
377
|
-
export type AnyStateNode = StateNode<any, any>;
|
|
378
|
-
export type AnyStateNodeDefinition = StateNodeDefinition<any, any>;
|
|
310
|
+
export type AnyStateNodeConfig = Next_StateNodeConfig<any, any, any, any, any, any, any, any, any, any, any>;
|
|
311
|
+
export type AnyStateNode = StateNode<any, any> | StateNode<never, EventObject> | StateNode<any, EventObject> | StateNode<never, any>;
|
|
379
312
|
export type AnyMachineSnapshot = MachineSnapshot<any, any, any, any, any, any, any, any>;
|
|
380
|
-
/** @deprecated Use `AnyMachineSnapshot` instead */
|
|
381
|
-
export type AnyState = AnyMachineSnapshot;
|
|
382
313
|
export type AnyStateMachine = StateMachine<any, // context
|
|
383
314
|
any, // event
|
|
384
315
|
any, // children
|
|
385
|
-
any, // actor
|
|
386
|
-
any, // action
|
|
387
|
-
any, // guard
|
|
388
|
-
any, // delay
|
|
389
316
|
any, // state value
|
|
390
317
|
any, // tag
|
|
391
318
|
any, // input
|
|
392
319
|
any, // output
|
|
393
320
|
any, // emitted
|
|
394
321
|
any, // TMeta
|
|
322
|
+
any, // TStateSchema,
|
|
323
|
+
any, // TActionMap,
|
|
324
|
+
any, // TActorMap
|
|
325
|
+
any, // TGuardMap
|
|
395
326
|
any>;
|
|
396
327
|
export type AnyStateConfig = StateConfig<any, AnyEventObject>;
|
|
397
|
-
export
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
onDone?: undefined;
|
|
403
|
-
}
|
|
404
|
-
export interface HistoryStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> extends AtomicStateNodeConfig<TContext, TEvent> {
|
|
405
|
-
history: 'shallow' | 'deep' | true;
|
|
406
|
-
target: string | undefined;
|
|
407
|
-
}
|
|
408
|
-
export type SimpleOrStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO, TODO, // emitted
|
|
409
|
-
TODO>;
|
|
410
|
-
export type ActionFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string, TEmitted extends EventObject = EventObject> = {
|
|
411
|
-
[K in TAction['type']]?: ActionFunction<TContext, TEvent, TEvent, GetParameterizedParams<TAction extends {
|
|
412
|
-
type: K;
|
|
413
|
-
} ? TAction : never>, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
414
|
-
};
|
|
415
|
-
type GuardMap<TContext extends MachineContext, TEvent extends EventObject, TGuard extends ParameterizedObject> = {
|
|
416
|
-
[K in TGuard['type']]?: GuardPredicate<TContext, TEvent, GetParameterizedParams<TGuard extends {
|
|
417
|
-
type: K;
|
|
418
|
-
} ? TGuard : never>, TGuard>;
|
|
419
|
-
};
|
|
420
|
-
export type DelayFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject> = Record<string, DelayConfig<TContext, TEvent, TAction['params'], TEvent>>;
|
|
421
|
-
export type DelayConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = number | DelayExpr<TContext, TExpressionEvent, TParams, TEvent>;
|
|
422
|
-
/** @ignore */
|
|
423
|
-
export interface MachineImplementationsSimplified<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject> {
|
|
424
|
-
guards: GuardMap<TContext, TEvent, TGuard>;
|
|
425
|
-
actions: ActionFunctionMap<TContext, TEvent, TActor, TAction>;
|
|
426
|
-
actors: Record<string, AnyActorLogic | {
|
|
427
|
-
src: AnyActorLogic;
|
|
428
|
-
input: Mapper<TContext, TEvent, unknown, TEvent> | NonReducibleUnknown;
|
|
429
|
-
}>;
|
|
430
|
-
delays: DelayFunctionMap<TContext, TEvent, TAction>;
|
|
431
|
-
}
|
|
432
|
-
type MachineImplementationsActions<TTypes extends StateMachineTypes> = {
|
|
433
|
-
[K in TTypes['actions']['type']]?: ActionFunction<TTypes['context'], TTypes['events'], TTypes['events'], GetConcreteByKey<TTypes['actions'], 'type', K>['params'], TTypes['actors'], TTypes['actions'], TTypes['guards'], TTypes['delays'], TTypes['emitted']>;
|
|
434
|
-
};
|
|
435
|
-
type MachineImplementationsActors<TTypes extends StateMachineTypes> = {
|
|
436
|
-
[K in TTypes['actors']['src']]?: GetConcreteByKey<TTypes['actors'], 'src', K>['logic'];
|
|
437
|
-
};
|
|
438
|
-
type MachineImplementationsDelays<TTypes extends StateMachineTypes> = {
|
|
439
|
-
[K in TTypes['delays']]?: DelayConfig<TTypes['context'], TTypes['events'], undefined, TTypes['events']>;
|
|
440
|
-
};
|
|
441
|
-
type MachineImplementationsGuards<TTypes extends StateMachineTypes> = {
|
|
442
|
-
[K in TTypes['guards']['type']]?: Guard<TTypes['context'], TTypes['events'], GetConcreteByKey<TTypes['guards'], 'type', K>['params'], TTypes['guards']>;
|
|
443
|
-
};
|
|
444
|
-
export type InternalMachineImplementations<TTypes extends StateMachineTypes> = {
|
|
445
|
-
actions?: MachineImplementationsActions<TTypes>;
|
|
446
|
-
actors?: MachineImplementationsActors<TTypes>;
|
|
447
|
-
delays?: MachineImplementationsDelays<TTypes>;
|
|
448
|
-
guards?: MachineImplementationsGuards<TTypes>;
|
|
449
|
-
};
|
|
450
|
-
type InitialContext<TContext extends MachineContext, TActor extends ProvidedActor, TInput, TEvent extends EventObject> = TContext | ContextFactory<TContext, TActor, TInput, TEvent>;
|
|
451
|
-
export type ContextFactory<TContext extends MachineContext, TActor extends ProvidedActor, TInput, TEvent extends EventObject = EventObject> = ({ spawn, input, self }: {
|
|
452
|
-
spawn: Spawner<TActor>;
|
|
328
|
+
export type DelayConfig<TContext extends MachineContext, TExpressionEvent extends EventObject> = number | DelayExpr<TContext, TExpressionEvent>;
|
|
329
|
+
export type InitialContext<TContext extends MachineContext, TActorMap extends Implementations['actors'], TInput, TEvent extends EventObject> = TContext | ContextFactory<TContext, TActorMap, TInput, TEvent>;
|
|
330
|
+
export type ContextFactory<TContext extends MachineContext, TActorMap extends Implementations['actors'], TInput, TEvent extends EventObject = EventObject> = ({ spawn, actors, input, self }: {
|
|
331
|
+
spawn: Spawner;
|
|
332
|
+
actors: TActorMap;
|
|
453
333
|
input: TInput;
|
|
454
|
-
self:
|
|
334
|
+
self: ActorSelf<MachineSnapshot<[
|
|
335
|
+
TContext
|
|
336
|
+
] extends [never] ? any : TContext, TEvent, Record<string, AnyActorRef | undefined>, // TODO: this should be replaced with `TChildren`
|
|
455
337
|
StateValue, string, unknown, TODO, // TMeta
|
|
456
338
|
TODO>, TEvent, AnyEventObject>;
|
|
457
|
-
}) => TContext;
|
|
458
|
-
/**
|
|
459
|
-
* Runtime options for state machine execution.
|
|
460
|
-
*
|
|
461
|
-
* @example
|
|
462
|
-
*
|
|
463
|
-
* ```ts
|
|
464
|
-
* const machine = createMachine({
|
|
465
|
-
* // ... machine config
|
|
466
|
-
* options: {
|
|
467
|
-
* maxIterations: 5000
|
|
468
|
-
* // other runtime options can be added here
|
|
469
|
-
* }
|
|
470
|
-
* });
|
|
471
|
-
* ```
|
|
472
|
-
*/
|
|
473
|
-
export interface MachineOptions {
|
|
474
|
-
/**
|
|
475
|
-
* Maximum number of microsteps allowed before throwing an infinite loop
|
|
476
|
-
* error. Defaults to `Infinity` (no limit). Set to a finite number to enable
|
|
477
|
-
* infinite loop detection.
|
|
478
|
-
*
|
|
479
|
-
* @default Infinity
|
|
480
|
-
*/
|
|
481
|
-
maxIterations?: number;
|
|
482
|
-
}
|
|
483
|
-
export type MachineConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string, TTag extends string = string, TInput = any, TOutput = unknown, TEmitted extends EventObject = EventObject, TMeta extends MetaObject = MetaObject> = (Omit<StateNodeConfig<DoNotInfer<TContext>, DoNotInfer<TEvent>, DoNotInfer<TActor>, DoNotInfer<TAction>, DoNotInfer<TGuard>, DoNotInfer<TDelay>, DoNotInfer<TTag>, DoNotInfer<TOutput>, DoNotInfer<TEmitted>, DoNotInfer<TMeta>>, 'output'> & {
|
|
484
|
-
/** The initial context (extended state) */
|
|
485
|
-
/** The machine's own version. */
|
|
486
|
-
version?: string;
|
|
487
|
-
output?: Mapper<TContext, DoneStateEvent, TOutput, TEvent> | TOutput;
|
|
488
|
-
/** Runtime options for machine execution. */
|
|
489
|
-
options?: MachineOptions;
|
|
490
|
-
}) & (MachineContext extends TContext ? {
|
|
491
|
-
context?: InitialContext<LowInfer<TContext>, TActor, TInput, TEvent>;
|
|
492
|
-
} : {
|
|
493
|
-
context: InitialContext<LowInfer<TContext>, TActor, TInput, TEvent>;
|
|
494
|
-
});
|
|
495
|
-
export type UnknownMachineConfig = MachineConfig<MachineContext, EventObject>;
|
|
339
|
+
}) => [TContext] extends [never] ? MachineContext : TContext;
|
|
496
340
|
export interface ProvidedActor {
|
|
497
341
|
src: string;
|
|
498
342
|
logic: UnknownActorLogic;
|
|
@@ -519,13 +363,12 @@ export interface HistoryStateNode<TContext extends MachineContext> extends State
|
|
|
519
363
|
history: 'shallow' | 'deep';
|
|
520
364
|
target: string | undefined;
|
|
521
365
|
}
|
|
522
|
-
export type HistoryValue
|
|
366
|
+
export type HistoryValue = Record<string, Array<AnyStateNode>>;
|
|
523
367
|
export type PersistedHistoryValue = Record<string, Array<{
|
|
524
368
|
id: string;
|
|
525
369
|
}>>;
|
|
526
|
-
export type AnyHistoryValue = HistoryValue
|
|
370
|
+
export type AnyHistoryValue = HistoryValue;
|
|
527
371
|
export type StateFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends AnyStateMachine ? ReturnType<T['transition']> : T extends (...args: any[]) => AnyStateMachine ? ReturnType<ReturnType<T>['transition']> : never;
|
|
528
|
-
export type Transitions<TContext extends MachineContext, TEvent extends EventObject> = Array<TransitionDefinition<TContext, TEvent>>;
|
|
529
372
|
export interface DoneActorEvent<TOutput = unknown, TId extends string = string> extends EventObject {
|
|
530
373
|
type: `xstate.done.actor.${TId}`;
|
|
531
374
|
output: TOutput;
|
|
@@ -544,64 +387,49 @@ export interface DoneStateEvent<TOutput = unknown> extends EventObject {
|
|
|
544
387
|
type: `xstate.done.state.${string}`;
|
|
545
388
|
output: TOutput;
|
|
546
389
|
}
|
|
547
|
-
export type DelayExpr<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = (args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams) => number;
|
|
548
|
-
export type LogExpr<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = (args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams) => unknown;
|
|
549
|
-
export type SendExpr<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TSentEvent extends EventObject, TEvent extends EventObject> = (args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams) => TSentEvent;
|
|
550
390
|
export declare enum SpecialTargets {
|
|
551
|
-
Parent = "#_parent",
|
|
552
391
|
Internal = "#_internal"
|
|
553
392
|
}
|
|
554
|
-
export
|
|
555
|
-
|
|
556
|
-
export interface RaiseActionOptions<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string> {
|
|
557
|
-
id?: string;
|
|
558
|
-
delay?: Delay<TDelay> | DelayExpr<TContext, TExpressionEvent, TParams, TEvent>;
|
|
559
|
-
}
|
|
560
|
-
export interface RaiseActionParams<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string> extends RaiseActionOptions<TContext, TExpressionEvent, TParams, TEvent, TDelay> {
|
|
561
|
-
event: TEvent | SendExpr<TContext, TExpressionEvent, TParams, TEvent, TEvent>;
|
|
562
|
-
}
|
|
563
|
-
export interface SendToActionParams<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TSentEvent extends EventObject, TEvent extends EventObject, TDelay extends string> extends SendToActionOptions<TContext, TExpressionEvent, TParams, TEvent, TDelay> {
|
|
564
|
-
event: TSentEvent | SendExpr<TContext, TExpressionEvent, TParams, TSentEvent, TEvent>;
|
|
565
|
-
}
|
|
566
|
-
export type Assigner<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor> = (args: AssignArgs<TContext, TExpressionEvent, TEvent, TActor>, params: TParams) => Partial<TContext>;
|
|
567
|
-
export type PartialAssigner<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor, TKey extends keyof TContext> = (args: AssignArgs<TContext, TExpressionEvent, TEvent, TActor>, params: TParams) => TContext[TKey];
|
|
568
|
-
export type PropertyAssigner<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor> = {
|
|
569
|
-
[K in keyof TContext]?: PartialAssigner<TContext, TExpressionEvent, TParams, TEvent, TActor, K> | TContext[K];
|
|
570
|
-
};
|
|
571
|
-
export type Mapper<TContext extends MachineContext, TExpressionEvent extends EventObject, TResult, TEvent extends EventObject> = (args: {
|
|
572
|
-
context: TContext;
|
|
393
|
+
export type Mapper<TContext extends MachineContext, TExpressionEvent extends EventObject, TResult, TEvent extends EventObject, _TCtx = [TContext] extends [never] ? any : TContext> = (args: {
|
|
394
|
+
context: _TCtx;
|
|
573
395
|
event: TExpressionEvent;
|
|
574
|
-
self:
|
|
396
|
+
self: ActorSelf<MachineSnapshot<_TCtx & MachineContext, TEvent, Record<string, AnyActorRef>, // TODO: this should be replaced with `TChildren`
|
|
575
397
|
StateValue, string, unknown, TODO, // TMeta
|
|
576
398
|
TODO>, TEvent, AnyEventObject>;
|
|
577
399
|
}) => TResult;
|
|
578
400
|
export interface TransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends Omit<TransitionConfig<TContext, TEvent, TEvent, TODO, TODO, TODO, TODO, TODO, // TEmitted
|
|
579
|
-
TODO>, 'target' | '
|
|
580
|
-
target: ReadonlyArray<
|
|
581
|
-
source:
|
|
582
|
-
actions: readonly UnknownAction[];
|
|
401
|
+
TODO>, 'target' | 'to'> {
|
|
402
|
+
target: ReadonlyArray<AnyStateNode> | undefined;
|
|
403
|
+
source: AnyStateNode;
|
|
583
404
|
reenter: boolean;
|
|
584
|
-
guard?: UnknownGuard;
|
|
585
405
|
eventType: EventDescriptor<TEvent>;
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
eventType: EventDescriptor<TEvent>;
|
|
592
|
-
meta?: Record<string, any>;
|
|
593
|
-
};
|
|
406
|
+
to?: ((...args: any[]) => any) | undefined;
|
|
407
|
+
input?: Record<string, unknown> | ((args: {
|
|
408
|
+
context: any;
|
|
409
|
+
event: any;
|
|
410
|
+
}) => Record<string, unknown>);
|
|
594
411
|
}
|
|
595
412
|
export type AnyTransitionDefinition = TransitionDefinition<any, any>;
|
|
596
|
-
export
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
413
|
+
export type InitialTransitionDefinition = {
|
|
414
|
+
source: AnyStateNode;
|
|
415
|
+
target: AnyStateNode[] | undefined;
|
|
416
|
+
reenter?: boolean;
|
|
417
|
+
eventType?: EventDescriptor<any>;
|
|
418
|
+
input?: Record<string, unknown> | ((args: {
|
|
419
|
+
context: MachineContext;
|
|
420
|
+
event: EventObject;
|
|
421
|
+
}) => Record<string, unknown>);
|
|
422
|
+
};
|
|
600
423
|
export type TransitionDefinitionMap<TContext extends MachineContext, TEvent extends EventObject> = {
|
|
601
424
|
[K in EventDescriptor<TEvent>]: Array<TransitionDefinition<TContext, ExtractEvent<TEvent, K>>>;
|
|
602
425
|
};
|
|
426
|
+
export type DelayExpr<TContext extends MachineContext, TEvent extends EventObject> = (args: {
|
|
427
|
+
context: [TContext] extends [never] ? any : TContext;
|
|
428
|
+
event: TEvent;
|
|
429
|
+
stateNode: AnyStateNode;
|
|
430
|
+
}) => number;
|
|
603
431
|
export interface DelayedTransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends TransitionDefinition<TContext, TEvent> {
|
|
604
|
-
delay: number | string | DelayExpr<TContext, TEvent
|
|
432
|
+
delay: number | string | DelayExpr<TContext, TEvent>;
|
|
605
433
|
}
|
|
606
434
|
export interface StateLike<TContext extends MachineContext> {
|
|
607
435
|
value: StateValue;
|
|
@@ -610,15 +438,52 @@ export interface StateLike<TContext extends MachineContext> {
|
|
|
610
438
|
}
|
|
611
439
|
export interface StateConfig<TContext extends MachineContext, TEvent extends EventObject> {
|
|
612
440
|
context: TContext;
|
|
613
|
-
historyValue?: HistoryValue
|
|
614
|
-
children: Record<string, AnyActorRef>;
|
|
441
|
+
historyValue?: HistoryValue;
|
|
442
|
+
children: Record<string, AnyActorRef | undefined>;
|
|
615
443
|
status: SnapshotStatus;
|
|
616
444
|
output?: any;
|
|
617
445
|
error?: unknown;
|
|
618
|
-
machine?: StateMachine<TContext, TEvent, any, any, any, any, any, any, any, any, any, any, any,
|
|
619
|
-
any>;
|
|
446
|
+
machine?: StateMachine<TContext, TEvent, any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
620
447
|
}
|
|
448
|
+
/**
|
|
449
|
+
* A pending effect (delayed event/transition that has not fired yet) captured
|
|
450
|
+
* in a persisted snapshot — a serialized built-in action descriptor plus its
|
|
451
|
+
* runtime progress, with enough information to restore it under any strategy.
|
|
452
|
+
*/
|
|
453
|
+
export interface PendingEffect {
|
|
454
|
+
/** The serialized built-in action type for this effect. */
|
|
455
|
+
type: '@xstate.raise';
|
|
456
|
+
event: EventObject;
|
|
457
|
+
id: string;
|
|
458
|
+
/** The original delay (in ms) the effect was scheduled with. */
|
|
459
|
+
delay: number;
|
|
460
|
+
/** Wall-clock timestamp (ms) when the effect was scheduled. */
|
|
461
|
+
startedAt: number;
|
|
462
|
+
/** Wall-clock time (ms) that had elapsed when the snapshot was persisted. */
|
|
463
|
+
elapsed: number;
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* How pending effects (timers) from a persisted snapshot are restored on
|
|
467
|
+
* `actor.start()`:
|
|
468
|
+
*
|
|
469
|
+
* - `'resume'` (default) — the clock was "frozen" while persisted: a 5-minute
|
|
470
|
+
* timer persisted with 1 minute elapsed fires after 4 more minutes.
|
|
471
|
+
* - `'restart'` — timers start over with their full delay.
|
|
472
|
+
* - `'absolute'` — timers honor the original wall-clock expiry (`startedAt +
|
|
473
|
+
* delay`); already-expired timers fire immediately.
|
|
474
|
+
* - A custom function receiving the pending effect and returning the remaining
|
|
475
|
+
* delay in ms.
|
|
476
|
+
*/
|
|
477
|
+
export type TimersRestoreStrategy = 'resume' | 'restart' | 'absolute' | ((pendingEffect: PendingEffect) => number);
|
|
621
478
|
export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
479
|
+
/**
|
|
480
|
+
* How pending timers (delayed events/transitions) from a persisted `snapshot`
|
|
481
|
+
* are restored when the actor starts. Applies to this actor and (when this is
|
|
482
|
+
* the root) all rehydrated child actors.
|
|
483
|
+
*
|
|
484
|
+
* @default 'resume'
|
|
485
|
+
*/
|
|
486
|
+
timers?: TimersRestoreStrategy;
|
|
622
487
|
/**
|
|
623
488
|
* The clock that is responsible for setting and clearing timeouts, such as
|
|
624
489
|
* delayed events and transitions.
|
|
@@ -642,7 +507,7 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
642
507
|
* native `console.log(...)` method.
|
|
643
508
|
*/
|
|
644
509
|
logger?: (...args: any[]) => void;
|
|
645
|
-
parent?:
|
|
510
|
+
parent?: AnyActor;
|
|
646
511
|
/** The custom `id` for referencing this service. */
|
|
647
512
|
id?: string;
|
|
648
513
|
/** @deprecated Use `inspect` instead. */
|
|
@@ -675,13 +540,14 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
675
540
|
*
|
|
676
541
|
* @remarks
|
|
677
542
|
* If a callback function is provided, it can accept an inspection event
|
|
678
|
-
* argument. The
|
|
543
|
+
* argument. The inspection protocol has two event types:
|
|
679
544
|
*
|
|
680
|
-
* - `@xstate.actor` - An actor ref
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
*
|
|
545
|
+
* - `@xstate.actor` - An actor ref was created in the system (announces actor
|
|
546
|
+
* topology: identity + parent).
|
|
547
|
+
* - `@xstate.transition` - An actor transitioned. Carries every facet of the
|
|
548
|
+
* transition with flat, always-present fields: `event`, `snapshot`,
|
|
549
|
+
* `sourceRef`, `microsteps`, executed `actions`, and `sent`/scheduled
|
|
550
|
+
* events.
|
|
685
551
|
*
|
|
686
552
|
* @example
|
|
687
553
|
*
|
|
@@ -699,19 +565,18 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
699
565
|
* }
|
|
700
566
|
*
|
|
701
567
|
* if (inspectionEvent.type === '@xstate.actor') {
|
|
702
|
-
* console.log(inspectionEvent.actorRef);
|
|
568
|
+
* console.log(inspectionEvent.actorRef, inspectionEvent.parentRef);
|
|
703
569
|
* }
|
|
704
570
|
*
|
|
705
|
-
* if (inspectionEvent.type === '@xstate.
|
|
571
|
+
* if (inspectionEvent.type === '@xstate.transition') {
|
|
706
572
|
* console.log(inspectionEvent.sourceRef);
|
|
707
573
|
* console.log(inspectionEvent.actorRef);
|
|
708
574
|
* console.log(inspectionEvent.event);
|
|
709
|
-
* }
|
|
710
|
-
*
|
|
711
|
-
* if (inspectionEvent.type === '@xstate.snapshot') {
|
|
712
|
-
* console.log(inspectionEvent.actorRef);
|
|
713
|
-
* console.log(inspectionEvent.event);
|
|
714
575
|
* console.log(inspectionEvent.snapshot);
|
|
576
|
+
* // flat, always-present facets — no narrowing required
|
|
577
|
+
* console.log(inspectionEvent.actions);
|
|
578
|
+
* console.log(inspectionEvent.sent);
|
|
579
|
+
* console.log(inspectionEvent.microsteps);
|
|
715
580
|
* }
|
|
716
581
|
* }
|
|
717
582
|
* });
|
|
@@ -731,19 +596,20 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
731
596
|
* }
|
|
732
597
|
*
|
|
733
598
|
* if (inspectionEvent.type === '@xstate.actor') {
|
|
734
|
-
* console.log(
|
|
599
|
+
* console.log(
|
|
600
|
+
* inspectionEvent.actorRef,
|
|
601
|
+
* inspectionEvent.parentRef
|
|
602
|
+
* );
|
|
735
603
|
* }
|
|
736
604
|
*
|
|
737
|
-
* if (inspectionEvent.type === '@xstate.
|
|
605
|
+
* if (inspectionEvent.type === '@xstate.transition') {
|
|
738
606
|
* console.log(inspectionEvent.sourceRef);
|
|
739
607
|
* console.log(inspectionEvent.actorRef);
|
|
740
608
|
* console.log(inspectionEvent.event);
|
|
741
|
-
* }
|
|
742
|
-
*
|
|
743
|
-
* if (inspectionEvent.type === '@xstate.snapshot') {
|
|
744
|
-
* console.log(inspectionEvent.actorRef);
|
|
745
|
-
* console.log(inspectionEvent.event);
|
|
746
609
|
* console.log(inspectionEvent.snapshot);
|
|
610
|
+
* console.log(inspectionEvent.actions);
|
|
611
|
+
* console.log(inspectionEvent.sent);
|
|
612
|
+
* console.log(inspectionEvent.microsteps);
|
|
747
613
|
* }
|
|
748
614
|
* }
|
|
749
615
|
* }
|
|
@@ -752,7 +618,7 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
752
618
|
*/
|
|
753
619
|
inspect?: Observer<InspectionEvent> | ((inspectionEvent: InspectionEvent) => void);
|
|
754
620
|
}
|
|
755
|
-
export type AnyActor =
|
|
621
|
+
export type AnyActor = ActorInstance<any, any, any, any>;
|
|
756
622
|
/** @deprecated Use `AnyActor` instead. */
|
|
757
623
|
export type AnyInterpreter = AnyActor;
|
|
758
624
|
export type Observer<T> = {
|
|
@@ -784,50 +650,105 @@ export interface BaseActorRef<TEvent extends EventObject> {
|
|
|
784
650
|
export interface ActorLike<TCurrent, TEvent extends EventObject> extends Subscribable<TCurrent> {
|
|
785
651
|
send: (event: TEvent) => void;
|
|
786
652
|
}
|
|
787
|
-
|
|
653
|
+
/**
|
|
654
|
+
* A consumer-facing actor handle.
|
|
655
|
+
*
|
|
656
|
+
* `ActorRef` describes the contract a consumer needs: which events can be sent
|
|
657
|
+
* to the actor, which snapshot it publishes for observation, and which emitted
|
|
658
|
+
* events can be listened to. It intentionally does not expose lifecycle control
|
|
659
|
+
* or runtime internals. A concrete `Actor` satisfies this interface, so APIs
|
|
660
|
+
* should accept `ActorRef` whenever they only need to send events, read
|
|
661
|
+
* snapshots, or listen to emitted events.
|
|
662
|
+
*/
|
|
663
|
+
export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> extends Subscribable<TSnapshot>, InteropObservable<TSnapshot> {
|
|
664
|
+
send: (event: TSendEvent) => void;
|
|
665
|
+
getSnapshot: () => TSnapshot;
|
|
666
|
+
on: <TType extends TEmitted['type'] | '*'>(type: TType, handler: (emitted: TEmitted & (TType extends '*' ? unknown : {
|
|
667
|
+
type: TType;
|
|
668
|
+
})) => void) => Subscription;
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Runtime-only actor capabilities.
|
|
672
|
+
*
|
|
673
|
+
* These members are needed by the interpreter, scheduler, inspection, and child
|
|
674
|
+
* management code. Public consumer APIs should prefer `ActorRef` unless they
|
|
675
|
+
* genuinely need lifecycle control such as starting, stopping, or accessing
|
|
676
|
+
* system-owned runtime state.
|
|
677
|
+
*/
|
|
678
|
+
export interface ActorRuntime<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, _TEmitted extends EventObject = EventObject> {
|
|
788
679
|
/** The unique identifier for this actor relative to its parent. */
|
|
789
680
|
id: string;
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
681
|
+
/**
|
|
682
|
+
* The globally unique process ID for this invocation.
|
|
683
|
+
*
|
|
684
|
+
* @remarks
|
|
685
|
+
* This is only defined once the actor is started.
|
|
686
|
+
*/
|
|
687
|
+
sessionId: string | undefined;
|
|
688
|
+
start: () => this;
|
|
794
689
|
getPersistedSnapshot: () => Snapshot<unknown>;
|
|
795
690
|
stop: () => void;
|
|
796
691
|
toJSON?: () => any;
|
|
797
|
-
_parent?:
|
|
798
|
-
system:
|
|
692
|
+
_parent?: any;
|
|
693
|
+
system: any;
|
|
799
694
|
src: string | AnyActorLogic;
|
|
800
|
-
|
|
801
|
-
type: TType;
|
|
802
|
-
})) => void) => Subscription;
|
|
695
|
+
trigger: any;
|
|
803
696
|
select<TSelected>(selector: (snapshot: TSnapshot) => TSelected, equalityFn?: (a: TSelected, b: TSelected) => boolean): Readable<TSelected>;
|
|
804
697
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
698
|
+
/**
|
|
699
|
+
* A concrete actor instance type.
|
|
700
|
+
*
|
|
701
|
+
* `ActorInstance` combines the consumer `ActorRef` contract with runtime
|
|
702
|
+
* lifecycle capabilities. Values returned by `createActor(...)` and
|
|
703
|
+
* `spawn(...)` naturally satisfy narrower `ActorRef` contracts.
|
|
704
|
+
*/
|
|
705
|
+
export interface ActorInstance<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> extends ActorRuntime<TSnapshot, TEvent, TEmitted>, ActorRef<TSnapshot, TEvent, TEmitted, TSendEvent> {
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* The actor's own full self handle.
|
|
709
|
+
*
|
|
710
|
+
* Internals and action/guard implementations receive this shape because `self`
|
|
711
|
+
* can participate in runtime-owned behavior while still being usable wherever
|
|
712
|
+
* an `ActorRef` is expected.
|
|
713
|
+
*/
|
|
714
|
+
export type ActorSelf<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> = ActorRuntime<TSnapshot, TEvent, TEmitted> & ActorRef<TSnapshot, TEvent, TEmitted, TSendEvent>;
|
|
715
|
+
export type ActorRefFrom<T> = T extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer TEmitted, infer TMeta, infer TConfig, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TConfig extends {
|
|
716
|
+
internalEvents?: readonly EventDescriptor<TEvent>[];
|
|
717
|
+
} ? ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, any>, TEvent, TEmitted, ExcludeInternalEvents<TEvent, TConfig['internalEvents'] extends readonly EventDescriptor<TEvent>[] ? TConfig['internalEvents'] extends readonly (infer TDesc)[] ? Extract<TDesc, string> : never : never>> : ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, any>, TEvent, TEmitted> : T extends Promise<infer U> ? ActorRefFrom<AsyncActorLogic<U>> : T extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? ActorRef<TSnapshot, TEvent, TEmitted> : never;
|
|
718
|
+
export type SendableEventFromLogic<TLogic extends AnyActorLogic> = TLogic extends StateMachine<infer _TContext, infer TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer TConfig, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TConfig extends {
|
|
719
|
+
internalEvents?: readonly EventDescriptor<TEvent>[];
|
|
720
|
+
} ? ExcludeInternalEvents<TEvent, TConfig['internalEvents'] extends readonly EventDescriptor<TEvent>[] ? TConfig['internalEvents'] extends readonly (infer TDesc)[] ? Extract<TDesc, string> : never : never> : TEvent : EventFromLogic<TLogic>;
|
|
721
|
+
export type ActorRefFromLogic<T extends AnyActorLogic> = ActorRef<SnapshotFrom<T>, EventFromLogic<T>, EmittedFrom<T>, SendableEventFromLogic<T>>;
|
|
722
|
+
export type AnyActorRef = ActorRef<any, any, any, any>;
|
|
723
|
+
/** The concrete actor instance type produced from actor logic. */
|
|
724
|
+
export type ActorFromLogic<T extends AnyActorLogic> = ActorInstance<SnapshotFrom<T>, EventFromLogic<T>, EmittedFrom<T>, SendableEventFromLogic<T>>;
|
|
725
|
+
type SendableEventFromActorRef<TActorRef, TFallback extends EventObject = AnyEventObject> = [NonNullable<TActorRef>] extends [never] ? TFallback : NonNullable<TActorRef> extends infer TNonNullableActorRef ? TNonNullableActorRef extends {
|
|
726
|
+
send: (event: infer TEvent) => void;
|
|
727
|
+
} ? [TEvent] extends [never] ? TFallback : TEvent extends EventObject ? TEvent : TFallback : never : never;
|
|
728
|
+
export type ActorRefLike = Pick<AnyActor, 'sessionId' | 'send' | 'getSnapshot'>;
|
|
808
729
|
export type UnknownActorRef = ActorRef<Snapshot<unknown>, EventObject>;
|
|
809
|
-
export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any, any, any, any, any, any, any, any, any, // TMeta
|
|
810
|
-
any> ? R : R extends Promise<infer U> ? PromiseActorLogic<U> : never : never;
|
|
811
|
-
export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer TEmitted, infer TMeta, infer TStateSchema> ? ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>, TEvent, TEmitted> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? ActorRef<TSnapshot, TEvent, TEmitted> : never : never;
|
|
812
|
-
export type ActorRefFromLogic<T extends AnyActorLogic> = ActorRef<SnapshotFrom<T>, EventFromLogic<T>, EmittedFrom<T>>;
|
|
813
730
|
export type DevToolsAdapter = (service: AnyActor) => void;
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
731
|
+
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TConfig, infer TActionMap, infer TActorMap, infer TGuardMap, infer TDelayMap> ? {
|
|
732
|
+
actions: TActionMap;
|
|
733
|
+
actors: TActorMap;
|
|
734
|
+
guards: TGuardMap;
|
|
735
|
+
delays: TDelayMap;
|
|
736
|
+
} : never;
|
|
737
|
+
export interface ActorScope<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TSystem extends AnyActorSystem = AnyActorSystem, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> {
|
|
738
|
+
self: ActorSelf<TSnapshot, TEvent, TEmitted, TSendEvent>;
|
|
819
739
|
id: string;
|
|
820
740
|
sessionId: string;
|
|
821
741
|
logger: (...args: any[]) => void;
|
|
822
742
|
defer: (fn: () => void) => void;
|
|
823
743
|
emit: (event: TEmitted) => void;
|
|
824
744
|
system: TSystem;
|
|
825
|
-
stopChild: (child:
|
|
745
|
+
stopChild: (child: AnyActor) => void;
|
|
826
746
|
actionExecutor: ActionExecutor;
|
|
827
747
|
}
|
|
828
748
|
export type AnyActorScope = ActorScope<any, // TSnapshot
|
|
829
749
|
any, // TEvent
|
|
830
|
-
AnyActorSystem, any
|
|
750
|
+
AnyActorSystem, any, // TEmitted
|
|
751
|
+
any>;
|
|
831
752
|
export type SnapshotStatus = 'active' | 'done' | 'error' | 'stopped';
|
|
832
753
|
export type Snapshot<TOutput> = {
|
|
833
754
|
status: 'active';
|
|
@@ -915,9 +836,9 @@ AnyActorSystem, any>;
|
|
|
915
836
|
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer TSnapshot, infer _, infer __> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends ActorLogic<infer _TSnapshot, infer _TEvent, infer _TInput, infer _TEmitted, infer _TSystem> ? ReturnType<R['transition']> : R extends ActorScope<infer TSnapshot, infer _TEvent, infer _TEmitted, infer _TSystem> ? TSnapshot : never : never;
|
|
916
837
|
export type EventFromLogic<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer TEvent, infer _TInput, infer _TEmitted, infer _TSystem> ? TEvent : never;
|
|
917
838
|
export type EmittedFrom<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? TEmitted : never;
|
|
918
|
-
type ResolveEventType<T> =
|
|
839
|
+
type ResolveEventType<T> = T extends infer R ? R extends StateMachine<infer _TContext, infer TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TConfig, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput, infer _TMeta, infer _TStateSchema> ? TEvent : R extends ActorRef<infer _TSnapshot, infer TEvent, infer _TEmitted> ? TEvent : never : never;
|
|
919
840
|
export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
|
|
920
|
-
export type ContextFrom<T> =
|
|
841
|
+
export type ContextFrom<T> = T extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TConfig, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TContext : T extends MachineSnapshot<infer TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput, infer _TMeta, infer _TStateSchema> ? TContext : T extends Actor<infer TActorLogic> ? TActorLogic extends AnyStateMachine ? ContextFrom<TActorLogic> : never : never;
|
|
921
842
|
export type InferEvent<E extends EventObject> = {
|
|
922
843
|
[T in E['type']]: {
|
|
923
844
|
type: T;
|
|
@@ -935,18 +856,21 @@ export type RequiredActorOptions<TActor extends ProvidedActor> = (undefined exte
|
|
|
935
856
|
export type RequiredLogicInput<TLogic extends AnyActorLogic> = undefined extends InputFrom<TLogic> ? never : 'input';
|
|
936
857
|
type ExtractLiteralString<T extends string | undefined> = T extends string ? string extends T ? never : T : never;
|
|
937
858
|
type ToConcreteChildren<TActor extends ProvidedActor> = {
|
|
938
|
-
[A in TActor as ExtractLiteralString<A['id']>]?:
|
|
859
|
+
[A in TActor as ExtractLiteralString<A['id']>]?: ActorFromLogic<A['logic']>;
|
|
939
860
|
};
|
|
940
|
-
|
|
861
|
+
type NonConcreteActors<TActor extends ProvidedActor> = TActor extends any ? ExtractLiteralString<TActor['id']> extends never ? TActor : never : never;
|
|
862
|
+
export type ToChildren<TActor extends ProvidedActor> = string extends TActor['src'] ? Record<string, AnyActor> : Compute<ToConcreteChildren<TActor> & {
|
|
941
863
|
include: {
|
|
942
|
-
[id: string]: TActor extends any ?
|
|
864
|
+
[id: string]: NonConcreteActors<TActor> extends never ? AnyActor | undefined : NonConcreteActors<TActor> extends any ? ActorFromLogic<NonConcreteActors<TActor>['logic']> | undefined : never;
|
|
943
865
|
};
|
|
944
866
|
exclude: unknown;
|
|
945
|
-
}[
|
|
867
|
+
}[NonConcreteActors<TActor> extends never ? 'exclude' : 'include']>;
|
|
946
868
|
export type StateSchema = {
|
|
947
869
|
id?: string;
|
|
948
870
|
route?: unknown;
|
|
949
871
|
states?: Record<string, StateSchema>;
|
|
872
|
+
contextSchema?: StandardSchemaV1;
|
|
873
|
+
input?: unknown;
|
|
950
874
|
type?: unknown;
|
|
951
875
|
invoke?: unknown;
|
|
952
876
|
on?: unknown;
|
|
@@ -955,17 +879,32 @@ export type StateSchema = {
|
|
|
955
879
|
onDone?: unknown;
|
|
956
880
|
after?: unknown;
|
|
957
881
|
always?: unknown;
|
|
882
|
+
choice?: unknown;
|
|
958
883
|
meta?: unknown;
|
|
959
884
|
output?: unknown;
|
|
960
885
|
tags?: unknown;
|
|
961
886
|
description?: unknown;
|
|
962
887
|
};
|
|
963
|
-
export type StateSchemaFrom<T extends AnyStateMachine> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer
|
|
888
|
+
export type StateSchemaFrom<T extends AnyStateMachine> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer TStateSchema, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TStateSchema : never;
|
|
964
889
|
export type StateId<TSchema extends StateSchema, TKey extends string = '(machine)', TParentKey extends string | null = null> = (TSchema extends {
|
|
965
890
|
id: string;
|
|
966
891
|
} ? TSchema['id'] : TParentKey extends null ? TKey : `${TParentKey}.${TKey}`) | (TSchema['states'] extends Record<string, any> ? Values<{
|
|
967
892
|
[K in keyof TSchema['states'] & string]: StateId<TSchema['states'][K], K, TParentKey extends string ? `${TParentKey}.${TKey}` : TSchema['id'] extends string ? TSchema['id'] : TKey>;
|
|
968
893
|
}> : never);
|
|
894
|
+
/** Maps state IDs to their input types based on the StateSchema. */
|
|
895
|
+
export type StateIdInputs<TSchema extends StateSchema, TKey extends string = '(machine)', TParentKey extends string | null = null> = {
|
|
896
|
+
[K in TSchema extends {
|
|
897
|
+
id: string;
|
|
898
|
+
} ? TSchema['id'] : TParentKey extends null ? TKey : `${TParentKey}.${TKey}`]: TSchema['input'] extends undefined ? undefined : TSchema['input'];
|
|
899
|
+
} & (TSchema['states'] extends Record<string, StateSchema> ? UnionToIntersection<Values<{
|
|
900
|
+
[K in keyof TSchema['states'] & string]: StateIdInputs<TSchema['states'][K], K, TParentKey extends string ? `${TParentKey}.${TKey}` : TSchema['id'] extends string ? TSchema['id'] : TKey>;
|
|
901
|
+
}>> : {});
|
|
902
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
903
|
+
type ContextFromStateSchema<TSchema extends StateSchema, TFallbackContext extends MachineContext> = TSchema['contextSchema'] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema['contextSchema']> & MachineContext : TFallbackContext;
|
|
904
|
+
type ContextFromChildStateValue<TChildSchema extends StateSchema, TFallbackContext extends MachineContext, TChildValue> = ContextFromStateSchema<TChildSchema, TFallbackContext> & StateContextFromStateValue<TChildSchema, ContextFromStateSchema<TChildSchema, TFallbackContext>, TChildValue>;
|
|
905
|
+
export type StateContextFromStateValue<TSchema extends StateSchema, TFallbackContext extends MachineContext, TStateValue> = (TSchema['states'] extends Record<string, StateSchema> ? TStateValue extends keyof TSchema['states'] & string ? ContextFromStateSchema<TSchema['states'][TStateValue], TFallbackContext> : TStateValue extends Record<string, unknown> ? UnionToIntersection<Values<{
|
|
906
|
+
[K in keyof TStateValue & keyof TSchema['states'] & string]: ContextFromChildStateValue<TSchema['states'][K], TFallbackContext, NonNullable<TStateValue[K]>>;
|
|
907
|
+
}>> : TFallbackContext : TFallbackContext) & MachineContext;
|
|
969
908
|
export type RoutableStateId<TSchema extends StateSchema> = (TSchema extends {
|
|
970
909
|
route: any;
|
|
971
910
|
id: string;
|
|
@@ -1015,32 +954,94 @@ export type ToStateValue<T extends StateSchema> = T extends {
|
|
|
1015
954
|
};
|
|
1016
955
|
}>> : never) : {};
|
|
1017
956
|
export interface ExecutableActionObject {
|
|
1018
|
-
type: string;
|
|
1019
|
-
info: ActionArgs<MachineContext, EventObject, EventObject>;
|
|
957
|
+
type: string & {};
|
|
1020
958
|
params: NonReducibleUnknown;
|
|
1021
|
-
|
|
959
|
+
args: unknown[];
|
|
960
|
+
exec: (() => void) | undefined;
|
|
1022
961
|
}
|
|
962
|
+
export type SpecialExecutableAction = Values<{
|
|
963
|
+
[K in keyof typeof builtInActions]: {
|
|
964
|
+
type: K;
|
|
965
|
+
args: Parameters<(typeof builtInActions)[K]>;
|
|
966
|
+
};
|
|
967
|
+
}>;
|
|
1023
968
|
export interface ToExecutableAction<T extends ParameterizedObject> extends ExecutableActionObject {
|
|
1024
969
|
type: T['type'];
|
|
1025
970
|
params: T['params'];
|
|
1026
971
|
exec: undefined;
|
|
1027
972
|
}
|
|
1028
|
-
export interface ExecutableSpawnAction extends ExecutableActionObject {
|
|
1029
|
-
type: 'xstate.spawnChild';
|
|
1030
|
-
info: ActionArgs<MachineContext, EventObject, EventObject>;
|
|
1031
|
-
params: {
|
|
1032
|
-
id: string;
|
|
1033
|
-
actorRef: AnyActorRef | undefined;
|
|
1034
|
-
src: string | AnyActorLogic;
|
|
1035
|
-
};
|
|
1036
|
-
}
|
|
1037
|
-
export type SpecialExecutableAction = ExecutableSpawnAction | ExecutableRaiseAction | ExecutableSendToAction;
|
|
1038
|
-
export type ExecutableActionsFrom<T extends AnyActorLogic> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TActor, infer TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TStateSchema> ? SpecialExecutableAction | (string extends TAction['type'] ? never : ToExecutableAction<TAction>) : never;
|
|
1039
973
|
export type ActionExecutor = (actionToExecute: ExecutableActionObject) => void;
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
974
|
+
/** Mappers for subscribeTo - maps lifecycle events to machine events */
|
|
975
|
+
export interface SubscribeToMappers<TSnapshot extends Snapshot<unknown>, TOutput, TMappedEvent extends EventObject> {
|
|
976
|
+
snapshot?: (snapshot: TSnapshot) => TMappedEvent;
|
|
977
|
+
done?: (output: TOutput) => TMappedEvent;
|
|
978
|
+
error?: (error: unknown) => TMappedEvent;
|
|
979
|
+
}
|
|
980
|
+
export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends EventObject> = {
|
|
981
|
+
cancel: (id: string) => void;
|
|
982
|
+
raise: (ev: TEvent, options?: {
|
|
983
|
+
id?: string;
|
|
984
|
+
delay?: number;
|
|
985
|
+
}) => void;
|
|
986
|
+
spawn: <T extends AnyActorLogic>(logic: T, options?: {
|
|
987
|
+
input?: InputFrom<T>;
|
|
988
|
+
id?: string;
|
|
989
|
+
syncSnapshot?: boolean;
|
|
990
|
+
systemId?: string;
|
|
991
|
+
}) => ActorFromLogic<T>;
|
|
992
|
+
emit: (emittedEvent: TEmittedEvent) => void;
|
|
993
|
+
<T extends (...args: any[]) => any>(fn: T, ...args: Parameters<T>): void;
|
|
994
|
+
log: (...args: any[]) => void;
|
|
995
|
+
sendTo: <TActorRef extends {
|
|
996
|
+
send: (...args: any[]) => void;
|
|
997
|
+
} | undefined>(actorRef: TActorRef, event: SendableEventFromActorRef<NoInfer<TActorRef>>, options?: {
|
|
998
|
+
id?: string;
|
|
999
|
+
delay?: number;
|
|
1000
|
+
}) => void;
|
|
1001
|
+
stop: (actor?: AnyActor) => void;
|
|
1002
|
+
/**
|
|
1003
|
+
* Listen to emitted events from an actor. Returns a listener actor that can
|
|
1004
|
+
* be stopped via `enq.stop()`.
|
|
1005
|
+
*
|
|
1006
|
+
* @param actor - The actor to listen to
|
|
1007
|
+
* @param eventType - The emitted event type to listen for (supports
|
|
1008
|
+
* wildcards: 'event._', '_')
|
|
1009
|
+
* @param mapper - Function to transform emitted events into machine events
|
|
1010
|
+
*/
|
|
1011
|
+
listen: <TEmitted extends EventObject, TMappedEvent extends TEvent>(actor: AnyActor, eventType: string, mapper: (event: TEmitted) => TMappedEvent) => AnyActor;
|
|
1012
|
+
/**
|
|
1013
|
+
* Subscribe to lifecycle events (done/error/snapshot) from an actor. Returns
|
|
1014
|
+
* a subscription actor that can be stopped via `enq.stop()`.
|
|
1015
|
+
*
|
|
1016
|
+
* @param actor - The actor to subscribe to
|
|
1017
|
+
* @param mappers - Object with done/error/snapshot mappers, or a single
|
|
1018
|
+
* snapshot mapper function
|
|
1019
|
+
*/
|
|
1020
|
+
subscribeTo: {
|
|
1021
|
+
<TSnapshot extends Snapshot<unknown>, TOutput, TMappedEvent extends TEvent>(actor: AnyActor, mappers: SubscribeToMappers<TSnapshot, TOutput, TMappedEvent> | ((snapshot: TSnapshot) => TMappedEvent)): AnyActor;
|
|
1022
|
+
<TValue, TMappedEvent extends TEvent>(atom: BaseAtom<TValue>, mappers: {
|
|
1023
|
+
snapshot?: (value: TValue) => TMappedEvent;
|
|
1024
|
+
} | ((value: TValue) => TMappedEvent)): AnyActor;
|
|
1025
|
+
};
|
|
1026
|
+
};
|
|
1027
|
+
export type Action<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TParams = Record<string, unknown> | undefined, _TCtx = [TContext] extends [never] ? any : TContext> = (_: {
|
|
1028
|
+
context: _TCtx;
|
|
1029
|
+
event: TEvent;
|
|
1030
|
+
parent: AnyActorRef | undefined;
|
|
1031
|
+
self: ActorSelf<MachineSnapshot<_TCtx & MachineContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO>, TEvent>;
|
|
1032
|
+
children: Record<string, AnyActor | undefined>;
|
|
1033
|
+
actions: TActionMap;
|
|
1034
|
+
actors: TActorMap;
|
|
1035
|
+
guards: TGuardMap;
|
|
1036
|
+
delays: TDelayMap;
|
|
1037
|
+
system?: AnyActorSystem;
|
|
1038
|
+
params: TParams;
|
|
1039
|
+
}, enqueue: EnqueueObject<TEvent, TEmittedEvent>) => {
|
|
1040
|
+
context?: _TCtx;
|
|
1041
|
+
children?: Record<string, AnyActor | undefined>;
|
|
1042
|
+
} | void;
|
|
1043
|
+
export type AnyAction = Action<MachineContext, EventObject, EventObject, Implementations['actions'], Implementations['actors'], Implementations['guards'], Implementations['delays']> | {
|
|
1044
|
+
action: (...args: any[]) => any;
|
|
1045
|
+
args: any[];
|
|
1046
|
+
} | AnyEventObject;
|
|
1046
1047
|
export {};
|