xstate 4.20.1 → 4.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/dist/xstate.interpreter.js +1 -1
  3. package/dist/xstate.js +1 -1
  4. package/dist/xstate.web.js +2 -2
  5. package/es/Actor.js +17 -5
  6. package/es/Machine.d.ts +6 -3
  7. package/es/Machine.js +3 -6
  8. package/es/State.js +1 -3
  9. package/es/StateNode.d.ts +4 -3
  10. package/es/StateNode.js +34 -20
  11. package/es/_virtual/_tslib.js +59 -73
  12. package/es/actionTypes.js +3 -2
  13. package/es/actions.d.ts +1 -1
  14. package/es/actions.js +51 -37
  15. package/es/behaviors.d.ts +37 -0
  16. package/es/behaviors.js +65 -0
  17. package/es/constants.js +2 -1
  18. package/es/devTools.js +1 -1
  19. package/es/environment.js +2 -1
  20. package/es/index.js +3 -1
  21. package/es/interpreter.d.ts +10 -3
  22. package/es/interpreter.js +44 -22
  23. package/es/invokeUtils.js +4 -3
  24. package/es/mapState.js +1 -1
  25. package/es/match.js +1 -1
  26. package/es/model.d.ts +2 -36
  27. package/es/model.types.d.ts +37 -0
  28. package/es/registry.js +2 -1
  29. package/es/scheduler.js +2 -1
  30. package/es/schema.js +1 -1
  31. package/es/serviceScope.js +1 -3
  32. package/es/stateUtils.js +1 -9
  33. package/es/types.d.ts +26 -5
  34. package/es/types.js +1 -1
  35. package/es/utils.d.ts +3 -2
  36. package/es/utils.js +4 -40
  37. package/lib/Actor.d.ts +25 -25
  38. package/lib/Actor.js +85 -66
  39. package/lib/Machine.d.ts +17 -14
  40. package/lib/Machine.js +14 -14
  41. package/lib/SimulatedClock.d.ts +16 -16
  42. package/lib/State.d.ts +108 -108
  43. package/lib/State.js +246 -236
  44. package/lib/StateNode.d.ts +279 -278
  45. package/lib/StateNode.js +1535 -1339
  46. package/lib/_virtual/_tslib.js +81 -0
  47. package/lib/actionTypes.d.ts +19 -19
  48. package/lib/actionTypes.js +43 -23
  49. package/lib/actions.d.ts +138 -138
  50. package/lib/actions.js +465 -387
  51. package/lib/behaviors.d.ts +37 -0
  52. package/lib/behaviors.js +69 -0
  53. package/lib/constants.d.ts +5 -5
  54. package/lib/constants.js +13 -7
  55. package/lib/devTools.d.ts +15 -15
  56. package/lib/devTools.js +37 -26
  57. package/lib/each.d.ts +3 -3
  58. package/lib/environment.d.ts +1 -1
  59. package/lib/environment.js +7 -4
  60. package/lib/index.d.ts +30 -30
  61. package/lib/index.js +67 -57
  62. package/lib/interpreter.d.ts +205 -198
  63. package/lib/interpreter.js +1306 -1054
  64. package/lib/invoke.d.ts +10 -10
  65. package/lib/invokeUtils.d.ts +6 -6
  66. package/lib/invokeUtils.js +40 -37
  67. package/lib/json.d.ts +30 -30
  68. package/lib/mapState.d.ts +3 -3
  69. package/lib/mapState.js +31 -32
  70. package/lib/match.d.ts +8 -8
  71. package/lib/match.js +33 -47
  72. package/lib/model.d.ts +4 -38
  73. package/lib/model.js +5 -1
  74. package/lib/model.types.d.ts +37 -0
  75. package/lib/model.types.js +2 -0
  76. package/lib/patterns.d.ts +13 -13
  77. package/lib/registry.d.ts +8 -8
  78. package/lib/registry.js +21 -18
  79. package/lib/scheduler.d.ts +16 -16
  80. package/lib/scheduler.js +79 -70
  81. package/lib/schema.d.ts +1 -1
  82. package/lib/schema.js +6 -4
  83. package/lib/scxml.d.ts +5 -5
  84. package/lib/serviceScope.d.ts +3 -3
  85. package/lib/serviceScope.js +16 -12
  86. package/lib/stateUtils.d.ts +14 -14
  87. package/lib/stateUtils.js +231 -199
  88. package/lib/types.d.ts +928 -907
  89. package/lib/types.js +29 -29
  90. package/lib/utils.d.ts +68 -67
  91. package/lib/utils.js +530 -529
  92. package/package.json +6 -6
