xstate 6.0.0-alpha.2 → 6.0.0-alpha.21
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 +19 -17
- package/bin/xstate.js +36 -0
- package/dist/{StateMachine-64813f46.cjs.js → StateMachine-1b155670.cjs.js} +182 -40
- package/dist/{StateMachine-2dcdb1f5.esm.js → StateMachine-3c17fe3e.esm.js} +182 -40
- package/dist/{StateMachine-8d22a79c.development.cjs.js → StateMachine-550ff7f2.development.cjs.js} +193 -36
- package/dist/{StateMachine-2ea0a7fa.development.esm.js → StateMachine-e25dd61f.development.esm.js} +193 -36
- package/dist/declarations/src/State.d.ts +13 -2
- package/dist/declarations/src/StateMachine.d.ts +23 -13
- package/dist/declarations/src/actions.d.ts +2 -1
- package/dist/declarations/src/actors/promise.d.ts +4 -2
- package/dist/declarations/src/createActor.d.ts +9 -11
- package/dist/declarations/src/createMachine.d.ts +14 -11
- package/dist/declarations/src/createMachineFromConfig.d.ts +61 -28
- package/dist/declarations/src/fsm.d.ts +74 -0
- package/dist/declarations/src/graph/graph.d.ts +3 -3
- package/dist/declarations/src/graph/shortestPaths.d.ts +2 -2
- package/dist/declarations/src/graph/simplePaths.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +6 -5
- package/dist/declarations/src/serialize.d.ts +10 -18
- package/dist/declarations/src/setup.d.ts +277 -65
- package/dist/declarations/src/spawn.d.ts +3 -3
- package/dist/declarations/src/stateUtils.d.ts +4 -1
- package/dist/declarations/src/system.d.ts +1 -1
- package/dist/declarations/src/transition.d.ts +8 -5
- package/dist/declarations/src/transitionActions.d.ts +12 -0
- package/dist/declarations/src/types.d.ts +237 -102
- package/dist/declarations/src/types.v6.d.ts +132 -58
- package/dist/declarations/src/utils.d.ts +4 -3
- package/dist/{index-93edd3bd.esm.js → index-3f87408c.esm.js} +936 -1389
- package/dist/{index-e61170ba.development.esm.js → index-d39fb138.development.esm.js} +968 -1421
- package/dist/{index-9cb3b3a0.cjs.js → index-e694228c.cjs.js} +945 -1394
- package/dist/{index-f6ef20d1.development.cjs.js → index-ec7c7a2d.development.cjs.js} +977 -1426
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +1 -1
- package/dist/xstate-actors.esm.js +1 -1
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +2 -2
- package/dist/xstate-graph.development.cjs.js +2 -2
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +1100 -182
- package/dist/xstate.cjs.mjs +3 -5
- package/dist/xstate.development.cjs.js +1100 -182
- package/dist/xstate.development.cjs.mjs +3 -5
- package/dist/xstate.development.esm.js +1101 -181
- package/dist/xstate.esm.js +1101 -181
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +6 -2
- package/dist/declarations/src/atom.d.ts +0 -81
|
@@ -2,7 +2,6 @@ import type { MachineSnapshot } from "./State.js";
|
|
|
2
2
|
import type { StateMachine } from "./StateMachine.js";
|
|
3
3
|
import type { StateNode } from "./StateNode.js";
|
|
4
4
|
import { AsyncActorLogic } from "./actors/promise.js";
|
|
5
|
-
import type { BaseAtom } from "./atom.js";
|
|
6
5
|
import type { Actor } from "./createActor.js";
|
|
7
6
|
import { InspectionEvent } from "./inspection.js";
|
|
8
7
|
import { Spawner } from "./spawn.js";
|
|
@@ -80,18 +79,27 @@ export interface ParameterizedObject {
|
|
|
80
79
|
type: string;
|
|
81
80
|
params?: NonReducibleUnknown;
|
|
82
81
|
}
|
|
83
|
-
export
|
|
82
|
+
export type UnifiedArg<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> = {
|
|
84
83
|
context: TContext;
|
|
85
84
|
event: TExpressionEvent;
|
|
86
85
|
self: ActorSelf<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>, // TODO: this should be replaced with `TChildren`
|
|
87
86
|
StateValue, string, unknown, TODO, // TMeta
|
|
88
87
|
TODO>, TEvent, AnyEventObject>;
|
|
89
88
|
system: AnyActorSystem;
|
|
90
|
-
}
|
|
89
|
+
} & OutputArg<TExpressionEvent>;
|
|
91
90
|
export type MachineContext = Record<string, any>;
|
|
92
|
-
|
|
91
|
+
type DoneEventType = `xstate.done.actor.${string}` | `xstate.done.state.${string}`;
|
|
92
|
+
export type OutputArg<TEvent extends EventObject> = TEvent extends {
|
|
93
|
+
type: DoneEventType;
|
|
94
|
+
output: infer TOutput;
|
|
95
|
+
} ? {
|
|
96
|
+
output: TOutput;
|
|
97
|
+
} : {
|
|
98
|
+
output: undefined;
|
|
99
|
+
};
|
|
100
|
+
export type ActionArgs<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> = UnifiedArg<TContext, TExpressionEvent, TEvent> & {
|
|
93
101
|
children: Record<string, AnyActor>;
|
|
94
|
-
}
|
|
102
|
+
};
|
|
95
103
|
export type InputFrom<T> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TStateSchema, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TInput : T extends ActorLogic<infer _TSnapshot, infer _TEvent, infer TInput, infer _TSystem, infer _TEmitted> ? TInput : never;
|
|
96
104
|
export type OutputFrom<T> = T extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? (TSnapshot & {
|
|
97
105
|
status: 'done';
|
|
@@ -102,10 +110,10 @@ export type NoRequiredParams<T extends ParameterizedObject> = T extends any ? un
|
|
|
102
110
|
export type ConditionalRequired<T, Condition extends boolean> = Condition extends true ? Required<T> : T;
|
|
103
111
|
export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent extends EventObject, T extends ParameterizedObject> = T extends any ? ConditionalRequired<{
|
|
104
112
|
type: T['type'];
|
|
105
|
-
params?: T['params'] | (({ context, event }: {
|
|
113
|
+
params?: T['params'] | (({ context, event, output }: {
|
|
106
114
|
context: TContext;
|
|
107
115
|
event: TExpressionEvent;
|
|
108
|
-
}) => T['params']);
|
|
116
|
+
} & OutputArg<TExpressionEvent>) => T['params']);
|
|
109
117
|
}, undefined extends T['params'] ? false : true> : never;
|
|
110
118
|
export type StateKey = string | AnyMachineSnapshot;
|
|
111
119
|
export interface StateValueMap {
|
|
@@ -122,16 +130,23 @@ export interface StateValueMap {
|
|
|
122
130
|
*/
|
|
123
131
|
export type StateValue = string | StateValueMap;
|
|
124
132
|
export type TransitionTarget = SingleOrArray<string>;
|
|
125
|
-
export
|
|
133
|
+
export type TransitionContextPatch<TContext extends MachineContext> = Partial<TContext> & {
|
|
134
|
+
call?: never;
|
|
135
|
+
apply?: never;
|
|
136
|
+
bind?: never;
|
|
137
|
+
};
|
|
138
|
+
export type TransitionContextMapper<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], _TCtx extends MachineContext = [TContext] extends [never] ? any : TContext> = (args: TransitionFunctionArgs<_TCtx, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>) => TransitionContextPatch<_TCtx>;
|
|
139
|
+
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
126
140
|
actions?: never;
|
|
127
141
|
guard?: unknown;
|
|
128
142
|
reenter?: boolean;
|
|
129
143
|
target?: TransitionTarget | undefined;
|
|
144
|
+
context?: TransitionContextPatch<TContext> | TransitionContextMapper<TContext, TExpressionEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
130
145
|
to?: TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
131
146
|
meta?: TMeta;
|
|
132
147
|
description?: string;
|
|
133
148
|
}
|
|
134
|
-
export interface InitialTransitionConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
149
|
+
export interface InitialTransitionConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> extends TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> {
|
|
135
150
|
target: string;
|
|
136
151
|
}
|
|
137
152
|
export type AnyTransitionConfig = TransitionConfig<any, // TContext
|
|
@@ -143,11 +158,11 @@ any, // TActionMap
|
|
|
143
158
|
any, // TActorMap
|
|
144
159
|
any, // TGuardMap
|
|
145
160
|
any>;
|
|
146
|
-
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
161
|
+
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
147
162
|
id: string;
|
|
148
|
-
|
|
149
|
-
logic: string | AnyActorLogic | (({
|
|
150
|
-
|
|
163
|
+
registryKey: string | undefined;
|
|
164
|
+
logic: string | AnyActorLogic | (({ actorSources, context, event, self }: {
|
|
165
|
+
actorSources: TActorMap;
|
|
151
166
|
context: TContext;
|
|
152
167
|
event: TEvent;
|
|
153
168
|
self: AnyActorRef;
|
|
@@ -177,9 +192,9 @@ export interface InvokeDefinition<TContext extends MachineContext, TEvent extend
|
|
|
177
192
|
/** The transition to take when the invoke-level `timeout` expires. */
|
|
178
193
|
onTimeout?: string | SingleOrArray<TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>>;
|
|
179
194
|
}
|
|
180
|
-
export type AnyInvokeDefinition = InvokeDefinition<MachineContext, EventObject, EventObject, MetaObject, Implementations['actions'], Implementations['
|
|
195
|
+
export type AnyInvokeDefinition = InvokeDefinition<MachineContext, EventObject, EventObject, MetaObject, Implementations['actions'], Implementations['actorSources'], Implementations['guards'], Implementations['delays']>;
|
|
181
196
|
type Delay<TDelay extends string> = TDelay | number;
|
|
182
|
-
export type DelayedTransitions<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
197
|
+
export type DelayedTransitions<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
183
198
|
[K in Delay<keyof TDelayMap & string>]?: string | SingleOrArray<TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>> | TransitionConfigFunction<TContext, TEvent, TEvent, TODO, any, any, any, any, any>;
|
|
184
199
|
};
|
|
185
200
|
export type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'choice' | 'history' | ({} & string);
|
|
@@ -188,26 +203,31 @@ export type StateNodesConfig<TContext extends MachineContext, TEvent extends Eve
|
|
|
188
203
|
[K in string]: StateNode<TContext, TEvent>;
|
|
189
204
|
};
|
|
190
205
|
export type TransitionConfigTarget = string | undefined;
|
|
191
|
-
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
192
|
-
export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
193
|
-
|
|
206
|
+
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = SingleOrArray<TransitionConfigTarget | TransitionConfig<TContext, TExpressionEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> | TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>>;
|
|
207
|
+
export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TInput = undefined, _TCtx extends MachineContext = [TContext] extends [never] ? any : TContext> = (args: TransitionFunctionArgs<_TCtx, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap> & {
|
|
208
|
+
input: TInput;
|
|
209
|
+
}, enq: EnqueueObject<TEvent, TEmitted>) => {
|
|
210
|
+
target?: string | string[];
|
|
211
|
+
context?: TransitionContextPatch<_TCtx>;
|
|
212
|
+
reenter?: boolean;
|
|
213
|
+
meta?: TMeta;
|
|
214
|
+
input?: Record<string, unknown>;
|
|
215
|
+
} | void;
|
|
216
|
+
type TransitionFunctionArgs<TContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
217
|
+
context: TContext;
|
|
194
218
|
event: TCurrentEvent;
|
|
195
|
-
self: ActorSelf<MachineSnapshot<
|
|
219
|
+
self: ActorSelf<MachineSnapshot<TContext & MachineContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO>, TEvent>;
|
|
196
220
|
parent: UnknownActorRef | undefined;
|
|
197
221
|
value: StateValue;
|
|
198
222
|
children: Record<string, AnyActor>;
|
|
223
|
+
system: AnyActorSystem;
|
|
199
224
|
actions: TActionMap;
|
|
200
|
-
|
|
225
|
+
actorSources: TActorMap;
|
|
201
226
|
guards: TGuardMap;
|
|
202
227
|
delays: TDelayMap;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
reenter?: boolean;
|
|
207
|
-
meta?: TMeta;
|
|
208
|
-
} | void;
|
|
209
|
-
export type AnyTransitionConfigFunction = TransitionConfigFunction<any, any, any, any, any, any, any, any, any>;
|
|
210
|
-
export type TransitionsConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
228
|
+
} & OutputArg<TCurrentEvent>;
|
|
229
|
+
export type AnyTransitionConfigFunction = TransitionConfigFunction<any, any, any, any, any, any, any, any, any, any>;
|
|
230
|
+
export type TransitionsConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
211
231
|
[K in EventDescriptor<TEvent>]?: TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
212
232
|
};
|
|
213
233
|
type PartialEventDescriptor<TEventType extends string> = TEventType extends `${infer TLeading}.${infer TTail}` ? `${TLeading}.*` | `${TLeading}.${PartialEventDescriptor<TTail>}` : never;
|
|
@@ -223,10 +243,10 @@ type ActorImplementationsBySrc<TActor extends ProvidedActor> = {
|
|
|
223
243
|
type DistributeActors<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, _TAction extends ParameterizedObject, _TGuard extends ParameterizedObject, _TDelay extends string, TEmitted extends EventObject, TMeta extends MetaObject, TSpecificActor extends ProvidedActor> = TSpecificActor extends {
|
|
224
244
|
src: infer TSrc;
|
|
225
245
|
} ? Compute<{
|
|
226
|
-
|
|
246
|
+
registryKey?: string;
|
|
227
247
|
/** The source of the machine to be invoked, or the machine itself. */
|
|
228
|
-
src: TSrc | (({
|
|
229
|
-
|
|
248
|
+
src: TSrc | (({ actorSources, context, event, self }: {
|
|
249
|
+
actorSources: ActorImplementationsBySrc<TActor>;
|
|
230
250
|
context: TContext;
|
|
231
251
|
event: TEvent;
|
|
232
252
|
self: AnyActorRef;
|
|
@@ -257,9 +277,9 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
257
277
|
[K in RequiredActorOptions<TSpecificActor>]: unknown;
|
|
258
278
|
}> | {
|
|
259
279
|
id?: never;
|
|
260
|
-
|
|
261
|
-
src: string | AnyActorLogic | (({
|
|
262
|
-
|
|
280
|
+
registryKey?: string;
|
|
281
|
+
src: string | AnyActorLogic | (({ actorSources, context, event, self }: {
|
|
282
|
+
actorSources: ActorImplementationsBySrc<TActor>;
|
|
263
283
|
context: TContext;
|
|
264
284
|
event: TEvent;
|
|
265
285
|
self: AnyActorRef;
|
|
@@ -280,10 +300,10 @@ export type InvokeConfig<TContext extends MachineContext, TEvent extends EventOb
|
|
|
280
300
|
* will be the machine's own `id`, or the URL (from `src`).
|
|
281
301
|
*/
|
|
282
302
|
id?: string;
|
|
283
|
-
|
|
303
|
+
registryKey?: string;
|
|
284
304
|
/** The source of the machine to be invoked, or the machine itself. */
|
|
285
|
-
src: string | AnyActorLogic | (({
|
|
286
|
-
|
|
305
|
+
src: string | AnyActorLogic | (({ actorSources, context, event, self }: {
|
|
306
|
+
actorSources: ActorImplementationsBySrc<TActor>;
|
|
287
307
|
context: TContext;
|
|
288
308
|
event: TEvent;
|
|
289
309
|
self: AnyActorRef;
|
|
@@ -307,29 +327,36 @@ export type InvokeConfig<TContext extends MachineContext, TEvent extends EventOb
|
|
|
307
327
|
onTimeout?: string | SingleOrArray<TransitionConfigOrTarget<TContext, TEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
|
|
308
328
|
};
|
|
309
329
|
export type AnyInvokeConfig = InvokeConfig<any, any, any, any, any, any, any, any>;
|
|
310
|
-
export type AnyStateNodeConfig = Next_StateNodeConfig<any, any, any, any, any, any, any, any, any, any, any>;
|
|
330
|
+
export type AnyStateNodeConfig = Next_StateNodeConfig<any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
311
331
|
export type AnyStateNode = StateNode<any, any> | StateNode<never, EventObject> | StateNode<any, EventObject> | StateNode<never, any>;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
any
|
|
315
|
-
|
|
316
|
-
any,
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
any,
|
|
324
|
-
any
|
|
325
|
-
|
|
326
|
-
any
|
|
332
|
+
type LoosenMachineSnapshot<TSnapshot> = TSnapshot extends MachineSnapshot<any, any, any, any, any, any, any, any> ? Omit<TSnapshot, 'matches' | 'can'> & {
|
|
333
|
+
matches(partialStateValue: StateValue): boolean;
|
|
334
|
+
can(event: any): boolean;
|
|
335
|
+
} : never;
|
|
336
|
+
export type AnyMachineSnapshot = LoosenMachineSnapshot<MachineSnapshot<any, any, any, any, any, any, any, any>>;
|
|
337
|
+
export interface AnyStateMachine extends AnyActorLogic {
|
|
338
|
+
id: string;
|
|
339
|
+
root: AnyStateNode;
|
|
340
|
+
options?: {
|
|
341
|
+
maxIterations?: number;
|
|
342
|
+
};
|
|
343
|
+
states: StateNodesConfig<any, any>;
|
|
344
|
+
events: Array<EventDescriptor<any>>;
|
|
345
|
+
implementations: Implementations;
|
|
346
|
+
config: any;
|
|
347
|
+
version?: string;
|
|
348
|
+
provide(implementations: any): AnyStateMachine;
|
|
349
|
+
resolveState(config: any): any;
|
|
350
|
+
getTransitionData(snapshot: any, event: any, actor: AnyActorRef): AnyTransitionDefinition[];
|
|
351
|
+
getStateNodeById(stateId: string): AnyStateNode;
|
|
352
|
+
getPersistedSnapshot(snapshot: any, options?: unknown): Snapshot<unknown>;
|
|
353
|
+
}
|
|
327
354
|
export type AnyStateConfig = StateConfig<any, AnyEventObject>;
|
|
328
355
|
export type DelayConfig<TContext extends MachineContext, TExpressionEvent extends EventObject> = number | DelayExpr<TContext, TExpressionEvent>;
|
|
329
|
-
export type InitialContext<TContext extends MachineContext, TActorMap extends Implementations['
|
|
330
|
-
export type ContextFactory<TContext extends MachineContext, TActorMap extends Implementations['
|
|
356
|
+
export type InitialContext<TContext extends MachineContext, TActorMap extends Implementations['actorSources'], TInput, TEvent extends EventObject> = TContext | ContextFactory<TContext, TActorMap, TInput, TEvent>;
|
|
357
|
+
export type ContextFactory<TContext extends MachineContext, TActorMap extends Implementations['actorSources'], TInput, TEvent extends EventObject = EventObject> = ({ spawn, actorSources, input, self }: {
|
|
331
358
|
spawn: Spawner;
|
|
332
|
-
|
|
359
|
+
actorSources: TActorMap;
|
|
333
360
|
input: TInput;
|
|
334
361
|
self: ActorSelf<MachineSnapshot<[
|
|
335
362
|
TContext
|
|
@@ -353,7 +380,7 @@ export interface SetupTypes<TContext extends MachineContext, TEvent extends Even
|
|
|
353
380
|
meta?: TMeta;
|
|
354
381
|
}
|
|
355
382
|
export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject> extends SetupTypes<TContext, TEvent, never, TTag, TInput, TOutput, TEmitted, TMeta> {
|
|
356
|
-
|
|
383
|
+
actorSources?: TActor;
|
|
357
384
|
actions?: TAction;
|
|
358
385
|
guards?: TGuard;
|
|
359
386
|
delays?: TDelay;
|
|
@@ -368,7 +395,20 @@ export type PersistedHistoryValue = Record<string, Array<{
|
|
|
368
395
|
id: string;
|
|
369
396
|
}>>;
|
|
370
397
|
export type AnyHistoryValue = HistoryValue;
|
|
371
|
-
export type StateFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends AnyStateMachine ?
|
|
398
|
+
export type StateFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends AnyStateMachine ? StateSnapshotFromMachine<T> : T extends (...args: any[]) => AnyStateMachine ? StateSnapshotFromMachine<ReturnType<T>> : never;
|
|
399
|
+
type StateValueFromStateSchema<T extends StateSchema> = StateSchema extends T ? StateValue : ToStateValue<T> extends infer TStateValue ? TStateValue extends StateValue ? TStateValue : StateValue : StateValue;
|
|
400
|
+
type MatchingStateValueForStateFrom<TStateValue extends StateValue, TTestStateValue extends StateValue> = TStateValue extends unknown ? TTestStateValue extends string ? TStateValue extends string ? TTestStateValue extends TStateValue ? TTestStateValue : Extract<TStateValue, TTestStateValue> : TStateValue extends StateValueMap ? TStateValue & Record<TTestStateValue, StateValue | undefined> : never : TTestStateValue extends StateValueMap ? TStateValue extends StateValueMap ? MatchingStateValueMapForStateFrom<TStateValue, TTestStateValue> : never : never : never;
|
|
401
|
+
type MatchingStateValueMapForStateFrom<TStateValue extends StateValueMap, TTestStateValue extends StateValueMap> = false extends {
|
|
402
|
+
[K in keyof TTestStateValue & string]: K extends keyof TStateValue ? IsNever<MatchingStateValueForStateFrom<NonNullable<TStateValue[K]>, NonNullable<TTestStateValue[K]>>> extends true ? false : true : false;
|
|
403
|
+
}[keyof TTestStateValue & string] ? never : {
|
|
404
|
+
[K in keyof TStateValue]: K extends keyof TTestStateValue ? MatchingStateValueForStateFrom<NonNullable<TStateValue[K]>, NonNullable<TTestStateValue[K]>> : TStateValue[K];
|
|
405
|
+
};
|
|
406
|
+
type StateSnapshotFromStateValue<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject, TStateSchema extends StateSchema, TAllStateValue extends StateValue = TStateValue> = TStateValue extends unknown ? Omit<MachineSnapshot<StateContextFromStateValue<TStateSchema, TContext, TStateValue>, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>, 'matches'> & {
|
|
407
|
+
matches<const TTestStateValue extends string>(partialStateValue: TTestStateValue, ...args: string extends TTestStateValue ? [never] : []): this is StateSnapshotFromStateValue<StateContextFromStateValue<TStateSchema, TContext, TTestStateValue>, TEvent, TChildren, MatchingStateValueForStateFrom<TAllStateValue, TTestStateValue>, TTag, TOutput, TMeta, TStateSchema, TAllStateValue>;
|
|
408
|
+
matches<const TTestStateValue extends StateValueMap>(partialStateValue: TTestStateValue, ...args: string extends keyof TTestStateValue ? [never] : []): this is StateSnapshotFromStateValue<StateContextFromStateValue<TStateSchema, TContext, TTestStateValue>, TEvent, TChildren, MatchingStateValueForStateFrom<TAllStateValue, TTestStateValue>, TTag, TOutput, TMeta, TStateSchema, TAllStateValue>;
|
|
409
|
+
matches(partialStateValue: StateValue): boolean;
|
|
410
|
+
} : never;
|
|
411
|
+
type StateSnapshotFromMachine<T extends AnyStateMachine> = SnapshotFrom<T> extends MachineSnapshot<infer TContext, infer TEvent, infer TChildren, infer _TStateValue, infer TTag, infer TOutput, infer TMeta, infer TStateSchema> ? StateSnapshotFromStateValue<TContext, TEvent, TChildren, StateValueFromStateSchema<TStateSchema>, TTag, TOutput, TMeta, TStateSchema, StateValueFromStateSchema<TStateSchema>> : SnapshotFrom<T>;
|
|
372
412
|
export interface DoneActorEvent<TOutput = unknown, TId extends string = string> extends EventObject {
|
|
373
413
|
type: `xstate.done.actor.${TId}`;
|
|
374
414
|
output: TOutput;
|
|
@@ -379,6 +419,11 @@ export interface ErrorActorEvent<TErrorData = unknown, TId extends string = stri
|
|
|
379
419
|
error: TErrorData;
|
|
380
420
|
actorId: TId;
|
|
381
421
|
}
|
|
422
|
+
export interface ErrorPlatformEvent<TErrorData = unknown, TKind extends string = string> extends EventObject {
|
|
423
|
+
type: `xstate.error.${TKind}`;
|
|
424
|
+
error: TErrorData;
|
|
425
|
+
}
|
|
426
|
+
export type ErrorEvent = ErrorActorEvent | ErrorPlatformEvent;
|
|
382
427
|
export interface SnapshotEvent<TSnapshot extends Snapshot<unknown> = Snapshot<unknown>> extends EventObject {
|
|
383
428
|
type: `xstate.snapshot.${string}`;
|
|
384
429
|
snapshot: TSnapshot;
|
|
@@ -396,7 +441,7 @@ export type Mapper<TContext extends MachineContext, TExpressionEvent extends Eve
|
|
|
396
441
|
self: ActorSelf<MachineSnapshot<_TCtx & MachineContext, TEvent, Record<string, AnyActorRef>, // TODO: this should be replaced with `TChildren`
|
|
397
442
|
StateValue, string, unknown, TODO, // TMeta
|
|
398
443
|
TODO>, TEvent, AnyEventObject>;
|
|
399
|
-
}) => TResult;
|
|
444
|
+
} & OutputArg<TExpressionEvent>) => TResult;
|
|
400
445
|
export interface TransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends Omit<TransitionConfig<TContext, TEvent, TEvent, TODO, TODO, TODO, TODO, TODO, // TEmitted
|
|
401
446
|
TODO>, 'target' | 'to'> {
|
|
402
447
|
target: ReadonlyArray<AnyStateNode> | undefined;
|
|
@@ -407,6 +452,7 @@ TODO>, 'target' | 'to'> {
|
|
|
407
452
|
input?: Record<string, unknown> | ((args: {
|
|
408
453
|
context: any;
|
|
409
454
|
event: any;
|
|
455
|
+
output: any;
|
|
410
456
|
}) => Record<string, unknown>);
|
|
411
457
|
}
|
|
412
458
|
export type AnyTransitionDefinition = TransitionDefinition<any, any>;
|
|
@@ -512,8 +558,8 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
512
558
|
id?: string;
|
|
513
559
|
/** @deprecated Use `inspect` instead. */
|
|
514
560
|
devTools?: never;
|
|
515
|
-
/** The
|
|
516
|
-
|
|
561
|
+
/** The registry key to register this actor under. */
|
|
562
|
+
registryKey?: string;
|
|
517
563
|
/** The input data to pass to the actor. */
|
|
518
564
|
input?: InputFrom<TLogic>;
|
|
519
565
|
/**
|
|
@@ -667,6 +713,10 @@ export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends Ev
|
|
|
667
713
|
type: TType;
|
|
668
714
|
})) => void) => Subscription;
|
|
669
715
|
}
|
|
716
|
+
type EventPayload<TEvent extends EventObject, TType extends TEvent['type']> = HomomorphicOmit<ExtractEvent<TEvent, TType>, 'type'>;
|
|
717
|
+
export type ActorTrigger<TEvent extends EventObject> = {
|
|
718
|
+
[K in TEvent['type']]: {} extends EventPayload<TEvent, K> ? () => void : (payload: EventPayload<TEvent, K>) => void;
|
|
719
|
+
};
|
|
670
720
|
/**
|
|
671
721
|
* Runtime-only actor capabilities.
|
|
672
722
|
*
|
|
@@ -675,7 +725,7 @@ export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends Ev
|
|
|
675
725
|
* genuinely need lifecycle control such as starting, stopping, or accessing
|
|
676
726
|
* system-owned runtime state.
|
|
677
727
|
*/
|
|
678
|
-
export interface ActorRuntime<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, _TEmitted extends EventObject = EventObject> {
|
|
728
|
+
export interface ActorRuntime<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, _TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> {
|
|
679
729
|
/** The unique identifier for this actor relative to its parent. */
|
|
680
730
|
id: string;
|
|
681
731
|
/**
|
|
@@ -692,7 +742,7 @@ export interface ActorRuntime<TSnapshot extends Snapshot<unknown>, TEvent extend
|
|
|
692
742
|
_parent?: any;
|
|
693
743
|
system: any;
|
|
694
744
|
src: string | AnyActorLogic;
|
|
695
|
-
trigger:
|
|
745
|
+
trigger: ActorTrigger<TSendEvent>;
|
|
696
746
|
select<TSelected>(selector: (snapshot: TSnapshot) => TSelected, equalityFn?: (a: TSelected, b: TSelected) => boolean): Readable<TSelected>;
|
|
697
747
|
}
|
|
698
748
|
/**
|
|
@@ -702,7 +752,7 @@ export interface ActorRuntime<TSnapshot extends Snapshot<unknown>, TEvent extend
|
|
|
702
752
|
* lifecycle capabilities. Values returned by `createActor(...)` and
|
|
703
753
|
* `spawn(...)` naturally satisfy narrower `ActorRef` contracts.
|
|
704
754
|
*/
|
|
705
|
-
export interface ActorInstance<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> extends ActorRuntime<TSnapshot, TEvent, TEmitted>, ActorRef<TSnapshot, TEvent, TEmitted, TSendEvent> {
|
|
755
|
+
export interface ActorInstance<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> extends ActorRuntime<TSnapshot, TEvent, TEmitted, TSendEvent>, ActorRef<TSnapshot, TEvent, TEmitted, TSendEvent> {
|
|
706
756
|
}
|
|
707
757
|
/**
|
|
708
758
|
* The actor's own full self handle.
|
|
@@ -711,15 +761,20 @@ export interface ActorInstance<TSnapshot extends Snapshot<unknown>, TEvent exten
|
|
|
711
761
|
* can participate in runtime-owned behavior while still being usable wherever
|
|
712
762
|
* an `ActorRef` is expected.
|
|
713
763
|
*/
|
|
714
|
-
export type ActorSelf<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> = ActorRuntime<TSnapshot, TEvent, TEmitted> & ActorRef<TSnapshot, TEvent, TEmitted, TSendEvent>;
|
|
764
|
+
export type ActorSelf<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject, TSendEvent extends EventObject = TEvent> = ActorRuntime<TSnapshot, TEvent, TEmitted, TSendEvent> & ActorRef<TSnapshot, TEvent, TEmitted, TSendEvent>;
|
|
715
765
|
export type ActorRefFrom<T> = T extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer TEmitted, infer TMeta, infer TConfig, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TConfig extends {
|
|
716
766
|
internalEvents?: readonly EventDescriptor<TEvent>[];
|
|
717
767
|
} ? ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, any>, TEvent, TEmitted, ExcludeInternalEvents<TEvent, TConfig['internalEvents'] extends readonly EventDescriptor<TEvent>[] ? TConfig['internalEvents'] extends readonly (infer TDesc)[] ? Extract<TDesc, string> : never : never>> : ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, any>, TEvent, TEmitted> : T extends Promise<infer U> ? ActorRefFrom<AsyncActorLogic<U>> : T extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? ActorRef<TSnapshot, TEvent, TEmitted> : never;
|
|
718
768
|
export type SendableEventFromLogic<TLogic extends AnyActorLogic> = TLogic extends StateMachine<infer _TContext, infer TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer TConfig, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TConfig extends {
|
|
719
769
|
internalEvents?: readonly EventDescriptor<TEvent>[];
|
|
720
770
|
} ? ExcludeInternalEvents<TEvent, TConfig['internalEvents'] extends readonly EventDescriptor<TEvent>[] ? TConfig['internalEvents'] extends readonly (infer TDesc)[] ? Extract<TDesc, string> : never : never> : TEvent : EventFromLogic<TLogic>;
|
|
721
|
-
|
|
722
|
-
export type
|
|
771
|
+
type OpaqueMachineSnapshot<TSnapshot extends Snapshot<unknown>> = TSnapshot extends MachineSnapshot<infer TContext, infer TEvent, infer TChildren, infer TStateValue, infer TTag, infer TOutput, infer TMeta, infer _TStateSchema> ? MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, any> : TSnapshot;
|
|
772
|
+
export type ActorRefFromLogic<T extends AnyActorLogic> = ActorRef<OpaqueMachineSnapshot<SnapshotFrom<T>>, EventFromLogic<T>, EmittedFrom<T>, SendableEventFromLogic<T>>;
|
|
773
|
+
export interface AnyActorRef extends Subscribable<any>, InteropObservable<any> {
|
|
774
|
+
send(event: any): void;
|
|
775
|
+
getSnapshot(): any;
|
|
776
|
+
on(type: string, handler: (emitted: any) => void): Subscription;
|
|
777
|
+
}
|
|
723
778
|
/** The concrete actor instance type produced from actor logic. */
|
|
724
779
|
export type ActorFromLogic<T extends AnyActorLogic> = ActorInstance<SnapshotFrom<T>, EventFromLogic<T>, EmittedFrom<T>, SendableEventFromLogic<T>>;
|
|
725
780
|
type SendableEventFromActorRef<TActorRef, TFallback extends EventObject = AnyEventObject> = [NonNullable<TActorRef>] extends [never] ? TFallback : NonNullable<TActorRef> extends infer TNonNullableActorRef ? TNonNullableActorRef extends {
|
|
@@ -730,7 +785,7 @@ export type UnknownActorRef = ActorRef<Snapshot<unknown>, EventObject>;
|
|
|
730
785
|
export type DevToolsAdapter = (service: AnyActor) => void;
|
|
731
786
|
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TConfig, infer TActionMap, infer TActorMap, infer TGuardMap, infer TDelayMap> ? {
|
|
732
787
|
actions: TActionMap;
|
|
733
|
-
|
|
788
|
+
actorSources: TActorMap;
|
|
734
789
|
guards: TGuardMap;
|
|
735
790
|
delays: TDelayMap;
|
|
736
791
|
} : never;
|
|
@@ -767,6 +822,7 @@ export type Snapshot<TOutput> = {
|
|
|
767
822
|
output: undefined;
|
|
768
823
|
error: undefined;
|
|
769
824
|
};
|
|
825
|
+
export type ActorLogicTransitionResult<TSnapshot extends Snapshot<unknown>, TEffect = unknown> = [nextSnapshot: TSnapshot, effects: TEffect[]];
|
|
770
826
|
/**
|
|
771
827
|
* Represents logic which can be used by an actor.
|
|
772
828
|
*
|
|
@@ -782,14 +838,22 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
|
|
|
782
838
|
config?: unknown;
|
|
783
839
|
/**
|
|
784
840
|
* Transition function that processes the current state and an incoming event
|
|
785
|
-
* to produce a new state.
|
|
841
|
+
* to produce a new state and effects.
|
|
786
842
|
*
|
|
787
843
|
* @param snapshot - The current state.
|
|
788
844
|
* @param event - The incoming event.
|
|
789
845
|
* @param actorScope - The actor scope.
|
|
790
|
-
* @returns
|
|
846
|
+
* @returns A tuple of the next state and effects.
|
|
847
|
+
*/
|
|
848
|
+
transition: (snapshot: TSnapshot, event: TEvent, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => ActorLogicTransitionResult<TSnapshot>;
|
|
849
|
+
/**
|
|
850
|
+
* Transition function that produces the initial state and effects.
|
|
851
|
+
*
|
|
852
|
+
* @param actorScope - The actor scope.
|
|
853
|
+
* @param input - The input for the initial state.
|
|
854
|
+
* @returns A tuple of the initial state and effects.
|
|
791
855
|
*/
|
|
792
|
-
|
|
856
|
+
initialTransition: (input: TInput, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => ActorLogicTransitionResult<TSnapshot>;
|
|
793
857
|
/**
|
|
794
858
|
* Called to provide the initial state of the actor.
|
|
795
859
|
*
|
|
@@ -823,19 +887,37 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
|
|
|
823
887
|
* @returns The a representation of the internal state to be persisted.
|
|
824
888
|
*/
|
|
825
889
|
getPersistedSnapshot: (snapshot: TSnapshot, options?: unknown) => Snapshot<unknown>;
|
|
890
|
+
/**
|
|
891
|
+
* Executes the non-action effects returned from `transition` (e.g. the
|
|
892
|
+
* effects produced by `createLogic`-based actors). Actor logic that never
|
|
893
|
+
* returns such effects can omit this.
|
|
894
|
+
*/
|
|
895
|
+
executeEffects?: (effects: readonly unknown[], actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => void;
|
|
896
|
+
/**
|
|
897
|
+
* Returns an event that the actor should transition with to recover from an
|
|
898
|
+
* execution error, or `undefined` if the given snapshot cannot handle it.
|
|
899
|
+
* Actor logic without error-recovery semantics can omit this.
|
|
900
|
+
*/
|
|
901
|
+
getExecutionErrorEvent?: (snapshot: TSnapshot, error: unknown) => TEvent | undefined;
|
|
902
|
+
}
|
|
903
|
+
export interface AnyActorLogic {
|
|
904
|
+
config?: unknown;
|
|
905
|
+
transition(snapshot: any, event: any, actorScope: any): ActorLogicTransitionResult<any>;
|
|
906
|
+
initialTransition(input: any, actorScope: any): ActorLogicTransitionResult<any>;
|
|
907
|
+
getInitialSnapshot(actorScope: any, input: any): any;
|
|
908
|
+
restoreSnapshot?(persistedState: Snapshot<unknown>, actorScope: any): any;
|
|
909
|
+
start?(snapshot: any, actorScope: any): void;
|
|
910
|
+
getPersistedSnapshot(snapshot: any, options?: unknown): Snapshot<unknown>;
|
|
911
|
+
executeEffects?(effects: readonly unknown[], actorScope: any): void;
|
|
912
|
+
getExecutionErrorEvent?(snapshot: any, error: unknown): any;
|
|
826
913
|
}
|
|
827
|
-
export type AnyActorLogic = ActorLogic<any, // snapshot
|
|
828
|
-
any, // event
|
|
829
|
-
any, // input
|
|
830
|
-
any, // system
|
|
831
|
-
any>;
|
|
832
914
|
export type UnknownActorLogic = ActorLogic<any, // snapshot
|
|
833
915
|
any, // event
|
|
834
916
|
any, // input
|
|
835
917
|
AnyActorSystem, any>;
|
|
836
|
-
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer TSnapshot, infer _, infer __> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends ActorLogic<infer
|
|
837
|
-
export type EventFromLogic<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer TEvent, infer _TInput, infer
|
|
838
|
-
export type EmittedFrom<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? TEmitted :
|
|
918
|
+
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer TSnapshot, infer _, infer __> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? TSnapshot : R extends ActorScope<infer TSnapshot, infer _TEvent, infer _TEmitted, infer _TSystem> ? TSnapshot : never : never;
|
|
919
|
+
export type EventFromLogic<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? TEvent : never;
|
|
920
|
+
export type EmittedFrom<TLogic extends AnyActorLogic> = TLogic extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer TEmitted, infer _TMeta, infer _TStateSchema, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TEmitted : [TLogic] extends [AnyStateMachine] ? AnyEventObject : TLogic extends ActorLogic<infer _TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? TEmitted : AnyEventObject;
|
|
839
921
|
type ResolveEventType<T> = T extends infer R ? R extends StateMachine<infer _TContext, infer TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TConfig, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput, infer _TMeta, infer _TStateSchema> ? TEvent : R extends ActorRef<infer _TSnapshot, infer TEvent, infer _TEmitted> ? TEvent : never : never;
|
|
840
922
|
export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
|
|
841
923
|
export type ContextFrom<T> = T extends StateMachine<infer TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TConfig, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TContext : T extends MachineSnapshot<infer TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput, infer _TMeta, infer _TStateSchema> ? TContext : T extends Actor<infer TActorLogic> ? TActorLogic extends AnyStateMachine ? ContextFrom<TActorLogic> : never : never;
|
|
@@ -852,6 +934,10 @@ export type TagsFrom<TMachine extends AnyStateMachine> = Parameters<StateFrom<TM
|
|
|
852
934
|
export interface ActorSystemInfo {
|
|
853
935
|
actors: Record<string, AnyActorRef>;
|
|
854
936
|
}
|
|
937
|
+
export type SystemRegistry = Record<string, AnyActorLogic>;
|
|
938
|
+
export type RegistryKeyForLogic<TLogic extends AnyActorLogic, TSystemRegistry extends SystemRegistry> = string extends keyof TSystemRegistry ? string : Values<{
|
|
939
|
+
[K in keyof TSystemRegistry & string]: ActorRefFromLogic<TLogic> extends ActorRefFromLogic<TSystemRegistry[K]> ? K : never;
|
|
940
|
+
}>;
|
|
855
941
|
export type RequiredActorOptions<TActor extends ProvidedActor> = (undefined extends TActor['id'] ? never : 'id') | (undefined extends InputFrom<TActor['logic']> ? never : 'input');
|
|
856
942
|
export type RequiredLogicInput<TLogic extends AnyActorLogic> = undefined extends InputFrom<TLogic> ? never : 'input';
|
|
857
943
|
type ExtractLiteralString<T extends string | undefined> = T extends string ? string extends T ? never : T : never;
|
|
@@ -877,6 +963,9 @@ export type StateSchema = {
|
|
|
877
963
|
entry?: unknown;
|
|
878
964
|
exit?: unknown;
|
|
879
965
|
onDone?: unknown;
|
|
966
|
+
onError?: unknown;
|
|
967
|
+
timeout?: unknown;
|
|
968
|
+
onTimeout?: unknown;
|
|
880
969
|
after?: unknown;
|
|
881
970
|
always?: unknown;
|
|
882
971
|
choice?: unknown;
|
|
@@ -914,7 +1003,7 @@ export type RoutableStateId<TSchema extends StateSchema> = (TSchema extends {
|
|
|
914
1003
|
export interface StateMachineTypes {
|
|
915
1004
|
context: MachineContext;
|
|
916
1005
|
events: EventObject;
|
|
917
|
-
|
|
1006
|
+
actorSources: ProvidedActor;
|
|
918
1007
|
actions: ParameterizedObject;
|
|
919
1008
|
guards: ParameterizedObject;
|
|
920
1009
|
delays: string;
|
|
@@ -925,7 +1014,7 @@ export interface StateMachineTypes {
|
|
|
925
1014
|
export interface ResolvedStateMachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TEmitted extends EventObject = EventObject> {
|
|
926
1015
|
context: TContext;
|
|
927
1016
|
events: TEvent;
|
|
928
|
-
|
|
1017
|
+
actorSources: TActor;
|
|
929
1018
|
actions: TAction;
|
|
930
1019
|
guards: TGuard;
|
|
931
1020
|
delays: TDelay;
|
|
@@ -937,7 +1026,9 @@ type _GroupStateKeys<T extends StateSchema, S extends keyof T['states']> = S ext
|
|
|
937
1026
|
type: 'history';
|
|
938
1027
|
} ? [never, never] : T extends {
|
|
939
1028
|
type: 'parallel';
|
|
940
|
-
} ? [S, never] :
|
|
1029
|
+
} ? [S, never] : T['states'][S] extends {
|
|
1030
|
+
states: Record<string, StateSchema>;
|
|
1031
|
+
} ? [S, never] : [never, S] : never;
|
|
941
1032
|
type GroupStateKeys<T extends StateSchema, S extends keyof T['states']> = {
|
|
942
1033
|
nonLeaf: _GroupStateKeys<T, S & string>[0];
|
|
943
1034
|
leaf: _GroupStateKeys<T, S & string>[1];
|
|
@@ -953,19 +1044,68 @@ export type ToStateValue<T extends StateSchema> = T extends {
|
|
|
953
1044
|
[StateKey in K]: ToStateValue<T['states'][K]>;
|
|
954
1045
|
};
|
|
955
1046
|
}>> : never) : {};
|
|
956
|
-
export interface
|
|
957
|
-
type: string & {};
|
|
1047
|
+
export interface BaseExecutableActionObject {
|
|
958
1048
|
params: NonReducibleUnknown;
|
|
959
1049
|
args: unknown[];
|
|
960
1050
|
exec: (() => void) | undefined;
|
|
961
1051
|
}
|
|
962
|
-
export
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1052
|
+
export interface CustomExecutableActionObject<TType extends string = string & {}> extends BaseExecutableActionObject {
|
|
1053
|
+
type: TType;
|
|
1054
|
+
}
|
|
1055
|
+
export interface SpawnExecutableActionObject extends BaseExecutableActionObject {
|
|
1056
|
+
type: '@xstate.spawn';
|
|
1057
|
+
actor: AnyActor;
|
|
1058
|
+
id: string;
|
|
1059
|
+
logic: AnyActorLogic;
|
|
1060
|
+
src: string | AnyActorLogic;
|
|
1061
|
+
input: unknown;
|
|
1062
|
+
args: Parameters<(typeof builtInActions)['@xstate.spawn']>;
|
|
1063
|
+
}
|
|
1064
|
+
export interface StartExecutableActionObject extends BaseExecutableActionObject {
|
|
1065
|
+
type: '@xstate.start';
|
|
1066
|
+
actor: AnyActor;
|
|
1067
|
+
id: string;
|
|
1068
|
+
args: Parameters<(typeof builtInActions)['@xstate.start']>;
|
|
1069
|
+
}
|
|
1070
|
+
export interface RaiseExecutableActionObject extends BaseExecutableActionObject {
|
|
1071
|
+
type: '@xstate.raise';
|
|
1072
|
+
event: EventObject;
|
|
1073
|
+
id: string | undefined;
|
|
1074
|
+
delay: number | undefined;
|
|
1075
|
+
args: Parameters<(typeof builtInActions)['@xstate.raise']>;
|
|
1076
|
+
}
|
|
1077
|
+
export interface SendToExecutableActionObject extends BaseExecutableActionObject {
|
|
1078
|
+
type: '@xstate.sendTo';
|
|
1079
|
+
target: AnyActor;
|
|
1080
|
+
event: EventObject;
|
|
1081
|
+
id: string | undefined;
|
|
1082
|
+
delay: number | undefined;
|
|
1083
|
+
args: Parameters<(typeof builtInActions)['@xstate.sendTo']>;
|
|
1084
|
+
}
|
|
1085
|
+
export interface CancelExecutableActionObject extends BaseExecutableActionObject {
|
|
1086
|
+
type: '@xstate.cancel';
|
|
1087
|
+
id: string;
|
|
1088
|
+
args: Parameters<(typeof builtInActions)['@xstate.cancel']>;
|
|
1089
|
+
}
|
|
1090
|
+
export interface StopExecutableActionObject extends BaseExecutableActionObject {
|
|
1091
|
+
type: '@xstate.stop';
|
|
1092
|
+
actor: AnyActor;
|
|
1093
|
+
args: Parameters<(typeof builtInActions)['@xstate.stop']>;
|
|
1094
|
+
}
|
|
1095
|
+
export type BuiltInExecutableActionObject = Values<{
|
|
1096
|
+
'@xstate.spawn': SpawnExecutableActionObject;
|
|
1097
|
+
'@xstate.start': StartExecutableActionObject;
|
|
1098
|
+
'@xstate.raise': RaiseExecutableActionObject;
|
|
1099
|
+
'@xstate.sendTo': SendToExecutableActionObject;
|
|
1100
|
+
'@xstate.cancel': CancelExecutableActionObject;
|
|
1101
|
+
'@xstate.stop': StopExecutableActionObject;
|
|
967
1102
|
}>;
|
|
968
|
-
export
|
|
1103
|
+
export type SpecialExecutableAction = BuiltInExecutableActionObject;
|
|
1104
|
+
type TransitionExecutableActionObject<TType extends string = never> = BuiltInExecutableActionObject | CustomExecutableActionObject<TType | (string & {})>;
|
|
1105
|
+
type KnownImplementationKeys<TImplementationMap> = string extends keyof TImplementationMap ? never : Extract<keyof TImplementationMap, string>;
|
|
1106
|
+
export type ExecutableActionObjectFromLogic<T extends AnyActorLogic> = T extends StateMachine<any, any, any, any, any, any, any, any, any, any, infer TActionMap, any, any, any> ? TransitionExecutableActionObject<KnownImplementationKeys<TActionMap>> : ExecutableActionObject;
|
|
1107
|
+
export type ExecutableActionObject<TType extends string = string & {}> = BuiltInExecutableActionObject | CustomExecutableActionObject<TType>;
|
|
1108
|
+
export interface ToExecutableAction<T extends ParameterizedObject> extends CustomExecutableActionObject<T['type']> {
|
|
969
1109
|
type: T['type'];
|
|
970
1110
|
params: T['params'];
|
|
971
1111
|
exec: undefined;
|
|
@@ -977,7 +1117,7 @@ export interface SubscribeToMappers<TSnapshot extends Snapshot<unknown>, TOutput
|
|
|
977
1117
|
done?: (output: TOutput) => TMappedEvent;
|
|
978
1118
|
error?: (error: unknown) => TMappedEvent;
|
|
979
1119
|
}
|
|
980
|
-
export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends EventObject> = {
|
|
1120
|
+
export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends EventObject, TSystemRegistry extends SystemRegistry = SystemRegistry> = {
|
|
981
1121
|
cancel: (id: string) => void;
|
|
982
1122
|
raise: (ev: TEvent, options?: {
|
|
983
1123
|
id?: string;
|
|
@@ -987,7 +1127,7 @@ export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends Even
|
|
|
987
1127
|
input?: InputFrom<T>;
|
|
988
1128
|
id?: string;
|
|
989
1129
|
syncSnapshot?: boolean;
|
|
990
|
-
|
|
1130
|
+
registryKey?: RegistryKeyForLogic<T, TSystemRegistry>;
|
|
991
1131
|
}) => ActorFromLogic<T>;
|
|
992
1132
|
emit: (emittedEvent: TEmittedEvent) => void;
|
|
993
1133
|
<T extends (...args: any[]) => any>(fn: T, ...args: Parameters<T>): void;
|
|
@@ -1017,30 +1157,25 @@ export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends Even
|
|
|
1017
1157
|
* @param mappers - Object with done/error/snapshot mappers, or a single
|
|
1018
1158
|
* snapshot mapper function
|
|
1019
1159
|
*/
|
|
1020
|
-
subscribeTo:
|
|
1021
|
-
<TSnapshot extends Snapshot<unknown>, TOutput, TMappedEvent extends TEvent>(actor: AnyActor, mappers: SubscribeToMappers<TSnapshot, TOutput, TMappedEvent> | ((snapshot: TSnapshot) => TMappedEvent)): AnyActor;
|
|
1022
|
-
<TValue, TMappedEvent extends TEvent>(atom: BaseAtom<TValue>, mappers: {
|
|
1023
|
-
snapshot?: (value: TValue) => TMappedEvent;
|
|
1024
|
-
} | ((value: TValue) => TMappedEvent)): AnyActor;
|
|
1025
|
-
};
|
|
1160
|
+
subscribeTo: <TActor extends AnyActor, TMappedEvent extends TEvent>(actor: TActor, mappers: SubscribeToMappers<SnapshotFrom<TActor>, OutputFrom<TActor>, TMappedEvent> | ((snapshot: SnapshotFrom<TActor>) => TMappedEvent)) => AnyActor;
|
|
1026
1161
|
};
|
|
1027
|
-
export type Action<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
1162
|
+
export type Action<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TParams = Record<string, unknown> | undefined, _TCtx = [TContext] extends [never] ? any : TContext> = (_: {
|
|
1028
1163
|
context: _TCtx;
|
|
1029
1164
|
event: TEvent;
|
|
1030
1165
|
parent: AnyActorRef | undefined;
|
|
1031
1166
|
self: ActorSelf<MachineSnapshot<_TCtx & MachineContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO>, TEvent>;
|
|
1032
1167
|
children: Record<string, AnyActor | undefined>;
|
|
1033
1168
|
actions: TActionMap;
|
|
1034
|
-
|
|
1169
|
+
actorSources: TActorMap;
|
|
1035
1170
|
guards: TGuardMap;
|
|
1036
1171
|
delays: TDelayMap;
|
|
1037
1172
|
system?: AnyActorSystem;
|
|
1038
1173
|
params: TParams;
|
|
1039
1174
|
}, enqueue: EnqueueObject<TEvent, TEmittedEvent>) => {
|
|
1040
|
-
context?: _TCtx
|
|
1175
|
+
context?: Partial<_TCtx>;
|
|
1041
1176
|
children?: Record<string, AnyActor | undefined>;
|
|
1042
1177
|
} | void;
|
|
1043
|
-
export type AnyAction = Action<MachineContext, EventObject, EventObject, Implementations['actions'], Implementations['
|
|
1178
|
+
export type AnyAction = Action<MachineContext, EventObject, EventObject, Implementations['actions'], Implementations['actorSources'], Implementations['guards'], Implementations['delays']> | {
|
|
1044
1179
|
action: (...args: any[]) => any;
|
|
1045
1180
|
args: any[];
|
|
1046
1181
|
} | AnyEventObject;
|