xstate 6.0.0-alpha.2 → 6.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/{StateMachine-64813f46.cjs.js → StateMachine-445a8480.cjs.js} +15 -6
  2. package/dist/{StateMachine-2ea0a7fa.development.esm.js → StateMachine-4deb4090.development.esm.js} +15 -6
  3. package/dist/{StateMachine-2dcdb1f5.esm.js → StateMachine-f310bc72.esm.js} +15 -6
  4. package/dist/{StateMachine-8d22a79c.development.cjs.js → StateMachine-f83f01f9.development.cjs.js} +15 -6
  5. package/dist/declarations/src/StateMachine.d.ts +9 -8
  6. package/dist/declarations/src/actions.d.ts +1 -1
  7. package/dist/declarations/src/createActor.d.ts +3 -2
  8. package/dist/declarations/src/createMachine.d.ts +10 -7
  9. package/dist/declarations/src/graph/graph.d.ts +3 -3
  10. package/dist/declarations/src/graph/shortestPaths.d.ts +2 -2
  11. package/dist/declarations/src/graph/simplePaths.d.ts +2 -2
  12. package/dist/declarations/src/index.d.ts +2 -3
  13. package/dist/declarations/src/serialize.d.ts +13 -8
  14. package/dist/declarations/src/setup.d.ts +79 -33
  15. package/dist/declarations/src/transition.d.ts +8 -5
  16. package/dist/declarations/src/transitionActions.d.ts +4 -0
  17. package/dist/declarations/src/types.d.ts +69 -21
  18. package/dist/declarations/src/types.v6.d.ts +47 -27
  19. package/dist/{index-9cb3b3a0.cjs.js → index-918ab496.cjs.js} +245 -816
  20. package/dist/{index-93edd3bd.esm.js → index-9cce3480.esm.js} +244 -811
  21. package/dist/{index-e61170ba.development.esm.js → index-ccbe7c0b.development.esm.js} +244 -811
  22. package/dist/{index-f6ef20d1.development.cjs.js → index-ebaf6fd8.development.cjs.js} +245 -816
  23. package/dist/xstate-actors.cjs.js +1 -1
  24. package/dist/xstate-actors.development.cjs.js +1 -1
  25. package/dist/xstate-actors.development.esm.js +1 -1
  26. package/dist/xstate-actors.esm.js +1 -1
  27. package/dist/xstate-actors.umd.min.js +1 -1
  28. package/dist/xstate-actors.umd.min.js.map +1 -1
  29. package/dist/xstate-graph.cjs.js +2 -2
  30. package/dist/xstate-graph.development.cjs.js +2 -2
  31. package/dist/xstate-graph.development.esm.js +2 -2
  32. package/dist/xstate-graph.esm.js +2 -2
  33. package/dist/xstate-graph.umd.min.js +1 -1
  34. package/dist/xstate-graph.umd.min.js.map +1 -1
  35. package/dist/xstate.cjs.js +150 -53
  36. package/dist/xstate.cjs.mjs +1 -5
  37. package/dist/xstate.development.cjs.js +150 -53
  38. package/dist/xstate.development.cjs.mjs +1 -5
  39. package/dist/xstate.development.esm.js +151 -50
  40. package/dist/xstate.esm.js +151 -50
  41. package/dist/xstate.umd.min.js +1 -1
  42. package/dist/xstate.umd.min.js.map +1 -1
  43. package/package.json +1 -1
  44. package/dist/declarations/src/atom.d.ts +0 -81
@@ -1,7 +1,15 @@
1
1
  import { StandardSchemaV1 } from "./schema.types.js";
2
2
  import { StateMachine } from "./StateMachine.js";
3
- import { AnyActorRef, EventObject, AnyEventObject, EventDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, ToChildren, MetaObject, Cast } from "./types.js";
4
- import { DelayMapFromNames, Implementations, InferOutput, InferEvents, Next_MachineConfig, Next_StateNodeConfig, ValidateDelayReferences, WithDefault } from "./types.v6.js";
3
+ import { AnyActorRef, AnyStateNode, EventObject, AnyEventObject, EventDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, ToChildren, MetaObject, Cast, Compute } from "./types.js";
4
+ import { DelayMapFromNames, InferChildren, Implementations, InferOutput, InferEvents, Next_MachineConfig, Next_StateNodeConfig, WithDefault } from "./types.v6.js";
5
+ type SetupConfig<TSchemas extends SetupSchemas, TStates extends Record<string, SetupStateSchema>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
6
+ schemas?: TSchemas;
7
+ states?: TStates;
8
+ actions?: TActionMap;
9
+ actors?: TActorMap;
10
+ guards?: TGuardMap;
11
+ delays?: TDelayMap;
12
+ };
5
13
  type SetupStateSchemas = {
6
14
  context?: StandardSchemaV1;
7
15
  input?: StandardSchemaV1;
@@ -14,6 +22,7 @@ type SetupSchemas = {
14
22
  output?: StandardSchemaV1;
15
23
  meta?: StandardSchemaV1;
16
24
  tags?: StandardSchemaV1;
25
+ children?: Record<string, StandardSchemaV1>;
17
26
  };
18
27
  /** State schema with optional schemas.input and nested states */
19
28
  interface SetupStateSchema {
@@ -21,9 +30,9 @@ interface SetupStateSchema {
21
30
  states?: Record<string, SetupStateSchema>;
22
31
  }
23
32
  type SetupSchema<TSchemas, TKey extends keyof SetupSchemas> = TKey extends keyof TSchemas ? TSchemas[TKey] extends StandardSchemaV1 ? TSchemas[TKey] : never : never;
24
- type SetupSchemaMap<TSchemas, TKey extends 'events' | 'emitted'> = TKey extends keyof TSchemas ? TSchemas[TKey] extends Record<string, StandardSchemaV1> ? TSchemas[TKey] : never : never;
33
+ type SetupSchemaMap<TSchemas, TKey extends 'events' | 'emitted' | 'children'> = TKey extends keyof TSchemas ? TSchemas[TKey] extends Record<string, StandardSchemaV1> ? TSchemas[TKey] : never : never;
25
34
  type SetupOrConfigSchema<TSchemas, TKey extends Exclude<keyof SetupSchemas, 'events' | 'emitted'>, TConfigSchema extends StandardSchemaV1> = [SetupSchema<TSchemas, TKey>] extends [never] ? TConfigSchema : SetupSchema<TSchemas, TKey>;
26
- type SetupOrConfigSchemaMap<TSchemas, TKey extends 'events' | 'emitted', TConfigSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, TKey>] extends [never] ? TConfigSchemaMap : SetupSchemaMap<TSchemas, TKey>;
35
+ type SetupOrConfigSchemaMap<TSchemas, TKey extends 'events' | 'emitted' | 'children', TConfigSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, TKey>] extends [never] ? TConfigSchemaMap : SetupSchemaMap<TSchemas, TKey>;
27
36
  type SetupStateKeys<TStateSchemas extends Record<string, SetupStateSchema>> = keyof TStateSchemas & string;