package/lib/types.d.ts CHANGED
@@ -1,908 +1,929 @@
1
- import { StateNode } from './StateNode';
2
- import { State } from './State';
3
- import { Interpreter, Clock } from './interpreter';
4
- export declare type EventType = string;
5
- export declare type ActionType = string;
6
- export declare type MetaObject = Record<string, any>;
7
- /**
8
- * The full definition of an event, with a string `type`.
9
- */
10
- export interface EventObject {
11
- /**
12
- * The type of event that is sent.
13
- */
14
- type: string;
15
- }
16
- export interface AnyEventObject extends EventObject {
17
- [key: string]: any;
18
- }
19
- /**
20
- * The full definition of an action, with a string `type` and an
21
- * `exec` implementation function.
22
- */
23
- export interface ActionObject<TContext, TEvent extends EventObject> {
24
- /**
25
- * The type of action that is executed.
26
- */
27
- type: string;
28
- /**
29
- * The implementation for executing the action.
30
- */
31
- exec?: ActionFunction<TContext, TEvent>;
32
- [other: string]: any;
33
- }
34
- export declare type DefaultContext = Record<string, any> | undefined;
35
- export declare type EventData = Record<string, any> & {
36
- type?: never;
37
- };
38
- /**
39
- * The specified string event types or the specified event objects.
40
- */
41
- export declare type Event<TEvent extends EventObject> = TEvent['type'] | TEvent;
42
- export interface ActionMeta<TContext, TEvent extends EventObject> extends StateMeta<TContext, TEvent> {
43
- action: ActionObject<TContext, TEvent>;
44
- _event: SCXML.Event<TEvent>;
45
- }
46
- export interface AssignMeta<TContext, TEvent extends EventObject> {
47
- state?: State<TContext, TEvent>;
48
- action: AssignAction<TContext, TEvent>;
49
- _event: SCXML.Event<TEvent>;
50
- }
51
- export declare type ActionFunction<TContext, TEvent extends EventObject> = (context: TContext, event: TEvent, meta: ActionMeta<TContext, TEvent>) => void;
52
- export interface ChooseConditon<TContext, TEvent extends EventObject> {
53
- cond?: Condition<TContext, TEvent>;
54
- actions: Actions<TContext, TEvent>;
55
- }
56
- export declare type Action<TContext, TEvent extends EventObject> = ActionType | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent>;
57
- export declare type Actions<TContext, TEvent extends EventObject> = SingleOrArray<Action<TContext, TEvent>>;
58
- export declare type StateKey = string | State<any>;
59
- export interface StateValueMap {
60
- [key: string]: StateValue;
61
- }
62
- /**
63
- * The string or object representing the state value relative to the parent state node.
64
- *
65
- * - For a child atomic state node, this is a string, e.g., `"pending"`.
66
- * - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
67
- */
68
- export declare type StateValue = string | StateValueMap;
69
- declare type KeysWithStates<TStates extends Record<string, StateSchema> | undefined> = TStates extends object ? {
70
- [K in keyof TStates]-?: TStates[K] extends {
71
- states: object;
72
- } ? K : never;
73
- }[keyof TStates] : never;
74
- export declare type ExtractStateValue<TSchema extends Required<Pick<StateSchema<any>, 'states'>>> = keyof TSchema['states'] | (KeysWithStates<TSchema['states']> extends never ? never : {
75
- [K in KeysWithStates<TSchema['states']>]?: ExtractStateValue<TSchema['states'][K]>;
76
- });
77
- export interface HistoryValue {
78
- states: Record<string, HistoryValue | undefined>;
79
- current: StateValue | undefined;
80
- }
81
- export declare type ConditionPredicate<TContext, TEvent extends EventObject> = (context: TContext, event: TEvent, meta: GuardMeta<TContext, TEvent>) => boolean;
82
- export declare type DefaultGuardType = 'xstate.guard';
83
- export interface GuardPredicate<TContext, TEvent extends EventObject> {
84
- type: DefaultGuardType;
85
- name: string | undefined;
86
- predicate: ConditionPredicate<TContext, TEvent>;
87
- }
88
- export declare type Guard<TContext, TEvent extends EventObject> = GuardPredicate<TContext, TEvent> | (Record<string, any> & {
89
- type: string;
90
- });
91
- export interface GuardMeta<TContext, TEvent extends EventObject> extends StateMeta<TContext, TEvent> {
92
- cond: Guard<TContext, TEvent>;
93
- }
94
- export declare type Condition<TContext, TEvent extends EventObject> = string | ConditionPredicate<TContext, TEvent> | Guard<TContext, TEvent>;
95
- export declare type TransitionTarget<TContext, TEvent extends EventObject> = SingleOrArray<string | StateNode<TContext, any, TEvent>>;
96
- export declare type TransitionTargets<TContext> = Array<string | StateNode<TContext, any>>;
97
- export interface TransitionConfig<TContext, TEvent extends EventObject> {
98
- cond?: Condition<TContext, TEvent>;
99
- actions?: Actions<TContext, TEvent>;
100
- in?: StateValue;
101
- internal?: boolean;
102
- target?: TransitionTarget<TContext, TEvent>;
103
- meta?: Record<string, any>;
104
- }
105
- export interface TargetTransitionConfig<TContext, TEvent extends EventObject> extends TransitionConfig<TContext, TEvent> {
106
- target: TransitionTarget<TContext, TEvent>;
107
- }
108
- export declare type ConditionalTransitionConfig<TContext, TEvent extends EventObject = EventObject> = Array<TransitionConfig<TContext, TEvent>>;
109
- export declare type Transition<TContext, TEvent extends EventObject = EventObject> = string | TransitionConfig<TContext, TEvent> | ConditionalTransitionConfig<TContext, TEvent>;
110
- export declare type DisposeActivityFunction = () => void;
111
- export declare type ActivityConfig<TContext, TEvent extends EventObject> = (ctx: TContext, activity: ActivityDefinition<TContext, TEvent>) => DisposeActivityFunction | void;
112
- export declare type Activity<TContext, TEvent extends EventObject> = string | ActivityDefinition<TContext, TEvent>;
113
- export interface ActivityDefinition<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
114
- id: string;
115
- type: string;
116
- }
117
- export declare type Sender<TEvent extends EventObject> = (event: Event<TEvent>) => void;
118
- declare type ExcludeType<A> = {
119
- [K in Exclude<keyof A, 'type'>]: A[K];
120
- };
121
- declare type ExtractExtraParameters<A, T> = A extends {
122
- type: T;
123
- } ? ExcludeType<A> : never;
124
- declare type ExtractSimple<A> = A extends any ? {} extends ExcludeType<A> ? A : never : never;
125
- declare type NeverIfEmpty<T> = {} extends T ? never : T;
126
- export interface PayloadSender<TEvent extends EventObject> {
127
- /**
128
- * Send an event object or just the event type, if the event has no other payload
129
- */
130
- (event: TEvent | ExtractSimple<TEvent>['type']): void;
131
- /**
132
- * Send an event type and its payload
133
- */
134
- <K extends TEvent['type']>(eventType: K, payload: NeverIfEmpty<ExtractExtraParameters<TEvent, K>>): void;
135
- }
136
- export declare type Receiver<TEvent extends EventObject> = (listener: (event: TEvent) => void) => void;
137
- export declare type InvokeCallback<TEvent extends EventObject = AnyEventObject, TSentEvent extends EventObject = AnyEventObject> = (callback: Sender<TSentEvent>, onReceive: Receiver<TEvent>) => (() => void) | Promise<any> | void;
138
- export interface InvokeMeta {
139
- data: any;
140
- src: InvokeSourceDefinition;
141
- }
142
- /**
143
- * Returns either a Promises or a callback handler (for streams of events) given the
144
- * machine's current `context` and `event` that invoked the service.
145
- *
146
- * For Promises, the only events emitted to the parent will be:
147
- * - `done.invoke.<id>` with the `data` containing the resolved payload when the promise resolves, or:
148
- * - `error.platform.<id>` with the `data` containing the caught error, and `src` containing the service `id`.
149
- *
150
- * For callback handlers, the `callback` will be provided, which will send events to the parent service.
151
- *
152
- * @param context The current machine `context`
153
- * @param event The event that invoked the service
154
- */
155
- export declare type InvokeCreator<TContext, TEvent extends EventObject, TFinalContext = any> = (context: TContext, event: TEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<EventObject> | InvokeCallback<any, TEvent>;
156
- export interface InvokeDefinition<TContext, TEvent extends EventObject> extends ActivityDefinition<TContext, TEvent> {
157
- /**
158
- * The source of the machine to be invoked, or the machine itself.
159
- */
160
- src: string | InvokeSourceDefinition;
161
- /**
162
- * If `true`, events sent to the parent service will be forwarded to the invoked service.
163
- *
164
- * Default: `false`
165
- */
166
- autoForward?: boolean;
167
- /**
168
- * @deprecated
169
- *
170
- * Use `autoForward` property instead of `forward`. Support for `forward` will get removed in the future.
171
- */
172
- forward?: boolean;
173
- /**
174
- * Data from the parent machine's context to set as the (partial or full) context
175
- * for the invoked child machine.
176
- *
177
- * Data should be mapped to match the child machine's context shape.
178
- */
179
- data?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
180
- }
181
- export interface Delay {
182
- id: string;
183
- /**
184
- * The time to delay the event, in milliseconds.
185
- */
186
- delay: number;
187
- }
188
- export declare type DelayedTransitions<TContext, TEvent extends EventObject> = Record<string | number, string | SingleOrArray<TransitionConfig<TContext, TEvent>>> | Array<TransitionConfig<TContext, TEvent> & {
189
- delay: number | string | Expr<TContext, TEvent, number>;
190
- }>;
191
- export declare type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | string;
192
- export declare type SingleOrArray<T> = T[] | T;
193
- export declare type StateNodesConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = {
194
- [K in keyof TStateSchema['states']]: StateNode<TContext, TStateSchema['states'][K], TEvent>;
195
- };
196
- export declare type StatesConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = {
197
- [K in keyof TStateSchema['states']]: StateNodeConfig<TContext, TStateSchema['states'][K], TEvent>;
198
- };
199
- export declare type StatesDefinition<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = {
200
- [K in keyof TStateSchema['states']]: StateNodeDefinition<TContext, TStateSchema['states'][K], TEvent>;
201
- };
202
- export declare type TransitionConfigTarget<TContext, TEvent extends EventObject> = string | undefined | StateNode<TContext, any, TEvent>;
203
- export declare type TransitionConfigOrTarget<TContext, TEvent extends EventObject> = SingleOrArray<TransitionConfigTarget<TContext, TEvent> | TransitionConfig<TContext, TEvent>>;
204
- export declare type TransitionsConfigMap<TContext, TEvent extends EventObject> = {
205
- [K in TEvent['type']]?: TransitionConfigOrTarget<TContext, TEvent extends {
206
- type: K;
207
- } ? TEvent : never>;
208
- } & {
209
- ''?: TransitionConfigOrTarget<TContext, TEvent>;
210
- } & {
211
- '*'?: TransitionConfigOrTarget<TContext, TEvent>;
212
- };
213
- declare type TransitionsConfigArray<TContext, TEvent extends EventObject> = Array<(TEvent extends EventObject ? TransitionConfig<TContext, TEvent> & {
214
- event: TEvent['type'];
215
- } : never) | (TransitionConfig<TContext, TEvent> & {
216
- event: '';
217
- }) | (TransitionConfig<TContext, TEvent> & {
218
- event: '*';
219
- })>;
220
- export declare type TransitionsConfig<TContext, TEvent extends EventObject> = TransitionsConfigMap<TContext, TEvent> | TransitionsConfigArray<TContext, TEvent>;
221
- export interface InvokeSourceDefinition {
222
- [key: string]: any;
223
- type: string;
224
- }
225
- export interface InvokeConfig<TContext, TEvent extends EventObject> {
226
- /**
227
- * The unique identifier for the invoked machine. If not specified, this
228
- * will be the machine's own `id`, or the URL (from `src`).
229
- */
230
- id?: string;
231
- /**
232
- * The source of the machine to be invoked, or the machine itself.
233
- */
234
- src: string | InvokeSourceDefinition | StateMachine<any, any, any> | InvokeCreator<TContext, TEvent, any>;
235
- /**
236
- * If `true`, events sent to the parent service will be forwarded to the invoked service.
237
- *
238
- * Default: `false`
239
- */
240
- autoForward?: boolean;
241
- /**
242
- * @deprecated
243
- *
244
- * Use `autoForward` property instead of `forward`. Support for `forward` will get removed in the future.
245
- */
246
- forward?: boolean;
247
- /**
248
- * Data from the parent machine's context to set as the (partial or full) context
249
- * for the invoked child machine.
250
- *
251
- * Data should be mapped to match the child machine's context shape.
252
- */
253
- data?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
254
- /**
255
- * The transition to take upon the invoked child machine reaching its final top-level state.
256
- */
257
- onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneInvokeEvent<any>>>;
258
- /**
259
- * The transition to take upon the invoked child machine sending an error event.
260
- */
261
- onError?: string | SingleOrArray<TransitionConfig<TContext, DoneInvokeEvent<any>>>;
262
- }
263
- export interface StateNodeConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> {
264
- /**
265
- * The relative key of the state node, which represents its location in the overall state value.
266
- * This is automatically determined by the configuration shape via the key where it was defined.
267
- */
268
- key?: string;
269
- /**
270
- * The initial state node key.
271
- */
272
- initial?: keyof TStateSchema['states'] | undefined;
273
- /**
274
- * @deprecated
275
- */
276
- parallel?: boolean | undefined;
277
- /**
278
- * The type of this state node:
279
- *
280
- * - `'atomic'` - no child state nodes
281
- * - `'compound'` - nested child state nodes (XOR)
282
- * - `'parallel'` - orthogonal nested child state nodes (AND)
283
- * - `'history'` - history state node
284
- * - `'final'` - final state node
285
- */
286
- type?: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
287
- /**
288
- * The initial context (extended state) of the machine.
289
- *
290
- * Can be an object or a function that returns an object.
291
- */
292
- context?: TContext | (() => TContext);
293
- /**
294
- * Indicates whether the state node is a history state node, and what
295
- * type of history:
296
- * shallow, deep, true (shallow), false (none), undefined (none)
297
- */
298
- history?: 'shallow' | 'deep' | boolean | undefined;
299
- /**
300
- * The mapping of state node keys to their state node configurations (recursive).
301
- */
302
- states?: StatesConfig<TContext, TStateSchema, TEvent> | undefined;
303
- /**
304
- * The services to invoke upon entering this state node. These services will be stopped upon exiting this state node.
305
- */
306
- invoke?: SingleOrArray<InvokeConfig<TContext, TEvent> | StateMachine<any, any, any>>;
307
- /**
308
- * The mapping of event types to their potential transition(s).
309
- */
310
- on?: TransitionsConfig<TContext, TEvent>;
311
- /**
312
- * The action(s) to be executed upon entering the state node.
313
- *
314
- * @deprecated Use `entry` instead.
315
- */
316
- onEntry?: Actions<TContext, TEvent>;
317
- /**
318
- * The action(s) to be executed upon entering the state node.
319
- */
320
- entry?: Actions<TContext, TEvent>;
321
- /**
322
- * The action(s) to be executed upon exiting the state node.
323
- *
324
- * @deprecated Use `exit` instead.
325
- */
326
- onExit?: Actions<TContext, TEvent>;
327
- /**
328
- * The action(s) to be executed upon exiting the state node.
329
- */
330
- exit?: Actions<TContext, TEvent>;
331
- /**
332
- * The potential transition(s) to be taken upon reaching a final child state node.
333
- *
334
- * This is equivalent to defining a `[done(id)]` transition on this state node's `on` property.
335
- */
336
- onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneEventObject>>;
337
- /**
338
- * The mapping (or array) of delays (in milliseconds) to their potential transition(s).
339
- * The delayed transitions are taken after the specified delay in an interpreter.
340
- */
341
- after?: DelayedTransitions<TContext, TEvent>;
342
- /**
343
- * An eventless transition that is always taken when this state node is active.
344
- * Equivalent to a transition specified as an empty `''`' string in the `on` property.
345
- */
346
- always?: TransitionConfigOrTarget<TContext, TEvent>;
347
- /**
348
- * The activities to be started upon entering the state node,
349
- * and stopped upon exiting the state node.
350
- */
351
- activities?: SingleOrArray<Activity<TContext, TEvent>>;
352
- /**
353
- * @private
354
- */
355
- parent?: StateNode<TContext, any, TEvent>;
356
- strict?: boolean | undefined;
357
- /**
358
- * The meta data associated with this state node, which will be returned in State instances.
359
- */
360
- meta?: TStateSchema extends {
361
- meta: infer D;
362
- } ? D : any;
363
- /**
364
- * The data sent with the "done.state._id_" event if this is a final state node.
365
- *
366
- * The data will be evaluated with the current `context` and placed on the `.data` property
367
- * of the event.
368
- */
369
- data?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
370
- /**
371
- * The unique ID of the state node, which can be referenced as a transition target via the
372
- * `#id` syntax.
373
- */
374
- id?: string | undefined;
375
- /**
376
- * The string delimiter for serializing the path to a string. The default is "."
377
- */
378
- delimiter?: string;
379
- /**
380
- * The order this state node appears. Corresponds to the implicit SCXML document order.
381
- */
382
- order?: number;
383
- /**
384
- * The tags for this state node, which are accumulated into the `state.tags` property.
385
- */
386
- tags?: SingleOrArray<string>;
387
- }
388
- export interface StateNodeDefinition<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> {
389
- id: string;
390
- version: string | undefined;
391
- key: string;
392
- context: TContext;
393
- type: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
394
- initial: StateNodeConfig<TContext, TStateSchema, TEvent>['initial'];
395
- history: boolean | 'shallow' | 'deep' | undefined;
396
- states: StatesDefinition<TContext, TStateSchema, TEvent>;
397
- on: TransitionDefinitionMap<TContext, TEvent>;
398
- transitions: Array<TransitionDefinition<TContext, TEvent>>;
399
- entry: Array<ActionObject<TContext, TEvent>>;
400
- exit: Array<ActionObject<TContext, TEvent>>;
401
- activities: Array<ActivityDefinition<TContext, TEvent>>;
402
- meta: any;
403
- order: number;
404
- data?: FinalStateNodeConfig<TContext, TEvent>['data'];
405
- invoke: Array<InvokeDefinition<TContext, TEvent>>;
406
- }
407
- export declare type AnyStateNodeDefinition = StateNodeDefinition<any, any, any>;
408
- export interface AtomicStateNodeConfig<TContext, TEvent extends EventObject> extends StateNodeConfig<TContext, StateSchema, TEvent> {
409
- initial?: undefined;
410
- parallel?: false | undefined;
411
- states?: undefined;
412
- onDone?: undefined;
413
- }
414
- export interface HistoryStateNodeConfig<TContext, TEvent extends EventObject> extends AtomicStateNodeConfig<TContext, TEvent> {
415
- history: 'shallow' | 'deep' | true;
416
- target: StateValue | undefined;
417
- }
418
- export interface FinalStateNodeConfig<TContext, TEvent extends EventObject> extends AtomicStateNodeConfig<TContext, TEvent> {
419
- type: 'final';
420
- /**
421
- * The data to be sent with the "done.state.<id>" event. The data can be
422
- * static or dynamic (based on assigners).
423
- */
424
- data?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
425
- }
426
- export declare type SimpleOrStateNodeConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TStateSchema, TEvent>;
427
- export declare type ActionFunctionMap<TContext, TEvent extends EventObject> = Record<string, ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent>>;
428
- export declare type DelayFunctionMap<TContext, TEvent extends EventObject> = Record<string, DelayConfig<TContext, TEvent>>;
429
- export declare type ServiceConfig<TContext, TEvent extends EventObject = AnyEventObject> = string | StateMachine<any, any, any> | InvokeCreator<TContext, TEvent>;
430
- export declare type DelayConfig<TContext, TEvent extends EventObject> = number | DelayExpr<TContext, TEvent>;
431
- export interface MachineOptions<TContext, TEvent extends EventObject> {
432
- guards: Record<string, ConditionPredicate<TContext, TEvent>>;
433
- actions: ActionFunctionMap<TContext, TEvent>;
434
- activities: Record<string, ActivityConfig<TContext, TEvent>>;
435
- services: Record<string, ServiceConfig<TContext, TEvent>>;
436
- delays: DelayFunctionMap<TContext, TEvent>;
437
- /**
438
- * @private
439
- */
440
- _parent?: StateNode<TContext, any, TEvent, any>;
441
- /**
442
- * @private
443
- */
444
- _key?: string;
445
- }
446
- export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> extends StateNodeConfig<TContext, TStateSchema, TEvent> {
447
- /**
448
- * The initial context (extended state)
449
- */
450
- context?: TContext | (() => TContext);
451
- /**
452
- * The machine's own version.
453
- */
454
- version?: string;
455
- schema?: MachineSchema<TContext, TEvent>;
456
- }
457
- export interface MachineSchema<TContext, TEvent extends EventObject> {
458
- context?: TContext;
459
- events?: TEvent;
460
- actions?: {
461
- type: string;
462
- [key: string]: any;
463
- };
464
- guards?: {
465
- type: string;
466
- [key: string]: any;
467
- };
468
- services?: {
469
- type: string;
470
- [key: string]: any;
471
- };
472
- }
473
- export interface StandardMachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> extends StateNodeConfig<TContext, TStateSchema, TEvent> {
474
- }
475
- export interface ParallelMachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> extends StateNodeConfig<TContext, TStateSchema, TEvent> {
476
- initial?: undefined;
477
- type?: 'parallel';
478
- }
479
- export interface EntryExitEffectMap<TContext, TEvent extends EventObject> {
480
- entry: Array<ActionObject<TContext, TEvent>>;
481
- exit: Array<ActionObject<TContext, TEvent>>;
482
- }
483
- export interface HistoryStateNode<TContext> extends StateNode<TContext> {
484
- history: 'shallow' | 'deep';
485
- target: StateValue | undefined;
486
- }
487
- export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
488
- value: any;
489
- context: TContext;
490
- }> extends StateNode<TContext, TStateSchema, TEvent, TTypestate> {
491
- id: string;
492
- states: StateNode<TContext, TStateSchema, TEvent>['states'];
493
- withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
494
- withContext(context: TContext): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
495
- }
496
- export declare type StateFrom<TMachine extends StateMachine<any, any, any>> = ReturnType<TMachine['transition']>;
497
- export interface ActionMap<TContext, TEvent extends EventObject> {
498
- onEntry: Array<Action<TContext, TEvent>>;
499
- actions: Array<Action<TContext, TEvent>>;
500
- onExit: Array<Action<TContext, TEvent>>;
501
- }
502
- export interface EntryExitStates<TContext> {
503
- entry: Set<StateNode<TContext>>;
504
- exit: Set<StateNode<TContext>>;
505
- }
506
- export interface EntryExitStateArrays<TContext> {
507
- entry: Array<StateNode<TContext>>;
508
- exit: Array<StateNode<TContext>>;
509
- }
510
- export interface ActivityMap {
511
- [activityKey: string]: ActivityDefinition<any, any> | false;
512
- }
513
- export interface StateTransition<TContext, TEvent extends EventObject> {
514
- transitions: Array<TransitionDefinition<TContext, TEvent>>;
515
- configuration: Array<StateNode<TContext, any, TEvent, any>>;
516
- entrySet: Array<StateNode<TContext, any, TEvent, any>>;
517
- exitSet: Array<StateNode<TContext, any, TEvent, any>>;
518
- /**
519
- * The source state that preceded the transition.
520
- */
521
- source: State<TContext, any, any, any> | undefined;
522
- actions: Array<ActionObject<TContext, TEvent>>;
523
- }
524
- export interface TransitionData<TContext, TEvent extends EventObject> {
525
- value: StateValue | undefined;
526
- actions: ActionMap<TContext, TEvent>;
527
- activities?: ActivityMap;
528
- }
529
- export declare enum ActionTypes {
530
- Start = "xstate.start",
531
- Stop = "xstate.stop",
532
- Raise = "xstate.raise",
533
- Send = "xstate.send",
534
- Cancel = "xstate.cancel",
535
- NullEvent = "",
536
- Assign = "xstate.assign",
537
- After = "xstate.after",
538
- DoneState = "done.state",
539
- DoneInvoke = "done.invoke",
540
- Log = "xstate.log",
541
- Init = "xstate.init",
542
- Invoke = "xstate.invoke",
543
- ErrorExecution = "error.execution",
544
- ErrorCommunication = "error.communication",
545
- ErrorPlatform = "error.platform",
546
- ErrorCustom = "xstate.error",
547
- Update = "xstate.update",
548
- Pure = "xstate.pure",
549
- Choose = "xstate.choose"
550
- }
551
- export interface RaiseAction<TEvent extends EventObject> {
552
- type: ActionTypes.Raise;
553
- event: TEvent['type'];
554
- }
555
- export interface RaiseActionObject<TEvent extends EventObject> {
556
- type: ActionTypes.Raise;
557
- _event: SCXML.Event<TEvent>;
558
- }
559
- export interface DoneInvokeEvent<TData> extends EventObject {
560
- data: TData;
561
- }
562
- export interface ErrorExecutionEvent extends EventObject {
563
- src: string;
564
- type: ActionTypes.ErrorExecution;
565
- data: any;
566
- }
567
- export interface ErrorPlatformEvent extends EventObject {
568
- data: any;
569
- }
570
- export interface DoneEventObject extends EventObject {
571
- data?: any;
572
- toString(): string;
573
- }
574
- export interface UpdateObject extends EventObject {
575
- id: string | number;
576
- state: State<any, any>;
577
- }
578
- export declare type DoneEvent = DoneEventObject & string;
579
- export interface NullEvent {
580
- type: ActionTypes.NullEvent;
581
- }
582
- export interface ActivityActionObject<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
583
- type: ActionTypes.Start | ActionTypes.Stop;
584
- activity: ActivityDefinition<TContext, TEvent> | undefined;
585
- exec: ActionFunction<TContext, TEvent> | undefined;
586
- }
587
- export interface InvokeActionObject<TContext, TEvent extends EventObject> extends ActivityActionObject<TContext, TEvent> {
588
- activity: InvokeDefinition<TContext, TEvent>;
589
- }
590
- export declare type DelayExpr<TContext, TEvent extends EventObject> = ExprWithMeta<TContext, TEvent, number>;
591
- export declare type LogExpr<TContext, TEvent extends EventObject> = ExprWithMeta<TContext, TEvent, any>;
592
- export interface LogAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
593
- label: string | undefined;
594
- expr: string | LogExpr<TContext, TEvent>;
595
- }
596
- export interface LogActionObject<TContext, TEvent extends EventObject> extends LogAction<TContext, TEvent> {
597
- value: any;
598
- }
599
- export interface SendAction<TContext, TEvent extends EventObject, TSentEvent extends EventObject> extends ActionObject<TContext, TEvent> {
600
- to: string | number | ActorRef<any> | ExprWithMeta<TContext, TEvent, string | number | ActorRef<any>> | undefined;
601
- event: TSentEvent | SendExpr<TContext, TEvent, TSentEvent>;
602
- delay?: number | string | DelayExpr<TContext, TEvent>;
603
- id: string | number;
604
- }
605
- export interface SendActionObject<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject> extends SendAction<TContext, TEvent, TSentEvent> {
606
- to: string | number | ActorRef<any> | undefined;
607
- _event: SCXML.Event<TSentEvent>;
608
- event: TSentEvent;
609
- delay?: number;
610
- id: string | number;
611
- }
612
- export interface StopAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
613
- type: ActionTypes.Stop;
614
- activity: string | {
615
- id: string;
616
- } | Expr<TContext, TEvent, string | {
617
- id: string;
618
- }>;
619
- }
620
- export interface StopActionObject {
621
- type: ActionTypes.Stop;
622
- activity: {
623
- id: string;
624
- };
625
- }
626
- export declare type Expr<TContext, TEvent extends EventObject, T> = (context: TContext, event: TEvent) => T;
627
- export declare type ExprWithMeta<TContext, TEvent extends EventObject, T> = (context: TContext, event: TEvent, meta: SCXMLEventMeta<TEvent>) => T;
628
- export declare type SendExpr<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject> = ExprWithMeta<TContext, TEvent, TSentEvent>;
629
- export declare enum SpecialTargets {
630
- Parent = "#_parent",
631
- Internal = "#_internal"
632
- }
633
- export interface SendActionOptions<TContext, TEvent extends EventObject> {
634
- id?: string | number;
635
- delay?: number | string | DelayExpr<TContext, TEvent>;
636
- to?: string | ExprWithMeta<TContext, TEvent, string | number | ActorRef<any>>;
637
- }
638
- export interface CancelAction extends ActionObject<any, any> {
639
- sendId: string | number;
640
- }
641
- export declare type Assigner<TContext, TEvent extends EventObject> = (context: TContext, event: TEvent, meta: AssignMeta<TContext, TEvent>) => Partial<TContext>;
642
- export declare type PartialAssigner<TContext, TEvent extends EventObject, TKey extends keyof TContext> = (context: TContext, event: TEvent, meta: AssignMeta<TContext, TEvent>) => TContext[TKey];
643
- export declare type PropertyAssigner<TContext, TEvent extends EventObject> = {
644
- [K in keyof TContext]?: PartialAssigner<TContext, TEvent, K> | TContext[K];
645
- };
646
- export declare type Mapper<TContext, TEvent extends EventObject, TParams extends {}> = (context: TContext, event: TEvent) => TParams;
647
- export declare type PropertyMapper<TContext, TEvent extends EventObject, TParams extends {}> = {
648
- [K in keyof TParams]?: ((context: TContext, event: TEvent) => TParams[K]) | TParams[K];
649
- };
650
- export interface AnyAssignAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
651
- type: ActionTypes.Assign;
652
- assignment: any;
653
- }
654
- export interface AssignAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
655
- type: ActionTypes.Assign;
656
- assignment: Assigner<TContext, TEvent> | PropertyAssigner<TContext, TEvent>;
657
- }
658
- export interface PureAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
659
- type: ActionTypes.Pure;
660
- get: (context: TContext, event: TEvent) => SingleOrArray<ActionObject<TContext, TEvent>> | undefined;
661
- }
662
- export interface ChooseAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
663
- type: ActionTypes.Choose;
664
- conds: Array<ChooseConditon<TContext, TEvent>>;
665
- }
666
- export interface TransitionDefinition<TContext, TEvent extends EventObject> extends TransitionConfig<TContext, TEvent> {
667
- target: Array<StateNode<TContext, any, TEvent>> | undefined;
668
- source: StateNode<TContext, any, TEvent>;
669
- actions: Array<ActionObject<TContext, TEvent>>;
670
- cond?: Guard<TContext, TEvent>;
671
- eventType: TEvent['type'] | NullEvent['type'] | '*';
672
- toJSON: () => {
673
- target: string[] | undefined;
674
- source: string;
675
- actions: Array<ActionObject<TContext, TEvent>>;
676
- cond?: Guard<TContext, TEvent>;
677
- eventType: TEvent['type'] | NullEvent['type'] | '*';
678
- meta?: Record<string, any>;
679
- };
680
- }
681
- export declare type TransitionDefinitionMap<TContext, TEvent extends EventObject> = {
682
- [K in TEvent['type'] | NullEvent['type'] | '*']: Array<TransitionDefinition<TContext, K extends TEvent['type'] ? Extract<TEvent, {
683
- type: K;
684
- }> : EventObject>>;
685
- };
686
- export interface DelayedTransitionDefinition<TContext, TEvent extends EventObject> extends TransitionDefinition<TContext, TEvent> {
687
- delay: number | string | DelayExpr<TContext, TEvent>;
688
- }
689
- export interface Edge<TContext, TEvent extends EventObject, TEventType extends TEvent['type'] = string> {
690
- event: TEventType;
691
- source: StateNode<TContext, any, TEvent>;
692
- target: StateNode<TContext, any, TEvent>;
693
- cond?: Condition<TContext, TEvent & {
694
- type: TEventType;
695
- }>;
696
- actions: Array<Action<TContext, TEvent>>;
697
- meta?: MetaObject;
698
- transition: TransitionDefinition<TContext, TEvent>;
699
- }
700
- export interface NodesAndEdges<TContext, TEvent extends EventObject> {
701
- nodes: StateNode[];
702
- edges: Array<Edge<TContext, TEvent, TEvent['type']>>;
703
- }
704
- export interface Segment<TContext, TEvent extends EventObject> {
705
- /**
706
- * From state.
707
- */
708
- state: State<TContext, TEvent>;
709
- /**
710
- * Event from state.
711
- */
712
- event: TEvent;
713
- }
714
- export interface PathItem<TContext, TEvent extends EventObject> {
715
- state: State<TContext, TEvent>;
716
- path: Array<Segment<TContext, TEvent>>;
717
- weight?: number;
718
- }
719
- export interface PathMap<TContext, TEvent extends EventObject> {
720
- [key: string]: PathItem<TContext, TEvent>;
721
- }
722
- export interface PathsItem<TContext, TEvent extends EventObject> {
723
- state: State<TContext, TEvent>;
724
- paths: Array<Array<Segment<TContext, TEvent>>>;
725
- }
726
- export interface PathsMap<TContext, TEvent extends EventObject> {
727
- [key: string]: PathsItem<TContext, TEvent>;
728
- }
729
- export interface TransitionMap {
730
- state: StateValue | undefined;
731
- }
732
- export interface AdjacencyMap {
733
- [stateId: string]: Record<string, TransitionMap>;
734
- }
735
- export interface ValueAdjacencyMap<TContext, TEvent extends EventObject> {
736
- [stateId: string]: Record<string, State<TContext, TEvent>>;
737
- }
738
- export interface SCXMLEventMeta<TEvent extends EventObject> {
739
- _event: SCXML.Event<TEvent>;
740
- }
741
- export interface StateMeta<TContext, TEvent extends EventObject> {
742
- state: State<TContext, TEvent, any, any>;
743
- _event: SCXML.Event<TEvent>;
744
- }
745
- export interface Typestate<TContext> {
746
- value: StateValue;
747
- context: TContext;
748
- }
749
- export interface StateLike<TContext> {
750
- value: StateValue;
751
- context: TContext;
752
- event: EventObject;
753
- _event: SCXML.Event<EventObject>;
754
- }
755
- export interface StateConfig<TContext, TEvent extends EventObject> {
756
- value: StateValue;
757
- context: TContext;
758
- _event: SCXML.Event<TEvent>;
759
- _sessionid: string | null;
760
- historyValue?: HistoryValue | undefined;
761
- history?: State<TContext, TEvent>;
762
- actions?: Array<ActionObject<TContext, TEvent>>;
763
- activities?: ActivityMap;
764
- meta?: any;
765
- events?: TEvent[];
766
- configuration: Array<StateNode<TContext, any, TEvent>>;
767
- transitions: Array<TransitionDefinition<TContext, TEvent>>;
768
- children: Record<string, ActorRef<any>>;
769
- done?: boolean;
770
- tags?: Set<string>;
771
- }
772
- export interface StateSchema<TC = any> {
773
- meta?: any;
774
- context?: Partial<TC>;
775
- states?: {
776
- [key: string]: StateSchema<TC>;
777
- };
778
- }
779
- export interface InterpreterOptions {
780
- /**
781
- * Whether state actions should be executed immediately upon transition. Defaults to `true`.
782
- */
783
- execute: boolean;
784
- clock: Clock;
785
- logger: (...args: any[]) => void;
786
- parent?: AnyInterpreter;
787
- /**
788
- * If `true`, defers processing of sent events until the service
789
- * is initialized (`.start()`). Otherwise, an error will be thrown
790
- * for events sent to an uninitialized service.
791
- *
792
- * Default: `true`
793
- */
794
- deferEvents: boolean;
795
- /**
796
- * The custom `id` for referencing this service.
797
- */
798
- id?: string;
799
- /**
800
- * If `true`, states and events will be logged to Redux DevTools.
801
- *
802
- * Default: `false`
803
- */
804
- devTools: boolean | object;
805
- [option: string]: any;
806
- }
807
- export declare namespace SCXML {
808
- interface Event<TEvent extends EventObject> {
809
- /**
810
- * This is a character string giving the name of the event.
811
- * The SCXML Processor must set the name field to the name of this event.
812
- * It is what is matched against the 'event' attribute of <transition>.
813
- * Note that transitions can do additional tests by using the value of this field
814
- * inside boolean expressions in the 'cond' attribute.
815
- */
816
- name: string;
817
- /**
818
- * This field describes the event type.
819
- * The SCXML Processor must set it to: "platform" (for events raised by the platform itself, such as error events),
820
- * "internal" (for events raised by <raise> and <send> with target '_internal')
821
- * or "external" (for all other events).
822
- */
823
- type: 'platform' | 'internal' | 'external';
824
- /**
825
- * If the sending entity has specified a value for this, the Processor must set this field to that value
826
- * (see C Event I/O Processors for details).
827
- * Otherwise, in the case of error events triggered by a failed attempt to send an event,
828
- * the Processor must set this field to the send id of the triggering <send> element.
829
- * Otherwise it must leave it blank.
830
- */
831
- sendid?: string;
832
- /**
833
- * This is a URI, equivalent to the 'target' attribute on the <send> element.
834
- * For external events, the SCXML Processor should set this field to a value which,
835
- * when used as the value of 'target', will allow the receiver of the event to <send>
836
- * a response back to the originating entity via the Event I/O Processor specified in 'origintype'.
837
- * For internal and platform events, the Processor must leave this field blank.
838
- */
839
- origin?: string;
840
- /**
841
- * This is equivalent to the 'type' field on the <send> element.
842
- * For external events, the SCXML Processor should set this field to a value which,
843
- * when used as the value of 'type', will allow the receiver of the event to <send>
844
- * a response back to the originating entity at the URI specified by 'origin'.
845
- * For internal and platform events, the Processor must leave this field blank.
846
- */
847
- origintype?: string;
848
- /**
849
- * If this event is generated from an invoked child process, the SCXML Processor
850
- * must set this field to the invoke id of the invocation that triggered the child process.
851
- * Otherwise it must leave it blank.
852
- */
853
- invokeid?: string;
854
- /**
855
- * This field contains whatever data the sending entity chose to include in this event.
856
- * The receiving SCXML Processor should reformat this data to match its data model,
857
- * but must not otherwise modify it.
858
- *
859
- * If the conversion is not possible, the Processor must leave the field blank
860
- * and must place an error 'error.execution' in the internal event queue.
861
- */
862
- data: TEvent;
863
- /**
864
- * @private
865
- */
866
- $$type: 'scxml';
867
- }
868
- }
869
- export interface Observer<T> {
870
- next: (value: T) => void;
871
- error: (err: any) => void;
872
- complete: () => void;
873
- }
874
- export interface Subscription {
875
- unsubscribe(): void;
876
- }
877
- export interface Subscribable<T> {
878
- subscribe(observer: Observer<T>): Subscription;
879
- subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
880
- }
881
- export declare type Spawnable = StateMachine<any, any, any> | Promise<any> | InvokeCallback | Subscribable<any>;
882
- export declare type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
883
- type: TEventType;
884
- } ? TEvent : never;
885
- export interface BaseActorRef<TEvent extends EventObject> {
886
- send: (event: TEvent) => void;
887
- }
888
- export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted> {
889
- send: Sender<TEvent>;
890
- id: string;
891
- getSnapshot: () => TEmitted | undefined;
892
- stop?: () => void;
893
- toJSON?: () => any;
894
- }
895
- /**
896
- * @deprecated Use `ActorRef` instead.
897
- */
898
- export declare type SpawnedActorRef<TEvent extends EventObject, TEmitted = any> = ActorRef<TEvent, TEmitted>;
899
- export declare type ActorRefFrom<T extends StateMachine<any, any, any> | Promise<any>> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRef<TEvent, State<TContext, TEvent, any, TTypestate>> & {
900
- /**
901
- * @deprecated Use `.getSnapshot()` instead.
902
- */
903
- state: State<TContext, TEvent, any, TTypestate>;
904
- } : T extends Promise<infer U> ? ActorRef<never, U> : never;
905
- export declare type AnyInterpreter = Interpreter<any, any, any, any>;
906
- export declare type InterpreterFrom<T extends StateMachine<any, any, any, any>> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : never;
907
- export {};
1
+ import { StateNode } from './StateNode';
2
+ import { State } from './State';
3
+ import { Interpreter, Clock } from './interpreter';
4
+ import { Model } from './model.types';
5
+ export declare type EventType = string;
6
+ export declare type ActionType = string;
7
+ export declare type MetaObject = Record<string, any>;
8
+ /**
9
+ * The full definition of an event, with a string `type`.
10
+ */
11
+ export interface EventObject {
12
+ /**
13
+ * The type of event that is sent.
14
+ */
15
+ type: string;
16
+ }
17
+ export interface AnyEventObject extends EventObject {
18
+ [key: string]: any;
19
+ }
20
+ /**
21
+ * The full definition of an action, with a string `type` and an
22
+ * `exec` implementation function.
23
+ */
24
+ export interface ActionObject<TContext, TEvent extends EventObject> {
25
+ /**
26
+ * The type of action that is executed.
27
+ */
28
+ type: string;
29
+ /**
30
+ * The implementation for executing the action.
31
+ */
32
+ exec?: ActionFunction<TContext, TEvent>;
33
+ [other: string]: any;
34
+ }
35
+ export declare type DefaultContext = Record<string, any> | undefined;
36
+ export declare type EventData = Record<string, any> & {
37
+ type?: never;
38
+ };
39
+ /**
40
+ * The specified string event types or the specified event objects.
41
+ */
42
+ export declare type Event<TEvent extends EventObject> = TEvent['type'] | TEvent;
43
+ export interface ActionMeta<TContext, TEvent extends EventObject> extends StateMeta<TContext, TEvent> {
44
+ action: ActionObject<TContext, TEvent>;
45
+ _event: SCXML.Event<TEvent>;
46
+ }
47
+ export interface AssignMeta<TContext, TEvent extends EventObject> {
48
+ state?: State<TContext, TEvent>;
49
+ action: AssignAction<TContext, TEvent>;
50
+ _event: SCXML.Event<TEvent>;
51
+ }
52
+ export declare type ActionFunction<TContext, TEvent extends EventObject> = (context: TContext, event: TEvent, meta: ActionMeta<TContext, TEvent>) => void;
53
+ export interface ChooseConditon<TContext, TEvent extends EventObject> {
54
+ cond?: Condition<TContext, TEvent>;
55
+ actions: Actions<TContext, TEvent>;
56
+ }
57
+ export declare type Action<TContext, TEvent extends EventObject> = ActionType | ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent>;
58
+ export declare type Actions<TContext, TEvent extends EventObject> = SingleOrArray<Action<TContext, TEvent>>;
59
+ export declare type StateKey = string | State<any>;
60
+ export interface StateValueMap {
61
+ [key: string]: StateValue;
62
+ }
63
+ /**
64
+ * The string or object representing the state value relative to the parent state node.
65
+ *
66
+ * - For a child atomic state node, this is a string, e.g., `"pending"`.
67
+ * - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
68
+ */
69
+ export declare type StateValue = string | StateValueMap;
70
+ declare type KeysWithStates<TStates extends Record<string, StateSchema> | undefined> = TStates extends object ? {
71
+ [K in keyof TStates]-?: TStates[K] extends {
72
+ states: object;
73
+ } ? K : never;
74
+ }[keyof TStates] : never;
75
+ export declare type ExtractStateValue<TSchema extends Required<Pick<StateSchema<any>, 'states'>>> = keyof TSchema['states'] | (KeysWithStates<TSchema['states']> extends never ? never : {
76
+ [K in KeysWithStates<TSchema['states']>]?: ExtractStateValue<TSchema['states'][K]>;
77
+ });
78
+ export interface HistoryValue {
79
+ states: Record<string, HistoryValue | undefined>;
80
+ current: StateValue | undefined;
81
+ }
82
+ export declare type ConditionPredicate<TContext, TEvent extends EventObject> = (context: TContext, event: TEvent, meta: GuardMeta<TContext, TEvent>) => boolean;
83
+ export declare type DefaultGuardType = 'xstate.guard';
84
+ export interface GuardPredicate<TContext, TEvent extends EventObject> {
85
+ type: DefaultGuardType;
86
+ name: string | undefined;
87
+ predicate: ConditionPredicate<TContext, TEvent>;
88
+ }
89
+ export declare type Guard<TContext, TEvent extends EventObject> = GuardPredicate<TContext, TEvent> | (Record<string, any> & {
90
+ type: string;
91
+ });
92
+ export interface GuardMeta<TContext, TEvent extends EventObject> extends StateMeta<TContext, TEvent> {
93
+ cond: Guard<TContext, TEvent>;
94
+ }
95
+ export declare type Condition<TContext, TEvent extends EventObject> = string | ConditionPredicate<TContext, TEvent> | Guard<TContext, TEvent>;
96
+ export declare type TransitionTarget<TContext, TEvent extends EventObject> = SingleOrArray<string | StateNode<TContext, any, TEvent>>;
97
+ export declare type TransitionTargets<TContext> = Array<string | StateNode<TContext, any>>;
98
+ export interface TransitionConfig<TContext, TEvent extends EventObject> {
99
+ cond?: Condition<TContext, TEvent>;
100
+ actions?: Actions<TContext, TEvent>;
101
+ in?: StateValue;
102
+ internal?: boolean;
103
+ target?: TransitionTarget<TContext, TEvent>;
104
+ meta?: Record<string, any>;
105
+ }
106
+ export interface TargetTransitionConfig<TContext, TEvent extends EventObject> extends TransitionConfig<TContext, TEvent> {
107
+ target: TransitionTarget<TContext, TEvent>;
108
+ }
109
+ export declare type ConditionalTransitionConfig<TContext, TEvent extends EventObject = EventObject> = Array<TransitionConfig<TContext, TEvent>>;
110
+ export declare type Transition<TContext, TEvent extends EventObject = EventObject> = string | TransitionConfig<TContext, TEvent> | ConditionalTransitionConfig<TContext, TEvent>;
111
+ export declare type DisposeActivityFunction = () => void;
112
+ export declare type ActivityConfig<TContext, TEvent extends EventObject> = (ctx: TContext, activity: ActivityDefinition<TContext, TEvent>) => DisposeActivityFunction | void;
113
+ export declare type Activity<TContext, TEvent extends EventObject> = string | ActivityDefinition<TContext, TEvent>;
114
+ export interface ActivityDefinition<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
115
+ id: string;
116
+ type: string;
117
+ }
118
+ export declare type Sender<TEvent extends EventObject> = (event: Event<TEvent>) => void;
119
+ declare type ExcludeType<A> = {
120
+ [K in Exclude<keyof A, 'type'>]: A[K];
121
+ };
122
+ declare type ExtractExtraParameters<A, T> = A extends {
123
+ type: T;
124
+ } ? ExcludeType<A> : never;
125
+ declare type ExtractSimple<A> = A extends any ? {} extends ExcludeType<A> ? A : never : never;
126
+ declare type NeverIfEmpty<T> = {} extends T ? never : T;
127
+ export interface PayloadSender<TEvent extends EventObject> {
128
+ /**
129
+ * Send an event object or just the event type, if the event has no other payload
130
+ */
131
+ (event: TEvent | ExtractSimple<TEvent>['type']): void;
132
+ /**
133
+ * Send an event type and its payload
134
+ */
135
+ <K extends TEvent['type']>(eventType: K, payload: NeverIfEmpty<ExtractExtraParameters<TEvent, K>>): void;
136
+ }
137
+ export declare type Receiver<TEvent extends EventObject> = (listener: (event: TEvent) => void) => void;
138
+ export declare type InvokeCallback<TEvent extends EventObject = AnyEventObject, TSentEvent extends EventObject = AnyEventObject> = (callback: Sender<TSentEvent>, onReceive: Receiver<TEvent>) => (() => void) | Promise<any> | void;
139
+ export interface InvokeMeta {
140
+ data: any;
141
+ src: InvokeSourceDefinition;
142
+ }
143
+ /**
144
+ * Returns either a Promises or a callback handler (for streams of events) given the
145
+ * machine's current `context` and `event` that invoked the service.
146
+ *
147
+ * For Promises, the only events emitted to the parent will be:
148
+ * - `done.invoke.<id>` with the `data` containing the resolved payload when the promise resolves, or:
149
+ * - `error.platform.<id>` with the `data` containing the caught error, and `src` containing the service `id`.
150
+ *
151
+ * For callback handlers, the `callback` will be provided, which will send events to the parent service.
152
+ *
153
+ * @param context The current machine `context`
154
+ * @param event The event that invoked the service
155
+ */
156
+ export declare type InvokeCreator<TContext, TEvent extends EventObject, TFinalContext = any> = (context: TContext, event: TEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<EventObject> | InvokeCallback<any, TEvent> | Behavior<any>;
157
+ export interface InvokeDefinition<TContext, TEvent extends EventObject> extends ActivityDefinition<TContext, TEvent> {
158
+ /**
159
+ * The source of the machine to be invoked, or the machine itself.
160
+ */
161
+ src: string | InvokeSourceDefinition;
162
+ /**
163
+ * If `true`, events sent to the parent service will be forwarded to the invoked service.
164
+ *
165
+ * Default: `false`
166
+ */
167
+ autoForward?: boolean;
168
+ /**
169
+ * @deprecated
170
+ *
171
+ * Use `autoForward` property instead of `forward`. Support for `forward` will get removed in the future.
172
+ */
173
+ forward?: boolean;
174
+ /**
175
+ * Data from the parent machine's context to set as the (partial or full) context
176
+ * for the invoked child machine.
177
+ *
178
+ * Data should be mapped to match the child machine's context shape.
179
+ */
180
+ data?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
181
+ }
182
+ export interface Delay {
183
+ id: string;
184
+ /**
185
+ * The time to delay the event, in milliseconds.
186
+ */
187
+ delay: number;
188
+ }
189
+ export declare type DelayedTransitions<TContext, TEvent extends EventObject> = Record<string | number, string | SingleOrArray<TransitionConfig<TContext, TEvent>>> | Array<TransitionConfig<TContext, TEvent> & {
190
+ delay: number | string | Expr<TContext, TEvent, number>;
191
+ }>;
192
+ export declare type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | string;
193
+ export declare type SingleOrArray<T> = T[] | T;
194
+ export declare type StateNodesConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = {
195
+ [K in keyof TStateSchema['states']]: StateNode<TContext, TStateSchema['states'][K], TEvent>;
196
+ };
197
+ export declare type StatesConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = {
198
+ [K in keyof TStateSchema['states']]: StateNodeConfig<TContext, TStateSchema['states'][K], TEvent>;
199
+ };
200
+ export declare type StatesDefinition<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = {
201
+ [K in keyof TStateSchema['states']]: StateNodeDefinition<TContext, TStateSchema['states'][K], TEvent>;
202
+ };
203
+ export declare type TransitionConfigTarget<TContext, TEvent extends EventObject> = string | undefined | StateNode<TContext, any, TEvent>;
204
+ export declare type TransitionConfigOrTarget<TContext, TEvent extends EventObject> = SingleOrArray<TransitionConfigTarget<TContext, TEvent> | TransitionConfig<TContext, TEvent>>;
205
+ export declare type TransitionsConfigMap<TContext, TEvent extends EventObject> = {
206
+ [K in TEvent['type']]?: TransitionConfigOrTarget<TContext, TEvent extends {
207
+ type: K;
208
+ } ? TEvent : never>;
209
+ } & {
210
+ ''?: TransitionConfigOrTarget<TContext, TEvent>;
211
+ } & {
212
+ '*'?: TransitionConfigOrTarget<TContext, TEvent>;
213
+ };
214
+ declare type TransitionsConfigArray<TContext, TEvent extends EventObject> = Array<(TEvent extends EventObject ? TransitionConfig<TContext, TEvent> & {
215
+ event: TEvent['type'];
216
+ } : never) | (TransitionConfig<TContext, TEvent> & {
217
+ event: '';
218
+ }) | (TransitionConfig<TContext, TEvent> & {
219
+ event: '*';
220
+ })>;
221
+ export declare type TransitionsConfig<TContext, TEvent extends EventObject> = TransitionsConfigMap<TContext, TEvent> | TransitionsConfigArray<TContext, TEvent>;
222
+ export interface InvokeSourceDefinition {
223
+ [key: string]: any;
224
+ type: string;
225
+ }
226
+ export interface InvokeConfig<TContext, TEvent extends EventObject> {
227
+ /**
228
+ * The unique identifier for the invoked machine. If not specified, this
229
+ * will be the machine's own `id`, or the URL (from `src`).
230
+ */
231
+ id?: string;
232
+ /**
233
+ * The source of the machine to be invoked, or the machine itself.
234
+ */
235
+ src: string | InvokeSourceDefinition | StateMachine<any, any, any> | InvokeCreator<TContext, TEvent, any>;
236
+ /**
237
+ * If `true`, events sent to the parent service will be forwarded to the invoked service.
238
+ *
239
+ * Default: `false`
240
+ */
241
+ autoForward?: boolean;
242
+ /**
243
+ * @deprecated
244
+ *
245
+ * Use `autoForward` property instead of `forward`. Support for `forward` will get removed in the future.
246
+ */
247
+ forward?: boolean;
248
+ /**
249
+ * Data from the parent machine's context to set as the (partial or full) context
250
+ * for the invoked child machine.
251
+ *
252
+ * Data should be mapped to match the child machine's context shape.
253
+ */
254
+ data?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
255
+ /**
256
+ * The transition to take upon the invoked child machine reaching its final top-level state.
257
+ */
258
+ onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneInvokeEvent<any>>>;
259
+ /**
260
+ * The transition to take upon the invoked child machine sending an error event.
261
+ */
262
+ onError?: string | SingleOrArray<TransitionConfig<TContext, DoneInvokeEvent<any>>>;
263
+ }
264
+ export interface StateNodeConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> {
265
+ /**
266
+ * The relative key of the state node, which represents its location in the overall state value.
267
+ * This is automatically determined by the configuration shape via the key where it was defined.
268
+ */
269
+ key?: string;
270
+ /**
271
+ * The initial state node key.
272
+ */
273
+ initial?: keyof TStateSchema['states'] | undefined;
274
+ /**
275
+ * @deprecated
276
+ */
277
+ parallel?: boolean | undefined;
278
+ /**
279
+ * The type of this state node:
280
+ *
281
+ * - `'atomic'` - no child state nodes
282
+ * - `'compound'` - nested child state nodes (XOR)
283
+ * - `'parallel'` - orthogonal nested child state nodes (AND)
284
+ * - `'history'` - history state node
285
+ * - `'final'` - final state node
286
+ */
287
+ type?: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
288
+ /**
289
+ * The initial context (extended state) of the machine.
290
+ *
291
+ * Can be an object or a function that returns an object.
292
+ */
293
+ context?: TContext | (() => TContext);
294
+ /**
295
+ * Indicates whether the state node is a history state node, and what
296
+ * type of history:
297
+ * shallow, deep, true (shallow), false (none), undefined (none)
298
+ */
299
+ history?: 'shallow' | 'deep' | boolean | undefined;
300
+ /**
301
+ * The mapping of state node keys to their state node configurations (recursive).
302
+ */
303
+ states?: StatesConfig<TContext, TStateSchema, TEvent> | undefined;
304
+ /**
305
+ * The services to invoke upon entering this state node. These services will be stopped upon exiting this state node.
306
+ */
307
+ invoke?: SingleOrArray<InvokeConfig<TContext, TEvent> | StateMachine<any, any, any>>;
308
+ /**
309
+ * The mapping of event types to their potential transition(s).
310
+ */
311
+ on?: TransitionsConfig<TContext, TEvent>;
312
+ /**
313
+ * The action(s) to be executed upon entering the state node.
314
+ *
315
+ * @deprecated Use `entry` instead.
316
+ */
317
+ onEntry?: Actions<TContext, TEvent>;
318
+ /**
319
+ * The action(s) to be executed upon entering the state node.
320
+ */
321
+ entry?: Actions<TContext, TEvent>;
322
+ /**
323
+ * The action(s) to be executed upon exiting the state node.
324
+ *
325
+ * @deprecated Use `exit` instead.
326
+ */
327
+ onExit?: Actions<TContext, TEvent>;
328
+ /**
329
+ * The action(s) to be executed upon exiting the state node.
330
+ */
331
+ exit?: Actions<TContext, TEvent>;
332
+ /**
333
+ * The potential transition(s) to be taken upon reaching a final child state node.
334
+ *
335
+ * This is equivalent to defining a `[done(id)]` transition on this state node's `on` property.
336
+ */
337
+ onDone?: string | SingleOrArray<TransitionConfig<TContext, DoneEventObject>>;
338
+ /**
339
+ * The mapping (or array) of delays (in milliseconds) to their potential transition(s).
340
+ * The delayed transitions are taken after the specified delay in an interpreter.
341
+ */
342
+ after?: DelayedTransitions<TContext, TEvent>;
343
+ /**
344
+ * An eventless transition that is always taken when this state node is active.
345
+ * Equivalent to a transition specified as an empty `''`' string in the `on` property.
346
+ */
347
+ always?: TransitionConfigOrTarget<TContext, TEvent>;
348
+ /**
349
+ * The activities to be started upon entering the state node,
350
+ * and stopped upon exiting the state node.
351
+ */
352
+ activities?: SingleOrArray<Activity<TContext, TEvent>>;
353
+ /**
354
+ * @private
355
+ */
356
+ parent?: StateNode<TContext, any, TEvent>;
357
+ strict?: boolean | undefined;
358
+ /**
359
+ * The meta data associated with this state node, which will be returned in State instances.
360
+ */
361
+ meta?: TStateSchema extends {
362
+ meta: infer D;
363
+ } ? D : any;
364
+ /**
365
+ * The data sent with the "done.state._id_" event if this is a final state node.
366
+ *
367
+ * The data will be evaluated with the current `context` and placed on the `.data` property
368
+ * of the event.
369
+ */
370
+ data?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
371
+ /**
372
+ * The unique ID of the state node, which can be referenced as a transition target via the
373
+ * `#id` syntax.
374
+ */
375
+ id?: string | undefined;
376
+ /**
377
+ * The string delimiter for serializing the path to a string. The default is "."
378
+ */
379
+ delimiter?: string;
380
+ /**
381
+ * The order this state node appears. Corresponds to the implicit SCXML document order.
382
+ */
383
+ order?: number;
384
+ /**
385
+ * The tags for this state node, which are accumulated into the `state.tags` property.
386
+ */
387
+ tags?: SingleOrArray<string>;
388
+ /**
389
+ * Whether actions should be called in order.
390
+ * When `false` (default), `assign(...)` actions are prioritized before other actions.
391
+ *
392
+ * @default false
393
+ */
394
+ preserveActionOrder?: boolean;
395
+ }
396
+ export interface StateNodeDefinition<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> {
397
+ id: string;
398
+ version: string | undefined;
399
+ key: string;
400
+ context: TContext;
401
+ type: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
402
+ initial: StateNodeConfig<TContext, TStateSchema, TEvent>['initial'];
403
+ history: boolean | 'shallow' | 'deep' | undefined;
404
+ states: StatesDefinition<TContext, TStateSchema, TEvent>;
405
+ on: TransitionDefinitionMap<TContext, TEvent>;
406
+ transitions: Array<TransitionDefinition<TContext, TEvent>>;
407
+ entry: Array<ActionObject<TContext, TEvent>>;
408
+ exit: Array<ActionObject<TContext, TEvent>>;
409
+ activities: Array<ActivityDefinition<TContext, TEvent>>;
410
+ meta: any;
411
+ order: number;
412
+ data?: FinalStateNodeConfig<TContext, TEvent>['data'];
413
+ invoke: Array<InvokeDefinition<TContext, TEvent>>;
414
+ }
415
+ export declare type AnyStateNodeDefinition = StateNodeDefinition<any, any, any>;
416
+ export interface AtomicStateNodeConfig<TContext, TEvent extends EventObject> extends StateNodeConfig<TContext, StateSchema, TEvent> {
417
+ initial?: undefined;
418
+ parallel?: false | undefined;
419
+ states?: undefined;
420
+ onDone?: undefined;
421
+ }
422
+ export interface HistoryStateNodeConfig<TContext, TEvent extends EventObject> extends AtomicStateNodeConfig<TContext, TEvent> {
423
+ history: 'shallow' | 'deep' | true;
424
+ target: StateValue | undefined;
425
+ }
426
+ export interface FinalStateNodeConfig<TContext, TEvent extends EventObject> extends AtomicStateNodeConfig<TContext, TEvent> {
427
+ type: 'final';
428
+ /**
429
+ * The data to be sent with the "done.state.<id>" event. The data can be
430
+ * static or dynamic (based on assigners).
431
+ */
432
+ data?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
433
+ }
434
+ export declare type SimpleOrStateNodeConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TStateSchema, TEvent>;
435
+ export declare type ActionFunctionMap<TContext, TEvent extends EventObject> = Record<string, ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent>>;
436
+ export declare type DelayFunctionMap<TContext, TEvent extends EventObject> = Record<string, DelayConfig<TContext, TEvent>>;
437
+ export declare type ServiceConfig<TContext, TEvent extends EventObject = AnyEventObject> = string | StateMachine<any, any, any> | InvokeCreator<TContext, TEvent>;
438
+ export declare type DelayConfig<TContext, TEvent extends EventObject> = number | DelayExpr<TContext, TEvent>;
439
+ export interface MachineOptions<TContext, TEvent extends EventObject> {
440
+ guards: Record<string, ConditionPredicate<TContext, TEvent>>;
441
+ actions: ActionFunctionMap<TContext, TEvent>;
442
+ activities: Record<string, ActivityConfig<TContext, TEvent>>;
443
+ services: Record<string, ServiceConfig<TContext, TEvent>>;
444
+ delays: DelayFunctionMap<TContext, TEvent>;
445
+ /**
446
+ * @private
447
+ */
448
+ _parent?: StateNode<TContext, any, TEvent, any>;
449
+ /**
450
+ * @private
451
+ */
452
+ _key?: string;
453
+ }
454
+ export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> extends StateNodeConfig<TContext, TStateSchema, TEvent> {
455
+ /**
456
+ * The initial context (extended state)
457
+ */
458
+ context?: TContext | (() => TContext);
459
+ /**
460
+ * The machine's own version.
461
+ */
462
+ version?: string;
463
+ schema?: MachineSchema<TContext, TEvent>;
464
+ }
465
+ export interface MachineSchema<TContext, TEvent extends EventObject> {
466
+ context?: TContext;
467
+ events?: TEvent;
468
+ actions?: {
469
+ type: string;
470
+ [key: string]: any;
471
+ };
472
+ guards?: {
473
+ type: string;
474
+ [key: string]: any;
475
+ };
476
+ services?: {
477
+ type: string;
478
+ [key: string]: any;
479
+ };
480
+ }
481
+ export interface StandardMachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> extends StateNodeConfig<TContext, TStateSchema, TEvent> {
482
+ }
483
+ export interface ParallelMachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> extends StateNodeConfig<TContext, TStateSchema, TEvent> {
484
+ initial?: undefined;
485
+ type?: 'parallel';
486
+ }
487
+ export interface EntryExitEffectMap<TContext, TEvent extends EventObject> {
488
+ entry: Array<ActionObject<TContext, TEvent>>;
489
+ exit: Array<ActionObject<TContext, TEvent>>;
490
+ }
491
+ export interface HistoryStateNode<TContext> extends StateNode<TContext> {
492
+ history: 'shallow' | 'deep';
493
+ target: StateValue | undefined;
494
+ }
495
+ export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
496
+ value: any;
497
+ context: TContext;
498
+ }> extends StateNode<TContext, TStateSchema, TEvent, TTypestate> {
499
+ id: string;
500
+ states: StateNode<TContext, TStateSchema, TEvent>['states'];
501
+ withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
502
+ withContext(context: TContext): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
503
+ }
504
+ export declare type StateFrom<TMachine extends StateMachine<any, any, any>> = ReturnType<TMachine['transition']>;
505
+ export interface ActionMap<TContext, TEvent extends EventObject> {
506
+ onEntry: Array<Action<TContext, TEvent>>;
507
+ actions: Array<Action<TContext, TEvent>>;
508
+ onExit: Array<Action<TContext, TEvent>>;
509
+ }
510
+ export interface EntryExitStates<TContext> {
511
+ entry: Set<StateNode<TContext>>;
512
+ exit: Set<StateNode<TContext>>;
513
+ }
514
+ export interface EntryExitStateArrays<TContext> {
515
+ entry: Array<StateNode<TContext>>;
516
+ exit: Array<StateNode<TContext>>;
517
+ }
518
+ export interface ActivityMap {
519
+ [activityKey: string]: ActivityDefinition<any, any> | false;
520
+ }
521
+ export interface StateTransition<TContext, TEvent extends EventObject> {
522
+ transitions: Array<TransitionDefinition<TContext, TEvent>>;
523
+ configuration: Array<StateNode<TContext, any, TEvent, any>>;
524
+ entrySet: Array<StateNode<TContext, any, TEvent, any>>;
525
+ exitSet: Array<StateNode<TContext, any, TEvent, any>>;
526
+ /**
527
+ * The source state that preceded the transition.
528
+ */
529
+ source: State<TContext, any, any, any> | undefined;
530
+ actions: Array<ActionObject<TContext, TEvent>>;
531
+ }
532
+ export interface TransitionData<TContext, TEvent extends EventObject> {
533
+ value: StateValue | undefined;
534
+ actions: ActionMap<TContext, TEvent>;
535
+ activities?: ActivityMap;
536
+ }
537
+ export declare enum ActionTypes {
538
+ Start = "xstate.start",
539
+ Stop = "xstate.stop",
540
+ Raise = "xstate.raise",
541
+ Send = "xstate.send",
542
+ Cancel = "xstate.cancel",
543
+ NullEvent = "",
544
+ Assign = "xstate.assign",
545
+ After = "xstate.after",
546
+ DoneState = "done.state",
547
+ DoneInvoke = "done.invoke",
548
+ Log = "xstate.log",
549
+ Init = "xstate.init",
550
+ Invoke = "xstate.invoke",
551
+ ErrorExecution = "error.execution",
552
+ ErrorCommunication = "error.communication",
553
+ ErrorPlatform = "error.platform",
554
+ ErrorCustom = "xstate.error",
555
+ Update = "xstate.update",
556
+ Pure = "xstate.pure",
557
+ Choose = "xstate.choose"
558
+ }
559
+ export interface RaiseAction<TEvent extends EventObject> {
560
+ type: ActionTypes.Raise;
561
+ event: TEvent['type'];
562
+ }
563
+ export interface RaiseActionObject<TEvent extends EventObject> {
564
+ type: ActionTypes.Raise;
565
+ _event: SCXML.Event<TEvent>;
566
+ }
567
+ export interface DoneInvokeEvent<TData> extends EventObject {
568
+ data: TData;
569
+ }
570
+ export interface ErrorExecutionEvent extends EventObject {
571
+ src: string;
572
+ type: ActionTypes.ErrorExecution;
573
+ data: any;
574
+ }
575
+ export interface ErrorPlatformEvent extends EventObject {
576
+ data: any;
577
+ }
578
+ export interface DoneEventObject extends EventObject {
579
+ data?: any;
580
+ toString(): string;
581
+ }
582
+ export interface UpdateObject extends EventObject {
583
+ id: string | number;
584
+ state: State<any, any>;
585
+ }
586
+ export declare type DoneEvent = DoneEventObject & string;
587
+ export interface NullEvent {
588
+ type: ActionTypes.NullEvent;
589
+ }
590
+ export interface ActivityActionObject<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
591
+ type: ActionTypes.Start | ActionTypes.Stop;
592
+ activity: ActivityDefinition<TContext, TEvent> | undefined;
593
+ exec: ActionFunction<TContext, TEvent> | undefined;
594
+ }
595
+ export interface InvokeActionObject<TContext, TEvent extends EventObject> extends ActivityActionObject<TContext, TEvent> {
596
+ activity: InvokeDefinition<TContext, TEvent>;
597
+ }
598
+ export declare type DelayExpr<TContext, TEvent extends EventObject> = ExprWithMeta<TContext, TEvent, number>;
599
+ export declare type LogExpr<TContext, TEvent extends EventObject> = ExprWithMeta<TContext, TEvent, any>;
600
+ export interface LogAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
601
+ label: string | undefined;
602
+ expr: string | LogExpr<TContext, TEvent>;
603
+ }
604
+ export interface LogActionObject<TContext, TEvent extends EventObject> extends LogAction<TContext, TEvent> {
605
+ value: any;
606
+ }
607
+ export interface SendAction<TContext, TEvent extends EventObject, TSentEvent extends EventObject> extends ActionObject<TContext, TEvent> {
608
+ to: string | number | ActorRef<any> | ExprWithMeta<TContext, TEvent, string | number | ActorRef<any>> | undefined;
609
+ event: TSentEvent | SendExpr<TContext, TEvent, TSentEvent>;
610
+ delay?: number | string | DelayExpr<TContext, TEvent>;
611
+ id: string | number;
612
+ }
613
+ export interface SendActionObject<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject> extends SendAction<TContext, TEvent, TSentEvent> {
614
+ to: string | number | ActorRef<any> | undefined;
615
+ _event: SCXML.Event<TSentEvent>;
616
+ event: TSentEvent;
617
+ delay?: number;
618
+ id: string | number;
619
+ }
620
+ export interface StopAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
621
+ type: ActionTypes.Stop;
622
+ activity: string | {
623
+ id: string;
624
+ } | Expr<TContext, TEvent, string | {
625
+ id: string;
626
+ }>;
627
+ }
628
+ export interface StopActionObject {
629
+ type: ActionTypes.Stop;
630
+ activity: {
631
+ id: string;
632
+ };
633
+ }
634
+ export declare type Expr<TContext, TEvent extends EventObject, T> = (context: TContext, event: TEvent) => T;
635
+ export declare type ExprWithMeta<TContext, TEvent extends EventObject, T> = (context: TContext, event: TEvent, meta: SCXMLEventMeta<TEvent>) => T;
636
+ export declare type SendExpr<TContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject> = ExprWithMeta<TContext, TEvent, TSentEvent>;
637
+ export declare enum SpecialTargets {
638
+ Parent = "#_parent",
639
+ Internal = "#_internal"
640
+ }
641
+ export interface SendActionOptions<TContext, TEvent extends EventObject> {
642
+ id?: string | number;
643
+ delay?: number | string | DelayExpr<TContext, TEvent>;
644
+ to?: string | ExprWithMeta<TContext, TEvent, string | number | ActorRef<any>>;
645
+ }
646
+ export interface CancelAction extends ActionObject<any, any> {
647
+ sendId: string | number;
648
+ }
649
+ export declare type Assigner<TContext, TEvent extends EventObject> = (context: TContext, event: TEvent, meta: AssignMeta<TContext, TEvent>) => Partial<TContext>;
650
+ export declare type PartialAssigner<TContext, TEvent extends EventObject, TKey extends keyof TContext> = (context: TContext, event: TEvent, meta: AssignMeta<TContext, TEvent>) => TContext[TKey];
651
+ export declare type PropertyAssigner<TContext, TEvent extends EventObject> = {
652
+ [K in keyof TContext]?: PartialAssigner<TContext, TEvent, K> | TContext[K];
653
+ };
654
+ export declare type Mapper<TContext, TEvent extends EventObject, TParams extends {}> = (context: TContext, event: TEvent) => TParams;
655
+ export declare type PropertyMapper<TContext, TEvent extends EventObject, TParams extends {}> = {
656
+ [K in keyof TParams]?: ((context: TContext, event: TEvent) => TParams[K]) | TParams[K];
657
+ };
658
+ export interface AnyAssignAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
659
+ type: ActionTypes.Assign;
660
+ assignment: any;
661
+ }
662
+ export interface AssignAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
663
+ type: ActionTypes.Assign;
664
+ assignment: Assigner<TContext, TEvent> | PropertyAssigner<TContext, TEvent>;
665
+ }
666
+ export interface PureAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
667
+ type: ActionTypes.Pure;
668
+ get: (context: TContext, event: TEvent) => SingleOrArray<ActionObject<TContext, TEvent>> | undefined;
669
+ }
670
+ export interface ChooseAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
671
+ type: ActionTypes.Choose;
672
+ conds: Array<ChooseConditon<TContext, TEvent>>;
673
+ }
674
+ export interface TransitionDefinition<TContext, TEvent extends EventObject> extends TransitionConfig<TContext, TEvent> {
675
+ target: Array<StateNode<TContext, any, TEvent>> | undefined;
676
+ source: StateNode<TContext, any, TEvent>;
677
+ actions: Array<ActionObject<TContext, TEvent>>;
678
+ cond?: Guard<TContext, TEvent>;
679
+ eventType: TEvent['type'] | NullEvent['type'] | '*';
680
+ toJSON: () => {
681
+ target: string[] | undefined;
682
+ source: string;
683
+ actions: Array<ActionObject<TContext, TEvent>>;
684
+ cond?: Guard<TContext, TEvent>;
685
+ eventType: TEvent['type'] | NullEvent['type'] | '*';
686
+ meta?: Record<string, any>;
687
+ };
688
+ }
689
+ export declare type TransitionDefinitionMap<TContext, TEvent extends EventObject> = {
690
+ [K in TEvent['type'] | NullEvent['type'] | '*']: Array<TransitionDefinition<TContext, K extends TEvent['type'] ? Extract<TEvent, {
691
+ type: K;
692
+ }> : EventObject>>;
693
+ };
694
+ export interface DelayedTransitionDefinition<TContext, TEvent extends EventObject> extends TransitionDefinition<TContext, TEvent> {
695
+ delay: number | string | DelayExpr<TContext, TEvent>;
696
+ }
697
+ export interface Edge<TContext, TEvent extends EventObject, TEventType extends TEvent['type'] = string> {
698
+ event: TEventType;
699
+ source: StateNode<TContext, any, TEvent>;
700
+ target: StateNode<TContext, any, TEvent>;
701
+ cond?: Condition<TContext, TEvent & {
702
+ type: TEventType;
703
+ }>;
704
+ actions: Array<Action<TContext, TEvent>>;
705
+ meta?: MetaObject;
706
+ transition: TransitionDefinition<TContext, TEvent>;
707
+ }
708
+ export interface NodesAndEdges<TContext, TEvent extends EventObject> {
709
+ nodes: StateNode[];
710
+ edges: Array<Edge<TContext, TEvent, TEvent['type']>>;
711
+ }
712
+ export interface Segment<TContext, TEvent extends EventObject> {
713
+ /**
714
+ * From state.
715
+ */
716
+ state: State<TContext, TEvent>;
717
+ /**
718
+ * Event from state.
719
+ */
720
+ event: TEvent;
721
+ }
722
+ export interface PathItem<TContext, TEvent extends EventObject> {
723
+ state: State<TContext, TEvent>;
724
+ path: Array<Segment<TContext, TEvent>>;
725
+ weight?: number;
726
+ }
727
+ export interface PathMap<TContext, TEvent extends EventObject> {
728
+ [key: string]: PathItem<TContext, TEvent>;
729
+ }
730
+ export interface PathsItem<TContext, TEvent extends EventObject> {
731
+ state: State<TContext, TEvent>;
732
+ paths: Array<Array<Segment<TContext, TEvent>>>;
733
+ }
734
+ export interface PathsMap<TContext, TEvent extends EventObject> {
735
+ [key: string]: PathsItem<TContext, TEvent>;
736
+ }
737
+ export interface TransitionMap {
738
+ state: StateValue | undefined;
739
+ }
740
+ export interface AdjacencyMap {
741
+ [stateId: string]: Record<string, TransitionMap>;
742
+ }
743
+ export interface ValueAdjacencyMap<TContext, TEvent extends EventObject> {
744
+ [stateId: string]: Record<string, State<TContext, TEvent>>;
745
+ }
746
+ export interface SCXMLEventMeta<TEvent extends EventObject> {
747
+ _event: SCXML.Event<TEvent>;
748
+ }
749
+ export interface StateMeta<TContext, TEvent extends EventObject> {
750
+ state: State<TContext, TEvent, any, any>;
751
+ _event: SCXML.Event<TEvent>;
752
+ }
753
+ export interface Typestate<TContext> {
754
+ value: StateValue;
755
+ context: TContext;
756
+ }
757
+ export interface StateLike<TContext> {
758
+ value: StateValue;
759
+ context: TContext;
760
+ event: EventObject;
761
+ _event: SCXML.Event<EventObject>;
762
+ }
763
+ export interface StateConfig<TContext, TEvent extends EventObject> {
764
+ value: StateValue;
765
+ context: TContext;
766
+ _event: SCXML.Event<TEvent>;
767
+ _sessionid: string | null;
768
+ historyValue?: HistoryValue | undefined;
769
+ history?: State<TContext, TEvent>;
770
+ actions?: Array<ActionObject<TContext, TEvent>>;
771
+ activities?: ActivityMap;
772
+ meta?: any;
773
+ events?: TEvent[];
774
+ configuration: Array<StateNode<TContext, any, TEvent>>;
775
+ transitions: Array<TransitionDefinition<TContext, TEvent>>;
776
+ children: Record<string, ActorRef<any>>;
777
+ done?: boolean;
778
+ tags?: Set<string>;
779
+ }
780
+ export interface StateSchema<TC = any> {
781
+ meta?: any;
782
+ context?: Partial<TC>;
783
+ states?: {
784
+ [key: string]: StateSchema<TC>;
785
+ };
786
+ }
787
+ export interface InterpreterOptions {
788
+ /**
789
+ * Whether state actions should be executed immediately upon transition. Defaults to `true`.
790
+ */
791
+ execute: boolean;
792
+ clock: Clock;
793
+ logger: (...args: any[]) => void;
794
+ parent?: AnyInterpreter;
795
+ /**
796
+ * If `true`, defers processing of sent events until the service
797
+ * is initialized (`.start()`). Otherwise, an error will be thrown
798
+ * for events sent to an uninitialized service.
799
+ *
800
+ * Default: `true`
801
+ */
802
+ deferEvents: boolean;
803
+ /**
804
+ * The custom `id` for referencing this service.
805
+ */
806
+ id?: string;
807
+ /**
808
+ * If `true`, states and events will be logged to Redux DevTools.
809
+ *
810
+ * Default: `false`
811
+ */
812
+ devTools: boolean | object;
813
+ [option: string]: any;
814
+ }
815
+ export declare namespace SCXML {
816
+ interface Event<TEvent extends EventObject> {
817
+ /**
818
+ * This is a character string giving the name of the event.
819
+ * The SCXML Processor must set the name field to the name of this event.
820
+ * It is what is matched against the 'event' attribute of <transition>.
821
+ * Note that transitions can do additional tests by using the value of this field
822
+ * inside boolean expressions in the 'cond' attribute.
823
+ */
824
+ name: string;
825
+ /**
826
+ * This field describes the event type.
827
+ * The SCXML Processor must set it to: "platform" (for events raised by the platform itself, such as error events),
828
+ * "internal" (for events raised by <raise> and <send> with target '_internal')
829
+ * or "external" (for all other events).
830
+ */
831
+ type: 'platform' | 'internal' | 'external';
832
+ /**
833
+ * If the sending entity has specified a value for this, the Processor must set this field to that value
834
+ * (see C Event I/O Processors for details).
835
+ * Otherwise, in the case of error events triggered by a failed attempt to send an event,
836
+ * the Processor must set this field to the send id of the triggering <send> element.
837
+ * Otherwise it must leave it blank.
838
+ */
839
+ sendid?: string;
840
+ /**
841
+ * This is a URI, equivalent to the 'target' attribute on the <send> element.
842
+ * For external events, the SCXML Processor should set this field to a value which,
843
+ * when used as the value of 'target', will allow the receiver of the event to <send>
844
+ * a response back to the originating entity via the Event I/O Processor specified in 'origintype'.
845
+ * For internal and platform events, the Processor must leave this field blank.
846
+ */
847
+ origin?: string;
848
+ /**
849
+ * This is equivalent to the 'type' field on the <send> element.
850
+ * For external events, the SCXML Processor should set this field to a value which,
851
+ * when used as the value of 'type', will allow the receiver of the event to <send>
852
+ * a response back to the originating entity at the URI specified by 'origin'.
853
+ * For internal and platform events, the Processor must leave this field blank.
854
+ */
855
+ origintype?: string;
856
+ /**
857
+ * If this event is generated from an invoked child process, the SCXML Processor
858
+ * must set this field to the invoke id of the invocation that triggered the child process.
859
+ * Otherwise it must leave it blank.
860
+ */
861
+ invokeid?: string;
862
+ /**
863
+ * This field contains whatever data the sending entity chose to include in this event.
864
+ * The receiving SCXML Processor should reformat this data to match its data model,
865
+ * but must not otherwise modify it.
866
+ *
867
+ * If the conversion is not possible, the Processor must leave the field blank
868
+ * and must place an error 'error.execution' in the internal event queue.
869
+ */
870
+ data: TEvent;
871
+ /**
872
+ * @private
873
+ */
874
+ $$type: 'scxml';
875
+ }
876
+ }
877
+ export interface Observer<T> {
878
+ next: (value: T) => void;
879
+ error: (err: any) => void;
880
+ complete: () => void;
881
+ }
882
+ export interface Subscription {
883
+ unsubscribe(): void;
884
+ }
885
+ export interface Subscribable<T> {
886
+ subscribe(next: (value: T) => void, error?: (error: any) => void, complete?: () => void): Subscription;
887
+ subscribe(observer: Observer<T>): Subscription;
888
+ }
889
+ export declare type Spawnable = StateMachine<any, any, any> | PromiseLike<any> | InvokeCallback | Subscribable<any> | Behavior<any>;
890
+ export declare type ExtractEvent<TEvent extends EventObject, TEventType extends TEvent['type']> = TEvent extends {
891
+ type: TEventType;
892
+ } ? TEvent : never;
893
+ export interface BaseActorRef<TEvent extends EventObject> {
894
+ send: (event: TEvent) => void;
895
+ }
896
+ export interface ActorRef<TEvent extends EventObject, TEmitted = any> extends Subscribable<TEmitted> {
897
+ send: Sender<TEvent>;
898
+ id: string;
899
+ getSnapshot: () => TEmitted | undefined;
900
+ stop?: () => void;
901
+ toJSON?: () => any;
902
+ }
903
+ /**
904
+ * @deprecated Use `ActorRef` instead.
905
+ */
906
+ export declare type SpawnedActorRef<TEvent extends EventObject, TEmitted = any> = ActorRef<TEvent, TEmitted>;
907
+ export declare type ActorRefFrom<T extends StateMachine<any, any, any> | Promise<any> | Behavior<any>> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRef<TEvent, State<TContext, TEvent, any, TTypestate>> & {
908
+ /**
909
+ * @deprecated Use `.getSnapshot()` instead.
910
+ */
911
+ state: State<TContext, TEvent, any, TTypestate>;
912
+ } : T extends Promise<infer U> ? ActorRef<never, U> : T extends Behavior<infer TEvent1, infer TEmitted> ? ActorRef<TEvent1, TEmitted> : never;
913
+ export declare type AnyInterpreter = Interpreter<any, any, any, any>;
914
+ export declare type InterpreterFrom<T extends StateMachine<any, any, any, any>> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : never;
915
+ export interface ActorContext<TEvent extends EventObject, TEmitted> {
916
+ parent?: ActorRef<any, any>;
917
+ self: ActorRef<TEvent, TEmitted>;
918
+ id: string;
919
+ observers: Set<Observer<TEmitted>>;
920
+ }
921
+ export interface Behavior<TEvent extends EventObject, TEmitted = any> {
922
+ transition: (state: TEmitted, event: TEvent, actorCtx: ActorContext<TEvent, TEmitted>) => TEmitted;
923
+ initialState: TEmitted;
924
+ start?: (actorCtx: ActorContext<TEvent, TEmitted>) => TEmitted;
925
+ }
926
+ export declare type EventFrom<T> = T extends StateMachine<any, any, infer TEvent, any> ? TEvent : T extends Model<any, infer TEvent, any> ? TEvent : T extends State<any, infer TEvent, any, any> ? TEvent : T extends Interpreter<any, any, infer TEvent, any> ? TEvent : never;
927
+ export declare type ContextFrom<T> = T extends StateMachine<infer TContext, any, any, any> ? TContext : T extends Model<infer TContext, any, any> ? TContext : T extends State<infer TContext, any, any, any> ? TContext : T extends Interpreter<infer TContext, any, any, any> ? TContext : never;
928
+ export {};
908
929
  //# sourceMappingURL=types.d.ts.map