xstate 5.0.0-beta.21 → 5.0.0-beta.23

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 (49) hide show
  1. package/actions/dist/xstate-actions.cjs.js +1 -1
  2. package/actions/dist/xstate-actions.development.cjs.js +1 -1
  3. package/actions/dist/xstate-actions.development.esm.js +1 -1
  4. package/actions/dist/xstate-actions.esm.js +1 -1
  5. package/actions/dist/xstate-actions.umd.min.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +1 -1
  8. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  9. package/actors/dist/xstate-actors.development.esm.js +1 -1
  10. package/actors/dist/xstate-actors.esm.js +1 -1
  11. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  12. package/dev/dist/xstate-dev.umd.min.js.map +1 -1
  13. package/dist/{actions-a95d2e66.development.cjs.js → actions-0fcd4d15.development.cjs.js} +47 -30
  14. package/dist/{actions-5039c951.esm.js → actions-bf7f6679.esm.js} +45 -30
  15. package/dist/{actions-c619a105.cjs.js → actions-e83129c5.cjs.js} +47 -30
  16. package/dist/{actions-49f0501e.development.esm.js → actions-f6b5002d.development.esm.js} +45 -30
  17. package/dist/declarations/src/Machine.d.ts +2 -2
  18. package/dist/declarations/src/State.d.ts +5 -5
  19. package/dist/declarations/src/StateMachine.d.ts +24 -18
  20. package/dist/declarations/src/StateNode.d.ts +8 -8
  21. package/dist/declarations/src/actions/assign.d.ts +6 -6
  22. package/dist/declarations/src/actions/cancel.d.ts +7 -7
  23. package/dist/declarations/src/actions/choose.d.ts +4 -10
  24. package/dist/declarations/src/actions/log.d.ts +7 -7
  25. package/dist/declarations/src/actions/pure.d.ts +5 -17
  26. package/dist/declarations/src/actions/raise.d.ts +3 -3
  27. package/dist/declarations/src/actions/send.d.ts +22 -22
  28. package/dist/declarations/src/actions/stop.d.ts +7 -7
  29. package/dist/declarations/src/dev/index.d.ts +6 -6
  30. package/dist/declarations/src/index.d.ts +3 -2
  31. package/dist/declarations/src/interpreter.d.ts +31 -17
  32. package/dist/declarations/src/stateUtils.d.ts +12 -12
  33. package/dist/declarations/src/typegenTypes.d.ts +1 -1
  34. package/dist/declarations/src/types.d.ts +117 -136
  35. package/dist/declarations/src/utils.d.ts +8 -8
  36. package/dist/xstate.cjs.js +12 -9
  37. package/dist/xstate.cjs.mjs +3 -1
  38. package/dist/xstate.development.cjs.js +12 -9
  39. package/dist/xstate.development.cjs.mjs +3 -1
  40. package/dist/xstate.development.esm.js +9 -8
  41. package/dist/xstate.esm.js +9 -8
  42. package/dist/xstate.umd.min.js +1 -1
  43. package/dist/xstate.umd.min.js.map +1 -1
  44. package/guards/dist/xstate-guards.cjs.js +1 -1
  45. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  46. package/guards/dist/xstate-guards.development.esm.js +1 -1
  47. package/guards/dist/xstate-guards.esm.js +1 -1
  48. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  49. package/package.json +1 -1
@@ -939,7 +939,7 @@ function toActorRef(actorRefLike) {
939
939
  }
940
940
  const emptyLogic = fromTransition(_ => undefined, undefined);
941
941
  function createEmptyActor() {
942
- return interpret(emptyLogic);
942
+ return createActor(emptyLogic);
943
943
  }
944
944
 
945
945
  /**
@@ -995,6 +995,11 @@ let ActorStatus = /*#__PURE__*/function (ActorStatus) {
995
995
  ActorStatus[ActorStatus["Stopped"] = 2] = "Stopped";
996
996
  return ActorStatus;
997
997
  }({});
