xstate 6.0.0-alpha.5 → 6.0.0-alpha.7

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 (39) hide show
  1. package/README.md +4 -2
  2. package/dist/{StateMachine-f310bc72.esm.js → StateMachine-1ff90553.esm.js} +6 -6
  3. package/dist/{StateMachine-4deb4090.development.esm.js → StateMachine-2b259bff.development.esm.js} +6 -6
  4. package/dist/{StateMachine-445a8480.cjs.js → StateMachine-6673bf76.cjs.js} +6 -6
  5. package/dist/{StateMachine-f83f01f9.development.cjs.js → StateMachine-68fe6077.development.cjs.js} +6 -6
  6. package/dist/declarations/src/createActor.d.ts +1 -1
  7. package/dist/declarations/src/createMachineFromConfig.d.ts +2 -1
  8. package/dist/declarations/src/index.d.ts +1 -1
  9. package/dist/declarations/src/setup.d.ts +97 -27
  10. package/dist/declarations/src/spawn.d.ts +3 -3
  11. package/dist/declarations/src/stateUtils.d.ts +1 -0
  12. package/dist/declarations/src/system.d.ts +1 -1
  13. package/dist/declarations/src/types.d.ts +15 -10
  14. package/dist/declarations/src/types.v6.d.ts +16 -14
  15. package/dist/{index-918ab496.cjs.js → index-87499be0.cjs.js} +51 -33
  16. package/dist/{index-ccbe7c0b.development.esm.js → index-9594f050.development.esm.js} +51 -33
  17. package/dist/{index-9cce3480.esm.js → index-aaf74d09.esm.js} +51 -33
  18. package/dist/{index-ebaf6fd8.development.cjs.js → index-b063a967.development.cjs.js} +51 -33
  19. package/dist/xstate-actors.cjs.js +1 -1
  20. package/dist/xstate-actors.development.cjs.js +1 -1
  21. package/dist/xstate-actors.development.esm.js +1 -1
  22. package/dist/xstate-actors.esm.js +1 -1
  23. package/dist/xstate-actors.umd.min.js +1 -1
  24. package/dist/xstate-actors.umd.min.js.map +1 -1
  25. package/dist/xstate-graph.cjs.js +2 -2
  26. package/dist/xstate-graph.development.cjs.js +2 -2
  27. package/dist/xstate-graph.development.esm.js +2 -2
  28. package/dist/xstate-graph.esm.js +2 -2
  29. package/dist/xstate-graph.umd.min.js +1 -1
  30. package/dist/xstate-graph.umd.min.js.map +1 -1
  31. package/dist/xstate.cjs.js +55 -3
  32. package/dist/xstate.cjs.mjs +1 -0
  33. package/dist/xstate.development.cjs.js +55 -3
  34. package/dist/xstate.development.cjs.mjs +1 -0
  35. package/dist/xstate.development.esm.js +57 -6
  36. package/dist/xstate.esm.js +57 -6
  37. package/dist/xstate.umd.min.js +1 -1
  38. package/dist/xstate.umd.min.js.map +1 -1
  39. package/package.json +1 -1
package/README.md CHANGED
@@ -119,7 +119,7 @@ npm install xstate
119
119
  ```
120
120
 
121
121
  ```ts
122
- import { createMachine, createActor, assign } from 'xstate';
122
+ import { createMachine, createActor } from 'xstate';
123
123
 
124
124
  // State machine
