xstate 5.32.1 → 6.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -8
- package/dist/StateMachine-2dcdb1f5.esm.js +720 -0
- package/dist/StateMachine-2ea0a7fa.development.esm.js +737 -0
- package/dist/StateMachine-64813f46.cjs.js +723 -0
- package/dist/StateMachine-8d22a79c.development.cjs.js +740 -0
- package/dist/declarations/src/State.d.ts +11 -13
- package/dist/declarations/src/StateMachine.d.ts +27 -21
- package/dist/declarations/src/StateNode.d.ts +18 -54
- package/dist/declarations/src/actions.d.ts +14 -9
- package/dist/declarations/src/actors/callback.d.ts +42 -16
- package/dist/declarations/src/actors/index.d.ts +9 -6
- package/dist/declarations/src/actors/listener.d.ts +18 -0
- package/dist/declarations/src/actors/logic.d.ts +105 -0
- package/dist/declarations/src/actors/observable.d.ts +72 -27
- package/dist/declarations/src/actors/promise.d.ts +133 -48
- package/dist/declarations/src/actors/subscription.d.ts +22 -0
- package/dist/declarations/src/atom.d.ts +81 -0
- package/dist/declarations/src/createActor.d.ts +31 -33
- package/dist/declarations/src/createMachine.d.ts +35 -7
- package/dist/declarations/src/createMachineFromConfig.d.ts +176 -0
- package/dist/declarations/src/graph/graph.d.ts +4 -2
- package/dist/declarations/src/index.d.ts +12 -8
- package/dist/declarations/src/inspection.d.ts +84 -30
- package/dist/declarations/src/mapState.d.ts +4 -2
- package/dist/declarations/src/schema.types.d.ts +90 -0
- package/dist/declarations/src/serialize.d.ts +44 -0
- package/dist/declarations/src/setup.d.ts +251 -135
- package/dist/declarations/src/spawn.d.ts +6 -31
- package/dist/declarations/src/stateUtils.d.ts +21 -19
- package/dist/declarations/src/system.d.ts +8 -7
- package/dist/declarations/src/transition.d.ts +5 -5
- package/dist/declarations/src/types.d.ts +405 -405
- package/dist/declarations/src/types.v6.d.ts +392 -0
- package/dist/declarations/src/utils.d.ts +4 -3
- package/dist/index-93edd3bd.esm.js +4909 -0
- package/dist/index-9cb3b3a0.cjs.js +4968 -0
- package/dist/index-e61170ba.development.esm.js +4948 -0
- package/dist/index-f6ef20d1.development.cjs.js +5007 -0
- package/dist/xstate-actors.cjs.js +12 -838
- package/dist/xstate-actors.cjs.mjs +10 -5
- package/dist/xstate-actors.development.cjs.js +12 -838
- package/dist/xstate-actors.development.cjs.mjs +10 -5
- package/dist/xstate-actors.development.esm.js +1 -836
- package/dist/xstate-actors.esm.js +1 -836
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +18 -29
- package/dist/xstate-graph.development.cjs.js +18 -29
- package/dist/xstate-graph.development.esm.js +15 -26
- package/dist/xstate-graph.esm.js +15 -26
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +1316 -112
- package/dist/xstate.cjs.mjs +22 -22
- package/dist/xstate.development.cjs.js +1316 -112
- package/dist/xstate.development.cjs.mjs +22 -22
- package/dist/xstate.development.esm.js +1278 -76
- package/dist/xstate.esm.js +1278 -76
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +3 -47
- package/dist/StateMachine-45e79c35.esm.js +0 -560
- package/dist/StateMachine-be2e51a3.development.cjs.js +0 -569
- package/dist/StateMachine-e0178d48.development.esm.js +0 -566
- package/dist/StateMachine-e6732977.cjs.js +0 -563
- package/dist/assign-2aa58daa.esm.js +0 -127
- package/dist/assign-927227d6.development.cjs.js +0 -135
- package/dist/assign-e8f2bd75.cjs.js +0 -129
- package/dist/assign-f338cee3.development.esm.js +0 -133
- package/dist/declarations/src/actions/assign.d.ts +0 -45
- package/dist/declarations/src/actions/cancel.d.ts +0 -39
- package/dist/declarations/src/actions/emit.d.ts +0 -44
- package/dist/declarations/src/actions/enqueueActions.d.ts +0 -57
- package/dist/declarations/src/actions/log.d.ts +0 -16
- package/dist/declarations/src/actions/raise.d.ts +0 -21
- package/dist/declarations/src/actions/send.d.ts +0 -42
- package/dist/declarations/src/actions/spawnChild.d.ts +0 -34
- package/dist/declarations/src/actions/stopChild.d.ts +0 -19
- package/dist/declarations/src/actors/transition.d.ts +0 -143
- package/dist/declarations/src/dev/index.d.ts +0 -14
- package/dist/declarations/src/guards.d.ts +0 -128
- package/dist/log-410e5e55.development.esm.js +0 -429
- package/dist/log-7776fcf2.cjs.js +0 -409
- package/dist/log-c2e11c01.development.cjs.js +0 -437
- package/dist/log-fa75ec2d.esm.js +0 -401
- package/dist/raise-74097812.development.esm.js +0 -2823
- package/dist/raise-7c948725.cjs.js +0 -2816
- package/dist/raise-964cd4e9.development.cjs.js +0 -2878
- package/dist/raise-e974d1c9.esm.js +0 -2761
- package/dist/xstate-actions.cjs.d.mts +0 -2
- package/dist/xstate-actions.cjs.d.ts +0 -2
- package/dist/xstate-actions.cjs.js +0 -23
- package/dist/xstate-actions.cjs.mjs +0 -14
- package/dist/xstate-actions.development.cjs.js +0 -23
- package/dist/xstate-actions.development.cjs.mjs +0 -14
- package/dist/xstate-actions.development.esm.js +0 -4
- package/dist/xstate-actions.esm.js +0 -4
- package/dist/xstate-actions.umd.min.js +0 -2
- package/dist/xstate-actions.umd.min.js.map +0 -1
- package/dist/xstate-dev.cjs.d.mts +0 -2
- package/dist/xstate-dev.cjs.d.ts +0 -2
- package/dist/xstate-dev.cjs.js +0 -48
- package/dist/xstate-dev.cjs.mjs +0 -5
- package/dist/xstate-dev.development.cjs.js +0 -51
- package/dist/xstate-dev.development.cjs.mjs +0 -5
- package/dist/xstate-dev.development.esm.js +0 -45
- package/dist/xstate-dev.esm.js +0 -42
- package/dist/xstate-dev.umd.min.js +0 -2
- package/dist/xstate-dev.umd.min.js.map +0 -1
- package/dist/xstate-guards.cjs.d.mts +0 -2
- package/dist/xstate-guards.cjs.d.ts +0 -2
- package/dist/xstate-guards.cjs.js +0 -14
- package/dist/xstate-guards.cjs.mjs +0 -7
- package/dist/xstate-guards.development.cjs.js +0 -14
- package/dist/xstate-guards.development.cjs.mjs +0 -7
- package/dist/xstate-guards.development.esm.js +0 -2
- package/dist/xstate-guards.esm.js +0 -2
- package/dist/xstate-guards.umd.min.js +0 -2
- package/dist/xstate-guards.umd.min.js.map +0 -1
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "./schema.types.js";
|
|
2
|
+
import { MachineSnapshot } from "./State.js";
|
|
3
|
+
import { Action, ActorSelf, AnyActorLogic, AnyActorRef, Compute, DoneActorEvent, DoNotInfer, EventDescriptor, EventObject, ExtractEvent, InitialContext, InputFrom, IsNever, MetaObject, NonReducibleUnknown, SingleOrArray, SnapshotEvent, StateValue, TODO, TransitionConfigFunction, Values, AnyStateNode } from "./types.js";
|
|
4
|
+
import { MachineContext, Mapper } from "./types.js";
|
|
5
|
+
import { LowInfer } from "./types.js";
|
|
6
|
+
import { DoneStateEvent } from "./types.js";
|
|
7
|
+
export type InferOutput<T extends StandardSchemaV1, U> = Compute<StandardSchemaV1.InferOutput<T> extends U ? StandardSchemaV1.InferOutput<T> : never>;
|
|
8
|
+
/**
|
|
9
|
+
* Event payloads from schemas (e.g. Zod) are often inferred as optional in
|
|
10
|
+
* output types. Wrapping in Required<> ensures properties defined in the schema
|
|
11
|
+
* are required on the event.
|
|
12
|
+
*/
|
|
13
|
+
export type InferEvents<TEventSchemaMap extends Record<string, StandardSchemaV1>> = Values<{
|
|
14
|
+
[K in keyof TEventSchemaMap & string]: StandardSchemaV1.InferOutput<TEventSchemaMap[K]> extends infer O ? unknown extends O ? O & {
|
|
15
|
+
type: K;
|
|
16
|
+
} : Required<O> & {
|
|
17
|
+
type: K;
|
|
18
|
+
} : never;
|
|
19
|
+
}>;
|
|
20
|
+
type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
21
|
+
type InternalEventDescriptorFor<TEvent extends EventObject> = [TEvent] extends [
|
|
22
|
+
never
|
|
23
|
+
] ? string : EventDescriptor<TEvent>;
|
|
24
|
+
/**
|
|
25
|
+
* Runtime options for state machine execution.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* const machine = createMachine({
|
|
31
|
+
* // ... machine config
|
|
32
|
+
* options: {
|
|
33
|
+
* maxIterations: 5000
|
|
34
|
+
* // other runtime options can be added here
|
|
35
|
+
* }
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export interface MachineOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Maximum number of microsteps allowed before throwing an infinite loop
|
|
42
|
+
* error. Defaults to `Infinity` (no limit). Set to a finite number to enable
|
|
43
|
+
* infinite loop detection.
|
|
44
|
+
*
|
|
45
|
+
* @default Infinity
|
|
46
|
+
*/
|
|
47
|
+
maxIterations?: number;
|
|
48
|
+
}
|
|
49
|
+
export type Next_MachineConfig<TContextSchema extends StandardSchemaV1, TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, TContext extends MachineContext = InferOutput<TContextSchema, MachineContext>, TEvent extends EventObject = InferEvents<TEventSchemaMap>, TDelays extends string = string, _TTag extends string = string, TActionMap extends Implementations['actions'] = Implementations['actions'], TActorMap extends Implementations['actors'] = Implementations['actors'], TGuardMap extends Implementations['guards'] = Implementations['guards'], TDelayMap extends Implementations['delays'] = Implementations['delays'], TContextRequired extends boolean = IsNever<TContext> extends true ? false : true> = (DistributiveOmit<Next_StateNodeConfig<TContext, DoNotInfer<InferEvents<TEventSchemaMap>>, DoNotInfer<TDelays>, DoNotInfer<StandardSchemaV1.InferOutput<TTagSchema> & string>, DoNotInfer<StandardSchemaV1.InferOutput<TOutputSchema>>, DoNotInfer<InferEvents<TEmittedSchemaMap>>, DoNotInfer<InferOutput<TMetaSchema, MetaObject>>, DoNotInfer<TActionMap>, DoNotInfer<TActorMap>, DoNotInfer<TGuardMap>, DoNotInfer<TDelayMap>>, 'output'> & {
|
|
50
|
+
internalEvents?: readonly InternalEventDescriptorFor<InferEvents<TEventSchemaMap>>[];
|
|
51
|
+
schemas?: {
|
|
52
|
+
events?: TEventSchemaMap;
|
|
53
|
+
context?: TContextSchema;
|
|
54
|
+
emitted?: TEmittedSchemaMap;
|
|
55
|
+
input?: TInputSchema;
|
|
56
|
+
output?: TOutputSchema;
|
|
57
|
+
meta?: TMetaSchema;
|
|
58
|
+
tags?: TTagSchema;
|
|
59
|
+
};
|
|
60
|
+
actions?: TActionMap;
|
|
61
|
+
guards?: TGuardMap;
|
|
62
|
+
actors?: TActorMap;
|
|
63
|
+
/** The machine's own version. */
|
|
64
|
+
version?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Migrates a persisted snapshot created by a different version of this
|
|
67
|
+
* machine to the current `version`. Called during restore when the persisted
|
|
68
|
+
* snapshot's `version` does not match the machine's `version` (`fromVersion`
|
|
69
|
+
* is the persisted version, possibly `undefined`). Restoring a
|
|
70
|
+
* version-mismatched snapshot without a `migrate` function throws.
|
|
71
|
+
*/
|
|
72
|
+
migrate?: (persistedSnapshot: any, fromVersion: string | undefined) => unknown;
|
|
73
|
+
output?: Mapper<TContext, DoneStateEvent, InferOutput<TOutputSchema, unknown>, TEvent> | InferOutput<TOutputSchema, unknown>;
|
|
74
|
+
delays?: {
|
|
75
|
+
[K in TDelays | number]?: number | (({ context, event, stateNode }: {
|
|
76
|
+
context: TContext;
|
|
77
|
+
event: TEvent;
|
|
78
|
+
stateNode: AnyStateNode;
|
|
79
|
+
}) => number);
|
|
80
|
+
};
|
|
81
|
+
options?: MachineOptions;
|
|
82
|
+
}) & (TContextRequired extends false ? {
|
|
83
|
+
context?: InitialContext<LowInfer<TContext>, TActorMap, InferOutput<TInputSchema, unknown>, TEvent>;
|
|
84
|
+
} : {
|
|
85
|
+
context: InitialContext<LowInfer<TContext>, TActorMap, InferOutput<TInputSchema, unknown>, TEvent>;
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* Recursively widens literal types and strips `readonly`. Used to widen context
|
|
89
|
+
* inferred from a literal initial value (e.g. `{ count: 0 }` becomes `{ count:
|
|
90
|
+
* number }`), since `createMachine`'s `const` state-schema inference would
|
|
91
|
+
* otherwise freeze context at its initial literal type and make every context
|
|
92
|
+
* update a type error.
|
|
93
|
+
*/
|
|
94
|
+
export type WidenLiterals<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends bigint ? bigint : T extends (...args: any[]) => any ? T : T extends readonly (infer U)[] ? WidenLiterals<U>[] : T extends object ? {
|
|
95
|
+
-readonly [K in keyof T]: WidenLiterals<T[K]>;
|
|
96
|
+
} : T;
|
|
97
|
+
type InvokeSrcArgs<TContext extends MachineContext, TEvent extends EventObject, TActorMap extends Implementations['actors']> = {
|
|
98
|
+
actors: TActorMap;
|
|
99
|
+
context: TContext;
|
|
100
|
+
event: TEvent;
|
|
101
|
+
self: AnyActorRef;
|
|
102
|
+
};
|
|
103
|
+
type InvokeInputArgs<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject> = {
|
|
104
|
+
context: TContext;
|
|
105
|
+
event: TEvent;
|
|
106
|
+
self: ActorSelf<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>, StateValue, string, unknown, TODO, TODO>, TEvent, TEmitted>;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Invoke config. A union of:
|
|
110
|
+
*
|
|
111
|
+
* - One branch per registered actor (distributed over the `actors` map), where
|
|
112
|
+
* `src` — a key, the logic itself, or a resolver function returning either —
|
|
113
|
+
* is correlated with `input`, so static and mapped inputs typecheck against
|
|
114
|
+
* that logic's input type.
|
|
115
|
+
* - A branch for inline (unregistered) actor logic values, whose `input` cannot
|
|
116
|
+
* be correlated (the config is not generic over inline logic).
|
|
117
|
+
*/
|
|
118
|
+
export type Next_InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> = string extends keyof TActorMap ? // No registered actors (permissive map): `src`/`input` cannot be
|
|
119
|
+
Next_InvokeConfigBase<TContext, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
|
|
120
|
+
src: string | AnyActorLogic | ((args: InvokeSrcArgs<TContext, TEvent, TActorMap>) => string | AnyActorLogic);
|
|
121
|
+
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted>) => unknown) | NonReducibleUnknown;
|
|
122
|
+
} : {
|
|
123
|
+
[K in keyof TActorMap & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
|
|
124
|
+
src: K | TActorMap[K] | ((args: InvokeSrcArgs<TContext, TEvent, TActorMap>) => K | TActorMap[K]);
|
|
125
|
+
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted>) => InputFrom<TActorMap[K]>) | InputFrom<TActorMap[K]>;
|
|
126
|
+
};
|
|
127
|
+
}[keyof TActorMap & string] | (Next_InvokeConfigBase<TContext, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
|
|
128
|
+
src: AnyActorLogic;
|
|
129
|
+
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted>) => unknown) | NonReducibleUnknown;
|
|
130
|
+
});
|
|
131
|
+
interface Next_InvokeConfigBase<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> {
|
|
132
|
+
id?: string;
|
|
133
|
+
systemId?: string;
|
|
134
|
+
onDone?: Next_TransitionConfigOrTarget<TContext, DoneActorEvent<any>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
135
|
+
onError?: Next_TransitionConfigOrTarget<TContext, ErrorEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
136
|
+
onSnapshot?: Next_TransitionConfigOrTarget<TContext, SnapshotEvent<any>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
137
|
+
/**
|
|
138
|
+
* The duration (in ms) after which this invocation will time out if it has
|
|
139
|
+
* not completed. "This task is taking too long."
|
|
140
|
+
*
|
|
141
|
+
* When the timeout expires, the `onTimeout` transition is taken. If the
|
|
142
|
+
* invoke completes first, the timeout is cancelled.
|
|
143
|
+
*/
|
|
144
|
+
timeout?: number | ((args: {
|
|
145
|
+
context: TContext;
|
|
146
|
+
event: TEvent;
|
|
147
|
+
}) => number);
|
|
148
|
+
/**
|
|
149
|
+
* Transition taken when the invoke-level `timeout` expires. Required when
|
|
150
|
+
* `timeout` is set on an invoke.
|
|
151
|
+
*/
|
|
152
|
+
onTimeout?: Next_TransitionConfigOrTarget<TContext, TEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
153
|
+
}
|
|
154
|
+
/** Lookup state input type from an input map, with fallback to undefined */
|
|
155
|
+
type LookupInput<TInputMap extends Record<string, unknown>, K extends string> = K extends keyof TInputMap ? TInputMap[K] : undefined;
|
|
156
|
+
type StateAction<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined> = (_: Omit<Parameters<Action<TContext, TEvent, TEmittedEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, never>>[0], 'params'> & {
|
|
157
|
+
input: TInput;
|
|
158
|
+
}, enqueue: Parameters<Action<TContext, TEvent, TEmittedEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, never>>[1]) => ReturnType<Action<TContext, TEvent, TEmittedEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, never>>;
|
|
159
|
+
type Next_ChoiceTarget<TMeta extends MetaObject> = {
|
|
160
|
+
target: string | string[];
|
|
161
|
+
description?: string;
|
|
162
|
+
reenter?: boolean;
|
|
163
|
+
meta?: TMeta;
|
|
164
|
+
input?: Record<string, unknown> | ((args: {
|
|
165
|
+
context: any;
|
|
166
|
+
event: any;
|
|
167
|
+
}) => Record<string, unknown>);
|
|
168
|
+
};
|
|
169
|
+
type Next_ChoiceArgs<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], _TCtx = [TContext] extends [never] ? any : TContext> = Parameters<TransitionConfigFunction<TContext, TCurrentEvent, TEvent, EventObject, TActionMap, TActorMap, TGuardMap, TDelayMap, MetaObject, _TCtx>>[0];
|
|
170
|
+
/**
|
|
171
|
+
* Route config: either a static config object, or a transition-style function
|
|
172
|
+
* that acts as the route's guard and resolver — returning `undefined`/`false`
|
|
173
|
+
* blocks the route; returning `true` or a config object allows it (optionally
|
|
174
|
+
* updating `context` and providing `input`/`reenter`/`meta`).
|
|
175
|
+
*
|
|
176
|
+
* Guard objects/strings on routes are only produced by the JSON layer
|
|
177
|
+
* (`createMachineFromConfig`) — authoring uses the function form.
|
|
178
|
+
*/
|
|
179
|
+
type Next_RouteConfig<TContext extends MachineContext, TEvent extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
180
|
+
description?: string;
|
|
181
|
+
reenter?: boolean;
|
|
182
|
+
meta?: TMeta;
|
|
183
|
+
input?: Record<string, unknown> | ((args: {
|
|
184
|
+
context: any;
|
|
185
|
+
event: any;
|
|
186
|
+
}) => Record<string, unknown>);
|
|
187
|
+
} | ((args: Next_ChoiceArgs<TContext, TEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>) => boolean | void | {
|
|
188
|
+
context?: TContext;
|
|
189
|
+
reenter?: boolean;
|
|
190
|
+
meta?: TMeta;
|
|
191
|
+
input?: Record<string, unknown> | ((args: {
|
|
192
|
+
context: any;
|
|
193
|
+
event: any;
|
|
194
|
+
}) => Record<string, unknown>);
|
|
195
|
+
});
|
|
196
|
+
type Next_ChoiceConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, _TCtx = [TContext] extends [never] ? any : TContext> = (args: Next_ChoiceArgs<TContext, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, _TCtx>) => Next_ChoiceTarget<TMeta>;
|
|
197
|
+
export type Next_StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown>> = Next_RegularStateNodeConfig<TContext, TEvent, TDelays, TTag, _TOutput, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TInput, TInputMap> | Next_ChoiceStateNodeConfig<TContext, TEvent, TTag, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
198
|
+
interface Next_ChoiceStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TTag extends string, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
199
|
+
contextSchema?: StandardSchemaV1;
|
|
200
|
+
type: 'choice';
|
|
201
|
+
/** Function that resolves this choice state to a target. */
|
|
202
|
+
choice: Next_ChoiceConfigFunction<TContext, TEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
203
|
+
id?: string | undefined;
|
|
204
|
+
order?: number;
|
|
205
|
+
tags?: TTag[];
|
|
206
|
+
description?: string;
|
|
207
|
+
meta?: TMeta;
|
|
208
|
+
route?: Next_RouteConfig<TContext, TEvent, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> | undefined;
|
|
209
|
+
initial?: never;
|
|
210
|
+
history?: never;
|
|
211
|
+
states?: never;
|
|
212
|
+
invoke?: never;
|
|
213
|
+
on?: never;
|
|
214
|
+
entry?: never;
|
|
215
|
+
exit?: never;
|
|
216
|
+
onDone?: never;
|
|
217
|
+
after?: never;
|
|
218
|
+
timeout?: never;
|
|
219
|
+
onTimeout?: never;
|
|
220
|
+
always?: never;
|
|
221
|
+
output?: never;
|
|
222
|
+
target?: never;
|
|
223
|
+
}
|
|
224
|
+
interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown>> {
|
|
225
|
+
contextSchema?: StandardSchemaV1;
|
|
226
|
+
/** The initial state transition. */
|
|
227
|
+
initial?: string | {
|
|
228
|
+
target: string;
|
|
229
|
+
input?: Record<string, unknown> | ((args: {
|
|
230
|
+
context: TContext;
|
|
231
|
+
event: TEvent;
|
|
232
|
+
}) => Record<string, unknown>);
|
|
233
|
+
} | undefined;
|
|
234
|
+
/**
|
|
235
|
+
* The type of this state node:
|
|
236
|
+
*
|
|
237
|
+
* - `'atomic'` - no child state nodes
|
|
238
|
+
* - `'compound'` - nested child state nodes (XOR)
|
|
239
|
+
* - `'parallel'` - orthogonal nested child state nodes (AND)
|
|
240
|
+
* - `'history'` - history state node
|
|
241
|
+
* - `'final'` - final state node
|
|
242
|
+
*/
|
|
243
|
+
type?: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
|
|
244
|
+
/**
|
|
245
|
+
* Indicates whether the state node is a history state node, and what type of
|
|
246
|
+
* history: shallow, deep, true (shallow), false (none), undefined (none)
|
|
247
|
+
*/
|
|
248
|
+
history?: 'shallow' | 'deep' | boolean | undefined;
|
|
249
|
+
/**
|
|
250
|
+
* The mapping of state node keys to their state node configurations
|
|
251
|
+
* (recursive).
|
|
252
|
+
*/
|
|
253
|
+
states?: {
|
|
254
|
+
[K in string]: Next_StateNodeConfig<TContext, TEvent, TDelays, TTag, any, // TOutput,
|
|
255
|
+
TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, LookupInput<TInputMap, K>, TInputMap>;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* The services to invoke upon entering this state node. These services will
|
|
259
|
+
* be stopped upon exiting this state node.
|
|
260
|
+
*/
|
|
261
|
+
invoke?: SingleOrArray<Next_InvokeConfig<TContext, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>>;
|
|
262
|
+
/** The mapping of event types to their potential transition(s). */
|
|
263
|
+
on?: {
|
|
264
|
+
[K in EventDescriptor<TEvent>]?: Next_TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Enables routing to this state via `{ type: 'xstate.route', to: '#id' }`.
|
|
268
|
+
* Requires this state node to have an explicit `id`.
|
|
269
|
+
*/
|
|
270
|
+
route?: Next_RouteConfig<TContext, TEvent, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> | undefined;
|
|
271
|
+
entry?: StateAction<TContext, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TInput>;
|
|
272
|
+
exit?: StateAction<TContext, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TInput>;
|
|
273
|
+
/**
|
|
274
|
+
* The potential transition(s) to be taken upon reaching a final child state
|
|
275
|
+
* node.
|
|
276
|
+
*
|
|
277
|
+
* This is equivalent to defining a `[done(id)]` transition on this state
|
|
278
|
+
* node's `on` property.
|
|
279
|
+
*/
|
|
280
|
+
onDone?: string | TransitionConfigFunction<TContext, DoneStateEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> | undefined;
|
|
281
|
+
/**
|
|
282
|
+
* The mapping (or array) of delays (in milliseconds) to their potential
|
|
283
|
+
* transition(s). The delayed transitions are taken after the specified delay
|
|
284
|
+
* in an interpreter.
|
|
285
|
+
*/
|
|
286
|
+
after?: {
|
|
287
|
+
[K in NoInfer<TDelays> | number]?: string | {
|
|
288
|
+
target: string;
|
|
289
|
+
} | TransitionConfigFunction<TContext, TEvent, TEvent, TODO, // TEmitted
|
|
290
|
+
TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* The duration (in ms) after which this state will transition via `onTimeout`
|
|
294
|
+
* if still active. "We've been in this state too long."
|
|
295
|
+
*
|
|
296
|
+
* Independent of `after` - both can coexist on the same state. Both cancel on
|
|
297
|
+
* state exit.
|
|
298
|
+
*
|
|
299
|
+
* Can be a static number, a delay reference string, or a dynamic function.
|
|
300
|
+
*/
|
|
301
|
+
timeout?: number | NoInfer<TDelays> | ((args: {
|
|
302
|
+
context: TContext;
|
|
303
|
+
event: TEvent;
|
|
304
|
+
stateNode: AnyStateNode;
|
|
305
|
+
}) => number);
|
|
306
|
+
/** Transition taken when `timeout` expires. Required when `timeout` is set. */
|
|
307
|
+
onTimeout?: Next_TransitionConfigOrTarget<TContext, TEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
308
|
+
/**
|
|
309
|
+
* An eventless transition that is always taken when this state node is
|
|
310
|
+
* active.
|
|
311
|
+
*/
|
|
312
|
+
always?: Next_TransitionConfigOrTarget<TContext, TEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
313
|
+
choice?: never;
|
|
314
|
+
/**
|
|
315
|
+
* The meta data associated with this state node, which will be returned in
|
|
316
|
+
* State instances.
|
|
317
|
+
*/
|
|
318
|
+
meta?: TMeta;
|
|
319
|
+
/**
|
|
320
|
+
* The output data sent with the "xstate.done.state._id_" event if this is a
|
|
321
|
+
* final state node.
|
|
322
|
+
*
|
|
323
|
+
* The output data will be evaluated with the current `context` and placed on
|
|
324
|
+
* the `.data` property of the event.
|
|
325
|
+
*/
|
|
326
|
+
output?: Mapper<TContext, TEvent, unknown, TEvent> | NonReducibleUnknown;
|
|
327
|
+
/**
|
|
328
|
+
* The unique ID of the state node, which can be referenced as a transition
|
|
329
|
+
* target via the `#id` syntax.
|
|
330
|
+
*/
|
|
331
|
+
id?: string | undefined;
|
|
332
|
+
/**
|
|
333
|
+
* The order this state node appears. Corresponds to the implicit document
|
|
334
|
+
* order.
|
|
335
|
+
*/
|
|
336
|
+
order?: number;
|
|
337
|
+
/**
|
|
338
|
+
* The tags for this state node, which are accumulated into the `state.tags`
|
|
339
|
+
* property.
|
|
340
|
+
*/
|
|
341
|
+
tags?: TTag[];
|
|
342
|
+
/** A text description of the state node */
|
|
343
|
+
description?: string;
|
|
344
|
+
/** A default target for a history state */
|
|
345
|
+
target?: string | undefined;
|
|
346
|
+
}
|
|
347
|
+
export type Next_TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> = string | undefined | {
|
|
348
|
+
target?: string | string[];
|
|
349
|
+
description?: string;
|
|
350
|
+
reenter?: boolean;
|
|
351
|
+
meta?: TMeta;
|
|
352
|
+
input?: Record<string, unknown> | ((args: {
|
|
353
|
+
context: any;
|
|
354
|
+
event: any;
|
|
355
|
+
}) => Record<string, unknown>);
|
|
356
|
+
} | {
|
|
357
|
+
to?: TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
358
|
+
description?: string;
|
|
359
|
+
reenter?: boolean;
|
|
360
|
+
meta?: TMeta;
|
|
361
|
+
input?: Record<string, unknown> | ((args: {
|
|
362
|
+
context: any;
|
|
363
|
+
event: any;
|
|
364
|
+
}) => Record<string, unknown>);
|
|
365
|
+
} | TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
366
|
+
export type WithDefault<T, Default> = IsNever<T> extends true ? Default : T;
|
|
367
|
+
export interface Implementations {
|
|
368
|
+
actions: Record<string, (...args: any[]) => void | {
|
|
369
|
+
context?: any;
|
|
370
|
+
children?: any;
|
|
371
|
+
}>;
|
|
372
|
+
guards: Record<string, (...args: any[]) => boolean>;
|
|
373
|
+
delays: Record<string, number | ((...args: any[]) => number)>;
|
|
374
|
+
actors: Record<string, AnyActorLogic>;
|
|
375
|
+
}
|
|
376
|
+
export type DelayMapFromNames<TDelays extends string, _TDelayMap extends Implementations['delays']> = string extends TDelays ? Implementations['delays'] : {
|
|
377
|
+
[K in TDelays]: Implementations['delays'][string];
|
|
378
|
+
};
|
|
379
|
+
type DelayNamesFromConfig<TConfig> = TConfig extends {
|
|
380
|
+
delays: infer TDelays;
|
|
381
|
+
} ? Extract<keyof TDelays, string> : string;
|
|
382
|
+
type InvalidDelayReferences<TConfig, TDelays extends string> = (TConfig extends {
|
|
383
|
+
after: infer TAfter;
|
|
384
|
+
} ? Exclude<Extract<keyof TAfter, string>, TDelays> : never) | (TConfig extends {
|
|
385
|
+
timeout: infer TTimeout;
|
|
386
|
+
} ? TTimeout extends string ? TTimeout extends TDelays ? never : TTimeout : never : never) | (TConfig extends {
|
|
387
|
+
states: infer TStates;
|
|
388
|
+
} ? TStates extends Record<string, unknown> ? {
|
|
389
|
+
[K in keyof TStates]: InvalidDelayReferences<TStates[K], TDelays>;
|
|
390
|
+
}[keyof TStates] : never : never);
|
|
391
|
+
export type ValidateDelayReferences<TConfig> = string extends DelayNamesFromConfig<TConfig> ? unknown : InvalidDelayReferences<TConfig, DelayNamesFromConfig<TConfig>> extends never ? unknown : never;
|
|
392
|
+
export {};
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import type { StateNode } from "./StateNode.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AnyActor, AnyEventObject, AnyMachineSnapshot, AnyStateMachine, AnyTransitionConfig, AnyTransitionConfigFunction, ErrorActorEvent, EventObject, MachineContext, Mapper, NonReducibleUnknown, Observer, SingleOrArray, StateValue, TransitionConfigTarget } from "./types.js";
|
|
3
3
|
export declare function matchesState(parentStateId: StateValue, childStateId: StateValue): boolean;
|
|
4
|
+
export declare function checkStateIn(snapshot: AnyMachineSnapshot, stateValue: StateValue): boolean;
|
|
4
5
|
export declare function toStatePath(stateId: string | string[]): string[];
|
|
5
6
|
export declare function pathToStateValue(statePath: string[]): StateValue;
|
|
6
7
|
export declare function mapValues<P, O extends Record<string, unknown>>(collection: O, iteratee: (item: O[keyof O], key: keyof O, collection: O, i: number) => P): {
|
|
7
8
|
[key in keyof O]: P;
|
|
8
9
|
};
|
|
9
10
|
export declare function toArray<T>(value: readonly T[] | T | undefined): readonly T[];
|
|
10
|
-
export declare function resolveOutput<TContext extends MachineContext, TExpressionEvent extends EventObject>(mapper: Mapper<TContext, TExpressionEvent, unknown, EventObject> | NonReducibleUnknown, context: TContext, event: TExpressionEvent, self:
|
|
11
|
+
export declare function resolveOutput<TContext extends MachineContext, TExpressionEvent extends EventObject>(mapper: Mapper<TContext, TExpressionEvent, unknown, EventObject> | NonReducibleUnknown, context: TContext, event: TExpressionEvent, self: AnyActor): unknown;
|
|
11
12
|
export declare function isErrorActorEvent(event: AnyEventObject): event is ErrorActorEvent;
|
|
12
|
-
export declare function toTransitionConfigArray(configLike: SingleOrArray<AnyTransitionConfig | TransitionConfigTarget>): Array<AnyTransitionConfig>;
|
|
13
|
+
export declare function toTransitionConfigArray(configLike: SingleOrArray<AnyTransitionConfig | TransitionConfigTarget | AnyTransitionConfigFunction>): Array<AnyTransitionConfig>;
|
|
13
14
|
export declare function normalizeTarget<TContext extends MachineContext, TEvent extends EventObject>(target: SingleOrArray<string | StateNode<TContext, TEvent>> | undefined): ReadonlyArray<string | StateNode<TContext, TEvent>> | undefined;
|
|
14
15
|
export declare function toObserver<T>(nextHandler?: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
|
|
15
16
|
export declare function createInvokeId(stateNodeId: string, index: number): string;
|