xstate 5.0.0-beta.8 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -8
- package/actions/dist/xstate-actions.cjs.d.mts +2 -0
- package/actions/dist/xstate-actions.cjs.d.mts.map +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts +1 -0
- package/actions/dist/xstate-actions.cjs.d.ts.map +1 -0
- package/actions/dist/xstate-actions.cjs.js +19 -5
- package/actions/dist/xstate-actions.cjs.mjs +13 -0
- package/actions/dist/xstate-actions.development.cjs.js +21 -0
- package/actions/dist/xstate-actions.development.cjs.mjs +13 -0
- package/actions/dist/xstate-actions.development.esm.js +3 -0
- package/actions/dist/xstate-actions.esm.js +3 -2
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.d.mts +2 -0
- package/actors/dist/xstate-actors.cjs.d.mts.map +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts +1 -0
- package/actors/dist/xstate-actors.cjs.d.ts.map +1 -0
- package/actors/dist/xstate-actors.cjs.js +621 -4
- package/actors/dist/xstate-actors.cjs.mjs +8 -0
- package/actors/dist/xstate-actors.development.cjs.js +624 -0
- package/actors/dist/xstate-actors.development.cjs.mjs +8 -0
- package/actors/dist/xstate-actors.development.esm.js +615 -0
- package/actors/dist/xstate-actors.esm.js +615 -2
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dev/dist/xstate-dev.cjs.d.mts +2 -0
- package/dev/dist/xstate-dev.cjs.d.mts.map +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts +1 -0
- package/dev/dist/xstate-dev.cjs.d.ts.map +1 -0
- package/dev/dist/xstate-dev.cjs.js +45 -4
- package/dev/dist/xstate-dev.cjs.mjs +5 -0
- package/{dist/index-ebaab3c9.cjs.dev.js → dev/dist/xstate-dev.development.cjs.js} +6 -7
- package/dev/dist/xstate-dev.development.cjs.mjs +5 -0
- package/{dist/index-50bd0aff.esm.js → dev/dist/xstate-dev.development.esm.js} +6 -8
- package/dev/dist/xstate-dev.esm.js +42 -1
- package/dev/dist/xstate-dev.umd.min.js +1 -1
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/declarations/src/SimulatedClock.d.ts +1 -1
- package/dist/declarations/src/State.d.ts +47 -73
- package/dist/declarations/src/StateMachine.d.ts +29 -57
- package/dist/declarations/src/StateNode.d.ts +36 -33
- package/dist/declarations/src/actions/assign.d.ts +11 -2
- package/dist/declarations/src/actions/cancel.d.ts +7 -3
- package/dist/declarations/src/actions/enqueueActions.d.ts +32 -0
- package/dist/declarations/src/actions/log.d.ts +7 -3
- package/dist/declarations/src/actions/raise.d.ts +7 -2
- package/dist/declarations/src/actions/send.d.ts +14 -36
- package/dist/declarations/src/actions/spawnChild.d.ts +29 -0
- package/dist/declarations/src/actions/stopChild.d.ts +18 -0
- package/dist/declarations/src/actions.d.ts +8 -48
- package/dist/declarations/src/actors/callback.d.ts +91 -8
- package/dist/declarations/src/actors/index.d.ts +6 -28
- package/dist/declarations/src/actors/observable.d.ts +101 -18
- package/dist/declarations/src/actors/promise.d.ts +80 -10
- package/dist/declarations/src/actors/transition.d.ts +64 -9
- package/dist/declarations/src/constants.d.ts +3 -0
- package/dist/declarations/src/createMachine.d.ts +20 -0
- package/dist/declarations/src/dev/index.d.ts +6 -6
- package/dist/declarations/src/guards.d.ts +41 -8
- package/dist/declarations/src/index.d.ts +18 -23
- package/dist/declarations/src/interpreter.d.ts +150 -41
- package/dist/declarations/src/setup.d.ts +51 -0
- package/dist/declarations/src/spawn.d.ts +23 -2
- package/dist/declarations/src/stateUtils.d.ts +30 -45
- package/dist/declarations/src/system.d.ts +26 -2
- package/dist/declarations/src/typegenTypes.d.ts +40 -22
- package/dist/declarations/src/types.d.ts +528 -669
- package/dist/declarations/src/utils.d.ts +15 -52
- package/dist/declarations/src/waitFor.d.ts +2 -2
- package/dist/log-22e678c5.esm.js +364 -0
- package/dist/log-5e226275.cjs.js +372 -0
- package/dist/log-641cd926.development.cjs.js +394 -0
- package/dist/log-f196f85f.development.esm.js +386 -0
- package/dist/raise-34e25c2c.cjs.js +2368 -0
- package/dist/raise-62704519.development.cjs.js +2422 -0
- package/dist/raise-89c581c4.development.esm.js +2371 -0
- package/dist/raise-8bc422d1.esm.js +2317 -0
- package/dist/xstate.cjs.d.mts +2 -0
- package/dist/xstate.cjs.d.mts.map +1 -0
- package/dist/xstate.cjs.d.ts +1 -0
- package/dist/xstate.cjs.d.ts.map +1 -0
- package/dist/xstate.cjs.js +728 -4
- package/dist/xstate.cjs.mjs +39 -0
- package/dist/xstate.development.cjs.js +737 -0
- package/dist/xstate.development.cjs.mjs +39 -0
- package/dist/xstate.development.esm.js +699 -0
- package/dist/xstate.esm.js +561 -770
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.d.mts +2 -0
- package/guards/dist/xstate-guards.cjs.d.mts.map +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts +1 -0
- package/guards/dist/xstate-guards.cjs.d.ts.map +1 -0
- package/guards/dist/xstate-guards.cjs.js +12 -5
- package/guards/dist/xstate-guards.cjs.mjs +7 -0
- package/guards/dist/xstate-guards.development.cjs.js +14 -0
- package/guards/dist/xstate-guards.development.cjs.mjs +7 -0
- package/guards/dist/xstate-guards.development.esm.js +2 -0
- package/guards/dist/xstate-guards.esm.js +2 -2
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +59 -1
- package/actions/dist/xstate-actions.cjs.dev.js +0 -32
- package/actions/dist/xstate-actions.cjs.prod.js +0 -32
- package/actions/dynamicAction.ts +0 -42
- package/actors/dist/xstate-actors.cjs.dev.js +0 -22
- package/actors/dist/xstate-actors.cjs.prod.js +0 -22
- package/dev/dist/xstate-dev.cjs.dev.js +0 -11
- package/dev/dist/xstate-dev.cjs.prod.js +0 -48
- package/dist/actions-900f9761.cjs.prod.js +0 -4349
- package/dist/actions-c8d7df32.esm.js +0 -4332
- package/dist/actions-d06ca158.cjs.dev.js +0 -4387
- package/dist/declarations/actions/dynamicAction.d.ts +0 -5
- package/dist/declarations/src/Machine.d.ts +0 -4
- package/dist/declarations/src/Mailbox.d.ts +0 -12
- package/dist/declarations/src/actionTypes.d.ts +0 -16
- package/dist/declarations/src/actions/choose.d.ts +0 -3
- package/dist/declarations/src/actions/invoke.d.ts +0 -3
- package/dist/declarations/src/actions/pure.d.ts +0 -6
- package/dist/declarations/src/actions/stop.d.ts +0 -7
- package/dist/declarations/src/environment.d.ts +0 -1
- package/dist/declarations/src/mapState.d.ts +0 -3
- package/dist/declarations/src/memo.d.ts +0 -2
- package/dist/xstate.cjs.dev.js +0 -956
- package/dist/xstate.cjs.prod.js +0 -953
- package/guards/dist/xstate-guards.cjs.dev.js +0 -15
- package/guards/dist/xstate-guards.cjs.prod.js +0 -15
|
@@ -1,30 +1,63 @@
|
|
|
1
|
-
import type { StateNode } from
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type { StateMachine } from
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
1
|
+
import type { StateNode } from "./StateNode.js";
|
|
2
|
+
import type { MachineSnapshot } from "./State.js";
|
|
3
|
+
import type { Clock, Actor } from "./interpreter.js";
|
|
4
|
+
import type { StateMachine } from "./StateMachine.js";
|
|
5
|
+
import { TypegenDisabled, ResolveTypegenMeta, TypegenConstraint, MarkAllImplementationsAsProvided, AreAllImplementationsAssumedToBeProvided } from "./typegenTypes.js";
|
|
6
|
+
import { PromiseActorLogic } from "./actors/promise.js";
|
|
7
|
+
import { Guard, GuardPredicate, UnknownGuard } from "./guards.js";
|
|
8
|
+
import { Spawner } from "./spawn.js";
|
|
9
|
+
import { AssignArgs } from "./actions/assign.js";
|
|
10
|
+
import { InspectionEvent } from './system.js';
|
|
11
|
+
export type Identity<T> = {
|
|
12
|
+
[K in keyof T]: T[K];
|
|
13
|
+
};
|
|
14
|
+
export type HomomorphicPick<T, K extends keyof any> = {
|
|
15
|
+
[P in keyof T as P & K]: T[P];
|
|
16
|
+
};
|
|
17
|
+
export type HomomorphicOmit<T, K extends keyof any> = {
|
|
18
|
+
[P in keyof T as Exclude<P, K>]: T[P];
|
|
19
|
+
};
|
|
20
|
+
export type Invert<T extends Record<PropertyKey, PropertyKey>> = {
|
|
21
|
+
[K in keyof T as T[K]]: K;
|
|
22
|
+
};
|
|
23
|
+
export type GetParameterizedParams<T extends ParameterizedObject | undefined> = T extends any ? ('params' extends keyof T ? T['params'] : undefined) : never;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
*
|
|
28
|
+
* `T | unknown` reduces to `unknown` and that can be problematic when it comes to contextual typing.
|
|
29
|
+
* It especially is a problem when the union has a function member, like here:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* declare function test(cbOrVal: ((arg: number) => unknown) | unknown): void;
|
|
33
|
+
* test((arg) => {}) // oops, implicit any
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* This type can be used to avoid this problem. This union represents the same value space as `unknown`.
|
|
37
|
+
*/
|
|
38
|
+
export type NonReducibleUnknown = {} | null | undefined;
|
|
7
39
|
export type AnyFunction = (...args: any[]) => any;
|
|
8
40
|
type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
|
|
9
41
|
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
42
|
+
export type IsNotNever<T> = [T] extends [never] ? false : true;
|
|
10
43
|
export type Compute<A extends any> = {
|
|
11
44
|
[K in keyof A]: A[K];
|
|
12
45
|
} & unknown;
|
|
13
46
|
export type Prop<T, K> = K extends keyof T ? T[K] : never;
|
|
14
47
|
export type Values<T> = T[keyof T];
|
|
48
|
+
export type Elements<T> = T[keyof T & `${number}`];
|
|
15
49
|
export type Merge<M, N> = Omit<M, keyof N> & N;
|
|
50
|
+
export type IndexByProp<T extends Record<P, string>, P extends keyof T> = {
|
|
51
|
+
[E in T as E[P]]: E;
|
|
52
|
+
};
|
|
16
53
|
export type IndexByType<T extends {
|
|
17
54
|
type: string;
|
|
18
|
-
}> =
|
|
19
|
-
[K in T['type']]: T extends any ? (K extends T['type'] ? T : never) : never;
|
|
20
|
-
};
|
|
55
|
+
}> = IndexByProp<T, 'type'>;
|
|
21
56
|
export type Equals<A1 extends any, A2 extends any> = (<A>() => A extends A2 ? true : false) extends <A>() => A extends A1 ? true : false ? true : false;
|
|
22
57
|
export type IsAny<T> = Equals<T, any>;
|
|
23
58
|
export type Cast<A, B> = A extends B ? A : B;
|
|
24
59
|
export type NoInfer<T> = [T][T extends any ? 0 : any];
|
|
25
60
|
export type LowInfer<T> = T & {};
|
|
26
|
-
export type EventType = string;
|
|
27
|
-
export type ActionType = string;
|
|
28
61
|
export type MetaObject = Record<string, any>;
|
|
29
62
|
export type Lazy<T> = () => T;
|
|
30
63
|
export type MaybeLazy<T> = T | Lazy<T>;
|
|
@@ -42,215 +75,143 @@ export interface AnyEventObject extends EventObject {
|
|
|
42
75
|
}
|
|
43
76
|
export interface ParameterizedObject {
|
|
44
77
|
type: string;
|
|
45
|
-
params?:
|
|
46
|
-
}
|
|
47
|
-
export interface BaseActionObject extends ParameterizedObject {
|
|
48
|
-
execute?: (actorCtx: AnyActorContext) => void;
|
|
49
|
-
}
|
|
50
|
-
export interface BuiltInActionObject extends ParameterizedObject {
|
|
51
|
-
type: `xstate.${string}`;
|
|
52
|
-
params: Record<string, any>;
|
|
78
|
+
params?: NonReducibleUnknown;
|
|
53
79
|
}
|
|
54
|
-
export interface UnifiedArg<TContext extends MachineContext, TEvent extends EventObject> {
|
|
80
|
+
export interface UnifiedArg<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> {
|
|
55
81
|
context: TContext;
|
|
56
|
-
event:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
params: TDynamicParams;
|
|
61
|
-
resolve: (_event: SCXML.Event<TExpressionEvent>, extra: {
|
|
62
|
-
state: State<TContext, TEvent>;
|
|
63
|
-
/**
|
|
64
|
-
* The original action object
|
|
65
|
-
*/
|
|
66
|
-
action: ParameterizedObject;
|
|
67
|
-
actorContext: AnyActorContext | undefined;
|
|
68
|
-
}) => [AnyState, TResolvedAction];
|
|
69
|
-
/** @deprecated an internal signature that doesn't exist at runtime. Its existence helps TS to choose a better code path in the inference algorithm */
|
|
70
|
-
(args: {
|
|
71
|
-
context: TContext;
|
|
72
|
-
event: TExpressionEvent;
|
|
73
|
-
} & ActionMeta<TEvent, ParameterizedObject>): void;
|
|
82
|
+
event: TExpressionEvent;
|
|
83
|
+
self: ActorRef<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>, // TODO: this should be replaced with `TChildren`
|
|
84
|
+
StateValue, string, unknown>, TEvent>;
|
|
85
|
+
system: ActorSystem<any>;
|
|
74
86
|
}
|
|
75
87
|
export type MachineContext = Record<string, any>;
|
|
76
|
-
export interface
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
export
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
} & ActionMeta<TEvent, TAction>) => void;
|
|
94
|
-
export interface ChooseCondition<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> {
|
|
95
|
-
guard?: GuardConfig<TContext, TEvent>;
|
|
96
|
-
actions: Actions<TContext, TExpressionEvent, TEvent>;
|
|
88
|
+
export interface ActionArgs<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> extends UnifiedArg<TContext, TExpressionEvent, TEvent> {
|
|
89
|
+
}
|
|
90
|
+
export type InputFrom<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 _TResolvedTypesMeta> ? TInput : T extends ActorLogic<infer _TSnapshot, infer _TEvent, infer TInput, infer _TSystem> ? TInput : never;
|
|
91
|
+
export type OutputFrom<T extends AnyActorLogic> = T extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem> ? (TSnapshot & {
|
|
92
|
+
status: 'done';
|
|
93
|
+
})['output'] : never;
|
|
94
|
+
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> = {
|
|
95
|
+
(args: ActionArgs<TContext, TExpressionEvent, TEvent>, params: TParams): void;
|
|
96
|
+
_out_TEvent?: TEvent;
|
|
97
|
+
_out_TActor?: TActor;
|
|
98
|
+
_out_TAction?: TAction;
|
|
99
|
+
_out_TGuard?: TGuard;
|
|
100
|
+
_out_TDelay?: TDelay;
|
|
101
|
+
};
|
|
102
|
+
export interface ChooseBranch<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string> {
|
|
103
|
+
guard?: Guard<TContext, TExpressionEvent, undefined, TGuard>;
|
|
104
|
+
actions: Actions<TContext, TExpressionEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay>;
|
|
97
105
|
}
|
|
98
|
-
export type
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
export type
|
|
106
|
+
export type NoRequiredParams<T extends ParameterizedObject> = T extends any ? undefined extends T['params'] ? T['type'] : never : never;
|
|
107
|
+
export type ConditionalRequired<T, Condition extends boolean> = Condition extends true ? Required<T> : T;
|
|
108
|
+
export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent extends EventObject, T extends ParameterizedObject> = T extends any ? ConditionalRequired<{
|
|
109
|
+
type: T['type'];
|
|
110
|
+
params?: T['params'] | (({ context, event }: {
|
|
111
|
+
context: TContext;
|
|
112
|
+
event: TExpressionEvent;
|
|
113
|
+
}) => T['params']);
|
|
114
|
+
}, undefined extends T['params'] ? false : true> : never;
|
|
115
|
+
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> = NoRequiredParams<TAction> | WithDynamicParams<TContext, TExpressionEvent, TAction> | ActionFunction<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay>;
|
|
116
|
+
export type UnknownAction = Action<MachineContext, EventObject, EventObject, ParameterizedObject['params'] | undefined, ProvidedActor, ParameterizedObject, ParameterizedObject, string>;
|
|
117
|
+
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> = SingleOrArray<Action<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay>>;
|
|
118
|
+
export type StateKey = string | AnyMachineSnapshot;
|
|
108
119
|
export interface StateValueMap {
|
|
109
120
|
[key: string]: StateValue;
|
|
110
121
|
}
|
|
111
122
|
/**
|
|
112
123
|
* The string or object representing the state value relative to the parent state node.
|
|
113
124
|
*
|
|
125
|
+
* @remarks
|
|
126
|
+
*
|
|
114
127
|
* - For a child atomic state node, this is a string, e.g., `"pending"`.
|
|
128
|
+
*
|
|
115
129
|
* - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
|
|
116
130
|
*/
|
|
117
131
|
export type StateValue = string | StateValueMap;
|
|
118
|
-
export type GuardPredicate<TContext extends MachineContext, TEvent extends EventObject> = (args: {
|
|
119
|
-
context: TContext;
|
|
120
|
-
event: TEvent;
|
|
121
|
-
} & GuardMeta<TContext, TEvent>) => boolean;
|
|
122
|
-
export interface DefaultGuardObject<TContext extends MachineContext, TEvent extends EventObject> extends ParameterizedObject {
|
|
123
|
-
/**
|
|
124
|
-
* Nested guards
|
|
125
|
-
*/
|
|
126
|
-
children?: Array<GuardObject<TContext, TEvent>>;
|
|
127
|
-
predicate?: GuardPredicate<TContext, TEvent>;
|
|
128
|
-
}
|
|
129
|
-
export type GuardEvaluator<TContext extends MachineContext, TEvent extends EventObject> = (guard: GuardDefinition<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>) => boolean;
|
|
130
|
-
export interface GuardMeta<TContext extends MachineContext, TEvent extends EventObject> {
|
|
131
|
-
state: State<TContext, TEvent, any>;
|
|
132
|
-
_event: SCXML.Event<TEvent>;
|
|
133
|
-
guard: GuardDefinition<TContext, TEvent>;
|
|
134
|
-
evaluate: GuardEvaluator<TContext, TEvent>;
|
|
135
|
-
}
|
|
136
|
-
export type GuardConfig<TContext extends MachineContext, TEvent extends EventObject> = string | GuardPredicate<TContext, TEvent> | GuardObject<TContext, TEvent>;
|
|
137
|
-
export type GuardObject<TContext extends MachineContext, TEvent extends EventObject> = BooleanGuardObject<TContext, TEvent> | DefaultGuardObject<TContext, TEvent>;
|
|
138
|
-
export interface GuardDefinition<TContext extends MachineContext, TEvent extends EventObject> {
|
|
139
|
-
type: string;
|
|
140
|
-
children?: Array<GuardDefinition<TContext, TEvent>>;
|
|
141
|
-
predicate?: GuardPredicate<TContext, TEvent>;
|
|
142
|
-
params: {
|
|
143
|
-
[key: string]: any;
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
export interface BooleanGuardObject<TContext extends MachineContext, TEvent extends EventObject> extends ParameterizedObject {
|
|
147
|
-
type: 'xstate.boolean';
|
|
148
|
-
children: Array<GuardConfig<TContext, TEvent>>;
|
|
149
|
-
params: {
|
|
150
|
-
op: 'and' | 'or' | 'not';
|
|
151
|
-
};
|
|
152
|
-
predicate: undefined;
|
|
153
|
-
}
|
|
154
|
-
export interface BooleanGuardDefinition<TContext extends MachineContext, TEvent extends EventObject> extends GuardDefinition<TContext, TEvent> {
|
|
155
|
-
type: 'xstate.boolean';
|
|
156
|
-
params: {
|
|
157
|
-
op: 'and' | 'or' | 'not';
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
132
|
export type TransitionTarget = SingleOrArray<string>;
|
|
161
|
-
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject
|
|
162
|
-
guard?:
|
|
163
|
-
actions?:
|
|
133
|
+
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> {
|
|
134
|
+
guard?: Guard<TContext, TExpressionEvent, undefined, TGuard>;
|
|
135
|
+
actions?: Actions<TContext, TExpressionEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay>;
|
|
164
136
|
reenter?: boolean;
|
|
165
137
|
target?: TransitionTarget | undefined;
|
|
166
138
|
meta?: Record<string, any>;
|
|
167
139
|
description?: string;
|
|
168
140
|
}
|
|
169
|
-
export interface
|
|
170
|
-
target:
|
|
141
|
+
export interface InitialTransitionConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> extends TransitionConfig<TContext, TEvent, TEvent, TActor, TAction, TGuard, TDelay> {
|
|
142
|
+
target: string;
|
|
171
143
|
}
|
|
172
|
-
export type
|
|
173
|
-
export interface
|
|
174
|
-
guard?: never;
|
|
175
|
-
target: TransitionTarget;
|
|
176
|
-
}
|
|
177
|
-
export type Transition<TContext extends MachineContext, TEvent extends EventObject = EventObject> = string | TransitionConfig<TContext, TEvent> | ConditionalTransitionConfig<TContext, TEvent>;
|
|
178
|
-
type ExtractWithSimpleSupport<T extends {
|
|
179
|
-
type: string;
|
|
180
|
-
}> = T extends any ? {
|
|
181
|
-
type: T['type'];
|
|
182
|
-
} extends T ? T : never : never;
|
|
183
|
-
export type Receiver<TEvent extends EventObject> = (listener: {
|
|
184
|
-
bivarianceHack(event: TEvent): void;
|
|
185
|
-
}['bivarianceHack']) => void;
|
|
186
|
-
export type InvokeCallback<TEvent extends EventObject = AnyEventObject, TSentEvent extends EventObject = AnyEventObject> = (sendBack: (event: TSentEvent) => void, onReceive: Receiver<TEvent>, { input }: {
|
|
187
|
-
input: any;
|
|
188
|
-
}) => (() => void) | Promise<any> | void;
|
|
189
|
-
export type ActorBehaviorCreator<TContext extends MachineContext, TEvent extends EventObject, TActorBehavior extends AnyActorBehavior = AnyActorBehavior> = (context: TContext, event: TEvent, meta: {
|
|
190
|
-
id: string;
|
|
191
|
-
data?: any;
|
|
192
|
-
src: string;
|
|
193
|
-
_event: SCXML.Event<TEvent>;
|
|
194
|
-
meta: MetaObject | undefined;
|
|
195
|
-
input: any;
|
|
196
|
-
}) => TActorBehavior;
|
|
197
|
-
export interface InvokeMeta {
|
|
198
|
-
src: string;
|
|
199
|
-
meta: MetaObject | undefined;
|
|
200
|
-
}
|
|
201
|
-
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject> {
|
|
144
|
+
export type AnyTransitionConfig = TransitionConfig<any, any, any, any, any, any, any>;
|
|
145
|
+
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> {
|
|
202
146
|
id: string;
|
|
203
147
|
systemId: string | undefined;
|
|
204
148
|
/**
|
|
205
|
-
* The source of the actor
|
|
149
|
+
* The source of the actor logic to be invoked
|
|
206
150
|
*/
|
|
207
|
-
src: string;
|
|
208
|
-
input?: Mapper<TContext, TEvent,
|
|
151
|
+
src: AnyActorLogic | string;
|
|
152
|
+
input?: Mapper<TContext, TEvent, NonReducibleUnknown, TEvent> | NonReducibleUnknown;
|
|
209
153
|
/**
|
|
210
154
|
* The transition to take upon the invoked child machine reaching its final top-level state.
|
|
211
155
|
*/
|
|
212
|
-
onDone?: string | SingleOrArray<TransitionConfig<TContext,
|
|
156
|
+
onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneActorEvent<unknown>, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
213
157
|
/**
|
|
214
158
|
* The transition to take upon the invoked child machine sending an error event.
|
|
215
159
|
*/
|
|
216
|
-
onError?: string | SingleOrArray<TransitionConfig<TContext,
|
|
217
|
-
onSnapshot?: string | SingleOrArray<TransitionConfig<TContext, SnapshotEvent
|
|
218
|
-
toJSON: () => Omit<InvokeDefinition<TContext, TEvent>, 'onDone' | 'onError' | 'toJSON'>;
|
|
219
|
-
meta: MetaObject | undefined;
|
|
160
|
+
onError?: string | SingleOrArray<TransitionConfig<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
161
|
+
onSnapshot?: string | SingleOrArray<TransitionConfig<TContext, SnapshotEvent, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
162
|
+
toJSON: () => Omit<InvokeDefinition<TContext, TEvent, TActor, TAction, TGuard, TDelay>, 'onDone' | 'onError' | 'toJSON'>;
|
|
220
163
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
*/
|
|
226
|
-
delay: number;
|
|
227
|
-
}
|
|
228
|
-
export type DelayedTransitions<TContext extends MachineContext, TEvent extends EventObject> = Record<string | number, string | SingleOrArray<TransitionConfig<TContext, TEvent>>> | Array<TransitionConfig<TContext, TEvent> & {
|
|
229
|
-
delay: number | string | Expr<TContext, TEvent, number>;
|
|
230
|
-
}>;
|
|
164
|
+
type Delay<TDelay extends string> = TDelay | number;
|
|
165
|
+
export type DelayedTransitions<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = {
|
|
166
|
+
[K in Delay<TDelay>]?: string | SingleOrArray<TransitionConfig<TContext, TEvent, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
167
|
+
};
|
|
231
168
|
export type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | string;
|
|
232
|
-
export type SingleOrArray<T> = T[] | T;
|
|
169
|
+
export type SingleOrArray<T> = readonly T[] | T;
|
|
233
170
|
export type StateNodesConfig<TContext extends MachineContext, TEvent extends EventObject> = {
|
|
234
171
|
[K in string]: StateNode<TContext, TEvent>;
|
|
235
172
|
};
|
|
236
|
-
export type StatesConfig<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject
|
|
237
|
-
[K in string]: StateNodeConfig<TContext, TEvent, TAction>;
|
|
173
|
+
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> = {
|
|
174
|
+
[K in string]: StateNodeConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TOutput>;
|
|
238
175
|
};
|
|
239
176
|
export type StatesDefinition<TContext extends MachineContext, TEvent extends EventObject> = {
|
|
240
177
|
[K in string]: StateNodeDefinition<TContext, TEvent>;
|
|
241
178
|
};
|
|
242
179
|
export type TransitionConfigTarget = string | undefined;
|
|
243
|
-
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject
|
|
244
|
-
export type
|
|
245
|
-
[K in TEvent
|
|
180
|
+
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = SingleOrArray<TransitionConfigTarget | TransitionConfig<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
181
|
+
export type TransitionsConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = {
|
|
182
|
+
[K in EventDescriptor<TEvent>]?: TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TActor, TAction, TGuard, TDelay>;
|
|
246
183
|
};
|
|
247
|
-
type
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
184
|
+
type PartialEventDescriptor<TEventType extends string> = TEventType extends `${infer TLeading}.${infer TTail}` ? `${TLeading}.*` | `${TLeading}.${PartialEventDescriptor<TTail>}` : never;
|
|
185
|
+
export type EventDescriptor<TEvent extends EventObject> = TEvent['type'] | PartialEventDescriptor<TEvent['type']> | '*';
|
|
186
|
+
type NormalizeDescriptor<TDescriptor extends string> = TDescriptor extends '*' ? string : TDescriptor extends `${infer TLeading}.*` ? `${TLeading}.${string}` : TDescriptor;
|
|
187
|
+
export type IsLiteralString<T extends string> = string extends T ? false : true;
|
|
188
|
+
type DistributeActors<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TSpecificActor extends ProvidedActor> = TSpecificActor extends {
|
|
189
|
+
src: infer TSrc;
|
|
190
|
+
} ? Compute<{
|
|
191
|
+
systemId?: string;
|
|
192
|
+
/**
|
|
193
|
+
* The source of the machine to be invoked, or the machine itself.
|
|
194
|
+
*/
|
|
195
|
+
src: TSrc;
|
|
196
|
+
/**
|
|
197
|
+
* The unique identifier for the invoked machine. If not specified, this
|
|
198
|
+
* will be the machine's own `id`, or the URL (from `src`).
|
|
199
|
+
*/
|
|
200
|
+
id?: TSpecificActor['id'];
|
|
201
|
+
input?: Mapper<TContext, TEvent, InputFrom<TSpecificActor['logic']>, TEvent> | InputFrom<TSpecificActor['logic']>;
|
|
202
|
+
/**
|
|
203
|
+
* The transition to take upon the invoked child machine reaching its final top-level state.
|
|
204
|
+
*/
|
|
205
|
+
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<OutputFrom<TSpecificActor['logic']>>, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
206
|
+
/**
|
|
207
|
+
* The transition to take upon the invoked child machine sending an error event.
|
|
208
|
+
*/
|
|
209
|
+
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
210
|
+
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent<SnapshotFrom<TSpecificActor['logic']>>, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
211
|
+
} & {
|
|
212
|
+
[K in RequiredActorOptions<TSpecificActor>]: unknown;
|
|
213
|
+
}> : never;
|
|
214
|
+
export type InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = IsLiteralString<TActor['src']> extends true ? DistributeActors<TContext, TEvent, TActor, TAction, TGuard, TDelay, TActor> : {
|
|
254
215
|
/**
|
|
255
216
|
* The unique identifier for the invoked machine. If not specified, this
|
|
256
217
|
* will be the machine's own `id`, or the URL (from `src`).
|
|
@@ -260,27 +221,25 @@ export interface InvokeConfig<TContext extends MachineContext, TEvent extends Ev
|
|
|
260
221
|
/**
|
|
261
222
|
* The source of the machine to be invoked, or the machine itself.
|
|
262
223
|
*/
|
|
263
|
-
src:
|
|
264
|
-
input?: Mapper<TContext, TEvent,
|
|
224
|
+
src: AnyActorLogic | string;
|
|
225
|
+
input?: Mapper<TContext, TEvent, NonReducibleUnknown, TEvent> | NonReducibleUnknown;
|
|
265
226
|
/**
|
|
266
227
|
* The transition to take upon the invoked child machine reaching its final top-level state.
|
|
267
228
|
*/
|
|
268
|
-
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext,
|
|
229
|
+
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<any>, // TODO: consider replacing with `unknown`
|
|
230
|
+
TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
269
231
|
/**
|
|
270
232
|
* The transition to take upon the invoked child machine sending an error event.
|
|
271
233
|
*/
|
|
272
|
-
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext,
|
|
273
|
-
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
meta?: MetaObject;
|
|
278
|
-
}
|
|
279
|
-
export interface StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject = ParameterizedObject> {
|
|
234
|
+
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
235
|
+
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
236
|
+
};
|
|
237
|
+
export type AnyInvokeConfig = InvokeConfig<any, any, any, any, any, any>;
|
|
238
|
+
export interface StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TOutput> {
|
|
280
239
|
/**
|
|
281
240
|
* The initial state transition.
|
|
282
241
|
*/
|
|
283
|
-
initial?: InitialTransitionConfig<TContext, TEvent> |
|
|
242
|
+
initial?: InitialTransitionConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay> | string | undefined;
|
|
284
243
|
/**
|
|
285
244
|
* The type of this state node:
|
|
286
245
|
*
|
|
@@ -300,70 +259,63 @@ export interface StateNodeConfig<TContext extends MachineContext, TEvent extends
|
|
|
300
259
|
/**
|
|
301
260
|
* The mapping of state node keys to their state node configurations (recursive).
|
|
302
261
|
*/
|
|
303
|
-
states?: StatesConfig<TContext, TEvent, TAction> | undefined;
|
|
262
|
+
states?: StatesConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, NonReducibleUnknown> | undefined;
|
|
304
263
|
/**
|
|
305
264
|
* The services to invoke upon entering this state node. These services will be stopped upon exiting this state node.
|
|
306
265
|
*/
|
|
307
|
-
invoke?: SingleOrArray<
|
|
266
|
+
invoke?: SingleOrArray<InvokeConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
308
267
|
/**
|
|
309
268
|
* The mapping of event types to their potential transition(s).
|
|
310
269
|
*/
|
|
311
|
-
on?: TransitionsConfig<TContext, TEvent>;
|
|
270
|
+
on?: TransitionsConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay>;
|
|
312
271
|
/**
|
|
313
272
|
* The action(s) to be executed upon entering the state node.
|
|
314
273
|
*/
|
|
315
|
-
entry?:
|
|
274
|
+
entry?: Actions<TContext, TEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay>;
|
|
316
275
|
/**
|
|
317
276
|
* The action(s) to be executed upon exiting the state node.
|
|
318
277
|
*/
|
|
319
|
-
exit?:
|
|
278
|
+
exit?: Actions<TContext, TEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay>;
|
|
320
279
|
/**
|
|
321
280
|
* The potential transition(s) to be taken upon reaching a final child state node.
|
|
322
281
|
*
|
|
323
282
|
* This is equivalent to defining a `[done(id)]` transition on this state node's `on` property.
|
|
324
283
|
*/
|
|
325
|
-
onDone?: string | SingleOrArray<TransitionConfig<TContext,
|
|
284
|
+
onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneStateEvent, TEvent, TActor, TAction, TGuard, TDelay>> | undefined;
|
|
326
285
|
/**
|
|
327
286
|
* The mapping (or array) of delays (in milliseconds) to their potential transition(s).
|
|
328
287
|
* The delayed transitions are taken after the specified delay in an interpreter.
|
|
329
288
|
*/
|
|
330
|
-
after?: DelayedTransitions<TContext, TEvent>;
|
|
289
|
+
after?: DelayedTransitions<TContext, TEvent, TActor, TAction, TGuard, TDelay>;
|
|
331
290
|
/**
|
|
332
291
|
* An eventless transition that is always taken when this state node is active.
|
|
333
292
|
*/
|
|
334
|
-
always?: TransitionConfigOrTarget<TContext, TEvent>;
|
|
335
|
-
/**
|
|
336
|
-
* @private
|
|
337
|
-
*/
|
|
293
|
+
always?: TransitionConfigOrTarget<TContext, TEvent, TEvent, TActor, TAction, TGuard, TDelay>;
|
|
338
294
|
parent?: StateNode<TContext, TEvent>;
|
|
339
295
|
/**
|
|
340
296
|
* The meta data associated with this state node, which will be returned in State instances.
|
|
341
297
|
*/
|
|
342
298
|
meta?: any;
|
|
343
299
|
/**
|
|
344
|
-
* The output data sent with the "done.state._id_" event if this is a final state node.
|
|
300
|
+
* The output data sent with the "xstate.done.state._id_" event if this is a final state node.
|
|
345
301
|
*
|
|
346
302
|
* The output data will be evaluated with the current `context` and placed on the `.data` property
|
|
347
303
|
* of the event.
|
|
348
304
|
*/
|
|
349
|
-
output?: Mapper<TContext, TEvent,
|
|
305
|
+
output?: Mapper<TContext, TEvent, unknown, TEvent> | NonReducibleUnknown;
|
|
350
306
|
/**
|
|
351
307
|
* The unique ID of the state node, which can be referenced as a transition target via the
|
|
352
308
|
* `#id` syntax.
|
|
353
309
|
*/
|
|
354
310
|
id?: string | undefined;
|
|
355
311
|
/**
|
|
356
|
-
* The
|
|
357
|
-
*/
|
|
358
|
-
delimiter?: string;
|
|
359
|
-
/**
|
|
360
|
-
* The order this state node appears. Corresponds to the implicit SCXML document order.
|
|
312
|
+
* The order this state node appears. Corresponds to the implicit document order.
|
|
361
313
|
*/
|
|
362
314
|
order?: number;
|
|
363
315
|
/**
|
|
364
316
|
* The tags for this state node, which are accumulated into the `state.tags` property.
|
|
365
317
|
*/
|
|
366
|
-
tags?: SingleOrArray<
|
|
318
|
+
tags?: SingleOrArray<TTag>;
|
|
367
319
|
/**
|
|
368
320
|
* A text description of the state node
|
|
369
321
|
*/
|
|
@@ -373,6 +325,7 @@ export interface StateNodeConfig<TContext extends MachineContext, TEvent extends
|
|
|
373
325
|
*/
|
|
374
326
|
target?: string;
|
|
375
327
|
}
|
|
328
|
+
export type AnyStateNodeConfig = StateNodeConfig<any, any, any, any, any, any, any, any>;
|
|
376
329
|
export interface StateNodeDefinition<TContext extends MachineContext, TEvent extends EventObject> {
|
|
377
330
|
id: string;
|
|
378
331
|
version?: string | undefined;
|
|
@@ -383,24 +336,36 @@ export interface StateNodeDefinition<TContext extends MachineContext, TEvent ext
|
|
|
383
336
|
states: StatesDefinition<TContext, TEvent>;
|
|
384
337
|
on: TransitionDefinitionMap<TContext, TEvent>;
|
|
385
338
|
transitions: Array<TransitionDefinition<TContext, TEvent>>;
|
|
386
|
-
entry:
|
|
387
|
-
exit:
|
|
339
|
+
entry: UnknownAction[];
|
|
340
|
+
exit: UnknownAction[];
|
|
388
341
|
meta: any;
|
|
389
342
|
order: number;
|
|
390
|
-
output?:
|
|
391
|
-
invoke: Array<InvokeDefinition<TContext, TEvent>>;
|
|
343
|
+
output?: StateNodeConfig<TContext, TEvent, ProvidedActor, ParameterizedObject, ParameterizedObject, string, string, unknown>['output'];
|
|
344
|
+
invoke: Array<InvokeDefinition<TContext, TEvent, TODO, TODO, TODO, TODO>>;
|
|
392
345
|
description?: string;
|
|
393
346
|
tags: string[];
|
|
394
347
|
}
|
|
395
348
|
export interface StateMachineDefinition<TContext extends MachineContext, TEvent extends EventObject> extends StateNodeDefinition<TContext, TEvent> {
|
|
396
|
-
context: TContext;
|
|
397
349
|
}
|
|
398
350
|
export type AnyStateNode = StateNode<any, any>;
|
|
399
351
|
export type AnyStateNodeDefinition = StateNodeDefinition<any, any>;
|
|
400
|
-
export type
|
|
401
|
-
|
|
352
|
+
export type AnyMachineSnapshot = MachineSnapshot<any, any, any, any, any, any, any>;
|
|
353
|
+
/** @deprecated use `AnyMachineSnapshot` instead */
|
|
354
|
+
export type AnyState = AnyMachineSnapshot;
|
|
355
|
+
export type AnyStateMachine = StateMachine<any, // context
|
|
356
|
+
any, // event
|
|
357
|
+
any, // children
|
|
358
|
+
any, // actor
|
|
359
|
+
any, // action
|
|
360
|
+
any, // guard
|
|
361
|
+
any, // delay
|
|
362
|
+
any, // state value
|
|
363
|
+
any, // tag
|
|
364
|
+
any, // input
|
|
365
|
+
any, // output
|
|
366
|
+
any>;
|
|
402
367
|
export type AnyStateConfig = StateConfig<any, AnyEventObject>;
|
|
403
|
-
export interface AtomicStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> extends StateNodeConfig<TContext, TEvent> {
|
|
368
|
+
export interface AtomicStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> extends StateNodeConfig<TContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO> {
|
|
404
369
|
initial?: undefined;
|
|
405
370
|
parallel?: false | undefined;
|
|
406
371
|
states?: undefined;
|
|
@@ -410,47 +375,40 @@ export interface HistoryStateNodeConfig<TContext extends MachineContext, TEvent
|
|
|
410
375
|
history: 'shallow' | 'deep' | true;
|
|
411
376
|
target: string | undefined;
|
|
412
377
|
}
|
|
413
|
-
export
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
* The data to be sent with the "done.state.<id>" event. The data can be
|
|
417
|
-
* static or dynamic (based on assigners).
|
|
418
|
-
*/
|
|
419
|
-
output?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
|
|
420
|
-
}
|
|
421
|
-
export type SimpleOrStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TEvent>;
|
|
422
|
-
export type ActionFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject = ParameterizedObject> = {
|
|
423
|
-
[K in TAction['type']]?: BaseDynamicActionObject<TContext, TEvent, TEvent, TAction, any> | ActionFunction<TContext, TEvent, TAction extends {
|
|
378
|
+
export type SimpleOrStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO>;
|
|
379
|
+
export type ActionFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string> = {
|
|
380
|
+
[K in TAction['type']]?: ActionFunction<TContext, TEvent, TEvent, GetParameterizedParams<TAction extends {
|
|
424
381
|
type: K;
|
|
425
|
-
} ? TAction : never>;
|
|
382
|
+
} ? TAction : never>, TActor, TAction, TGuard, TDelay>;
|
|
426
383
|
};
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
384
|
+
type GuardMap<TContext extends MachineContext, TEvent extends EventObject, TGuard extends ParameterizedObject> = {
|
|
385
|
+
[K in TGuard['type']]?: GuardPredicate<TContext, TEvent, GetParameterizedParams<TGuard extends {
|
|
386
|
+
type: K;
|
|
387
|
+
} ? TGuard : never>, TGuard>;
|
|
388
|
+
};
|
|
389
|
+
export type DelayFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject> = Record<string, DelayConfig<TContext, TEvent, TAction['params'], TEvent>>;
|
|
390
|
+
export type DelayConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = number | DelayExpr<TContext, TExpressionEvent, TParams, TEvent>;
|
|
391
|
+
export interface MachineImplementationsSimplified<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject> {
|
|
392
|
+
guards: GuardMap<TContext, TEvent, TGuard>;
|
|
393
|
+
actions: ActionFunctionMap<TContext, TEvent, TActor, TAction>;
|
|
394
|
+
actors: Record<string, AnyActorLogic | {
|
|
395
|
+
src: AnyActorLogic;
|
|
396
|
+
input: Mapper<TContext, TEvent, unknown, TEvent> | NonReducibleUnknown;
|
|
435
397
|
}>;
|
|
436
|
-
delays: DelayFunctionMap<TContext, TEvent>;
|
|
398
|
+
delays: DelayFunctionMap<TContext, TEvent, TAction>;
|
|
437
399
|
}
|
|
438
|
-
type
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>>;
|
|
400
|
+
type MaybeNarrowedEvent<TIndexedEvents, TCausingLookup, K> = Cast<Prop<TIndexedEvents, K extends keyof TCausingLookup ? TCausingLookup[K] : TIndexedEvents[keyof TIndexedEvents]>, EventObject>;
|
|
401
|
+
type MachineImplementationsActions<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingActions'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActors'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>, TIndexedGuards = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedGuards'>, TIndexedDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedDelays'>> = {
|
|
402
|
+
[K in keyof TIndexedActions]?: ActionFunction<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingActions, K>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>, GetParameterizedParams<Cast<TIndexedActions[K], ParameterizedObject>>, Cast<Prop<TIndexedActors, keyof TIndexedActors>, ProvidedActor>, Cast<Prop<TIndexedActions, keyof TIndexedActions>, ParameterizedObject>, Cast<Prop<TIndexedGuards, keyof TIndexedGuards>, ParameterizedObject>, Cast<Prop<TIndexedDelays, keyof TIndexedDelays>, ParameterizedObject>['type']>;
|
|
442
403
|
};
|
|
443
|
-
type
|
|
444
|
-
[K in keyof
|
|
404
|
+
type MachineImplementationsActors<_TContext extends MachineContext, TResolvedTypesMeta, TIndexedActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActors'>, _TInvokeSrcNameMap = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'invokeSrcNameMap'>> = {
|
|
405
|
+
[K in keyof TIndexedActors]?: Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>;
|
|
445
406
|
};
|
|
446
|
-
type
|
|
447
|
-
[K in keyof
|
|
407
|
+
type MachineImplementationsDelays<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingDelays'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>, TIndexedDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedDelays'>> = {
|
|
408
|
+
[K in keyof TIndexedDelays]?: DelayConfig<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingDelays, K>, Cast<Prop<Prop<TIndexedActions, keyof TIndexedActions>, 'params'>, ParameterizedObject['params'] | undefined> | undefined, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>>;
|
|
448
409
|
};
|
|
449
|
-
type
|
|
450
|
-
[K in keyof
|
|
451
|
-
src: AnyActorBehavior;
|
|
452
|
-
input: Mapper<TContext, Cast<Prop<TIndexedEvents, TEventsCausingActors[K]>, EventObject>, any> | any;
|
|
453
|
-
};
|
|
410
|
+
type MachineImplementationsGuards<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingGuards = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingGuards'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedGuards = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedGuards'>> = {
|
|
411
|
+
[K in keyof TIndexedGuards]?: Guard<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingGuards, K>, GetParameterizedParams<Cast<TIndexedGuards[K], ParameterizedObject | undefined>>, Cast<Prop<TIndexedGuards, keyof TIndexedGuards>, ParameterizedObject>>;
|
|
454
412
|
};
|
|
455
413
|
type MakeKeysRequired<T extends string> = {
|
|
456
414
|
[K in T]: unknown;
|
|
@@ -458,55 +416,58 @@ type MakeKeysRequired<T extends string> = {
|
|
|
458
416
|
type MaybeMakeMissingImplementationsRequired<TImplementationType, TMissingImplementationsForType, TRequireMissingImplementations> = TRequireMissingImplementations extends true ? IsNever<TMissingImplementationsForType> extends true ? {} : {
|
|
459
417
|
[K in Cast<TImplementationType, string>]: MakeKeysRequired<Cast<TMissingImplementationsForType, string>>;
|
|
460
418
|
} : {};
|
|
461
|
-
type GenerateActionsImplementationsPart<TContext extends MachineContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'actions', Prop<TMissingImplementations, 'actions'>, TRequireMissingImplementations> & {
|
|
419
|
+
type GenerateActionsImplementationsPart<TContext extends MachineContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = Compute<MaybeMakeMissingImplementationsRequired<'actions', Prop<TMissingImplementations, 'actions'>, TRequireMissingImplementations> & {
|
|
462
420
|
actions?: MachineImplementationsActions<TContext, TResolvedTypesMeta>;
|
|
463
|
-
}
|
|
464
|
-
type
|
|
421
|
+
}>;
|
|
422
|
+
type GenerateActorsImplementationsPart<TContext extends MachineContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = Compute<MaybeMakeMissingImplementationsRequired<'actors', Prop<TMissingImplementations, 'actors'>, TRequireMissingImplementations> & {
|
|
423
|
+
actors?: MachineImplementationsActors<TContext, TResolvedTypesMeta>;
|
|
424
|
+
}>;
|
|
425
|
+
type GenerateDelaysImplementationsPart<TContext extends MachineContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = Compute<MaybeMakeMissingImplementationsRequired<'delays', Prop<TMissingImplementations, 'delays'>, TRequireMissingImplementations> & {
|
|
465
426
|
delays?: MachineImplementationsDelays<TContext, TResolvedTypesMeta>;
|
|
466
|
-
}
|
|
467
|
-
type GenerateGuardsImplementationsPart<TContext extends MachineContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'guards', Prop<TMissingImplementations, 'guards'>, TRequireMissingImplementations> & {
|
|
427
|
+
}>;
|
|
428
|
+
type GenerateGuardsImplementationsPart<TContext extends MachineContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = Compute<MaybeMakeMissingImplementationsRequired<'guards', Prop<TMissingImplementations, 'guards'>, TRequireMissingImplementations> & {
|
|
468
429
|
guards?: MachineImplementationsGuards<TContext, TResolvedTypesMeta>;
|
|
469
|
-
}
|
|
470
|
-
type
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
export type
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
export type ContextFactory<TContext extends MachineContext> = ({ spawn, input }: {
|
|
477
|
-
spawn: Spawner;
|
|
478
|
-
input: any;
|
|
430
|
+
}>;
|
|
431
|
+
export type InternalMachineImplementations<TContext extends MachineContext, TResolvedTypesMeta, TRequireMissingImplementations extends boolean = false, TMissingImplementations = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'missingImplementations'>> = Compute<GenerateActionsImplementationsPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateActorsImplementationsPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateDelaysImplementationsPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateGuardsImplementationsPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations>>;
|
|
432
|
+
export type MachineImplementations<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, TTypesMeta extends TypegenConstraint = TypegenDisabled> = InternalMachineImplementations<TContext, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>;
|
|
433
|
+
type InitialContext<TContext extends MachineContext, TActor extends ProvidedActor, TInput> = TContext | ContextFactory<TContext, TActor, TInput>;
|
|
434
|
+
export type ContextFactory<TContext extends MachineContext, TActor extends ProvidedActor, TInput> = ({ spawn, input }: {
|
|
435
|
+
spawn: Spawner<TActor>;
|
|
436
|
+
input: TInput;
|
|
479
437
|
}) => TContext;
|
|
480
|
-
export
|
|
438
|
+
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, TTypesMeta = TypegenDisabled> = (Omit<StateNodeConfig<NoInfer<TContext>, NoInfer<TEvent>, NoInfer<TActor>, NoInfer<TAction>, NoInfer<TGuard>, NoInfer<TDelay>, NoInfer<TTag>, NoInfer<TOutput>>, 'output'> & {
|
|
481
439
|
/**
|
|
482
440
|
* The initial context (extended state)
|
|
483
441
|
*/
|
|
484
|
-
context?: InitialContext<LowInfer<TContext>>;
|
|
485
442
|
/**
|
|
486
443
|
* The machine's own version.
|
|
487
444
|
*/
|
|
488
445
|
version?: string;
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
446
|
+
types?: MachineTypes<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TTypesMeta>;
|
|
447
|
+
output?: Mapper<TContext, DoneStateEvent, TOutput, TEvent> | TOutput;
|
|
448
|
+
}) & (MachineContext extends TContext ? {
|
|
449
|
+
context?: InitialContext<LowInfer<TContext>, TActor, TInput>;
|
|
450
|
+
} : {
|
|
451
|
+
context: InitialContext<LowInfer<TContext>, TActor, TInput>;
|
|
452
|
+
});
|
|
453
|
+
export interface ProvidedActor {
|
|
454
|
+
src: string;
|
|
455
|
+
logic: AnyActorLogic;
|
|
456
|
+
id?: string;
|
|
494
457
|
}
|
|
495
|
-
export
|
|
496
|
-
output: any;
|
|
497
|
-
}>;
|
|
498
|
-
export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActorMap extends ActorMap = ActorMap, TTypesMeta = TypegenDisabled> {
|
|
458
|
+
export interface SetupTypes<TContext extends MachineContext, TEvent extends EventObject, TChildrenMap extends Record<string, string>, TTag extends string, TInput, TOutput> {
|
|
499
459
|
context?: TContext;
|
|
500
|
-
actions?: {
|
|
501
|
-
type: string;
|
|
502
|
-
[key: string]: any;
|
|
503
|
-
};
|
|
504
|
-
actors?: TActorMap;
|
|
505
460
|
events?: TEvent;
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
461
|
+
children?: TChildrenMap;
|
|
462
|
+
tags?: TTag;
|
|
463
|
+
input?: TInput;
|
|
464
|
+
output?: TOutput;
|
|
465
|
+
}
|
|
466
|
+
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, TTypesMeta = TypegenDisabled> extends SetupTypes<TContext, TEvent, never, TTag, TInput, TOutput> {
|
|
467
|
+
actors?: TActor;
|
|
468
|
+
actions?: TAction;
|
|
469
|
+
guards?: TGuard;
|
|
470
|
+
delays?: TDelay;
|
|
510
471
|
typegen?: TTypesMeta;
|
|
511
472
|
}
|
|
512
473
|
export interface HistoryStateNode<TContext extends MachineContext> extends StateNode<TContext> {
|
|
@@ -517,313 +478,115 @@ export type HistoryValue<TContext extends MachineContext, TEvent extends EventOb
|
|
|
517
478
|
export type AnyHistoryValue = HistoryValue<any, any>;
|
|
518
479
|
export type StateFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends AnyStateMachine ? ReturnType<T['transition']> : T extends (...args: any[]) => AnyStateMachine ? ReturnType<ReturnType<T>['transition']> : never;
|
|
519
480
|
export type Transitions<TContext extends MachineContext, TEvent extends EventObject> = Array<TransitionDefinition<TContext, TEvent>>;
|
|
520
|
-
export
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
Send = "xstate.send",
|
|
524
|
-
Cancel = "xstate.cancel",
|
|
525
|
-
Assign = "xstate.assign",
|
|
526
|
-
After = "xstate.after",
|
|
527
|
-
DoneState = "done.state",
|
|
528
|
-
DoneInvoke = "done.invoke",
|
|
529
|
-
Log = "xstate.log",
|
|
530
|
-
Init = "xstate.init",
|
|
531
|
-
Invoke = "xstate.invoke",
|
|
532
|
-
ErrorExecution = "error.execution",
|
|
533
|
-
ErrorCommunication = "error.communication",
|
|
534
|
-
ErrorPlatform = "error.platform",
|
|
535
|
-
ErrorCustom = "xstate.error",
|
|
536
|
-
Pure = "xstate.pure",
|
|
537
|
-
Choose = "xstate.choose"
|
|
481
|
+
export interface DoneActorEvent<TOutput = unknown> {
|
|
482
|
+
type: `xstate.done.actor.${string}`;
|
|
483
|
+
output: TOutput;
|
|
538
484
|
}
|
|
539
|
-
export interface
|
|
540
|
-
type:
|
|
541
|
-
|
|
542
|
-
event: TEvent;
|
|
543
|
-
_event: SCXML.Event<TEvent>;
|
|
544
|
-
delay: RaiseActionOptions<TContext, TExpressionEvent>['delay'];
|
|
545
|
-
id: string | number;
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
export interface DoneInvokeEvent<TData> extends EventObject {
|
|
549
|
-
type: `done.invoke.${string}`;
|
|
550
|
-
output: TData;
|
|
485
|
+
export interface ErrorActorEvent<TErrorData = unknown> extends EventObject {
|
|
486
|
+
type: `xstate.error.actor.${string}`;
|
|
487
|
+
error: TErrorData;
|
|
551
488
|
}
|
|
552
|
-
export interface
|
|
553
|
-
type: `error.${string}`;
|
|
554
|
-
data: TErrorData;
|
|
555
|
-
}
|
|
556
|
-
export interface SnapshotEvent<TData> {
|
|
489
|
+
export interface SnapshotEvent<TSnapshot extends Snapshot<unknown> = Snapshot<unknown>> extends EventObject {
|
|
557
490
|
type: `xstate.snapshot.${string}`;
|
|
558
|
-
|
|
559
|
-
}
|
|
560
|
-
export interface ErrorExecutionEvent extends EventObject {
|
|
561
|
-
src: string;
|
|
562
|
-
type: ActionTypes.ErrorExecution;
|
|
563
|
-
data: any;
|
|
564
|
-
}
|
|
565
|
-
export interface ErrorPlatformEvent extends EventObject {
|
|
566
|
-
data: any;
|
|
567
|
-
}
|
|
568
|
-
export interface SCXMLErrorEvent extends SCXML.Event<any> {
|
|
569
|
-
name: ActionTypes.ErrorExecution | ActionTypes.ErrorPlatform | ActionTypes.ErrorCommunication;
|
|
570
|
-
data: any;
|
|
491
|
+
snapshot: TSnapshot;
|
|
571
492
|
}
|
|
572
|
-
export interface
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}
|
|
576
|
-
export type DoneEvent = DoneEventObject & string;
|
|
577
|
-
export interface InvokeAction {
|
|
578
|
-
type: ActionTypes.Invoke;
|
|
579
|
-
src: string | ActorRef<any>;
|
|
580
|
-
id: string;
|
|
581
|
-
exec?: undefined;
|
|
582
|
-
meta: MetaObject | undefined;
|
|
583
|
-
}
|
|
584
|
-
export interface DynamicInvokeActionObject<TContext extends MachineContext, TEvent extends EventObject> {
|
|
585
|
-
type: ActionTypes.Invoke;
|
|
586
|
-
params: InvokeDefinition<TContext, TEvent>;
|
|
493
|
+
export interface DoneStateEvent<TOutput = unknown> extends EventObject {
|
|
494
|
+
type: `xstate.done.state.${string}`;
|
|
495
|
+
output: TOutput;
|
|
587
496
|
}
|
|
588
|
-
export
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
src: string | ActorRef<any>;
|
|
592
|
-
id: string;
|
|
593
|
-
exec?: undefined;
|
|
594
|
-
ref?: ActorRef<any>;
|
|
595
|
-
meta: MetaObject | undefined;
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
export interface DynamicStopActionObject<TContext extends MachineContext, TExpressionEvent extends EventObject> {
|
|
599
|
-
type: ActionTypes.Stop;
|
|
600
|
-
params: {
|
|
601
|
-
actor: string | ActorRef<any> | Expr<TContext, TExpressionEvent, ActorRef<any> | string>;
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
export interface StopActionObject {
|
|
605
|
-
type: ActionTypes.Stop;
|
|
606
|
-
params: {
|
|
607
|
-
actor: ActorRef<any>;
|
|
608
|
-
};
|
|
609
|
-
}
|
|
610
|
-
export type DelayExpr<TContext extends MachineContext, TEvent extends EventObject> = ExprWithMeta<TContext, TEvent, number>;
|
|
611
|
-
export type LogExpr<TContext extends MachineContext, TEvent extends EventObject> = ExprWithMeta<TContext, TEvent, any>;
|
|
612
|
-
export interface DynamicLogAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> extends BaseDynamicActionObject<TContext, TExpressionEvent, TEvent, LogActionObject, {
|
|
613
|
-
label: string | undefined;
|
|
614
|
-
expr: string | LogExpr<TContext, TExpressionEvent>;
|
|
615
|
-
}> {
|
|
616
|
-
type: ActionTypes.Log;
|
|
617
|
-
}
|
|
618
|
-
export interface LogActionObject extends BuiltInActionObject {
|
|
619
|
-
type: ActionTypes.Log;
|
|
620
|
-
params: {
|
|
621
|
-
label: string | undefined;
|
|
622
|
-
value: any;
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
export interface SendActionObject<TSentEvent extends EventObject = AnyEventObject> extends BaseActionObject {
|
|
626
|
-
type: 'xstate.send';
|
|
627
|
-
params: {
|
|
628
|
-
to: ActorRef<TSentEvent> | undefined;
|
|
629
|
-
_event: SCXML.Event<TSentEvent>;
|
|
630
|
-
event: TSentEvent;
|
|
631
|
-
delay?: number;
|
|
632
|
-
id: string | number;
|
|
633
|
-
internal: boolean;
|
|
634
|
-
};
|
|
635
|
-
}
|
|
636
|
-
export type Expr<TContext extends MachineContext, TEvent extends EventObject, T> = (arg: UnifiedArg<TContext, TEvent>) => T;
|
|
637
|
-
export type ExprWithMeta<TContext extends MachineContext, TEvent extends EventObject, T> = (args: UnifiedArg<TContext, TEvent> & StateMeta<TEvent>) => T;
|
|
638
|
-
export type SendExpr<TContext extends MachineContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject> = ExprWithMeta<TContext, TEvent, TSentEvent>;
|
|
497
|
+
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;
|
|
498
|
+
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;
|
|
499
|
+
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;
|
|
639
500
|
export declare enum SpecialTargets {
|
|
640
501
|
Parent = "#_parent",
|
|
641
502
|
Internal = "#_internal"
|
|
642
503
|
}
|
|
643
|
-
export interface
|
|
644
|
-
to?: string | ActorRef<any, any> | ExprWithMeta<TContext, TEvent, string | ActorRef<any, any>>;
|
|
645
|
-
}
|
|
646
|
-
export interface RaiseActionOptions<TContext extends MachineContext, TEvent extends EventObject> {
|
|
647
|
-
id?: string | number;
|
|
648
|
-
delay?: number | string | DelayExpr<TContext, TEvent>;
|
|
649
|
-
}
|
|
650
|
-
export interface RaiseActionParams<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> extends RaiseActionOptions<TContext, TExpressionEvent> {
|
|
651
|
-
event: TEvent | SendExpr<TContext, TExpressionEvent, TEvent>;
|
|
504
|
+
export interface SendToActionOptions<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string> extends RaiseActionOptions<TContext, TExpressionEvent, TParams, TEvent, TDelay> {
|
|
652
505
|
}
|
|
653
|
-
export interface
|
|
654
|
-
|
|
506
|
+
export interface RaiseActionOptions<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TDelay extends string> {
|
|
507
|
+
id?: string;
|
|
508
|
+
delay?: Delay<TDelay> | DelayExpr<TContext, TExpressionEvent, TParams, TEvent>;
|
|
655
509
|
}
|
|
656
|
-
export interface
|
|
657
|
-
|
|
658
|
-
params: {
|
|
659
|
-
sendId: string | ExprWithMeta<TContext, TExpressionEvent, string>;
|
|
660
|
-
};
|
|
510
|
+
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> {
|
|
511
|
+
event: TEvent | SendExpr<TContext, TExpressionEvent, TParams, TEvent, TEvent>;
|
|
661
512
|
}
|
|
662
|
-
export interface
|
|
663
|
-
|
|
664
|
-
params: {
|
|
665
|
-
sendId: string;
|
|
666
|
-
};
|
|
513
|
+
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> {
|
|
514
|
+
event: TSentEvent | SendExpr<TContext, TExpressionEvent, TParams, TSentEvent, TEvent>;
|
|
667
515
|
}
|
|
668
|
-
export type Assigner<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
export type PartialAssigner<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TKey extends keyof TContext> = (args: {
|
|
673
|
-
context: TContext;
|
|
674
|
-
event: TExpressionEvent;
|
|
675
|
-
} & AssignMeta<TExpressionEvent, TEvent>) => TContext[TKey];
|
|
676
|
-
export type PropertyAssigner<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> = {
|
|
677
|
-
[K in keyof TContext]?: PartialAssigner<TContext, TExpressionEvent, TEvent, K> | TContext[K];
|
|
516
|
+
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>;
|
|
517
|
+
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];
|
|
518
|
+
export type PropertyAssigner<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject, TActor extends ProvidedActor> = {
|
|
519
|
+
[K in keyof TContext]?: PartialAssigner<TContext, TExpressionEvent, TParams, TEvent, TActor, K> | TContext[K];
|
|
678
520
|
};
|
|
679
|
-
export type Mapper<TContext extends MachineContext,
|
|
521
|
+
export type Mapper<TContext extends MachineContext, TExpressionEvent extends EventObject, TResult, TEvent extends EventObject> = (args: {
|
|
680
522
|
context: TContext;
|
|
681
|
-
event:
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
}) => TParams[K]) | TParams[K];
|
|
688
|
-
};
|
|
689
|
-
export interface AnyAssignAction extends BaseActionObject {
|
|
690
|
-
type: ActionTypes.Assign;
|
|
691
|
-
assignment: any;
|
|
692
|
-
}
|
|
693
|
-
export type DynamicAssignAction<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent> = BaseDynamicActionObject<TContext, TExpressionEvent, TEvent, AssignActionObject<TContext> | RaiseActionObject<TContext, TExpressionEvent>, {
|
|
694
|
-
assignment: Assigner<TContext, TExpressionEvent, TEvent> | PropertyAssigner<TContext, TExpressionEvent, TEvent>;
|
|
695
|
-
}>;
|
|
696
|
-
export interface AssignActionObject<TContext extends MachineContext> extends BaseActionObject {
|
|
697
|
-
type: ActionTypes.Assign;
|
|
698
|
-
params: {
|
|
699
|
-
context: TContext;
|
|
700
|
-
actions: BaseActionObject[];
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
|
-
export interface DynamicPureActionObject<TContext extends MachineContext, TEvent extends EventObject> {
|
|
704
|
-
type: ActionTypes.Pure;
|
|
705
|
-
params: {
|
|
706
|
-
get: (args: {
|
|
707
|
-
context: TContext;
|
|
708
|
-
event: TEvent;
|
|
709
|
-
}) => SingleOrArray<BaseActionObject | BaseActionObject['type']> | undefined;
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
export interface PureActionObject extends BaseActionObject {
|
|
713
|
-
type: ActionTypes.Pure;
|
|
714
|
-
params: {
|
|
715
|
-
actions: BaseActionObject[];
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
export interface ChooseAction<TContext extends MachineContext, TEvent extends EventObject> extends BaseActionObject {
|
|
719
|
-
type: ActionTypes.Choose;
|
|
720
|
-
params: {
|
|
721
|
-
guards: Array<ChooseCondition<TContext, TEvent>>;
|
|
722
|
-
};
|
|
723
|
-
}
|
|
724
|
-
export interface ResolvedChooseAction extends BaseActionObject {
|
|
725
|
-
type: ActionTypes.Choose;
|
|
726
|
-
params: {
|
|
727
|
-
actions: BaseActionObject[];
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
export interface TransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends Omit<TransitionConfig<TContext, TEvent>, 'target'> {
|
|
731
|
-
target: Array<StateNode<TContext, TEvent>> | undefined;
|
|
523
|
+
event: TExpressionEvent;
|
|
524
|
+
self: ActorRef<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef>, // TODO: this should be replaced with `TChildren`
|
|
525
|
+
StateValue, string, unknown>, TEvent>;
|
|
526
|
+
}) => TResult;
|
|
527
|
+
export interface TransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends Omit<TransitionConfig<TContext, TEvent, TEvent, TODO, TODO, TODO, TODO>, 'target' | 'guard'> {
|
|
528
|
+
target: ReadonlyArray<StateNode<TContext, TEvent>> | undefined;
|
|
732
529
|
source: StateNode<TContext, TEvent>;
|
|
733
|
-
actions:
|
|
530
|
+
actions: readonly UnknownAction[];
|
|
734
531
|
reenter: boolean;
|
|
735
|
-
guard?:
|
|
736
|
-
eventType: TEvent
|
|
532
|
+
guard?: UnknownGuard;
|
|
533
|
+
eventType: EventDescriptor<TEvent>;
|
|
737
534
|
toJSON: () => {
|
|
738
535
|
target: string[] | undefined;
|
|
739
536
|
source: string;
|
|
740
|
-
actions:
|
|
741
|
-
guard?:
|
|
742
|
-
eventType: TEvent
|
|
537
|
+
actions: readonly UnknownAction[];
|
|
538
|
+
guard?: UnknownGuard;
|
|
539
|
+
eventType: EventDescriptor<TEvent>;
|
|
743
540
|
meta?: Record<string, any>;
|
|
744
541
|
};
|
|
745
542
|
}
|
|
746
543
|
export type AnyTransitionDefinition = TransitionDefinition<any, any>;
|
|
747
544
|
export interface InitialTransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends TransitionDefinition<TContext, TEvent> {
|
|
748
|
-
target:
|
|
545
|
+
target: ReadonlyArray<StateNode<TContext, TEvent>>;
|
|
749
546
|
guard?: never;
|
|
750
547
|
}
|
|
751
548
|
export type TransitionDefinitionMap<TContext extends MachineContext, TEvent extends EventObject> = {
|
|
752
|
-
[K in TEvent
|
|
753
|
-
type: K;
|
|
754
|
-
}> : EventObject>>;
|
|
549
|
+
[K in EventDescriptor<TEvent>]: Array<TransitionDefinition<TContext, ExtractEvent<TEvent, K>>>;
|
|
755
550
|
};
|
|
756
551
|
export interface DelayedTransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends TransitionDefinition<TContext, TEvent> {
|
|
757
|
-
delay: number | string | DelayExpr<TContext, TEvent>;
|
|
758
|
-
}
|
|
759
|
-
export interface Edge<TContext extends MachineContext, TEvent extends EventObject, TEventType extends TEvent['type'] = string> {
|
|
760
|
-
event: TEventType;
|
|
761
|
-
source: StateNode<TContext, TEvent>;
|
|
762
|
-
target: StateNode<TContext, TEvent>;
|
|
763
|
-
cond?: GuardConfig<TContext, TEvent & {
|
|
764
|
-
type: TEventType;
|
|
765
|
-
}>;
|
|
766
|
-
actions: Array<Action<TContext, TEvent>>;
|
|
767
|
-
meta?: MetaObject;
|
|
768
|
-
transition: TransitionDefinition<TContext, TEvent>;
|
|
769
|
-
}
|
|
770
|
-
export interface NodesAndEdges<TContext extends MachineContext, TEvent extends EventObject> {
|
|
771
|
-
nodes: StateNode[];
|
|
772
|
-
edges: Array<Edge<TContext, TEvent, TEvent['type']>>;
|
|
773
|
-
}
|
|
774
|
-
export interface Segment<TContext extends MachineContext, TEvent extends EventObject> {
|
|
775
|
-
/**
|
|
776
|
-
* From state.
|
|
777
|
-
*/
|
|
778
|
-
state: State<TContext, TEvent>;
|
|
779
|
-
/**
|
|
780
|
-
* Event from state.
|
|
781
|
-
*/
|
|
782
|
-
event: TEvent;
|
|
783
|
-
}
|
|
784
|
-
export interface StateMeta<TEvent extends EventObject> {
|
|
785
|
-
_event: SCXML.Event<TEvent>;
|
|
786
|
-
self: ActorRef<TEvent>;
|
|
787
|
-
system: ActorSystem<any>;
|
|
552
|
+
delay: number | string | DelayExpr<TContext, TEvent, undefined, TEvent>;
|
|
788
553
|
}
|
|
789
554
|
export interface StateLike<TContext extends MachineContext> {
|
|
790
555
|
value: StateValue;
|
|
791
556
|
context: TContext;
|
|
792
557
|
event: EventObject;
|
|
793
|
-
_event: SCXML.Event<EventObject>;
|
|
794
558
|
}
|
|
795
559
|
export interface StateConfig<TContext extends MachineContext, TEvent extends EventObject> {
|
|
796
|
-
value: StateValue;
|
|
797
560
|
context: TContext;
|
|
798
|
-
_event: SCXML.Event<TEvent>;
|
|
799
561
|
historyValue?: HistoryValue<TContext, TEvent>;
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
configuration?: Array<StateNode<TContext, TEvent>>;
|
|
803
|
-
transitions?: Array<TransitionDefinition<TContext, TEvent>>;
|
|
804
|
-
children: Record<string, ActorRef<any>>;
|
|
805
|
-
done?: boolean;
|
|
562
|
+
children: Record<string, ActorRef<any, any>>;
|
|
563
|
+
status: 'active' | 'done' | 'error' | 'stopped';
|
|
806
564
|
output?: any;
|
|
807
|
-
|
|
808
|
-
machine?: StateMachine<TContext, TEvent, any, any, any>;
|
|
809
|
-
_internalQueue?: Array<SCXML.Event<TEvent>>;
|
|
565
|
+
error?: unknown;
|
|
566
|
+
machine?: StateMachine<TContext, TEvent, any, any, any, any, any, any, any, any, any>;
|
|
810
567
|
}
|
|
811
|
-
export interface
|
|
568
|
+
export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
812
569
|
/**
|
|
813
|
-
*
|
|
570
|
+
* The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
|
|
571
|
+
*
|
|
572
|
+
* @remarks
|
|
573
|
+
* You can create your own “clock”. The clock interface is an object with two functions/methods:
|
|
574
|
+
*
|
|
575
|
+
* - `setTimeout` - same arguments as `window.setTimeout(fn, timeout)`
|
|
576
|
+
* - `clearTimeout` - same arguments as `window.clearTimeout(id)`
|
|
577
|
+
*
|
|
578
|
+
* By default, the native `setTimeout` and `clearTimeout` functions are used.
|
|
579
|
+
*
|
|
580
|
+
* For testing, XState provides `SimulatedClock`.
|
|
581
|
+
*
|
|
582
|
+
* @see {@link Clock}
|
|
583
|
+
* @see {@link SimulatedClock}
|
|
814
584
|
*/
|
|
815
|
-
execute?: boolean;
|
|
816
585
|
clock?: Clock;
|
|
817
|
-
logger?: (...args: any[]) => void;
|
|
818
|
-
parent?: ActorRef<any>;
|
|
819
586
|
/**
|
|
820
|
-
*
|
|
821
|
-
* is initialized (`.start()`). Otherwise, an error will be thrown
|
|
822
|
-
* for events sent to an uninitialized service.
|
|
823
|
-
*
|
|
824
|
-
* Default: `true`
|
|
587
|
+
* Specifies the logger to be used for log(...) actions. Defaults to the native console.log method.
|
|
825
588
|
*/
|
|
826
|
-
|
|
589
|
+
logger?: (...args: any[]) => void;
|
|
827
590
|
/**
|
|
828
591
|
* The custom `id` for referencing this service.
|
|
829
592
|
*/
|
|
@@ -834,7 +597,6 @@ export interface InterpreterOptions<_TActorBehavior extends AnyActorBehavior> {
|
|
|
834
597
|
* Default: `false`
|
|
835
598
|
*/
|
|
836
599
|
devTools?: boolean | DevToolsAdapter;
|
|
837
|
-
sync?: boolean;
|
|
838
600
|
/**
|
|
839
601
|
* The system ID to register this actor under
|
|
840
602
|
*/
|
|
@@ -842,79 +604,113 @@ export interface InterpreterOptions<_TActorBehavior extends AnyActorBehavior> {
|
|
|
842
604
|
/**
|
|
843
605
|
* The input data to pass to the actor.
|
|
844
606
|
*/
|
|
845
|
-
input?:
|
|
846
|
-
|
|
607
|
+
input?: InputFrom<TLogic>;
|
|
608
|
+
/**
|
|
609
|
+
* Initializes actor logic from a specific persisted internal state.
|
|
610
|
+
*
|
|
611
|
+
* @remarks
|
|
612
|
+
*
|
|
613
|
+
* If the state is compatible with the actor logic, when the actor is started it will be at that persisted state.
|
|
614
|
+
* Actions from machine actors will not be re-executed, because they are assumed to have been already executed.
|
|
615
|
+
* However, invocations will be restarted, and spawned actors will be restored recursively.
|
|
616
|
+
*
|
|
617
|
+
* Can be generated with {@link Actor.getPersistedSnapshot}.
|
|
618
|
+
*
|
|
619
|
+
* @see https://stately.ai/docs/persistence
|
|
620
|
+
*/
|
|
621
|
+
snapshot?: Snapshot<unknown>;
|
|
622
|
+
/**
|
|
623
|
+
* @deprecated Use `snapshot` instead.
|
|
624
|
+
*/
|
|
625
|
+
state?: Snapshot<unknown>;
|
|
847
626
|
/**
|
|
848
627
|
* The source definition.
|
|
849
628
|
*/
|
|
850
|
-
src?: string;
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
629
|
+
src?: string | AnyActorLogic;
|
|
630
|
+
/**
|
|
631
|
+
* A callback function or observer object which can be used to inspect actor system updates.
|
|
632
|
+
*
|
|
633
|
+
* @remarks
|
|
634
|
+
* If a callback function is provided, it can accept an inspection event argument. The types of inspection events that can be observed include:
|
|
635
|
+
*
|
|
636
|
+
* - `@xstate.actor` - An actor ref has been created in the system
|
|
637
|
+
* - `@xstate.event` - An event was sent from a source actor ref to a target actor ref in the system
|
|
638
|
+
* - `@xstate.snapshot` - An actor ref emitted a snapshot due to a received event
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* ```ts
|
|
642
|
+
* import { createMachine } from 'xstate';
|
|
643
|
+
*
|
|
644
|
+
* const machine = createMachine({
|
|
645
|
+
* // ...
|
|
646
|
+
* });
|
|
647
|
+
*
|
|
648
|
+
* const actor = createActor(machine, {
|
|
649
|
+
* inspect: (inspectionEvent) => {
|
|
650
|
+
* if (inspectionEvent.actorRef === actor) {
|
|
651
|
+
* // This event is for the root actor
|
|
652
|
+
* }
|
|
653
|
+
*
|
|
654
|
+
* if (inspectionEvent.type === '@xstate.actor') {
|
|
655
|
+
* console.log(inspectionEvent.actorRef);
|
|
656
|
+
* }
|
|
657
|
+
*
|
|
658
|
+
* if (inspectionEvent.type === '@xstate.event') {
|
|
659
|
+
* console.log(inspectionEvent.sourceRef);
|
|
660
|
+
* console.log(inspectionEvent.actorRef);
|
|
661
|
+
* console.log(inspectionEvent.event);
|
|
662
|
+
* }
|
|
663
|
+
*
|
|
664
|
+
* if (inspectionEvent.type === '@xstate.snapshot') {
|
|
665
|
+
* console.log(inspectionEvent.actorRef);
|
|
666
|
+
* console.log(inspectionEvent.event);
|
|
667
|
+
* console.log(inspectionEvent.snapshot);
|
|
668
|
+
* }
|
|
669
|
+
* }
|
|
670
|
+
* });
|
|
671
|
+
* ```
|
|
672
|
+
*
|
|
673
|
+
* Alternately, an observer object (`{ next?, error?, complete? }`) can be provided:
|
|
674
|
+
*
|
|
675
|
+
* @example
|
|
676
|
+
* ```ts
|
|
677
|
+
* const actor = createActor(machine, {
|
|
678
|
+
* inspect: {
|
|
679
|
+
* next: (inspectionEvent) => {
|
|
680
|
+
* if (inspectionEvent.actorRef === actor) {
|
|
681
|
+
* // This event is for the root actor
|
|
682
|
+
* }
|
|
683
|
+
*
|
|
684
|
+
* if (inspectionEvent.type === '@xstate.actor') {
|
|
685
|
+
* console.log(inspectionEvent.actorRef);
|
|
686
|
+
* }
|
|
687
|
+
*
|
|
688
|
+
* if (inspectionEvent.type === '@xstate.event') {
|
|
689
|
+
* console.log(inspectionEvent.sourceRef);
|
|
690
|
+
* console.log(inspectionEvent.actorRef);
|
|
691
|
+
* console.log(inspectionEvent.event);
|
|
692
|
+
* }
|
|
693
|
+
*
|
|
694
|
+
* if (inspectionEvent.type === '@xstate.snapshot') {
|
|
695
|
+
* console.log(inspectionEvent.actorRef);
|
|
696
|
+
* console.log(inspectionEvent.event);
|
|
697
|
+
* console.log(inspectionEvent.snapshot);
|
|
698
|
+
* }
|
|
699
|
+
* }
|
|
700
|
+
* }
|
|
701
|
+
* });
|
|
702
|
+
* ```
|
|
703
|
+
*/
|
|
704
|
+
inspect?: Observer<InspectionEvent> | ((inspectionEvent: InspectionEvent) => void);
|
|
705
|
+
}
|
|
706
|
+
export type AnyActor = Actor<any>;
|
|
707
|
+
/**
|
|
708
|
+
* @deprecated Use `AnyActor` instead.
|
|
709
|
+
*/
|
|
710
|
+
export type AnyInterpreter = AnyActor;
|
|
915
711
|
export type Observer<T> = {
|
|
916
712
|
next?: (value: T) => void;
|
|
917
|
-
error?: (err:
|
|
713
|
+
error?: (err: unknown) => void;
|
|
918
714
|
complete?: () => void;
|
|
919
715
|
};
|
|
920
716
|
export interface Subscription {
|
|
@@ -930,42 +726,51 @@ export interface Subscribable<T> extends InteropSubscribable<T> {
|
|
|
930
726
|
subscribe(observer: Observer<T>): Subscription;
|
|
931
727
|
subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
|
|
932
728
|
}
|
|
933
|
-
export type
|
|
934
|
-
export type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends any ? TEventType extends TEvent['type'] ? TEvent : never : never;
|
|
729
|
+
export type ExtractEvent<TEvent extends EventObject, TDescriptor extends EventDescriptor<TEvent>> = string extends TEvent['type'] ? TEvent : NormalizeDescriptor<TDescriptor> extends infer TNormalizedDescriptor ? TEvent extends any ? TEvent['type'] extends TNormalizedDescriptor ? TEvent : never : never : never;
|
|
935
730
|
export interface BaseActorRef<TEvent extends EventObject> {
|
|
936
731
|
send: (event: TEvent) => void;
|
|
937
732
|
}
|
|
938
733
|
export interface ActorLike<TCurrent, TEvent extends EventObject> extends Subscribable<TCurrent> {
|
|
939
734
|
send: (event: TEvent) => void;
|
|
940
735
|
}
|
|
941
|
-
export interface ActorRef<
|
|
736
|
+
export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject> extends Subscribable<TSnapshot>, InteropObservable<TSnapshot> {
|
|
942
737
|
/**
|
|
943
738
|
* The unique identifier for this actor relative to its parent.
|
|
944
739
|
*/
|
|
945
740
|
id: string;
|
|
946
741
|
sessionId: string;
|
|
947
742
|
send: (event: TEvent) => void;
|
|
948
|
-
start
|
|
949
|
-
getSnapshot: () => TSnapshot
|
|
950
|
-
|
|
743
|
+
start: () => void;
|
|
744
|
+
getSnapshot: () => TSnapshot;
|
|
745
|
+
getPersistedSnapshot: () => Snapshot<unknown>;
|
|
951
746
|
stop: () => void;
|
|
952
747
|
toJSON?: () => any;
|
|
953
748
|
_parent?: ActorRef<any, any>;
|
|
954
749
|
system?: ActorSystem<any>;
|
|
955
|
-
|
|
956
|
-
src?: string;
|
|
750
|
+
src: string | AnyActorLogic;
|
|
957
751
|
}
|
|
958
752
|
export type AnyActorRef = ActorRef<any, any>;
|
|
959
|
-
export type
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
export type
|
|
966
|
-
export type
|
|
967
|
-
export
|
|
968
|
-
|
|
753
|
+
export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any, any, any, any, any, any, any> ? R : R extends Promise<infer U> ? PromiseActorLogic<U> : never : never;
|
|
754
|
+
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 TResolvedTypesMeta> ? ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>, TEvent> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem> ? ActorRef<TSnapshot, TEvent> : never : never;
|
|
755
|
+
export type DevToolsAdapter = (service: AnyActor) => void;
|
|
756
|
+
/**
|
|
757
|
+
* @deprecated Use `Actor<T>` instead.
|
|
758
|
+
*/
|
|
759
|
+
export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<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 TResolvedTypesMeta> ? Actor<ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TResolvedTypesMeta>, TEvent, TInput, ActorSystem<any>>> : never;
|
|
760
|
+
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<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 TResolvedTypesMeta> ? InternalMachineImplementations<TContext, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
761
|
+
export type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, // context
|
|
762
|
+
any, // event
|
|
763
|
+
any, // children
|
|
764
|
+
any, // actor
|
|
765
|
+
any, // action
|
|
766
|
+
any, // guard
|
|
767
|
+
any, // delay
|
|
768
|
+
any, // tag
|
|
769
|
+
any, // input
|
|
770
|
+
any, // output
|
|
771
|
+
infer TResolvedTypesMeta> ? TResolvedTypesMeta : never;
|
|
772
|
+
export interface ActorScope<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TSystem extends ActorSystem<any> = ActorSystem<any>> {
|
|
773
|
+
self: ActorRef<TSnapshot, TEvent>;
|
|
969
774
|
id: string;
|
|
970
775
|
sessionId: string;
|
|
971
776
|
logger: (...args: any[]) => void;
|
|
@@ -973,34 +778,84 @@ export interface ActorContext<TEvent extends EventObject, TSnapshot, TSystem ext
|
|
|
973
778
|
system: TSystem;
|
|
974
779
|
stopChild: (child: AnyActorRef) => void;
|
|
975
780
|
}
|
|
976
|
-
export type
|
|
977
|
-
export
|
|
781
|
+
export type AnyActorScope = ActorScope<any, any, AnyActorSystem>;
|
|
782
|
+
export type Snapshot<TOutput> = {
|
|
783
|
+
status: 'active';
|
|
784
|
+
output: undefined;
|
|
785
|
+
error: undefined;
|
|
786
|
+
} | {
|
|
787
|
+
status: 'done';
|
|
788
|
+
output: TOutput;
|
|
789
|
+
error: undefined;
|
|
790
|
+
} | {
|
|
791
|
+
status: 'error';
|
|
792
|
+
output: undefined;
|
|
793
|
+
error: unknown;
|
|
794
|
+
} | {
|
|
795
|
+
status: 'stopped';
|
|
796
|
+
output: undefined;
|
|
797
|
+
error: undefined;
|
|
798
|
+
};
|
|
978
799
|
/**
|
|
979
|
-
*
|
|
800
|
+
* Represents logic which can be used by an actor.
|
|
801
|
+
*
|
|
802
|
+
* @template TSnapshot - The type of the snapshot.
|
|
803
|
+
* @template TEvent - The type of the event object.
|
|
804
|
+
* @template TInput - The type of the input.
|
|
805
|
+
* @template TSystem - The type of the actor system.
|
|
980
806
|
*/
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
807
|
+
export interface ActorLogic<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput = NonReducibleUnknown, TSystem extends ActorSystem<any> = ActorSystem<any>> {
|
|
808
|
+
/** The initial setup/configuration used to create the actor logic. */
|
|
809
|
+
config?: unknown;
|
|
810
|
+
/**
|
|
811
|
+
* Transition function that processes the current state and an incoming message
|
|
812
|
+
* to produce a new state.
|
|
813
|
+
* @param snapshot - The current state.
|
|
814
|
+
* @param message - The incoming message.
|
|
815
|
+
* @param ctx - The actor scope.
|
|
816
|
+
* @returns The new state.
|
|
817
|
+
*/
|
|
818
|
+
transition: (snapshot: TSnapshot, message: TEvent, ctx: ActorScope<TSnapshot, TEvent, TSystem>) => TSnapshot;
|
|
819
|
+
/**
|
|
820
|
+
* Called to provide the initial state of the actor.
|
|
821
|
+
* @param actorScope - The actor scope.
|
|
822
|
+
* @param input - The input for the initial state.
|
|
823
|
+
* @returns The initial state.
|
|
824
|
+
*/
|
|
825
|
+
getInitialSnapshot: (actorScope: ActorScope<TSnapshot, TEvent, TSystem>, input: TInput) => TSnapshot;
|
|
826
|
+
/**
|
|
827
|
+
* Called when Actor is created to restore the internal state of the actor given a persisted state.
|
|
828
|
+
* The persisted state can be created by `getPersistedSnapshot`.
|
|
829
|
+
* @param persistedState - The persisted state to restore from.
|
|
830
|
+
* @param actorScope - The actor scope.
|
|
831
|
+
* @returns The restored state.
|
|
832
|
+
*/
|
|
833
|
+
restoreSnapshot?: (persistedState: Snapshot<unknown>, actorScope: ActorScope<TSnapshot, TEvent>) => TSnapshot;
|
|
834
|
+
/**
|
|
835
|
+
* Called when the actor is started.
|
|
836
|
+
* @param snapshot - The starting state.
|
|
837
|
+
* @param actorScope - The actor scope.
|
|
838
|
+
*/
|
|
839
|
+
start?: (snapshot: TSnapshot, actorScope: ActorScope<TSnapshot, TEvent>) => void;
|
|
840
|
+
/**
|
|
841
|
+
* Obtains the internal state of the actor in a representation which can be be persisted.
|
|
842
|
+
* The persisted state can be restored by `restoreSnapshot`.
|
|
843
|
+
* @param snapshot - The current state.
|
|
844
|
+
* @returns The a representation of the internal state to be persisted.
|
|
845
|
+
*/
|
|
846
|
+
getPersistedSnapshot: (snapshot: TSnapshot, options?: unknown) => Snapshot<unknown>;
|
|
847
|
+
}
|
|
848
|
+
export type AnyActorLogic = ActorLogic<any, // snapshot
|
|
849
|
+
any, // event
|
|
850
|
+
any, // input
|
|
851
|
+
any>;
|
|
852
|
+
export type UnknownActorLogic = ActorLogic<any, // this is invariant and it's hard to figure out a better default than `any`
|
|
853
|
+
EventObject, NonReducibleUnknown, ActorSystem<any>>;
|
|
854
|
+
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer TSnapshot, infer _> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends ActorLogic<infer _, infer __, infer ___, infer ____> ? ReturnType<R['transition']> : R extends ActorScope<infer TSnapshot, infer _, infer __> ? TSnapshot : never : never;
|
|
855
|
+
export type EventFromLogic<TLogic extends ActorLogic<any, any, any, any>> = TLogic extends ActorLogic<infer _, infer TEvent, infer __, infer _____> ? TEvent : never;
|
|
856
|
+
type ResolveEventType<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 _TResolvedTypesMeta> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TChildren, infer _TTag, infer _TOutput, infer _TResolvedTypesMeta> ? TEvent : R extends ActorRef<infer _, infer TEvent> ? TEvent : never : never;
|
|
1002
857
|
export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
|
|
1003
|
-
export type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer
|
|
858
|
+
export type ContextFrom<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 _TTypesMeta> ? TContext : R extends MachineSnapshot<infer TContext, infer _TEvent, infer _TChildren, infer _TTag, infer _TOutput, infer _TResolvedTypesMeta> ? TContext : R extends Actor<infer TActorLogic> ? TActorLogic extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer _TTypesMeta> ? TContext : never : never : never;
|
|
1004
859
|
export type InferEvent<E extends EventObject> = {
|
|
1005
860
|
[T in E['type']]: {
|
|
1006
861
|
type: T;
|
|
@@ -1010,23 +865,27 @@ export type InferEvent<E extends EventObject> = {
|
|
|
1010
865
|
}[E['type']];
|
|
1011
866
|
export type TODO = any;
|
|
1012
867
|
export type StateValueFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TMachine>['matches']>[0];
|
|
1013
|
-
export type
|
|
868
|
+
export type TagsFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TMachine>['hasTag']>[0];
|
|
1014
869
|
export interface ActorSystemInfo {
|
|
1015
870
|
actors: Record<string, AnyActorRef>;
|
|
1016
871
|
}
|
|
1017
872
|
export interface ActorSystem<T extends ActorSystemInfo> {
|
|
1018
|
-
_bookId: () => string;
|
|
1019
|
-
_register: (sessionId: string, actorRef: AnyActorRef) => string;
|
|
1020
|
-
_unregister: (actorRef: AnyActorRef) => void;
|
|
1021
|
-
_set: <K extends keyof T['actors']>(key: K, actorRef: T['actors'][K]) => void;
|
|
1022
873
|
get: <K extends keyof T['actors']>(key: K) => T['actors'][K] | undefined;
|
|
874
|
+
inspect: (observer: Observer<InspectionEvent>) => void;
|
|
1023
875
|
}
|
|
1024
|
-
export type
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
876
|
+
export type AnyActorSystem = ActorSystem<any>;
|
|
877
|
+
export type RequiredActorOptions<TActor extends ProvidedActor> = (undefined extends TActor['id'] ? never : 'id') | (undefined extends InputFrom<TActor['logic']> ? never : 'input');
|
|
878
|
+
type ExtractLiteralString<T extends string | undefined> = T extends string ? string extends T ? never : T : never;
|
|
879
|
+
type ToConcreteChildren<TActor extends ProvidedActor> = {
|
|
880
|
+
[A in TActor as ExtractLiteralString<A['id']>]?: ActorRefFrom<A['logic']>;
|
|
881
|
+
};
|
|
882
|
+
export type ToChildren<TActor extends ProvidedActor> = string extends TActor['src'] ? Record<string, AnyActorRef> : Compute<ToConcreteChildren<TActor> & {
|
|
883
|
+
include: {
|
|
884
|
+
[id: string]: TActor extends any ? ActorRefFrom<TActor['logic']> | undefined : never;
|
|
1030
885
|
};
|
|
886
|
+
exclude: {};
|
|
887
|
+
}[undefined extends TActor['id'] ? 'include' : string extends TActor['id'] ? 'include' : 'exclude']>;
|
|
888
|
+
export type StateSchema = {
|
|
889
|
+
states?: Record<string, StateSchema>;
|
|
1031
890
|
};
|
|
1032
891
|
export {};
|