125
125
  const toggleMachine = createMachine({
@@ -135,7 +135,9 @@ const toggleMachine = createMachine({
135
135
  }
136
136
  },
137
137
  active: {
138
- entry: assign({ count: ({ context }) => context.count + 1 }),
138
+ entry: ({ context }) => ({
139
+ context: { count: context.count + 1 }
140
+ }),
139
141
  on: {
140
142
  TOGGLE: { target: 'inactive' }
141
143
  }
@@ -1,4 +1,4 @@
1
- import { P as ProcessingStatus, C as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, D as mapValues, t as toArray, E as createInvokeId, F as getDelayedTransitions, G as evaluateCandidate, H as formatTransition, N as NULL_EVENT, I as toTransitionConfigArray, J as createInvokeTimeoutEvent, K as getCandidates, L as formatRouteTransitions, M as resolveStateValue, O as getAllStateNodes, f as getStateNodes, Q as createMachineSnapshot, R as isInFinalState, a as macrostep, U as transitionNode, m as matchesEventDescriptor, V as resolveActionsWithContext, b as createInitEvent, d as initialMicrostep, W as toStatePath, X as isStateId, Y as getStateNodeByPath, Z as getPersistedSnapshot, $ as $$ACTOR_TYPE } from './index-9cce3480.esm.js';
1
+ import { P as ProcessingStatus, C as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, D as mapValues, t as toArray, E as createInvokeId, F as getDelayedTransitions, G as evaluateCandidate, H as formatTransition, N as NULL_EVENT, I as toTransitionConfigArray, J as createInvokeTimeoutEvent, K as getCandidates, L as formatRouteTransitions, M as resolveStateValue, O as getAllStateNodes, f as getStateNodes, Q as createMachineSnapshot, R as isInFinalState, a as macrostep, U as transitionNode, m as matchesEventDescriptor, V as resolveActionsWithContext, b as createInitEvent, d as initialMicrostep, W as toStatePath, X as isStateId, Y as getStateNodeByPath, Z as getPersistedSnapshot, $ as $$ACTOR_TYPE } from './index-aaf74d09.esm.js';
2
2
 
3
3
  function createSpawner(actorScope, {
4
4
  machine,
@@ -20,7 +20,7 @@ function createSpawner(actorScope, {
20
20
  self: actorScope.self
21
21
  }) : options?.input,
22
22
  src,
23
- systemId: options?.systemId
23
+ registryKey: options?.registryKey
24
24
  });
25
25
  spawnedChildren[actor.id] = actor;
26
26
  return actor;
@@ -31,7 +31,7 @@ function createSpawner(actorScope, {
31
31
  syncSnapshot: options?.syncSnapshot,
32
32
  input: options?.input,
33
33
  src,
34
- systemId: options?.systemId
34
+ registryKey: options?.registryKey
35
35
  });
36
36
  return actor;
37
37
  }
@@ -171,7 +171,7 @@ class StateNode {
171
171
  this.invoke = toArray(this.config.invoke).map((invokeConfig, i) => {
172
172
  const {
173
173
  src,
174
- systemId
174
+ registryKey
175
175
  } = invokeConfig;
176
176
  const invokeId = createInvokeId(this.id, i);
177
177
  const resolvedId = invokeConfig.id ?? invokeId;
@@ -184,7 +184,7 @@ class StateNode {
184
184
  src: sourceName,
185
185
  logic: src,
186
186
  id: resolvedId,
187
- systemId
187
+ registryKey
188
188
  };
189
189
  });
190
190
  }
@@ -658,7 +658,7 @@ class StateMachine {
658
658
  syncSnapshot: actorData.syncSnapshot,
659
659
  snapshot: childState,
660
660
  src,
661
- systemId: actorData.systemId
661
+ registryKey: actorData.registryKey
662
662
  });
663
663
  // Mark so `start()` knows to start this child (freshly invoked/spawned
664
664
  // children are started via deferred `@xstate.start` actions instead).
@@ -1,4 +1,4 @@
1
- import { P as ProcessingStatus, C as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, D as mapValues, t as toArray, E as createInvokeId, F as getDelayedTransitions, G as evaluateCandidate, H as formatTransition, N as NULL_EVENT, I as toTransitionConfigArray, J as createInvokeTimeoutEvent, K as getCandidates, L as formatRouteTransitions, M as resolveStateValue, O as getAllStateNodes, f as getStateNodes, Q as createMachineSnapshot, R as isInFinalState, a as macrostep, U as transitionNode, m as matchesEventDescriptor, V as resolveActionsWithContext, b as createInitEvent, d as initialMicrostep, W as toStatePath, X as isStateId, Y as getStateNodeByPath, Z as getPersistedSnapshot, $ as $$ACTOR_TYPE } from './index-ccbe7c0b.development.esm.js';
1
+ import { P as ProcessingStatus, C as resolveReferencedActor, c as createActor, S as STATE_DELIMITER, D as mapValues, t as toArray, E as createInvokeId, F as getDelayedTransitions, G as evaluateCandidate, H as formatTransition, N as NULL_EVENT, I as toTransitionConfigArray, J as createInvokeTimeoutEvent, K as getCandidates, L as formatRouteTransitions, M as resolveStateValue, O as getAllStateNodes, f as getStateNodes, Q as createMachineSnapshot, R as isInFinalState, a as macrostep, U as transitionNode, m as matchesEventDescriptor, V as resolveActionsWithContext, b as createInitEvent, d as initialMicrostep, W as toStatePath, X as isStateId, Y as getStateNodeByPath, Z as getPersistedSnapshot, $ as $$ACTOR_TYPE } from './index-9594f050.development.esm.js';
2
2
 
3
3
  function createSpawner(actorScope, {
4
4
  machine,
@@ -20,7 +20,7 @@ function createSpawner(actorScope, {
20
20
  self: actorScope.self
21
21
  }) : options?.input,
22
22
  src,
23
- systemId: options?.systemId
23
+ registryKey: options?.registryKey
24
24
  });
25
25
  spawnedChildren[actor.id] = actor;
26
26
  return actor;
@@ -31,7 +31,7 @@ function createSpawner(actorScope, {
31
31
  syncSnapshot: options?.syncSnapshot,
32
32
  input: options?.input,
33
33
  src,
34
- systemId: options?.systemId
34
+ registryKey: options?.registryKey
35
35
  });
36
36
  return actor;
37
37
  }