28
37
  type SetupStateKey<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : SetupStateKeys<TStateSchemas>;
29
38
  type SetupStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : SetupStateKeys<TStateSchemas> | `.${string}` | `#${string}`;
@@ -64,6 +73,29 @@ type SetupEmitted<TSchemas, TEmittedSchemaMap extends Record<string, StandardSch
64
73
  type SetupMeta<TSchemas, TMetaSchema extends StandardSchemaV1> = [
65
74
  SetupSchema<TSchemas, 'meta'>
66
75
  ] extends [never] ? InferOutput<TMetaSchema, MetaObject> : InferOutput<SetupSchema<TSchemas, 'meta'>, MetaObject>;
76
+ type SetupChildren<TSchemas, TChildrenSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, 'children'>] extends [never] ? InferChildren<TChildrenSchemaMap> : InferChildren<SetupSchemaMap<TSchemas, 'children'>>;
77
+ type MergeChildren<TChildren extends Record<string, AnyActorRef | undefined>, TActor extends ProvidedActor> = [keyof TChildren] extends [never] ? Compute<ToChildren<TActor>> : Compute<TChildren>;
78
+ type MergeImplementationMaps<TBase extends Record<string, unknown>, TExtension extends Record<string, unknown>> = Compute<TBase & TExtension>;
79
+ type DelayNamesFromConfigOrString<TConfig> = TConfig extends {
80
+ delays: infer TDelays;
81
+ } ? Extract<keyof TDelays, string> : string;
82
+ type DelayNamesFromConfig<TConfig> = TConfig extends {
83
+ delays: infer TDelays;
84
+ } ? Extract<keyof TDelays, string> : never;
85
+ type InvalidDelayReferences<TConfig, TDelays extends string> = (TConfig extends {
86
+ after: infer TAfter;
87
+ } ? Exclude<Extract<keyof TAfter, string>, TDelays> : never) | (TConfig extends {
88
+ timeout: infer TTimeout;
89
+ } ? TTimeout extends string ? TTimeout extends TDelays ? never : TTimeout : never : never) | (TConfig extends {
90
+ states: infer TStates;
91
+ } ? TStates extends Record<string, unknown> ? {
92
+ [K in keyof TStates]: InvalidDelayReferences<TStates[K], TDelays>;
93
+ }[keyof TStates] : never : never);
94
+ type ValidateSetupDelayReferences<TConfig, TSetupDelays extends string> = string extends ([
95
+ TSetupDelays
96
+ ] extends [never] ? DelayNamesFromConfigOrString<TConfig> : TSetupDelays | DelayNamesFromConfig<TConfig>) ? unknown : InvalidDelayReferences<TConfig, [
97
+ TSetupDelays
98
+ ] extends [never] ? DelayNamesFromConfigOrString<TConfig> : TSetupDelays | DelayNamesFromConfig<TConfig>> extends never ? unknown : never;
67
99
  /** Extracts input type from a state schema */
68
100
  type StateInput<TStateSchema extends SetupStateSchema> = TStateSchema['schemas'] extends {
69
101
  input: infer TInputSchema;
@@ -122,29 +154,39 @@ type MergeStateSchema<TConfig extends StateSchema, TSetup extends StateSchema> =
122
154
  } : undefined : undefined;
123
155
  };
124
156
  /** Machine config with typed state input */
