xstate 4.26.0-pr2674-20219515814 → 4.26.1

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 +37 -10
  2. package/dist/xstate.interpreter.js +1 -1
  3. package/dist/xstate.js +1 -1
  4. package/dist/xstate.web.js +2 -2
  5. package/es/Actor.d.ts +2 -1
  6. package/es/Machine.d.ts +4 -5
  7. package/es/State.d.ts +10 -12
  8. package/es/State.js +1 -1
  9. package/es/StateNode.d.ts +14 -15
  10. package/es/StateNode.js +39 -39
  11. package/es/_virtual/_tslib.js +8 -4
  12. package/es/actions.d.ts +5 -4
  13. package/es/actions.js +7 -7
  14. package/es/behaviors.d.ts +1 -1
  15. package/es/devTools.d.ts +2 -3
  16. package/es/devTools.js +4 -0
  17. package/es/each.d.ts +1 -1
  18. package/es/index.d.ts +0 -1
  19. package/es/interpreter.d.ts +25 -35
  20. package/es/interpreter.js +19 -17
  21. package/es/model.d.ts +2 -2
  22. package/es/model.types.d.ts +9 -8
  23. package/es/registry.js +1 -1
  24. package/es/scxml.d.ts +2 -2
  25. package/es/stateUtils.d.ts +6 -6
  26. package/es/stateUtils.js +8 -3
  27. package/es/types.d.ts +46 -60
  28. package/es/utils.d.ts +1 -1
  29. package/es/utils.js +10 -10
  30. package/lib/Actor.d.ts +2 -1
  31. package/lib/Machine.d.ts +4 -5
  32. package/lib/SimulatedClock.js +9 -5
  33. package/lib/State.d.ts +10 -12
  34. package/lib/State.js +1 -1
  35. package/lib/StateNode.d.ts +14 -15
  36. package/lib/StateNode.js +38 -38
  37. package/lib/_virtual/_tslib.js +8 -4
  38. package/lib/actions.d.ts +5 -4
  39. package/lib/actions.js +7 -7
  40. package/lib/behaviors.d.ts +1 -1
  41. package/lib/devTools.d.ts +2 -3
  42. package/lib/devTools.js +4 -0
  43. package/lib/each.d.ts +1 -1
  44. package/lib/index.d.ts +0 -1
  45. package/lib/interpreter.d.ts +25 -35
  46. package/lib/interpreter.js +19 -17
  47. package/lib/json.js +7 -7
  48. package/lib/model.d.ts +2 -2
  49. package/lib/model.js +14 -10
  50. package/lib/model.types.d.ts +9 -8
  51. package/lib/patterns.js +2 -2
  52. package/lib/registry.js +1 -1
  53. package/lib/scxml.d.ts +2 -2
  54. package/lib/scxml.js +29 -25
  55. package/lib/stateUtils.d.ts +6 -6
  56. package/lib/stateUtils.js +7 -1
  57. package/lib/types.d.ts +46 -60
  58. package/lib/utils.d.ts +1 -1
  59. package/lib/utils.js +10 -10
  60. package/package.json +4 -8
  61. package/dist/xstate.cjs.d.ts +0 -11
  62. package/dist/xstate.cjs.js +0 -16
  63. package/es/typegenTypes.d.ts +0 -78
  64. package/lib/typegenTypes.d.ts +0 -78
  65. package/lib/typegenTypes.js +0 -2
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;
@@ -1,16 +1,16 @@
1
- import { EventObject, StateValue } from './types';
2
- import { StateNode } from './StateNode';
1
+ import { EventObject, StateNode, StateValue } from '.';
3
2
  declare type Configuration<TC, TE extends EventObject> = Iterable<StateNode<TC, any, TE>>;
4
3
  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;
4
+ export declare const isLeafNode: (stateNode: StateNode<any, any, any, any>) => boolean;
6
5
  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>>;
6
+ export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any>): Array<StateNode<TC, any, TE, any>>;
7
+ export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any>>): Iterable<StateNode<TC, any, TE, any>>;
9
8
  export declare function getAdjList<TC, TE extends EventObject>(configuration: Configuration<TC, TE>): AdjList<TC, TE>;