@@ -171,7 +171,7 @@ class StateNode {
171
171
  this.invoke = toArray(this.config.invoke).map((invokeConfig, i) => {
172
172
  const {
173
173
  src,
174
- systemId
174
+ registryKey
175
175
  } = invokeConfig;
176
176
  const invokeId = createInvokeId(this.id, i);
177
177
  const resolvedId = invokeConfig.id ?? invokeId;
@@ -184,7 +184,7 @@ class StateNode {
184
184
  src: sourceName,
185
185
  logic: src,
186
186
  id: resolvedId,
187
- systemId
187
+ registryKey
188
188
  };
189
189
  });
190
190
  }
@@ -672,7 +672,7 @@ class StateMachine {
672
672
  syncSnapshot: actorData.syncSnapshot,
673
673
  snapshot: childState,
674
674
  src,
675
- systemId: actorData.systemId
675
+ registryKey: actorData.registryKey
676
676
  });
677
677
  // Mark so `start()` knows to start this child (freshly invoked/spawned
678
678
  // children are started via deferred `@xstate.start` actions instead).
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var dist_xstateActors = require('./index-918ab496.cjs.js');
3
+ var dist_xstateActors = require('./index-87499be0.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, {
6
6
  machine,
@@ -22,7 +22,7 @@ function createSpawner(actorScope, {
22
22
  self: actorScope.self
23
23
  }) : options?.input,
24
24
  src,
25
- systemId: options?.systemId
25
+ registryKey: options?.registryKey
26
26
  });
27
27
  spawnedChildren[actor.id] = actor;
28
28
  return actor;
@@ -33,7 +33,7 @@ function createSpawner(actorScope, {
33
33
  syncSnapshot: options?.syncSnapshot,
34
34
  input: options?.input,
35
35
  src,
36
- systemId: options?.systemId
36
+ registryKey: options?.registryKey
37
37
  });
38
38
  return actor;
39
39
  }
@@ -173,7 +173,7 @@ class StateNode {
173
173
  this.invoke = dist_xstateActors.toArray(this.config.invoke).map((invokeConfig, i) => {
174
174
  const {
175
175
  src,
176
- systemId
176
+ registryKey
177
177
  } = invokeConfig;
178
178
  const invokeId = dist_xstateActors.createInvokeId(this.id, i);
179
179
  const resolvedId = invokeConfig.id ?? invokeId;
@@ -186,7 +186,7 @@ class StateNode {
186
186
  src: sourceName,
187
187
  logic: src,
188
188
  id: resolvedId,
189
- systemId
189
+ registryKey
190
190
  };
191
191
  });
192
192
  }
@@ -660,7 +660,7 @@ class StateMachine {
660
660
  syncSnapshot: actorData.syncSnapshot,
661
661
  snapshot: childState,
662
662
  src,
663
- systemId: actorData.systemId
663
+ registryKey: actorData.registryKey
664
664
  });
665
665
  // Mark so `start()` knows to start this child (freshly invoked/spawned
