xstate 5.13.2 → 5.15.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/actions/dist/xstate-actions.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.cjs.js +2 -2
- package/actions/dist/xstate-actions.development.esm.js +2 -2
- package/actions/dist/xstate-actions.esm.js +2 -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.js +289 -79
- package/actors/dist/xstate-actors.development.cjs.js +289 -79
- package/actors/dist/xstate-actors.development.esm.js +289 -79
- package/actors/dist/xstate-actors.esm.js +289 -79
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +21 -25
- package/dist/declarations/src/StateMachine.d.ts +18 -30
- package/dist/declarations/src/StateNode.d.ts +29 -51
- package/dist/declarations/src/actions/assign.d.ts +29 -27
- package/dist/declarations/src/actions/cancel.d.ts +28 -22
- package/dist/declarations/src/actions/emit.d.ts +33 -33
- package/dist/declarations/src/actions/enqueueActions.d.ts +18 -16
- package/dist/declarations/src/actions/log.d.ts +5 -4
- package/dist/declarations/src/actions/send.d.ts +5 -3
- package/dist/declarations/src/actors/callback.d.ts +69 -29
- package/dist/declarations/src/actors/index.d.ts +4 -4
- package/dist/declarations/src/actors/observable.d.ts +74 -29
- package/dist/declarations/src/actors/promise.d.ts +91 -13
- package/dist/declarations/src/actors/transition.d.ts +90 -16
- package/dist/declarations/src/assert.d.ts +21 -20
- package/dist/declarations/src/createActor.d.ts +51 -42
- package/dist/declarations/src/createMachine.d.ts +40 -54
- package/dist/declarations/src/getNextSnapshot.d.ts +27 -24
- package/dist/declarations/src/guards.d.ts +67 -66
- package/dist/declarations/src/index.d.ts +0 -1
- package/dist/declarations/src/inspection.d.ts +1 -0
- package/dist/declarations/src/setup.d.ts +1 -2
- package/dist/declarations/src/spawn.d.ts +2 -5
- package/dist/declarations/src/stateUtils.d.ts +5 -10
- package/dist/declarations/src/system.d.ts +2 -2
- package/dist/declarations/src/toPromise.d.ts +1 -0
- package/dist/declarations/src/types.d.ts +169 -192
- package/dist/declarations/src/waitFor.d.ts +9 -9
- package/dist/{log-c447a931.esm.js → log-63de2429.esm.js} +112 -117
- package/dist/{log-5b14d850.cjs.js → log-b8c93ee3.cjs.js} +112 -117
- package/dist/{log-d06dd00b.development.cjs.js → log-d2c282d6.development.cjs.js} +112 -117
- package/dist/{log-b3b03961.development.esm.js → log-e9953143.development.esm.js} +112 -117
- package/dist/{raise-f406edbd.esm.js → raise-2cfe6b8f.esm.js} +302 -284
- package/dist/{raise-150d5679.development.esm.js → raise-7d030497.development.esm.js} +302 -284
- package/dist/{raise-ff8990f7.cjs.js → raise-a6298350.cjs.js} +302 -284
- package/dist/{raise-bf7a8462.development.cjs.js → raise-bad6a97b.development.cjs.js} +302 -284
- package/dist/xstate.cjs.js +134 -157
- package/dist/xstate.development.cjs.js +134 -157
- package/dist/xstate.development.esm.js +136 -159
- package/dist/xstate.esm.js +136 -159
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/declarations/src/typegenTypes.d.ts +0 -168
|
@@ -8,7 +8,6 @@ import type { Actor } from "./createActor.js";
|
|
|
8
8
|
import { Spawner } from "./spawn.js";
|
|
9
9
|
import { AnyActorSystem, Clock } from './system.js';
|
|
10
10
|
import { InspectionEvent } from "./inspection.js";
|
|
11
|
-
import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from "./typegenTypes.js";
|
|
12
11
|
export type Identity<T> = {
|
|
13
12
|
[K in keyof T]: T[K];
|
|
14
13
|
};
|
|
@@ -23,18 +22,20 @@ export type Invert<T extends Record<PropertyKey, PropertyKey>> = {
|
|
|
23
22
|
};
|
|
24
23
|
export type GetParameterizedParams<T extends ParameterizedObject | undefined> = T extends any ? ('params' extends keyof T ? T['params'] : undefined) : never;
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
27
25
|
* @remarks
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
26
|
+
* `T | unknown` reduces to `unknown` and that can be problematic when it comes
|
|
27
|
+
* to contextual typing. It especially is a problem when the union has a
|
|
28
|
+
* function member, like here:
|
|
31
29
|
*
|
|
32
30
|
* ```ts
|
|
33
|
-
* declare function test(
|
|
34
|
-
*
|
|
31
|
+
* declare function test(
|
|
32
|
+
* cbOrVal: ((arg: number) => unknown) | unknown
|
|
33
|
+
* ): void;
|
|
34
|
+
* test((arg) => {}); // oops, implicit any
|
|
35
35
|
* ```
|
|
36
36
|
*
|
|
37
|
-
* This type can be used to avoid this problem. This union represents the same
|
|
37
|
+
* This type can be used to avoid this problem. This union represents the same
|
|
38
|
+
* value space as `unknown`.
|
|
38
39
|
*/
|
|
39
40
|
export type NonReducibleUnknown = {} | null | undefined;
|
|
40
41
|
export type AnyFunction = (...args: any[]) => any;
|
|
@@ -58,21 +59,15 @@ export type Equals<A1 extends any, A2 extends any> = (<A>() => A extends A2 ? tr
|
|
|
58
59
|
export type IsAny<T> = Equals<T, any>;
|
|
59
60
|
export type Cast<A, B> = A extends B ? A : B;
|
|
60
61
|
export type DoNotInfer<T> = [T][T extends any ? 0 : any];
|
|
61
|
-
/**
|
|
62
|
-
* @deprecated Use the built-in `NoInfer` type instead
|
|
63
|
-
*/
|
|
62
|
+
/** @deprecated Use the built-in `NoInfer` type instead */
|
|
64
63
|
export type NoInfer<T> = DoNotInfer<T>;
|
|
65
64
|
export type LowInfer<T> = T & {};
|
|
66
65
|
export type MetaObject = Record<string, any>;
|
|
67
66
|
export type Lazy<T> = () => T;
|
|
68
67
|
export type MaybeLazy<T> = T | Lazy<T>;
|
|
69
|
-
/**
|
|
70
|
-
* The full definition of an event, with a string `type`.
|
|
71
|
-
*/
|
|
68
|
+
/** The full definition of an event, with a string `type`. */
|
|
72
69
|
export type EventObject = {
|
|
73
|
-
/**
|
|
74
|
-
* The type of event that is sent.
|
|
75
|
-
*/
|
|
70
|
+
/** The type of event that is sent. */
|
|
76
71
|
type: string;
|
|
77
72
|
};
|
|
78
73
|
export interface AnyEventObject extends EventObject {
|
|
@@ -92,7 +87,7 @@ export interface UnifiedArg<TContext extends MachineContext, TExpressionEvent ex
|
|
|
92
87
|
export type MachineContext = Record<string, any>;
|
|
93
88
|
export interface ActionArgs<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> extends UnifiedArg<TContext, TExpressionEvent, TEvent> {
|
|
94
89
|
}
|
|
95
|
-
export type InputFrom<T> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer TInput, infer _TOutput, infer _TEmitted, infer _TMeta
|
|
90
|
+
export type InputFrom<T> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer TInput, infer _TOutput, infer _TEmitted, infer _TMeta> ? TInput : T extends ActorLogic<infer _TSnapshot, infer _TEvent, infer TInput, infer _TSystem, infer _TEmitted> ? TInput : never;
|
|
96
91
|
export type OutputFrom<T> = T extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? (TSnapshot & {
|
|
97
92
|
status: 'done';
|
|
98
93
|
})['output'] : T extends ActorRef<infer TSnapshot, infer _TEvent, infer _TEmitted> ? (TSnapshot & {
|
|
@@ -124,13 +119,13 @@ export interface StateValueMap {
|
|
|
124
119
|
[key: string]: StateValue | undefined;
|
|
125
120
|
}
|
|
126
121
|
/**
|
|
127
|
-
* The string or object representing the state value relative to the parent
|
|
122
|
+
* The string or object representing the state value relative to the parent
|
|
123
|
+
* state node.
|
|
128
124
|
*
|
|
129
125
|
* @remarks
|
|
130
|
-
*
|
|
131
126
|
* - For a child atomic state node, this is a string, e.g., `"pending"`.
|
|
132
|
-
*
|
|
133
|
-
*
|
|
127
|
+
* - For complex state nodes, this is an object, e.g., `{ success:
|
|
128
|
+
* "someChildState" }`.
|
|
134
129
|
*/
|
|
135
130
|
export type StateValue = string | StateValueMap;
|
|
136
131
|
export type TransitionTarget = SingleOrArray<string>;
|
|
@@ -158,17 +153,17 @@ any>;
|
|
|
158
153
|
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TEmitted extends EventObject, TMeta extends MetaObject> {
|
|
159
154
|
id: string;
|
|
160
155
|
systemId: string | undefined;
|
|
161
|
-
/**
|
|
162
|
-
* The source of the actor logic to be invoked
|
|
163
|
-
*/
|
|
156
|
+
/** The source of the actor logic to be invoked */
|
|
164
157
|
src: AnyActorLogic | string;
|
|
165
158
|
input?: Mapper<TContext, TEvent, NonReducibleUnknown, TEvent> | NonReducibleUnknown;
|
|
166
159
|
/**
|
|
167
|
-
* The transition to take upon the invoked child machine reaching its final
|
|
160
|
+
* The transition to take upon the invoked child machine reaching its final
|
|
161
|
+
* top-level state.
|
|
168
162
|
*/
|
|
169
163
|
onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneActorEvent<unknown>, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
170
164
|
/**
|
|
171
|
-
* The transition to take upon the invoked child machine sending an error
|
|
165
|
+
* The transition to take upon the invoked child machine sending an error
|
|
166
|
+
* event.
|
|
172
167
|
*/
|
|
173
168
|
onError?: string | SingleOrArray<TransitionConfig<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
174
169
|
onSnapshot?: string | SingleOrArray<TransitionConfig<TContext, SnapshotEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
@@ -203,22 +198,22 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
203
198
|
src: infer TSrc;
|
|
204
199
|
} ? Compute<{
|
|
205
200
|
systemId?: string;
|
|
206
|
-
/**
|
|
207
|
-
* The source of the machine to be invoked, or the machine itself.
|
|
208
|
-
*/
|
|
201
|
+
/** The source of the machine to be invoked, or the machine itself. */
|
|
209
202
|
src: TSrc;
|
|
210
203
|
/**
|
|
211
|
-
* The unique identifier for the invoked machine. If not specified,
|
|
212
|
-
* will be the machine's own `id`, or the URL (from `src`).
|
|
204
|
+
* The unique identifier for the invoked machine. If not specified,
|
|
205
|
+
* this will be the machine's own `id`, or the URL (from `src`).
|
|
213
206
|
*/
|
|
214
207
|
id?: TSpecificActor['id'];
|
|
215
208
|
input?: Mapper<TContext, TEvent, InputFrom<TSpecificActor['logic']>, TEvent> | InputFrom<TSpecificActor['logic']>;
|
|
216
209
|
/**
|
|
217
|
-
* The transition to take upon the invoked child machine reaching
|
|
210
|
+
* The transition to take upon the invoked child machine reaching
|
|
211
|
+
* its final top-level state.
|
|
218
212
|
*/
|
|
219
213
|
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<OutputFrom<TSpecificActor['logic']>>, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
220
214
|
/**
|
|
221
|
-
* The transition to take upon the invoked child machine sending an
|
|
215
|
+
* The transition to take upon the invoked child machine sending an
|
|
216
|
+
* error event.
|
|
222
217
|
*/
|
|
223
218
|
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
224
219
|
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent<SnapshotFrom<TSpecificActor['logic']>>, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
@@ -240,111 +235,108 @@ export type InvokeConfig<TContext extends MachineContext, TEvent extends EventOb
|
|
|
240
235
|
*/
|
|
241
236
|
id?: string;
|
|
242
237
|
systemId?: string;
|
|
243
|
-
/**
|
|
244
|
-
* The source of the machine to be invoked, or the machine itself.
|
|
245
|
-
*/
|
|
238
|
+
/** The source of the machine to be invoked, or the machine itself. */
|
|
246
239
|
src: AnyActorLogic | string;
|
|
247
240
|
input?: Mapper<TContext, TEvent, NonReducibleUnknown, TEvent> | NonReducibleUnknown;
|
|
248
241
|
/**
|
|
249
|
-
* The transition to take upon the invoked child machine reaching its
|
|
242
|
+
* The transition to take upon the invoked child machine reaching its
|
|
243
|
+
* final top-level state.
|
|
250
244
|
*/
|
|
251
245
|
onDone?: string | SingleOrArray<TransitionConfigOrTarget<TContext, DoneActorEvent<any>, // TODO: consider replacing with `unknown`
|
|
252
246
|
TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
253
247
|
/**
|
|
254
|
-
* The transition to take upon the invoked child machine sending an error
|
|
248
|
+
* The transition to take upon the invoked child machine sending an error
|
|
249
|
+
* event.
|
|
255
250
|
*/
|
|
256
251
|
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
257
252
|
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
258
253
|
};
|
|
259
254
|
export type AnyInvokeConfig = InvokeConfig<any, any, any, any, any, any, any, any>;
|
|
260
255
|
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, TEmitted extends EventObject, TMeta extends MetaObject> {
|
|
261
|
-
/**
|
|
262
|
-
* The initial state transition.
|
|
263
|
-
*/
|
|
256
|
+
/** The initial state transition. */
|
|
264
257
|
initial?: InitialTransitionConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay> | string | undefined;
|
|
265
258
|
/**
|
|
266
259
|
* The type of this state node:
|
|
267
260
|
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
261
|
+
* - `'atomic'` - no child state nodes
|
|
262
|
+
* - `'compound'` - nested child state nodes (XOR)
|
|
263
|
+
* - `'parallel'` - orthogonal nested child state nodes (AND)
|
|
264
|
+
* - `'history'` - history state node
|
|
265
|
+
* - `'final'` - final state node
|
|
273
266
|
*/
|
|
274
267
|
type?: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
|
|
275
268
|
/**
|
|
276
|
-
* Indicates whether the state node is a history state node, and what
|
|
277
|
-
*
|
|
278
|
-
* shallow, deep, true (shallow), false (none), undefined (none)
|
|
269
|
+
* Indicates whether the state node is a history state node, and what type of
|
|
270
|
+
* history: shallow, deep, true (shallow), false (none), undefined (none)
|
|
279
271
|
*/
|
|
280
272
|
history?: 'shallow' | 'deep' | boolean | undefined;
|
|
281
273
|
/**
|
|
282
|
-
* The mapping of state node keys to their state node configurations
|
|
274
|
+
* The mapping of state node keys to their state node configurations
|
|
275
|
+
* (recursive).
|
|
283
276
|
*/
|
|
284
277
|
states?: StatesConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, NonReducibleUnknown, TEmitted, TMeta> | undefined;
|
|
285
278
|
/**
|
|
286
|
-
* The services to invoke upon entering this state node. These services will
|
|
279
|
+
* The services to invoke upon entering this state node. These services will
|
|
280
|
+
* be stopped upon exiting this state node.
|
|
287
281
|
*/
|
|
288
282
|
invoke?: SingleOrArray<InvokeConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>>;
|
|
289
|
-
/**
|
|
290
|
-
* The mapping of event types to their potential transition(s).
|
|
291
|
-
*/
|
|
283
|
+
/** The mapping of event types to their potential transition(s). */
|
|
292
284
|
on?: TransitionsConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>;
|
|
293
|
-
/**
|
|
294
|
-
* The action(s) to be executed upon entering the state node.
|
|
295
|
-
*/
|
|
285
|
+
/** The action(s) to be executed upon entering the state node. */
|
|
296
286
|
entry?: Actions<TContext, TEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
297
|
-
/**
|
|
298
|
-
* The action(s) to be executed upon exiting the state node.
|
|
299
|
-
*/
|
|
287
|
+
/** The action(s) to be executed upon exiting the state node. */
|
|
300
288
|
exit?: Actions<TContext, TEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay, TEmitted>;
|
|
301
289
|
/**
|
|
302
|
-
* The potential transition(s) to be taken upon reaching a final child state
|
|
290
|
+
* The potential transition(s) to be taken upon reaching a final child state
|
|
291
|
+
* node.
|
|
303
292
|
*
|
|
304
|
-
* This is equivalent to defining a `[done(id)]` transition on this state
|
|
293
|
+
* This is equivalent to defining a `[done(id)]` transition on this state
|
|
294
|
+
* node's `on` property.
|
|
305
295
|
*/
|
|
306
296
|
onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneStateEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>> | undefined;
|
|
307
297
|
/**
|
|
308
|
-
* The mapping (or array) of delays (in milliseconds) to their potential
|
|
309
|
-
* The delayed transitions are taken after the specified delay
|
|
298
|
+
* The mapping (or array) of delays (in milliseconds) to their potential
|
|
299
|
+
* transition(s). The delayed transitions are taken after the specified delay
|
|
300
|
+
* in an interpreter.
|
|
310
301
|
*/
|
|
311
302
|
after?: DelayedTransitions<TContext, TEvent, TActor, TAction, TGuard, TDelay>;
|
|
312
303
|
/**
|
|
313
|
-
* An eventless transition that is always taken when this state node is
|
|
304
|
+
* An eventless transition that is always taken when this state node is
|
|
305
|
+
* active.
|
|
314
306
|
*/
|
|
315
307
|
always?: TransitionConfigOrTarget<TContext, TEvent, TEvent, TActor, TAction, TGuard, TDelay, TEmitted, TMeta>;
|
|
316
308
|
parent?: StateNode<TContext, TEvent>;
|
|
317
309
|
/**
|
|
318
|
-
* The meta data associated with this state node, which will be returned in
|
|
310
|
+
* The meta data associated with this state node, which will be returned in
|
|
311
|
+
* State instances.
|
|
319
312
|
*/
|
|
320
313
|
meta?: TMeta;
|
|
321
314
|
/**
|
|
322
|
-
* The output data sent with the "xstate.done.state._id_" event if this is a
|
|
315
|
+
* The output data sent with the "xstate.done.state._id_" event if this is a
|
|
316
|
+
* final state node.
|
|
323
317
|
*
|
|
324
|
-
* The output data will be evaluated with the current `context` and placed on
|
|
325
|
-
* of the event.
|
|
318
|
+
* The output data will be evaluated with the current `context` and placed on
|
|
319
|
+
* the `.data` property of the event.
|
|
326
320
|
*/
|
|
327
321
|
output?: Mapper<TContext, TEvent, unknown, TEvent> | NonReducibleUnknown;
|
|
328
322
|
/**
|
|
329
|
-
* The unique ID of the state node, which can be referenced as a transition
|
|
330
|
-
* `#id` syntax.
|
|
323
|
+
* The unique ID of the state node, which can be referenced as a transition
|
|
324
|
+
* target via the `#id` syntax.
|
|
331
325
|
*/
|
|
332
326
|
id?: string | undefined;
|
|
333
327
|
/**
|
|
334
|
-
* The order this state node appears. Corresponds to the implicit document
|
|
328
|
+
* The order this state node appears. Corresponds to the implicit document
|
|
329
|
+
* order.
|
|
335
330
|
*/
|
|
336
331
|
order?: number;
|
|
337
332
|
/**
|
|
338
|
-
* The tags for this state node, which are accumulated into the `state.tags`
|
|
333
|
+
* The tags for this state node, which are accumulated into the `state.tags`
|
|
334
|
+
* property.
|
|
339
335
|
*/
|
|
340
336
|
tags?: SingleOrArray<TTag>;
|
|
341
|
-
/**
|
|
342
|
-
* A text description of the state node
|
|
343
|
-
*/
|
|
337
|
+
/** A text description of the state node */
|
|
344
338
|
description?: string;
|
|
345
|
-
/**
|
|
346
|
-
* A default target for a history state
|
|
347
|
-
*/
|
|
339
|
+
/** A default target for a history state */
|
|
348
340
|
target?: string;
|
|
349
341
|
}
|
|
350
342
|
export type AnyStateNodeConfig = StateNodeConfig<any, any, any, any, any, any, any, any, any, // emitted
|
|
@@ -375,7 +367,7 @@ export interface StateMachineDefinition<TContext extends MachineContext, TEvent
|
|
|
375
367
|
export type AnyStateNode = StateNode<any, any>;
|
|
376
368
|
export type AnyStateNodeDefinition = StateNodeDefinition<any, any>;
|
|
377
369
|
export type AnyMachineSnapshot = MachineSnapshot<any, any, any, any, any, any, any>;
|
|
378
|
-
/** @deprecated
|
|
370
|
+
/** @deprecated Use `AnyMachineSnapshot` instead */
|
|
379
371
|
export type AnyState = AnyMachineSnapshot;
|
|
380
372
|
export type AnyStateMachine = StateMachine<any, // context
|
|
381
373
|
any, // event
|
|
@@ -389,7 +381,6 @@ any, // tag
|
|
|
389
381
|
any, // input
|
|
390
382
|
any, // output
|
|
391
383
|
any, // emitted
|
|
392
|
-
any, // TMeta
|
|
393
384
|
any>;
|
|
394
385
|
export type AnyStateConfig = StateConfig<any, AnyEventObject>;
|
|
395
386
|
export interface AtomicStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject> extends StateNodeConfig<TContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO, TODO, // emitted
|
|
@@ -417,9 +408,7 @@ type GuardMap<TContext extends MachineContext, TEvent extends EventObject, TGuar
|
|
|
417
408
|
};
|
|
418
409
|
export type DelayFunctionMap<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject> = Record<string, DelayConfig<TContext, TEvent, TAction['params'], TEvent>>;
|
|
419
410
|
export type DelayConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TEvent extends EventObject> = number | DelayExpr<TContext, TExpressionEvent, TParams, TEvent>;
|
|
420
|
-
/**
|
|
421
|
-
* @hidden
|
|
422
|
-
*/
|
|
411
|
+
/** @ignore */
|
|
423
412
|
export interface MachineImplementationsSimplified<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject> {
|
|
424
413
|
guards: GuardMap<TContext, TEvent, TGuard>;
|
|
425
414
|
actions: ActionFunctionMap<TContext, TEvent, TActor, TAction>;
|
|
@@ -429,39 +418,24 @@ export interface MachineImplementationsSimplified<TContext extends MachineContex
|
|
|
429
418
|
}>;
|
|
430
419
|
delays: DelayFunctionMap<TContext, TEvent, TAction>;
|
|
431
420
|
}
|
|
432
|
-
type
|
|
433
|
-
|
|
434
|
-
[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'], Cast<TEmitted, EventObject>>;
|
|
421
|
+
type MachineImplementationsActions<TTypes extends StateMachineTypes> = {
|
|
422
|
+
[K in TTypes['actions']['type']]?: ActionFunction<TTypes['context'], TTypes['events'], TTypes['events'], GetConcreteByKey<TTypes['actions'], 'type', K>['params'], TTypes['actors'], TTypes['actions'], TTypes['guards'], TTypes['delays'], TTypes['emitted']>;
|
|
435
423
|
};
|
|
436
|
-
type MachineImplementationsActors<
|
|
437
|
-
[K in
|
|
424
|
+
type MachineImplementationsActors<TTypes extends StateMachineTypes> = {
|
|
425
|
+
[K in TTypes['actors']['src']]?: GetConcreteByKey<TTypes['actors'], 'src', K>['logic'];
|
|
438
426
|
};
|
|
439
|
-
type MachineImplementationsDelays<
|
|
440
|
-
[K in
|
|
427
|
+
type MachineImplementationsDelays<TTypes extends StateMachineTypes> = {
|
|
428
|
+
[K in TTypes['delays']]?: DelayConfig<TTypes['context'], TTypes['events'], undefined, TTypes['events']>;
|
|
441
429
|
};
|
|
442
|
-
type MachineImplementationsGuards<
|
|
443
|
-
[K in
|
|
430
|
+
type MachineImplementationsGuards<TTypes extends StateMachineTypes> = {
|
|
431
|
+
[K in TTypes['guards']['type']]?: Guard<TTypes['context'], TTypes['events'], GetConcreteByKey<TTypes['guards'], 'type', K>['params'], TTypes['guards']>;
|
|
444
432
|
};
|
|
445
|
-
type
|
|
446
|
-
|
|
433
|
+
export type InternalMachineImplementations<TTypes extends StateMachineTypes> = {
|
|
434
|
+
actions?: MachineImplementationsActions<TTypes>;
|
|
435
|
+
actors?: MachineImplementationsActors<TTypes>;
|
|
436
|
+
delays?: MachineImplementationsDelays<TTypes>;
|
|
437
|
+
guards?: MachineImplementationsGuards<TTypes>;
|
|
447
438
|
};
|
|
448
|
-
type MaybeMakeMissingImplementationsRequired<TImplementationType, TMissingImplementationsForType, TRequireMissingImplementations> = TRequireMissingImplementations extends true ? IsNever<TMissingImplementationsForType> extends true ? {} : {
|
|
449
|
-
[K in Cast<TImplementationType, string>]: MakeKeysRequired<Cast<TMissingImplementationsForType, string>>;
|
|
450
|
-
} : {};
|
|
451
|
-
type GenerateActionsImplementationsPart<TContext extends MachineContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = Compute<MaybeMakeMissingImplementationsRequired<'actions', Prop<TMissingImplementations, 'actions'>, TRequireMissingImplementations> & {
|
|
452
|
-
actions?: MachineImplementationsActions<TContext, TResolvedTypesMeta>;
|
|
453
|
-
}>;
|
|
454
|
-
type GenerateActorsImplementationsPart<TContext extends MachineContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = Compute<MaybeMakeMissingImplementationsRequired<'actors', Prop<TMissingImplementations, 'actors'>, TRequireMissingImplementations> & {
|
|
455
|
-
actors?: MachineImplementationsActors<TContext, TResolvedTypesMeta>;
|
|
456
|
-
}>;
|
|
457
|
-
type GenerateDelaysImplementationsPart<TContext extends MachineContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = Compute<MaybeMakeMissingImplementationsRequired<'delays', Prop<TMissingImplementations, 'delays'>, TRequireMissingImplementations> & {
|
|
458
|
-
delays?: MachineImplementationsDelays<TContext, TResolvedTypesMeta>;
|
|
459
|
-
}>;
|
|
460
|
-
type GenerateGuardsImplementationsPart<TContext extends MachineContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = Compute<MaybeMakeMissingImplementationsRequired<'guards', Prop<TMissingImplementations, 'guards'>, TRequireMissingImplementations> & {
|
|
461
|
-
guards?: MachineImplementationsGuards<TContext, TResolvedTypesMeta>;
|
|
462
|
-
}>;
|
|
463
|
-
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>>;
|
|
464
|
-
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>>;
|
|
465
439
|
type InitialContext<TContext extends MachineContext, TActor extends ProvidedActor, TInput, TEvent extends EventObject> = TContext | ContextFactory<TContext, TActor, TInput, TEvent>;
|
|
466
440
|
export type ContextFactory<TContext extends MachineContext, TActor extends ProvidedActor, TInput, TEvent extends EventObject = EventObject> = ({ spawn, input, self }: {
|
|
467
441
|
spawn: Spawner<TActor>;
|
|
@@ -469,13 +443,9 @@ export type ContextFactory<TContext extends MachineContext, TActor extends Provi
|
|
|
469
443
|
self: ActorRef<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>, // TODO: this should be replaced with `TChildren`
|
|
470
444
|
StateValue, string, unknown, TODO>, TEvent, AnyEventObject>;
|
|
471
445
|
}) => TContext;
|
|
472
|
-
export type MachineConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string, TTag extends string = string, TInput = any, TOutput = unknown, TEmitted extends EventObject = EventObject, TMeta extends MetaObject = MetaObject
|
|
473
|
-
/**
|
|
474
|
-
|
|
475
|
-
*/
|
|
476
|
-
/**
|
|
477
|
-
* The machine's own version.
|
|
478
|
-
*/
|
|
446
|
+
export type MachineConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string, TTag extends string = string, TInput = any, TOutput = unknown, TEmitted extends EventObject = EventObject, TMeta extends MetaObject = MetaObject> = (Omit<StateNodeConfig<DoNotInfer<TContext>, DoNotInfer<TEvent>, DoNotInfer<TActor>, DoNotInfer<TAction>, DoNotInfer<TGuard>, DoNotInfer<TDelay>, DoNotInfer<TTag>, DoNotInfer<TOutput>, DoNotInfer<TEmitted>, DoNotInfer<TMeta>>, 'output'> & {
|
|
447
|
+
/** The initial context (extended state) */
|
|
448
|
+
/** The machine's own version. */
|
|
479
449
|
version?: string;
|
|
480
450
|
output?: Mapper<TContext, DoneStateEvent, TOutput, TEvent> | TOutput;
|
|
481
451
|
}) & (MachineContext extends TContext ? {
|
|
@@ -499,12 +469,11 @@ export interface SetupTypes<TContext extends MachineContext, TEvent extends Even
|
|
|
499
469
|
emitted?: TEmitted;
|
|
500
470
|
meta?: TMeta;
|
|
501
471
|
}
|
|
502
|
-
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
|
|
472
|
+
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> {
|
|
503
473
|
actors?: TActor;
|
|
504
474
|
actions?: TAction;
|
|
505
475
|
guards?: TGuard;
|
|
506
476
|
delays?: TDelay;
|
|
507
|
-
typegen?: TTypesMeta;
|
|
508
477
|
meta?: TMeta;
|
|
509
478
|
}
|
|
510
479
|
export interface HistoryStateNode<TContext extends MachineContext> extends StateNode<TContext> {
|
|
@@ -515,13 +484,15 @@ export type HistoryValue<TContext extends MachineContext, TEvent extends EventOb
|
|
|
515
484
|
export type AnyHistoryValue = HistoryValue<any, any>;
|
|
516
485
|
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;
|
|
517
486
|
export type Transitions<TContext extends MachineContext, TEvent extends EventObject> = Array<TransitionDefinition<TContext, TEvent>>;
|
|
518
|
-
export interface DoneActorEvent<TOutput = unknown> {
|
|
519
|
-
type: `xstate.done.actor.${
|
|
487
|
+
export interface DoneActorEvent<TOutput = unknown, TId extends string = string> extends EventObject {
|
|
488
|
+
type: `xstate.done.actor.${TId}`;
|
|
520
489
|
output: TOutput;
|
|
490
|
+
actorId: TId;
|
|
521
491
|
}
|
|
522
|
-
export interface ErrorActorEvent<TErrorData = unknown> extends EventObject {
|
|
523
|
-
type: `xstate.error.actor.${
|
|
492
|
+
export interface ErrorActorEvent<TErrorData = unknown, TId extends string = string> extends EventObject {
|
|
493
|
+
type: `xstate.error.actor.${TId}`;
|
|
524
494
|
error: TErrorData;
|
|
495
|
+
actorId: TId;
|
|
525
496
|
}
|
|
526
497
|
export interface SnapshotEvent<TSnapshot extends Snapshot<unknown> = Snapshot<unknown>> extends EventObject {
|
|
527
498
|
type: `xstate.snapshot.${string}`;
|
|
@@ -606,10 +577,12 @@ export interface StateConfig<TContext extends MachineContext, TEvent extends Eve
|
|
|
606
577
|
}
|
|
607
578
|
export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
608
579
|
/**
|
|
609
|
-
* The clock that is responsible for setting and clearing timeouts, such as
|
|
580
|
+
* The clock that is responsible for setting and clearing timeouts, such as
|
|
581
|
+
* delayed events and transitions.
|
|
610
582
|
*
|
|
611
583
|
* @remarks
|
|
612
|
-
* You can create your own “clock”. The clock interface is an object with two
|
|
584
|
+
* You can create your own “clock”. The clock interface is an object with two
|
|
585
|
+
* functions/methods:
|
|
613
586
|
*
|
|
614
587
|
* - `setTimeout` - same arguments as `window.setTimeout(fn, timeout)`
|
|
615
588
|
* - `clearTimeout` - same arguments as `window.clearTimeout(id)`
|
|
@@ -617,65 +590,58 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
617
590
|
* By default, the native `setTimeout` and `clearTimeout` functions are used.
|
|
618
591
|
*
|
|
619
592
|
* For testing, XState provides `SimulatedClock`.
|
|
620
|
-
*
|
|
621
593
|
* @see {@link Clock}
|
|
622
594
|
* @see {@link SimulatedClock}
|
|
623
595
|
*/
|
|
624
596
|
clock?: Clock;
|
|
625
597
|
/**
|
|
626
|
-
* Specifies the logger to be used for `log(...)` actions. Defaults to the
|
|
598
|
+
* Specifies the logger to be used for `log(...)` actions. Defaults to the
|
|
599
|
+
* native `console.log(...)` method.
|
|
627
600
|
*/
|
|
628
601
|
logger?: (...args: any[]) => void;
|
|
629
602
|
parent?: AnyActorRef;
|
|
630
|
-
/**
|
|
631
|
-
* The custom `id` for referencing this service.
|
|
632
|
-
*/
|
|
603
|
+
/** The custom `id` for referencing this service. */
|
|
633
604
|
id?: string;
|
|
634
|
-
/**
|
|
635
|
-
* @deprecated Use `inspect` instead.
|
|
636
|
-
*/
|
|
605
|
+
/** @deprecated Use `inspect` instead. */
|
|
637
606
|
devTools?: never;
|
|
638
|
-
/**
|
|
639
|
-
* The system ID to register this actor under.
|
|
640
|
-
*/
|
|
607
|
+
/** The system ID to register this actor under. */
|
|
641
608
|
systemId?: string;
|
|
642
|
-
/**
|
|
643
|
-
* The input data to pass to the actor.
|
|
644
|
-
*/
|
|
609
|
+
/** The input data to pass to the actor. */
|
|
645
610
|
input?: InputFrom<TLogic>;
|
|
646
611
|
/**
|
|
647
612
|
* Initializes actor logic from a specific persisted internal state.
|
|
648
613
|
*
|
|
649
614
|
* @remarks
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
* However, invocations will be restarted, and spawned actors will be restored
|
|
615
|
+
* If the state is compatible with the actor logic, when the actor is started
|
|
616
|
+
* it will be at that persisted state. Actions from machine actors will not be
|
|
617
|
+
* re-executed, because they are assumed to have been already executed.
|
|
618
|
+
* However, invocations will be restarted, and spawned actors will be restored
|
|
619
|
+
* recursively.
|
|
654
620
|
*
|
|
655
621
|
* Can be generated with {@link Actor.getPersistedSnapshot}.
|
|
656
|
-
*
|
|
657
622
|
* @see https://stately.ai/docs/persistence
|
|
658
623
|
*/
|
|
659
624
|
snapshot?: Snapshot<unknown>;
|
|
660
|
-
/**
|
|
661
|
-
* @deprecated Use `snapshot` instead.
|
|
662
|
-
*/
|
|
625
|
+
/** @deprecated Use `snapshot` instead. */
|
|
663
626
|
state?: Snapshot<unknown>;
|
|
664
|
-
/**
|
|
665
|
-
* The source actor logic.
|
|
666
|
-
*/
|
|
627
|
+
/** The source actor logic. */
|
|
667
628
|
src?: string | AnyActorLogic;
|
|
668
629
|
/**
|
|
669
|
-
* A callback function or observer object which can be used to inspect actor
|
|
630
|
+
* A callback function or observer object which can be used to inspect actor
|
|
631
|
+
* system updates.
|
|
670
632
|
*
|
|
671
633
|
* @remarks
|
|
672
|
-
* If a callback function is provided, it can accept an inspection event
|
|
634
|
+
* If a callback function is provided, it can accept an inspection event
|
|
635
|
+
* argument. The types of inspection events that can be observed include:
|
|
673
636
|
*
|
|
674
637
|
* - `@xstate.actor` - An actor ref has been created in the system
|
|
675
|
-
* - `@xstate.event` - An event was sent from a source actor ref to a target
|
|
676
|
-
*
|
|
638
|
+
* - `@xstate.event` - An event was sent from a source actor ref to a target
|
|
639
|
+
* actor ref in the system
|
|
640
|
+
* - `@xstate.snapshot` - An actor ref emitted a snapshot due to a received
|
|
641
|
+
* event
|
|
677
642
|
*
|
|
678
643
|
* @example
|
|
644
|
+
*
|
|
679
645
|
* ```ts
|
|
680
646
|
* import { createMachine } from 'xstate';
|
|
681
647
|
*
|
|
@@ -708,9 +674,11 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
708
674
|
* });
|
|
709
675
|
* ```
|
|
710
676
|
*
|
|
711
|
-
* Alternately, an observer object (`{ next?, error?, complete? }`) can be
|
|
677
|
+
* Alternately, an observer object (`{ next?, error?, complete? }`) can be
|
|
678
|
+
* provided:
|
|
712
679
|
*
|
|
713
680
|
* @example
|
|
681
|
+
*
|
|
714
682
|
* ```ts
|
|
715
683
|
* const actor = createActor(machine, {
|
|
716
684
|
* inspect: {
|
|
@@ -742,9 +710,7 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
742
710
|
inspect?: Observer<InspectionEvent> | ((inspectionEvent: InspectionEvent) => void);
|
|
743
711
|
}
|
|
744
712
|
export type AnyActor = Actor<any>;
|
|
745
|
-
/**
|
|
746
|
-
* @deprecated Use `AnyActor` instead.
|
|
747
|
-
*/
|
|
713
|
+
/** @deprecated Use `AnyActor` instead. */
|
|
748
714
|
export type AnyInterpreter = AnyActor;
|
|
749
715
|
export type Observer<T> = {
|
|
750
716
|
next?: (value: T) => void;
|
|
@@ -773,9 +739,7 @@ export interface ActorLike<TCurrent, TEvent extends EventObject> extends Subscri
|
|
|
773
739
|
send: (event: TEvent) => void;
|
|
774
740
|
}
|
|
775
741
|
export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TEmitted extends EventObject = EventObject> extends Subscribable<TSnapshot>, InteropObservable<TSnapshot> {
|
|
776
|
-
/**
|
|
777
|
-
* The unique identifier for this actor relative to its parent.
|
|
778
|
-
*/
|
|
742
|
+
/** The unique identifier for this actor relative to its parent. */
|
|
779
743
|
id: string;
|
|
780
744
|
sessionId: string;
|
|
781
745
|
send: (event: TEvent) => void;
|
|
@@ -792,29 +756,14 @@ export interface ActorRef<TSnapshot extends Snapshot<unknown>, TEvent extends Ev
|
|
|
792
756
|
})) => void) => Subscription;
|
|
793
757
|
}
|
|
794
758
|
export type AnyActorRef = ActorRef<any, any, any>;
|
|
759
|
+
export type UnknownActorRef = ActorRef<Snapshot<unknown>, EventObject>;
|
|
795
760
|
export type ActorLogicFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<any, any, any, any, any, any, any, any, any, any, any, any, // TMeta
|
|
796
761
|
any> ? R : R extends Promise<infer U> ? PromiseActorLogic<U> : never : never;
|
|
797
|
-
export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer TEmitted, infer TMeta
|
|
762
|
+
export type ActorRefFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer TEvent, infer TChildren, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TStateValue, infer TTag, infer _TInput, infer TOutput, infer TEmitted, infer TMeta> ? ActorRef<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>, TEvent, TEmitted> : R extends Promise<infer U> ? ActorRefFrom<PromiseActorLogic<U>> : R extends ActorLogic<infer TSnapshot, infer TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? ActorRef<TSnapshot, TEvent, TEmitted> : never : never;
|
|
798
763
|
export type DevToolsAdapter = (service: AnyActor) => void;
|
|
799
|
-
/**
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
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 TEmitted, infer TMeta, infer _TResolvedTypesMeta> ? Actor<ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>, TEvent, TInput, AnyActorSystem, TEmitted>> : never;
|
|
803
|
-
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 _TEmitted, infer _TMeta, infer TResolvedTypesMeta> ? InternalMachineImplementations<TContext, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
804
|
-
export type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, // context
|
|
805
|
-
any, // event
|
|
806
|
-
any, // children
|
|
807
|
-
any, // actor
|
|
808
|
-
any, // action
|
|
809
|
-
any, // guard
|
|
810
|
-
any, // delay
|
|
811
|
-
any, // state value
|
|
812
|
-
any, // tag
|
|
813
|
-
any, // input
|
|
814
|
-
any, // output
|
|
815
|
-
any, // emitted
|
|
816
|
-
any, // TMeta
|
|
817
|
-
infer TResolvedTypesMeta> ? TResolvedTypesMeta : never;
|
|
764
|
+
/** @deprecated Use `Actor<T>` instead. */
|
|
765
|
+
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 TEmitted, infer TMeta> ? Actor<ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta>, TEvent, TInput, AnyActorSystem, TEmitted>> : never;
|
|
766
|
+
export type MachineImplementationsFrom<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 TEmitted, infer _TMeta> ? InternalMachineImplementations<ResolvedStateMachineTypes<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TEmitted>> : never;
|
|
818
767
|
export interface ActorScope<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TSystem extends AnyActorSystem = AnyActorSystem, TEmitted extends EventObject = EventObject> {
|
|
819
768
|
self: ActorRef<TSnapshot, TEvent, TEmitted>;
|
|
820
769
|
id: string;
|
|
@@ -859,8 +808,9 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
|
|
|
859
808
|
/** The initial setup/configuration used to create the actor logic. */
|
|
860
809
|
config?: unknown;
|
|
861
810
|
/**
|
|
862
|
-
* Transition function that processes the current state and an incoming
|
|
863
|
-
* to produce a new state.
|
|
811
|
+
* Transition function that processes the current state and an incoming
|
|
812
|
+
* message to produce a new state.
|
|
813
|
+
*
|
|
864
814
|
* @param snapshot - The current state.
|
|
865
815
|
* @param message - The incoming message.
|
|
866
816
|
* @param actorScope - The actor scope.
|
|
@@ -869,14 +819,17 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
|
|
|
869
819
|
transition: (snapshot: TSnapshot, message: TEvent, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => TSnapshot;
|
|
870
820
|
/**
|
|
871
821
|
* Called to provide the initial state of the actor.
|
|
822
|
+
*
|
|
872
823
|
* @param actorScope - The actor scope.
|
|
873
824
|
* @param input - The input for the initial state.
|
|
874
825
|
* @returns The initial state.
|
|
875
826
|
*/
|
|
876
827
|
getInitialSnapshot: (actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>, input: TInput) => TSnapshot;
|
|
877
828
|
/**
|
|
878
|
-
* Called when Actor is created to restore the internal state of the actor
|
|
879
|
-
* The persisted state can be created by
|
|
829
|
+
* Called when Actor is created to restore the internal state of the actor
|
|
830
|
+
* given a persisted state. The persisted state can be created by
|
|
831
|
+
* `getPersistedSnapshot`.
|
|
832
|
+
*
|
|
880
833
|
* @param persistedState - The persisted state to restore from.
|
|
881
834
|
* @param actorScope - The actor scope.
|
|
882
835
|
* @returns The restored state.
|
|
@@ -884,13 +837,15 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
|
|
|
884
837
|
restoreSnapshot?: (persistedState: Snapshot<unknown>, actorScope: ActorScope<TSnapshot, TEvent, AnyActorSystem, TEmitted>) => TSnapshot;
|
|
885
838
|
/**
|
|
886
839
|
* Called when the actor is started.
|
|
840
|
+
*
|
|
887
841
|
* @param snapshot - The starting state.
|
|
888
842
|
* @param actorScope - The actor scope.
|
|
889
843
|
*/
|
|
890
844
|
start?: (snapshot: TSnapshot, actorScope: ActorScope<TSnapshot, TEvent, AnyActorSystem, TEmitted>) => void;
|
|
891
845
|
/**
|
|
892
|
-
* Obtains the internal state of the actor in a representation which can be be
|
|
893
|
-
* The persisted state can be restored by `restoreSnapshot`.
|
|
846
|
+
* Obtains the internal state of the actor in a representation which can be be
|
|
847
|
+
* persisted. The persisted state can be restored by `restoreSnapshot`.
|
|
848
|
+
*
|
|
894
849
|
* @param snapshot - The current state.
|
|
895
850
|
* @returns The a representation of the internal state to be persisted.
|
|
896
851
|
*/
|
|
@@ -908,9 +863,9 @@ AnyActorSystem, any>;
|
|
|
908
863
|
export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer TSnapshot, infer _, infer __> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends ActorLogic<infer _TSnapshot, infer _TEvent, infer _TInput, infer _TEmitted, infer _TSystem> ? ReturnType<R['transition']> : R extends ActorScope<infer TSnapshot, infer _TEvent, infer _TEmitted, infer _TSystem> ? TSnapshot : never : never;
|
|
909
864
|
export type EventFromLogic<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer TEvent, infer _TInput, infer _TEmitted, infer _TSystem> ? TEvent : never;
|
|
910
865
|
export type EmittedFrom<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? TEmitted : never;
|
|
911
|
-
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 _TEmitted, infer _TMeta
|
|
866
|
+
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 _TEmitted, infer _TMeta> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput, infer _TMeta> ? TEvent : R extends ActorRef<infer _TSnapshot, infer TEvent, infer _TEmitted> ? TEvent : never : never;
|
|
912
867
|
export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
|
|
913
|
-
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 _TEmitted, infer _TMeta
|
|
868
|
+
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 _TEmitted, infer _TMeta> ? TContext : R extends MachineSnapshot<infer TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput, infer _TMeta> ? 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 _TEmitted, infer _TMeta, infer _TTypes> ? TContext : never : never : never;
|
|
914
869
|
export type InferEvent<E extends EventObject> = {
|
|
915
870
|
[T in E['type']]: {
|
|
916
871
|
type: T;
|
|
@@ -938,4 +893,26 @@ export type ToChildren<TActor extends ProvidedActor> = string extends TActor['sr
|
|
|
938
893
|
export type StateSchema = {
|
|
939
894
|
states?: Record<string, StateSchema>;
|
|
940
895
|
};
|
|
896
|
+
export interface StateMachineTypes {
|
|
897
|
+
context: MachineContext;
|
|
898
|
+
events: EventObject;
|
|
899
|
+
actors: ProvidedActor;
|
|
900
|
+
actions: ParameterizedObject;
|
|
901
|
+
guards: ParameterizedObject;
|
|
902
|
+
delays: string;
|
|
903
|
+
tags: string;
|
|
904
|
+
emitted: EventObject;
|
|
905
|
+
}
|
|
906
|
+
/** @deprecated */
|
|
907
|
+
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> {
|
|
908
|
+
context: TContext;
|
|
909
|
+
events: TEvent;
|
|
910
|
+
actors: TActor;
|
|
911
|
+
actions: TAction;
|
|
912
|
+
guards: TGuard;
|
|
913
|
+
delays: TDelay;
|
|
914
|
+
tags: TTag;
|
|
915
|
+
emitted: TEmitted;
|
|
916
|
+
}
|
|
917
|
+
export type GetConcreteByKey<T, TKey extends keyof T, TValue extends T[TKey]> = T & Record<TKey, TValue>;
|
|
941
918
|
export {};
|