xstate 5.2.1 → 5.3.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 (36) hide show
  1. package/README.md +21 -0
  2. package/actions/dist/xstate-actions.cjs.js +2 -2
  3. package/actions/dist/xstate-actions.development.cjs.js +2 -2
  4. package/actions/dist/xstate-actions.development.esm.js +2 -2
  5. package/actions/dist/xstate-actions.esm.js +2 -2
  6. package/actions/dist/xstate-actions.umd.min.js +1 -1
  7. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  8. package/actors/dist/xstate-actors.cjs.js +1 -1
  9. package/actors/dist/xstate-actors.development.cjs.js +1 -1
  10. package/actors/dist/xstate-actors.development.esm.js +1 -1
  11. package/actors/dist/xstate-actors.esm.js +1 -1
  12. package/dist/declarations/src/actions/enqueueActions.d.ts +5 -5
  13. package/dist/declarations/src/assert.d.ts +26 -0
  14. package/dist/declarations/src/index.d.ts +1 -0
  15. package/dist/{log-74467f02.cjs.js → log-a32b44b3.cjs.js} +5 -3
  16. package/dist/{log-557e5fa3.development.esm.js → log-b852bac9.development.esm.js} +5 -3
  17. package/dist/{log-a56e34a9.development.cjs.js → log-cb766272.development.cjs.js} +5 -3
  18. package/dist/{log-5409ee89.esm.js → log-e870aec8.esm.js} +5 -3
  19. package/dist/{raise-6fb30f8b.development.cjs.js → raise-4538b891.development.cjs.js} +1 -1
  20. package/dist/{raise-5d7ae4b7.esm.js → raise-7df513e7.esm.js} +1 -1
  21. package/dist/{raise-746abff7.cjs.js → raise-c3bbdd3a.cjs.js} +1 -1
  22. package/dist/{raise-0ff85b7b.development.esm.js → raise-c8b9d708.development.esm.js} +1 -1
  23. package/dist/xstate.cjs.js +33 -2
  24. package/dist/xstate.cjs.mjs +1 -0
  25. package/dist/xstate.development.cjs.js +33 -2
  26. package/dist/xstate.development.cjs.mjs +1 -0
  27. package/dist/xstate.development.esm.js +35 -5
  28. package/dist/xstate.esm.js +35 -5
  29. package/dist/xstate.umd.min.js +1 -1
  30. package/dist/xstate.umd.min.js.map +1 -1
  31. package/guards/dist/xstate-guards.cjs.js +1 -1
  32. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  33. package/guards/dist/xstate-guards.development.esm.js +1 -1
  34. package/guards/dist/xstate-guards.esm.js +1 -1
  35. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  36. package/package.json +1 -1
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var guards_dist_xstateGuards = require('../../dist/raise-746abff7.cjs.js');
5
+ var guards_dist_xstateGuards = require('../../dist/raise-c3bbdd3a.cjs.js');
6
6
  require('../../dev/dist/xstate-dev.cjs.js');
7
7
 