666
666
  // children are started via deferred `@xstate.start` actions instead).
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var dist_xstateActors = require('./index-ebaf6fd8.development.cjs.js');
3
+ var dist_xstateActors = require('./index-b063a967.development.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, {
6
6
  machine,
@@ -22,7 +22,7 @@ function createSpawner(actorScope, {
22
22
  self: actorScope.self
23
23
  }) : options?.input,
24
24
  src,
25
- systemId: options?.systemId
25
+ registryKey: options?.registryKey
26
26
  });
27
27
  spawnedChildren[actor.id] = actor;
28
28
  return actor;
@@ -33,7 +33,7 @@ function createSpawner(actorScope, {
33
33
  syncSnapshot: options?.syncSnapshot,
34
34
  input: options?.input,
35
35
  src,
36
- systemId: options?.systemId
36
+ registryKey: options?.registryKey
37
37
  });
38
38
  return actor;
39
39
  }
@@ -173,7 +173,7 @@ class StateNode {
173
173
  this.invoke = dist_xstateActors.toArray(this.config.invoke).map((invokeConfig, i) => {
174
174
  const {
175
175
  src,
176
- systemId
176
+ registryKey
177
177
  } = invokeConfig;
178
178
  const invokeId = dist_xstateActors.createInvokeId(this.id, i);
179
179
  const resolvedId = invokeConfig.id ?? invokeId;
@@ -186,7 +186,7 @@ class StateNode {
186
186
  src: sourceName,
187
187
  logic: src,
188
188
  id: resolvedId,
189
- systemId
189
+ registryKey
190
190
  };
191
191
  });
192
192
  }
@@ -674,7 +674,7 @@ class StateMachine {
674
674
  syncSnapshot: actorData.syncSnapshot,
675
675
  snapshot: childState,
676
676
  src,
677
- systemId: actorData.systemId
677
+ registryKey: actorData.registryKey
678
678
  });
679
679
  // Mark so `start()` knows to start this child (freshly invoked/spawned
680
680
  // children are started via deferred `@xstate.start` actions instead).
@@ -40,7 +40,7 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorInstanc
40
40
  ref: ActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, EmittedFrom<TLogic>, SendableEventFromLogic<TLogic>>;
41
41
  private _actorScope;
42
42
  private _initialEffects;
43
- systemId: string | undefined;
43
+ registryKey: string | undefined;
44
44
  /** The globally unique process ID for this invocation. */
45
45
  sessionId: string;
46
46
  /** The system to which this actor belongs. */
@@ -99,7 +99,7 @@ export interface GuardJSON {
99
99
  }