125
- 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, TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TContextRequired extends boolean> = 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>, TContext, TEvent, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, TContextRequired>, 'states' | 'initial'> & {
157
+ 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['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TContextRequired extends boolean, TRootDelays extends string = TDelays, TRootActionMap extends Implementations['actions'] = TActionMap, TRootActorMap extends Implementations['actors'] = 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>, 'states' | 'initial' | 'actions' | 'actors' | 'guards' | 'delays'> & {
158
+ actions?: TRootActionMap;
159
+ actors?: TRootActorMap;
160
+ guards?: TRootGuardMap;
161
+ delays?: {
162
+ [K in TRootDelays | number]?: number | (({ context, event, stateNode }: {
163
+ context: TContext;
164
+ event: TEvent;
165
+ stateNode: AnyStateNode;
166
+ }) => number);
167
+ };
126
168
  initial?: SetupStateKey<TStateSchemas> | InitialTransitionWithInput<TStateSchemas, TContext, TEvent> | undefined;
127
- states?: StatesWithInput<TStateSchemas, TStateSchemas, TContext, TEvent, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
169
+ states?: StatesWithInput<TStateSchemas, TStateSchemas, TContext, TEvent, TChildren, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
128
170
  };
129
171
  /** States config type that provides typed input for known states */
130
- type StatesWithInput<TRootStateSchemas extends Record<string, SetupStateSchema>, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
131
- [K in keyof TStateSchemas & string]?: StateNodeConfigWithNestedInput<TRootStateSchemas, TStateSchemas[K], TContext, TEvent, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
172
+ type StatesWithInput<TRootStateSchemas extends Record<string, SetupStateSchema>, TStateSchemas extends Record<string, SetupStateSchema>, 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['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
173
+ [K in keyof TStateSchemas & string]?: StateNodeConfigWithNestedInput<TRootStateSchemas, TStateSchemas[K], TContext, TEvent, TChildren, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
132
174
  };
133
175
  /** State node config that recursively applies typed input for nested states */
134
- type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = WithNestedStates<Omit<Next_StateNodeConfig<StateContext<TStateSchema, TContext>, TEvent, TDelays, TTag, any, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, StateInput<TStateSchema>>, 'on' | 'always' | 'initial'> & {
176
+ type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, 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['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = WithNestedStates<Omit<Next_StateNodeConfig<StateContext<TStateSchema, TContext>, TEvent, TDelays, TTag, any, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, StateInput<TStateSchema>>, 'on' | 'always' | 'initial'> & {
135
177
  initial?: TStateSchema['states'] extends Record<string, SetupStateSchema> ? SetupStateKey<TStateSchema['states']> | InitialTransitionWithInput<TStateSchema['states'], StateContext<TStateSchema, TContext>, TEvent> : string | {
136
178
  target: string;
137
179
  input?: Record<string, unknown>;
138
180
  } | undefined;
139
- on?: StateTransitions<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, TEvent, TEmitted, TMeta>;
140
- always?: StateTransitionConfigOrTarget<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, TEvent, TEvent, TEmitted, TMeta>;
141
- }, TStateSchema['states'] extends Record<string, SetupStateSchema> ? StatesWithInput<TStateSchema['states'], TStateSchema['states'], TContext, TEvent, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> : {
142
- [K in string]?: Next_StateNodeConfig<TContext, TEvent, TDelays, TTag, any, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, undefined>;
181
+ on?: StateTransitions<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
182
+ always?: StateTransitionConfigOrTarget<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, TEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
183
+ }, TStateSchema['states'] extends Record<string, SetupStateSchema> ? StatesWithInput<TStateSchema['states'], TStateSchema['states'], TContext, TEvent, TChildren, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> : {
184
+ [K in string]?: Next_StateNodeConfig<TContext, TEvent, TDelays, TTag, any, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, undefined>;
143
185
  }>;
144
- type StateTransitions<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject> = {
145
- [K in EventDescriptor<TEvent>]?: StateTransitionConfigOrTarget<TStateSchemas, TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TMeta>;
186
+ type StateTransitions<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
187
+ [K in EventDescriptor<TEvent>]?: StateTransitionConfigOrTarget<TStateSchemas, TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
146
188
  };
147
- type StateTransitionConfigOrTarget<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject> = SetupStateTarget<TStateSchemas> | undefined | {
189
+ type StateTransitionConfigOrTarget<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, 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['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = SetupStateTarget<TStateSchemas> | undefined | {
148
190
  target?: SetupStateTarget<TStateSchemas> | SetupStateTarget<TStateSchemas>[];
149
191
  description?: string;
150
192
  reenter?: boolean;
@@ -153,18 +195,18 @@ type StateTransitionConfigOrTarget<TStateSchemas extends Record<string, SetupSta
153
195
  context: TContext;
154
196
  event: TExpressionEvent;
155
197
  }) => Record<string, unknown>);
156
- } | StateTransitionFunction<TStateSchemas, TContext, TExpressionEvent, TEvent, TEmitted, TMeta>;
157
- type StateTransitionFunction<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TExpressionEvent extends EventObject, _TEvent extends EventObject, _TEmitted extends EventObject, TMeta extends MetaObject> = (args: {
198
+ } | StateTransitionFunction<TStateSchemas, TContext, TExpressionEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
199
+ type StateTransitionFunction<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, 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['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = (args: {
158
200
  context: TContext;
159
201
  event: TExpressionEvent;
160
202
  self: AnyActorRef;
161
203
  parent: AnyActorRef | undefined;
162
204
  value: StateValue;
163
- children: Record<string, AnyActorRef>;
164
- actions: Implementations['actions'];
165
- actors: Implementations['actors'];
166
- guards: Implementations['guards'];
167
- delays: Implementations['delays'];
205
+ children: TChildren;
206
+ actions: TActionMap;
207
+ actors: TActorMap;
208
+ guards: TGuardMap;
209
+ delays: TDelayMap;
168
210
  }, enq: any) => StateTransitionResult<TStateSchemas, TContext, TMeta> | void;
169
211
  type StateTransitionResult<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TMeta extends MetaObject> = {
170
212
  target?: never;
@@ -194,9 +236,11 @@ type InitialTransitionWithInput<TStateSchemas extends Record<string, SetupStateS
194
236
  };
195
237
  }[keyof TStateSchemas & string];
196
238
  /** Return type of setup() */
197
- interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TSchemas extends SetupSchemas = {}> {
239
+ interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TSchemas extends SetupSchemas = {}, TSetupActionMap extends Implementations['actions'] = {}, TSetupActorMap extends Implementations['actors'] = {}, TSetupGuardMap extends Implementations['guards'] = {}, TSetupDelayMap extends Implementations['delays'] = {}, TSetupDelays extends string = Extract<keyof TSetupDelayMap, string>> {
240
+ /** Extends the setup configuration */
241
+ extend<const TExtendSchemas extends SetupSchemas = {}, const TExtendStates extends Record<string, SetupStateSchema> = {}, TExtendActionMap extends Implementations['actions'] = {}, TExtendActorMap extends Implementations['actors'] = {}, 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>>;
198
242
  /** Creates a state machine with the setup configuration */
199
- createMachine<TContextSchema extends StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, _TEvent extends EventObject, TActor extends ProvidedActor, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TDelays extends string, TTag extends SetupTags<TSchemas, TTagSchema>, TInput, TConfig extends SetupMachineConfig<TStates, TSchemas, TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap>, TDelays, TTag, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, TActionMap, TActorMap, TGuardMap, TDelayMap, SetupContextRequired<TSchemas, TContextSchema>>>(config: TConfig & ValidateSetupStateKeys<TConfig, TStates> & ValidateNestedSetupStateKeys<TConfig, TStates> & ValidateDelayReferences<TConfig> & {
243
+ 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['actors'] = {}, 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>, 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>, SetupContextRequired<TSchemas, TContextSchema>, TDelays, TActionMap, TActorMap, TGuardMap>>(config: {
200
244
  schemas?: {
201
245
  events?: TEventSchemaMap;
202
246
  context?: TContextSchema;
@@ -205,15 +249,20 @@ interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<
205
249
  output?: TOutputSchema;
206
250
  meta?: TMetaSchema;
207
251
  tags?: TTagSchema;
252
+ children?: TChildrenSchemaMap;
208
253
  };
209
- }): StateMachine<SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap> | ([RoutableStateId<Cast<TConfig, StateSchema>>] extends [never] ? never : {
254
+ actions?: TActionMap;
255
+ actors?: TActorMap;
256
+ guards?: TGuardMap;
257
+ delays?: TDelayMap;
258
+ } & TConfig & ValidateSetupStateKeys<TConfig, TStates> & ValidateNestedSetupStateKeys<TConfig, TStates> & ValidateSetupDelayReferences<TConfig, TSetupDelays>): StateMachine<SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap> | ([RoutableStateId<Cast<TConfig, StateSchema>>] extends [never] ? never : {
210
259
  type: 'xstate.route';
211
260
  to: RoutableStateId<Cast<TConfig, StateSchema>>;
212
- }), Cast<ToChildren<TActor>, Record<string, AnyActorRef | undefined>>, StateValue, TTag & string, [
261
+ }), Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValue, TTag & string, [
213
262
  SetupSchema<TSchemas, 'input'>
214
- ] extends [never] ? TInput : SetupInput<TSchemas, TInputSchema>, SetupOutput<TSchemas, TOutputSchema>, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeStateSchema<Cast<TConfig, StateSchema>, SetupStatesToStateSchema<TStates>>, TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>>;
263
+ ] extends [never] ? TInput : SetupInput<TSchemas, TInputSchema>, SetupOutput<TSchemas, TOutputSchema>, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeStateSchema<Cast<TConfig, StateSchema>, SetupStatesToStateSchema<TStates>>, MergeImplementationMaps<TSetupActionMap, TActionMap>, MergeImplementationMaps<TSetupActorMap, TActorMap>, MergeImplementationMaps<TSetupGuardMap, TGuardMap>, DelayMapFromNames<TSetupDelays | TDelays, MergeImplementationMaps<TSetupDelayMap, TDelayMap>>>;
215
264
  /** Creates a state node config with the setup configuration */
216
- createStateConfig<const TConfig extends StateNodeConfigWithNestedInput<TStates, SetupStateSchema, SetupContext<TSchemas, StandardSchemaV1>, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>, string, SetupTags<TSchemas, StandardSchemaV1>, SetupEmitted<TSchemas, Record<string, StandardSchemaV1>>, SetupMeta<TSchemas, StandardSchemaV1>, Implementations['actions'], Implementations['actors'], Implementations['guards'], Implementations['delays']>>(config: TConfig): TConfig;
265
+ createStateConfig<const TConfig extends StateNodeConfigWithNestedInput<TStates, SetupStateSchema, SetupContext<TSchemas, StandardSchemaV1>, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>, Cast<SetupChildren<TSchemas, Record<string, StandardSchemaV1>>, Record<string, AnyActorRef | undefined>>, string, SetupTags<TSchemas, StandardSchemaV1>, SetupEmitted<TSchemas, Record<string, StandardSchemaV1>>, SetupMeta<TSchemas, StandardSchemaV1>, TSetupActionMap, TSetupActorMap, TSetupGuardMap, TSetupDelayMap>>(config: TConfig): TConfig;
217
266
  /** State input schemas from setup config */
218
267
  states: TStates;
219
268
  }
@@ -253,8 +302,5 @@ interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<
253
302
  * });