8
8
  /**
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var guards_dist_xstateGuards = require('../../dist/raise-6fb30f8b.development.cjs.js');
5
+ var guards_dist_xstateGuards = require('../../dist/raise-4538b891.development.cjs.js');
6
6
  require('../../dev/dist/xstate-dev.development.cjs.js');
7
7
 
8
8
  /**
@@ -1,4 +1,4 @@
1
- import { X as XSTATE_STOP, z as createActor } from '../../dist/raise-0ff85b7b.development.esm.js';
1
+ import { X as XSTATE_STOP, z as createActor } from '../../dist/raise-c8b9d708.development.esm.js';
2
2
  import '../../dev/dist/xstate-dev.development.esm.js';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { X as XSTATE_STOP, z as createActor } from '../../dist/raise-5d7ae4b7.esm.js';
1
+ import { X as XSTATE_STOP, z as createActor } from '../../dist/raise-7df513e7.esm.js';
2
2
  import '../../dev/dist/xstate-dev.esm.js';
3
3
 
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { Guard } from "../guards.js";
2
- import { Action, ActionArgs, AnyActorRef, EventObject, MachineContext, ParameterizedObject, ProvidedActor } from "../types.js";
2
+ import { Action, ActionArgs, AnyActorRef, EventObject, MachineContext, ParameterizedObject, ProvidedActor, UnifiedArg } from "../types.js";
3
3
  import { assign } from "./assign.js";
4
4
  import { cancel } from "./cancel.js";
5
5
  import { raise } from "./raise.js";
@@ -23,10 +23,10 @@ export interface EnqueueActionsAction<TContext extends MachineContext, TExpressi
23
23
  _out_TGuard?: TGuard;
24
24
  _out_TDelay?: TDelay;
25
25
  }
26
- export declare function enqueueActions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string>(collect: ({ context, event, check, enqueue }: {
27
- context: TContext;
28
- event: TExpressionEvent;
26
+ interface CollectActionsArg<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> extends UnifiedArg<TContext, TExpressionEvent, TEvent> {
29
27
  check: (guard: Guard<TContext, TExpressionEvent, undefined, TGuard>) => boolean;
30
28
  enqueue: ActionEnqueuer<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>;
31
- }) => void): EnqueueActionsAction<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>;
29
+ }
30
+ type CollectActions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = ({ context, event, check, enqueue, self }: CollectActionsArg<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>) => void;
31
+ export declare function enqueueActions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject = TExpressionEvent, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string>(collect: CollectActions<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>): EnqueueActionsAction<TContext, TExpressionEvent, TEvent, TActor, TAction, TGuard, TDelay>;
32
32
  export {};
@@ -0,0 +1,26 @@
1
+ import { EventObject } from "./types.js";
2
+ /**
3
+ * Asserts that the given event object is of the specified type or types.
4
+ * Throws an error if the event object is not of the specified types.
5
+ @example
6
+
7
+ ```ts
8
+ // ...
9
+ entry: ({ event }) => {
10
+ assertEvent(event, 'doNothing');
11
+ // event is { type: 'doNothing' }
12
+ },
13
+ // ...
14
+ exit: ({ event }) => {
15
+ assertEvent(event, 'greet');
16
+ // event is { type: 'greet'; message: string }
17
+
18
+ assertEvent(event, ['greet', 'notify']);
19
+ // event is { type: 'greet'; message: string }
20
+ // or { type: 'notify'; message: string; level: 'info' | 'error' }
21
+ },
22
+ ```
23
+ */
24
+ export declare function assertEvent<TEvent extends EventObject, TAssertedType extends TEvent['type']>(event: TEvent, type: TAssertedType | TAssertedType[]): asserts event is TEvent & {
25
+ type: TAssertedType;
26
+ };
@@ -17,6 +17,7 @@ export type { ActorSystem, InspectedActorEvent, InspectedEventEvent, InspectedSn
17
17
  export { toPromise } from "./toPromise.js";
18
18
  export { getAllOwnEventDescriptors as __unsafe_getAllOwnEventDescriptors, matchesState, pathToStateValue, toObserver } from "./utils.js";
19
19
  export { Actor, createActor, createMachine, interpret, StateNode, type Interpreter };
20
+ export { assertEvent } from "./assert.js";
20
21
  declare global {
21
22
  interface SymbolConstructor {
22
23
  readonly observable: symbol;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-746abff7.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-c3bbdd3a.cjs.js');
4
4
 
5
5
  // it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
6
6
  // but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
@@ -282,7 +282,7 @@ function forwardTo(target, options) {
282
282
  }) => event, options);
283
283
  }
284
284
 
285
- function resolveEnqueueActions(_, snapshot, args, _actionParams, {
285
+ function resolveEnqueueActions(actorScope, snapshot, args, _actionParams, {
286
286
  collect
287
287
  }) {
288
288
  const actions = [];
@@ -311,7 +311,9 @@ function resolveEnqueueActions(_, snapshot, args, _actionParams, {
311
311
  context: args.context,
312
312
  event: args.event,
313
313
  enqueue,
314
- check: guard => guards_dist_xstateGuards.evaluateGuard(guard, snapshot.context, args.event, snapshot)
314
+ check: guard => guards_dist_xstateGuards.evaluateGuard(guard, snapshot.context, args.event, snapshot),
315
+ self: actorScope.self,
316
+ system: actorScope.system
315
317
  });
316
318
  return [snapshot, undefined, actions];
317
319
  }
@@ -1,4 +1,4 @@
1
- import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot, U as XSTATE_ERROR, V as createErrorActorEvent, e as evaluateGuard, L as cancel, M as raise, O as spawnChild, Q as stopChild } from './raise-0ff85b7b.development.esm.js';
1
+ import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot, U as XSTATE_ERROR, V as createErrorActorEvent, e as evaluateGuard, L as cancel, M as raise, O as spawnChild, Q as stopChild } from './raise-c8b9d708.development.esm.js';
2
2
 