100
100
  export interface InvokeJSON {
101
101
  id?: string;
102
- systemId?: string;
102
+ registryKey?: string;
103
103
  src: string | UnserializableMarker;
104
104
  input?: unknown;
105
105
  onDone?: TransitionJSON | TransitionJSON[];
@@ -110,6 +110,7 @@ export interface InvokeJSON {
110
110
  }
111
111
  export interface TransitionJSON {
112
112
  target?: string | string[];
113
+ context?: MachineContext;
113
114
  actions?: ActionJSON[];
114
115
  guard?: GuardJSON;
115
116
  description?: string;
@@ -7,7 +7,7 @@ export type { ActionJSON, GuardJSON, InvokeJSON, MachineJSON, StateNodeJSON, Tra
7
7
  export { machineConfigToJSON, serializeMachine, type CodeExpression, type UnserializableMarker } from "./serialize.js";
8
8
  export { mapState } from "./mapState.js";
9
9
  export { types, isTypeSchema, type StandardSchemaV1, type TypeSchema } from "./schema.types.js";
10
- export { setup } from "./setup.js";
10
+ export { createSystem, setup } from "./setup.js";
11
11
  export { getInitialSnapshot, getNextSnapshot } from "./getNextSnapshot.js";
12
12
  export type { InspectionEvent, ActorInspectionEvent, TransitionInspectionEvent, ActionRecord, SentRecord } from "./inspection.js";
13
13
  export { SimulatedClock } from "./SimulatedClock.js";
@@ -1,6 +1,8 @@
1
1
  import { StandardSchemaV1 } from "./schema.types.js";
2
2
  import { StateMachine } from "./StateMachine.js";
3
- import { AnyActorRef, AnyStateNode, EventObject, AnyEventObject, EventDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, ToChildren, MetaObject, Cast, Compute } from "./types.js";
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";
5
+ import { InspectionEvent } from "./inspection.js";
4
6
  import { DelayMapFromNames, InferChildren, Implementations, InferOutput, InferEvents, Next_MachineConfig, Next_StateNodeConfig, WithDefault } from "./types.v6.js";
5
7
  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
8
  schemas?: TSchemas;
@@ -10,6 +12,38 @@ type SetupConfig<TSchemas extends SetupSchemas, TStates extends Record<string, S
10
12
  guards?: TGuardMap;
11
13
  delays?: TDelayMap;
12
14
  };
15
+ type SystemConfig<TSystemRegistry extends SystemRegistry> = {
16
+ registry?: TSystemRegistry;
17
+ };
18
+ type SystemActorMap<TSystemRegistry extends SystemRegistry> = {
19
+ [K in keyof TSystemRegistry & string]: ActorRefFromLogic<TSystemRegistry[K]>;
20
+ };
21
+ 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['actors']> = TKey extends keyof TSystemRegistry & string ? TSrc extends keyof TActorMap & string ? LogicMatchesRegistryKey<TActorMap[TSrc], TSystemRegistry[TKey]> : TSrc extends AnyActorLogic ? LogicMatchesRegistryKey<TSrc, TSystemRegistry[TKey]> : true : false;
23
+ type ValidateSystemInvoke<TInvoke, TSystemRegistry extends SystemRegistry, TActorMap extends Implementations['actors']> = TInvoke extends readonly unknown[] ? {
24
+ [K in keyof TInvoke]: TInvoke[K] & ValidateSystemInvoke<TInvoke[K], TSystemRegistry, TActorMap>;
25
+ } : TInvoke extends {
26
+ registryKey: infer TKey;
27
+ } ? TKey extends string ? TInvoke extends {
28
+ src: infer TSrc;
29
+ } ? RegistryKeyMatchesSrc<TKey, TSrc, TSystemRegistry, TActorMap> extends true ? unknown : {
30
+ registryKey: never;
31
+ } : TKey extends keyof TSystemRegistry & string ? unknown : {
32
+ registryKey: never;
33
+ } : {
34
+ registryKey: never;
35
+ } : unknown;
36
+ type ValidateRegistryKeys<TConfig, TSystemRegistry extends SystemRegistry, TActorMap extends Implementations['actors']> = string extends keyof TSystemRegistry ? unknown : (TConfig extends {
37
+ invoke: infer TInvoke;
38
+ } ? {
39
+ invoke: TInvoke & ValidateSystemInvoke<TInvoke, TSystemRegistry, TActorMap>;
40
+ } : unknown) & (TConfig extends {
41
+ states: infer TStates;
42
+ } ? {
43
+ states: {
44
+ [K in keyof TStates]: TStates[K] & ValidateRegistryKeys<TStates[K], TSystemRegistry, TActorMap>;
45
+ };
46
+ } : unknown);
13
47
  type SetupStateSchemas = {
14
48
  context?: StandardSchemaV1;
15
49
  input?: StandardSchemaV1;
@@ -56,6 +90,7 @@ type ValidateNestedSetupStateKeys<TConfig, TStateSchemas extends Record<string,
56
90
  type SetupContext<TSchemas, TContextSchema extends StandardSchemaV1> = [
57
91
  SetupSchema<TSchemas, 'context'>
58
92
  ] extends [never] ? unknown extends StandardSchemaV1.InferOutput<TContextSchema> ? MachineContext : StandardSchemaV1.InferOutput<TContextSchema> & MachineContext : StandardSchemaV1.InferOutput<SetupSchema<TSchemas, 'context'>> & MachineContext;
93
+ type SetupContextShape<TSchemas, TContextSchema extends StandardSchemaV1, TFallbackContext> = [SetupSchema<TSchemas, 'context'>] extends [never] ? unknown extends StandardSchemaV1.InferOutput<TContextSchema> ? TFallbackContext : StandardSchemaV1.InferOutput<TContextSchema> : StandardSchemaV1.InferOutput<SetupSchema<TSchemas, 'context'>>;
59
94
  type SetupContextRequired<TSchemas, TContextSchema extends StandardSchemaV1> = [
60
95
  SetupSchema<TSchemas, 'context'>
61
96
  ] extends [never] ? unknown extends StandardSchemaV1.InferOutput<TContextSchema> ? false : true : true;
@@ -103,6 +138,9 @@ type StateInput<TStateSchema extends SetupStateSchema> = TStateSchema['schemas']
103
138
  type StateContext<TStateSchema extends SetupStateSchema, TFallbackContext extends MachineContext> = TStateSchema['schemas'] extends {
104
139
  context: infer TContextSchema;
105
140
  } ? TContextSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TContextSchema> & MachineContext : TFallbackContext : TFallbackContext;
141
+ type StateContextShape<TStateSchema extends SetupStateSchema, TFallbackContext> = TStateSchema['schemas'] extends {
142
+ context: infer TContextSchema;
143
+ } ? TContextSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TContextSchema> : TFallbackContext : TFallbackContext;
106
144
  type WithNestedStates<TConfig, TNestedStates> = TConfig extends {
107
145
  type: 'choice';
108
146
  } ? TConfig : Omit<TConfig, 'states'> & {
@@ -154,7 +192,7 @@ type MergeStateSchema<TConfig extends StateSchema, TSetup extends StateSchema> =
154
192
  } : undefined : undefined;
155
193
  };
156
194
  /** Machine config with typed state input */
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'> & {
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['actors'], 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['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, TSystemRegistry>, 'states' | 'initial' | 'on' | 'always' | 'actions' | 'actors' | 'guards' | 'delays'> & {
158
196
  actions?: TRootActionMap;
159
197
  actors?: TRootActorMap;
160
198
  guards?: TRootGuardMap;
@@ -166,28 +204,34 @@ type SetupMachineConfig<TStateSchemas extends Record<string, SetupStateSchema>,
166
204
  }) => number);
