xstate 5.32.2 → 6.0.0-alpha.10
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 +25 -24
- package/dist/StateMachine-0aa98f54.development.esm.js +746 -0
- package/dist/StateMachine-aef700df.cjs.js +732 -0
- package/dist/StateMachine-d4931336.esm.js +729 -0
- package/dist/StateMachine-da872dde.development.cjs.js +749 -0
- package/dist/declarations/src/State.d.ts +11 -13
- package/dist/declarations/src/StateMachine.d.ts +40 -26
- 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/createActor.d.ts +33 -34
- package/dist/declarations/src/createMachine.d.ts +38 -7
- package/dist/declarations/src/createMachineFromConfig.d.ts +177 -0
- package/dist/declarations/src/graph/graph.d.ts +6 -4
- package/dist/declarations/src/graph/shortestPaths.d.ts +2 -2
- package/dist/declarations/src/graph/simplePaths.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +13 -9
- 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 +50 -0
- package/dist/declarations/src/setup.d.ts +396 -136
- package/dist/declarations/src/spawn.d.ts +7 -32
- package/dist/declarations/src/stateUtils.d.ts +22 -19
- package/dist/declarations/src/system.d.ts +8 -7
- package/dist/declarations/src/transition.d.ts +8 -5
- package/dist/declarations/src/transitionActions.d.ts +4 -0
- package/dist/declarations/src/types.d.ts +494 -429
- package/dist/declarations/src/types.v6.d.ts +423 -0
- package/dist/declarations/src/utils.d.ts +5 -3
- package/dist/index-219cb621.development.cjs.js +4476 -0
- package/dist/index-2f2fbd9b.development.esm.js +4421 -0
- package/dist/index-559ceab3.cjs.js +4437 -0
- package/dist/index-8828376f.esm.js +4382 -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 +1477 -122
- package/dist/xstate.cjs.mjs +19 -22
- package/dist/xstate.development.cjs.js +1477 -122
- package/dist/xstate.development.cjs.mjs +19 -22
- package/dist/xstate.development.esm.js +1442 -86
- package/dist/xstate.esm.js +1442 -86
- 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-23c204bb.development.esm.js +0 -566
- package/dist/StateMachine-67a0f463.development.cjs.js +0 -569
- package/dist/StateMachine-94d215e3.cjs.js +0 -563
- package/dist/StateMachine-d1d80308.esm.js +0 -560
- package/dist/assign-43b1b558.development.esm.js +0 -133
- package/dist/assign-54b312bc.esm.js +0 -127
- package/dist/assign-b5bc78f7.cjs.js +0 -129
- package/dist/assign-f8f66278.development.cjs.js +0 -135
- 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-9b02c355.esm.js +0 -401
- package/dist/log-c94995c7.cjs.js +0 -409
- package/dist/log-d9f3f459.development.cjs.js +0 -437
- package/dist/log-db444cad.development.esm.js +0 -429
- package/dist/raise-235108c6.esm.js +0 -2762
- package/dist/raise-45f11c00.development.esm.js +0 -2824
- package/dist/raise-c445379d.cjs.js +0 -2817
- package/dist/raise-eca73993.development.cjs.js +0 -2879
- 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,14 @@
|
|
|
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 { ExecutableRaiseAction } from "./actions/raise.js";
|
|
6
|
-
import { ExecutableSendToAction } from "./actions/send.js";
|
|
7
|
-
import { PromiseActorLogic } from "./actors/promise.js";
|
|
4
|
+
import { AsyncActorLogic } from "./actors/promise.js";
|
|
8
5
|
import type { Actor } from "./createActor.js";
|
|
9
|
-
import { Guard, GuardPredicate, UnknownGuard } from "./guards.js";
|
|
10
6
|
import { InspectionEvent } from "./inspection.js";
|
|
11
7
|
import { Spawner } from "./spawn.js";
|
|
12
8
|
import { AnyActorSystem, Clock } from "./system.js";
|
|
9
|
+
import { Implementations, Next_StateNodeConfig } from "./types.v6.js";
|
|
10
|
+
import { StandardSchemaV1 } from "./schema.types.js";
|
|
11
|
+
import { builtInActions } from "./actions.js";
|
|
13
12
|
export type Identity<T> = {
|
|
14
13
|
[K in keyof T]: T[K];
|
|
15
14
|
};
|
|
@@ -57,6 +56,7 @@ export type IndexByProp<T extends Record<P, string>, P extends keyof T> = {
|
|
|
57
56
|
export type IndexByType<T extends {
|
|
58
57
|
type: string;
|
|
59
58
|
}> = IndexByProp<T, 'type'>;
|
|
59
|
+
export type IsEmptyObject<T> = keyof T extends never ? true : false;
|
|
60
60
|
export type Equals<A1, A2> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
|
|
61
61
|
export type IsAny<T> = Equals<T, any>;
|
|
62
62
|
export type Cast<A, B> = A extends B ? A : B;
|
|
@@ -79,44 +79,42 @@ export interface ParameterizedObject {
|
|
|
79
79
|
type: string;
|
|
80
80
|
params?: NonReducibleUnknown;
|
|
81
81
|
}
|
|
82
|
-
export
|
|
82
|
+
export type UnifiedArg<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> = {
|
|
83
83
|
context: TContext;
|
|
84
84
|
event: TExpressionEvent;
|
|
85
|
-
self:
|
|
85
|
+
self: ActorSelf<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>, // TODO: this should be replaced with `TChildren`
|
|
86
86
|
StateValue, string, unknown, TODO, // TMeta
|
|
87
87
|
TODO>, TEvent, AnyEventObject>;
|
|
88
88
|
system: AnyActorSystem;
|
|
89
|
-
}
|
|
89
|
+
} & OutputArg<TExpressionEvent>;
|
|
90
90
|
export type MachineContext = Record<string, any>;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
type DoneEventType = `xstate.done.actor.${string}` | `xstate.done.state.${string}`;
|
|
92
|
+
export type OutputArg<TEvent extends EventObject> = TEvent extends {
|
|
93
|
+
type: DoneEventType;
|
|
94
|
+
output: infer TOutput;
|
|
95
|
+
} ? {
|
|
96
|
+
output: TOutput;
|
|
97
|
+
} : {
|
|
98
|
+
output: undefined;
|
|
99
|
+
};
|
|
100
|
+
export type ActionArgs<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> = UnifiedArg<TContext, TExpressionEvent, TEvent> & {
|
|
101
|
+
children: Record<string, AnyActor>;
|
|
102
|
+
};
|
|
103
|
+
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
104
|
export type OutputFrom<T> = T extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? (TSnapshot & {
|
|
95
105
|
status: 'done';
|
|
96
106
|
})['output'] : T extends ActorRef<infer TSnapshot, infer _TEvent, infer _TEmitted> ? (TSnapshot & {
|
|
97
107
|
status: 'done';
|
|
98
108
|
})['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
109
|
export type NoRequiredParams<T extends ParameterizedObject> = T extends any ? undefined extends T['params'] ? T['type'] : never : never;
|
|
109
110
|
export type ConditionalRequired<T, Condition extends boolean> = Condition extends true ? Required<T> : T;
|
|
110
111
|
export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent extends EventObject, T extends ParameterizedObject> = T extends any ? ConditionalRequired<{
|
|
111
112
|
type: T['type'];
|
|
112
|
-
params?: T['params'] | (({ context, event }: {
|
|
113
|
+
params?: T['params'] | (({ context, event, output }: {
|
|
113
114
|
context: TContext;
|
|
114
115
|
event: TExpressionEvent;
|
|
115
|
-
}) => T['params']);
|
|
116
|
+
} & OutputArg<TExpressionEvent>) => T['params']);
|
|
116
117
|
}, 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
118
|
export type StateKey = string | AnyMachineSnapshot;
|
|
121
119
|
export interface StateValueMap {
|
|
122
120
|
[key: string]: StateValue | undefined;
|
|
@@ -132,30 +130,37 @@ export interface StateValueMap {
|
|
|
132
130
|
*/
|
|
133
131
|
export type StateValue = string | StateValueMap;
|
|
134
132
|
export type TransitionTarget = SingleOrArray<string>;
|
|
135
|
-
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject,
|
|
136
|
-
|
|
137
|
-
|
|
133
|
+
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['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
134
|
+
actions?: never;
|
|
135
|
+
guard?: unknown;
|
|
138
136
|
reenter?: boolean;
|
|
139
137
|
target?: TransitionTarget | undefined;
|
|
138
|
+
context?: Partial<TContext>;
|
|
139
|
+
to?: TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
140
140
|
meta?: TMeta;
|
|
141
141
|
description?: string;
|
|
142
142
|
}
|
|
143
|
-
export interface InitialTransitionConfig<TContext extends MachineContext, TEvent extends EventObject,
|
|
144
|
-
TODO> {
|
|
143
|
+
export interface InitialTransitionConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> extends TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> {
|
|
145
144
|
target: string;
|
|
146
145
|
}
|
|
147
146
|
export type AnyTransitionConfig = TransitionConfig<any, // TContext
|
|
148
147
|
any, // TExpressionEvent
|
|
149
148
|
any, // TEvent
|
|
150
|
-
any, // TActor
|
|
151
|
-
any, // TAction
|
|
152
|
-
any, // TGuard
|
|
153
|
-
any, // TDelay
|
|
154
149
|
any, // TEmitted
|
|
150
|
+
any, // TMeta
|
|
151
|
+
any, // TActionMap
|
|
152
|
+
any, // TActorMap
|
|
153
|
+
any, // TGuardMap
|
|
155
154
|
any>;
|
|
156
|
-
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject,
|
|
155
|
+
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
157
156
|
id: string;
|
|
158
|
-
|
|
157
|
+
registryKey: string | undefined;
|
|
158
|
+
logic: string | AnyActorLogic | (({ actorSources, context, event, self }: {
|
|
159
|
+
actorSources: TActorMap;
|
|
160
|
+
context: TContext;
|
|
161
|
+
event: TEvent;
|
|
162
|
+
self: AnyActorRef;
|
|
163
|
+
}) => string | AnyActorLogic);
|
|
159
164
|
/** The source of the actor logic to be invoked */
|
|
160
165
|
src: AnyActorLogic | string;
|
|
161
166
|
input?: Mapper<TContext, TEvent, NonReducibleUnknown, TEvent> | NonReducibleUnknown;
|
|
@@ -163,46 +168,80 @@ export interface InvokeDefinition<TContext extends MachineContext, TEvent extend
|
|
|
163
168
|
* The transition to take upon the invoked child machine reaching its final
|
|
164
169
|
* top-level state.
|
|
165
170
|
*/
|
|
166
|
-
onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneActorEvent<unknown>, TEvent,
|
|
171
|
+
onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneActorEvent<unknown>, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>>;
|
|
167
172
|
/**
|
|
168
173
|
* The transition to take upon the invoked child machine sending an error
|
|
169
174
|
* event.
|
|
170
175
|
*/
|
|
171
|
-
onError?: string | SingleOrArray<TransitionConfig<TContext, ErrorActorEvent, TEvent,
|
|
172
|
-
onSnapshot?: string | SingleOrArray<TransitionConfig<TContext, SnapshotEvent, TEvent,
|
|
173
|
-
|
|
176
|
+
onError?: string | SingleOrArray<TransitionConfig<TContext, ErrorActorEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>>;
|
|
177
|
+
onSnapshot?: string | SingleOrArray<TransitionConfig<TContext, SnapshotEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>>;
|
|
178
|
+
/**
|
|
179
|
+
* The duration (in ms) after which this invocation times out if it has not
|
|
180
|
+
* completed.
|
|
181
|
+
*/
|
|
182
|
+
timeout?: number | ((args: {
|
|
183
|
+
context: TContext;
|
|
184
|
+
event: TEvent;
|
|
185
|
+
}) => number);
|
|
186
|
+
/** The transition to take when the invoke-level `timeout` expires. */
|
|
187
|
+
onTimeout?: string | SingleOrArray<TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>>;
|
|
174
188
|
}
|
|
189
|
+
export type AnyInvokeDefinition = InvokeDefinition<MachineContext, EventObject, EventObject, MetaObject, Implementations['actions'], Implementations['actorSources'], Implementations['guards'], Implementations['delays']>;
|
|
175
190
|
type Delay<TDelay extends string> = TDelay | number;
|
|
176
|
-
export type DelayedTransitions<TContext extends MachineContext, TEvent extends EventObject,
|
|
177
|
-
[K in Delay<
|
|
178
|
-
TODO>>;
|
|
191
|
+
export type DelayedTransitions<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
192
|
+
[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
193
|
};
|
|
180
|
-
export type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | ({} & string);
|
|
194
|
+
export type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'choice' | 'history' | ({} & string);
|
|
181
195
|
export type SingleOrArray<T> = readonly T[] | T;
|
|
182
196
|
export type StateNodesConfig<TContext extends MachineContext, TEvent extends EventObject> = {
|
|
183
197
|
[K in string]: StateNode<TContext, TEvent>;
|
|
184
198
|
};
|
|
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
199
|
export type TransitionConfigTarget = string | undefined;
|
|
192
|
-
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject,
|
|
193
|
-
export type
|
|
194
|
-
|
|
200
|
+
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['actorSources'], 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>>;
|
|
201
|
+
export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, _TCtx = [TContext] extends [never] ? any : TContext> = (args: TransitionFunctionArgs<_TCtx, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>, enq: EnqueueObject<TEvent, TEmitted>) => {
|
|
202
|
+
target?: string | string[];
|
|
203
|
+
context?: Partial<_TCtx>;
|
|
204
|
+
reenter?: boolean;
|
|
205
|
+
meta?: TMeta;
|
|
206
|
+
} | void;
|
|
207
|
+
type TransitionFunctionArgs<TContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
208
|
+
context: TContext;
|
|
209
|
+
event: TCurrentEvent;
|
|
210
|
+
self: ActorSelf<MachineSnapshot<TContext & MachineContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO>, TEvent>;
|
|
211
|
+
parent: UnknownActorRef | undefined;
|
|
212
|
+
value: StateValue;
|
|
213
|
+
children: Record<string, AnyActor>;
|
|
214
|
+
system: AnyActorSystem;
|
|
215
|
+
actions: TActionMap;
|
|
216
|
+
actorSources: TActorMap;
|
|
217
|
+
guards: TGuardMap;
|
|
218
|
+
delays: TDelayMap;
|
|
219
|
+
} & OutputArg<TCurrentEvent>;
|
|
220
|
+
export type AnyTransitionConfigFunction = TransitionConfigFunction<any, any, any, any, any, any, any, any, any, any>;
|
|
221
|
+
export type TransitionsConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
222
|
+
[K in EventDescriptor<TEvent>]?: TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
195
223
|
};
|
|
196
224
|
type PartialEventDescriptor<TEventType extends string> = TEventType extends `${infer TLeading}.${infer TTail}` ? `${TLeading}.*` | `${TLeading}.${PartialEventDescriptor<TTail>}` : never;
|
|
197
225
|
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;
|
|
226
|
+
export type NormalizeDescriptor<TDescriptor extends string> = TDescriptor extends '*' ? string : TDescriptor extends `${infer TLeading}.*` ? `${TLeading}.${string}` : TDescriptor;
|
|
227
|
+
type EventTypeMatchesDescriptor<TEventType extends string, TDescriptor extends string> = TEventType extends NormalizeDescriptor<TDescriptor> ? true : false;
|
|
228
|
+
type IsInternalEventType<TEventType extends string, TDescriptors extends string> = true extends (TDescriptors extends any ? EventTypeMatchesDescriptor<TEventType, TDescriptors> : never) ? true : false;
|
|
229
|
+
type ExcludeInternalEvents<TEvent extends EventObject, TDescriptors extends string> = TEvent extends any ? IsInternalEventType<TEvent['type'], TDescriptors> extends true ? never : TEvent : never;
|
|
199
230
|
export type IsLiteralString<T extends string> = string extends T ? false : true;
|
|
200
|
-
type
|
|
231
|
+
type ActorImplementationsBySrc<TActor extends ProvidedActor> = {
|
|
232
|
+
[A in TActor as A['src']]: A['logic'];
|
|
233
|
+
};
|
|
234
|
+
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
235
|
src: infer TSrc;
|
|
202
236
|
} ? Compute<{
|
|
203
|
-
|
|
237
|
+
registryKey?: string;
|
|
204
238
|
/** The source of the machine to be invoked, or the machine itself. */
|
|
205
|
-
src: TSrc
|
|
239
|
+
src: TSrc | (({ actorSources, context, event, self }: {
|
|
240
|
+
actorSources: ActorImplementationsBySrc<TActor>;
|
|
241
|
+
context: TContext;
|
|
242
|
+
event: TEvent;
|
|
243
|
+
self: AnyActorRef;
|
|
244
|
+
}) => TSrc | TSpecificActor['logic']);
|
|
206
245
|
/**
|
|
207
246
|
* The unique identifier for the invoked machine. If not specified,
|
|
208
247
|
* this will be the machine's own `id`, or the URL (from `src`).
|
|
@@ -213,23 +252,38 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
213
252
|
* The transition to take upon the invoked child machine reaching
|
|
214
253
|
* its final top-level state.
|
|
215
254
|
*/
|
|
216
|
-
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<OutputFrom<TSpecificActor['logic']>>, TEvent,
|
|
255
|
+
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<OutputFrom<TSpecificActor['logic']>>, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
217
256
|
/**
|
|
218
257
|
* The transition to take upon the invoked child machine sending an
|
|
219
258
|
* error event.
|
|
220
259
|
*/
|
|
221
|
-
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent,
|
|
222
|
-
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent<SnapshotFrom<TSpecificActor['logic']>>, TEvent,
|
|
260
|
+
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
261
|
+
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent<SnapshotFrom<TSpecificActor['logic']>>, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
262
|
+
timeout?: number | ((args: {
|
|
263
|
+
context: TContext;
|
|
264
|
+
event: TEvent;
|
|
265
|
+
}) => number);
|
|
266
|
+
onTimeout?: string | SingleOrArray<TransitionConfigOrTarget<TContext, TEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
223
267
|
} & {
|
|
224
268
|
[K in RequiredActorOptions<TSpecificActor>]: unknown;
|
|
225
269
|
}> | {
|
|
226
270
|
id?: never;
|
|
227
|
-
|
|
228
|
-
src: AnyActorLogic
|
|
271
|
+
registryKey?: string;
|
|
272
|
+
src: string | AnyActorLogic | (({ actorSources, context, event, self }: {
|
|
273
|
+
actorSources: ActorImplementationsBySrc<TActor>;
|
|
274
|
+
context: TContext;
|
|
275
|
+
event: TEvent;
|
|
276
|
+
self: AnyActorRef;
|
|
277
|
+
}) => string | AnyActorLogic);
|
|
229
278
|
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,
|
|
279
|
+
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<unknown>, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
280
|
+
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
281
|
+
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
282
|
+
timeout?: number | ((args: {
|
|
283
|
+
context: TContext;
|
|
284
|
+
event: TEvent;
|
|
285
|
+
}) => number);
|
|
286
|
+
onTimeout?: string | SingleOrArray<TransitionConfigOrTarget<TContext, TEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
233
287
|
} : never;
|
|
234
288
|
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
289
|
/**
|
|
@@ -237,262 +291,63 @@ export type InvokeConfig<TContext extends MachineContext, TEvent extends EventOb
|
|
|
237
291
|
* will be the machine's own `id`, or the URL (from `src`).
|
|
238
292
|
*/
|
|
239
293
|
id?: string;
|
|
240
|
-
|
|
294
|
+
registryKey?: string;
|
|
241
295
|
/** The source of the machine to be invoked, or the machine itself. */
|
|
242
|
-
src: AnyActorLogic |
|
|
296
|
+
src: string | AnyActorLogic | (({ actorSources, context, event, self }: {
|
|
297
|
+
actorSources: ActorImplementationsBySrc<TActor>;
|
|
298
|
+
context: TContext;
|
|
299
|
+
event: TEvent;
|
|
300
|
+
self: AnyActorRef;
|
|
301
|
+
}) => string | AnyActorLogic);
|
|
243
302
|
input?: Mapper<TContext, TEvent, NonReducibleUnknown, TEvent> | NonReducibleUnknown;
|
|
244
303
|
/**
|
|
245
304
|
* The transition to take upon the invoked child machine reaching its
|
|
246
305
|
* final top-level state.
|
|
247
306
|
*/
|
|
248
|
-
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<
|
|
249
|
-
TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
307
|
+
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<unknown>, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
250
308
|
/**
|
|
251
309
|
* The transition to take upon the invoked child machine sending an
|
|
252
310
|
* error event.
|
|
253
311
|
*/
|
|
254
|
-
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent,
|
|
255
|
-
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent,
|
|
312
|
+
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
313
|
+
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
314
|
+
timeout?: number | ((args: {
|
|
315
|
+
context: TContext;
|
|
316
|
+
event: TEvent;
|
|
317
|
+
}) => number);
|
|
318
|
+
onTimeout?: string | SingleOrArray<TransitionConfigOrTarget<TContext, TEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
256
319
|
};
|
|
257
320
|
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>;
|
|
321
|
+
export type AnyStateNodeConfig = Next_StateNodeConfig<any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
322
|
+
export type AnyStateNode = StateNode<any, any> | StateNode<never, EventObject> | StateNode<any, EventObject> | StateNode<never, any>;
|
|
379
323
|
export type AnyMachineSnapshot = MachineSnapshot<any, any, any, any, any, any, any, any>;
|
|
380
|
-
/** @deprecated Use `AnyMachineSnapshot` instead */
|
|
381
|
-
export type AnyState = AnyMachineSnapshot;
|
|
382
324
|
export type AnyStateMachine = StateMachine<any, // context
|
|
383
325
|
any, // event
|
|
384
326
|
any, // children
|
|
385
|
-
any, // actor
|
|
386
|
-
any, // action
|
|
387
|
-
any, // guard
|
|
388
|
-
any, // delay
|
|
389
327
|
any, // state value
|
|
390
328
|
any, // tag
|
|
391
329
|
any, // input
|
|
392
330
|
any, // output
|
|
393
331
|
any, // emitted
|
|
394
332
|
any, // TMeta
|
|
333
|
+
any, // TStateSchema,
|
|
334
|
+
any, // TActionMap,
|
|
335
|
+
any, // TActorMap
|
|
336
|
+
any, // TGuardMap
|
|
395
337
|
any>;
|
|
396
338
|
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>;
|
|
339
|
+
export type DelayConfig<TContext extends MachineContext, TExpressionEvent extends EventObject> = number | DelayExpr<TContext, TExpressionEvent>;
|
|
340
|
+
export type InitialContext<TContext extends MachineContext, TActorMap extends Implementations['actorSources'], TInput, TEvent extends EventObject> = TContext | ContextFactory<TContext, TActorMap, TInput, TEvent>;
|
|
341
|
+
export type ContextFactory<TContext extends MachineContext, TActorMap extends Implementations['actorSources'], TInput, TEvent extends EventObject = EventObject> = ({ spawn, actorSources, input, self }: {
|
|
342
|
+
spawn: Spawner;
|
|
343
|
+
actorSources: TActorMap;
|
|
453
344
|
input: TInput;
|
|
454
|
-
self:
|
|
345
|
+
self: ActorSelf<MachineSnapshot<[
|
|
346
|
+
TContext
|
|
347
|
+
] extends [never] ? any : TContext, TEvent, Record<string, AnyActorRef | undefined>, // TODO: this should be replaced with `TChildren`
|
|
455
348
|
StateValue, string, unknown, TODO, // TMeta
|
|
456
349
|
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>;
|
|
350
|
+
}) => [TContext] extends [never] ? MachineContext : TContext;
|
|
496
351
|
export interface ProvidedActor {
|
|
497
352
|
src: string;
|
|
498
353
|
logic: UnknownActorLogic;
|
|
@@ -509,7 +364,7 @@ export interface SetupTypes<TContext extends MachineContext, TEvent extends Even
|
|
|
509
364
|
meta?: TMeta;
|
|
510
365
|
}
|
|
511
366
|
export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject> extends SetupTypes<TContext, TEvent, never, TTag, TInput, TOutput, TEmitted, TMeta> {
|
|
512
|
-
|
|
367
|
+
actorSources?: TActor;
|
|
513
368
|
actions?: TAction;
|
|
514
369
|
guards?: TGuard;
|
|
515
370
|
delays?: TDelay;
|
|
@@ -519,13 +374,12 @@ export interface HistoryStateNode<TContext extends MachineContext> extends State
|
|
|
519
374
|
history: 'shallow' | 'deep';
|
|
520
375
|
target: string | undefined;
|
|
521
376
|
}
|
|
522
|
-
export type HistoryValue
|
|
377
|
+
export type HistoryValue = Record<string, Array<AnyStateNode>>;
|
|
523
378
|
export type PersistedHistoryValue = Record<string, Array<{
|
|
524
379
|
id: string;
|
|
525
380
|
}>>;
|
|
526
|
-
export type AnyHistoryValue = HistoryValue
|
|
527
|
-
export type StateFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends AnyStateMachine ?
|
|
528
|
-
export type Transitions<TContext extends MachineContext, TEvent extends EventObject> = Array<TransitionDefinition<TContext, TEvent>>;
|
|
381
|
+
export type AnyHistoryValue = HistoryValue;
|
|
382
|
+
export type StateFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends AnyStateMachine ? SnapshotFrom<T> : T extends (...args: any[]) => AnyStateMachine ? SnapshotFrom<ReturnType<T>> : never;
|
|
529
383
|
export interface DoneActorEvent<TOutput = unknown, TId extends string = string> extends EventObject {
|
|
530
384
|
type: `xstate.done.actor.${TId}`;
|
|
531
385
|
output: TOutput;
|
|
@@ -544,64 +398,50 @@ export interface DoneStateEvent<TOutput = unknown> extends EventObject {
|
|
|
544
398
|
type: `xstate.done.state.${string}`;
|
|
545
399
|
output: TOutput;
|
|
546
400
|
}
|
|
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
401
|
export declare enum SpecialTargets {
|
|
551
|
-
Parent = "#_parent",
|
|
552
402
|
Internal = "#_internal"
|
|
553
403
|
}
|
|
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;
|
|
404
|
+
export type Mapper<TContext extends MachineContext, TExpressionEvent extends EventObject, TResult, TEvent extends EventObject, _TCtx = [TContext] extends [never] ? any : TContext> = (args: {
|
|
405
|
+
context: _TCtx;
|
|
573
406
|
event: TExpressionEvent;
|
|
574
|
-
self:
|
|
407
|
+
self: ActorSelf<MachineSnapshot<_TCtx & MachineContext, TEvent, Record<string, AnyActorRef>, // TODO: this should be replaced with `TChildren`
|
|
575
408
|
StateValue, string, unknown, TODO, // TMeta
|
|
576
409
|
TODO>, TEvent, AnyEventObject>;
|
|
577
|
-
}) => TResult;
|
|
410
|
+
} & OutputArg<TExpressionEvent>) => TResult;
|
|
578
411
|
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[];
|
|
412
|
+
TODO>, 'target' | 'to'> {
|
|
413
|
+
target: ReadonlyArray<AnyStateNode> | undefined;
|
|
414
|
+
source: AnyStateNode;
|
|
583
415
|
reenter: boolean;
|
|
584
|
-
guard?: UnknownGuard;
|
|
585
416
|
eventType: EventDescriptor<TEvent>;
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
meta?: Record<string, any>;
|
|
593
|
-
};
|
|
417
|
+
to?: ((...args: any[]) => any) | undefined;
|
|
418
|
+
input?: Record<string, unknown> | ((args: {
|
|
419
|
+
context: any;
|
|
420
|
+
event: any;
|
|
421
|
+
output: any;
|
|
422
|
+
}) => Record<string, unknown>);
|
|
594
423
|
}
|
|
595
424
|
export type AnyTransitionDefinition = TransitionDefinition<any, any>;
|
|
596
|
-
export
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
425
|
+
export type InitialTransitionDefinition = {
|
|
426
|
+
source: AnyStateNode;
|
|
427
|
+
target: AnyStateNode[] | undefined;
|
|
428
|
+
reenter?: boolean;
|
|
429
|
+
eventType?: EventDescriptor<any>;
|
|
430
|
+
input?: Record<string, unknown> | ((args: {
|
|
431
|
+
context: MachineContext;
|
|
432
|
+
event: EventObject;
|
|
433
|
+
}) => Record<string, unknown>);
|
|
434
|
+
};
|
|
600
435
|
export type TransitionDefinitionMap<TContext extends MachineContext, TEvent extends EventObject> = {
|
|
601
436
|
[K in EventDescriptor<TEvent>]: Array<TransitionDefinition<TContext, ExtractEvent<TEvent, K>>>;
|
|
602
437
|
};
|
|
438
|
+
export type DelayExpr<TContext extends MachineContext, TEvent extends EventObject> = (args: {
|
|
439
|
+
context: [TContext] extends [never] ? any : TContext;
|
|
440
|
+
event: TEvent;
|
|
441
|
+
stateNode: AnyStateNode;
|
|
442
|
+
}) => number;
|
|
603
443
|
export interface DelayedTransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends TransitionDefinition<TContext, TEvent> {
|
|
604
|
-
delay: number | string | DelayExpr<TContext, TEvent
|
|
444
|
+
delay: number | string | DelayExpr<TContext, TEvent>;
|
|
605
445
|
}
|
|
606
446
|
export interface StateLike<TContext extends MachineContext> {
|
|
607
447
|
value: StateValue;
|
|
@@ -610,15 +450,52 @@ export interface StateLike<TContext extends MachineContext> {
|
|
|
610
450
|
}
|
|
611
451
|
export interface StateConfig<TContext extends MachineContext, TEvent extends EventObject> {
|
|
612
452
|
context: TContext;
|
|
613
|
-
historyValue?: HistoryValue
|
|
614
|
-
children: Record<string, AnyActorRef>;
|
|
453
|
+
historyValue?: HistoryValue;
|
|
454
|
+
children: Record<string, AnyActorRef | undefined>;
|
|
615
455
|
status: SnapshotStatus;
|
|
616
456
|
output?: any;
|
|
617
457
|
error?: unknown;
|
|
618
|
-
machine?: StateMachine<TContext, TEvent, any, any, any, any, any, any, any, any, any, any, any,
|
|
619
|
-
any>;
|
|
458
|
+
machine?: StateMachine<TContext, TEvent, any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
620
459
|
}
|
|
460
|
+
/**
|
|
461
|
+
* A pending effect (delayed event/transition that has not fired yet) captured
|
|
462
|
+
* in a persisted snapshot — a serialized built-in action descriptor plus its
|
|
463
|
+
* runtime progress, with enough information to restore it under any strategy.
|
|
464
|
+
*/
|
|
465
|
+
export interface PendingEffect {
|
|
466
|
+
/** The serialized built-in action type for this effect. */
|
|
467
|
+
type: '@xstate.raise';
|
|
468
|
+
event: EventObject;
|
|
469
|
+
id: string;
|
|
470
|
+
/** The original delay (in ms) the effect was scheduled with. */
|
|
471
|
+
delay: number;
|
|
472
|
+
/** Wall-clock timestamp (ms) when the effect was scheduled. */
|
|
473
|
+
startedAt: number;
|
|
474
|
+
/** Wall-clock time (ms) that had elapsed when the snapshot was persisted. */
|
|
475
|
+
elapsed: number;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* How pending effects (timers) from a persisted snapshot are restored on
|
|
479
|
+
* `actor.start()`:
|
|
480
|
+
*
|
|
481
|
+
* - `'resume'` (default) — the clock was "frozen" while persisted: a 5-minute
|
|
482
|
+
* timer persisted with 1 minute elapsed fires after 4 more minutes.
|
|
483
|
+
* - `'restart'` — timers start over with their full delay.
|
|
484
|
+
* - `'absolute'` — timers honor the original wall-clock expiry (`startedAt +
|
|
485
|
+
* delay`); already-expired timers fire immediately.
|
|
486
|
+
* - A custom function receiving the pending effect and returning the remaining
|
|
487
|
+
* delay in ms.
|
|
488
|
+
*/
|
|
489
|
+
export type TimersRestoreStrategy = 'resume' | 'restart' | 'absolute' | ((pendingEffect: PendingEffect) => number);
|
|
621
490
|
export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
491
|
+
/**
|
|
492
|
+
* How pending timers (delayed events/transitions) from a persisted `snapshot`
|
|
493
|
+
* are restored when the actor starts. Applies to this actor and (when this is
|
|
494
|
+
* the root) all rehydrated child actors.
|
|
495
|
+
*
|
|
496
|
+
* @default 'resume'
|
|
497
|
+
*/
|
|
498
|
+
timers?: TimersRestoreStrategy;
|
|
622
499
|
/**
|
|
623
500
|
* The clock that is responsible for setting and clearing timeouts, such as
|
|
624
501
|
* delayed events and transitions.
|
|
@@ -642,13 +519,13 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
642
519
|
* native `console.log(...)` method.
|
|
643
520
|
*/
|
|
644
521
|
logger?: (...args: any[]) => void;
|
|
645
|
-
parent?:
|
|
522
|
+
parent?: AnyActor;
|
|
646
523
|
/** The custom `id` for referencing this service. */
|
|
647
524
|
id?: string;
|
|
648
525
|
/** @deprecated Use `inspect` instead. */
|
|
649
526
|
devTools?: never;
|
|
650
|
-
/** The
|
|
651
|
-
|
|
527
|
+
/** The registry key to register this actor under. */
|
|
528
|
+
registryKey?: string;
|
|
652
529
|
/** The input data to pass to the actor. */
|
|
653
530
|
input?: InputFrom<TLogic>;
|
|
654
531
|
/**
|
|
@@ -675,13 +552,14 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
675
552
|
*
|
|
676
553
|
* @remarks
|
|
677
554
|
* If a callback function is provided, it can accept an inspection event
|
|
678
|
-
* argument. The
|
|
555
|
+
* argument. The inspection protocol has two event types:
|
|
679
556
|
*
|
|
680
|
-
* - `@xstate.actor` - An actor ref
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
684
|
-
*
|
|
557
|
+
* - `@xstate.actor` - An actor ref was created in the system (announces actor
|
|
558
|
+
* topology: identity + parent).
|
|
559
|
+
* - `@xstate.transition` - An actor transitioned. Carries every facet of the
|
|
560
|
+
* transition with flat, always-present fields: `event`, `snapshot`,
|
|
561
|
+
* `sourceRef`, `microsteps`, executed `actions`, and `sent`/scheduled
|
|
562
|
+
* events.
|
|
685
563
|
*
|
|
686
564
|
* @example
|
|
687
565
|
*
|
|
@@ -699,19 +577,18 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
699
577
|
* }
|
|
700
578
|
*
|
|
701
579
|
* if (inspectionEvent.type === '@xstate.actor') {
|
|
702
|
-
* console.log(inspectionEvent.actorRef);
|
|
580
|
+
* console.log(inspectionEvent.actorRef, inspectionEvent.parentRef);
|
|
703
581
|
* }
|
|
704
582
|
*
|
|
705
|
-
* if (inspectionEvent.type === '@xstate.
|
|
583
|
+
* if (inspectionEvent.type === '@xstate.transition') {
|
|
706
584
|
* console.log(inspectionEvent.sourceRef);
|
|
707
585
|
* console.log(inspectionEvent.actorRef);
|
|
708
586
|
* console.log(inspectionEvent.event);
|
|
709
|
-
* }
|
|
710
|
-
*
|
|
711
|
-
* if (inspectionEvent.type === '@xstate.snapshot') {
|
|
712
|
-
* console.log(inspectionEvent.actorRef);
|
|
713
|
-
* console.log(inspectionEvent.event);
|
|
714
587
|
* console.log(inspectionEvent.snapshot);
|
|
588
|
+
* // flat, always-present facets — no narrowing required
|
|
589
|
+
* console.log(inspectionEvent.actions);
|
|
590
|
+
* console.log(inspectionEvent.sent);
|
|
591
|
+
* console.log(inspectionEvent.microsteps);
|
|
715
592
|
* }
|
|
716
593
|
* }
|
|
717
594
|
* });
|
|
@@ -731,19 +608,20 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
731
608
|
* }
|
|
732
609
|
*
|
|
733
610
|
* if (inspectionEvent.type === '@xstate.actor') {
|
|
734
|
-
* console.log(
|
|
611
|
+
* console.log(
|
|
612
|
+
* inspectionEvent.actorRef,
|
|
613
|
+
* inspectionEvent.parentRef
|
|
614
|
+
* );
|
|
735
615
|
* }
|
|
736
616
|
*
|
|
737
|
-
* if (inspectionEvent.type === '@xstate.
|
|
617
|
+
* if (inspectionEvent.type === '@xstate.transition') {
|
|
738
618
|
* console.log(inspectionEvent.sourceRef);
|
|
739
619
|
* console.log(inspectionEvent.actorRef);
|
|
740
620
|
* console.log(inspectionEvent.event);
|
|
741
|
-
* }
|
|
742
|
-
*
|
|
743
|
-
* if (inspectionEvent.type === '@xstate.snapshot') {
|
|
744
|
-
* console.log(inspectionEvent.actorRef);
|
|
745
|
-
* console.log(inspectionEvent.event);
|
|
746
621
|
* console.log(inspectionEvent.snapshot);
|
|
622
|
+
* console.log(inspectionEvent.actions);
|
|
623
|
+
* console.log(inspectionEvent.sent);
|
|
624
|
+
* console.log(inspectionEvent.microsteps);
|
|
747
625
|
* }
|
|
748
626
|
* }
|
|
749
627
|
* }
|
|
@@ -752,7 +630,7 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
752
630
|
*/
|
|
753
631
|
inspect?: Observer<InspectionEvent> | ((inspectionEvent: InspectionEvent) => void);
|
|
754
632
|
}
|
|
755
|
-
export type AnyActor =
|
|
633
|
+
export type AnyActor = ActorInstance<any, any, any, any>;
|
|
756
634
|
/** @deprecated Use `AnyActor` instead. */
|
|
757
635
|
export type AnyInterpreter = AnyActor;
|
|
758
636
|
export type Observer<T> = {
|
|
@@ -784,50 +662,106 @@ export interface BaseActorRef<TEvent extends EventObject> {
|
|
|
784
662
|
export interface ActorLike<TCurrent, TEvent extends EventObject> extends Subscribable<TCurrent> {
|
|
785
663
|
send: (event: TEvent) => void;
|
|
786
664
|
}
|
|
787
|
-
|
|
665
|
+
/**
|
|
666
|
+
* A consumer-facing actor handle.
|
|
667
|
+
*
|
|
668
|
+
* `ActorRef` describes the contract a consumer needs: which events can be sent
|
|
669
|
+
* to the actor, which snapshot it publishes for observation, and which emitted
|
|
670
|
+
* events can be listened to. It intentionally does not expose lifecycle control
|
|
671
|
+
* or runtime internals. A concrete `Actor` satisfies this interface, so APIs
|
|
672
|
+
* should accept `ActorRef` whenever they only need to send events, read
|
|
673
|
+
* snapshots, or listen to emitted events.
|
|
674
|
+
*/
|
|
675
|
+
export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> extends Subscribable<TSnapshot>, InteropObservable<TSnapshot> {
|
|
676
|
+
send: (event: TSendEvent) => void;
|
|
677
|
+
getSnapshot: () => TSnapshot;
|
|
678
|
+
on: <TType extends TEmitted['type'] | '*'>(type: TType, handler: (emitted: TEmitted & (TType extends '*' ? unknown : {
|
|
679
|
+
type: TType;
|
|
680
|
+
})) => void) => Subscription;
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Runtime-only actor capabilities.
|
|
684
|
+
*
|
|
685
|
+
* These members are needed by the interpreter, scheduler, inspection, and child
|
|
686
|
+
* management code. Public consumer APIs should prefer `ActorRef` unless they
|
|
687
|
+
* genuinely need lifecycle control such as starting, stopping, or accessing
|
|
688
|
+
* system-owned runtime state.
|
|
689
|
+
*/
|
|
690
|
+
export interface ActorRuntime<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, _TEmitted extends EventObject = EventObject> {
|
|
788
691
|
/** The unique identifier for this actor relative to its parent. */
|
|
789
692
|
id: string;
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
693
|
+
/**
|
|
694
|
+
* The globally unique process ID for this invocation.
|
|
695
|
+
*
|
|
696
|
+
* @remarks
|
|
697
|
+
* This is only defined once the actor is started.
|
|
698
|
+
*/
|
|
699
|
+
sessionId: string | undefined;
|
|
700
|
+
start: () => this;
|
|
794
701
|
getPersistedSnapshot: () => Snapshot<unknown>;
|
|
795
702
|
stop: () => void;
|
|
796
703
|
toJSON?: () => any;
|
|
797
|
-
_parent?:
|
|
798
|
-
system:
|
|
704
|
+
_parent?: any;
|
|
705
|
+
system: any;
|
|
799
706
|
src: string | AnyActorLogic;
|
|
800
|
-
|
|
801
|
-
type: TType;
|
|
802
|
-
})) => void) => Subscription;
|
|
707
|
+
trigger: any;
|
|
803
708
|
select<TSelected>(selector: (snapshot: TSnapshot) => TSelected, equalityFn?: (a: TSelected, b: TSelected) => boolean): Readable<TSelected>;
|
|
804
709
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
710
|
+
/**
|
|
711
|
+
* A concrete actor instance type.
|
|
712
|
+
*
|
|
713
|
+
* `ActorInstance` combines the consumer `ActorRef` contract with runtime
|
|
714
|
+
* lifecycle capabilities. Values returned by `createActor(...)` and
|
|
715
|
+
* `spawn(...)` naturally satisfy narrower `ActorRef` contracts.
|
|
716
|
+
*/
|
|
717
|
+
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> {
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* The actor's own full self handle.
|
|
721
|
+
*
|
|
722
|
+
* Internals and action/guard implementations receive this shape because `self`
|
|
723
|
+
* can participate in runtime-owned behavior while still being usable wherever
|
|
724
|
+
* an `ActorRef` is expected.
|
|
725
|
+
*/
|
|
726
|
+
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>;
|
|
727
|
+
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 {
|
|
728
|
+
internalEvents?: readonly EventDescriptor<TEvent>[];
|
|
729
|
+
} ? 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;
|
|
730
|
+
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 {
|
|
731
|
+
internalEvents?: readonly EventDescriptor<TEvent>[];
|
|
732
|
+
} ? ExcludeInternalEvents<TEvent, TConfig['internalEvents'] extends readonly EventDescriptor<TEvent>[] ? TConfig['internalEvents'] extends readonly (infer TDesc)[] ? Extract<TDesc, string> : never : never> : TEvent : EventFromLogic<TLogic>;
|
|
733
|
+
type OpaqueMachineSnapshot<TSnapshot extends Snapshot<unknown>> = TSnapshot extends MachineSnapshot<infer TContext, infer TEvent, infer TChildren, infer TStateValue, infer TTag, infer TOutput, infer TMeta, infer _TStateSchema> ? MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, any> : TSnapshot;
|
|
734
|
+
export type ActorRefFromLogic<T extends AnyActorLogic> = ActorRef<OpaqueMachineSnapshot<SnapshotFrom<T>>, EventFromLogic<T>, EmittedFrom<T>, SendableEventFromLogic<T>>;
|
|
735
|
+
export type AnyActorRef = ActorRef<any, any, any, any>;
|
|
736
|
+
/** The concrete actor instance type produced from actor logic. */
|
|
737
|
+
export type ActorFromLogic<T extends AnyActorLogic> = ActorInstance<SnapshotFrom<T>, EventFromLogic<T>, EmittedFrom<T>, SendableEventFromLogic<T>>;
|
|
738
|
+
type SendableEventFromActorRef<TActorRef, TFallback extends EventObject = AnyEventObject> = [NonNullable<TActorRef>] extends [never] ? TFallback : NonNullable<TActorRef> extends infer TNonNullableActorRef ? TNonNullableActorRef extends {
|
|
739
|
+
send: (event: infer TEvent) => void;
|
|
740
|
+
} ? [TEvent] extends [never] ? TFallback : TEvent extends EventObject ? TEvent : TFallback : never : never;
|
|
741
|
+
export type ActorRefLike = Pick<AnyActor, 'sessionId' | 'send' | 'getSnapshot'>;
|
|
808
742
|
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
743
|
export type DevToolsAdapter = (service: AnyActor) => void;
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
744
|
+
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> ? {
|
|
745
|
+
actions: TActionMap;
|
|
746
|
+
actorSources: TActorMap;
|
|
747
|
+
guards: TGuardMap;
|
|
748
|
+
delays: TDelayMap;
|
|
749
|
+
} : never;
|
|
750
|
+
export interface ActorScope<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TSystem extends AnyActorSystem = AnyActorSystem, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> {
|
|
751
|
+
self: ActorSelf<TSnapshot, TEvent, TEmitted, TSendEvent>;
|
|
819
752
|
id: string;
|
|
820
753
|
sessionId: string;
|
|
821
754
|
logger: (...args: any[]) => void;
|
|
822
755
|
defer: (fn: () => void) => void;
|
|
823
756
|
emit: (event: TEmitted) => void;
|
|
824
757
|
system: TSystem;
|
|
825
|
-
stopChild: (child:
|
|
758
|
+
stopChild: (child: AnyActor) => void;
|
|
826
759
|
actionExecutor: ActionExecutor;
|
|
827
760
|
}
|
|
828
761
|
export type AnyActorScope = ActorScope<any, // TSnapshot
|
|
829
762
|
any, // TEvent
|
|
830
|
-
AnyActorSystem, any
|
|
763
|
+
AnyActorSystem, any, // TEmitted
|
|
764
|
+
any>;
|
|
831
765
|
export type SnapshotStatus = 'active' | 'done' | 'error' | 'stopped';
|
|
832
766
|
export type Snapshot<TOutput> = {
|
|
833
767
|
status: 'active';
|
|
@@ -846,6 +780,7 @@ export type Snapshot<TOutput> = {
|
|
|
846
780
|
output: undefined;
|
|
847
781
|
error: undefined;
|
|
848
782
|
};
|
|
783
|
+
export type ActorLogicTransitionResult<TSnapshot extends Snapshot<unknown>, TEffect = unknown> = [nextSnapshot: TSnapshot, effects: TEffect[]];
|
|
849
784
|
/**
|
|
850
785
|
* Represents logic which can be used by an actor.
|
|
851
786
|
*
|
|
@@ -861,14 +796,22 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
|
|
|
861
796
|
config?: unknown;
|
|
862
797
|
/**
|
|
863
798
|
* Transition function that processes the current state and an incoming event
|
|
864
|
-
* to produce a new state.
|
|
799
|
+
* to produce a new state and effects.
|
|
865
800
|
*
|
|
866
801
|
* @param snapshot - The current state.
|
|
867
802
|
* @param event - The incoming event.
|
|
868
803
|
* @param actorScope - The actor scope.
|
|
869
|
-
* @returns
|
|
804
|
+
* @returns A tuple of the next state and effects.
|
|
870
805
|
*/
|
|
871
|
-
transition: (snapshot: TSnapshot, event: TEvent, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => TSnapshot
|
|
806
|
+
transition: (snapshot: TSnapshot, event: TEvent, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => ActorLogicTransitionResult<TSnapshot>;
|
|
807
|
+
/**
|
|
808
|
+
* Transition function that produces the initial state and effects.
|
|
809
|
+
*
|
|
810
|
+
* @param actorScope - The actor scope.
|
|
811
|
+
* @param input - The input for the initial state.
|
|
812
|
+
* @returns A tuple of the initial state and effects.
|
|
813
|
+
*/
|
|
814
|
+
initialTransition: (input: TInput, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => ActorLogicTransitionResult<TSnapshot>;
|
|
872
815
|
/**
|
|
873
816
|
* Called to provide the initial state of the actor.
|
|
874
817
|
*
|
|
@@ -912,12 +855,12 @@ export type UnknownActorLogic = ActorLogic<any, // snapshot
|
|
|
912
855
|
any, // event
|
|
913
856
|
any, // input
|
|
914
857
|
AnyActorSystem, any>;
|
|
915
|
-
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
|
|
916
|
-
export type EventFromLogic<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer TEvent, infer _TInput, infer
|
|
858
|
+
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 _TSystem, infer _TEmitted> ? TSnapshot : R extends ActorScope<infer TSnapshot, infer _TEvent, infer _TEmitted, infer _TSystem> ? TSnapshot : never : never;
|
|
859
|
+
export type EventFromLogic<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? TEvent : never;
|
|
917
860
|
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> =
|
|
861
|
+
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
862
|
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> =
|
|
863
|
+
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
864
|
export type InferEvent<E extends EventObject> = {
|
|
922
865
|
[T in E['type']]: {
|
|
923
866
|
type: T;
|
|
@@ -931,16 +874,20 @@ export type TagsFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TM
|
|
|
931
874
|
export interface ActorSystemInfo {
|
|
932
875
|
actors: Record<string, AnyActorRef>;
|
|
933
876
|
}
|
|
877
|
+
export type SystemRegistry = Record<string, AnyActorLogic>;
|
|
878
|
+
export type RegistryKeyForLogic<TLogic extends AnyActorLogic, TSystemRegistry extends SystemRegistry> = string extends keyof TSystemRegistry ? string : Values<{
|
|
879
|
+
[K in keyof TSystemRegistry & string]: ActorRefFromLogic<TLogic> extends ActorRefFromLogic<TSystemRegistry[K]> ? K : never;
|
|
880
|
+
}>;
|
|
934
881
|
export type RequiredActorOptions<TActor extends ProvidedActor> = (undefined extends TActor['id'] ? never : 'id') | (undefined extends InputFrom<TActor['logic']> ? never : 'input');
|
|
935
882
|
export type RequiredLogicInput<TLogic extends AnyActorLogic> = undefined extends InputFrom<TLogic> ? never : 'input';
|
|
936
883
|
type ExtractLiteralString<T extends string | undefined> = T extends string ? string extends T ? never : T : never;
|
|
937
884
|
type ToConcreteChildren<TActor extends ProvidedActor> = {
|
|
938
|
-
[A in TActor as ExtractLiteralString<A['id']>]?:
|
|
885
|
+
[A in TActor as ExtractLiteralString<A['id']>]?: ActorFromLogic<A['logic']>;
|
|
939
886
|
};
|
|
940
887
|
type NonConcreteActors<TActor extends ProvidedActor> = TActor extends any ? ExtractLiteralString<TActor['id']> extends never ? TActor : never : never;
|
|
941
|
-
export type ToChildren<TActor extends ProvidedActor> = string extends TActor['src'] ? Record<string,
|
|
888
|
+
export type ToChildren<TActor extends ProvidedActor> = string extends TActor['src'] ? Record<string, AnyActor> : Compute<ToConcreteChildren<TActor> & {
|
|
942
889
|
include: {
|
|
943
|
-
[id: string]: NonConcreteActors<TActor> extends never ?
|
|
890
|
+
[id: string]: NonConcreteActors<TActor> extends never ? AnyActor | undefined : NonConcreteActors<TActor> extends any ? ActorFromLogic<NonConcreteActors<TActor>['logic']> | undefined : never;
|
|
944
891
|
};
|
|
945
892
|
exclude: unknown;
|
|
946
893
|
}[NonConcreteActors<TActor> extends never ? 'exclude' : 'include']>;
|
|
@@ -948,6 +895,8 @@ export type StateSchema = {
|
|
|
948
895
|
id?: string;
|
|
949
896
|
route?: unknown;
|
|
950
897
|
states?: Record<string, StateSchema>;
|
|
898
|
+
contextSchema?: StandardSchemaV1;
|
|
899
|
+
input?: unknown;
|
|
951
900
|
type?: unknown;
|
|
952
901
|
invoke?: unknown;
|
|
953
902
|
on?: unknown;
|
|
@@ -956,17 +905,32 @@ export type StateSchema = {
|
|
|
956
905
|
onDone?: unknown;
|
|
957
906
|
after?: unknown;
|
|
958
907
|
always?: unknown;
|
|
908
|
+
choice?: unknown;
|
|
959
909
|
meta?: unknown;
|
|
960
910
|
output?: unknown;
|
|
961
911
|
tags?: unknown;
|
|
962
912
|
description?: unknown;
|
|
963
913
|
};
|
|
964
|
-
export type StateSchemaFrom<T extends AnyStateMachine> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer
|
|
914
|
+
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;
|
|
965
915
|
export type StateId<TSchema extends StateSchema, TKey extends string = '(machine)', TParentKey extends string | null = null> = (TSchema extends {
|
|
966
916
|
id: string;
|
|
967
917
|
} ? TSchema['id'] : TParentKey extends null ? TKey : `${TParentKey}.${TKey}`) | (TSchema['states'] extends Record<string, any> ? Values<{
|
|
968
918
|
[K in keyof TSchema['states'] & string]: StateId<TSchema['states'][K], K, TParentKey extends string ? `${TParentKey}.${TKey}` : TSchema['id'] extends string ? TSchema['id'] : TKey>;
|
|
969
919
|
}> : never);
|
|
920
|
+
/** Maps state IDs to their input types based on the StateSchema. */
|
|
921
|
+
export type StateIdInputs<TSchema extends StateSchema, TKey extends string = '(machine)', TParentKey extends string | null = null> = {
|
|
922
|
+
[K in TSchema extends {
|
|
923
|
+
id: string;
|
|
924
|
+
} ? TSchema['id'] : TParentKey extends null ? TKey : `${TParentKey}.${TKey}`]: TSchema['input'] extends undefined ? undefined : TSchema['input'];
|
|
925
|
+
} & (TSchema['states'] extends Record<string, StateSchema> ? UnionToIntersection<Values<{
|
|
926
|
+
[K in keyof TSchema['states'] & string]: StateIdInputs<TSchema['states'][K], K, TParentKey extends string ? `${TParentKey}.${TKey}` : TSchema['id'] extends string ? TSchema['id'] : TKey>;
|
|
927
|
+
}>> : {});
|
|
928
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
929
|
+
type ContextFromStateSchema<TSchema extends StateSchema, TFallbackContext extends MachineContext> = TSchema['contextSchema'] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema['contextSchema']> & MachineContext : TFallbackContext;
|
|
930
|
+
type ContextFromChildStateValue<TChildSchema extends StateSchema, TFallbackContext extends MachineContext, TChildValue> = ContextFromStateSchema<TChildSchema, TFallbackContext> & StateContextFromStateValue<TChildSchema, ContextFromStateSchema<TChildSchema, TFallbackContext>, TChildValue>;
|
|
931
|
+
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<{
|
|
932
|
+
[K in keyof TStateValue & keyof TSchema['states'] & string]: ContextFromChildStateValue<TSchema['states'][K], TFallbackContext, NonNullable<TStateValue[K]>>;
|
|
933
|
+
}>> : TFallbackContext : TFallbackContext) & MachineContext;
|
|
970
934
|
export type RoutableStateId<TSchema extends StateSchema> = (TSchema extends {
|
|
971
935
|
route: any;
|
|
972
936
|
id: string;
|
|
@@ -976,7 +940,7 @@ export type RoutableStateId<TSchema extends StateSchema> = (TSchema extends {
|
|
|
976
940
|
export interface StateMachineTypes {
|
|
977
941
|
context: MachineContext;
|
|
978
942
|
events: EventObject;
|
|
979
|
-
|
|
943
|
+
actorSources: ProvidedActor;
|
|
980
944
|
actions: ParameterizedObject;
|
|
981
945
|
guards: ParameterizedObject;
|
|
982
946
|
delays: string;
|
|
@@ -987,7 +951,7 @@ export interface StateMachineTypes {
|
|
|
987
951
|
export interface ResolvedStateMachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TEmitted extends EventObject = EventObject> {
|
|
988
952
|
context: TContext;
|
|
989
953
|
events: TEvent;
|
|
990
|
-
|
|
954
|
+
actorSources: TActor;
|
|
991
955
|
actions: TAction;
|
|
992
956
|
guards: TGuard;
|
|
993
957
|
delays: TDelay;
|
|
@@ -1015,33 +979,134 @@ export type ToStateValue<T extends StateSchema> = T extends {
|
|
|
1015
979
|
[StateKey in K]: ToStateValue<T['states'][K]>;
|
|
1016
980
|
};
|
|
1017
981
|
}>> : never) : {};
|
|
1018
|
-
export interface
|
|
1019
|
-
type: string;
|
|
1020
|
-
info: ActionArgs<MachineContext, EventObject, EventObject>;
|
|
982
|
+
export interface BaseExecutableActionObject {
|
|
1021
983
|
params: NonReducibleUnknown;
|
|
1022
|
-
|
|
984
|
+
args: unknown[];
|
|
985
|
+
exec: (() => void) | undefined;
|
|
1023
986
|
}
|
|
1024
|
-
export interface
|
|
987
|
+
export interface CustomExecutableActionObject<TType extends string = string & {}> extends BaseExecutableActionObject {
|
|
988
|
+
type: TType;
|
|
989
|
+
}
|
|
990
|
+
export interface StartExecutableActionObject extends BaseExecutableActionObject {
|
|
991
|
+
type: '@xstate.start';
|
|
992
|
+
actor: AnyActor;
|
|
993
|
+
id: string;
|
|
994
|
+
logic: AnyActorLogic;
|
|
995
|
+
src: string | AnyActorLogic;
|
|
996
|
+
input: unknown;
|
|
997
|
+
args: Parameters<(typeof builtInActions)['@xstate.start']>;
|
|
998
|
+
}
|
|
999
|
+
export interface RaiseExecutableActionObject extends BaseExecutableActionObject {
|
|
1000
|
+
type: '@xstate.raise';
|
|
1001
|
+
event: EventObject;
|
|
1002
|
+
id: string | undefined;
|
|
1003
|
+
delay: number | undefined;
|
|
1004
|
+
args: Parameters<(typeof builtInActions)['@xstate.raise']>;
|
|
1005
|
+
}
|
|
1006
|
+
export interface SendToExecutableActionObject extends BaseExecutableActionObject {
|
|
1007
|
+
type: '@xstate.sendTo';
|
|
1008
|
+
target: AnyActor;
|
|
1009
|
+
event: EventObject;
|
|
1010
|
+
id: string | undefined;
|
|
1011
|
+
delay: number | undefined;
|
|
1012
|
+
args: Parameters<(typeof builtInActions)['@xstate.sendTo']>;
|
|
1013
|
+
}
|
|
1014
|
+
export interface CancelExecutableActionObject extends BaseExecutableActionObject {
|
|
1015
|
+
type: '@xstate.cancel';
|
|
1016
|
+
id: string;
|
|
1017
|
+
args: Parameters<(typeof builtInActions)['@xstate.cancel']>;
|
|
1018
|
+
}
|
|
1019
|
+
export interface StopExecutableActionObject extends BaseExecutableActionObject {
|
|
1020
|
+
type: '@xstate.stop';
|
|
1021
|
+
actor: AnyActor;
|
|
1022
|
+
args: Parameters<(typeof builtInActions)['@xstate.stop']>;
|
|
1023
|
+
}
|
|
1024
|
+
export type BuiltInExecutableActionObject = Values<{
|
|
1025
|
+
'@xstate.start': StartExecutableActionObject;
|
|
1026
|
+
'@xstate.raise': RaiseExecutableActionObject;
|
|
1027
|
+
'@xstate.sendTo': SendToExecutableActionObject;
|
|
1028
|
+
'@xstate.cancel': CancelExecutableActionObject;
|
|
1029
|
+
'@xstate.stop': StopExecutableActionObject;
|
|
1030
|
+
}>;
|
|
1031
|
+
export type SpecialExecutableAction = BuiltInExecutableActionObject;
|
|
1032
|
+
type TransitionExecutableActionObject<TType extends string = never> = BuiltInExecutableActionObject | CustomExecutableActionObject<TType | (string & {})>;
|
|
1033
|
+
type KnownImplementationKeys<TImplementationMap> = string extends keyof TImplementationMap ? never : Extract<keyof TImplementationMap, string>;
|
|
1034
|
+
export type ExecutableActionObjectFromLogic<T extends AnyActorLogic> = T extends StateMachine<any, any, any, any, any, any, any, any, any, any, infer TActionMap, any, any, any> ? TransitionExecutableActionObject<KnownImplementationKeys<TActionMap>> : ExecutableActionObject;
|
|
1035
|
+
export type ExecutableActionObject<TType extends string = string & {}> = BuiltInExecutableActionObject | CustomExecutableActionObject<TType>;
|
|
1036
|
+
export interface ToExecutableAction<T extends ParameterizedObject> extends CustomExecutableActionObject<T['type']> {
|
|
1025
1037
|
type: T['type'];
|
|
1026
1038
|
params: T['params'];
|
|
1027
1039
|
exec: undefined;
|
|
1028
1040
|
}
|
|
1029
|
-
export interface ExecutableSpawnAction extends ExecutableActionObject {
|
|
1030
|
-
type: 'xstate.spawnChild';
|
|
1031
|
-
info: ActionArgs<MachineContext, EventObject, EventObject>;
|
|
1032
|
-
params: {
|
|
1033
|
-
id: string;
|
|
1034
|
-
actorRef: AnyActorRef | undefined;
|
|
1035
|
-
src: string | AnyActorLogic;
|
|
1036
|
-
};
|
|
1037
|
-
}
|
|
1038
|
-
export type SpecialExecutableAction = ExecutableSpawnAction | ExecutableRaiseAction | ExecutableSendToAction;
|
|
1039
|
-
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;
|
|
1040
1041
|
export type ActionExecutor = (actionToExecute: ExecutableActionObject) => void;
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1042
|
+
/** Mappers for subscribeTo - maps lifecycle events to machine events */
|
|
1043
|
+
export interface SubscribeToMappers<TSnapshot extends Snapshot<unknown>, TOutput, TMappedEvent extends EventObject> {
|
|
1044
|
+
snapshot?: (snapshot: TSnapshot) => TMappedEvent;
|
|
1045
|
+
done?: (output: TOutput) => TMappedEvent;
|
|
1046
|
+
error?: (error: unknown) => TMappedEvent;
|
|
1047
|
+
}
|
|
1048
|
+
export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends EventObject, TSystemRegistry extends SystemRegistry = SystemRegistry> = {
|
|
1049
|
+
cancel: (id: string) => void;
|
|
1050
|
+
raise: (ev: TEvent, options?: {
|
|
1051
|
+
id?: string;
|
|
1052
|
+
delay?: number;
|
|
1053
|
+
}) => void;
|
|
1054
|
+
spawn: <T extends AnyActorLogic>(logic: T, options?: {
|
|
1055
|
+
input?: InputFrom<T>;
|
|
1056
|
+
id?: string;
|
|
1057
|
+
syncSnapshot?: boolean;
|
|
1058
|
+
registryKey?: RegistryKeyForLogic<T, TSystemRegistry>;
|
|
1059
|
+
}) => ActorFromLogic<T>;
|
|
1060
|
+
emit: (emittedEvent: TEmittedEvent) => void;
|
|
1061
|
+
<T extends (...args: any[]) => any>(fn: T, ...args: Parameters<T>): void;
|
|
1062
|
+
log: (...args: any[]) => void;
|
|
1063
|
+
sendTo: <TActorRef extends {
|
|
1064
|
+
send: (...args: any[]) => void;
|
|
1065
|
+
} | undefined>(actorRef: TActorRef, event: SendableEventFromActorRef<NoInfer<TActorRef>>, options?: {
|
|
1066
|
+
id?: string;
|
|
1067
|
+
delay?: number;
|
|
1068
|
+
}) => void;
|
|
1069
|
+
stop: (actor?: AnyActor) => void;
|
|
1070
|
+
/**
|
|
1071
|
+
* Listen to emitted events from an actor. Returns a listener actor that can
|
|
1072
|
+
* be stopped via `enq.stop()`.
|
|
1073
|
+
*
|
|
1074
|
+
* @param actor - The actor to listen to
|
|
1075
|
+
* @param eventType - The emitted event type to listen for (supports
|
|
1076
|
+
* wildcards: 'event._', '_')
|
|
1077
|
+
* @param mapper - Function to transform emitted events into machine events
|
|
1078
|
+
*/
|
|
1079
|
+
listen: <TEmitted extends EventObject, TMappedEvent extends TEvent>(actor: AnyActor, eventType: string, mapper: (event: TEmitted) => TMappedEvent) => AnyActor;
|
|
1080
|
+
/**
|
|
1081
|
+
* Subscribe to lifecycle events (done/error/snapshot) from an actor. Returns
|
|
1082
|
+
* a subscription actor that can be stopped via `enq.stop()`.
|
|
1083
|
+
*
|
|
1084
|
+
* @param actor - The actor to subscribe to
|
|
1085
|
+
* @param mappers - Object with done/error/snapshot mappers, or a single
|
|
1086
|
+
* snapshot mapper function
|
|
1087
|
+
*/
|
|
1088
|
+
subscribeTo: {
|
|
1089
|
+
<TSnapshot extends Snapshot<unknown>, TOutput, TMappedEvent extends TEvent>(actor: AnyActor, mappers: SubscribeToMappers<TSnapshot, TOutput, TMappedEvent> | ((snapshot: TSnapshot) => TMappedEvent)): AnyActor;
|
|
1090
|
+
};
|
|
1091
|
+
};
|
|
1092
|
+
export type Action<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TParams = Record<string, unknown> | undefined, _TCtx = [TContext] extends [never] ? any : TContext> = (_: {
|
|
1093
|
+
context: _TCtx;
|
|
1094
|
+
event: TEvent;
|
|
1095
|
+
parent: AnyActorRef | undefined;
|
|
1096
|
+
self: ActorSelf<MachineSnapshot<_TCtx & MachineContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO>, TEvent>;
|
|
1097
|
+
children: Record<string, AnyActor | undefined>;
|
|
1098
|
+
actions: TActionMap;
|
|
1099
|
+
actorSources: TActorMap;
|
|
1100
|
+
guards: TGuardMap;
|
|
1101
|
+
delays: TDelayMap;
|
|
1102
|
+
system?: AnyActorSystem;
|
|
1103
|
+
params: TParams;
|
|
1104
|
+
}, enqueue: EnqueueObject<TEvent, TEmittedEvent>) => {
|
|
1105
|
+
context?: Partial<_TCtx>;
|
|
1106
|
+
children?: Record<string, AnyActor | undefined>;
|
|
1107
|
+
} | void;
|
|
1108
|
+
export type AnyAction = Action<MachineContext, EventObject, EventObject, Implementations['actions'], Implementations['actorSources'], Implementations['guards'], Implementations['delays']> | {
|
|
1109
|
+
action: (...args: any[]) => any;
|
|
1110
|
+
args: any[];
|
|
1111
|
+
} | AnyEventObject;
|
|
1047
1112
|
export {};
|