xstate 6.0.0-alpha.7 → 6.0.0-alpha.9
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/dist/{StateMachine-2b259bff.development.esm.js → StateMachine-0aa98f54.development.esm.js} +10 -10
- package/dist/{StateMachine-6673bf76.cjs.js → StateMachine-aef700df.cjs.js} +9 -9
- package/dist/{StateMachine-1ff90553.esm.js → StateMachine-d4931336.esm.js} +9 -9
- package/dist/{StateMachine-68fe6077.development.cjs.js → StateMachine-da872dde.development.cjs.js} +10 -10
- package/dist/declarations/src/StateMachine.d.ts +13 -6
- package/dist/declarations/src/createMachine.d.ts +4 -4
- package/dist/declarations/src/createMachineFromConfig.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/serialize.d.ts +2 -1
- package/dist/declarations/src/setup.d.ts +56 -28
- package/dist/declarations/src/types.d.ts +54 -42
- package/dist/declarations/src/types.v6.d.ts +35 -26
- package/dist/declarations/src/utils.d.ts +2 -1
- package/dist/{index-b063a967.development.cjs.js → index-219cb621.development.cjs.js} +35 -13
- package/dist/{index-9594f050.development.esm.js → index-2f2fbd9b.development.esm.js} +35 -13
- package/dist/{index-87499be0.cjs.js → index-559ceab3.cjs.js} +35 -13
- package/dist/{index-aaf74d09.esm.js → index-8828376f.esm.js} +35 -13
- 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.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 +19 -17
- package/dist/xstate.development.cjs.js +19 -17
- package/dist/xstate.development.esm.js +21 -19
- package/dist/xstate.esm.js +21 -19
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./schema.types.js";
|
|
2
2
|
import { StateMachine } from "./StateMachine.js";
|
|
3
3
|
import { type Actor, type RequiredActorOptionsKeys } from "./createActor.js";
|
|
4
|
-
import { AnyActorRef, AnyActorLogic, ActorRefFromLogic, AnyStateNode, EventObject, AnyEventObject, EventDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, ToChildren, MetaObject, Cast, Compute, EnqueueObject, SystemRegistry, RegistryKeyForLogic, ActorOptions, Observer, Subscription } from "./types.js";
|
|
4
|
+
import { AnyActorRef, AnyActorLogic, ActorRefFromLogic, AnyStateNode, EventObject, AnyEventObject, EventDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, ToChildren, MetaObject, Cast, Compute, EnqueueObject, SystemRegistry, RegistryKeyForLogic, ActorOptions, Observer, Subscription, OutputArg } from "./types.js";
|
|
5
|
+
import { AnyActorSystem } from "./system.js";
|
|
5
6
|
import { InspectionEvent } from "./inspection.js";
|
|
6
7
|
import { DelayMapFromNames, InferChildren, Implementations, InferOutput, InferEvents, Next_MachineConfig, Next_StateNodeConfig, WithDefault } from "./types.v6.js";
|
|
7
|
-
type SetupConfig<TSchemas extends SetupSchemas, TStates extends Record<string, SetupStateSchema>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
8
|
+
export type SetupConfig<TSchemas extends SetupSchemas, TStates extends Record<string, SetupStateSchema>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
8
9
|
schemas?: TSchemas;
|
|
9
10
|
states?: TStates;
|
|
10
11
|
actions?: TActionMap;
|
|
11
|
-
|
|
12
|
+
actorSources?: TActorMap;
|
|
12
13
|
guards?: TGuardMap;
|
|
13
14
|
delays?: TDelayMap;
|
|
14
15
|
};
|
|
16
|
+
export type AnySetupConfig = SetupConfig<SetupSchemas, Record<string, SetupStateSchema>, Implementations['actions'], Implementations['actorSources'], Implementations['guards'], Implementations['delays']>;
|
|
15
17
|
type SystemConfig<TSystemRegistry extends SystemRegistry> = {
|
|
16
18
|
registry?: TSystemRegistry;
|
|
17
19
|
};
|
|
18
20
|
type SystemActorMap<TSystemRegistry extends SystemRegistry> = {
|
|
19
21
|
[K in keyof TSystemRegistry & string]: ActorRefFromLogic<TSystemRegistry[K]>;
|
|
20
22
|
};
|
|
23
|
+
type SystemRuntime<TSystemRegistry extends SystemRegistry> = Omit<AnyActorSystem, 'get' | 'getAll'> & {
|
|
24
|
+
get<K extends keyof SystemActorMap<TSystemRegistry> & string>(key: K): SystemActorMap<TSystemRegistry>[K] | undefined;
|
|
25
|
+
getAll(): Partial<SystemActorMap<TSystemRegistry>>;
|
|
26
|
+
};
|
|
21
27
|
type LogicMatchesRegistryKey<TLogic, TSystemLogic> = TLogic extends AnyActorLogic ? TSystemLogic extends AnyActorLogic ? [TLogic] extends [TSystemLogic] ? true : [TSystemLogic] extends [TLogic] ? true : ActorRefFromLogic<TLogic> extends ActorRefFromLogic<TSystemLogic> ? true : false : false : false;
|
|
22
|
-
type RegistryKeyMatchesSrc<TKey extends string, TSrc, TSystemRegistry extends SystemRegistry, TActorMap extends Implementations['
|
|
23
|
-
type ValidateSystemInvoke<TInvoke, TSystemRegistry extends SystemRegistry, TActorMap extends Implementations['
|
|
28
|
+
type RegistryKeyMatchesSrc<TKey extends string, TSrc, TSystemRegistry extends SystemRegistry, TActorMap extends Implementations['actorSources']> = TKey extends keyof TSystemRegistry & string ? TSrc extends keyof TActorMap & string ? LogicMatchesRegistryKey<TActorMap[TSrc], TSystemRegistry[TKey]> : TSrc extends AnyActorLogic ? LogicMatchesRegistryKey<TSrc, TSystemRegistry[TKey]> : true : false;
|
|
29
|
+
type ValidateSystemInvoke<TInvoke, TSystemRegistry extends SystemRegistry, TActorMap extends Implementations['actorSources']> = TInvoke extends readonly unknown[] ? {
|
|
24
30
|
[K in keyof TInvoke]: TInvoke[K] & ValidateSystemInvoke<TInvoke[K], TSystemRegistry, TActorMap>;
|
|
25
31
|
} : TInvoke extends {
|
|
26
32
|
registryKey: infer TKey;
|
|
@@ -33,7 +39,7 @@ type ValidateSystemInvoke<TInvoke, TSystemRegistry extends SystemRegistry, TActo
|
|
|
33
39
|
} : {
|
|
34
40
|
registryKey: never;
|
|
35
41
|
} : unknown;
|
|
36
|
-
type ValidateRegistryKeys<TConfig, TSystemRegistry extends SystemRegistry, TActorMap extends Implementations['
|
|
42
|
+
type ValidateRegistryKeys<TConfig, TSystemRegistry extends SystemRegistry, TActorMap extends Implementations['actorSources']> = string extends keyof TSystemRegistry ? unknown : (TConfig extends {
|
|
37
43
|
invoke: infer TInvoke;
|
|
38
44
|
} ? {
|
|
39
45
|
invoke: TInvoke & ValidateSystemInvoke<TInvoke, TSystemRegistry, TActorMap>;
|
|
@@ -44,11 +50,11 @@ type ValidateRegistryKeys<TConfig, TSystemRegistry extends SystemRegistry, TActo
|
|
|
44
50
|
[K in keyof TStates]: TStates[K] & ValidateRegistryKeys<TStates[K], TSystemRegistry, TActorMap>;
|
|
45
51
|
};
|
|
46
52
|
} : unknown);
|
|
47
|
-
type SetupStateSchemas = {
|
|
53
|
+
export type SetupStateSchemas = {
|
|
48
54
|
context?: StandardSchemaV1;
|
|
49
55
|
input?: StandardSchemaV1;
|
|
50
56
|
};
|
|
51
|
-
type SetupSchemas = {
|
|
57
|
+
export type SetupSchemas = {
|
|
52
58
|
context?: StandardSchemaV1;
|
|
53
59
|
events?: Record<string, StandardSchemaV1>;
|
|
54
60
|
emitted?: Record<string, StandardSchemaV1>;
|
|
@@ -59,7 +65,7 @@ type SetupSchemas = {
|
|
|
59
65
|
children?: Record<string, StandardSchemaV1>;
|
|
60
66
|
};
|
|
61
67
|
/** State schema with optional schemas.input and nested states */
|
|
62
|
-
interface SetupStateSchema {
|
|
68
|
+
export interface SetupStateSchema {
|
|
63
69
|
schemas?: SetupStateSchemas;
|
|
64
70
|
states?: Record<string, SetupStateSchema>;
|
|
65
71
|
}
|
|
@@ -192,9 +198,9 @@ type MergeStateSchema<TConfig extends StateSchema, TSetup extends StateSchema> =
|
|
|
192
198
|
} : undefined : undefined;
|
|
193
199
|
};
|
|
194
200
|
/** Machine config with typed state input */
|
|
195
|
-
type SetupMachineConfig<TStateSchemas extends Record<string, SetupStateSchema>, TSchemas extends SetupSchemas, 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, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
201
|
+
type SetupMachineConfig<TStateSchemas extends Record<string, SetupStateSchema>, TSchemas extends SetupSchemas, 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, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry, TContextRequired extends boolean, TRootDelays extends string = TDelays, TRootActionMap extends Implementations['actions'] = TActionMap, TRootActorMap extends Implementations['actorSources'] = TActorMap, TRootGuardMap extends Implementations['guards'] = TGuardMap> = Omit<Next_MachineConfig<SetupOrConfigSchema<TSchemas, 'context', TContextSchema>, SetupOrConfigSchemaMap<TSchemas, 'events', TEventSchemaMap>, SetupOrConfigSchemaMap<TSchemas, 'emitted', TEmittedSchemaMap>, SetupOrConfigSchema<TSchemas, 'input', TInputSchema>, SetupOrConfigSchema<TSchemas, 'output', TOutputSchema>, SetupOrConfigSchema<TSchemas, 'meta', TMetaSchema>, SetupOrConfigSchema<TSchemas, 'tags', TTagSchema>, SetupOrConfigSchemaMap<TSchemas, 'children', TChildrenSchemaMap>, TContext, TEvent, TChildren, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, TContextRequired, TSystemRegistry>, 'states' | 'initial' | 'on' | 'always' | 'actions' | 'actorSources' | 'guards' | 'delays'> & {
|
|
196
202
|
actions?: TRootActionMap;
|
|
197
|
-
|
|
203
|
+
actorSources?: TRootActorMap;
|
|
198
204
|
guards?: TRootGuardMap;
|
|
199
205
|
delays?: {
|
|
200
206
|
[K in TRootDelays | number]?: number | (({ context, event, stateNode }: {
|
|
@@ -209,11 +215,11 @@ type SetupMachineConfig<TStateSchemas extends Record<string, SetupStateSchema>,
|
|
|
209
215
|
states?: StatesWithInput<TStateSchemas, TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TChildren, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
210
216
|
};
|
|
211
217
|
/** States config type that provides typed input for known states */
|
|
212
|
-
type StatesWithInput<TRootStateSchemas extends Record<string, SetupStateSchema>, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
218
|
+
type StatesWithInput<TRootStateSchemas extends Record<string, SetupStateSchema>, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = {
|
|
213
219
|
[K in keyof TStateSchemas & string]?: StateNodeConfigWithNestedInput<TRootStateSchemas, TStateSchemas[K], TContext, TContextShape, TEvent, TChildren, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
214
220
|
};
|
|
215
221
|
/** State node config that recursively applies typed input for nested states */
|
|
216
|
-
type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
222
|
+
type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = WithNestedStates<Omit<Next_StateNodeConfig<StateContext<TStateSchema, TContext>, TEvent, TDelays, TTag, any, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, StateInput<TStateSchema>, Record<string, unknown>, TSystemRegistry>, 'on' | 'always' | 'initial'> & {
|
|
217
223
|
initial?: TStateSchema['states'] extends Record<string, SetupStateSchema> ? SetupStateKey<TStateSchema['states']> | InitialTransitionWithInput<TStateSchema['states'], StateContext<TStateSchema, TContext>, TEvent> : string | {
|
|
218
224
|
target: string;
|
|
219
225
|
input?: Record<string, unknown>;
|
|
@@ -223,10 +229,10 @@ type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string,
|
|
|
223
229
|
}, TStateSchema['states'] extends Record<string, SetupStateSchema> ? StatesWithInput<TStateSchema['states'], TStateSchema['states'], TContext, StateContextShape<TStateSchema, TContextShape>, TEvent, TChildren, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry> : {
|
|
224
230
|
[K in string]?: Next_StateNodeConfig<TContext, TEvent, TDelays, TTag, any, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, undefined, Record<string, unknown>, TSystemRegistry>;
|
|
225
231
|
}>;
|
|
226
|
-
type StateTransitions<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
232
|
+
type StateTransitions<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = {
|
|
227
233
|
[K in EventDescriptor<TEvent>]?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, ExtractEvent<TEvent, K>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
228
234
|
};
|
|
229
|
-
type StateTransitionConfigOrTarget<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
235
|
+
type StateTransitionConfigOrTarget<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = undefined | StateTransitionObjectConfig<TStateSchemas, TContext, TContextShape, TExpressionEvent, TMeta> | StateTransitionFunction<TStateSchemas, TContext, TContextShape, TExpressionEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
|
|
230
236
|
type StateTransitionObjectConfig<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TMeta extends MetaObject> = (StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta> & {
|
|
231
237
|
description?: string;
|
|
232
238
|
}) | {
|
|
@@ -238,20 +244,21 @@ type StateTransitionObjectConfig<TStateSchemas extends Record<string, SetupState
|
|
|
238
244
|
input?: Record<string, unknown> | ((args: {
|
|
239
245
|
context: TContext;
|
|
240
246
|
event: TExpressionEvent;
|
|
241
|
-
}) => Record<string, unknown>);
|
|
247
|
+
} & OutputArg<TExpressionEvent>) => Record<string, unknown>);
|
|
242
248
|
};
|
|
243
|
-
type StateTransitionFunction<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
249
|
+
type StateTransitionFunction<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = (args: {
|
|
244
250
|
context: TContext;
|
|
245
251
|
event: TExpressionEvent;
|
|
246
252
|
self: AnyActorRef;
|
|
247
253
|
parent: AnyActorRef | undefined;
|
|
248
254
|
value: StateValue;
|
|
249
255
|
children: TChildren;
|
|
256
|
+
system: SystemRuntime<TSystemRegistry>;
|
|
250
257
|
actions: TActionMap;
|
|
251
|
-
|
|
258
|
+
actorSources: TActorMap;
|
|
252
259
|
guards: TGuardMap;
|
|
253
260
|
delays: TDelayMap;
|
|
254
|
-
}
|
|
261
|
+
} & OutputArg<TExpressionEvent>, enq: EnqueueObject<TEvent, TEmitted, TSystemRegistry>) => StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta> | void;
|
|
255
262
|
type StateTransitionResult<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TMeta extends MetaObject> = {
|
|
256
263
|
target?: never;
|
|
257
264
|
context?: ContextPatch<TContextShape, TContextShape, TContext>;
|
|
@@ -265,7 +272,7 @@ type StateTransitionResult<TStateSchemas extends Record<string, SetupStateSchema
|
|
|
265
272
|
input?: StateInput<TStateSchemas[K]> | ((args: {
|
|
266
273
|
context: TContext;
|
|
267
274
|
event: EventObject;
|
|
268
|
-
}) => StateInput<TStateSchemas[K]>);
|
|
275
|
+
} & OutputArg<EventObject>) => StateInput<TStateSchemas[K]>);
|
|
269
276
|
} & ([TContextShape] extends [
|
|
270
277
|
StateContextShape<TStateSchemas[K], TContextShape>
|
|
271
278
|
] ? {
|
|
@@ -294,11 +301,11 @@ type InitialTransitionWithInput<TStateSchemas extends Record<string, SetupStateS
|
|
|
294
301
|
};
|
|
295
302
|
}[keyof TStateSchemas & string];
|
|
296
303
|
/** Return type of setup() */
|
|
297
|
-
interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TSchemas extends SetupSchemas = {}, TSetupActionMap extends Implementations['actions'] = {}, TSetupActorMap extends Implementations['
|
|
304
|
+
export interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TSchemas extends SetupSchemas = {}, TSetupActionMap extends Implementations['actions'] = {}, TSetupActorMap extends Implementations['actorSources'] = {}, TSetupGuardMap extends Implementations['guards'] = {}, TSetupDelayMap extends Implementations['delays'] = {}, TSetupDelays extends string = Extract<keyof TSetupDelayMap, string>, TSystemRegistry extends SystemRegistry = SystemRegistry> {
|
|
298
305
|
/** Extends the setup configuration */
|
|
299
|
-
extend<const TExtendSchemas extends SetupSchemas = {}, const TExtendStates extends Record<string, SetupStateSchema> = {}, TExtendActionMap extends Implementations['actions'] = {}, TExtendActorMap extends Implementations['
|
|
306
|
+
extend<const TExtendSchemas extends SetupSchemas = {}, const TExtendStates extends Record<string, SetupStateSchema> = {}, TExtendActionMap extends Implementations['actions'] = {}, TExtendActorMap extends Implementations['actorSources'] = {}, TExtendGuardMap extends Implementations['guards'] = {}, TExtendDelayMap extends Implementations['delays'] = {}>(config: SetupConfig<TExtendSchemas, TExtendStates, TExtendActionMap, TExtendActorMap, TExtendGuardMap, TExtendDelayMap>): SetupReturn<MergeImplementationMaps<TStates, TExtendStates>, MergeImplementationMaps<TSchemas, TExtendSchemas>, MergeImplementationMaps<TSetupActionMap, TExtendActionMap>, MergeImplementationMaps<TSetupActorMap, TExtendActorMap>, MergeImplementationMaps<TSetupGuardMap, TExtendGuardMap>, MergeImplementationMaps<TSetupDelayMap, TExtendDelayMap>, TSetupDelays | Extract<keyof TExtendDelayMap, string>, TSystemRegistry>;
|
|
300
307
|
/** Creates a state machine with the setup configuration */
|
|
301
|
-
createMachine<TContextSchema extends StandardSchemaV1 = StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Implementations['actions'] = {}, TActorMap extends Implementations['
|
|
308
|
+
createMachine<TContextSchema extends StandardSchemaV1 = StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Implementations['actions'] = {}, TActorMap extends Implementations['actorSources'] = {}, TGuardMap extends Implementations['guards'] = {}, TDelayMap extends Implementations['delays'] = {}, TDelays extends string = Extract<keyof TDelayMap, string>, TTag extends SetupTags<TSchemas, TTagSchema> = SetupTags<TSchemas, TTagSchema>, TInput = unknown, TConfig extends SetupMachineConfig<TStates, TSchemas, TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap>, Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TSetupDelays | TDelays, TTag, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeImplementationMaps<TSetupActionMap, TActionMap>, MergeImplementationMaps<TSetupActorMap, TActorMap>, MergeImplementationMaps<TSetupGuardMap, TGuardMap>, MergeImplementationMaps<TSetupDelayMap, TDelayMap>, TSystemRegistry, SetupContextRequired<TSchemas, TContextSchema>, TDelays, TActionMap, TActorMap, TGuardMap> = SetupMachineConfig<TStates, TSchemas, TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap>, Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TSetupDelays | TDelays, TTag, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeImplementationMaps<TSetupActionMap, TActionMap>, MergeImplementationMaps<TSetupActorMap, TActorMap>, MergeImplementationMaps<TSetupGuardMap, TGuardMap>, MergeImplementationMaps<TSetupDelayMap, TDelayMap>, TSystemRegistry, SetupContextRequired<TSchemas, TContextSchema>, TDelays, TActionMap, TActorMap, TGuardMap>>(config: {
|
|
302
309
|
schemas?: {
|
|
303
310
|
events?: TEventSchemaMap;
|
|
304
311
|
context?: TContextSchema;
|
|
@@ -310,7 +317,7 @@ interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<
|
|
|
310
317
|
children?: TChildrenSchemaMap;
|
|
311
318
|
};
|
|
312
319
|
actions?: TActionMap;
|
|
313
|
-
|
|
320
|
+
actorSources?: TActorMap;
|
|
314
321
|
guards?: TGuardMap;
|
|
315
322
|
delays?: TDelayMap;
|
|
316
323
|
} & TConfig & ValidateSetupStateKeys<TConfig, TStates> & ValidateNestedSetupStateKeys<TConfig, TStates> & ValidateSetupDelayReferences<TConfig, TSetupDelays> & ValidateRegistryKeys<TConfig, TSystemRegistry, MergeImplementationMaps<TSetupActorMap, TActorMap>>): StateMachine<SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap> | ([RoutableStateId<Cast<TConfig, StateSchema>>] extends [never] ? never : {
|
|
@@ -324,6 +331,25 @@ interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<
|
|
|
324
331
|
/** State input schemas from setup config */
|
|
325
332
|
states: TStates;
|
|
326
333
|
}
|
|
334
|
+
type SetupConfigSchemas<TConfig> = TConfig extends {
|
|
335
|
+
schemas?: infer TSchemas;
|
|
336
|
+
} ? TSchemas extends SetupSchemas ? TSchemas : {} : {};
|
|
337
|
+
type SetupConfigStates<TConfig> = TConfig extends {
|
|
338
|
+
states?: infer TStates;
|
|
339
|
+
} ? TStates extends Record<string, SetupStateSchema> ? TStates : Record<string, SetupStateSchema> : Record<string, SetupStateSchema>;
|
|
340
|
+
type SetupConfigActions<TConfig> = TConfig extends {
|
|
341
|
+
actions?: infer TActions;
|
|
342
|
+
} ? TActions extends Implementations['actions'] ? TActions : {} : {};
|
|
343
|
+
type SetupConfigActorSources<TConfig> = TConfig extends {
|
|
344
|
+
actorSources?: infer TActorSources;
|
|
345
|
+
} ? TActorSources extends Implementations['actorSources'] ? TActorSources : {} : {};
|
|
346
|
+
type SetupConfigGuards<TConfig> = TConfig extends {
|
|
347
|
+
guards?: infer TGuards;
|
|
348
|
+
} ? TGuards extends Implementations['guards'] ? TGuards : {} : {};
|
|
349
|
+
type SetupConfigDelays<TConfig> = TConfig extends {
|
|
350
|
+
delays?: infer TDelays;
|
|
351
|
+
} ? TDelays extends Implementations['delays'] ? TDelays : {} : {};
|
|
352
|
+
export type SetupReturnFromConfig<TConfig extends AnySetupConfig> = SetupReturn<SetupConfigStates<TConfig>, SetupConfigSchemas<TConfig>, SetupConfigActions<TConfig>, SetupConfigActorSources<TConfig>, SetupConfigGuards<TConfig>, SetupConfigDelays<TConfig>>;
|
|
327
353
|
/**
|
|
328
354
|
* Sets up a state machine with state input schemas and other configuration.
|
|
329
355
|
*
|
|
@@ -360,17 +386,19 @@ interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<
|
|
|
360
386
|
* });
|
|
361
387
|
* ```
|
|
362
388
|
*/
|
|
363
|
-
export declare function setup
|
|
389
|
+
export declare function setup(): SetupReturn;
|
|
390
|
+
export declare function setup<const TSchemas extends SetupSchemas = {}, const TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TActionMap extends Implementations['actions'] = {}, TActorMap extends Implementations['actorSources'] = {}, TGuardMap extends Implementations['guards'] = {}, TDelayMap extends Implementations['delays'] = {}>(config: SetupConfig<TSchemas, TStates, TActionMap, TActorMap, TGuardMap, TDelayMap>): SetupReturn<TStates, TSchemas, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
391
|
+
export declare function setup<const TConfig extends AnySetupConfig>(config: TConfig): SetupReturnFromConfig<TConfig>;
|
|
364
392
|
type SystemBuilder<TSystemRegistry extends SystemRegistry> = {
|
|
365
393
|
createActor<TLogic extends AnyActorLogic>(logic: TLogic, options?: Omit<ActorOptions<TLogic>, 'registryKey'> & {
|
|
366
394
|
registryKey?: RegistryKeyForLogic<TLogic, TSystemRegistry>;
|
|
367
395
|
} & {
|
|
368
396
|
[K in RequiredActorOptionsKeys<TLogic>]: unknown;
|
|
369
397
|
}): Actor<TLogic>;
|
|
370
|
-
get
|
|
371
|
-
getAll
|
|
398
|
+
get: SystemRuntime<TSystemRegistry>['get'];
|
|
399
|
+
getAll: SystemRuntime<TSystemRegistry>['getAll'];
|
|
372
400
|
inspect(observer: Observer<InspectionEvent> | ((inspectionEvent: InspectionEvent) => void)): Subscription;
|
|
373
|
-
setup<const TSchemas extends SetupSchemas = {}, const TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TActionMap extends Implementations['actions'] = {}, TActorMap extends Implementations['
|
|
401
|
+
setup<const TSchemas extends SetupSchemas = {}, const TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TActionMap extends Implementations['actions'] = {}, TActorMap extends Implementations['actorSources'] = {}, TGuardMap extends Implementations['guards'] = {}, TDelayMap extends Implementations['delays'] = {}>(config?: SetupConfig<TSchemas, TStates, TActionMap, TActorMap, TGuardMap, TDelayMap>): SetupReturn<TStates, TSchemas, TActionMap, TActorMap, TGuardMap, TDelayMap, Extract<keyof TDelayMap, string>, TSystemRegistry>;
|
|
374
402
|
};
|
|
375
403
|
export declare function createSystem<const TSystemRegistry extends SystemRegistry = {}>(_config?: SystemConfig<TSystemRegistry>): SystemBuilder<TSystemRegistry>;
|
|
376
404
|
export {};
|
|
@@ -79,18 +79,27 @@ export interface ParameterizedObject {
|
|
|
79
79
|
type: string;
|
|
80
80
|
params?: NonReducibleUnknown;
|
|
81
81
|
}
|
|
82
|
-
export
|
|
82
|
+
export type UnifiedArg<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> = {
|
|
83
83
|
context: TContext;
|
|
84
84
|
event: TExpressionEvent;
|
|
85
85
|
self: ActorSelf<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>, // TODO: this should be replaced with `TChildren`
|
|
86
86
|
StateValue, string, unknown, TODO, // TMeta
|
|
87
87
|
TODO>, TEvent, AnyEventObject>;
|
|
88
88
|
system: AnyActorSystem;
|
|
89
|
-
}
|
|
89
|
+
} & OutputArg<TExpressionEvent>;
|
|
90
90
|
export type MachineContext = Record<string, any>;
|
|
91
|
-
|
|
91
|
+
type DoneEventType = `xstate.done.actor.${string}` | `xstate.done.state.${string}`;
|
|
92
|
+
export type OutputArg<TEvent extends EventObject> = TEvent extends {
|
|
93
|
+
type: DoneEventType;
|
|
94
|
+
output: infer TOutput;
|
|
95
|
+
} ? {
|
|
96
|
+
output: TOutput;
|
|
97
|
+
} : {
|
|
98
|
+
output: undefined;
|
|
99
|
+
};
|
|
100
|
+
export type ActionArgs<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> = UnifiedArg<TContext, TExpressionEvent, TEvent> & {
|
|
92
101
|
children: Record<string, AnyActor>;
|
|
93
|
-
}
|
|
102
|
+
};
|
|
94
103
|
export type InputFrom<T> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TStateSchema, infer _TActionMap, infer _TActorMap, infer _TGuardMap, infer _TDelayMap> ? TInput : T extends ActorLogic<infer _TSnapshot, infer _TEvent, infer TInput, infer _TSystem, infer _TEmitted> ? TInput : never;
|
|
95
104
|
export type OutputFrom<T> = T extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? (TSnapshot & {
|
|
96
105
|
status: 'done';
|
|
@@ -101,10 +110,10 @@ export type NoRequiredParams<T extends ParameterizedObject> = T extends any ? un
|
|
|
101
110
|
export type ConditionalRequired<T, Condition extends boolean> = Condition extends true ? Required<T> : T;
|
|
102
111
|
export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent extends EventObject, T extends ParameterizedObject> = T extends any ? ConditionalRequired<{
|
|
103
112
|
type: T['type'];
|
|
104
|
-
params?: T['params'] | (({ context, event }: {
|
|
113
|
+
params?: T['params'] | (({ context, event, output }: {
|
|
105
114
|
context: TContext;
|
|
106
115
|
event: TExpressionEvent;
|
|
107
|
-
}) => T['params']);
|
|
116
|
+
} & OutputArg<TExpressionEvent>) => T['params']);
|
|
108
117
|
}, undefined extends T['params'] ? false : true> : never;
|
|
109
118
|
export type StateKey = string | AnyMachineSnapshot;
|
|
110
119
|
export interface StateValueMap {
|
|
@@ -121,7 +130,7 @@ export interface StateValueMap {
|
|
|
121
130
|
*/
|
|
122
131
|
export type StateValue = string | StateValueMap;
|
|
123
132
|
export type TransitionTarget = SingleOrArray<string>;
|
|
124
|
-
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
133
|
+
export interface TransitionConfig<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
125
134
|
actions?: never;
|
|
126
135
|
guard?: unknown;
|
|
127
136
|
reenter?: boolean;
|
|
@@ -131,7 +140,7 @@ export interface TransitionConfig<TContext extends MachineContext, TExpressionEv
|
|
|
131
140
|
meta?: TMeta;
|
|
132
141
|
description?: string;
|
|
133
142
|
}
|
|
134
|
-
export interface InitialTransitionConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
143
|
+
export interface InitialTransitionConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> extends TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> {
|
|
135
144
|
target: string;
|
|
136
145
|
}
|
|
137
146
|
export type AnyTransitionConfig = TransitionConfig<any, // TContext
|
|
@@ -143,11 +152,11 @@ any, // TActionMap
|
|
|
143
152
|
any, // TActorMap
|
|
144
153
|
any, // TGuardMap
|
|
145
154
|
any>;
|
|
146
|
-
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
155
|
+
export interface InvokeDefinition<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
|
|
147
156
|
id: string;
|
|
148
157
|
registryKey: string | undefined;
|
|
149
|
-
logic: string | AnyActorLogic | (({
|
|
150
|
-
|
|
158
|
+
logic: string | AnyActorLogic | (({ actorSources, context, event, self }: {
|
|
159
|
+
actorSources: TActorMap;
|
|
151
160
|
context: TContext;
|
|
152
161
|
event: TEvent;
|
|
153
162
|
self: AnyActorRef;
|
|
@@ -177,9 +186,9 @@ export interface InvokeDefinition<TContext extends MachineContext, TEvent extend
|
|
|
177
186
|
/** The transition to take when the invoke-level `timeout` expires. */
|
|
178
187
|
onTimeout?: string | SingleOrArray<TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>>;
|
|
179
188
|
}
|
|
180
|
-
export type AnyInvokeDefinition = InvokeDefinition<MachineContext, EventObject, EventObject, MetaObject, Implementations['actions'], Implementations['
|
|
189
|
+
export type AnyInvokeDefinition = InvokeDefinition<MachineContext, EventObject, EventObject, MetaObject, Implementations['actions'], Implementations['actorSources'], Implementations['guards'], Implementations['delays']>;
|
|
181
190
|
type Delay<TDelay extends string> = TDelay | number;
|
|
182
|
-
export type DelayedTransitions<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
191
|
+
export type DelayedTransitions<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
183
192
|
[K in Delay<keyof TDelayMap & string>]?: string | SingleOrArray<TransitionConfig<TContext, TEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>> | TransitionConfigFunction<TContext, TEvent, TEvent, TODO, any, any, any, any, any>;
|
|
184
193
|
};
|
|
185
194
|
export type StateTypes = 'atomic' | 'compound' | 'parallel' | 'final' | 'choice' | 'history' | ({} & string);
|
|
@@ -188,26 +197,28 @@ export type StateNodesConfig<TContext extends MachineContext, TEvent extends Eve
|
|
|
188
197
|
[K in string]: StateNode<TContext, TEvent>;
|
|
189
198
|
};
|
|
190
199
|
export type TransitionConfigTarget = string | undefined;
|
|
191
|
-
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
192
|
-
export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
193
|
-
|
|
200
|
+
export type TransitionConfigOrTarget<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = SingleOrArray<TransitionConfigTarget | TransitionConfig<TContext, TExpressionEvent, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> | TransitionConfigFunction<TContext, TExpressionEvent, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>>;
|
|
201
|
+
export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, _TCtx = [TContext] extends [never] ? any : TContext> = (args: TransitionFunctionArgs<_TCtx, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap>, enq: EnqueueObject<TEvent, TEmitted>) => {
|
|
202
|
+
target?: string | string[];
|
|
203
|
+
context?: Partial<_TCtx>;
|
|
204
|
+
reenter?: boolean;
|
|
205
|
+
meta?: TMeta;
|
|
206
|
+
} | void;
|
|
207
|
+
type TransitionFunctionArgs<TContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
208
|
+
context: TContext;
|
|
194
209
|
event: TCurrentEvent;
|
|
195
|
-
self: ActorSelf<MachineSnapshot<
|
|
210
|
+
self: ActorSelf<MachineSnapshot<TContext & MachineContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO>, TEvent>;
|
|
196
211
|
parent: UnknownActorRef | undefined;
|
|
197
212
|
value: StateValue;
|
|
198
213
|
children: Record<string, AnyActor>;
|
|
214
|
+
system: AnyActorSystem;
|
|
199
215
|
actions: TActionMap;
|
|
200
|
-
|
|
216
|
+
actorSources: TActorMap;
|
|
201
217
|
guards: TGuardMap;
|
|
202
218
|
delays: TDelayMap;
|
|
203
|
-
}
|
|
204
|
-
target?: string | string[];
|
|
205
|
-
context?: Partial<_TCtx>;
|
|
206
|
-
reenter?: boolean;
|
|
207
|
-
meta?: TMeta;
|
|
208
|
-
} | void;
|
|
219
|
+
} & OutputArg<TCurrentEvent>;
|
|
209
220
|
export type AnyTransitionConfigFunction = TransitionConfigFunction<any, any, any, any, any, any, any, any, any, any>;
|
|
210
|
-
export type TransitionsConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
221
|
+
export type TransitionsConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
211
222
|
[K in EventDescriptor<TEvent>]?: TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
212
223
|
};
|
|
213
224
|
type PartialEventDescriptor<TEventType extends string> = TEventType extends `${infer TLeading}.${infer TTail}` ? `${TLeading}.*` | `${TLeading}.${PartialEventDescriptor<TTail>}` : never;
|
|
@@ -225,8 +236,8 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
225
236
|
} ? Compute<{
|
|
226
237
|
registryKey?: string;
|
|
227
238
|
/** The source of the machine to be invoked, or the machine itself. */
|
|
228
|
-
src: TSrc | (({
|
|
229
|
-
|
|
239
|
+
src: TSrc | (({ actorSources, context, event, self }: {
|
|
240
|
+
actorSources: ActorImplementationsBySrc<TActor>;
|
|
230
241
|
context: TContext;
|
|
231
242
|
event: TEvent;
|
|
232
243
|
self: AnyActorRef;
|
|
@@ -258,8 +269,8 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
258
269
|
}> | {
|
|
259
270
|
id?: never;
|
|
260
271
|
registryKey?: string;
|
|
261
|
-
src: string | AnyActorLogic | (({
|
|
262
|
-
|
|
272
|
+
src: string | AnyActorLogic | (({ actorSources, context, event, self }: {
|
|
273
|
+
actorSources: ActorImplementationsBySrc<TActor>;
|
|
263
274
|
context: TContext;
|
|
264
275
|
event: TEvent;
|
|
265
276
|
self: AnyActorRef;
|
|
@@ -282,8 +293,8 @@ export type InvokeConfig<TContext extends MachineContext, TEvent extends EventOb
|
|
|
282
293
|
id?: string;
|
|
283
294
|
registryKey?: string;
|
|
284
295
|
/** The source of the machine to be invoked, or the machine itself. */
|
|
285
|
-
src: string | AnyActorLogic | (({
|
|
286
|
-
|
|
296
|
+
src: string | AnyActorLogic | (({ actorSources, context, event, self }: {
|
|
297
|
+
actorSources: ActorImplementationsBySrc<TActor>;
|
|
287
298
|
context: TContext;
|
|
288
299
|
event: TEvent;
|
|
289
300
|
self: AnyActorRef;
|
|
@@ -326,10 +337,10 @@ any, // TGuardMap
|
|
|
326
337
|
any>;
|
|
327
338
|
export type AnyStateConfig = StateConfig<any, AnyEventObject>;
|
|
328
339
|
export type DelayConfig<TContext extends MachineContext, TExpressionEvent extends EventObject> = number | DelayExpr<TContext, TExpressionEvent>;
|
|
329
|
-
export type InitialContext<TContext extends MachineContext, TActorMap extends Implementations['
|
|
330
|
-
export type ContextFactory<TContext extends MachineContext, TActorMap extends Implementations['
|
|
340
|
+
export type InitialContext<TContext extends MachineContext, TActorMap extends Implementations['actorSources'], TInput, TEvent extends EventObject> = TContext | ContextFactory<TContext, TActorMap, TInput, TEvent>;
|
|
341
|
+
export type ContextFactory<TContext extends MachineContext, TActorMap extends Implementations['actorSources'], TInput, TEvent extends EventObject = EventObject> = ({ spawn, actorSources, input, self }: {
|
|
331
342
|
spawn: Spawner;
|
|
332
|
-
|
|
343
|
+
actorSources: TActorMap;
|
|
333
344
|
input: TInput;
|
|
334
345
|
self: ActorSelf<MachineSnapshot<[
|
|
335
346
|
TContext
|
|
@@ -353,7 +364,7 @@ export interface SetupTypes<TContext extends MachineContext, TEvent extends Even
|
|
|
353
364
|
meta?: TMeta;
|
|
354
365
|
}
|
|
355
366
|
export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject> extends SetupTypes<TContext, TEvent, never, TTag, TInput, TOutput, TEmitted, TMeta> {
|
|
356
|
-
|
|
367
|
+
actorSources?: TActor;
|
|
357
368
|
actions?: TAction;
|
|
358
369
|
guards?: TGuard;
|
|
359
370
|
delays?: TDelay;
|
|
@@ -396,7 +407,7 @@ export type Mapper<TContext extends MachineContext, TExpressionEvent extends Eve
|
|
|
396
407
|
self: ActorSelf<MachineSnapshot<_TCtx & MachineContext, TEvent, Record<string, AnyActorRef>, // TODO: this should be replaced with `TChildren`
|
|
397
408
|
StateValue, string, unknown, TODO, // TMeta
|
|
398
409
|
TODO>, TEvent, AnyEventObject>;
|
|
399
|
-
}) => TResult;
|
|
410
|
+
} & OutputArg<TExpressionEvent>) => TResult;
|
|
400
411
|
export interface TransitionDefinition<TContext extends MachineContext, TEvent extends EventObject> extends Omit<TransitionConfig<TContext, TEvent, TEvent, TODO, TODO, TODO, TODO, TODO, // TEmitted
|
|
401
412
|
TODO>, 'target' | 'to'> {
|
|
402
413
|
target: ReadonlyArray<AnyStateNode> | undefined;
|
|
@@ -407,6 +418,7 @@ TODO>, 'target' | 'to'> {
|
|
|
407
418
|
input?: Record<string, unknown> | ((args: {
|
|
408
419
|
context: any;
|
|
409
420
|
event: any;
|
|
421
|
+
output: any;
|
|
410
422
|
}) => Record<string, unknown>);
|
|
411
423
|
}
|
|
412
424
|
export type AnyTransitionDefinition = TransitionDefinition<any, any>;
|
|
@@ -731,7 +743,7 @@ export type UnknownActorRef = ActorRef<Snapshot<unknown>, EventObject>;
|
|
|
731
743
|
export type DevToolsAdapter = (service: AnyActor) => void;
|
|
732
744
|
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TConfig, infer TActionMap, infer TActorMap, infer TGuardMap, infer TDelayMap> ? {
|
|
733
745
|
actions: TActionMap;
|
|
734
|
-
|
|
746
|
+
actorSources: TActorMap;
|
|
735
747
|
guards: TGuardMap;
|
|
736
748
|
delays: TDelayMap;
|
|
737
749
|
} : never;
|
|
@@ -928,7 +940,7 @@ export type RoutableStateId<TSchema extends StateSchema> = (TSchema extends {
|
|
|
928
940
|
export interface StateMachineTypes {
|
|
929
941
|
context: MachineContext;
|
|
930
942
|
events: EventObject;
|
|
931
|
-
|
|
943
|
+
actorSources: ProvidedActor;
|
|
932
944
|
actions: ParameterizedObject;
|
|
933
945
|
guards: ParameterizedObject;
|
|
934
946
|
delays: string;
|
|
@@ -939,7 +951,7 @@ export interface StateMachineTypes {
|
|
|
939
951
|
export interface ResolvedStateMachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TEmitted extends EventObject = EventObject> {
|
|
940
952
|
context: TContext;
|
|
941
953
|
events: TEvent;
|
|
942
|
-
|
|
954
|
+
actorSources: TActor;
|
|
943
955
|
actions: TAction;
|
|
944
956
|
guards: TGuard;
|
|
945
957
|
delays: TDelay;
|
|
@@ -1077,14 +1089,14 @@ export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends Even
|
|
|
1077
1089
|
<TSnapshot extends Snapshot<unknown>, TOutput, TMappedEvent extends TEvent>(actor: AnyActor, mappers: SubscribeToMappers<TSnapshot, TOutput, TMappedEvent> | ((snapshot: TSnapshot) => TMappedEvent)): AnyActor;
|
|
1078
1090
|
};
|
|
1079
1091
|
};
|
|
1080
|
-
export type Action<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
1092
|
+
export type Action<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TParams = Record<string, unknown> | undefined, _TCtx = [TContext] extends [never] ? any : TContext> = (_: {
|
|
1081
1093
|
context: _TCtx;
|
|
1082
1094
|
event: TEvent;
|
|
1083
1095
|
parent: AnyActorRef | undefined;
|
|
1084
1096
|
self: ActorSelf<MachineSnapshot<_TCtx & MachineContext, TEvent, TODO, TODO, TODO, TODO, TODO, TODO>, TEvent>;
|
|
1085
1097
|
children: Record<string, AnyActor | undefined>;
|
|
1086
1098
|
actions: TActionMap;
|
|
1087
|
-
|
|
1099
|
+
actorSources: TActorMap;
|
|
1088
1100
|
guards: TGuardMap;
|
|
1089
1101
|
delays: TDelayMap;
|
|
1090
1102
|
system?: AnyActorSystem;
|
|
@@ -1093,7 +1105,7 @@ export type Action<TContext extends MachineContext, TEvent extends EventObject,
|
|
|
1093
1105
|
context?: Partial<_TCtx>;
|
|
1094
1106
|
children?: Record<string, AnyActor | undefined>;
|
|
1095
1107
|
} | void;
|
|
1096
|
-
export type AnyAction = Action<MachineContext, EventObject, EventObject, Implementations['actions'], Implementations['
|
|
1108
|
+
export type AnyAction = Action<MachineContext, EventObject, EventObject, Implementations['actions'], Implementations['actorSources'], Implementations['guards'], Implementations['delays']> | {
|
|
1097
1109
|
action: (...args: any[]) => any;
|
|
1098
1110
|
args: any[];
|
|
1099
1111
|
} | AnyEventObject;
|