3
3
  // it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
4
4
  // but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
@@ -296,7 +296,7 @@ function forwardTo(target, options) {
296
296
  }) => event, options);
297
297
  }
298
298
 
299
- function resolveEnqueueActions(_, snapshot, args, _actionParams, {
299
+ function resolveEnqueueActions(actorScope, snapshot, args, _actionParams, {
300
300
  collect
301
301
  }) {
302
302
  const actions = [];
@@ -325,7 +325,9 @@ function resolveEnqueueActions(_, snapshot, args, _actionParams, {
325
325
  context: args.context,
326
326
  event: args.event,
327
327
  enqueue,
328
- check: guard => evaluateGuard(guard, snapshot.context, args.event, snapshot)
328
+ check: guard => evaluateGuard(guard, snapshot.context, args.event, snapshot),
329
+ self: actorScope.self,
330
+ system: actorScope.system
329
331
  });
330
332
  return [snapshot, undefined, actions];
331
333
  }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var guards_dist_xstateGuards = require('./raise-6fb30f8b.development.cjs.js');
3
+ var guards_dist_xstateGuards = require('./raise-4538b891.development.cjs.js');
4
4
 
5
5
  // it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
6
6
  // but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
@@ -298,7 +298,7 @@ function forwardTo(target, options) {
298
298
  }) => event, options);
299
299
  }
300
300
 
301
- function resolveEnqueueActions(_, snapshot, args, _actionParams, {
301
+ function resolveEnqueueActions(actorScope, snapshot, args, _actionParams, {
302
302
  collect
303
303
  }) {
304
304
  const actions = [];
@@ -327,7 +327,9 @@ function resolveEnqueueActions(_, snapshot, args, _actionParams, {
327
327
  context: args.context,
328
328
  event: args.event,
329
329
  enqueue,
330
- check: guard => guards_dist_xstateGuards.evaluateGuard(guard, snapshot.context, args.event, snapshot)
330
+ check: guard => guards_dist_xstateGuards.evaluateGuard(guard, snapshot.context, args.event, snapshot),
331
+ self: actorScope.self,
332
+ system: actorScope.system
331
333
  });
332
334
  return [snapshot, undefined, actions];
333
335
  }
@@ -1,4 +1,4 @@
1
- import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot, U as XSTATE_ERROR, V as createErrorActorEvent, e as evaluateGuard, L as cancel, M as raise, O as spawnChild, Q as stopChild } from './raise-5d7ae4b7.esm.js';
1
+ import { R as ProcessingStatus, y as resolveReferencedActor, z as createActor, T as cloneMachineSnapshot, U as XSTATE_ERROR, V as createErrorActorEvent, e as evaluateGuard, L as cancel, M as raise, O as spawnChild, Q as stopChild } from './raise-7df513e7.esm.js';
2
2
 
3
3
  // it's likely-ish that `(TActor & { src: TSrc })['logic']` would be faster
4
4
  // but it's only possible to do it since https://github.com/microsoft/TypeScript/pull/53098 (TS 5.1)
@@ -280,7 +280,7 @@ function forwardTo(target, options) {
280
280
  }) => event, options);
281
281
  }
282
282
 
283
- function resolveEnqueueActions(_, snapshot, args, _actionParams, {
283
+ function resolveEnqueueActions(actorScope, snapshot, args, _actionParams, {
284
284
  collect
285
285
  }) {
286
286
  const actions = [];
@@ -309,7 +309,9 @@ function resolveEnqueueActions(_, snapshot, args, _actionParams, {
309
309
  context: args.context,
310
310
  event: args.event,
311
311
  enqueue,
312
- check: guard => evaluateGuard(guard, snapshot.context, args.event, snapshot)
312
+ check: guard => evaluateGuard(guard, snapshot.context, args.event, snapshot),
313
+ self: actorScope.self,
314
+ system: actorScope.system
313
315
  });
314
316
  return [snapshot, undefined, actions];
315
317
  }
@@ -1999,7 +1999,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
1999
1999
  addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
2000
2000
  }
2001
2001
  for (const s of historyDefaultTransition.target) {
2002
- addProperAncestorStatesToEnter(s, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
2002
+ addProperAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
2003
2003
  }
2004
2004
  }
2005
2005
  } else {
@@ -1955,7 +1955,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
1955
1955
  addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
1956
1956
  }
