xstate 4.27.0-pr2674-2021926101023 → 4.29.0

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 (65) hide show
  1. package/CHANGELOG.md +210 -94
  2. package/README.md +5 -5
  3. package/dist/xstate.interpreter.js +1 -1
  4. package/dist/xstate.js +1 -1
  5. package/dist/xstate.web.js +2 -2
  6. package/es/Actor.js +5 -5
  7. package/es/Machine.d.ts +4 -4
  8. package/es/State.d.ts +9 -6
  9. package/es/State.js +10 -3
  10. package/es/StateNode.d.ts +12 -11
  11. package/es/StateNode.js +61 -71
  12. package/es/_virtual/_tslib.js +8 -4
  13. package/es/actions.d.ts +18 -2
  14. package/es/actions.js +22 -8
  15. package/es/devTools.d.ts +4 -6
  16. package/es/devTools.js +4 -0
  17. package/es/index.d.ts +9 -3
  18. package/es/index.js +3 -2
  19. package/es/interpreter.d.ts +6 -10
  20. package/es/interpreter.js +40 -27
  21. package/es/model.types.d.ts +3 -3
  22. package/es/registry.js +1 -1
  23. package/es/schema.d.ts +1 -0
  24. package/es/schema.js +2 -1
  25. package/es/scxml.d.ts +1 -1
  26. package/es/stateUtils.d.ts +4 -4
  27. package/es/stateUtils.js +1 -1
  28. package/es/typegenTypes.d.ts +66 -37
  29. package/es/types.d.ts +42 -41
  30. package/es/utils.d.ts +6 -1
  31. package/es/utils.js +17 -10
  32. package/lib/Actor.js +4 -4
  33. package/lib/Machine.d.ts +4 -4
  34. package/lib/SimulatedClock.js +9 -5
  35. package/lib/State.d.ts +9 -6
  36. package/lib/State.js +10 -3
  37. package/lib/StateNode.d.ts +12 -11
  38. package/lib/StateNode.js +59 -69
  39. package/lib/_virtual/_tslib.js +8 -4
  40. package/lib/actions.d.ts +18 -2
  41. package/lib/actions.js +22 -7
  42. package/lib/devTools.d.ts +4 -6
  43. package/lib/devTools.js +4 -0
  44. package/lib/index.d.ts +9 -3
  45. package/lib/index.js +2 -0
  46. package/lib/interpreter.d.ts +6 -10
  47. package/lib/interpreter.js +38 -25
  48. package/lib/json.js +7 -7
  49. package/lib/model.js +14 -10
  50. package/lib/model.types.d.ts +3 -3
  51. package/lib/patterns.js +2 -2
  52. package/lib/registry.js +1 -1
  53. package/lib/schema.d.ts +1 -0
  54. package/lib/schema.js +2 -0
  55. package/lib/scxml.d.ts +1 -1
  56. package/lib/scxml.js +29 -25
  57. package/lib/stateUtils.d.ts +4 -4
  58. package/lib/stateUtils.js +1 -1
  59. package/lib/typegenTypes.d.ts +66 -37
  60. package/lib/types.d.ts +42 -41
  61. package/lib/utils.d.ts +6 -1
  62. package/lib/utils.js +18 -9
  63. package/package.json +7 -11
  64. package/dist/xstate.cjs.d.ts +0 -11
  65. package/dist/xstate.cjs.js +0 -16
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { StateMachine, Event, EventObject, DefaultContext, StateSchema, StateValue, InterpreterOptions, SingleOrArray, Subscribable, DoneEvent, MachineOptions, SCXML, EventData, Observer, Spawnable, Typestate, ActorRef, ActorRefFrom, Behavior, Subscription } from './types';
2
3
  import { State } from './State';
3
4
  import { AreAllImplementationsAssumedToBeProvided, TypegenDisabled } from './typegenTypes';
@@ -22,16 +23,11 @@ export declare enum InterpreterStatus {
22
23
  Running = 1,
23
24
  Stopped = 2
24
25
  }
25
- declare global {
26
- interface SymbolConstructor {
27
- readonly observable: symbol;
28
- }
29
- }
30
26
  export declare class Interpreter<TContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
31
27
  value: any;
32
28
  context: TContext;