10
9
  export declare function getValue<TC, TE extends EventObject>(rootNode: StateNode<TC, any, TE, any>, configuration: Configuration<TC, TE>): StateValue;
11
10
  export declare function has<T>(iterable: Iterable<T>, item: T): boolean;
12
11
  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;
12
+ export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any>>, stateNode: StateNode<TC, any, TE, any>): boolean;
14
13
  export declare function getMeta(configuration?: StateNode[]): Record<string, any>;
14
+ export declare function getTagsFromConfiguration(configuration: StateNode<any, any, any, any>[]): Set<string>;
15
15
  export {};
16
16
  //# sourceMappingURL=stateUtils.d.ts.map
package/lib/stateUtils.js CHANGED
@@ -226,7 +226,7 @@ function has(iterable, item) {
226
226
  function nextEvents(configuration) {
227
227
  return _tslib.__spreadArray([], _tslib.__read(new Set(utils.flatten(_tslib.__spreadArray([], _tslib.__read(configuration.map(function (sn) {
228
228
  return sn.ownEvents;
229
- })))))));
229
+ })), false)))), false);
230
230
  }
231
231
  function isInFinalState(configuration, stateNode) {
232
232
  if (stateNode.type === 'compound') {
@@ -256,12 +256,18 @@ function getMeta(configuration) {
256
256
  return acc;
257
257
  }, {});
258
258
  }
259
+ function getTagsFromConfiguration(configuration) {
260
+ return new Set(utils.flatten(configuration.map(function (sn) {
261
+ return sn.tags;
262
+ })));
263
+ }
259
264
 
260
265
  exports.getAdjList = getAdjList;
261
266
  exports.getAllStateNodes = getAllStateNodes;
262
267
  exports.getChildren = getChildren;
263
268
  exports.getConfiguration = getConfiguration;
264
269
  exports.getMeta = getMeta;
270
+ exports.getTagsFromConfiguration = getTagsFromConfiguration;
265
271
  exports.getValue = getValue;
266
272
  exports.has = has;
267
273
  exports.isInFinalState = isInFinalState;
package/lib/types.d.ts CHANGED
@@ -1,25 +1,9 @@
1
- import { Clock, Interpreter } from './interpreter';
2
- import { Model } from './model.types';
3
- import { State } from './State';
4
1
  import { StateNode } from './StateNode';
5
- import { MarkAllImplementationsAsProvided, MaybeTypegenMachineOptions, TypegenDisabled } from './typegenTypes';
6
- export declare type AnyFunction = (...args: any[]) => any;
2
+ import { State } from './State';
3
+ import { Interpreter, Clock } from './interpreter';
4
+ import { IsNever, Model, Prop } from './model.types';
5
+ declare type AnyFunction = (...args: any[]) => any;
7
6
  declare type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
8
- export declare type IsNever<T> = [T] extends [never] ? true : false;
9
- export declare type Cast<T extends any, TCastType extends any> = T extends TCastType ? T : TCastType;
10
- export declare type Compute<A extends any> = {
11
- [K in keyof A]: A[K];
12
- } & unknown;
13
- export declare type Prop<T, K> = K extends keyof T ? T[K] : never;
14
- export declare type Values<T> = T[keyof T];
15
- export declare type Merge<M, N> = Omit<M, keyof N> & N;
16
- export declare type IndexByType<T extends {
17
- type: string;
18
- }> = {
19
- [K in T['type']]: Extract<T, {
20
- type: K;
21
- }>;
22
- };
23
7
  export declare type EventType = string;
24
8
  export declare type ActionType = string;
25
9
  export declare type MetaObject = Record<string, any>;