254
303
  * ```
255
304
  */
256
- export declare function setup<const TSchemas extends SetupSchemas = {}, const TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>>(config?: {
257
- schemas?: TSchemas;
258
- states?: TStates;
259
- }): SetupReturn<TStates, TSchemas>;
305
+ export declare function setup<const TSchemas extends SetupSchemas = {}, const TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TActionMap extends Implementations['actions'] = {}, TActorMap extends Implementations['actors'] = {}, TGuardMap extends Implementations['guards'] = {}, TDelayMap extends Implementations['delays'] = {}>(config?: SetupConfig<TSchemas, TStates, TActionMap, TActorMap, TGuardMap, TDelayMap>): SetupReturn<TStates, TSchemas, TActionMap, TActorMap, TGuardMap, TDelayMap>;
260
306
  export {};
@@ -1,11 +1,14 @@
1
- import { AnyActorLogic, AnyStateMachine, EventFromLogic, InputFrom, SnapshotFrom, ExecutableActionObject, AnyTransitionDefinition, AnyMachineSnapshot } from "./types.js";
1
+ import { AnyActorLogic, AnyStateMachine, EventFromLogic, InputFrom, SnapshotFrom, ExecutableActionObjectFromLogic, AnyTransitionDefinition, AnyMachineSnapshot } from "./types.js";
2
2
  /**
3
3
  * Given actor `logic`, a `snapshot`, and an `event`, returns a tuple of the
4
4
  * `nextSnapshot` and `actions` to execute.
5
5
  *
6
6
  * This is a pure function that does not execute `actions`.
7
7
  */
8
- export declare function transition<T extends AnyActorLogic>(logic: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): [nextSnapshot: SnapshotFrom<T>, actions: ExecutableActionObject[]];
8
+ export declare function transition<T extends AnyActorLogic>(logic: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): [
9
+ nextSnapshot: SnapshotFrom<T>,
10
+ actions: ExecutableActionObjectFromLogic<T>[]
11
+ ];
9
12
  /**
10
13
  * Given actor `logic` and optional `input`, returns a tuple of the
11
14
  * `nextSnapshot` and `actions` to execute from the initial transition (no
@@ -13,14 +16,14 @@ export declare function transition<T extends AnyActorLogic>(logic: T, snapshot:
13
16
  *
14
17
  * This is a pure function that does not execute `actions`.
15
18
  */
16
- export declare function initialTransition<T extends AnyActorLogic>(logic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): [SnapshotFrom<T>, ExecutableActionObject[]];
19
+ export declare function initialTransition<T extends AnyActorLogic>(logic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): [SnapshotFrom<T>, ExecutableActionObjectFromLogic<T>[]];
17
20
  /**
18
21
  * Given a state `machine`, a `snapshot`, and an `event`, returns an array of
19
22
  * microsteps, where each microstep is a tuple of `[snapshot, actions]`.
20
23
  *
21
24
  * This is a pure function that does not execute `actions`.
22
25
  */
23
- export declare function getMicrosteps<T extends AnyStateMachine>(machine: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): Array<[SnapshotFrom<T>, ExecutableActionObject[]]>;
26
+ export declare function getMicrosteps<T extends AnyStateMachine>(machine: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): Array<[SnapshotFrom<T>, ExecutableActionObjectFromLogic<T>[]]>;
24
27
  /**
25
28
  * Given a state `machine` and optional `input`, returns an array of microsteps
26
29
  * from the initial transition, where each microstep is a tuple of `[snapshot,
@@ -28,7 +31,7 @@ export declare function getMicrosteps<T extends AnyStateMachine>(machine: T, sna
28
31
  *
29
32
  * This is a pure function that does not execute `actions`.
30
33
  */
31
- export declare function getInitialMicrosteps<T extends AnyStateMachine>(machine: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): Array<[SnapshotFrom<T>, ExecutableActionObject[]]>;
34
+ export declare function getInitialMicrosteps<T extends AnyStateMachine>(machine: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): Array<[SnapshotFrom<T>, ExecutableActionObjectFromLogic<T>[]]>;
32
35
  /**
33
36
  * Gets all potential next transitions from the current state.
34
37
  *
@@ -0,0 +1,4 @@
1
+ import type { AnyAction, AnyActorScope, AnyEventObject, AnyMachineSnapshot, EnqueueObject, EventObject, ExecutableActionObject, SpecialExecutableAction } from "./types.js";
2
+ export declare function createTransitionEnqueue(actorScope: AnyActorScope, actions: any[], internalEvents: EventObject[], actorSubscriptions?: boolean): EnqueueObject<any, any>;
3
+ export declare function isBuiltInExecutableAction(action: ExecutableActionObject): action is SpecialExecutableAction;
4
+ export declare function resolveActionsWithContext(currentSnapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope, actions: AnyAction[]): [AnyMachineSnapshot, ExecutableActionObject[]];
@@ -2,7 +2,6 @@ import type { MachineSnapshot } from "./State.js";
2
2
  import type { StateMachine } from "./StateMachine.js";
3
3
  import type { StateNode } from "./StateNode.js";
4
4
  import { AsyncActorLogic } from "./actors/promise.js";
5
- import type { BaseAtom } from "./atom.js";
6
5
  import type { Actor } from "./createActor.js";
7
6
  import { InspectionEvent } from "./inspection.js";
8
7
  import { Spawner } from "./spawn.js";
@@ -206,7 +205,7 @@ export type TransitionConfigFunction<TContext extends MachineContext, TCurrentEv
206
205
  reenter?: boolean;
207
206
  meta?: TMeta;
208
207
  } | void;
209
- export type AnyTransitionConfigFunction = TransitionConfigFunction<any, any, any, any, any, any, any, any, any>;
208
+ export type AnyTransitionConfigFunction = TransitionConfigFunction<any, any, any, any, any, any, any, any, any, any>;
210
209
  export type TransitionsConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
211
210
  [K in EventDescriptor<TEvent>]?: TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
212
211
  };
@@ -307,7 +306,7 @@ export type InvokeConfig<TContext extends MachineContext, TEvent extends EventOb
307
306
  onTimeout?: string | SingleOrArray<TransitionConfigOrTarget<TContext, TEvent, TEvent, TEmitted, TMeta, any, any, any, any>>;
308
307
  };
309
308
  export type AnyInvokeConfig = InvokeConfig<any, any, any, any, any, any, any, any>;
310
- export type AnyStateNodeConfig = Next_StateNodeConfig<any, any, any, any, any, any, any, any, any, any, any>;
309
+ export type AnyStateNodeConfig = Next_StateNodeConfig<any, any, any, any, any, any, any, any, any, any, any, any>;
311
310
  export type AnyStateNode = StateNode<any, any> | StateNode<never, EventObject> | StateNode<any, EventObject> | StateNode<never, any>;
312
311
  export type AnyMachineSnapshot = MachineSnapshot<any, any, any, any, any, any, any, any>;
313
312
  export type AnyStateMachine = StateMachine<any, // context
@@ -368,7 +367,7 @@ export type PersistedHistoryValue = Record<string, Array<{
368
367
  id: string;
369
368
  }>>;
370
369
  export type AnyHistoryValue = HistoryValue;
371
- export type StateFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends AnyStateMachine ? ReturnType<T['transition']> : T extends (...args: any[]) => AnyStateMachine ? ReturnType<ReturnType<T>['transition']> : never;
370
+ export type StateFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = T extends AnyStateMachine ? SnapshotFrom<T> : T extends (...args: any[]) => AnyStateMachine ? SnapshotFrom<ReturnType<T>> : never;
372
371
  export interface DoneActorEvent<TOutput = unknown, TId extends string = string> extends EventObject {
373
372
  type: `xstate.done.actor.${TId}`;
374
373
  output: TOutput;
@@ -718,7 +717,8 @@ export type ActorRefFrom<T> = T extends StateMachine<infer TContext, infer TEven
718
717
  export type SendableEventFromLogic<TLogic extends AnyActorLogic> = TLogic 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> ? TConfig extends {
719
718
  internalEvents?: readonly EventDescriptor<TEvent>[];
720
719
  } ? ExcludeInternalEvents<TEvent, TConfig['internalEvents'] extends readonly EventDescriptor<TEvent>[] ? TConfig['internalEvents'] extends readonly (infer TDesc)[] ? Extract<TDesc, string> : never : never> : TEvent : EventFromLogic<TLogic>;
721
- export type ActorRefFromLogic<T extends AnyActorLogic> = ActorRef<SnapshotFrom<T>, EventFromLogic<T>, EmittedFrom<T>, SendableEventFromLogic<T>>;
720
+ type OpaqueMachineSnapshot<TSnapshot extends Snapshot<unknown>> = TSnapshot extends MachineSnapshot<infer TContext, infer TEvent, infer TChildren, infer TStateValue, infer TTag, infer TOutput, infer TMeta, infer _TStateSchema> ? MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, any> : TSnapshot;
721
+ export type ActorRefFromLogic<T extends AnyActorLogic> = ActorRef<OpaqueMachineSnapshot<SnapshotFrom<T>>, EventFromLogic<T>, EmittedFrom<T>, SendableEventFromLogic<T>>;
722
722
  export type AnyActorRef = ActorRef<any, any, any, any>;
723
723
  /** The concrete actor instance type produced from actor logic. */
724
724
  export type ActorFromLogic<T extends AnyActorLogic> = ActorInstance<SnapshotFrom<T>, EventFromLogic<T>, EmittedFrom<T>, SendableEventFromLogic<T>>;
@@ -767,6 +767,7 @@ export type Snapshot<TOutput> = {
767
767
  output: undefined;
768
768
  error: undefined;
769
769
  };
770
+ export type ActorLogicTransitionResult<TSnapshot extends Snapshot<unknown>, TEffect = unknown> = [nextSnapshot: TSnapshot, effects: TEffect[]];
770
771
  /**
771
772
  * Represents logic which can be used by an actor.
772
773
  *
@@ -782,14 +783,22 @@ in TInput = NonReducibleUnknown, TSystem extends AnyActorSystem = AnyActorSystem
782
783
  config?: unknown;
783
784
  /**
784
785
  * Transition function that processes the current state and an incoming event
785
- * to produce a new state.
786
+ * to produce a new state and effects.
786
787
  *
787
788
  * @param snapshot - The current state.
788
789
  * @param event - The incoming event.
789
790
  * @param actorScope - The actor scope.
790
- * @returns The new state.
791
+ * @returns A tuple of the next state and effects.
791
792
  */
792
- transition: (snapshot: TSnapshot, event: TEvent, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => TSnapshot;
793
+ transition: (snapshot: TSnapshot, event: TEvent, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => ActorLogicTransitionResult<TSnapshot>;
794
+ /**
795
+ * Transition function that produces the initial state and effects.
796
+ *
797
+ * @param actorScope - The actor scope.
798
+ * @param input - The input for the initial state.
799
+ * @returns A tuple of the initial state and effects.
800
+ */
801
+ initialTransition: (input: TInput, actorScope: ActorScope<TSnapshot, TEvent, TSystem, TEmitted>) => ActorLogicTransitionResult<TSnapshot>;
793
802
  /**
794
803
  * Called to provide the initial state of the actor.
795
804
  *
@@ -833,8 +842,8 @@ export type UnknownActorLogic = ActorLogic<any, // snapshot
833
842
  any, // event
834
843
  any, // input
835
844
  AnyActorSystem, any>;
836
- export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer TSnapshot, infer _, infer __> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends ActorLogic<infer _TSnapshot, infer _TEvent, infer _TInput, infer _TEmitted, infer _TSystem> ? ReturnType<R['transition']> : R extends ActorScope<infer TSnapshot, infer _TEvent, infer _TEmitted, infer _TSystem> ? TSnapshot : never : never;
837
- export type EventFromLogic<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer TEvent, infer _TInput, infer _TEmitted, infer _TSystem> ? TEvent : never;
845
+ export type SnapshotFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer TSnapshot, infer _, infer __> ? TSnapshot : R extends Actor<infer TLogic> ? SnapshotFrom<TLogic> : R extends ActorLogic<infer TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? TSnapshot : R extends ActorScope<infer TSnapshot, infer _TEvent, infer _TEmitted, infer _TSystem> ? TSnapshot : never : never;
846
+ export type EventFromLogic<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer TEvent, infer _TInput, infer _TSystem, infer _TEmitted> ? TEvent : never;
838
847
  export type EmittedFrom<TLogic extends AnyActorLogic> = TLogic extends ActorLogic<infer _TSnapshot, infer _TEvent, infer _TInput, infer _TSystem, infer TEmitted> ? TEmitted : never;
839
848
  type ResolveEventType<T> = T extends infer R ? R 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> ? TEvent : R extends MachineSnapshot<infer _TContext, infer TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput, infer _TMeta, infer _TStateSchema> ? TEvent : R extends ActorRef<infer _TSnapshot, infer TEvent, infer _TEmitted> ? TEvent : never : never;
840
849
  export type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent extends EventObject = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : ExtractEvent<TEvent, K>;
@@ -953,19 +962,61 @@ export type ToStateValue<T extends StateSchema> = T extends {
953
962
  [StateKey in K]: ToStateValue<T['states'][K]>;
954
963
  };
955
964
  }>> : never) : {};
956
- export interface ExecutableActionObject {
957
- type: string & {};
965
+ export interface BaseExecutableActionObject {
958
966
  params: NonReducibleUnknown;
959
967
  args: unknown[];
960
968
  exec: (() => void) | undefined;
961
969
  }
962
- export type SpecialExecutableAction = Values<{
963
- [K in keyof typeof builtInActions]: {
964
- type: K;
965
- args: Parameters<(typeof builtInActions)[K]>;
966
- };
970
+ export interface CustomExecutableActionObject<TType extends string = string & {}> extends BaseExecutableActionObject {
971
+ type: TType;
972
+ }
973
+ export interface StartExecutableActionObject extends BaseExecutableActionObject {
974
+ type: '@xstate.start';
975
+ actor: AnyActor;
976
+ id: string;
977
+ logic: AnyActorLogic;
978
+ src: string | AnyActorLogic;
979
+ input: unknown;
980
+ args: Parameters<(typeof builtInActions)['@xstate.start']>;
981
+ }
982
+ export interface RaiseExecutableActionObject extends BaseExecutableActionObject {
983
+ type: '@xstate.raise';
984
+ event: EventObject;
985
+ id: string | undefined;
986
+ delay: number | undefined;
987
+ args: Parameters<(typeof builtInActions)['@xstate.raise']>;
988
+ }
989
+ export interface SendToExecutableActionObject extends BaseExecutableActionObject {
990
+ type: '@xstate.sendTo';
991
+ target: AnyActor;
992
+ event: EventObject;
993
+ id: string | undefined;
994
+ delay: number | undefined;
995
+ args: Parameters<(typeof builtInActions)['@xstate.sendTo']>;
996
+ }
997
+ export interface CancelExecutableActionObject extends BaseExecutableActionObject {
998
+ type: '@xstate.cancel';
999
+ id: string;
1000
+ args: Parameters<(typeof builtInActions)['@xstate.cancel']>;
1001
+ }
1002
+ export interface StopExecutableActionObject extends BaseExecutableActionObject {
1003
+ type: '@xstate.stop';
1004
+ actor: AnyActor;
1005
+ args: Parameters<(typeof builtInActions)['@xstate.stop']>;
1006
+ }
1007
+ export type BuiltInExecutableActionObject = Values<{
1008
+ '@xstate.start': StartExecutableActionObject;
1009
+ '@xstate.raise': RaiseExecutableActionObject;
1010
+ '@xstate.sendTo': SendToExecutableActionObject;
1011
+ '@xstate.cancel': CancelExecutableActionObject;
1012
+ '@xstate.stop': StopExecutableActionObject;
967
1013
  }>;
968
- export interface ToExecutableAction<T extends ParameterizedObject> extends ExecutableActionObject {
1014
+ export type SpecialExecutableAction = BuiltInExecutableActionObject;
1015
+ type TransitionExecutableActionObject<TType extends string = never> = BuiltInExecutableActionObject | CustomExecutableActionObject<TType | (string & {})>;
1016
+ type KnownImplementationKeys<TImplementationMap> = string extends keyof TImplementationMap ? never : Extract<keyof TImplementationMap, string>;
1017
+ export type ExecutableActionObjectFromLogic<T extends AnyActorLogic> = T extends StateMachine<any, any, any, any, any, any, any, any, any, any, infer TActionMap, any, any, any> ? TransitionExecutableActionObject<KnownImplementationKeys<TActionMap>> : ExecutableActionObject;
1018
+ export type ExecutableActionObject<TType extends string = string & {}> = BuiltInExecutableActionObject | CustomExecutableActionObject<TType>;
1019
+ export interface ToExecutableAction<T extends ParameterizedObject> extends CustomExecutableActionObject<T['type']> {
969
1020
  type: T['type'];
970
1021
  params: T['params'];
971
1022
  exec: undefined;
@@ -1019,9 +1070,6 @@ export type EnqueueObject<TEvent extends EventObject, TEmittedEvent extends Even
1019
1070
  */
1020
1071
  subscribeTo: {
1021
1072
  <TSnapshot extends Snapshot<unknown>, TOutput, TMappedEvent extends TEvent>(actor: AnyActor, mappers: SubscribeToMappers<TSnapshot, TOutput, TMappedEvent> | ((snapshot: TSnapshot) => TMappedEvent)): AnyActor;
1022
- <TValue, TMappedEvent extends TEvent>(atom: BaseAtom<TValue>, mappers: {
1023
- snapshot?: (value: TValue) => TMappedEvent;
1024
- } | ((value: TValue) => TMappedEvent)): AnyActor;
1025
1073
  };
1026
1074
  };
1027
1075
  export type Action<TContext extends MachineContext, TEvent extends EventObject, TEmittedEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TParams = Record<string, unknown> | undefined, _TCtx = [TContext] extends [never] ? any : TContext> = (_: {
@@ -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, EventDescriptor, EventObject, ExtractEvent, InitialContext, InputFrom, IsNever, MetaObject, NonReducibleUnknown, SingleOrArray, SnapshotEvent, StateValue, TODO, TransitionConfigFunction, Values, AnyStateNode } 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";
@@ -17,6 +17,10 @@ export type InferEvents<TEventSchemaMap extends Record<string, StandardSchemaV1>
17
17
  type: K;
18
18
  } : never;
19
19
  }>;
20
+ export type InferChildren<TChildrenSchemaMap extends Record<string, StandardSchemaV1>> = string extends keyof TChildrenSchemaMap ? {} : {
21
+ [K in keyof TChildrenSchemaMap & string]?: StandardSchemaV1.InferOutput<TChildrenSchemaMap[K]> extends AnyActorRef ? NormalizeActorRef<StandardSchemaV1.InferOutput<TChildrenSchemaMap[K]>> : never;
22
+ };
23
+ type NormalizeActorRef<TActorRef> = TActorRef extends ActorRef<infer TSnapshot, infer TEvent, infer TEmitted, infer TSendEvent> ? ActorRef<TSnapshot, TEvent, TEmitted, TSendEvent> : never;
20
24
  type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
21
25
  type InternalEventDescriptorFor<TEvent extends EventObject> = [TEvent] extends [
22
26
  never
@@ -46,17 +50,20 @@ export interface MachineOptions {
46
50
  */
47
51
  maxIterations?: number;
48
52
  }
49
- export type Next_MachineConfig<TContextSchema extends StandardSchemaV1, TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, TContext extends MachineContext = InferOutput<TContextSchema, MachineContext>, TEvent extends EventObject = InferEvents<TEventSchemaMap>, TDelays extends string = string, _TTag extends string = string, TActionMap extends Implementations['actions'] = Implementations['actions'], TActorMap extends Implementations['actors'] = Implementations['actors'], TGuardMap extends Implementations['guards'] = Implementations['guards'], TDelayMap extends Implementations['delays'] = Implementations['delays'], TContextRequired extends boolean = IsNever<TContext> extends true ? false : true> = (DistributiveOmit<Next_StateNodeConfig<TContext, DoNotInfer<InferEvents<TEventSchemaMap>>, DoNotInfer<TDelays>, DoNotInfer<StandardSchemaV1.InferOutput<TTagSchema> & string>, DoNotInfer<StandardSchemaV1.InferOutput<TOutputSchema>>, DoNotInfer<InferEvents<TEmittedSchemaMap>>, DoNotInfer<InferOutput<TMetaSchema, MetaObject>>, DoNotInfer<TActionMap>, DoNotInfer<TActorMap>, DoNotInfer<TGuardMap>, DoNotInfer<TDelayMap>>, 'output'> & {
53
+ 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>> = {
54
+ events?: TEventSchemaMap;
55
+ context?: TContextSchema;
56
+ emitted?: TEmittedSchemaMap;
57
+ input?: TInputSchema;
58
+ output?: TOutputSchema;
59
+ meta?: TMetaSchema;
60
+ tags?: TTagSchema;
61
+ children?: TChildrenSchemaMap;
62
+ };
63
+ export type AnyMachineSchemas = MachineSchemas<StandardSchemaV1, Record<string, StandardSchemaV1>, Record<string, StandardSchemaV1>, StandardSchemaV1, StandardSchemaV1, StandardSchemaV1, StandardSchemaV1, Record<string, StandardSchemaV1>>;
64
+ 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['actors'] = Implementations['actors'], TGuardMap extends Implementations['guards'] = Implementations['guards'], TDelayMap extends Implementations['delays'] = Implementations['delays'], TContextRequired extends boolean = IsNever<TContext> extends true ? false : true> = (DistributiveOmit<Next_StateNodeConfig<TContext, DoNotInfer<InferEvents<TEventSchemaMap>>, DoNotInfer<TDelays>, DoNotInfer<StandardSchemaV1.InferOutput<TTagSchema> & string>, DoNotInfer<StandardSchemaV1.InferOutput<TOutputSchema>>, DoNotInfer<InferEvents<TEmittedSchemaMap>>, DoNotInfer<InferOutput<TMetaSchema, MetaObject>>, DoNotInfer<TChildren>, DoNotInfer<TActionMap>, DoNotInfer<TActorMap>, DoNotInfer<TGuardMap>, DoNotInfer<TDelayMap>>, 'output'> & {
50
65
  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
- };
66
+ schemas?: MachineSchemas<TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap>;
60
67
  actions?: TActionMap;
61
68
  guards?: TGuardMap;
62
69
  actors?: TActorMap;
@@ -100,10 +107,26 @@ type InvokeSrcArgs<TContext extends MachineContext, TEvent extends EventObject,
100
107
  event: TEvent;
101
108
  self: AnyActorRef;
102
109
  };
103
- type InvokeInputArgs<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject> = {
110
+ type InvokeInputArgs<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>> = {
104
111
  context: TContext;
105
112
  event: TEvent;
106
- self: ActorSelf<MachineSnapshot<TContext, TEvent, Record<string, AnyActorRef | undefined>, StateValue, string, unknown, TODO, TODO>, TEvent, TEmitted>;
113
+ self: ActorSelf<MachineSnapshot<TContext, TEvent, TChildren, StateValue, string, unknown, TODO, TODO>, TEvent, TEmitted>;
114
+ };
115
+ type HasExplicitChildren<TChildren extends Record<string, AnyActorRef | undefined>> = string extends keyof TChildren ? false : [keyof TChildren] extends [never] ? false : true;
116
+ type ChildIdForLogic<TLogic extends AnyActorLogic, TChildren extends Record<string, AnyActorRef | undefined>> = HasExplicitChildren<TChildren> extends true ? Values<{
117
+ [K in keyof TChildren & string]: ActorRefFromLogic<TLogic> extends NonNullable<TChildren[K]> ? K : never;
118
+ }> : string;
119
+ type LogicForChildRef<TActorRef> = NonNullable<TActorRef> extends ActorRef<infer TSnapshot, infer TEvent, infer TEmitted, any> ? ActorLogic<TSnapshot, TEvent, any, any, TEmitted> : never;
120
+ type InlineChildInvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> = Values<{
121
+ [K in keyof TChildren & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
122
+ id: K;
123
+ src: LogicForChildRef<TChildren[K]>;
124
+ input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => unknown) | NonReducibleUnknown;
125
+ };
126
+ }>;
127
+ type InlineInvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> = HasExplicitChildren<TChildren> extends true ? InlineChildInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> : Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
128
+ src: AnyActorLogic;
129
+ input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => unknown) | NonReducibleUnknown;
107
130
  };
108
131
  /**
109
132
  * Invoke config. A union of:
@@ -115,20 +138,17 @@ type InvokeInputArgs<TContext extends MachineContext, TEvent extends EventObject
115
138
  * - A branch for inline (unregistered) actor logic values, whose `input` cannot
116
139
  * be correlated (the config is not generic over inline logic).
117
140
  */
118
- export type Next_InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> = string extends keyof TActorMap ? // No registered actors (permissive map): `src`/`input` cannot be
119
- Next_InvokeConfigBase<TContext, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
141
+ 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['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> = string extends keyof TActorMap ? HasExplicitChildren<TChildren> extends true ? InlineInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> : Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
120
142
  src: string | AnyActorLogic | ((args: InvokeSrcArgs<TContext, TEvent, TActorMap>) => string | AnyActorLogic);
121
- input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted>) => unknown) | NonReducibleUnknown;
143
+ input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => unknown) | NonReducibleUnknown;
122
144
  } : {
123
- [K in keyof TActorMap & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
145
+ [K in keyof TActorMap & string]: Next_InvokeConfigBase<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
124
146
  src: K | TActorMap[K] | ((args: InvokeSrcArgs<TContext, TEvent, TActorMap>) => K | TActorMap[K]);
125
- input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted>) => InputFrom<TActorMap[K]>) | InputFrom<TActorMap[K]>;
147
+ id?: ChildIdForLogic<TActorMap[K], TChildren>;
148
+ input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted, TChildren>) => InputFrom<TActorMap[K]>) | InputFrom<TActorMap[K]>;
126
149
  };