1957
1957
  for (const s of historyDefaultTransition.target) {
1958
- addProperAncestorStatesToEnter(s, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
1958
+ addProperAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
1959
1959
  }
1960
1960
  }
1961
1961
  } else {
@@ -1957,7 +1957,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
1957
1957
  addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
1958
1958
  }
1959
1959
  for (const s of historyDefaultTransition.target) {
1960
- addProperAncestorStatesToEnter(s, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
1960
+ addProperAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
1961
1961
  }
1962
1962
  }
1963
1963
  } else {
@@ -1997,7 +1997,7 @@ function addDescendantStatesToEnter(stateNode, historyValue, statesForDefaultEnt
1997
1997
  addDescendantStatesToEnter(s, historyValue, statesForDefaultEntry, statesToEnter);
1998
1998
  }
1999
1999
  for (const s of historyDefaultTransition.target) {
2000
- addProperAncestorStatesToEnter(s, stateNode, statesToEnter, historyValue, statesForDefaultEntry);
2000
+ addProperAncestorStatesToEnter(s, stateNode.parent, statesToEnter, historyValue, statesForDefaultEntry);
2001
2001
  }
2002
2002
  }
2003
2003
  } else {
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var actors_dist_xstateActors = require('../actors/dist/xstate-actors.cjs.js');
6
- var guards_dist_xstateGuards = require('./raise-746abff7.cjs.js');
7
- var log = require('./log-74467f02.cjs.js');
6
+ var guards_dist_xstateGuards = require('./raise-c3bbdd3a.cjs.js');
7
+ var log = require('./log-a32b44b3.cjs.js');
8
8
  require('../dev/dist/xstate-dev.cjs.js');
9
9
 
10
10
  class SimulatedClock {
@@ -743,6 +743,36 @@ function toPromise(actor) {
743
743
  });
744
744
  }
745
745
 
746
+ /**
747
+ * Asserts that the given event object is of the specified type or types.
748
+ * Throws an error if the event object is not of the specified types.
749
+ @example
750
+
751
+ ```ts
752
+ // ...
753
+ entry: ({ event }) => {
754
+ assertEvent(event, 'doNothing');
755
+ // event is { type: 'doNothing' }
756
+ },
757
+ // ...
758
+ exit: ({ event }) => {
759
+ assertEvent(event, 'greet');
760
+ // event is { type: 'greet'; message: string }
761
+
762
+ assertEvent(event, ['greet', 'notify']);
763
+ // event is { type: 'greet'; message: string }
764
+ // or { type: 'notify'; message: string; level: 'info' | 'error' }
765
+ },
766
+ ```
767
+ */
768
+ function assertEvent(event, type) {
769
+ const types = guards_dist_xstateGuards.toArray(type);
770
+ if (!types.includes(event.type)) {
771
+ const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
772
+ throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
773
+ }
774
+ }
775
+
746
776
  exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
747
777
  exports.fromCallback = actors_dist_xstateActors.fromCallback;
748
778
  exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
@@ -777,6 +807,7 @@ exports.sendTo = log.sendTo;
777
807
  exports.SimulatedClock = SimulatedClock;
778
808
  exports.StateMachine = StateMachine;
779
809
  exports.StateNode = StateNode;
810
+ exports.assertEvent = assertEvent;
780
811
  exports.createMachine = createMachine;
781
812
  exports.setup = setup;
782
813
  exports.toPromise = toPromise;
@@ -6,6 +6,7 @@ export {
6
6
  StateNode,
7
7
  __unsafe_getAllOwnEventDescriptors,
8
8
  and,
9
+ assertEvent,
9
10
  assign,
10
11
  cancel,
11
12
  createActor,
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var actors_dist_xstateActors = require('../actors/dist/xstate-actors.development.cjs.js');
6
- var guards_dist_xstateGuards = require('./raise-6fb30f8b.development.cjs.js');
7
- var log = require('./log-a56e34a9.development.cjs.js');
6
+ var guards_dist_xstateGuards = require('./raise-4538b891.development.cjs.js');
7
+ var log = require('./log-cb766272.development.cjs.js');
8
8
  require('../dev/dist/xstate-dev.development.cjs.js');
9
9
 
10
10
  class SimulatedClock {
@@ -749,6 +749,36 @@ function toPromise(actor) {
749
749
  });
750
750
  }