167
205
  };
168
206
  initial?: SetupStateKey<TStateSchemas> | InitialTransitionWithInput<TStateSchemas, TContext, TEvent> | undefined;
169
- states?: StatesWithInput<TStateSchemas, TStateSchemas, TContext, TEvent, TChildren, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
207
+ on?: StateTransitions<TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
208
+ always?: StateTransitionConfigOrTarget<TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
209
+ states?: StatesWithInput<TStateSchemas, TStateSchemas, TContext, SetupContextShape<TSchemas, TContextSchema, TContext>, TEvent, TChildren, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
170
210
  };
171
211
  /** States config type that provides typed input for known states */
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>;
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['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = {
213
+ [K in keyof TStateSchemas & string]?: StateNodeConfigWithNestedInput<TRootStateSchemas, TStateSchemas[K], TContext, TContextShape, TEvent, TChildren, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
174
214
  };
175
215
  /** State node config that recursively applies typed input for nested states */
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'> & {
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['actors'], 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'> & {
177
217
  initial?: TStateSchema['states'] extends Record<string, SetupStateSchema> ? SetupStateKey<TStateSchema['states']> | InitialTransitionWithInput<TStateSchema['states'], StateContext<TStateSchema, TContext>, TEvent> : string | {
178
218
  target: string;
179
219
  input?: Record<string, unknown>;
180
220
  } | 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>;