33
29
  }, TResolvedTypesMeta = TypegenDisabled> implements ActorRef<TEvent, State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>> {
34
- machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, TResolvedTypesMeta>;
30
+ machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta>;
35
31
  /**
36
32
  * The default interpreter options:
37
33
  *
@@ -42,7 +38,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
42
38
  execute: boolean;
43
39
  deferEvents: boolean;
44
40
  clock: {
45
- setTimeout: (fn: any, ms: any) => number;
41
+ setTimeout: (fn: any, ms: any) => NodeJS.Timeout;
46
42
  clearTimeout: (id: any) => void;
47
43
  };
48
44
  logger: any;
@@ -87,7 +83,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
87
83
  * @param machine The machine to be interpreted
88
84
  * @param options Interpreter options
89
85
  */
90
- constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, TResolvedTypesMeta>, options?: InterpreterOptions);
86
+ constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta>, options?: InterpreterOptions);
91
87
  get initialState(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
92
88
  get state(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
93
89
  static interpret: typeof interpret;
@@ -200,7 +196,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
200
196
  getSnapshot(): State<TContext, TEvent, TStateSchema, TTypestate, TResolvedTypesMeta>;
201
197
  }
202
198
  export declare function spawn<T extends Behavior<any, any>>(entity: T, nameOrOptions?: string | SpawnOptions): ActorRefFrom<T>;
203
- export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE>>;
199
+ export declare function spawn<TC, TE extends EventObject>(entity: StateMachine<TC, any, TE, any, any, any, any>, nameOrOptions?: string | SpawnOptions): ActorRefFrom<StateMachine<TC, any, TE, any, any, any, any>>;
204
200
  export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnOptions): ActorRef<any>;