751
751
 
752
+ /**
753
+ * Asserts that the given event object is of the specified type or types.
754
+ * Throws an error if the event object is not of the specified types.
755
+ @example
756
+
757
+ ```ts
758
+ // ...
759
+ entry: ({ event }) => {
760
+ assertEvent(event, 'doNothing');
761
+ // event is { type: 'doNothing' }
762
+ },
763
+ // ...
764
+ exit: ({ event }) => {
765
+ assertEvent(event, 'greet');
766
+ // event is { type: 'greet'; message: string }
767
+
768
+ assertEvent(event, ['greet', 'notify']);
769
+ // event is { type: 'greet'; message: string }
770
+ // or { type: 'notify'; message: string; level: 'info' | 'error' }
771
+ },
772
+ ```
773
+ */
774
+ function assertEvent(event, type) {
775
+ const types = guards_dist_xstateGuards.toArray(type);
776
+ if (!types.includes(event.type)) {
777
+ const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
778
+ throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
779
+ }
780
+ }
781
+
752
782
  exports.createEmptyActor = actors_dist_xstateActors.createEmptyActor;
753
783
  exports.fromCallback = actors_dist_xstateActors.fromCallback;
754
784
  exports.fromEventObservable = actors_dist_xstateActors.fromEventObservable;
@@ -783,6 +813,7 @@ exports.sendTo = log.sendTo;
783
813
  exports.SimulatedClock = SimulatedClock;
784
814
  exports.StateMachine = StateMachine;
785
815
  exports.StateNode = StateNode;
816
+ exports.assertEvent = assertEvent;
786
817
  exports.createMachine = createMachine;
787
818
  exports.setup = setup;
788
819
  exports.toPromise = toPromise;