127
- }[keyof TActorMap & string] | (Next_InvokeConfigBase<TContext, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta> & {
128
- src: AnyActorLogic;
129
- input?: ((args: InvokeInputArgs<TContext, TEvent, TEmitted>) => unknown) | NonReducibleUnknown;
130
- });
131
- interface Next_InvokeConfigBase<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> {
150
+ }[keyof TActorMap & string] | InlineInvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
151
+ 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['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject> {
132
152
  id?: string;
133
153
  systemId?: string;
134
154
  onDone?: Next_TransitionConfigOrTarget<TContext, DoneActorEvent<any>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;
@@ -194,7 +214,7 @@ type Next_RouteConfig<TContext extends MachineContext, TEvent extends EventObjec
194
214
  }) => Record<string, unknown>);
195
215
  });
196
216
  type Next_ChoiceConfigFunction<TContext extends MachineContext, TCurrentEvent extends EventObject, TEvent extends EventObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TMeta extends MetaObject, _TCtx = [TContext] extends [never] ? any : TContext> = (args: Next_ChoiceArgs<TContext, TCurrentEvent, TEvent, TActionMap, TActorMap, TGuardMap, TDelayMap, _TCtx>) => Next_ChoiceTarget<TMeta>;
197
- export type Next_StateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown>> = Next_RegularStateNodeConfig<TContext, TEvent, TDelays, TTag, _TOutput, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TInput, TInputMap> | Next_ChoiceStateNodeConfig<TContext, TEvent, TTag, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
217
+ 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['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown>> = Next_RegularStateNodeConfig<TContext, TEvent, TDelays, TTag, _TOutput, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TInput, TInputMap> | Next_ChoiceStateNodeConfig<TContext, TEvent, TTag, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
198
218
  interface Next_ChoiceStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TTag extends string, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> {
199
219
  contextSchema?: StandardSchemaV1;
200
220
  type: 'choice';
@@ -221,7 +241,7 @@ interface Next_ChoiceStateNodeConfig<TContext extends MachineContext, TEvent ext
221
241
  output?: never;
222
242
  target?: never;
223
243
  }
224
- interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, _TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown>> {
244
+ 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['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TInput = Record<string, unknown> | undefined, TInputMap extends Record<string, unknown> = Record<string, unknown>> {
225
245
  contextSchema?: StandardSchemaV1;
226
246
  /** The initial state transition. */
227
247
  initial?: string | {
@@ -252,13 +272,13 @@ interface Next_RegularStateNodeConfig<TContext extends MachineContext, TEvent ex
252
272
  */
253
273
  states?: {
254
274
  [K in string]: Next_StateNodeConfig<TContext, TEvent, TDelays, TTag, any, // TOutput,
255
- TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, LookupInput<TInputMap, K>, TInputMap>;
275
+ TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, LookupInput<TInputMap, K>, TInputMap>;
256
276
  };
257
277
  /**
258
278
  * The services to invoke upon entering this state node. These services will
259
279
  * be stopped upon exiting this state node.
260
280
  */
261
- invoke?: SingleOrArray<Next_InvokeConfig<TContext, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>>;
281
+ invoke?: SingleOrArray<Next_InvokeConfig<TContext, TEvent, TEmitted, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>>;
262
282
  /** The mapping of event types to their potential transition(s). */
263
283
  on?: {
264
284
  [K in EventDescriptor<TEvent>]?: Next_TransitionConfigOrTarget<TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta>;