205
201
  /**
206
202
  * Creates a new Interpreter instance for the given machine with the provided options, if any.
@@ -211,6 +207,6 @@ export declare function spawn(entity: Spawnable, nameOrOptions?: string | SpawnO
211
207
  export declare function interpret<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = EventObject, TTypestate extends Typestate<TContext> = {
212
208
  value: any;
213
209
  context: TContext;
214
- }, TResolvedTypesMeta = TypegenDisabled>(machine: AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends true ? StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, TResolvedTypesMeta> : 'Some implementations missing', options?: InterpreterOptions): Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
210
+ }, TResolvedTypesMeta = TypegenDisabled>(machine: AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends true ? StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, any, TResolvedTypesMeta> : 'Some implementations missing', options?: InterpreterOptions): Interpreter<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>;
215
211
  export {};
216
212
  //# sourceMappingURL=interpreter.d.ts.map
package/es/interpreter.js CHANGED
@@ -1,6 +1,6 @@
1
- import { __values, __assign, __spreadArray, __read } from './_virtual/_tslib.js';
1
+ import { __values, __spreadArray, __read, __assign } from './_virtual/_tslib.js';
2
2
  import { IS_PRODUCTION } from './environment.js';
3
- import { warn, mapContext, isFunction, keys, toSCXMLEvent, toInvokeSource, isMachine, isPromiseLike, isObservable, isBehavior, reportUnhandledExceptionOnInvocation, symbolObservable, isArray, toEventObject, isString, isActor, uniqueId, toObserver } from './utils.js';
3
+ import { warn, mapContext, isFunction, keys, toSCXMLEvent, toInvokeSource, isMachine, isPromiseLike, isObservable, isBehavior, reportUnhandledExceptionOnInvocation, interopSymbols, symbolObservable, isArray, toEventObject, isString, isActor, toObserver, uniqueId } from './utils.js';
4
4
  import { ActionTypes, SpecialTargets } from './types.js';
5
5
  import { isInFinalState } from './stateUtils.js';
6
6
  import { errorPlatform, log, stop, start, cancel, send, update, error as error$1 } from './actionTypes.js';
@@ -87,14 +87,15 @@ function () {
87
87
  if (_this.status === InterpreterStatus.Stopped) {
88
88
  // do nothing
89
89
  if (!IS_PRODUCTION) {
90
- warn(false, "Event \"" + _event.name + "\" was sent to stopped service \"" + _this.machine.id + "\". This service has already reached its final state, and will not transition.\nEvent: " + JSON.stringify(_event.data));
90
+ warn(false, "Event \"".concat(_event.name, "\" was sent to stopped service \"").concat(_this.machine.id, "\". This service has already reached its final state, and will not transition.\nEvent: ").concat(JSON.stringify(_event.data)));
91
91
  }
92
92
 
93
93
  return _this.state;
94
94
  }
95
95
 
96
96
  if (_this.status !== InterpreterStatus.Running && !_this.options.deferEvents) {
97
- throw new Error("Event \"" + _event.name + "\" was sent to uninitialized service \"" + _this.machine.id + "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: " + JSON.stringify(_event.data));
97
+ throw new Error("Event \"".concat(_event.name, "\" was sent to uninitialized service \"").concat(_this.machine.id // tslint:disable-next-line:max-line-length
98
+ , "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ").concat(JSON.stringify(_event.data)));
98
99
  }
99
100
 
100
101
  _this.scheduler.schedule(function () {
@@ -116,12 +117,12 @@ function () {
116
117
 
117
118
  if (!target) {
118
119
  if (!isParent) {
119
- throw new Error("Unable to send event to child '" + to + "' from service '" + _this.id + "'.");
120
+ throw new Error("Unable to send event to child '".concat(to, "' from service '").concat(_this.id, "'."));
120
121
  } // tslint:disable-next-line:no-console
121
122
 
122
123
 
123
124
  if (!IS_PRODUCTION) {
124
- warn(false, "Service '" + _this.id + "' has no parent: unable to send event " + event.type);
125
+ warn(false, "Service '".concat(_this.id, "' has no parent: unable to send event ").concat(event.type));
125
126
  }
126
127
 
127
128
  return;
@@ -130,7 +131,7 @@ function () {
130
131
  if ('machine' in target) {
131
132
  // Send SCXML events to machines
132
133
  target.send(__assign(__assign({}, event), {
133
- name: event.name === error$1 ? "" + error(_this.id) : event.name,
134
+ name: event.name === error$1 ? "".concat(error(_this.id)) : event.name,
134
135
  origin: _this.sessionId
135
136
  }));
136
137
  } else {
@@ -176,7 +177,7 @@ function () {
176
177
  Object.defineProperty(Interpreter.prototype, "state", {
177
178
  get: function () {
178
179
  if (!IS_PRODUCTION) {
179
- warn(this.status !== InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '" + this.id + "'. Make sure the service is started first.");
180
+ warn(this.status !== InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '".concat(this.id, "'. Make sure the service is started first."));
180
181
  }
181
182
 
182
183
  return this._state;
@@ -557,7 +558,9 @@ function () {
557
558
  return this;
558
559
  }
559
560
 
560
- this.state.configuration.forEach(function (stateNode) {
561
+ __spreadArray([], __read(this.state.configuration), false).sort(function (a, b) {
562
+ return b.order - a.order;
563
+ }).forEach(function (stateNode) {
561
564
  var e_11, _a;
562
565
 
563
566
  try {
@@ -579,6 +582,7 @@ function () {
579
582
  }
580
583
  }); // Stop all children
581
584
 
585
+
582
586
  this.children.forEach(function (child) {
583
587
  if (isFunction(child.stop)) {
584
588
  child.stop();
@@ -616,11 +620,11 @@ function () {
616
620
  if (this.status === InterpreterStatus.NotStarted && this.options.deferEvents) {
617
621
  // tslint:disable-next-line:no-console
618
622
  if (!IS_PRODUCTION) {
619
- warn(false, events.length + " event(s) were sent to uninitialized service \"" + this.machine.id + "\" and are deferred. Make sure .start() is called for this service.\nEvent: " + JSON.stringify(event));
623
+ warn(false, "".concat(events.length, " event(s) were sent to uninitialized service \"").concat(this.machine.id, "\" and are deferred. Make sure .start() is called for this service.\nEvent: ").concat(JSON.stringify(event)));
620
624
  }
621
625
  } else if (this.status !== InterpreterStatus.Running) {
622
626
  throw new Error( // tslint:disable-next-line:max-line-length
623
- events.length + " event(s) were sent to uninitialized service \"" + this.machine.id + "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.");
627
+ "".concat(events.length, " event(s) were sent to uninitialized service \"").concat(this.machine.id, "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options."));
624
628
  }
625
629
 
626
630
  this.scheduler.schedule(function () {
@@ -640,7 +644,7 @@ function () {
640
644
  });
641
645
  batchedActions.push.apply(batchedActions, __spreadArray([], __read(nextState.actions.map(function (a) {
642
646
  return bindActionToState(a, nextState);
643
- }))));
647
+ })), false));
644
648
  batchChanged = batchChanged || !!nextState.changed;
645
649
  };
646
650
 
@@ -713,7 +717,7 @@ function () {
713
717
  var child = this.children.get(id);
714
718
 
715
719
  if (!child) {
716
- throw new Error("Unable to forward event '" + event + "' from interpreter '" + this.id + "' to nonexistant child '" + id + "'.");
720
+ throw new Error("Unable to forward event '".concat(event, "' from interpreter '").concat(this.id, "' to nonexistant child '").concat(id, "'."));
717
721
  }
718
722
 
719
723
  child.send(event);
@@ -800,6 +804,10 @@ function () {
800
804
 
801
805
  case start:
802
806
  {
807
+ if (this.status !== InterpreterStatus.Running) {
808
+ return;
809
+ }
810
+
803
811
  var activity = action.activity; // If the activity will be stopped right after it's started
804
812
  // (such as in transient states)
805
813
  // don't bother starting the activity.
@@ -817,7 +825,7 @@ function () {
817
825
 
818
826
  if (!IS_PRODUCTION) {
819
827
  warn(!('forward' in activity), // tslint:disable-next-line:max-line-length
820
- "`forward` property is deprecated (found in invocation of '" + activity.src + "' in in machine '" + this.machine.id + "'). " + "Please use `autoForward` instead.");
828
+ "`forward` property is deprecated (found in invocation of '".concat(activity.src, "' in in machine '").concat(this.machine.id, "'). ") + "Please use `autoForward` instead.");
821
829
  }
822
830
 
823
831
  var autoForward = 'autoForward' in activity ? activity.autoForward : !!activity.forward;
@@ -825,7 +833,7 @@ function () {
825
833
  if (!serviceCreator) {
826
834
  // tslint:disable-next-line:no-console
827
835
  if (!IS_PRODUCTION) {
828
- warn(false, "No service found for invocation '" + activity.src + "' in machine '" + this.machine.id + "'.");
836
+ warn(false, "No service found for invocation '".concat(activity.src, "' in machine '").concat(this.machine.id, "'."));
829
837
  }
830
838
 
831
839
  return;
@@ -886,7 +894,7 @@ function () {
886
894
 
887
895
  default:
888
896
  if (!IS_PRODUCTION) {
889
- warn(false, "No implementation found for action type '" + action.type + "'");
897
+ warn(false, "No implementation found for action type '".concat(action.type, "'"));
890
898
  }
891
899
 
892
900
  break;
@@ -935,7 +943,7 @@ function () {
935
943
  } else if (isBehavior(entity)) {
936
944
  return this.spawnBehavior(entity, name);
937
945
  } else {
938
- throw new Error("Unable to spawn entity \"" + name + "\" of type \"" + typeof entity + "\".");
946
+ throw new Error("Unable to spawn entity \"".concat(name, "\" of type \"").concat(typeof entity, "\"."));
939
947
  }
940
948
  };
941
949
 
@@ -1031,7 +1039,8 @@ function () {
1031
1039
  }
1032
1040
  }
1033
1041
  });
1034
- var actor = {
1042
+
1043
+ var actor = __assign({
1035
1044
  id: id,
1036
1045
  send: function () {
1037
1046
  return void 0;
@@ -1075,7 +1084,8 @@ function () {
1075
1084
  getSnapshot: function () {
1076
1085
  return resolvedData;
1077
1086
  }
1078
- };
1087
+ }, interopSymbols);
1088
+
1079
1089
  this.children.set(id, actor);
1080
1090
  return actor;
1081
1091
  };
@@ -1119,7 +1129,7 @@ function () {
1119
1129
  return this.spawnPromise(callbackStop, id);
1120
1130
  }
1121
1131
 
1122
- var actor = {
1132
+ var actor = __assign({
1123
1133
  id: id,
1124
1134
  send: function (event) {
1125
1135
  return receivers.forEach(function (receiver) {
@@ -1149,7 +1159,8 @@ function () {
1149
1159
  getSnapshot: function () {
1150
1160
  return emitted;
1151
1161
  }
1152
- };
1162
+ }, interopSymbols);
1163
+
1153
1164
  this.children.set(id, actor);
1154
1165
  return actor;
1155
1166
  };
@@ -1177,7 +1188,8 @@ function () {
1177
1188
  origin: id
1178
1189
  }));
1179
1190
  });
1180
- var actor = {
1191
+
1192
+ var actor = __assign({
1181
1193
  id: id,
1182
1194
  send: function () {
1183
1195
  return void 0;
@@ -1196,7 +1208,8 @@ function () {
1196
1208
  id: id
1197
1209
  };
1198
1210
  }
1199
- };
1211
+ }, interopSymbols);
1212
+
1200
1213
  this.children.set(id, actor);
1201
1214
  return actor;
1202
1215
  };
@@ -1211,7 +1224,7 @@ function () {
1211
1224
 
1212
1225
  if (!implementation) {
1213
1226
  if (!IS_PRODUCTION) {
1214
- warn(false, "No implementation found for activity '" + activity.type + "'");
1227
+ warn(false, "No implementation found for activity '".concat(activity.type, "'"));
1215
1228
  } // tslint:disable-next-line:no-console
1216
1229
 
1217
1230
 
@@ -1224,7 +1237,7 @@ function () {
1224
1237
  };
1225
1238
 
1226
1239
  Interpreter.prototype.spawnEffect = function (id, dispose) {
1227
- this.children.set(id, {
1240
+ this.children.set(id, __assign({
1228
1241
  id: id,
1229
1242
  send: function () {
1230
1243
  return void 0;
@@ -1245,7 +1258,7 @@ function () {
1245
1258
  id: id
1246
1259
  };
1247
1260
  }
1248
- });
1261
+ }, interopSymbols));
1249
1262
  };
1250
1263
 
1251
1264
  Interpreter.prototype.attachDev = function () {
@@ -1343,7 +1356,7 @@ function spawn(entity, nameOrOptions) {
1343
1356
  return consume(function (service) {
1344
1357
  if (!IS_PRODUCTION) {
1345
1358
  var isLazyEntity = isMachine(entity) || isFunction(entity);
1346
- warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \"" + (isMachine(entity) ? entity.id : 'undefined') + "\") outside of a service. This will have no effect.");
1359
+ warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \"".concat(isMachine(entity) ? entity.id : 'undefined', "\") outside of a service. This will have no effect."));
1347
1360
  }
1348
1361
 
1349
1362
  if (service) {
@@ -1,4 +1,4 @@
1
- import { AnyFunction, AssignAction, Assigner, BaseActionObject, Compute, EventObject, ExtractEvent, MachineConfig, Prop, PropertyAssigner, StateMachine, InternalMachineOptions } from './types';
1
+ import { AnyFunction, AssignAction, Assigner, BaseActionObject, Compute, EventObject, ExtractEvent, MachineConfig, Prop, PropertyAssigner, StateMachine, InternalMachineOptions, ServiceMap } from './types';
2
2
  import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from './typegenTypes';
3
3
  export interface Model<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TModelCreators = void> {
4
4
  initialContext: TContext;
@@ -7,10 +7,10 @@ export interface Model<TContext, TEvent extends EventObject, TAction extends Bas
7
7
  actions: Prop<TModelCreators, 'actions'>;
8
8
  reset: () => AssignAction<TContext, any>;
9
9
  createMachine: {
10
- <TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, TAction, TTypesMeta>, implementations?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction>>): StateMachine<TContext, any, TEvent, {
10
+ <TServiceMap extends ServiceMap = ServiceMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, any, TEvent, TAction, TServiceMap, TTypesMeta>, implementations?: InternalMachineOptions<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>): StateMachine<TContext, any, TEvent, {
11
11
  value: any;
12
12
  context: TContext;
13
- }, TAction, ResolveTypegenMeta<TTypesMeta, TEvent, TAction>>;
13
+ }, TAction, TServiceMap, ResolveTypegenMeta<TTypesMeta, TEvent, TAction, TServiceMap>>;
14
14
  };
15
15
  }
16
16
  export declare type ModelContextFrom<TModel extends Model<any, any, any, any>> = TModel extends Model<infer TContext, any, any, any> ? TContext : never;
package/es/registry.js CHANGED
@@ -2,7 +2,7 @@ var children = /*#__PURE__*/new Map();
2
2
  var sessionIdIndex = 0;