@@ -6,6 +6,7 @@ export {
6
6
  StateNode,
7
7
  __unsafe_getAllOwnEventDescriptors,
8
8
  and,
9
+ assertEvent,
9
10
  assign,
10
11
  cancel,
11
12
  createActor,
@@ -1,8 +1,8 @@
1
1
  export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.development.esm.js';
2
- import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedSnapshot, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-0ff85b7b.development.esm.js';
3
- export { A as Actor, H as __unsafe_getAllOwnEventDescriptors, D as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, I as matchesState, E as not, F as or, J as pathToStateValue, M as raise, O as spawnChild, G as stateIn, P as stop, Q as stopChild, K as toObserver } from './raise-0ff85b7b.development.esm.js';
4
- import { a as assign } from './log-557e5fa3.development.esm.js';
5
- export { S as SpecialTargets, a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from './log-557e5fa3.development.esm.js';
2
+ import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedSnapshot, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-c8b9d708.development.esm.js';
3
+ export { A as Actor, H as __unsafe_getAllOwnEventDescriptors, D as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, I as matchesState, E as not, F as or, J as pathToStateValue, M as raise, O as spawnChild, G as stateIn, P as stop, Q as stopChild, K as toObserver } from './raise-c8b9d708.development.esm.js';
4
+ import { a as assign } from './log-b852bac9.development.esm.js';
5
+ export { S as SpecialTargets, a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from './log-b852bac9.development.esm.js';
6
6
  import '../dev/dist/xstate-dev.development.esm.js';
7
7
 
8
8
  class SimulatedClock {
@@ -747,4 +747,34 @@ function toPromise(actor) {
747
747
  });
748
748
  }
749
749
 
750
- export { SimulatedClock, StateMachine, StateNode, createMachine, setup, toPromise, waitFor };
750
+ /**
751
+ * Asserts that the given event object is of the specified type or types.
752
+ * Throws an error if the event object is not of the specified types.
753
+ @example
754
+
755
+ ```ts
756
+ // ...
757
+ entry: ({ event }) => {
758
+ assertEvent(event, 'doNothing');
759
+ // event is { type: 'doNothing' }
760
+ },
761
+ // ...
762
+ exit: ({ event }) => {
763
+ assertEvent(event, 'greet');
764
+ // event is { type: 'greet'; message: string }
765
+
766
+ assertEvent(event, ['greet', 'notify']);
767
+ // event is { type: 'greet'; message: string }
768
+ // or { type: 'notify'; message: string; level: 'info' | 'error' }
769
+ },
770
+ ```
771
+ */
772
+ function assertEvent(event, type) {
773
+ const types = toArray(type);
774
+ if (!types.includes(event.type)) {
775
+ const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
776
+ throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
777
+ }
778
+ }
779
+
780
+ export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, setup, toPromise, waitFor };
@@ -1,8 +1,8 @@
1
1
  export { createEmptyActor, fromCallback, fromEventObservable, fromObservable, fromPromise, fromTransition } from '../actors/dist/xstate-actors.esm.js';
2
- import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedSnapshot, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-5d7ae4b7.esm.js';
3
- export { A as Actor, H as __unsafe_getAllOwnEventDescriptors, D as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, I as matchesState, E as not, F as or, J as pathToStateValue, M as raise, O as spawnChild, G as stateIn, P as stop, Q as stopChild, K as toObserver } from './raise-5d7ae4b7.esm.js';
4
- import { a as assign } from './log-5409ee89.esm.js';
5
- export { S as SpecialTargets, a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from './log-5409ee89.esm.js';
2
+ import { S as STATE_DELIMITER, m as mapValues, t as toArray, f as formatTransitions, a as toTransitionConfigArray, b as formatTransition, N as NULL_EVENT, e as evaluateGuard, c as createInvokeId, g as getDelayedTransitions, d as formatInitialTransition, h as getCandidates, r as resolveStateValue, i as getAllStateNodes, j as getStateNodes, k as createMachineSnapshot, l as isInFinalState, n as macrostep, o as transitionNode, p as resolveActionsAndContext, q as createInitEvent, s as microstep, u as getInitialStateNodes, v as isStateId, w as getStateNodeByPath, x as getPersistedSnapshot, y as resolveReferencedActor, z as createActor, $ as $$ACTOR_TYPE } from './raise-7df513e7.esm.js';
3
+ export { A as Actor, H as __unsafe_getAllOwnEventDescriptors, D as and, L as cancel, z as createActor, j as getStateNodes, B as interpret, C as isMachineSnapshot, I as matchesState, E as not, F as or, J as pathToStateValue, M as raise, O as spawnChild, G as stateIn, P as stop, Q as stopChild, K as toObserver } from './raise-7df513e7.esm.js';
4
+ import { a as assign } from './log-e870aec8.esm.js';
5
+ export { S as SpecialTargets, a as assign, e as enqueueActions, f as forwardTo, l as log, s as sendParent, b as sendTo } from './log-e870aec8.esm.js';
6
6
  import '../dev/dist/xstate-dev.esm.js';
7
7
 
8
8
  class SimulatedClock {
@@ -741,4 +741,34 @@ function toPromise(actor) {
741
741
  });
742
742
  }
743
743
 
744
- export { SimulatedClock, StateMachine, StateNode, createMachine, setup, toPromise, waitFor };
744
+ /**
745
+ * Asserts that the given event object is of the specified type or types.
746
+ * Throws an error if the event object is not of the specified types.
747
+ @example
748
+
749
+ ```ts
750
+ // ...
751
+ entry: ({ event }) => {
752
+ assertEvent(event, 'doNothing');
753
+ // event is { type: 'doNothing' }
754
+ },
755
+ // ...
756
+ exit: ({ event }) => {
757
+ assertEvent(event, 'greet');
758
+ // event is { type: 'greet'; message: string }
759
+
760
+ assertEvent(event, ['greet', 'notify']);
761
+ // event is { type: 'greet'; message: string }
762
+ // or { type: 'notify'; message: string; level: 'info' | 'error' }
763
+ },
764
+ ```
765
+ */
766
+ function assertEvent(event, type) {
767
+ const types = toArray(type);
768
+ if (!types.includes(event.type)) {
769
+ const typesText = types.length === 1 ? `type "${types[0]}"` : `one of types "${types.join('", "')}"`;
770
+ throw new Error(`Expected event ${JSON.stringify(event)} to have ${typesText}`);
771
+ }
772
+ }
773
+
774
+ export { SimulatedClock, StateMachine, StateNode, assertEvent, createMachine, setup, toPromise, waitFor };