@@ -60,7 +44,7 @@ export declare type EventData = Record<string, any> & {
60
44
  * The specified string event types or the specified event objects.
61
45
  */
62
46
  export declare type Event<TEvent extends EventObject> = TEvent['type'] | TEvent;
63
- export interface ActionMeta<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> extends StateMeta<TContext, TEvent> {
47
+ export interface ActionMeta<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> extends StateMeta<TContext, TEvent> {
64
48
  action: TAction;
65
49
  _event: SCXML.Event<TEvent>;
66
50
  }
@@ -69,8 +53,8 @@ export interface AssignMeta<TContext, TEvent extends EventObject> {
69
53
  action: AssignAction<TContext, TEvent>;
70
54
  _event: SCXML.Event<TEvent>;
71
55
  }
72
- export declare type ActionFunction<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> = (context: TContext, event: TEvent, meta: ActionMeta<TContext, TEvent, TAction>) => void;
73
- export interface ChooseConditon<TContext, TEvent extends EventObject> {
56
+ export declare type ActionFunction<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> = (context: TContext, event: TEvent, meta: ActionMeta<TContext, TEvent, TAction>) => void;
57
+ export interface ChooseCondition<TContext, TEvent extends EventObject> {
74
58
  cond?: Condition<TContext, TEvent>;
75
59
  actions: Actions<TContext, TEvent>;
76
60
  }
@@ -97,14 +81,6 @@ export interface StateValueMap {
97
81
  * - For complex state nodes, this is an object, e.g., `{ success: "someChildState" }`.
98
82
  */
99
83
  export declare type StateValue = string | StateValueMap;
100
- declare type KeysWithStates<TStates extends Record<string, StateSchema> | undefined> = TStates extends object ? {
101
- [K in keyof TStates]-?: TStates[K] extends {
102
- states: object;
103
- } ? K : never;
104
- }[keyof TStates] : never;
105
- export declare type ExtractStateValue<TSchema extends Required<Pick<StateSchema<any>, 'states'>>> = keyof TSchema['states'] | (KeysWithStates<TSchema['states']> extends never ? never : {
106
- [K in KeysWithStates<TSchema['states']>]?: ExtractStateValue<TSchema['states'][K]>;
107
- });
108
84
  export interface HistoryValue {
109
85
  states: Record<string, HistoryValue | undefined>;
110
86
  current: StateValue | undefined;
@@ -174,6 +150,7 @@ export declare type InvokeCallback<TEvent extends EventObject = AnyEventObject,
174
150
  export interface InvokeMeta {
175
151
  data: any;
176
152
  src: InvokeSourceDefinition;
153
+ meta?: MetaObject;
177
154
  }
178
155
  /**
179
156
  * Returns either a Promises or a callback handler (for streams of events) given the
@@ -213,6 +190,7 @@ export interface InvokeDefinition<TContext, TEvent extends EventObject> extends
213
190
  * Data should be mapped to match the child machine's context shape.
214
191
  */
215
192
  data?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
193
+ meta?: MetaObject;
216
194
  }
217
195
  export interface Delay {
218
196
  id: string;
@@ -295,6 +273,10 @@ export interface InvokeConfig<TContext, TEvent extends EventObject> {
295
273
  * The transition to take upon the invoked child machine sending an error event.
296
274
  */
297
275
  onError?: string | SingleOrArray<TransitionConfig<TContext, DoneInvokeEvent<any>>>;
276
+ /**
277
+ * Meta data related to this invocation
278
+ */
279
+ meta?: MetaObject;
298
280
  }
299
281
  export interface StateNodeConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> {
300
282
  /**
@@ -450,6 +432,7 @@ export interface StateNodeDefinition<TContext, TStateSchema extends StateSchema,
450
432
  data?: FinalStateNodeConfig<TContext, TEvent>['data'];
451
433
  invoke: Array<InvokeDefinition<TContext, TEvent>>;
452
434
  description?: string;
435
+ tags: string[];
453
436
  }
454
437
  export declare type AnyStateNodeDefinition = StateNodeDefinition<any, any, any>;
455
438
  export interface AtomicStateNodeConfig<TContext, TEvent extends EventObject> extends StateNodeConfig<TContext, StateSchema, TEvent> {
@@ -471,7 +454,7 @@ export interface FinalStateNodeConfig<TContext, TEvent extends EventObject> exte
471
454
  data?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
472
455
  }
473
456
  export declare type SimpleOrStateNodeConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> = AtomicStateNodeConfig<TContext, TEvent> | StateNodeConfig<TContext, TStateSchema, TEvent>;
474
- export declare type ActionFunctionMap<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> = {
457
+ export declare type ActionFunctionMap<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> = {
475
458
  [K in TAction['type']]?: ActionObject<TContext, TEvent> | ActionFunction<TContext, TEvent, TAction extends {
476
459
  type: K;
477
460
  } ? TAction : never>;
@@ -479,25 +462,25 @@ export declare type ActionFunctionMap<TContext, TEvent extends EventObject, TAct
479
462
  export declare type DelayFunctionMap<TContext, TEvent extends EventObject> = Record<string, DelayConfig<TContext, TEvent>>;
480
463
  export declare type ServiceConfig<TContext, TEvent extends EventObject = AnyEventObject> = string | StateMachine<any, any, any> | InvokeCreator<TContext, TEvent>;
481
464
  export declare type DelayConfig<TContext, TEvent extends EventObject> = number | DelayExpr<TContext, TEvent>;
482
- export interface MachineOptions<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject> {
483
- guards?: Record<string, ConditionPredicate<TContext, TEvent>>;
484
- actions?: ActionFunctionMap<TContext, TEvent, TAction>;
465
+ export interface MachineOptions<TContext, TEvent extends EventObject, TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> {
466
+ guards: Record<string, ConditionPredicate<TContext, TEvent>>;
467
+ actions: ActionFunctionMap<TContext, TEvent, TAction>;
485
468
  /**
486
469
  * @deprecated Use `services` instead.
487
470
  */
488
- activities?: Record<string, ActivityConfig<TContext, TEvent>>;
489
- services?: Record<string, ServiceConfig<TContext, TEvent>>;
490
- delays?: DelayFunctionMap<TContext, TEvent>;
471
+ activities: Record<string, ActivityConfig<TContext, TEvent>>;
472
+ services: Record<string, ServiceConfig<TContext, TEvent>>;
473
+ delays: DelayFunctionMap<TContext, TEvent>;
491
474
  /**
492
475
  * @private
493
476
  */
494
- _parent?: StateNode<TContext, any, TEvent, any, any>;
477
+ _parent?: StateNode<TContext, any, TEvent, any>;
495
478
  /**
496
479
  * @private
497
480
  */
498
481
  _key?: string;
499
482
  }
500
- export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject, TTypesMeta = TypegenDisabled> extends StateNodeConfig<TContext, TStateSchema, TEvent, TAction> {
483
+ export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TAction extends BaseActionObject = ActionObject<TContext, TEvent>> extends StateNodeConfig<TContext, TStateSchema, TEvent, TAction> {
501
484
  /**
502
485
  * The initial context (extended state)
503
486
  */
@@ -507,7 +490,6 @@ export interface MachineConfig<TContext, TStateSchema extends StateSchema, TEven
507
490
  */
508
491
  version?: string;
509
492
  schema?: MachineSchema<TContext, TEvent>;
510
- tsTypes?: TTypesMeta | true;
511
493
  }
512
494
  export interface MachineSchema<TContext, TEvent extends EventObject> {
513
495
  context?: TContext;
@@ -542,11 +524,11 @@ export interface HistoryStateNode<TContext> extends StateNode<TContext> {
542
524
  export interface StateMachine<TContext, TStateSchema extends StateSchema, TEvent extends EventObject, TTypestate extends Typestate<TContext> = {
543
525
  value: any;
544
526
  context: TContext;
545
- }, TAction extends BaseActionObject = BaseActionObject, TResolvedTypesMeta = TypegenDisabled> extends StateNode<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta> {
527
+ }, _TAction extends ActionObject<TContext, TEvent> = ActionObject<TContext, TEvent>> extends StateNode<TContext, TStateSchema, TEvent, TTypestate> {
546
528
  id: string;
547
- states: StateNode<TContext, TStateSchema, TEvent, TTypestate, TResolvedTypesMeta>['states'];
548
- withConfig(options: MaybeTypegenMachineOptions<TContext, TEvent, TAction, TResolvedTypesMeta, true>, context?: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, TAction, MarkAllImplementationsAsProvided<TResolvedTypesMeta>>;
549
- withContext(context: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate, any, TResolvedTypesMeta>;
529
+ states: StateNode<TContext, TStateSchema, TEvent>['states'];
530
+ withConfig(options: Partial<MachineOptions<TContext, TEvent>>, context?: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
531
+ withContext(context: TContext | (() => TContext)): StateMachine<TContext, TStateSchema, TEvent, TTypestate>;
550
532
  }
551
533
  export declare type StateFrom<T extends StateMachine<any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any>)> = T extends StateMachine<any, any, any> ? ReturnType<T['transition']> : T extends (...args: any[]) => StateMachine<any, any, any> ? ReturnType<ReturnType<T>['transition']> : never;
552
534
  export interface ActionMap<TContext, TEvent extends EventObject> {
@@ -567,13 +549,13 @@ export interface ActivityMap {
567
549
  }
568
550
  export interface StateTransition<TContext, TEvent extends EventObject> {
569
551
  transitions: Array<TransitionDefinition<TContext, TEvent>>;
570
- configuration: Array<StateNode<TContext, any, TEvent, any, any>>;
571
- entrySet: Array<StateNode<TContext, any, TEvent, any, any>>;
572
- exitSet: Array<StateNode<TContext, any, TEvent, any, any>>;
552
+ configuration: Array<StateNode<TContext, any, TEvent, any>>;
553
+ entrySet: Array<StateNode<TContext, any, TEvent, any>>;
554
+ exitSet: Array<StateNode<TContext, any, TEvent, any>>;
573
555
  /**
574
556
  * The source state that preceded the transition.
575
557
  */
576
- source: State<TContext, any, any, any, any> | undefined;
558
+ source: State<TContext, any, any, any> | undefined;
577
559
  actions: Array<ActionObject<TContext, TEvent>>;
578
560
  }
579
561
  export interface TransitionData<TContext, TEvent extends EventObject> {
@@ -716,7 +698,7 @@ export interface PureAction<TContext, TEvent extends EventObject> extends Action
716
698
  }
717
699
  export interface ChooseAction<TContext, TEvent extends EventObject> extends ActionObject<TContext, TEvent> {
718
700
  type: ActionTypes.Choose;
719
- conds: Array<ChooseConditon<TContext, TEvent>>;
701
+ conds: Array<ChooseCondition<TContext, TEvent>>;
720
702
  }
721
703
  export interface TransitionDefinition<TContext, TEvent extends EventObject> extends TransitionConfig<TContext, TEvent> {
722
704
  target: Array<StateNode<TContext, any, TEvent>> | undefined;
@@ -794,7 +776,7 @@ export interface SCXMLEventMeta<TEvent extends EventObject> {
794
776
  _event: SCXML.Event<TEvent>;
795
777
  }
796
778
  export interface StateMeta<TContext, TEvent extends EventObject> {
797
- state: State<TContext, TEvent, any, any, any>;
779
+ state: State<TContext, TEvent, any, any>;
798
780
  _event: SCXML.Event<TEvent>;
799
781
  }
800
782
  export interface Typestate<TContext> {
@@ -813,7 +795,7 @@ export interface StateConfig<TContext, TEvent extends EventObject> {
813
795
  _event: SCXML.Event<TEvent>;
814
796
  _sessionid: string | null;
815
797
  historyValue?: HistoryValue | undefined;
816
- history?: State<TContext, TEvent, any, any, any>;
798
+ history?: State<TContext, TEvent>;
817
799
  actions?: Array<ActionObject<TContext, TEvent>>;
818
800
  /**
819
801
  * @deprecated
@@ -826,7 +808,7 @@ export interface StateConfig<TContext, TEvent extends EventObject> {
826
808
  children: Record<string, ActorRef<any>>;
827
809
  done?: boolean;
828
810
  tags?: Set<string>;
829
- machine?: StateMachine<TContext, any, TEvent, any, any, any>;
811
+ machine?: StateMachine<TContext, any, TEvent, any>;
830
812
  }
831
813
  export interface StateSchema<TC = any> {
832
814
  meta?: any;
@@ -839,9 +821,9 @@ export interface InterpreterOptions {
839
821
  /**
840
822
  * Whether state actions should be executed immediately upon transition. Defaults to `true`.
841
823
  */
842
- execute?: boolean;
843
- clock?: Clock;
844
- logger?: (...args: any[]) => void;
824
+ execute: boolean;
825
+ clock: Clock;
826
+ logger: (...args: any[]) => void;
845
827
  parent?: AnyInterpreter;
846
828
  /**
847
829
  * If `true`, defers processing of sent events until the service
@@ -850,7 +832,7 @@ export interface InterpreterOptions {
850
832
  *
851
833
  * Default: `true`
852
834
  */
853
- deferEvents?: boolean;
835
+ deferEvents: boolean;
854
836
  /**
855
837
  * The custom `id` for referencing this service.
856
838
  */
@@ -860,7 +842,8 @@ export interface InterpreterOptions {
860
842
  *
861
843
  * Default: `false`
862
844
  */
863
- devTools?: boolean | object;
845
+ devTools: boolean | object;
846
+ [option: string]: any;
864
847
  }
865
848
  export declare namespace SCXML {
866
849
  interface Event<TEvent extends EventObject> {
@@ -961,7 +944,7 @@ export declare type ActorRefWithDeprecatedState<TContext, TEvent extends EventOb
961
944
  state: State<TContext, TEvent, any, TTypestate>;
962
945
  };
963
946
  export declare type ActorRefFrom<T> = T extends StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate> : T extends (...args: any[]) => StateMachine<infer TContext, any, infer TEvent, infer TTypestate> ? ActorRefWithDeprecatedState<TContext, TEvent, TTypestate> : T extends Promise<infer U> ? ActorRef<never, U> : T extends Behavior<infer TEvent1, infer TEmitted> ? ActorRef<TEvent1, TEmitted> : T extends (...args: any[]) => Behavior<infer TEvent1, infer TEmitted> ? ActorRef<TEvent1, TEmitted> : never;
964
- export declare type AnyInterpreter = Interpreter<any, any, any, any, any>;
947
+ export declare type AnyInterpreter = Interpreter<any, any, any, any>;
965
948
  export declare type InterpreterFrom<T extends StateMachine<any, any, any, any> | ((...args: any[]) => StateMachine<any, any, any, any>)> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : T extends (...args: any[]) => StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : never;
966
949
  export interface ActorContext<TEvent extends EventObject, TEmitted> {
967
950
  parent?: ActorRef<any, any>;
@@ -975,7 +958,10 @@ export interface Behavior<TEvent extends EventObject, TEmitted = any> {
975
958
  start?: (actorCtx: ActorContext<TEvent, TEmitted>) => TEmitted;
976
959
  }
977
960
  export declare type EmittedFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends ActorRef<infer _, infer TEmitted> ? TEmitted : R extends Behavior<infer _, infer TEmitted> ? TEmitted : R extends ActorContext<infer _, infer TEmitted> ? TEmitted : never : never;
978
- export declare type EventFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends Model<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends State<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends Interpreter<infer _, infer __, infer TEvent, infer ____> ? TEvent : never : never;
961
+ declare type ResolveEventType<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer _, infer __, infer TEvent, infer ____> ? TEvent : R extends Model<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends State<infer _, infer TEvent, infer ___, infer ____> ? TEvent : R extends Interpreter<infer _, infer __, infer TEvent, infer ____> ? TEvent : never : never;
962
+ export declare type EventFrom<T, K extends Prop<TEvent, 'type'> = never, TEvent = ResolveEventType<T>> = IsNever<K> extends true ? TEvent : Extract<TEvent, {
963
+ type: K;
964
+ }>;
979
965
  export declare type ContextFrom<T> = ReturnTypeOrValue<T> extends infer R ? R extends StateMachine<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Model<infer TContext, infer _, infer __, infer ___> ? TContext : R extends State<infer TContext, infer _, infer __, infer ___> ? TContext : R extends Interpreter<infer TContext, infer _, infer __, infer ___> ? TContext : never : never;
980
966
  export {};
981
967
  //# sourceMappingURL=types.d.ts.map
package/lib/utils.d.ts CHANGED
@@ -63,7 +63,7 @@ export declare function toTransitionConfigArray<TContext, TEvent extends EventOb
63
63
  }>;
64
64
  export declare function normalizeTarget<TContext, TEvent extends EventObject>(target: SingleOrArray<string | StateNode<TContext, any, TEvent>> | undefined): Array<string | StateNode<TContext, any, TEvent>> | undefined;
65
65
  export declare function reportUnhandledExceptionOnInvocation(originalError: any, currentError: any, id: string): void;
66
- export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any>, guard: Guard<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
66
+ export declare function evaluateGuard<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any>, guard: Guard<TContext, TEvent>, context: TContext, _event: SCXML.Event<TEvent>, state: State<TContext, TEvent>): boolean;
67
67
  export declare function toInvokeSource(src: string | InvokeSourceDefinition): InvokeSourceDefinition;
68
68
  export declare function toObserver<T>(nextHandler: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
69
69
  //# sourceMappingURL=utils.d.ts.map
package/lib/utils.js CHANGED
@@ -40,7 +40,7 @@ function matchesState(parentStateId, childStateId, delimiter) {
40
40
  }
41
41
  function getEventType(event) {
42
42
  try {
43
- return isString(event) || typeof event === 'number' ? "" + event : event.type;
43
+ return isString(event) || typeof event === 'number' ? "".concat(event) : event.type;
44
44
  } catch (e) {
45
45
  throw new Error('Events must be strings or objects with a string event.type property.');
46
46
  }
@@ -53,7 +53,7 @@ function toStatePath(stateId, delimiter) {
53
53
 
54
54
  return stateId.toString().split(delimiter);
55
55
  } catch (e) {
56
- throw new Error("'" + stateId + "' is not a valid state path.");
56
+ throw new Error("'".concat(stateId, "' is not a valid state path."));
57
57
  }
58
58
  }
59
59
  function isStateLike(state) {
@@ -222,7 +222,7 @@ function toStatePaths(stateValue) {
222
222
  function flatten(array) {
223
223
  var _a;
224
224
 
225
- return (_a = []).concat.apply(_a, _tslib.__spreadArray([], _tslib.__read(array)));
225
+ return (_a = []).concat.apply(_a, _tslib.__spreadArray([], _tslib.__read(array), false));
226
226
  }
227
227
  function toArrayStrict(value) {
228
228
  if (isArray(value)) {
@@ -399,7 +399,7 @@ if (!environment.IS_PRODUCTION) {
399
399
  }
400
400
 
401
401
  if (console !== undefined) {
402
- var args = ["Warning: " + message];
402
+ var args = ["Warning: ".concat(message)];
403
403
 
404
404
  if (error) {
405
405
  args.push(error);
@@ -528,15 +528,15 @@ function normalizeTarget(target) {
528
528
  }
529
529
  function reportUnhandledExceptionOnInvocation(originalError, currentError, id) {
530
530
  if (!environment.IS_PRODUCTION) {
531
- var originalStackTrace = originalError.stack ? " Stacktrace was '" + originalError.stack + "'" : '';
531
+ var originalStackTrace = originalError.stack ? " Stacktrace was '".concat(originalError.stack, "'") : '';
532
532
 
533
533
  if (originalError === currentError) {
534
534
  // tslint:disable-next-line:no-console
535
- console.error("Missing onError handler for invocation '" + id + "', error was '" + originalError + "'." + originalStackTrace);
535
+ console.error("Missing onError handler for invocation '".concat(id, "', error was '").concat(originalError, "'.").concat(originalStackTrace));
536
536
  } else {
537
- var stackTrace = currentError.stack ? " Stacktrace was '" + currentError.stack + "'" : ''; // tslint:disable-next-line:no-console
537
+ var stackTrace = currentError.stack ? " Stacktrace was '".concat(currentError.stack, "'") : ''; // tslint:disable-next-line:no-console
538
538
 
539
- console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '" + id + "'. " + ("Original error: '" + originalError + "'. " + originalStackTrace + " Current error is '" + currentError + "'." + stackTrace));
539
+ console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '".concat(id, "'. ") + "Original error: '".concat(originalError, "'. ").concat(originalStackTrace, " Current error is '").concat(currentError, "'.").concat(stackTrace));
540
540
  }
541
541
  }
542
542
  }
@@ -552,10 +552,10 @@ function evaluateGuard(machine, guard, context, _event, state) {
552
552
  return ((guards === null || guards === void 0 ? void 0 : guards[guard.name]) || guard.predicate)(context, _event.data, guardMeta);
553
553
  }
554
554
 
555
- var condFn = guards === null || guards === void 0 ? void 0 : guards[guard.type];
555
+ var condFn = guards[guard.type];
556
556
 
557
557
  if (!condFn) {
558
- throw new Error("Guard '" + guard.type + "' is not implemented on machine '" + machine.id + "'.");
558
+ throw new Error("Guard '".concat(guard.type, "' is not implemented on machine '").concat(machine.id, "'."));
559
559
  }
560
560
 
561
561
  return condFn(context, _event.data, guardMeta);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xstate",
3
- "version": "4.26.0-pr2674-20219515814",
3
+ "version": "4.26.1",
4
4
  "description": "Finite State Machines and Statecharts for the Modern Web.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -30,11 +30,7 @@
30
30
  "clean": "rm -rf lib es dist tsconfig.tsbuildinfo",
31
31
  "test": "jest",
32
32
  "build": "rollup -c",
33
- "preversion": "npm run test",
34
- "version": "npm run build",
35
- "postversion": "git push --follow-tags",
36
- "prepublishOnly": "npm run build",
37
- "publish:next": "npm version prerelease && npm publish --tag next"
33
+ "prepublishOnly": "npm run build"
38
34
  },
39
35
  "repository": {
40
36
  "type": "git",
@@ -65,8 +61,8 @@
65
61
  "rollup-plugin-uglify": "^6.0.2",
66
62
  "rxjs": "^7.1.0",
67
63
  "ts-jest": "^26.5.6",
68
- "tslib": "^2.2.0",
69
- "typescript": "^4.3.5",
64
+ "tslib": "^2.3.1",
65
+ "typescript": "^4.5.2",
70
66
  "xml-js": "^1.6.11"
71
67
  }
72
68
  }
@@ -1,11 +0,0 @@
1
- // are you seeing an error that a default export doesn't exist but your source file has a default export?
2
- // you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
3
-
4
- // curious why you need to?
5
- // this file exists so that you can import from the entrypoint normally
6
- // except that it points to your source file and you don't need to run build constantly
7
- // which means we need to re-export all of the modules from your source file
8
- // and since export * doesn't include default exports, we need to read your source file
9
- // to check for a default export and re-export it if it exists
10
- // it's not ideal, but it works pretty well ¯\_(ツ)_/¯
11
- export * from "../src/index";
@@ -1,16 +0,0 @@
1
- "use strict";
2
- // this file might look strange and you might be wondering what it's for
3
- // it's lets you import your source files by importing this entrypoint
4
- // as you would import it if it was built with preconstruct build
5
- // this file is slightly different to some others though
6
- // it has a require hook which compiles your code with Babel
7
- // this means that you don't have to set up @babel/register or anything like that
8
- // but you can still require this module and it'll be compiled
9
-
10
- // this bit of code imports the require hook and registers it
11
- let unregister = require("../../../node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../..", "..");
12
-
13
- // this re-exports the source file
14
- module.exports = require("../src/index.ts");
15
-
16
- unregister();