998
+
999
+ /**
1000
+ * @deprecated Use `ActorStatus` instead.
1001
+ */
1002
+ const InterpreterStatus = ActorStatus;
998
1003
  const defaultOptions = {
999
1004
  deferEvents: true,
1000
1005
  clock: {
@@ -1008,9 +1013,9 @@ const defaultOptions = {
1008
1013
  logger: console.log.bind(console),
1009
1014
  devTools: false
1010
1015
  };
1011
- class Interpreter {
1016
+ class Actor {
1012
1017
  /**
1013
- * The current state of the interpreted logic.
1018
+ * The current internal state of the actor.
1014
1019
  */
1015
1020
 
1016
1021
  /**
@@ -1034,10 +1039,10 @@ class Interpreter {
1034
1039
  */
1035
1040
 
1036
1041
  /**
1037
- * Creates a new Interpreter instance (i.e., service) for the given logic with the provided options, if any.
1042
+ * Creates a new actor instance for the given logic with the provided options, if any.
1038
1043
  *
1039
- * @param logic The logic to be interpreted
1040
- * @param options Interpreter options
1044
+ * @param logic The logic to create an actor from
1045
+ * @param options Actor options
1041
1046
  */
1042
1047
  constructor(logic, options) {
1043
1048
  this.logic = logic;
@@ -1101,7 +1106,7 @@ class Interpreter {
1101
1106
  }
1102
1107
  };
1103
1108
 
1104
- // Ensure that the send method is bound to this interpreter instance
1109
+ // Ensure that the send method is bound to this Actor instance
1105
1110
  // if destructured
1106
1111
  this.send = this.send.bind(this);
1107
1112
  this._initState();
@@ -1164,7 +1169,7 @@ class Interpreter {
1164
1169
  }
1165
1170
 
1166
1171
  /**
1167
- * Starts the interpreter from the initial state
1172
+ * Starts the Actor from the initial state
1168
1173
  */
1169
1174
  start() {
1170
1175
  if (this.status === ActorStatus.Running) {
@@ -1251,7 +1256,7 @@ class Interpreter {
1251
1256
  }
1252
1257
 
1253
1258
  /**
1254
- * Stops the interpreter and unsubscribe all listeners.
1259
+ * Stops the Actor and unsubscribe all listeners.
1255
1260
  */
1256
1261
  stop() {
1257
1262
  if (this._parent) {
@@ -1293,7 +1298,7 @@ class Interpreter {
1293
1298
  }
1294
1299
  _stopProcedure() {
1295
1300
  if (this.status !== ActorStatus.Running) {
1296
- // Interpreter already stopped; do nothing
1301
+ // Actor already stopped; do nothing
1297
1302
  return this;
1298
1303
  }
1299
1304
 
@@ -1315,7 +1320,7 @@ class Interpreter {
1315
1320
  }
1316
1321
 
1317
1322
  /**
1318
- * Sends an event to the running interpreter to trigger a transition.
1323
+ * Sends an event to the running Actor to trigger a transition.
1319
1324
  *
1320
1325
  * @param event The event to send
1321
1326
  */
@@ -1391,17 +1396,28 @@ class Interpreter {
1391
1396
  }
1392
1397
 
1393
1398
  /**
1394
- * Creates a new Interpreter instance for the given machine with the provided options, if any.
1399
+ * Creates a new `ActorRef` instance for the given machine with the provided options, if any.
1395
1400
  *
1396
- * @param machine The machine to interpret
1397
- * @param options Interpreter options
1401
+ * @param machine The machine to create an actor from
1402
+ * @param options `ActorRef` options
1398
1403
  */
1399
1404
 
1400
- function interpret(logic, options) {
1401
- const interpreter = new Interpreter(logic, options);
1405
+ function createActor(logic, options) {
1406
+ const interpreter = new Actor(logic, options);
1402
1407
  return interpreter;
1403
1408
  }
1404
1409
 
1410
+ /**
1411
+ * Creates a new Interpreter instance for the given machine with the provided options, if any.
1412
+ *
1413
+ * @deprecated Use `createActor` instead
1414
+ */
1415
+ const interpret = createActor;
1416
+
1417
+ /**
1418
+ * @deprecated Use `Actor` instead.
1419
+ */
1420
+
1405
1421
  function resolve$6(actorContext, state, actionArgs, {
1406
1422
  id,
1407
1423
  systemId,
@@ -1413,7 +1429,7 @@ function resolve$6(actorContext, state, actionArgs, {
1413
1429
  if (referenced) {
1414
1430
  // TODO: inline `input: undefined` should win over the referenced one
1415
1431
  const configuredInput = input || referenced.input;
1416
- actorRef = interpret(referenced.src, {
1432
+ actorRef = createActor(referenced.src, {
1417
1433
  id,
1418
1434
  src,
1419
1435
  parent: actorContext?.self,
@@ -2423,7 +2439,12 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
2423
2439
  _internalQueue: []
2424
2440
  });
2425
2441
  for (const action of actions) {
2426
- const resolved = typeof action === 'function' ? action : machine.implementations.actions[typeof action === 'string' ? action : action.type];
2442
+ const isInline = typeof action === 'function';
2443
+ const resolved = isInline ? action :
2444
+ // the existing type of `.actions` assumes non-nullable `TExpressionAction`
2445
+ // it's fine to cast this here to get a common type and lack of errors in the rest of the code
2446
+ // our logic below makes sure that we call those 2 "variants" correctly
2447
+ machine.implementations.actions[typeof action === 'string' ? action : action.type];
2427
2448
  if (!resolved) {
2428
2449
  continue;
2429
2450
  }
@@ -2432,12 +2453,7 @@ function resolveActionsAndContext(actions, event, currentState, actorCtx) {
2432
2453
  event,
2433
2454
  self: actorCtx?.self,
2434
2455
  system: actorCtx?.system,
2435
- // TODO: figure out story for `action` and inline actions
2436
- // what those ones should receive?
2437
- //
2438
- // entry: ({ action }) => {}
2439
- // exit: assign(({ action }) => {})
2440
- action: typeof action === 'string' ? {
2456
+ action: isInline ? undefined : typeof action === 'string' ? {
2441
2457
  type: action
2442
2458
  } : action
2443
2459
  };
@@ -2577,9 +2593,8 @@ class State {
2577
2593
  */
2578
2594
 
2579
2595
  /**
2580
- * The done data of the top-level finite state.
2596
+ * The output data of the top-level finite state.
2581
2597
  */
2582
- // TODO: add an explicit type for `output`
2583
2598
 
2584
2599
  /**
2585
2600
  * The enabled state nodes representative of the state value.
@@ -2868,7 +2883,7 @@ function createSpawner(actorContext, {
2868
2883
  const input = 'input' in options ? options.input : referenced.input;
2869
2884
 
2870
2885
  // TODO: this should also receive `src`
2871
- const actor = interpret(referenced.src, {
2886
+ const actor = createActor(referenced.src, {
2872
2887
  id: options.id,
2873
2888
  parent: actorContext.self,
2874
2889
  input: typeof input === 'function' ? input({
@@ -2882,7 +2897,7 @@ function createSpawner(actorContext, {
2882
2897
  return actor;
2883
2898
  } else {
2884
2899
  // TODO: this should also receive `src`
2885
- return interpret(src, {
2900
+ return createActor(src, {
2886
2901
  id: options.id,
2887
2902
  parent: actorContext.self,
2888
2903
  input: options.input,
@@ -3038,7 +3053,7 @@ function resolve(_, state, args, {
3038
3053
  get
3039
3054
  }) {
3040
3055
  return [state, undefined, toArray(get({
3041
- context: state.context,
3056
+ context: args.context,
3042
3057
  event: args.event
3043
3058
  }))];
3044
3059
  }
@@ -3117,4 +3132,4 @@ function createInitEvent(input) {
3117
3132
  };
3118
3133
  }
3119
3134
 
3120
- export { fromEventObservable as $, microstep as A, isAtomicStateNode as B, isStateId as C, getStateNodeByPath as D, getPersistedState as E, resolveReferencedActor as F, interpret as G, matchesState as H, sendTo as I, sendParent as J, forwardTo as K, Interpreter as L, ActorStatus as M, NULL_EVENT as N, doneInvoke as O, cancel as P, choose as Q, log as R, STATE_DELIMITER as S, pure as T, raise as U, stop as V, pathToStateValue as W, toObserver as X, fromPromise as Y, fromObservable as Z, fromCallback as _, toTransitionConfigArray as a, fromTransition as a0, stateIn as a1, not as a2, and as a3, or as a4, ConstantPrefix as a5, SpecialTargets as a6, startSignalType as a7, stopSignalType as a8, startSignal as a9, stopSignal as aa, isSignal as ab, isActorRef as ac, toActorRef as ad, createEmptyActor as ae, toGuardDefinition as af, constantPrefixes as ag, after as ah, done as ai, error as aj, escalate as ak, formatTransition as b, memo as c, flatten as d, evaluateGuard as e, formatTransitions as f, createInvokeId as g, getDelayedTransitions as h, formatInitialTransition as i, getCandidates as j, toInvokeConfig as k, getConfiguration as l, mapValues as m, getStateNodes as n, isInFinalState as o, State as p, isErrorEvent as q, resolveStateValue as r, cloneState as s, toArray as t, macrostep as u, transitionNode as v, getInitialConfiguration as w, resolveActionsAndContext as x, assign as y, createInitEvent as z };
3135
+ export { fromObservable as $, microstep as A, isAtomicStateNode as B, isStateId as C, getStateNodeByPath as D, getPersistedState as E, resolveReferencedActor as F, createActor as G, matchesState as H, sendTo as I, sendParent as J, forwardTo as K, interpret as L, Actor as M, NULL_EVENT as N, ActorStatus as O, InterpreterStatus as P, doneInvoke as Q, cancel as R, STATE_DELIMITER as S, choose as T, log as U, pure as V, raise as W, stop as X, pathToStateValue as Y, toObserver as Z, fromPromise as _, toTransitionConfigArray as a, fromCallback as a0, fromEventObservable as a1, fromTransition as a2, stateIn as a3, not as a4, and as a5, or as a6, ConstantPrefix as a7, SpecialTargets as a8, startSignalType as a9, stopSignalType as aa, startSignal as ab, stopSignal as ac, isSignal as ad, isActorRef as ae, toActorRef as af, createEmptyActor as ag, toGuardDefinition as ah, constantPrefixes as ai, after as aj, done as ak, error as al, escalate as am, formatTransition as b, memo as c, flatten as d, evaluateGuard as e, formatTransitions as f, createInvokeId as g, getDelayedTransitions as h, formatInitialTransition as i, getCandidates as j, toInvokeConfig as k, getConfiguration as l, mapValues as m, getStateNodes as n, isInFinalState as o, State as p, isErrorEvent as q, resolveStateValue as r, cloneState as s, toArray as t, macrostep as u, transitionNode as v, getInitialConfiguration as w, resolveActionsAndContext as x, assign as y, createInitEvent as z };
@@ -1,4 +1,4 @@
1
- import { MachineConfig, EventObject, MachineContext, InternalMachineImplementations, ParameterizedObject, ProvidedActor, AnyEventObject } from "./types.js";
1
+ import { MachineConfig, EventObject, MachineContext, InternalMachineImplementations, ParameterizedObject, ProvidedActor, AnyEventObject, NonReducibleUnknown } from "./types.js";
2
2
  import { TypegenConstraint, TypegenDisabled, ResolveTypegenMeta } from "./typegenTypes.js";
3
3
  import { StateMachine } from "./StateMachine.js";
4
- export declare function createMachine<TContext extends MachineContext, TEvent extends EventObject = AnyEventObject, TActor extends ProvidedActor = ProvidedActor, TInput = any, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, TEvent, ParameterizedObject, TActor, TInput, TTypesMeta>, implementations?: InternalMachineImplementations<TContext, TEvent, ParameterizedObject, TActor, ResolveTypegenMeta<TTypesMeta, TEvent, ParameterizedObject, TActor>>): StateMachine<TContext, TEvent, ParameterizedObject, TActor, TInput, ResolveTypegenMeta<TTypesMeta, TEvent, ParameterizedObject, TActor>>;
4
+ export declare function createMachine<TContext extends MachineContext, TEvent extends EventObject = AnyEventObject, TActor extends ProvidedActor = ProvidedActor, TInput = any, TOutput = NonReducibleUnknown, TAction extends ParameterizedObject = ParameterizedObject, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, TEvent, TAction, TActor, TInput, TOutput, TTypesMeta>, implementations?: InternalMachineImplementations<TContext, TEvent, TAction, TActor, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TActor>>): StateMachine<TContext, TEvent, TAction, TActor, TInput, TOutput, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TActor>>;
@@ -12,7 +12,7 @@ export declare function isStateConfig<TContext extends MachineContext, TEvent ex
12
12
  * @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
13
13
  */
14
14
  export declare const isState: typeof isStateConfig;
15
- export declare class State<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TResolvedTypesMeta = TypegenDisabled> {
15
+ export declare class State<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TOutput, TResolvedTypesMeta = TypegenDisabled> {
16
16
  machine: AnyStateMachine;
17
17
  tags: Set<string>;
18
18
  value: StateValue;
@@ -21,9 +21,9 @@ export declare class State<TContext extends MachineContext, TEvent extends Event
21
21
  */
22
22
  done: boolean;
23
23
  /**
24
- * The done data of the top-level finite state.
24
+ * The output data of the top-level finite state.
25
25
  */
26
- output: any;
26
+ output: TOutput | undefined;
27
27
  error: unknown;
28
28
  context: TContext;
29
29
  historyValue: Readonly<HistoryValue<TContext, TEvent>>;
@@ -41,7 +41,7 @@ export declare class State<TContext extends MachineContext, TEvent extends Event
41
41
  * @param stateValue
42
42
  * @param context
43
43
  */
44
- static from<TContext extends MachineContext, TEvent extends EventObject = EventObject>(stateValue: State<TContext, TEvent, TODO, any> | StateValue, context: TContext | undefined, machine: AnyStateMachine): State<TContext, TEvent, TODO, any>;
44
+ static from<TContext extends MachineContext, TEvent extends EventObject = EventObject>(stateValue: State<TContext, TEvent, TODO, any, any> | StateValue, context: TContext | undefined, machine: AnyStateMachine): State<TContext, TEvent, TODO, any, any>;
45
45
  /**
46
46
  * Creates a new `State` instance that represents the current state of a running machine.
47
47
  *
@@ -80,7 +80,7 @@ export declare class State<TContext extends MachineContext, TEvent extends Event
80
80
  /**
81
81
  * The next events that will cause a transition from the current state.
82
82
  */
83
- get nextEvents(): Array<TEvent['type']>;
83
+ get nextEvents(): Array<string>;
84
84
  get meta(): Record<string, any>;
85
85
  }
86
86
  export declare function cloneState<TState extends AnyState>(state: TState, config?: Partial<StateConfig<any, any>>): TState;
@@ -4,17 +4,17 @@ import type { AreAllImplementationsAssumedToBeProvided, MarkAllImplementationsAs
4
4
  import type { ActorContext, ActorLogic, EventObject, InternalMachineImplementations, MachineConfig, MachineContext, MachineImplementationsSimplified, MachineTypes, NoInfer, StateConfig, StateMachineDefinition, StateValue, TransitionDefinition, PersistedMachineState, ParameterizedObject, AnyActorContext, ProvidedActor, Equals, TODO } from "./types.js";
5
5
  export declare const STATE_IDENTIFIER = "#";
6
6
  export declare const WILDCARD = "*";
7
- export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject, TActor extends ProvidedActor, TInput, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, NoInfer<TEvent>, TAction, TActor>> implements ActorLogic<TEvent, State<TContext, TEvent, TActor, TResolvedTypesMeta>, State<TContext, TEvent, TActor, TResolvedTypesMeta>, PersistedMachineState<State<TContext, TEvent, TActor, TResolvedTypesMeta>>, TODO, TInput, TODO> {
7
+ export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TAction extends ParameterizedObject, TActor extends ProvidedActor, TInput, TOutput, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, NoInfer<TEvent>, TAction, TActor>> implements ActorLogic<TEvent, State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>, State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>, PersistedMachineState<State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>>, TODO, TInput, TOutput> {
8
8
  /**
9
9
  * The raw config used to create the machine.
10
10
  */
11
- config: MachineConfig<TContext, TEvent, any, any, any>;
11
+ config: MachineConfig<TContext, TEvent, any, any, any, TOutput, any>;
12
12
  /**
13
13
  * The machine's own version.
14
14
  */
15
15
  version?: string;
16
16
  implementations: MachineImplementationsSimplified<TContext, TEvent>;
17
- types: MachineTypes<TContext, TEvent, TActor, TInput>;
17
+ types: MachineTypes<TContext, TEvent, TAction, TActor, TInput, TOutput>;
18
18
  __xstatenode: true;
19
19
  idMap: Map<string, StateNode<TContext, TEvent>>;
20
20
  root: StateNode<TContext, TEvent>;
@@ -25,7 +25,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
25
25
  /**
26
26
  * The raw config used to create the machine.
27
27
  */
28
- config: MachineConfig<TContext, TEvent, any, any, any>, implementations?: MachineImplementationsSimplified<TContext, TEvent>);
28
+ config: MachineConfig<TContext, TEvent, any, any, any, TOutput, any>, implementations?: MachineImplementationsSimplified<TContext, TEvent>);
29
29
  /**
30
30
  * Clones this state machine with the provided implementations
31
31
  * and merges the `context` (if provided).
@@ -35,7 +35,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
35
35
  *
36
36
  * @returns A new `StateMachine` instance with the provided implementations.
37
37
  */
38
- provide(implementations: InternalMachineImplementations<TContext, TEvent, TAction, TActor, TResolvedTypesMeta, true>): StateMachine<TContext, TEvent, TAction, TActor, TInput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>;
38
+ provide(implementations: InternalMachineImplementations<TContext, TEvent, TAction, TActor, TResolvedTypesMeta, true>): StateMachine<TContext, TEvent, TAction, TActor, TInput, TOutput, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>;
39
39
  /**
40
40
  * Resolves the given `state` to a new `State` instance relative to this machine.
41
41
  *
@@ -43,8 +43,8 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
43
43
  *
44
44
  * @param state The state to resolve
45
45
  */
46
- resolveState(state: State<TContext, TEvent, TActor, TResolvedTypesMeta>): typeof state;
47
- resolveStateValue(stateValue: StateValue, ...[context]: Equals<TContext, MachineContext> extends true ? [] : [TContext]): State<TContext, TEvent, TActor, TResolvedTypesMeta>;
46
+ resolveState(state: State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>): typeof state;
47
+ resolveStateValue(stateValue: StateValue, ...[context]: Equals<TContext, MachineContext> extends true ? [] : [TContext]): State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>;
48
48
  /**
49
49
  * Determines the next state given the current `state` and received `event`.
50
50
  * Calculates a full macrostep from all microsteps.
@@ -52,7 +52,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
52
52
  * @param state The current State instance or state value
53
53
  * @param event The received event
54
54
  */
55
- transition(state: State<TContext, TEvent, TActor, TResolvedTypesMeta>, event: TEvent, actorCtx: ActorContext<TEvent, State<TContext, TEvent, TActor, any>>): State<TContext, TEvent, TActor, TResolvedTypesMeta>;
55
+ transition(state: State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>, event: TEvent, actorCtx: ActorContext<TEvent, typeof state>): State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>;
56
56
  /**
57
57
  * Determines the next state given the current `state` and `event`.
58
58
  * Calculates a microstep.
@@ -60,8 +60,8 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
60
60
  * @param state The current state
61
61
  * @param event The received event
62
62
  */
63
- microstep(state: State<TContext, TEvent, TActor, TResolvedTypesMeta>, event: TEvent, actorCtx: AnyActorContext): Array<State<TContext, TEvent, TActor, TResolvedTypesMeta>>;
64
- getTransitionData(state: State<TContext, TEvent, TActor, TResolvedTypesMeta>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>>;
63
+ microstep(state: State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>, event: TEvent, actorCtx: AnyActorContext): Array<State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>>;
64
+ getTransitionData(state: State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>>;
65
65
  /**
66
66
  * The initial state _before_ evaluating any microsteps.
67
67
  * This "pre-initial" state is provided to initial actions executed in the initial state.
@@ -70,21 +70,24 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
70
70
  /**
71
71
  * Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
72
72
  */
73
- getInitialState(actorCtx: ActorContext<TEvent, State<TContext, TEvent, TActor, TResolvedTypesMeta>>, input?: TInput): State<TContext, TEvent, TActor, TResolvedTypesMeta>;
74
- start(state: State<TContext, TEvent, TActor, TResolvedTypesMeta>): void;
73
+ getInitialState(actorCtx: ActorContext<TEvent, State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>>, input?: TInput): State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>;
74
+ start(state: State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>): void;
75
75
  getStateNodeById(stateId: string): StateNode<TContext, TEvent>;
76
76
  get definition(): StateMachineDefinition<TContext, TEvent>;
77
77
  toJSON(): StateMachineDefinition<TContext, TEvent>;
78
- getPersistedState(state: State<TContext, TEvent, TActor, TResolvedTypesMeta>): PersistedMachineState<State<TContext, TEvent, TActor, TResolvedTypesMeta>>;
79
- createState(stateConfig: State<TContext, TEvent, TActor, TResolvedTypesMeta> | StateConfig<TContext, TEvent>): State<TContext, TEvent, TActor, TResolvedTypesMeta>;
80
- getStatus(state: State<TContext, TEvent, TActor, TResolvedTypesMeta>): {
78
+ getPersistedState(state: State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>): PersistedMachineState<State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>>;
79
+ createState(stateConfig: State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta> | StateConfig<TContext, TEvent>): State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>;
80
+ getStatus(state: State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>): {
81
81
  status: string;
82
- data: any;
82
+ data: {};
83
+ } | {
84
+ status: string;
85
+ data: TOutput | undefined;
83
86
  } | {
84
87
  status: string;
85
88
  data?: undefined;
86
89
  };
87
- restoreState(state: PersistedMachineState<State<TContext, TEvent, TActor, TResolvedTypesMeta>>, _actorCtx: ActorContext<TEvent, State<TContext, TEvent, TActor, TResolvedTypesMeta>>): State<TContext, TEvent, TActor, TResolvedTypesMeta>;
90
+ restoreState(state: PersistedMachineState<State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>>, _actorCtx: ActorContext<TEvent, State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>>): State<TContext, TEvent, TActor, TOutput, TResolvedTypesMeta>;
88
91
  /**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
89
92
  __TContext: TContext;
90
93
  /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
@@ -94,6 +97,9 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
94
97
  /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
95
98
  __TActor: TActor;
96
99
  /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
97
- __TResolvedTypesMeta: TResolvedTypesMeta;
98
100
  __TInput: TInput;
101
+ /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
102
+ __TOutput: TOutput;
103
+ /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
104
+ __TResolvedTypesMeta: TResolvedTypesMeta;
99
105
  }
@@ -1,16 +1,16 @@
1
1
  import type { State } from "./State.js";
2
2
  import type { StateMachine } from "./StateMachine.js";
3
- import type { Action, DelayedTransitionDefinition, EventObject, InitialTransitionDefinition, InvokeDefinition, MachineContext, Mapper, StateNodeConfig, StateNodeDefinition, StateNodesConfig, TransitionDefinition, TransitionDefinitionMap, TODO } from "./types.js";
3
+ import type { DelayedTransitionDefinition, EventObject, InitialTransitionDefinition, InvokeDefinition, MachineContext, Mapper, StateNodeConfig, StateNodeDefinition, StateNodesConfig, TransitionDefinition, TransitionDefinitionMap, TODO, UnknownAction, ParameterizedObject } from "./types.js";
4
4
  interface StateNodeOptions<TContext extends MachineContext, TEvent extends EventObject> {
5
5
  _key: string;
6
6
  _parent?: StateNode<TContext, TEvent>;
7
- _machine: StateMachine<TContext, TEvent, any, any, any>;
7
+ _machine: StateMachine<TContext, TEvent, any, any, any, any>;
8
8
  }
9
9
  export declare class StateNode<TContext extends MachineContext = MachineContext, TEvent extends EventObject = EventObject> {
10
10
  /**
11
11
  * The raw config used to create the machine.
12
12
  */
13
- config: StateNodeConfig<TContext, TEvent, TODO, TODO>;
13
+ config: StateNodeConfig<TContext, TEvent, TODO, TODO, TODO>;
14
14
  /**
15
15
  * The relative key of the state node, which represents its location in the overall state value.
16
16
  */
@@ -47,11 +47,11 @@ export declare class StateNode<TContext extends MachineContext = MachineContext,
47
47
  /**
48
48
  * The action(s) to be executed upon entering the state node.
49
49
  */
50
- entry: Action<any, any, any>[];
50
+ entry: UnknownAction[];
51
51
  /**
52
52
  * The action(s) to be executed upon exiting the state node.
53
53
  */
54
- exit: Action<any, any, any>[];
54
+ exit: UnknownAction[];
55
55
  /**
56
56
  * The parent state node.
57
57
  */
@@ -80,7 +80,7 @@ export declare class StateNode<TContext extends MachineContext = MachineContext,
80
80
  /**
81
81
  * The raw config used to create the machine.
82
82
  */
83
- config: StateNodeConfig<TContext, TEvent, TODO, TODO>, options: StateNodeOptions<TContext, TEvent>);
83
+ config: StateNodeConfig<TContext, TEvent, TODO, TODO, TODO>, options: StateNodeOptions<TContext, TEvent>);
84
84
  _initialize(): void;
85
85
  /**
86
86
  * The well-structured state node definition.
@@ -90,14 +90,14 @@ export declare class StateNode<TContext extends MachineContext = MachineContext,
90
90
  /**
91
91
  * The logic invoked as actors by this state node.
92
92
  */
93
- get invoke(): Array<InvokeDefinition<TContext, TEvent>>;
93
+ get invoke(): Array<InvokeDefinition<TContext, TEvent, ParameterizedObject>>;
94
94
  /**
95
95
  * The mapping of events to transitions.
96
96
  */
97
97
  get on(): TransitionDefinitionMap<TContext, TEvent>;
98
98
  get after(): Array<DelayedTransitionDefinition<TContext, TEvent>>;
99
99
  get initial(): InitialTransitionDefinition<TContext, TEvent>;
100
- next(state: State<TContext, TEvent, TODO>, event: TEvent): TransitionDefinition<TContext, TEvent>[] | undefined;
100
+ next(state: State<TContext, TEvent, TODO, TODO>, event: TEvent): TransitionDefinition<TContext, TEvent>[] | undefined;
101
101
  /**
102
102
  * The target state value of the history state node, if it exists. This represents the
103
103
  * default state value to transition to if no history value exists yet.
@@ -1,16 +1,16 @@
1
- import type { ActionArgs, AnyActorContext, AnyState, Assigner, EventObject, LowInfer, MachineContext, PropertyAssigner } from "../types.js";
2
- declare function resolve(actorContext: AnyActorContext, state: AnyState, actionArgs: ActionArgs<any, any>, { assignment }: {
3
- assignment: Assigner<any, any> | PropertyAssigner<any, any>;
1
+ import type { ActionArgs, AnyActorContext, AnyState, Assigner, EventObject, LowInfer, MachineContext, ParameterizedObject, PropertyAssigner } from "../types.js";
2
+ declare function resolve(actorContext: AnyActorContext, state: AnyState, actionArgs: ActionArgs<any, any, any>, { assignment }: {
3
+ assignment: Assigner<any, any, any> | PropertyAssigner<any, any, any>;
4
4
  }): AnyState[];
5
5
  /**
6
6
  * Updates the current context of the machine.
7
7
  *
8
8
  * @param assignment An object that represents the partial context to update.
9
9
  */
10
- export declare function assign<TContext extends MachineContext, TExpressionEvent extends EventObject = EventObject, TEvent extends EventObject = TExpressionEvent>(assignment: Assigner<LowInfer<TContext>, TExpressionEvent> | PropertyAssigner<LowInfer<TContext>, TExpressionEvent>): {
11
- (_: ActionArgs<TContext, TExpressionEvent>): void;
10
+ export declare function assign<TContext extends MachineContext, TExpressionEvent extends EventObject = EventObject, TExpressionAction extends ParameterizedObject | undefined = ParameterizedObject | undefined>(assignment: Assigner<LowInfer<TContext>, TExpressionEvent, TExpressionAction> | PropertyAssigner<LowInfer<TContext>, TExpressionEvent, TExpressionAction>): {
11
+ (_: ActionArgs<TContext, TExpressionEvent, TExpressionAction>): void;
12
12
  type: string;
13
- assignment: Assigner<LowInfer<TContext>, TExpressionEvent> | PropertyAssigner<LowInfer<TContext>, TExpressionEvent>;
13
+ assignment: Assigner<LowInfer<TContext>, TExpressionEvent, TExpressionAction> | PropertyAssigner<LowInfer<TContext>, TExpressionEvent, TExpressionAction>;
14
14
  resolve: typeof resolve;
15
15
  };
16
16
  export {};
@@ -1,7 +1,7 @@
1
- import { AnyActorContext, AnyState, EventObject, MachineContext, ActionArgs } from "../types.js";
2
- type ResolvableSendId<TContext extends MachineContext, TExpressionEvent extends EventObject> = string | ((args: ActionArgs<TContext, TExpressionEvent>) => string);
3
- declare function resolve(_: AnyActorContext, state: AnyState, actionArgs: ActionArgs<any, any>, { sendId }: {
4
- sendId: ResolvableSendId<any, any>;
1
+ import { AnyActorContext, AnyState, EventObject, MachineContext, ActionArgs, ParameterizedObject } from "../types.js";
2
+ type ResolvableSendId<TContext extends MachineContext, TExpressionEvent extends EventObject, TExpressionAction extends ParameterizedObject | undefined> = string | ((args: ActionArgs<TContext, TExpressionEvent, TExpressionAction>) => string);
3
+ declare function resolve(_: AnyActorContext, state: AnyState, actionArgs: ActionArgs<any, any, any>, { sendId }: {
4
+ sendId: ResolvableSendId<any, any, any>;
5
5
  }): (string | AnyState)[];
6
6
  declare function execute(actorContext: AnyActorContext, resolvedSendId: string): void;
7
7
  /**
@@ -11,10 +11,10 @@ declare function execute(actorContext: AnyActorContext, resolvedSendId: string):
11
11
  *
12
12
  * @param sendId The `id` of the `send(...)` action to cancel.
13
13
  */
14
- export declare function cancel<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject>(sendId: ResolvableSendId<TContext, TExpressionEvent>): {
15
- (_: ActionArgs<TContext, TExpressionEvent>): void;
14
+ export declare function cancel<TContext extends MachineContext, TExpressionEvent extends EventObject, TExpressionAction extends ParameterizedObject | undefined>(sendId: ResolvableSendId<TContext, TExpressionEvent, TExpressionAction>): {
15
+ (_: ActionArgs<TContext, TExpressionEvent, TExpressionAction>): void;
16
16
  type: string;
17
- sendId: ResolvableSendId<TContext, TExpressionEvent>;
17
+ sendId: ResolvableSendId<TContext, TExpressionEvent, TExpressionAction>;
18
18
  resolve: typeof resolve;
19
19
  execute: typeof execute;
20
20
  };
@@ -1,11 +1,5 @@
1
- import { EventObject, ChooseBranch, MachineContext, AnyActorContext, AnyState, ActionArgs } from "../types.js";
2
- declare function resolve(_: AnyActorContext, state: AnyState, actionArgs: ActionArgs<any, any>, { branches }: {
3
- branches: Array<ChooseBranch<MachineContext, EventObject>>;
4
- }): (AnyState | (string | import("../types.js").ParameterizedObject | import("../types.js").ActionFunction<MachineContext, EventObject, EventObject, import("../types.js").ParameterizedObject>)[] | undefined)[];
5
- export declare function choose<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject>(branches: Array<ChooseBranch<TContext, TExpressionEvent>>): {
6
- (_: ActionArgs<TContext, TExpressionEvent>): void;
7
- type: string;
8
- branches: ChooseBranch<TContext, TExpressionEvent, TExpressionEvent>[];
9
- resolve: typeof resolve;
1
+ import { EventObject, ChooseBranch, MachineContext, ActionArgs, ParameterizedObject } from "../types.js";
2
+ export declare function choose<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TExpressionAction extends ParameterizedObject | undefined, TAction extends ParameterizedObject>(branches: ReadonlyArray<ChooseBranch<TContext, TExpressionEvent, TEvent, TAction>>): {
3
+ (args: ActionArgs<TContext, TExpressionEvent, TExpressionAction>): void;
4
+ _out_TAction?: TAction | undefined;
10
5
  };
11
- export {};
@@ -1,7 +1,7 @@
1
- import { ActionArgs, AnyActorContext, AnyState, EventObject, LogExpr, MachineContext } from "../types.js";
2
- type ResolvableLogValue<TContext extends MachineContext, TExpressionEvent extends EventObject> = string | LogExpr<TContext, TExpressionEvent>;
3
- declare function resolve(_: AnyActorContext, state: AnyState, actionArgs: ActionArgs<any, any>, { value, label }: {
4
- value: ResolvableLogValue<any, any>;
1
+ import { ActionArgs, AnyActorContext, AnyState, EventObject, LogExpr, MachineContext, ParameterizedObject } from "../types.js";
2
+ type ResolvableLogValue<TContext extends MachineContext, TExpressionEvent extends EventObject, TExpressionAction extends ParameterizedObject | undefined> = string | LogExpr<TContext, TExpressionEvent, TExpressionAction>;
3
+ declare function resolve(_: AnyActorContext, state: AnyState, actionArgs: ActionArgs<any, any, any>, { value, label }: {
4
+ value: ResolvableLogValue<any, any, any>;
5
5
  label: string | undefined;
6
6
  }): (AnyState | {
7
7
  value: unknown;
@@ -19,10 +19,10 @@ declare function execute({ logger }: AnyActorContext, { value, label }: {
19
19
  * - `event` - the event that caused this action to be executed.
20
20
  * @param label The label to give to the logged expression.
21
21
  */
22
- export declare function log<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(value?: ResolvableLogValue<TContext, TExpressionEvent>, label?: string): {
23
- (_: ActionArgs<TContext, TExpressionEvent>): void;
22
+ export declare function log<TContext extends MachineContext, TExpressionEvent extends EventObject, TExpressionAction extends ParameterizedObject | undefined>(value?: ResolvableLogValue<TContext, TExpressionEvent, TExpressionAction>, label?: string): {
23
+ (_: ActionArgs<TContext, TExpressionEvent, TExpressionAction>): void;
24
24
  type: string;
25
- value: ResolvableLogValue<TContext, TExpressionEvent>;
25
+ value: ResolvableLogValue<TContext, TExpressionEvent, TExpressionAction>;
26
26
  label: string | undefined;
27
27
  resolve: typeof resolve;
28
28
  execute: typeof execute;
@@ -1,20 +1,8 @@
1
- import { Action, ActionArgs, AnyActorContext, AnyState, EventObject, MachineContext, SingleOrArray } from "../types.js";
2
- declare function resolve(_: AnyActorContext, state: AnyState, args: ActionArgs<any, any>, { get }: {
3
- get: ({ context, event }: {
4
- context: MachineContext;
5
- event: EventObject;
6
- }) => SingleOrArray<Action<any, any, any>> | undefined;
7
- }): (AnyState | (string | import("../types.js").ParameterizedObject | import("../types.js").ActionFunction<any, any, any, import("../types.js").ParameterizedObject>)[] | undefined)[];
8
- export declare function pure<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(getActions: ({ context, event }: {
1
+ import { Actions, ActionArgs, EventObject, MachineContext, ParameterizedObject } from "../types.js";
2
+ export declare function pure<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent, TExpressionAction extends ParameterizedObject | undefined = ParameterizedObject | undefined, TAction extends ParameterizedObject = ParameterizedObject>(getActions: ({ context, event }: {
9
3
  context: TContext;
10
4
  event: TExpressionEvent;
11
- }) => SingleOrArray<Action<TContext, TExpressionEvent> | string> | undefined): {
12
- (_: ActionArgs<TContext, TExpressionEvent>): void;
13
- type: string;
14
- get: ({ context, event }: {
15
- context: TContext;
16
- event: TExpressionEvent;
17
- }) => SingleOrArray<Action<TContext, TExpressionEvent> | string> | undefined;
18
- resolve: typeof resolve;
5
+ }) => Actions<TContext, TExpressionEvent, TEvent, undefined, TAction> | undefined): {
6
+ (args: ActionArgs<TContext, TExpressionEvent, TExpressionAction>): void;
7
+ _out_TAction?: TAction | undefined;
19
8
  };
20
- export {};
@@ -1,11 +1,11 @@
1
- import { ActionArgs, EventObject, MachineContext, NoInfer, RaiseActionOptions, SendExpr } from "../types.js";
1
+ import { ActionArgs, EventObject, MachineContext, NoInfer, RaiseActionOptions, SendExpr, ParameterizedObject } from "../types.js";
2
2
  /**
3
3
  * Raises an event. This places the event in the internal event queue, so that
4
4
  * the event is immediately consumed by the machine in the current step.
5
5
  *
6
6
  * @param eventType The event to raise.
7
7
  */
8
- export declare function raise<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent>(eventOrExpr: NoInfer<TEvent> | SendExpr<TContext, TExpressionEvent, NoInfer<TEvent>>, options?: RaiseActionOptions<TContext, TExpressionEvent>): {
9
- (args: ActionArgs<TContext, TExpressionEvent>): void;
8
+ export declare function raise<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent, TExpressionAction extends ParameterizedObject | undefined = ParameterizedObject | undefined>(eventOrExpr: NoInfer<TEvent> | SendExpr<TContext, TExpressionEvent, TExpressionAction, NoInfer<TEvent>>, options?: RaiseActionOptions<TContext, TExpressionEvent, TExpressionAction>): {
9
+ (args: ActionArgs<TContext, TExpressionEvent, TExpressionAction>): void;
10
10
  _out_TEvent?: TEvent | undefined;
11
11
  };