xstate 6.0.0-alpha.2 → 6.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -17
- package/bin/xstate.js +36 -0
- package/dist/{StateMachine-64813f46.cjs.js → StateMachine-1b155670.cjs.js} +182 -40
- package/dist/{StateMachine-2dcdb1f5.esm.js → StateMachine-3c17fe3e.esm.js} +182 -40
- package/dist/{StateMachine-8d22a79c.development.cjs.js → StateMachine-550ff7f2.development.cjs.js} +193 -36
- package/dist/{StateMachine-2ea0a7fa.development.esm.js → StateMachine-e25dd61f.development.esm.js} +193 -36
- package/dist/declarations/src/State.d.ts +13 -2
- package/dist/declarations/src/StateMachine.d.ts +23 -13
- package/dist/declarations/src/actions.d.ts +2 -1
- package/dist/declarations/src/actors/promise.d.ts +4 -2
- package/dist/declarations/src/createActor.d.ts +9 -11
- package/dist/declarations/src/createMachine.d.ts +14 -11
- package/dist/declarations/src/createMachineFromConfig.d.ts +61 -28
- package/dist/declarations/src/fsm.d.ts +74 -0
- package/dist/declarations/src/graph/graph.d.ts +3 -3
- package/dist/declarations/src/graph/shortestPaths.d.ts +2 -2
- package/dist/declarations/src/graph/simplePaths.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +6 -5
- package/dist/declarations/src/serialize.d.ts +10 -18
- package/dist/declarations/src/setup.d.ts +277 -65
- package/dist/declarations/src/spawn.d.ts +3 -3
- package/dist/declarations/src/stateUtils.d.ts +4 -1
- package/dist/declarations/src/system.d.ts +1 -1
- package/dist/declarations/src/transition.d.ts +8 -5
- package/dist/declarations/src/transitionActions.d.ts +12 -0
- package/dist/declarations/src/types.d.ts +237 -102
- package/dist/declarations/src/types.v6.d.ts +132 -58
- package/dist/declarations/src/utils.d.ts +4 -3
- package/dist/{index-93edd3bd.esm.js → index-3f87408c.esm.js} +936 -1389
- package/dist/{index-e61170ba.development.esm.js → index-d39fb138.development.esm.js} +968 -1421
- package/dist/{index-9cb3b3a0.cjs.js → index-e694228c.cjs.js} +945 -1394
- package/dist/{index-f6ef20d1.development.cjs.js → index-ec7c7a2d.development.cjs.js} +977 -1426
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +1 -1
- package/dist/xstate-actors.esm.js +1 -1
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +2 -2
- package/dist/xstate-graph.development.cjs.js +2 -2
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +1100 -182
- package/dist/xstate.cjs.mjs +3 -5
- package/dist/xstate.development.cjs.js +1100 -182
- package/dist/xstate.development.cjs.mjs +3 -5
- package/dist/xstate.development.esm.js +1101 -181
- package/dist/xstate.esm.js +1101 -181
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +6 -2
- package/dist/declarations/src/atom.d.ts +0 -81
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./schema.types.js";
|
|
2
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";
|
|
3
|
+
import { Action, ActorLogic, ActorRef, ActorRefFromLogic, ActorSelf, AnyActorLogic, AnyActorRef, Compute, DoneActorEvent, DoNotInfer, ErrorActorEvent, EventDescriptor, ErrorEvent, EventObject, ExtractEvent, InitialContext, InputFrom, IsNever, MetaObject, NonReducibleUnknown, OutputFrom, SingleOrArray, SnapshotEvent, StateValue, TODO, TransitionContextMapper, TransitionContextPatch, TransitionConfigFunction, Values, AnyStateNode, SystemRegistry } from "./types.js";
|
|
4
4
|
import { MachineContext, Mapper } from "./types.js";
|
|
5
5
|
import { LowInfer } from "./types.js";
|
|
6
6
|
import { DoneStateEvent } from "./types.js";
|
|
@@ -11,12 +11,55 @@ export type InferOutput<T extends StandardSchemaV1, U> = Compute<StandardSchemaV
|
|
|
11
11
|
* are required on the event.
|
|
12
12
|
*/
|
|
13
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 & {
|
|
14
|
+
[K in keyof TEventSchemaMap & string]: StandardSchemaV1.InferOutput<TEventSchemaMap[K]> extends infer O ? [O] extends [never] ? never : unknown extends O ? O & {
|
|
15
|
+
type: K;
|
|
16
|
+
} : [O] extends [void] ? {
|
|
17
|
+
type: K;
|
|
18
|
+
} : string extends keyof O ? [O[string]] extends [never] ? {
|
|
19
|
+
type: K;
|
|
20
|
+
} : Required<O> & {
|
|
15
21
|
type: K;
|
|
16
22
|
} : Required<O> & {
|
|
17
23
|
type: K;
|
|
18
24
|
} : never;
|
|
19
25
|
}>;
|
|
26
|
+
export type InferChildren<TChildrenSchemaMap extends Record<string, StandardSchemaV1>> = string extends keyof TChildrenSchemaMap ? {} : {
|
|
27
|
+
[K in keyof TChildrenSchemaMap & string]?: StandardSchemaV1.InferOutput<TChildrenSchemaMap[K]> extends AnyActorRef ? NormalizeActorRef<StandardSchemaV1.InferOutput<TChildrenSchemaMap[K]>> : never;
|
|
28
|
+
};
|
|
29
|
+
export type ActionSchemas = Record<string, {
|
|
30
|
+
params: StandardSchemaV1;
|
|
31
|
+
}>;
|
|
32
|
+
export type GuardSchemas = Record<string, {
|
|
33
|
+
params: StandardSchemaV1;
|
|
34
|
+
}>;
|
|
35
|
+
export type InferActions<TActionSchemaMap extends ActionSchemas> = string extends keyof TActionSchemaMap ? {} : {
|
|
36
|
+
[K in keyof TActionSchemaMap & string]: (params: StandardSchemaV1.InferOutput<TActionSchemaMap[K]['params']>) => void | {
|
|
37
|
+
context?: any;
|
|
38
|
+
children?: any;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export type InferGuards<TGuardSchemaMap extends GuardSchemas> = string extends keyof TGuardSchemaMap ? {} : {
|
|
42
|
+
[K in keyof TGuardSchemaMap & string]: (params: StandardSchemaV1.InferOutput<TGuardSchemaMap[K]['params']>) => boolean;
|
|
43
|
+
};
|
|
44
|
+
type OutputMapper<TContext extends MachineContext, TEvent extends EventObject, TResult, TInput = Record<string, unknown> | undefined> = (args: Parameters<Mapper<TContext, TEvent, TResult, TEvent>>[0] & {
|
|
45
|
+
input: TInput;
|
|
46
|
+
}) => TResult;
|
|
47
|
+
type OutputConfig<TContext extends MachineContext, TEvent extends EventObject, TOutput, TInput = Record<string, unknown> | undefined> = unknown extends TOutput ? OutputMapper<TContext, TEvent, NonReducibleUnknown, TInput> | NonReducibleUnknown : OutputMapper<TContext, TEvent, TOutput, TInput> | TOutput;
|
|
48
|
+
export type ValidateTopLevelFinalOutputs<TConfig, TContext extends MachineContext, TEvent extends EventObject> = TConfig extends {
|
|
49
|
+
schemas: {
|
|
50
|
+
output: infer TOutputSchema extends StandardSchemaV1;
|
|
51
|
+
};
|
|
52
|
+
states: infer TStates;
|
|
53
|
+
} ? {
|
|
54
|
+
states?: {
|
|
55
|
+
[K in keyof TStates]: TStates[K] extends {
|
|
56
|
+
type: 'final';
|
|
57
|
+
} ? TStates[K] & {
|
|
58
|
+
output?: OutputConfig<TContext, TEvent, StandardSchemaV1.InferOutput<TOutputSchema>>;
|
|
59
|
+
} : TStates[K];
|
|
60
|
+
};
|
|
61
|
+
} : {};
|
|
62
|
+
type NormalizeActorRef<TActorRef> = TActorRef extends ActorRef<infer TSnapshot, infer TEvent, infer TEmitted, infer TSendEvent> ? ActorRef<TSnapshot, TEvent, TEmitted, TSendEvent> : never;
|
|
20
63
|
type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
21
64
|
type InternalEventDescriptorFor<TEvent extends EventObject> = [TEvent] extends [
|
|
22
65
|
never
|
|
@@ -46,20 +89,25 @@ export interface MachineOptions {
|
|
|
46
89
|
*/
|
|
47
90
|
maxIterations?: number;
|
|
48
91
|
}
|
|
49
|
-
|
|
92
|
+
type MachineSchemas<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, TChildrenSchemaMap extends Record<string, StandardSchemaV1>> = {
|
|
93
|
+
events?: TEventSchemaMap;
|
|
94
|
+
actions?: ActionSchemas;
|
|
95
|
+
guards?: GuardSchemas;
|
|
96
|
+
context?: TContextSchema;
|
|
97
|
+
emitted?: TEmittedSchemaMap;
|
|
98
|
+
input?: TInputSchema;
|
|
99
|
+
output?: TOutputSchema;
|
|
100
|
+
meta?: TMetaSchema;
|
|
101
|
+
tags?: TTagSchema;
|
|
102
|
+
children?: TChildrenSchemaMap;
|
|
103
|
+
};
|
|
104
|
+
export type AnyMachineSchemas = MachineSchemas<StandardSchemaV1, Record<string, StandardSchemaV1>, Record<string, StandardSchemaV1>, StandardSchemaV1, StandardSchemaV1, StandardSchemaV1, StandardSchemaV1, Record<string, StandardSchemaV1>>;
|
|
105
|
+
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, TChildrenSchemaMap extends Record<string, StandardSchemaV1>, TContext extends MachineContext = InferOutput<TContextSchema, MachineContext>, TEvent extends EventObject = InferEvents<TEventSchemaMap>, TChildren extends Record<string, AnyActorRef | undefined> = InferChildren<TChildrenSchemaMap>, TDelays extends string = string, _TTag extends string = string, TActionMap extends Implementations['actions'] = Implementations['actions'], TActorMap extends Implementations['actorSources'] = Implementations['actorSources'], TGuardMap extends Implementations['guards'] = Implementations['guards'], TDelayMap extends Implementations['delays'] = Implementations['delays'], TContextRequired extends boolean = IsNever<TContext> extends true ? false : true, TSystemRegistry extends SystemRegistry = SystemRegistry> = (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<TChildren>, DoNotInfer<TActionMap>, DoNotInfer<TActorMap>, DoNotInfer<TGuardMap>, DoNotInfer<TDelayMap>, Record<string, unknown> | undefined, Record<string, unknown>, DoNotInfer<TSystemRegistry>, DoNotInfer<InferOutput<TOutputSchema, unknown>>>, 'output'> & {
|
|
50
106
|
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
|
-
};
|
|
107
|
+
schemas?: MachineSchemas<TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap>;
|
|
60
108
|
actions?: TActionMap;
|
|
61
109
|
guards?: TGuardMap;
|
|
62
|
-
|
|
110
|
+
actorSources?: TActorMap;
|
|
63
111
|
/** The machine's own version. */
|
|
64
112
|
version?: string;
|
|
65
113
|
/**
|
|
@@ -70,7 +118,7 @@ export type Next_MachineConfig<TContextSchema extends StandardSchemaV1, TEventSc
|
|
|
70
118
|
* version-mismatched snapshot without a `migrate` function throws.
|
|
71
119
|
*/
|
|
72
120
|
migrate?: (persistedSnapshot: any, fromVersion: string | undefined) => unknown;
|
|
73
|
-
output?: Mapper<TContext, DoneStateEvent, InferOutput<TOutputSchema, unknown
|
|
121
|
+
output?: Mapper<TContext, DoneStateEvent<DoNotInfer<InferOutput<TOutputSchema, unknown>>>, DoNotInfer<InferOutput<TOutputSchema, unknown>>, TEvent> | DoNotInfer<InferOutput<TOutputSchema, unknown>>;
|
|
74
122
|
delays?: {
|
|
75
123
|
[K in TDelays | number]?: number | (({ context, event, stateNode }: {
|
|
76
124
|
context: TContext;
|
|
@@ -94,45 +142,63 @@ export type Next_MachineConfig<TContextSchema extends StandardSchemaV1, TEventSc
|
|
|
94
142
|
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
143
|
-readonly [K in keyof T]: WidenLiterals<T[K]>;
|
|
96
144
|
} : T;
|
|
97
|
-
type InvokeSrcArgs<TContext extends MachineContext, TEvent extends EventObject, TActorMap extends Implementations['
|
|
98
|
-
|
|
145
|
+
type InvokeSrcArgs<TContext extends MachineContext, TEvent extends EventObject, TActorMap extends Implementations['actorSources']> = {
|
|
146
|
+
actorSources: TActorMap;
|
|
99
147
|
context: TContext;
|
|
100
148
|
event: TEvent;
|
|
101
149
|
self: AnyActorRef;
|
|
102
150
|
};
|
|
103
|
-
type InvokeInputArgs<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject
|
|
151
|
+
type InvokeInputArgs<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>> = {
|
|
104
152
|
context: TContext;
|
|
105
153
|
event: TEvent;
|
|
106
|
-
self: ActorSelf<MachineSnapshot<TContext, TEvent,
|
|
154
|
+
self: ActorSelf<MachineSnapshot<TContext, TEvent, TChildren, StateValue, string, unknown, TODO, TODO>, TEvent, TEmitted>;
|
|
155
|
+
};
|
|
156
|
+
type HasExplicitChildren<TChildren extends Record<string, AnyActorRef | undefined>> = string extends keyof TChildren ? false : [keyof TChildren] extends [never] ? false : true;
|
|
157
|
+
type ChildIdForLogic<TLogic extends AnyActorLogic, TChildren extends Record<string, AnyActorRef | undefined>> = HasExplicitChildren<TChildren> extends true ? Values<{
|
|
158
|
+
[K in keyof TChildren & string]: ActorRefFromLogic<TLogic> extends NonNullable<TChildren[K]> ? K : never;
|
|
159
|
+
}> : string;
|
|
160
|
+
type LogicForChildRef<TActorRef> = NonNullable<TActorRef> extends ActorRef<infer TSnapshot, infer TEvent, infer TEmitted, any> ? ActorLogic<TSnapshot, TEvent, any, any, TEmitted> : never;
|
|
161
|
+
type InlineChildInvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry> = Values<{
|
|
162
|
+
[K in keyof TChildren & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> & {
|
|
163
|
+
id: K;
|
|
164
|
+
src: LogicForChildRef<TChildren[K]>;
|
|
165
|
+
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => unknown) | NonReducibleUnknown;
|
|
166
|
+
};
|
|
167
|
+
}>;
|
|
168
|
+
type InlineInvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry> = HasExplicitChildren<TChildren> extends true ? InlineChildInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> : Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> & {
|
|
169
|
+
src: AnyActorLogic;
|
|
170
|
+
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => unknown) | NonReducibleUnknown;
|
|
107
171
|
};
|
|
108
172
|
/**
|
|
109
173
|
* Invoke config. A union of:
|
|
110
174
|
*
|
|
111
|
-
* - One branch per registered actor (distributed over the `
|
|
112
|
-
* `src` — a key, the logic itself, or a resolver function
|
|
113
|
-
* is correlated with `input`, so static and mapped inputs
|
|
114
|
-
* that logic's input type.
|
|
175
|
+
* - One branch per registered actor source (distributed over the `actorSources`
|
|
176
|
+
* map), where `src` — a key, the logic itself, or a resolver function
|
|
177
|
+
* returning either — is correlated with `input`, so static and mapped inputs
|
|
178
|
+
* typecheck against that logic's input type.
|
|
115
179
|
* - A branch for inline (unregistered) actor logic values, whose `input` cannot
|
|
116
180
|
* be correlated (the config is not generic over inline logic).
|
|
117
181
|
*/
|
|
118
|
-
export type Next_InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
119
|
-
Next_InvokeConfigBase<TContext, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
|
|
182
|
+
export type Next_InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry = SystemRegistry> = string extends keyof TActorMap ? HasExplicitChildren<TChildren> extends true ? InlineInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> : Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry> & {
|
|
120
183
|
src: string | AnyActorLogic | ((args: InvokeSrcArgs<TContext, TEvent, TActorMap>) => string | AnyActorLogic);
|
|
121
|
-
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted>) => unknown) | NonReducibleUnknown;
|
|
184
|
+
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => unknown) | NonReducibleUnknown;
|
|
122
185
|
} : {
|
|
123
|
-
[K in keyof TActorMap & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta
|
|
124
|
-
|
|
125
|
-
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted>) => InputFrom<TActorMap[K]>) | InputFrom<TActorMap[K]>;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
186
|
+
[K in keyof TActorMap & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry, DoneActorEvent<OutputFrom<TActorMap[K]>>> & {
|
|
187
|
+
id?: ChildIdForLogic<TActorMap[K], TChildren>;
|
|
188
|
+
input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => InputFrom<TActorMap[K]>) | InputFrom<TActorMap[K]>;
|
|
189
|
+
} & ({
|
|
190
|
+
src: K;
|
|
191
|
+
} | {
|
|
192
|
+
src: TActorMap[K];
|
|
193
|
+
} | {
|
|
194
|
+
src: (args: InvokeSrcArgs<TContext, TEvent, TActorMap>) => K | TActorMap[K];
|
|
195
|
+
});
|
|
196
|
+
}[keyof TActorMap & string] | InlineInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry>;
|
|
197
|
+
interface Next_InvokeConfigBase<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, _TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TSystemRegistry extends SystemRegistry, TDoneEvent extends EventObject = [keyof TActorMap & string] extends [never] ? DoneActorEvent<any> : DoneActorEvent<OutputFrom<TActorMap[keyof TActorMap & string]>>> {
|
|
132
198
|
id?: string;
|
|
133
|
-
|
|
134
|
-
onDone?: Next_TransitionConfigOrTarget<TContext,
|
|
135
|
-
onError?: Next_TransitionConfigOrTarget<TContext,
|
|
199
|
+
registryKey?: keyof TSystemRegistry & string;
|
|
200
|
+
onDone?: Next_TransitionConfigOrTarget<TContext, TDoneEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
201
|
+
onError?: Next_TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
136
202
|
onSnapshot?: Next_TransitionConfigOrTarget<TContext, SnapshotEvent<any>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
137
203
|
/**
|
|
138
204
|
* The duration (in ms) after which this invocation will time out if it has
|
|
@@ -153,7 +219,7 @@ interface Next_InvokeConfigBase<TContext extends MachineContext, TEvent extends
|
|
|
153
219
|
}
|
|
154
220
|
/** Lookup state input type from an input map, with fallback to undefined */
|
|
155
221
|
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['
|
|
222
|
+
type StateAction<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined> = (_: Omit<Parameters<Action<TContext, TEvent, TEmittedEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, never>>[0], 'params'> & {
|
|
157
223
|
input: TInput;
|
|
158
224
|
}, enqueue: Parameters<Action<TContext, TEvent, TEmittedEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, never>>[1]) => ReturnType<Action<TContext, TEvent, TEmittedEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, never>>;
|
|
159
225
|
type Next_ChoiceTarget<TMeta extends MetaObject> = {
|
|
@@ -166,7 +232,8 @@ type Next_ChoiceTarget<TMeta extends MetaObject> = {
|
|
|
166
232
|
event: any;
|
|
167
233
|
}) => Record<string, unknown>);
|
|
168
234
|
};
|
|
169
|
-
type Next_ChoiceArgs<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
235
|
+
type Next_ChoiceArgs<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], _TCtx extends MachineContext = [TContext] extends [never] ? any : TContext> = Parameters<TransitionConfigFunction<TContext, TCurrentEvent, TEvent, EventObject, TActionMap, TActorMap, TGuardMap, TDelayMap, MetaObject, undefined, // TInput
|
|
236
|
+
_TCtx>>[0];
|
|
170
237
|
/**
|
|
171
238
|
* Route config: either a static config object, or a transition-style function
|
|
172
239
|
* that acts as the route's guard and resolver — returning `undefined`/`false`
|
|
@@ -176,7 +243,7 @@ type Next_ChoiceArgs<TContext extends MachineContext, TCurrentEvent extends Even
|
|
|
176
243
|
* Guard objects/strings on routes are only produced by the JSON layer
|
|
177
244
|
* (`createMachineFromConfig`) — authoring uses the function form.
|
|
178
245
|
*/
|
|
179
|
-
type Next_RouteConfig<TContext extends MachineContext, TEvent extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
246
|
+
type Next_RouteConfig<TContext extends MachineContext, TEvent extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
180
247
|
description?: string;
|
|
181
248
|
reenter?: boolean;
|
|
182
249
|
meta?: TMeta;
|
|
@@ -193,9 +260,9 @@ type Next_RouteConfig<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
193
260
|
event: any;
|
|
194
261
|
}) => Record<string, unknown>);
|
|
195
262
|
});
|
|
196
|
-
type Next_ChoiceConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
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['
|
|
198
|
-
interface Next_ChoiceStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TTag extends string, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
263
|
+
type Next_ChoiceConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, _TCtx extends MachineContext = [TContext] extends [never] ? any : TContext> = (args: Next_ChoiceArgs<TContext, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, _TCtx>) => Next_ChoiceTarget<TMeta>;
|
|
264
|
+
export type Next_StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown>, TSystemRegistry extends SystemRegistry = SystemRegistry, TChildOutput = unknown> = Next_RegularStateNodeConfig<TContext, TEvent, TDelays, TTag, _TOutput, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TInput, TInputMap, TSystemRegistry, TChildOutput> | Next_ChoiceStateNodeConfig<TContext, TEvent, TTag, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
265
|
+
interface Next_ChoiceStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TTag extends string, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
199
266
|
contextSchema?: StandardSchemaV1;
|
|
200
267
|
type: 'choice';
|
|
201
268
|
/** Function that resolves this choice state to a target. */
|
|
@@ -214,6 +281,7 @@ interface Next_ChoiceStateNodeConfig<TContext extends MachineContext, TEvent ext
|
|
|
214
281
|
entry?: never;
|
|
215
282
|
exit?: never;
|
|
216
283
|
onDone?: never;
|
|
284
|
+
onError?: never;
|
|
217
285
|
after?: never;
|
|
218
286
|
timeout?: never;
|
|
219
287
|
onTimeout?: never;
|
|
@@ -221,7 +289,7 @@ interface Next_ChoiceStateNodeConfig<TContext extends MachineContext, TEvent ext
|
|
|
221
289
|
output?: never;
|
|
222
290
|
target?: never;
|
|
223
291
|
}
|
|
224
|
-
interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string,
|
|
292
|
+
interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown>, TSystemRegistry extends SystemRegistry = SystemRegistry, TChildOutput = unknown> {
|
|
225
293
|
contextSchema?: StandardSchemaV1;
|
|
226
294
|
/** The initial state transition. */
|
|
227
295
|
initial?: string | {
|
|
@@ -252,16 +320,16 @@ interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
252
320
|
*/
|
|
253
321
|
states?: {
|
|
254
322
|
[K in string]: Next_StateNodeConfig<TContext, TEvent, TDelays, TTag, any, // TOutput,
|
|
255
|
-
TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, LookupInput<TInputMap, K>, TInputMap>;
|
|
323
|
+
TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, LookupInput<TInputMap, K>, TInputMap, TSystemRegistry, TChildOutput>;
|
|
256
324
|
};
|
|
257
325
|
/**
|
|
258
326
|
* The services to invoke upon entering this state node. These services will
|
|
259
327
|
* be stopped upon exiting this state node.
|
|
260
328
|
*/
|
|
261
|
-
invoke?: SingleOrArray<Next_InvokeConfig<TContext, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>>;
|
|
329
|
+
invoke?: SingleOrArray<Next_InvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TSystemRegistry>>;
|
|
262
330
|
/** The mapping of event types to their potential transition(s). */
|
|
263
331
|
on?: {
|
|
264
|
-
[K in EventDescriptor<TEvent>]?: Next_TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
332
|
+
[K in EventDescriptor<TEvent>]?: Next_TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TInput>;
|
|
265
333
|
};
|
|
266
334
|
/**
|
|
267
335
|
* Enables routing to this state via `{ type: 'xstate.route', to: '#id' }`.
|
|
@@ -277,17 +345,22 @@ interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
277
345
|
* This is equivalent to defining a `[done(id)]` transition on this state
|
|
278
346
|
* node's `on` property.
|
|
279
347
|
*/
|
|
280
|
-
onDone?:
|
|
348
|
+
onDone?: Next_TransitionConfigOrTarget<TContext, DoneStateEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
349
|
+
/**
|
|
350
|
+
* The transition to take when an `xstate.error.*` event is raised while this
|
|
351
|
+
* state node or one of its descendants is active.
|
|
352
|
+
*/
|
|
353
|
+
onError?: Next_TransitionConfigOrTarget<TContext, ErrorEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
281
354
|
/**
|
|
282
355
|
* The mapping (or array) of delays (in milliseconds) to their potential
|
|
283
356
|
* transition(s). The delayed transitions are taken after the specified delay
|
|
284
357
|
* in an interpreter.
|
|
285
358
|
*/
|
|
286
359
|
after?: {
|
|
287
|
-
[K in NoInfer<TDelays> | number]?:
|
|
360
|
+
[K in NoInfer<TDelays> | number]?: {
|
|
288
361
|
target: string;
|
|
289
362
|
} | TransitionConfigFunction<TContext, TEvent, TEvent, TODO, // TEmitted
|
|
290
|
-
TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
363
|
+
TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TInput>;
|
|
291
364
|
};
|
|
292
365
|
/**
|
|
293
366
|
* The duration (in ms) after which this state will transition via `onTimeout`
|
|
@@ -302,9 +375,10 @@ interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
302
375
|
context: TContext;
|
|
303
376
|
event: TEvent;
|
|
304
377
|
stateNode: AnyStateNode;
|
|
378
|
+
input: TInput;
|
|
305
379
|
}) => number);
|
|
306
380
|
/** Transition taken when `timeout` expires. Required when `timeout` is set. */
|
|
307
|
-
onTimeout?: Next_TransitionConfigOrTarget<TContext, TEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
381
|
+
onTimeout?: Next_TransitionConfigOrTarget<TContext, TEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TInput>;
|
|
308
382
|
/**
|
|
309
383
|
* An eventless transition that is always taken when this state node is
|
|
310
384
|
* active.
|
|
@@ -323,7 +397,7 @@ interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
323
397
|
* The output data will be evaluated with the current `context` and placed on
|
|
324
398
|
* the `.data` property of the event.
|
|
325
399
|
*/
|
|
326
|
-
output?:
|
|
400
|
+
output?: OutputConfig<TContext, TEvent, TOutput, TInput>;
|
|
327
401
|
/**
|
|
328
402
|
* The unique ID of the state node, which can be referenced as a transition
|
|
329
403
|
* target via the `#id` syntax.
|
|
@@ -344,8 +418,9 @@ interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent ex
|
|
|
344
418
|
/** A default target for a history state */
|
|
345
419
|
target?: string | undefined;
|
|
346
420
|
}
|
|
347
|
-
export type Next_TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
421
|
+
export type Next_TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, TInput = undefined> = undefined | {
|
|
348
422
|
target?: string | string[];
|
|
423
|
+
context?: TransitionContextPatch<TContext> | TransitionContextMapper<TContext, TExpressionEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
349
424
|
description?: string;
|
|
350
425
|
reenter?: boolean;
|
|
351
426
|
meta?: TMeta;
|
|
@@ -354,7 +429,8 @@ export type Next_TransitionConfigOrTarget<TContext extends MachineContext, TExpr
|
|
|
354
429
|
event: any;
|
|
355
430
|
}) => Record<string, unknown>);
|
|
356
431
|
} | {
|
|
357
|
-
to?: TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
432
|
+
to?: TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TInput>;
|
|
433
|
+
context?: TransitionContextPatch<TContext> | TransitionContextMapper<TContext, TExpressionEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
358
434
|
description?: string;
|
|
359
435
|
reenter?: boolean;
|
|
360
436
|
meta?: TMeta;
|
|
@@ -362,7 +438,7 @@ export type Next_TransitionConfigOrTarget<TContext extends MachineContext, TExpr
|
|
|
362
438
|
context: any;
|
|
363
439
|
event: any;
|
|
364
440
|
}) => Record<string, unknown>);
|
|
365
|
-
} | TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
|
|
441
|
+
} | TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, TInput>;
|
|
366
442
|
export type WithDefault<T, Default> = IsNever<T> extends true ? Default : T;
|
|
367
443
|
export interface Implementations {
|
|
368
444
|
actions: Record<string, (...args: any[]) => void | {
|
|
@@ -371,7 +447,7 @@ export interface Implementations {
|
|
|
371
447
|
}>;
|
|
372
448
|
guards: Record<string, (...args: any[]) => boolean>;
|
|
373
449
|
delays: Record<string, number | ((...args: any[]) => number)>;
|
|
374
|
-
|
|
450
|
+
actorSources: Record<string, AnyActorLogic>;
|
|
375
451
|
}
|
|
376
452
|
export type DelayMapFromNames<TDelays extends string, _TDelayMap extends Implementations['delays']> = string extends TDelays ? Implementations['delays'] : {
|
|
377
453
|
[K in TDelays]: Implementations['delays'][string];
|
|
@@ -382,8 +458,6 @@ type DelayNamesFromConfig<TConfig> = TConfig extends {
|
|
|
382
458
|
type InvalidDelayReferences<TConfig, TDelays extends string> = (TConfig extends {
|
|
383
459
|
after: infer TAfter;
|
|
384
460
|
} ? 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
461
|
states: infer TStates;
|
|
388
462
|
} ? TStates extends Record<string, unknown> ? {
|
|
389
463
|
[K in keyof TStates]: InvalidDelayReferences<TStates[K], TDelays>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { StateNode } from "./StateNode.js";
|
|
2
|
-
import type { AnyActor, AnyEventObject, AnyMachineSnapshot, AnyStateMachine, AnyTransitionConfig, AnyTransitionConfigFunction,
|
|
2
|
+
import type { AnyActor, AnyEventObject, AnyMachineSnapshot, AnyStateMachine, AnyTransitionConfig, AnyTransitionConfigFunction, ErrorEvent, EventObject, MachineContext, Mapper, NonReducibleUnknown, Observer, OutputArg, SingleOrArray, StateValue, TransitionConfigTarget } from "./types.js";
|
|
3
3
|
export declare function matchesState(parentStateId: StateValue, childStateId: StateValue): boolean;
|
|
4
4
|
export declare function checkStateIn(snapshot: AnyMachineSnapshot, stateValue: StateValue): boolean;
|
|
5
5
|
export declare function toStatePath(stateId: string | string[]): string[];
|
|
@@ -8,8 +8,9 @@ export declare function mapValues<P, O extends Record<string, unknown>>(collecti
|
|
|
8
8
|
[key in keyof O]: P;
|
|
9
9
|
};
|
|
10
10
|
export declare function toArray<T>(value: readonly T[] | T | undefined): readonly T[];
|
|
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;
|
|
12
|
-
export declare function
|
|
11
|
+
export declare function resolveOutput<TContext extends MachineContext, TExpressionEvent extends EventObject>(mapper: Mapper<TContext, TExpressionEvent, unknown, EventObject> | NonReducibleUnknown, context: TContext, event: TExpressionEvent, self: AnyActor, input?: Record<string, unknown>): unknown;
|
|
12
|
+
export declare function getEventOutput<TEvent extends EventObject>(event: TEvent): OutputArg<TEvent>['output'];
|
|
13
|
+
export declare function isErrorEvent(event: AnyEventObject): event is ErrorEvent;
|
|
13
14
|
export declare function toTransitionConfigArray(configLike: SingleOrArray<AnyTransitionConfig | TransitionConfigTarget | AnyTransitionConfigFunction>): Array<AnyTransitionConfig>;
|
|
14
15
|
export declare function normalizeTarget<TContext extends MachineContext, TEvent extends EventObject>(target: SingleOrArray<string | StateNode<TContext, TEvent>> | undefined): ReadonlyArray<string | StateNode<TContext, TEvent>> | undefined;
|
|
15
16
|
export declare function toObserver<T>(nextHandler?: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
|