221
+ on?: StateTransitions<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
222
+ always?: StateTransitionConfigOrTarget<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, StateContextShape<TStateSchema, TContextShape>, TEvent, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
223
+ }, 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
+ [K in string]?: Next_StateNodeConfig<TContext, TEvent, TDelays, TTag, any, TEmitted, TMeta, TChildren, TActionMap, TActorMap, TGuardMap, TDelayMap, undefined, Record<string, unknown>, TSystemRegistry>;
185
225
  }>;
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>;
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['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = {
227
+ [K in EventDescriptor<TEvent>]?: StateTransitionConfigOrTarget<TStateSchemas, TContext, TContextShape, ExtractEvent<TEvent, K>, TEvent, TEmitted, TChildren, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, TSystemRegistry>;
188
228
  };
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']> = undefined | {
190
- target?: SetupStateTarget<TStateSchemas> | SetupStateTarget<TStateSchemas>[];
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['actors'], 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
+ type StateTransitionObjectConfig<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TExpressionEvent extends EventObject, TMeta extends MetaObject> = (StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta> & {
231
+ description?: string;
232
+ }) | {
233
+ target: SetupStateTarget<TStateSchemas>[];
234
+ context?: ContextPatch<TContextShape, TContextShape, TContext>;
191
235
  description?: string;
192
236
  reenter?: boolean;
193
237
  meta?: TMeta;
@@ -195,8 +239,8 @@ type StateTransitionConfigOrTarget<TStateSchemas extends Record<string, SetupSta
195
239
  context: TContext;
196
240
  event: TExpressionEvent;
197
241
  }) => Record<string, unknown>);
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: {
242
+ };
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['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TSystemRegistry extends SystemRegistry> = (args: {
200
244
  context: TContext;
201
245
  event: TExpressionEvent;
202
246
  self: AnyActorRef;
@@ -207,24 +251,38 @@ type StateTransitionFunction<TStateSchemas extends Record<string, SetupStateSche
207
251
  actors: TActorMap;
208
252
  guards: TGuardMap;
209
253
  delays: TDelayMap;
210
- }, enq: any) => StateTransitionResult<TStateSchemas, TContext, TMeta> | void;
211
- type StateTransitionResult<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TMeta extends MetaObject> = {
254
+ }, enq: EnqueueObject<TEvent, TEmitted, TSystemRegistry>) => StateTransitionResult<TStateSchemas, TContext, TContextShape, TMeta> | void;
255
+ type StateTransitionResult<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TContextShape, TMeta extends MetaObject> = {
212
256
  target?: never;
213
- context?: TContext;
257
+ context?: ContextPatch<TContextShape, TContextShape, TContext>;
214
258
  reenter?: boolean;
215
259
  meta?: TMeta;
216
260
  } | {
217
261
  [K in keyof TStateSchemas & string]: {
218
262
  target: K;
219
- context: StateContext<TStateSchemas[K], TContext>;
220
263
  reenter?: boolean;
221
264
  meta?: TMeta;
222
265
  input?: StateInput<TStateSchemas[K]> | ((args: {
223
266
  context: TContext;
224
267
  event: EventObject;
225
268
  }) => StateInput<TStateSchemas[K]>);
226
- };
227
- }[keyof TStateSchemas & string];
269
+ } & ([TContextShape] extends [
270
+ StateContextShape<TStateSchemas[K], TContextShape>
271
+ ] ? {
272
+ context?: ContextPatch<TContextShape, StateContextShape<TStateSchemas[K], TContextShape>, StateContext<TStateSchemas[K], TContext>>;
273
+ } : {
274
+ context: ContextPatch<TContextShape, StateContextShape<TStateSchemas[K], TContextShape>, StateContext<TStateSchemas[K], TContext>>;
275
+ });
276
+ }[keyof TStateSchemas & string] | {
277
+ target: Exclude<SetupStateTarget<TStateSchemas>, keyof TStateSchemas & string>;
278
+ context?: ContextPatch<TContextShape, TContextShape, TContext>;
279
+ reenter?: boolean;
280
+ meta?: TMeta;
281
+ };
282
+ type ContextPatch<TCurrentContext, TTargetContext, TResolvedTargetContext extends MachineContext> = Compute<Partial<TResolvedTargetContext> & Pick<TResolvedTargetContext, Extract<RequiredContextKeys<TCurrentContext, TTargetContext>, string>>>;
283
+ type RequiredContextKeys<TCurrentContext, TTargetContext> = {
284
+ [K in keyof TTargetContext]-?: K extends keyof TCurrentContext ? [TCurrentContext[K]] extends [TTargetContext[K]] ? never : K : K;
285
+ }[keyof TTargetContext];
228
286
  /** Initial transition with typed input based on target state */
229
287
  type InitialTransitionWithInput<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject> = {
230
288
  [K in keyof TStateSchemas & string]: {
@@ -236,11 +294,11 @@ type InitialTransitionWithInput<TStateSchemas extends Record<string, SetupStateS
236
294
  };
237
295
  }[keyof TStateSchemas & string];
