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
@@ -90,14 +90,15 @@ function () {
90
90
  if (_this.status === exports.InterpreterStatus.Stopped) {
91
91
  // do nothing
92
92
  if (!environment.IS_PRODUCTION) {
93
- utils.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));
93
+ utils.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)));
94
94
  }
95
95
 
96
96
  return _this.state;
97
97
  }
98
98
 
99
99
  if (_this.status !== exports.InterpreterStatus.Running && !_this.options.deferEvents) {
100
- 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));
100
+ throw new Error("Event \"".concat(_event.name, "\" was sent to uninitialized service \"").concat(_this.machine.id // tslint:disable-next-line:max-line-length
101
+ , "\". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ").concat(JSON.stringify(_event.data)));
101
102
  }
102
103
 
103
104
  _this.scheduler.schedule(function () {
@@ -119,12 +120,12 @@ function () {
119
120
 
120
121
  if (!target) {
121
122
  if (!isParent) {
122
- throw new Error("Unable to send event to child '" + to + "' from service '" + _this.id + "'.");
123
+ throw new Error("Unable to send event to child '".concat(to, "' from service '").concat(_this.id, "'."));
123
124
  } // tslint:disable-next-line:no-console
124
125
 
125
126
 
126
127
  if (!environment.IS_PRODUCTION) {
127
- utils.warn(false, "Service '" + _this.id + "' has no parent: unable to send event " + event.type);
128
+ utils.warn(false, "Service '".concat(_this.id, "' has no parent: unable to send event ").concat(event.type));
128
129
  }
129
130
 
130
131
  return;
@@ -133,7 +134,7 @@ function () {
133
134
  if ('machine' in target) {
134
135
  // Send SCXML events to machines
135
136
  target.send(_tslib.__assign(_tslib.__assign({}, event), {
136
- name: event.name === actionTypes.error ? "" + actions.error(_this.id) : event.name,
137
+ name: event.name === actionTypes.error ? "".concat(actions.error(_this.id)) : event.name,
137
138
  origin: _this.sessionId
138
139
  }));
139
140
  } else {
@@ -179,7 +180,7 @@ function () {
179
180
  Object.defineProperty(Interpreter.prototype, "state", {
180
181
  get: function () {
181
182
  if (!environment.IS_PRODUCTION) {
182
- utils.warn(this.status !== exports.InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '" + this.id + "'. Make sure the service is started first.");
183
+ utils.warn(this.status !== exports.InterpreterStatus.NotStarted, "Attempted to read state from uninitialized service '".concat(this.id, "'. Make sure the service is started first."));
183
184
  }
184
185
 
185
186
  return this._state;
@@ -560,7 +561,9 @@ function () {
560
561
  return this;
561
562
  }
562
563
 
563
- this.state.configuration.forEach(function (stateNode) {
564
+ _tslib.__spreadArray([], _tslib.__read(this.state.configuration), false).sort(function (a, b) {
565
+ return b.order - a.order;
566
+ }).forEach(function (stateNode) {
564
567
  var e_11, _a;
565
568
 
566
569
  try {
@@ -582,6 +585,7 @@ function () {
582
585
  }
583
586
  }); // Stop all children
584
587
 
588
+
585
589
  this.children.forEach(function (child) {
586
590
  if (utils.isFunction(child.stop)) {
587
591
  child.stop();
@@ -619,11 +623,11 @@ function () {
619
623
  if (this.status === exports.InterpreterStatus.NotStarted && this.options.deferEvents) {
620
624
  // tslint:disable-next-line:no-console
621
625
  if (!environment.IS_PRODUCTION) {
622
- utils.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));
626
+ utils.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)));
623
627
  }
624
628
  } else if (this.status !== exports.InterpreterStatus.Running) {
625
629
  throw new Error( // tslint:disable-next-line:max-line-length
626
- 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.");
630
+ "".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."));
627
631
  }
628
632
 
629
633
  this.scheduler.schedule(function () {
@@ -643,7 +647,7 @@ function () {
643
647
  });
644
648
  batchedActions.push.apply(batchedActions, _tslib.__spreadArray([], _tslib.__read(nextState.actions.map(function (a) {
645
649
  return State.bindActionToState(a, nextState);
646
- }))));
650
+ })), false));
647
651
  batchChanged = batchChanged || !!nextState.changed;
648
652
  };
649
653
 
@@ -716,7 +720,7 @@ function () {
716
720
  var child = this.children.get(id);
717
721
 
718
722
  if (!child) {
719
- throw new Error("Unable to forward event '" + event + "' from interpreter '" + this.id + "' to nonexistant child '" + id + "'.");
723
+ throw new Error("Unable to forward event '".concat(event, "' from interpreter '").concat(this.id, "' to nonexistant child '").concat(id, "'."));
720
724
  }
721
725
 
722
726
  child.send(event);
@@ -803,6 +807,10 @@ function () {
803
807
 
804
808
  case actionTypes.start:
805
809
  {
810
+ if (this.status !== exports.InterpreterStatus.Running) {
811
+ return;
812
+ }
813
+
806
814
  var activity = action.activity; // If the activity will be stopped right after it's started
807
815
  // (such as in transient states)
808
816
  // don't bother starting the activity.
@@ -820,7 +828,7 @@ function () {
820
828
 
821
829
  if (!environment.IS_PRODUCTION) {
822
830
  utils.warn(!('forward' in activity), // tslint:disable-next-line:max-line-length
823
- "`forward` property is deprecated (found in invocation of '" + activity.src + "' in in machine '" + this.machine.id + "'). " + "Please use `autoForward` instead.");
831
+ "`forward` property is deprecated (found in invocation of '".concat(activity.src, "' in in machine '").concat(this.machine.id, "'). ") + "Please use `autoForward` instead.");
824
832
  }
825
833
 
826
834
  var autoForward = 'autoForward' in activity ? activity.autoForward : !!activity.forward;
@@ -828,7 +836,7 @@ function () {
828
836
  if (!serviceCreator) {
829
837
  // tslint:disable-next-line:no-console
830
838
  if (!environment.IS_PRODUCTION) {
831
- utils.warn(false, "No service found for invocation '" + activity.src + "' in machine '" + this.machine.id + "'.");
839
+ utils.warn(false, "No service found for invocation '".concat(activity.src, "' in machine '").concat(this.machine.id, "'."));
832
840
  }
833
841
 
834
842
  return;
@@ -889,7 +897,7 @@ function () {
889
897
 
890
898
  default:
891
899
  if (!environment.IS_PRODUCTION) {
892
- utils.warn(false, "No implementation found for action type '" + action.type + "'");
900
+ utils.warn(false, "No implementation found for action type '".concat(action.type, "'"));
893
901
  }
894
902
 
895
903
  break;
@@ -938,7 +946,7 @@ function () {
938
946
  } else if (utils.isBehavior(entity)) {
939
947
  return this.spawnBehavior(entity, name);
940
948
  } else {
941
- throw new Error("Unable to spawn entity \"" + name + "\" of type \"" + typeof entity + "\".");
949
+ throw new Error("Unable to spawn entity \"".concat(name, "\" of type \"").concat(typeof entity, "\"."));
942
950
  }
943
951
  };
944
952
 
@@ -1034,7 +1042,8 @@ function () {
1034
1042
  }
1035
1043
  }
1036
1044
  });
1037
- var actor = {
1045
+
1046
+ var actor = _tslib.__assign({
1038
1047
  id: id,
1039
1048
  send: function () {
1040
1049
  return void 0;
@@ -1078,7 +1087,8 @@ function () {
1078
1087
  getSnapshot: function () {
1079
1088
  return resolvedData;
1080
1089
  }
1081
- };
1090
+ }, utils.interopSymbols);
1091
+
1082
1092
  this.children.set(id, actor);
1083
1093
  return actor;
1084
1094
  };
@@ -1122,7 +1132,7 @@ function () {
1122
1132
  return this.spawnPromise(callbackStop, id);
1123
1133
  }
1124
1134
 
1125
- var actor = {
1135
+ var actor = _tslib.__assign({
1126
1136
  id: id,
1127
1137
  send: function (event) {
1128
1138
  return receivers.forEach(function (receiver) {
@@ -1152,7 +1162,8 @@ function () {
1152
1162
  getSnapshot: function () {
1153
1163
  return emitted;
1154
1164
  }
1155
- };
1165
+ }, utils.interopSymbols);
1166
+
1156
1167
  this.children.set(id, actor);
1157
1168
  return actor;
1158
1169
  };
@@ -1180,7 +1191,8 @@ function () {
1180
1191
  origin: id
1181
1192
  }));
1182
1193
  });
1183
- var actor = {
1194
+
1195
+ var actor = _tslib.__assign({
1184
1196
  id: id,
1185
1197
  send: function () {
1186
1198
  return void 0;
@@ -1199,7 +1211,8 @@ function () {
1199
1211
  id: id
1200
1212
  };
1201
1213
  }
1202
- };
1214
+ }, utils.interopSymbols);
1215
+
1203
1216
  this.children.set(id, actor);
1204
1217
  return actor;
1205
1218
  };
@@ -1214,7 +1227,7 @@ function () {
1214
1227
 
1215
1228
  if (!implementation) {
1216
1229
  if (!environment.IS_PRODUCTION) {
1217
- utils.warn(false, "No implementation found for activity '" + activity.type + "'");
1230
+ utils.warn(false, "No implementation found for activity '".concat(activity.type, "'"));
1218
1231
  } // tslint:disable-next-line:no-console
1219
1232
 
1220
1233
 
@@ -1227,7 +1240,7 @@ function () {
1227
1240
  };
1228
1241
 
1229
1242
  Interpreter.prototype.spawnEffect = function (id, dispose) {
1230
- this.children.set(id, {
1243
+ this.children.set(id, _tslib.__assign({
1231
1244
  id: id,
1232
1245
  send: function () {
1233
1246
  return void 0;
@@ -1248,7 +1261,7 @@ function () {
1248
1261
  id: id
1249
1262
  };
1250
1263
  }
1251
- });
1264
+ }, utils.interopSymbols));
1252
1265
  };
1253
1266
 
1254
1267
  Interpreter.prototype.attachDev = function () {
@@ -1346,7 +1359,7 @@ function spawn(entity, nameOrOptions) {
1346
1359
  return serviceScope.consume(function (service) {
1347
1360
  if (!environment.IS_PRODUCTION) {
1348
1361
  var isLazyEntity = utils.isMachine(entity) || utils.isFunction(entity);
1349
- utils.warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \"" + (utils.isMachine(entity) ? entity.id : 'undefined') + "\") outside of a service. This will have no effect.");
1362
+ utils.warn(!!service || isLazyEntity, "Attempted to spawn an Actor (ID: \"".concat(utils.isMachine(entity) ? entity.id : 'undefined', "\") outside of a service. This will have no effect."));
1350
1363
  }
1351
1364
 
1352
1365
  if (service) {
package/lib/json.js CHANGED
@@ -10,7 +10,7 @@ function stringifyFunction(fn) {
10
10
  }
11
11
  exports.stringifyFunction = stringifyFunction;
12
12
  function getStateNodeId(stateNode) {
13
- return "#" + stateNode.id;
13
+ return "#".concat(stateNode.id);
14
14
  }
15
15
  // derive config from machine
16
16
  function machineToJSON(stateNode) {
@@ -21,7 +21,7 @@ function machineToJSON(stateNode) {
21
21
  key: stateNode.key,
22
22
  entry: stateNode.onEntry,
23
23
  exit: stateNode.onExit,
24
- on: utils_1.mapValues(stateNode.on, function (transition) {
24
+ on: (0, utils_1.mapValues)(stateNode.on, function (transition) {
25
25
  return transition.map(function (t) {
26
26
  return {
27
27
  target: t.target ? t.target.map(getStateNodeId) : [],
@@ -43,7 +43,7 @@ function machineToJSON(stateNode) {
43
43
  exports.machineToJSON = machineToJSON;
44
44
  function stringify(machine) {
45
45
  return JSON.stringify(machineToJSON(machine), function (_, value) {
46
- if (utils_1.isFunction(value)) {
46
+ if ((0, utils_1.isFunction)(value)) {
47
47
  return { $function: value.toString() };
48
48
  }
49
49
  return value;
@@ -63,14 +63,14 @@ exports.parse = parse;
63
63
  function jsonify(value) {
64
64
  Object.defineProperty(value, 'toJSON', {
65
65
  value: function () {
66
- return utils_1.mapValues(value, function (subValue) {
67
- if (utils_1.isFunction(subValue)) {
66
+ return (0, utils_1.mapValues)(value, function (subValue) {
67
+ if ((0, utils_1.isFunction)(subValue)) {
68
68
  return stringifyFunction(subValue);
69
69
  }
70
70
  else if (typeof subValue === 'object' && !Array.isArray(subValue)) {
71
71
  // mostly for assignments
72
- return utils_1.mapValues(subValue, function (subSubValue) {
73
- if (utils_1.isFunction(subSubValue)) {
72
+ return (0, utils_1.mapValues)(subValue, function (subSubValue) {
73
+ if ((0, utils_1.isFunction)(subSubValue)) {
74
74
  return stringifyFunction(subSubValue);
75
75
  }
76
76
  return subSubValue;
package/lib/model.js CHANGED
@@ -26,10 +26,14 @@ var __read = (this && this.__read) || function (o, n) {
26
26
  }
27
27
  return ar;
28
28
  };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
30
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
31
- to[j] = from[i];
32
- return to;
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
33
37
  };
34
38
  Object.defineProperty(exports, "__esModule", { value: true });
35
39
  exports.createModel = void 0;
@@ -43,26 +47,26 @@ function createModel(initialContext, creators) {
43
47
  initialContext: initialContext,
44
48
  assign: actions_1.assign,
45
49
  events: (eventCreators
46
- ? utils_1.mapValues(eventCreators, function (fn, eventType) { return function () {
50
+ ? (0, utils_1.mapValues)(eventCreators, function (fn, eventType) { return function () {
47
51
  var args = [];
48
52
  for (var _i = 0; _i < arguments.length; _i++) {
49
53
  args[_i] = arguments[_i];
50
54
  }
51
- return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args)))), { type: eventType }));
55
+ return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args), false))), { type: eventType }));
52
56
  }; })
53
57
  : undefined),
54
58
  actions: actionCreators
55
- ? utils_1.mapValues(actionCreators, function (fn, actionType) { return function () {
59
+ ? (0, utils_1.mapValues)(actionCreators, function (fn, actionType) { return function () {
56
60
  var args = [];
57
61
  for (var _i = 0; _i < arguments.length; _i++) {
58
62
  args[_i] = arguments[_i];
59
63
  }
60
- return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args)))), { type: actionType }));
64
+ return (__assign(__assign({}, fn.apply(void 0, __spreadArray([], __read(args), false))), { type: actionType }));
61
65
  }; })
62
66
  : undefined,
63
- reset: function () { return actions_1.assign(initialContext); },
67
+ reset: function () { return (0, actions_1.assign)(initialContext); },
64
68
  createMachine: function (config, implementations) {
65
- return Machine_1.createMachine('context' in config ? config : __assign(__assign({}, config), { context: initialContext }), implementations);
69
+ return (0, Machine_1.createMachine)('context' in config ? config : __assign(__assign({}, config), { context: initialContext }), implementations);
66
70
  }
67
71
  };
68
72
  return model;
@@ -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/lib/patterns.js CHANGED
@@ -34,10 +34,10 @@ function sequence(items, options) {
34
34
  var states = {};
35
35
  var nextEventObject = resolvedOptions.nextEvent === undefined
36
36
  ? undefined
37
- : utils_1.toEventObject(resolvedOptions.nextEvent);
37
+ : (0, utils_1.toEventObject)(resolvedOptions.nextEvent);
38
38
  var prevEventObject = resolvedOptions.prevEvent === undefined
39
39
  ? undefined
40
- : utils_1.toEventObject(resolvedOptions.prevEvent);
40
+ : (0, utils_1.toEventObject)(resolvedOptions.prevEvent);
41
41
  items.forEach(function (item, i) {
42
42
  var state = {
43
43
  on: {}
package/lib/registry.js CHANGED
@@ -6,7 +6,7 @@ var children = /*#__PURE__*/new Map();
6
6
  var sessionIdIndex = 0;
7
7
  var registry = {
8
8
  bookId: function () {
9
- return "x:" + sessionIdIndex++;
9
+ return "x:".concat(sessionIdIndex++);
10
10
  },
11
11
  register: function (id, actor) {
12
12
  children.set(id, actor);
package/lib/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/lib/schema.js CHANGED
@@ -5,5 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  function createSchema(schema) {
6
6
  return schema;
7
7
  }
8
+ var t = createSchema;
8
9
 
9
10
  exports.createSchema = createSchema;
11
+ exports.t = t;
package/lib/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
package/lib/scxml.js CHANGED
@@ -26,10 +26,14 @@ var __read = (this && this.__read) || function (o, n) {
26
26
  }
27
27
  return ar;
28
28
  };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
30
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
31
- to[j] = from[i];
32
- return to;
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
33
37
  };
34
38
  var __values = (this && this.__values) || function(o) {
35
39
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
@@ -53,7 +57,7 @@ function getAttribute(element, attribute) {
53
57
  }
54
58
  function indexedRecord(items, identifier) {
55
59
  var record = {};
56
- var identifierFn = utils_1.isString(identifier)
60
+ var identifierFn = (0, utils_1.isString)(identifier)
57
61
  ? function (item) { return item[identifier]; }
58
62
  : identifier;
59
63
  items.forEach(function (item) {
@@ -71,7 +75,7 @@ function executableContent(elements) {
71
75
  function getTargets(targetAttr) {
72
76
  // return targetAttr ? [`#${targetAttr}`] : undefined;
73
77
  return targetAttr
74
- ? ("" + targetAttr).split(/\s+/).map(function (target) { return "#" + target; })
78
+ ? "".concat(targetAttr).split(/\s+/).map(function (target) { return "#".concat(target); })
75
79
  : undefined;
76
80
  }
77
81
  function delayToMs(delay) {
@@ -96,29 +100,29 @@ function delayToMs(delay) {
96
100
  : 0;
97
101
  var millisecondsPart = parseInt(secondsMatch[3].padEnd(3, '0'), 10);
98
102
  if (millisecondsPart >= 1000) {
99
- throw new Error("Can't parse \"" + delay + " delay.\"");
103
+ throw new Error("Can't parse \"".concat(delay, " delay.\""));
100
104
  }
101
105
  return secondsPart + millisecondsPart;
102
106
  }
103
- throw new Error("Can't parse \"" + delay + " delay.\"");
107
+ throw new Error("Can't parse \"".concat(delay, " delay.\""));
104
108
  }
105
109
  var evaluateExecutableContent = function (context, _ev, meta, body) {
106
110
  var datamodel = context
107
- ? utils_1.keys(context)
108
- .map(function (key) { return "const " + key + " = context['" + key + "'];"; })
111
+ ? (0, utils_1.keys)(context)
112
+ .map(function (key) { return "const ".concat(key, " = context['").concat(key, "'];"); })
109
113
  .join('\n')
110
114
  : '';
111
115
  var scope = ['const _sessionid = "NOT_IMPLEMENTED";', datamodel]
112
116
  .filter(Boolean)
113
117
  .join('\n');
114
118
  var args = ['context', '_event'];
115
- var fnBody = "\n " + scope + "\n " + body + "\n ";
116
- var fn = new (Function.bind.apply(Function, __spreadArray(__spreadArray([void 0], __read(args)), [fnBody])))();
119
+ var fnBody = "\n ".concat(scope, "\n ").concat(body, "\n ");
120
+ var fn = new (Function.bind.apply(Function, __spreadArray(__spreadArray([void 0], __read(args), false), [fnBody], false)))();
117
121
  return fn(context, meta._event);
118
122
  };
119
123
  function createCond(cond) {
120
124
  return function (context, _event, meta) {
121
- return evaluateExecutableContent(context, _event, meta, "return " + cond + ";");
125
+ return evaluateExecutableContent(context, _event, meta, "return ".concat(cond, ";"));
122
126
  };
123
127
  }
124
128
  function mapAction(element) {
@@ -129,7 +133,7 @@ function mapAction(element) {
129
133
  }
130
134
  case 'assign': {
131
135
  return actions.assign(function (context, e, meta) {
132
- var fnBody = "\n return {'" + element.attributes.location + "': " + element.attributes.expr + "};\n ";
136
+ var fnBody = "\n return {'".concat(element.attributes.location, "': ").concat(element.attributes.expr, "};\n ");
133
137
  return evaluateExecutableContent(context, e, meta, fnBody);
134
138
  });
135
139
  }
@@ -142,14 +146,14 @@ function mapAction(element) {
142
146
  if (child.name === 'content') {
143
147
  throw new Error('Conversion of <content/> inside <send/> not implemented.');
144
148
  }
145
- return "" + acc + child.attributes.name + ":" + child.attributes.expr + ",\n";
149
+ return "".concat(acc).concat(child.attributes.name, ":").concat(child.attributes.expr, ",\n");
146
150
  }, '');
147
151
  if (event_1 && !params_1) {
148
152
  convertedEvent = event_1;
149
153
  }
150
154
  else {
151
155
  convertedEvent = function (context, _ev, meta) {
152
- var fnBody = "\n return { type: " + (event_1 ? "\"" + event_1 + "\"" : eventexpr_1) + ", " + (params_1 ? params_1 : '') + " }\n ";
156
+ var fnBody = "\n return { type: ".concat(event_1 ? "\"".concat(event_1, "\"") : eventexpr_1, ", ").concat(params_1 ? params_1 : '', " }\n ");
153
157
  return evaluateExecutableContent(context, _ev, meta, fnBody);
154
158
  };
155
159
  }
@@ -158,7 +162,7 @@ function mapAction(element) {
158
162
  }
159
163
  else if (element.attributes.delayexpr) {
160
164
  convertedDelay = function (context, _ev, meta) {
161
- var fnBody = "\n return (" + delayToMs + ")(" + element.attributes.delayexpr + ");\n ";
165
+ var fnBody = "\n return (".concat(delayToMs, ")(").concat(element.attributes.delayexpr, ");\n ");
162
166
  return evaluateExecutableContent(context, _ev, meta, fnBody);
163
167
  };
164
168
  }
@@ -170,7 +174,7 @@ function mapAction(element) {
170
174
  case 'log': {
171
175
  var label = element.attributes.label;
172
176
  return actions.log(function (context, e, meta) {
173
- var fnBody = "\n return " + element.attributes.expr + ";\n ";
177
+ var fnBody = "\n return ".concat(element.attributes.expr, ";\n ");
174
178
  return evaluateExecutableContent(context, e, meta, fnBody);
175
179
  }, label !== undefined ? String(label) : undefined);
176
180
  }
@@ -215,7 +219,7 @@ function mapAction(element) {
215
219
  return actions.choose(conds);
216
220
  }
217
221
  default:
218
- throw new Error("Conversion of \"" + element.name + "\" elements is not implemented yet.");
222
+ throw new Error("Conversion of \"".concat(element.name, "\" elements is not implemented yet."));
219
223
  }
220
224
  }
221
225
  function mapActions(elements) {
@@ -257,7 +261,7 @@ function toConfig(nodeJson, id, options) {
257
261
  return {
258
262
  id: id,
259
263
  history: history_1,
260
- target: target ? "#" + target : undefined
264
+ target: target ? "#".concat(target) : undefined
261
265
  };
262
266
  }
263
267
  case 'final': {
@@ -277,7 +281,7 @@ function toConfig(nodeJson, id, options) {
277
281
  var invokeElements = nodeJson.elements.filter(function (element) { return element.name === 'invoke'; });
278
282
  var onEntryElement = nodeJson.elements.find(function (element) { return element.name === 'onentry'; });
279
283
  var onExitElement = nodeJson.elements.find(function (element) { return element.name === 'onexit'; });
280
- var states = indexedRecord(stateElements, function (item) { return "" + item.attributes.id; });
284
+ var states = indexedRecord(stateElements, function (item) { return "".concat(item.attributes.id); });
281
285
  var initialElement = !initial
282
286
  ? nodeJson.elements.find(function (element) { return element.name === 'initial'; })
283
287
  : undefined;
@@ -312,7 +316,7 @@ function toConfig(nodeJson, id, options) {
312
316
  });
313
317
  return __assign(__assign(__assign(__assign(__assign(__assign(__assign({ id: id }, (initial ? { initial: initial } : undefined)), (parallel ? { type: 'parallel' } : undefined)), (stateElements.length
314
318
  ? {
315
- states: utils_1.mapValues(states, function (state, key) {
319
+ states: (0, utils_1.mapValues)(states, function (state, key) {
316
320
  return toConfig(state, key, options);
317
321
  })
318
322
  }
@@ -332,15 +336,15 @@ function scxmlToMachine(scxmlJson, options) {
332
336
  }
333
337
  acc[element.attributes.id] = element.attributes.expr
334
338
  ? // tslint:disable-next-line:no-eval
335
- eval("(" + element.attributes.expr + ")")
339
+ eval("(".concat(element.attributes.expr, ")"))
336
340
  : undefined;
337
341
  return acc;
338
342
  }, {})
339
343
  : undefined;
340
- return index_1.Machine(__assign(__assign({}, toConfig(machineElement, '(machine)', options)), { context: extState, delimiter: options.delimiter }));
344
+ return (0, index_1.Machine)(__assign(__assign({}, toConfig(machineElement, '(machine)', options)), { context: extState, delimiter: options.delimiter }));
341
345
  }
342
346
  function toMachine(xml, options) {
343
- var json = xml_js_1.xml2js(xml);
347
+ var json = (0, xml_js_1.xml2js)(xml);
344
348
  return scxmlToMachine(json, options);
345
349
  }
346
350
  exports.toMachine = toMachine;