3
3
  var registry = {
4
4
  bookId: function () {
5
- return "x:" + sessionIdIndex++;
5
+ return "x:".concat(sessionIdIndex++);
6
6
  },
7
7
  register: function (id, actor) {
8
8
  children.set(id, actor);
package/es/schema.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare function createSchema<T>(schema?: any): T;
2
+ export declare const t: typeof createSchema;
2
3
  //# sourceMappingURL=schema.d.ts.map
package/es/schema.js CHANGED
@@ -1,5 +1,6 @@
1
1
  function createSchema(schema) {
2
2
  return schema;
3
3
  }
4
+ var t = createSchema;
4
5
 
5
- export { createSchema };
6
+ export { createSchema, t };
package/es/scxml.d.ts CHANGED
@@ -2,5 +2,5 @@ import { StateMachine } from './index';
2
2
  export interface ScxmlToMachineOptions {
3
3
  delimiter?: string;
4
4
  }
5
- export declare function toMachine(xml: string, options: ScxmlToMachineOptions): StateMachine<any, any, any>;
5
+ export declare function toMachine(xml: string, options: ScxmlToMachineOptions): StateMachine<any, any, any, any, any, any, any>;
6
6
  //# sourceMappingURL=scxml.d.ts.map
@@ -2,15 +2,15 @@ import { EventObject, StateValue } from './types';
2
2
  import { StateNode } from './StateNode';
3
3
  declare type Configuration<TC, TE extends EventObject> = Iterable<StateNode<TC, any, TE>>;
4
4
  declare type AdjList<TC, TE extends EventObject> = Map<StateNode<TC, any, TE>, Array<StateNode<TC, any, TE>>>;
5
- export declare const isLeafNode: (stateNode: StateNode<any, any, any, any, any>) => boolean;
5
+ export declare const isLeafNode: (stateNode: StateNode<any, any, any, any, any, any>) => boolean;
6
6
  export declare function getChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
7
- export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any, any>): Array<StateNode<TC, any, TE, any, any>>;
8
- export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any, any>>): Iterable<StateNode<TC, any, TE, any, any>>;
7
+ export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any, any, any>): Array<StateNode<TC, any, TE, any, any, any>>;
8
+ export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any, any, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any, any, any>>): Set<StateNode<TC, any, TE, any, any, any>>;
9
9
  export declare function getAdjList<TC, TE extends EventObject>(configuration: Configuration<TC, TE>): AdjList<TC, TE>;