238
296
  /** Return type of setup() */
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>> {
297
+ 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>, TSystemRegistry extends SystemRegistry = SystemRegistry> {
240
298
  /** 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>>;
299
+ 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>, TSystemRegistry>;
242
300
  /** Creates a state machine with the setup configuration */
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: {
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['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>, 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: {
244
302
  schemas?: {
245
303
  events?: TEventSchemaMap;
246
304
  context?: TContextSchema;
@@ -255,14 +313,14 @@ interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<
255
313
  actors?: TActorMap;
256
314
  guards?: TGuardMap;
257
315
  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 : {
316
+ } & 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 : {
259
317
  type: 'xstate.route';
260
318
  to: RoutableStateId<Cast<TConfig, StateSchema>>;
261
319
  }), Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValue, TTag & string, [
262
320
  SetupSchema<TSchemas, 'input'>
263
321
  ] 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>>>;
264
322
  /** Creates a state node config with the setup configuration */
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;
323
+ createStateConfig<const TConfig extends StateNodeConfigWithNestedInput<TStates, SetupStateSchema, SetupContext<TSchemas, StandardSchemaV1>, SetupContextShape<TSchemas, StandardSchemaV1, 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, TSystemRegistry>>(config: TConfig): TConfig;
266
324
  /** State input schemas from setup config */
267
325
  states: TStates;
268
326
  }
@@ -303,4 +361,16 @@ interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<
303
361
  * ```
304
362
  */
305
363
  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>;
364
+ type SystemBuilder<TSystemRegistry extends SystemRegistry> = {
365
+ createActor<TLogic extends AnyActorLogic>(logic: TLogic, options?: Omit<ActorOptions<TLogic>, 'registryKey'> & {
366
+ registryKey?: RegistryKeyForLogic<TLogic, TSystemRegistry>;
367
+ } & {
368
+ [K in RequiredActorOptionsKeys<TLogic>]: unknown;
369
+ }): Actor<TLogic>;
370
+ get<K extends keyof SystemActorMap<TSystemRegistry> & string>(key: K): SystemActorMap<TSystemRegistry>[K] | undefined;
371
+ getAll(): Partial<SystemActorMap<TSystemRegistry>>;
372
+ 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['actors'] = {}, 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
+ };
375
+ export declare function createSystem<const TSystemRegistry extends SystemRegistry = {}>(_config?: SystemConfig<TSystemRegistry>): SystemBuilder<TSystemRegistry>;
306
376
  export {};
@@ -1,8 +1,8 @@
1
- import { ActorFromLogic, AnyActorLogic, AnyActorRef, AnyActorScope, AnyEventObject, AnyMachineSnapshot, ConditionalRequired, InputFrom, IsNotNever, type RequiredLogicInput } from "./types.js";
2
- export type Spawner = <TLogic extends AnyActorLogic>(src: TLogic, ...[options]: ConditionalRequired<[
1
+ import { ActorFromLogic, AnyActorLogic, AnyActorRef, AnyActorScope, AnyEventObject, AnyMachineSnapshot, ConditionalRequired, InputFrom, IsNotNever, RegistryKeyForLogic, SystemRegistry, type RequiredLogicInput } from "./types.js";
2
+ export type Spawner<TSystemRegistry extends SystemRegistry = SystemRegistry> = <TLogic extends AnyActorLogic>(src: TLogic, ...[options]: ConditionalRequired<[
3
3
  options?: {
4
4
  id?: string;
5
- systemId?: string;
5
+ registryKey?: RegistryKeyForLogic<TLogic, TSystemRegistry>;
6
6
  input?: TLogic extends string ? unknown : InputFrom<TLogic>;
7
7
  syncSnapshot?: boolean;
8
8
  } & {
@@ -39,6 +39,7 @@ export declare function initialMicrostep(root: AnyStateNode, preInitialState: An
39
39
  export declare function getTransitionResult(transition: Pick<AnyTransitionDefinition, 'target' | 'to' | 'source'> & {
40
40
  reenter?: AnyTransitionDefinition['reenter'];
41
41
  input?: AnyTransitionDefinition['input'];
42
+ context?: AnyTransitionDefinition['context'];
42
43
  }, snapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope): {
43
44
  targets: Readonly<AnyStateNode[]> | undefined;
44
45
  context: MachineContext | undefined;
@@ -30,7 +30,7 @@ export interface ActorSystem<T extends ActorSystemInfo> {
30
30
  _logger: (...args: any[]) => void;
31
31
  }
32
32
  export type AnyActorSystem = ActorSystem<any>;
33
- export declare function createSystem<T extends ActorSystemInfo>(rootActor: AnyActor, options: {
33
+ export declare function createRuntimeSystem<T extends ActorSystemInfo>(rootActor: AnyActor, options: {
34
34
  clock: Clock;
35
35
  logger: (...args: any[]) => void;
36
36
  snapshot?: unknown;