10
10
  export declare function getValue<TC, TE extends EventObject>(rootNode: StateNode<TC, any, TE, any>, configuration: Configuration<TC, TE>): StateValue;
11
11
  export declare function has<T>(iterable: Iterable<T>, item: T): boolean;
12
12
  export declare function nextEvents<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE>>): Array<TE['type']>;
13
- export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any, any>>, stateNode: StateNode<TC, any, TE, any, any>): boolean;
13
+ export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any, any, any>>, stateNode: StateNode<TC, any, TE, any, any, any>): boolean;
14
14
  export declare function getMeta(configuration?: StateNode[]): Record<string, any>;
15
15
  export declare function getTagsFromConfiguration(configuration: StateNode<any, any, any, any>[]): Set<string>;
16
16
  export {};
package/es/stateUtils.js CHANGED
@@ -222,7 +222,7 @@ function has(iterable, item) {
222
222
  function nextEvents(configuration) {
223
223
  return __spreadArray([], __read(new Set(flatten(__spreadArray([], __read(configuration.map(function (sn) {
224
224
  return sn.ownEvents;
225
- })))))));
225
+ })), false)))), false);
226
226
  }
227
227
  function isInFinalState(configuration, stateNode) {
228
228
  if (stateNode.type === 'compound') {
@@ -1,4 +1,4 @@
1
- import { ActionObject, ActionFunction, Cast, ConditionPredicate, BaseActionObject, DelayConfig, EventObject, InvokeCreator, IndexByType, IsNever, MachineOptions, Prop, Values } from './types';
1
+ import { BaseActionObject, EventObject, IndexByType, IsNever, Prop, Values, IsAny, ServiceMap, Cast } from './types';
2
2
  export interface TypegenDisabled {
3
3
  '@@xstate/typegen': false;
4
4
  }
@@ -6,19 +6,74 @@ export interface TypegenEnabled {
6
6
  '@@xstate/typegen': true;
7
7
  }
8
8
  export interface TypegenMeta extends TypegenEnabled {
9
- matchesStates: string;
9
+ /**
10
+ * Allows you to specify all the results of state.matches
11
+ */
12
+ matchesStates: string | {};
13
+ /**
14
+ * Allows you to specify all tags used by the machine
15
+ */
10
16
  tags: string;
17
+ /**
18
+ * Allows you to specify all the missing implementations
19
+ * of the machine
20
+ */
11
21
  missingImplementations: {
12
22
  actions: string;
13
23
  delays: string;
14
24
  guards: string;
15
25
  services: string;
16
26
  };
27
+ /**
28
+ * A map for the internal events of the machine.
29
+ *
30
+ * key: 'done.invoke.myService'
31
+ * value: {
32
+ * type: 'done.invoke.myService';
33
+ * data: unknown;
34
+ * __tip: 'Declare the type in event types!';
35
+ * }
36
+ */
17
37
  internalEvents: {};
38
+ /**
39
+ * Maps the name of the service to the event type
40
+ * of the done.invoke action
41
+ *
42
+ * key: 'invokeSrc'
43
+ * value: 'done.invoke.invokeName'
44
+ */
18
45
  invokeSrcNameMap: Record<string, string>;
46
+ /**
47
+ * Keeps track of which events lead to which
48
+ * actions.
49
+ *
50
+ * Key: 'EVENT_NAME'
51
+ * Value: 'actionName' | 'otherActionName'
52
+ */
19
53
  eventsCausingActions: Record<string, string>;
54
+ /**
55
+ * Keeps track of which events lead to which
56
+ * delays.
57
+ *
58
+ * Key: 'EVENT_NAME'
59
+ * Value: 'delayName' | 'otherDelayName'
60
+ */
20
61
  eventsCausingDelays: Record<string, string>;
62
+ /**
63
+ * Keeps track of which events lead to which
64
+ * guards.
65
+ *
66
+ * Key: 'EVENT_NAME'
67
+ * Value: 'guardName' | 'otherGuardName'
68
+ */
21
69
  eventsCausingGuards: Record<string, string>;
70
+ /**
71
+ * Keeps track of which events lead to which
72
+ * services.
73
+ *
74
+ * Key: 'EVENT_NAME'
75
+ * Value: 'serviceName' | 'otherServiceName'
76
+ */
22
77
  eventsCausingServices: Record<string, string>;
23
78
  }
24
79
  export interface ResolvedTypegenMeta extends TypegenMeta {
@@ -26,7 +81,7 @@ export interface ResolvedTypegenMeta extends TypegenMeta {
26
81
  indexedEvents: Record<string, EventObject>;
27
82
  }
28
83
  export declare type TypegenConstraint = TypegenEnabled | TypegenDisabled;
29
- export declare type AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta, TMissingImplementations = Prop<TResolvedTypesMeta, 'missingImplementations'>> = TResolvedTypesMeta extends TypegenEnabled ? IsNever<Values<{
84
+ export declare type AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta, TMissingImplementations = Prop<TResolvedTypesMeta, 'missingImplementations'>> = IsAny<TResolvedTypesMeta> extends true ? true : TResolvedTypesMeta extends TypegenEnabled ? IsNever<Values<{
30
85
  [K in keyof TMissingImplementations]: TMissingImplementations[K];
31
86
  }>> extends true ? true : false : true;
32
87
  export declare type MarkAllImplementationsAsProvided<TResolvedTypesMeta> = TResolvedTypesMeta & {
@@ -37,6 +92,12 @@ export declare type MarkAllImplementationsAsProvided<TResolvedTypesMeta> = TReso
37
92
  services: never;
38
93
  };
39
94
  };
95
+ declare type GenerateServiceEvent<TServiceName, TEventType, TServiceMap extends ServiceMap> = TEventType extends any ? {
96
+ type: TEventType;
97
+ } & Prop<TServiceMap, TServiceName> : never;
98
+ declare type GenerateServiceEvents<TServiceMap extends ServiceMap, TInvokeSrcNameMap> = string extends keyof TServiceMap ? never : Cast<{
99
+ [K in keyof TInvokeSrcNameMap]: GenerateServiceEvent<K, TInvokeSrcNameMap[K], TServiceMap>;
100
+ }[keyof TInvokeSrcNameMap], EventObject>;
40
101
  declare type MergeWithInternalEvents<TIndexedEvents, TInternalEvents> = TIndexedEvents & Pick<TInternalEvents, Exclude<keyof TInternalEvents, keyof TIndexedEvents>>;
41
102
  declare type AllowAllEvents = {
42
103
  eventsCausingActions: Record<string, string>;
@@ -44,9 +105,9 @@ declare type AllowAllEvents = {
44
105
  eventsCausingGuards: Record<string, string>;
45
106
  eventsCausingServices: Record<string, string>;
46
107
  };
47
- export declare type ResolveTypegenMeta<TTypesMeta extends TypegenConstraint, TEvent extends EventObject, TAction extends BaseActionObject> = TTypesMeta extends TypegenEnabled ? TTypesMeta & {
108
+ export declare type ResolveTypegenMeta<TTypesMeta extends TypegenConstraint, TEvent extends EventObject, TAction extends BaseActionObject, TServiceMap extends ServiceMap> = TTypesMeta extends TypegenEnabled ? TTypesMeta & {
48
109
  indexedActions: IndexByType<TAction>;
49
- indexedEvents: MergeWithInternalEvents<IndexByType<TEvent>, Prop<TTypesMeta, 'internalEvents'>>;
110
+ indexedEvents: MergeWithInternalEvents<IndexByType<(string extends TEvent['type'] ? never : TEvent) | GenerateServiceEvents<TServiceMap, Prop<TTypesMeta, 'invokeSrcNameMap'>>>, Prop<TTypesMeta, 'internalEvents'>>;
50
111
  } : MarkAllImplementationsAsProvided<TypegenDisabled> & AllowAllEvents & {
51
112
  indexedActions: IndexByType<TAction>;
52
113
  indexedEvents: Record<string, TEvent> & {
@@ -56,37 +117,5 @@ export declare type ResolveTypegenMeta<TTypesMeta extends TypegenConstraint, TEv
56
117
  };
57
118
  invokeSrcNameMap: Record<string, '__XSTATE_ALLOW_ANY_INVOKE_DATA_HACK__'>;
58
119
  };
59
- export declare type TypegenMachineOptionsActions<TContext, TResolvedTypesMeta, TEventsCausingActions = Prop<TResolvedTypesMeta, 'eventsCausingActions'>, TIndexedEvents = Prop<TResolvedTypesMeta, 'indexedEvents'>, TIndexedActions = Prop<TResolvedTypesMeta, 'indexedActions'>> = {
60
- [K in keyof TEventsCausingActions]?: ActionObject<TContext, Cast<Prop<TIndexedEvents, TEventsCausingActions[K]>, EventObject>> | ActionFunction<TContext, Cast<Prop<TIndexedEvents, TEventsCausingActions[K]>, EventObject>, Cast<Prop<TIndexedActions, K>, BaseActionObject>>;
61
- };
62
- export declare type TypegenMachineOptionsDelays<TContext, TResolvedTypesMeta, TEventsCausingDelays = Prop<TResolvedTypesMeta, 'eventsCausingDelays'>, TIndexedEvents = Prop<TResolvedTypesMeta, 'indexedEvents'>> = {
63
- [K in keyof TEventsCausingDelays]?: DelayConfig<TContext, Cast<Prop<TIndexedEvents, TEventsCausingDelays[K]>, EventObject>>;
64
- };
65
- export declare type TypegenMachineOptionsGuards<TContext, TResolvedTypesMeta, TEventsCausingGuards = Prop<TResolvedTypesMeta, 'eventsCausingGuards'>, TIndexedEvents = Prop<TResolvedTypesMeta, 'indexedEvents'>> = {
66
- [K in keyof TEventsCausingGuards]?: ConditionPredicate<TContext, Cast<Prop<TIndexedEvents, TEventsCausingGuards[K]>, EventObject>>;
67
- };
68
- export declare type TypegenMachineOptionsServices<TContext, TResolvedTypesMeta, TEventsCausingServices = Prop<TResolvedTypesMeta, 'eventsCausingServices'>, TIndexedEvents = Prop<TResolvedTypesMeta, 'indexedEvents'>, TInvokeSrcNameMap = Prop<TResolvedTypesMeta, 'invokeSrcNameMap'>> = {
69
- [K in keyof TEventsCausingServices]?: InvokeCreator<TContext, Cast<Prop<TIndexedEvents, TEventsCausingServices[K]>, EventObject>, Prop<Prop<TIndexedEvents, Prop<TInvokeSrcNameMap, K>>, 'data'>>;
70
- };
71
- declare type MakeKeysRequired<T extends string> = {
72
- [K in T]: unknown;
73
- };
74
- declare type MaybeMakeMissingImplementationsRequired<TImplementationType, TMissingImplementationsForType, TRequireMissingImplementations> = TRequireMissingImplementations extends true ? IsNever<TMissingImplementationsForType> extends true ? {} : {
75
- [K in Cast<TImplementationType, string>]: MakeKeysRequired<Cast<TMissingImplementationsForType, string>>;
76
- } : {};
77
- declare type GenerateActionsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'actions', Prop<TMissingImplementations, 'actions'>, TRequireMissingImplementations> & {
78
- actions?: TypegenMachineOptionsActions<TContext, TResolvedTypesMeta>;
79
- };
80
- declare type GenerateDelaysConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'delays', Prop<TMissingImplementations, 'delays'>, TRequireMissingImplementations> & {
81
- delays?: TypegenMachineOptionsDelays<TContext, TResolvedTypesMeta>;
82
- };
83
- declare type GenerateGuardsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'guards', Prop<TMissingImplementations, 'guards'>, TRequireMissingImplementations> & {
84
- guards?: TypegenMachineOptionsGuards<TContext, TResolvedTypesMeta>;
85
- };
86
- declare type GenerateServicesConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = MaybeMakeMissingImplementationsRequired<'services', Prop<TMissingImplementations, 'services'>, TRequireMissingImplementations> & {
87
- services?: TypegenMachineOptionsServices<TContext, TResolvedTypesMeta>;
88
- };
89
- export declare type TypegenMachineOptions<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations = Prop<TResolvedTypesMeta, 'missingImplementations'>> = GenerateActionsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateDelaysConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateGuardsConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateServicesConfigPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations>;
90
- export declare type MaybeTypegenMachineOptions<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TResolvedTypesMeta = TypegenDisabled, TRequireMissingImplementations extends boolean = false> = TResolvedTypesMeta extends TypegenEnabled ? TypegenMachineOptions<TContext, TResolvedTypesMeta, TRequireMissingImplementations> : MachineOptions<TContext, TEvent, TAction>;
91
120
  export {};
92
121
  //# sourceMappingURL=typegenTypes.d.ts.map