xstate 5.14.0 → 5.16.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 (59) hide show
  1. package/actions/dist/xstate-actions.cjs.js +2 -2
  2. package/actions/dist/xstate-actions.development.cjs.js +2 -2
  3. package/actions/dist/xstate-actions.development.esm.js +2 -2
  4. package/actions/dist/xstate-actions.esm.js +2 -2
  5. package/actions/dist/xstate-actions.umd.min.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +272 -65
  8. package/actors/dist/xstate-actors.development.cjs.js +272 -65
  9. package/actors/dist/xstate-actors.development.esm.js +272 -65
  10. package/actors/dist/xstate-actors.esm.js +272 -65
  11. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  12. package/dist/declarations/src/State.d.ts +23 -27
  13. package/dist/declarations/src/StateMachine.d.ts +19 -31
  14. package/dist/declarations/src/StateNode.d.ts +29 -51
  15. package/dist/declarations/src/actions/assign.d.ts +29 -27
  16. package/dist/declarations/src/actions/cancel.d.ts +28 -22
  17. package/dist/declarations/src/actions/emit.d.ts +33 -33
  18. package/dist/declarations/src/actions/enqueueActions.d.ts +21 -18
  19. package/dist/declarations/src/actions/log.d.ts +5 -4
  20. package/dist/declarations/src/actions/send.d.ts +5 -3
  21. package/dist/declarations/src/actors/callback.d.ts +65 -26
  22. package/dist/declarations/src/actors/index.d.ts +4 -4
  23. package/dist/declarations/src/actors/observable.d.ts +65 -22
  24. package/dist/declarations/src/actors/promise.d.ts +86 -9
  25. package/dist/declarations/src/actors/transition.d.ts +89 -15
  26. package/dist/declarations/src/assert.d.ts +21 -20
  27. package/dist/declarations/src/createActor.d.ts +51 -42
  28. package/dist/declarations/src/createMachine.d.ts +40 -54
  29. package/dist/declarations/src/getNextSnapshot.d.ts +27 -24
  30. package/dist/declarations/src/guards.d.ts +67 -66
  31. package/dist/declarations/src/index.d.ts +1 -2
  32. package/dist/declarations/src/inspection.d.ts +1 -0
  33. package/dist/declarations/src/setup.d.ts +1 -2
  34. package/dist/declarations/src/spawn.d.ts +2 -5
  35. package/dist/declarations/src/stateUtils.d.ts +5 -10
  36. package/dist/declarations/src/toPromise.d.ts +1 -0
  37. package/dist/declarations/src/types.d.ts +164 -189
  38. package/dist/declarations/src/waitFor.d.ts +9 -9
  39. package/dist/{log-c943e6aa.development.esm.js → log-17f4495d.development.esm.js} +115 -117
  40. package/dist/{log-505687fd.development.cjs.js → log-31321d85.development.cjs.js} +115 -117
  41. package/dist/{log-b87cb6bd.esm.js → log-8320f5e6.esm.js} +115 -117
  42. package/dist/{log-7ae0ddf8.cjs.js → log-f9587b82.cjs.js} +115 -117
  43. package/dist/{raise-4e39e875.esm.js → raise-2cfe6b8f.esm.js} +164 -154
  44. package/dist/{raise-0f400094.development.esm.js → raise-7d030497.development.esm.js} +164 -154
  45. package/dist/{raise-f79d2832.cjs.js → raise-a6298350.cjs.js} +164 -154
  46. package/dist/{raise-0cd7e521.development.cjs.js → raise-bad6a97b.development.cjs.js} +164 -154
  47. package/dist/xstate.cjs.js +134 -157
  48. package/dist/xstate.development.cjs.js +134 -157
  49. package/dist/xstate.development.esm.js +136 -159
  50. package/dist/xstate.esm.js +136 -159
  51. package/dist/xstate.umd.min.js +1 -1
  52. package/dist/xstate.umd.min.js.map +1 -1
  53. package/guards/dist/xstate-guards.cjs.js +1 -1
  54. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  55. package/guards/dist/xstate-guards.development.esm.js +1 -1
  56. package/guards/dist/xstate-guards.esm.js +1 -1
  57. package/guards/dist/xstate-guards.umd.min.js.map +1 -1
  58. package/package.json +1 -1
  59. package/dist/declarations/src/typegenTypes.d.ts +0 -168
@@ -13,22 +13,21 @@ export declare enum ProcessingStatus {
13
13
  Stopped = 2
14
14
  }
15
15
  /**
16
- * An Actor is a running process that can receive events, send events and change its behavior based on the events it receives, which can cause effects outside of the actor. When you run a state machine, it becomes an actor.
16
+ * An Actor is a running process that can receive events, send events and change
17
+ * its behavior based on the events it receives, which can cause effects outside
18
+ * of the actor. When you run a state machine, it becomes an actor.
17
19
  */
18
20
  export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, EmittedFrom<TLogic>> {
19
21
  logic: TLogic;
20
- /**
21
- * The current internal state of the actor.
22
- */
22
+ /** The current internal state of the actor. */
23
23
  private _snapshot;
24
24
  /**
25
- * The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
25
+ * The clock that is responsible for setting and clearing timeouts, such as
26
+ * delayed events and transitions.
26
27
  */
27
28
  clock: Clock;
28
29
  options: Readonly<ActorOptions<TLogic>>;
29
- /**
30
- * The unique identifier for this actor relative to its parent.
31
- */
30
+ /** The unique identifier for this actor relative to its parent. */
32
31
  id: string;
33
32
  private mailbox;
34
33
  private observers;
@@ -38,18 +37,15 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
38
37
  ref: ActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, EmittedFrom<TLogic>>;
39
38
  private _actorScope;
40
39
  private _systemId;
41
- /**
42
- * The globally unique process ID for this invocation.
43
- */
40
+ /** The globally unique process ID for this invocation. */
44
41
  sessionId: string;
45
- /**
46
- * The system to which this actor belongs.
47
- */
42
+ /** The system to which this actor belongs. */
48
43
  system: AnyActorSystem;
49
44
  private _doneEvent?;
50
45
  src: string | AnyActorLogic;
51
46
  /**
52
- * Creates a new actor instance for the given logic with the provided options, if any.
47
+ * Creates a new actor instance for the given logic with the provided options,
48
+ * if any.
53
49
  *
54
50
  * @param logic The logic to create an actor from
55
51
  * @param options Actor options
@@ -62,11 +58,15 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
62
58
  * Subscribe an observer to an actor’s snapshot values.
63
59
  *
64
60
  * @remarks
65
- * The observer will receive the actor’s snapshot value when it is emitted. The observer can be:
61
+ * The observer will receive the actor’s snapshot value when it is emitted.
62
+ * The observer can be:
63
+ *
66
64
  * - A plain function that receives the latest snapshot, or
67
- * - An observer object whose `.next(snapshot)` method receives the latest snapshot
65
+ * - An observer object whose `.next(snapshot)` method receives the latest
66
+ * snapshot
68
67
  *
69
68
  * @example
69
+ *
70
70
  * ```ts
71
71
  * // Observer as a plain function
72
72
  * const subscription = actor.subscribe((snapshot) => {
@@ -75,6 +75,7 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
75
75
  * ```
76
76
  *
77
77
  * @example
78
+ *
78
79
  * ```ts
79
80
  * // Observer as an object
80
81
  * const subscription = actor.subscribe({
@@ -86,13 +87,16 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
86
87
  * },
87
88
  * complete() {
88
89
  * // ...
89
- * },
90
+ * }
90
91
  * });
91
92
  * ```
92
93
  *
93
- * The return value of `actor.subscribe(observer)` is a subscription object that has an `.unsubscribe()` method. You can call `subscription.unsubscribe()` to unsubscribe the observer:
94
+ * The return value of `actor.subscribe(observer)` is a subscription object
95
+ * that has an `.unsubscribe()` method. You can call
96
+ * `subscription.unsubscribe()` to unsubscribe the observer:
94
97
  *
95
98
  * @example
99
+ *
96
100
  * ```ts
97
101
  * const subscription = actor.subscribe((snapshot) => {
98
102
  * // ...
@@ -102,24 +106,23 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
102
106
  * subscription.unsubscribe();
103
107
  * ```
104
108
  *
105
- * When the actor is stopped, all of its observers will automatically be unsubscribed.
109
+ * When the actor is stopped, all of its observers will automatically be
110
+ * unsubscribed.
106
111
  *
107
- * @param observer - Either a plain function that receives the latest snapshot, or an observer object whose `.next(snapshot)` method receives the latest snapshot
112
+ * @param observer - Either a plain function that receives the latest
113
+ * snapshot, or an observer object whose `.next(snapshot)` method receives
114
+ * the latest snapshot
108
115
  */
109
116
  subscribe(observer: Observer<SnapshotFrom<TLogic>>): Subscription;
110
117
  subscribe(nextListener?: (snapshot: SnapshotFrom<TLogic>) => void, errorListener?: (error: any) => void, completeListener?: () => void): Subscription;
111
118
  on<TType extends EmittedFrom<TLogic>['type'] | '*'>(type: TType, handler: (emitted: EmittedFrom<TLogic> & (TType extends '*' ? {} : {
112
119
  type: TType;
113
120
  })) => void): Subscription;
114
- /**
115
- * Starts the Actor from the initial state
116
- */
121
+ /** Starts the Actor from the initial state */
117
122
  start(): this;
118
123
  private _process;
119
124
  private _stop;
120
- /**
121
- * Stops the Actor and unsubscribe all listeners.
122
- */
125
+ /** Stops the Actor and unsubscribe all listeners. */
123
126
  stop(): this;
124
127
  private _complete;
125
128
  private _reportError;
@@ -142,10 +145,11 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
142
145
  * @remarks
143
146
  * The internal state can be persisted from any actor, not only machines.
144
147
  *
145
- * Note that the persisted state is not the same as the snapshot from {@link Actor.getSnapshot}. Persisted state represents the internal state of the actor, while snapshots represent the actor's last emitted value.
148
+ * Note that the persisted state is not the same as the snapshot from
149
+ * {@link Actor.getSnapshot}. Persisted state represents the internal state of
150
+ * the actor, while snapshots represent the actor's last emitted value.
146
151
  *
147
152
  * Can be restored with {@link ActorOptions.state}
148
- *
149
153
  * @see https://stately.ai/docs/persistence
150
154
  */
151
155
  getPersistedSnapshot(): Snapshot<unknown>;
@@ -156,11 +160,11 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
156
160
  * @remarks
157
161
  * The snapshot represent an actor's last emitted value.
158
162
  *
159
- * When an actor receives an event, its internal state may change.
160
- * An actor may emit a snapshot when a state transition occurs.
161
- *
162
- * Note that some actors, such as callback actors generated with `fromCallback`, will not emit snapshots.
163
+ * When an actor receives an event, its internal state may change. An actor
164
+ * may emit a snapshot when a state transition occurs.
163
165
  *
166
+ * Note that some actors, such as callback actors generated with
167
+ * `fromCallback`, will not emit snapshots.
164
168
  * @see {@link Actor.subscribe} to subscribe to an actor’s snapshot values.
165
169
  * @see {@link Actor.getPersistedSnapshot} to persist the internal state of an actor (which is more than just a snapshot).
166
170
  */
@@ -168,13 +172,16 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Sna
168
172
  }
169
173
  type RequiredOptions<TLogic extends AnyActorLogic> = undefined extends InputFrom<TLogic> ? never : 'input';
170
174
  /**
171
- * Creates a new actor instance for the given actor logic with the provided options, if any.
175
+ * Creates a new actor instance for the given actor logic with the provided
176
+ * options, if any.
172
177
  *
173
178
  * @remarks
174
- * When you create an actor from actor logic via `createActor(logic)`, you implicitly create an actor system where the created actor is the root actor.
175
- * Any actors spawned from this root actor and its descendants are part of that actor system.
176
- *
179
+ * When you create an actor from actor logic via `createActor(logic)`, you
180
+ * implicitly create an actor system where the created actor is the root actor.
181
+ * Any actors spawned from this root actor and its descendants are part of that
182
+ * actor system.
177
183
  * @example
184
+ *
178
185
  * ```ts
179
186
  * import { createActor } from 'xstate';
180
187
  * import { someActorLogic } from './someActorLogic.ts';
@@ -196,7 +203,10 @@ type RequiredOptions<TLogic extends AnyActorLogic> = undefined extends InputFrom
196
203
  * actor.stop();
197
204
  * ```
198
205
  *
199
- * @param logic - The actor logic to create an actor from. For a state machine actor logic creator, see {@link createMachine}. Other actor logic creators include {@link fromCallback}, {@link fromEventObservable}, {@link fromObservable}, {@link fromPromise}, and {@link fromTransition}.
206
+ * @param logic - The actor logic to create an actor from. For a state machine
207
+ * actor logic creator, see {@link createMachine}. Other actor logic creators
208
+ * include {@link fromCallback}, {@link fromEventObservable},
209
+ * {@link fromObservable}, {@link fromPromise}, and {@link fromTransition}.
200
210
  * @param options - Actor options
201
211
  */
202
212
  export declare function createActor<TLogic extends AnyActorLogic>(logic: TLogic, ...[options]: ConditionalRequired<[
@@ -205,13 +215,12 @@ export declare function createActor<TLogic extends AnyActorLogic>(logic: TLogic,
205
215
  }
206
216
  ], IsNotNever<RequiredOptions<TLogic>>>): Actor<TLogic>;
207
217
  /**
208
- * Creates a new Interpreter instance for the given machine with the provided options, if any.
218
+ * Creates a new Interpreter instance for the given machine with the provided
219
+ * options, if any.
209
220
  *
210
221
  * @deprecated Use `createActor` instead
211
222
  */
212
223
  export declare const interpret: typeof createActor;
213
- /**
214
- * @deprecated Use `Actor` instead.
215
- */
224
+ /** @deprecated Use `Actor` instead. */
216
225
  export type Interpreter = typeof Actor;
217
226
  export {};
@@ -1,64 +1,50 @@
1
1
  import { StateMachine } from "./StateMachine.js";
2
- import { ResolveTypegenMeta, TypegenConstraint, TypegenDisabled } from "./typegenTypes.js";
3
- import { AnyActorRef, EventObject, AnyEventObject, Cast, InternalMachineImplementations, IsNever, MachineConfig, MachineContext, MachineTypes, NonReducibleUnknown, ParameterizedObject, Prop, ProvidedActor, StateValue, ToChildren, MetaObject } from "./types.js";
4
- type TestValue = string | {
5
- [k: string]: TestValue | undefined;
6
- };
7
- type _GroupTestValues<TTestValue extends string | TestValue> = TTestValue extends string ? TTestValue extends `${string}.${string}` ? [never, never] : [TTestValue, never] : [never, TTestValue];
8
- type GroupTestValues<TTestValue extends string | TestValue> = {
9
- leafCandidates: _GroupTestValues<TTestValue>[0];
10
- nonLeaf: _GroupTestValues<TTestValue>[1];
11
- };
12
- type FilterLeafValues<TLeafCandidate extends string, TNonLeaf extends {
13
- [k: string]: TestValue | undefined;
14
- }> = IsNever<TNonLeaf> extends true ? TLeafCandidate : TLeafCandidate extends string ? TLeafCandidate extends keyof TNonLeaf ? never : TLeafCandidate : never;
15
- type ToStateValue<TTestValue extends string | TestValue> = FilterLeafValues<GroupTestValues<TTestValue>['leafCandidates'], GroupTestValues<TTestValue>['nonLeaf']> | (IsNever<GroupTestValues<TTestValue>['nonLeaf']> extends false ? {
16
- [K in keyof GroupTestValues<TTestValue>['nonLeaf']]: ToStateValue<NonNullable<GroupTestValues<TTestValue>['nonLeaf'][K]>>;
17
- } : never);
2
+ import { ResolvedStateMachineTypes } from "./types.js";
3
+ import { AnyActorRef, EventObject, AnyEventObject, Cast, InternalMachineImplementations, MachineConfig, MachineContext, MachineTypes, NonReducibleUnknown, ParameterizedObject, ProvidedActor, StateValue, ToChildren, MetaObject } from "./types.js";
18
4
  /**
19
5
  * Creates a state machine (statechart) with the given configuration.
20
6
  *
21
7
  * The state machine represents the pure logic of a state machine actor.
22
8
  *
23
- * @param config The state machine configuration.
24
- * @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })` to provide machine implementations instead.
25
- *
26
9
  * @example
27
- ```ts
28
- import { createMachine } from 'xstate';
29
-
30
- const lightMachine = createMachine({
31
- id: 'light',
32
- initial: 'green',
33
- states: {
34
- green: {
35
- on: {
36
- TIMER: { target: 'yellow' }
37
- }
38
- },
39
- yellow: {
40
- on: {
41
- TIMER: { target: 'red' }
42
- }
43
- },
44
- red: {
45
- on: {
46
- TIMER: { target: 'green' }
47
- }
48
- }
49
- }
50
- });
51
-
52
- const lightActor = createActor(lightMachine);
53
- lightActor.start();
54
-
55
- lightActor.send({ type: 'TIMER' });
56
- ```
10
+ *
11
+ * ```ts
12
+ * import { createMachine } from 'xstate';
13
+ *
14
+ * const lightMachine = createMachine({
15
+ * id: 'light',
16
+ * initial: 'green',
17
+ * states: {
18
+ * green: {
19
+ * on: {
20
+ * TIMER: { target: 'yellow' }
21
+ * }
22
+ * },
23
+ * yellow: {
24
+ * on: {
25
+ * TIMER: { target: 'red' }
26
+ * }
27
+ * },
28
+ * red: {
29
+ * on: {
30
+ * TIMER: { target: 'green' }
31
+ * }
32
+ * }
33
+ * }
34
+ * });
35
+ *
36
+ * const lightActor = createActor(lightMachine);
37
+ * lightActor.start();
38
+ *
39
+ * lightActor.send({ type: 'TIMER' });
40
+ * ```
41
+ *
42
+ * @param config The state machine configuration.
43
+ * @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })`
44
+ * to provide machine implementations instead.
57
45
  */
58
46
  export declare function createMachine<TContext extends MachineContext, TEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
59
- TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TEmitted extends EventObject, TMeta extends MetaObject, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: {
60
- types?: MachineTypes<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TEmitted, TMeta, TTypesMeta>;
47
+ TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TEmitted extends EventObject, TMeta extends MetaObject, _ = any>(config: {
48
+ types?: MachineTypes<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TEmitted, TMeta>;
61
49
  schemas?: unknown;
62
- } & MachineConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TEmitted, TMeta, TTypesMeta>, implementations?: InternalMachineImplementations<TContext, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag, TEmitted>>): StateMachine<TContext, TEvent, Cast<ToChildren<TActor>, Record<string, AnyActorRef | undefined>>, TActor, TAction, TGuard, TDelay, 'matchesStates' extends keyof TTypesMeta ? ToStateValue<Cast<TTypesMeta['matchesStates'], TestValue>> : StateValue, Prop<ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag, TEmitted>['resolved'], 'tags'> & string, TInput, TOutput, TEmitted, TMeta, // TMeta
63
- ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag, TEmitted>>;
64
- export {};
50
+ } & MachineConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TEmitted, TMeta>, implementations?: InternalMachineImplementations<ResolvedStateMachineTypes<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TEmitted>>): StateMachine<TContext, TEvent, Cast<ToChildren<TActor>, Record<string, AnyActorRef | undefined>>, TActor, TAction, TGuard, TDelay, StateValue, TTag & string, TInput, TOutput, TEmitted, TMeta>;
@@ -1,32 +1,35 @@
1
1
  import { AnyActorLogic, EventFromLogic, InputFrom, SnapshotFrom } from "./types.js";
2
2
  export declare function getInitialSnapshot<T extends AnyActorLogic>(actorLogic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): SnapshotFrom<T>;
3
3
  /**
4
- * Determines the next snapshot for the given `actorLogic` based on
5
- * the given `snapshot` and `event`.
4
+ * Determines the next snapshot for the given `actorLogic` based on the given
5
+ * `snapshot` and `event`.
6
6
  *
7
- * If the `snapshot` is `undefined`, the initial snapshot of the
8
- * `actorLogic` is used.
7
+ * If the `snapshot` is `undefined`, the initial snapshot of the `actorLogic` is
8
+ * used.
9
9
  *
10
10
  * @example
11
- ```ts
12
- import { getNextSnapshot } from 'xstate';
13
- import { trafficLightMachine } from './trafficLightMachine.ts';
14
-
15
- const nextSnapshot = getNextSnapshot(
16
- trafficLightMachine, // actor logic
17
- undefined, // snapshot (or initial state if undefined)
18
- { type: 'TIMER' }); // event object
19
-
20
- console.log(nextSnapshot.value);
21
- // => 'yellow'
22
-
23
- const nextSnapshot2 = getNextSnapshot(
24
- trafficLightMachine, // actor logic
25
- nextSnapshot, // snapshot
26
- { type: 'TIMER' }); // event object
27
-
28
- console.log(nextSnapshot2.value);
29
- // =>'red'
30
- ```
11
+ *
12
+ * ```ts
13
+ * import { getNextSnapshot } from 'xstate';
14
+ * import { trafficLightMachine } from './trafficLightMachine.ts';
15
+ *
16
+ * const nextSnapshot = getNextSnapshot(
17
+ * trafficLightMachine, // actor logic
18
+ * undefined, // snapshot (or initial state if undefined)
19
+ * { type: 'TIMER' }
20
+ * ); // event object
21
+ *
22
+ * console.log(nextSnapshot.value);
23
+ * // => 'yellow'
24
+ *
25
+ * const nextSnapshot2 = getNextSnapshot(
26
+ * trafficLightMachine, // actor logic
27
+ * nextSnapshot, // snapshot
28
+ * { type: 'TIMER' }
29
+ * ); // event object
30
+ *
31
+ * console.log(nextSnapshot2.value);
32
+ * // =>'red'
33
+ * ```
31
34
  */
32
35
  export declare function getNextSnapshot<T extends AnyActorLogic>(actorLogic: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): SnapshotFrom<T>;
@@ -27,29 +27,32 @@ type UnknownReferencedGuard = Guard<MachineContext, EventObject, ParameterizedOb
27
27
  type UnknownInlineGuard = Guard<MachineContext, EventObject, undefined, ParameterizedObject>;
28
28
  export declare function stateIn<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined>(stateValue: StateValue): GuardPredicate<TContext, TExpressionEvent, TParams, any>;
29
29
  /**
30
- * Higher-order guard that evaluates to `true` if the `guard` passed to it evaluates to `false`.
30
+ * Higher-order guard that evaluates to `true` if the `guard` passed to it
31
+ * evaluates to `false`.
31
32
  *
32
33
  * @category Guards
33
34
  * @example
34
- ```ts
35
- import { setup, not } from 'xstate';
36
-
37
- const machine = setup({
38
- guards: {
39
- someNamedGuard: () => false
40
- }
41
- }).createMachine({
42
- on: {
43
- someEvent: {
44
- guard: not('someNamedGuard'),
45
- actions: () => {
46
- // will be executed if guard in `not(...)`
47
- // evaluates to `false`
48
- }
49
- }
50
- }
51
- });
52
- ```
35
+ *
36
+ * ```ts
37
+ * import { setup, not } from 'xstate';
38
+ *
39
+ * const machine = setup({
40
+ * guards: {
41
+ * someNamedGuard: () => false
42
+ * }
43
+ * }).createMachine({
44
+ * on: {
45
+ * someEvent: {
46
+ * guard: not('someNamedGuard'),
47
+ * actions: () => {
48
+ * // will be executed if guard in `not(...)`
49
+ * // evaluates to `false`
50
+ * }
51
+ * }
52
+ * }
53
+ * });
54
+ * ```
55
+ *
53
56
  * @returns A guard
54
57
  */
55
58
  export declare function not<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg>(guard: SingleGuardArg<TContext, TExpressionEvent, unknown, TArg>): GuardPredicate<TContext, TExpressionEvent, unknown, NormalizeGuardArg<DoNotInfer<TArg>>>;
@@ -59,28 +62,27 @@ export declare function not<TContext extends MachineContext, TExpressionEvent ex
59
62
  *
60
63
  * @category Guards
61
64
  * @example
62
- ```ts
63
- import { setup, and } from 'xstate';
64
-
65
- const machine = setup({
66
- guards: {
67
- someNamedGuard: () => true
68
- }
69
- }).createMachine({
70
- on: {
71
- someEvent: {
72
- guard: and([
73
- ({ context }) => context.value > 0,
74
- 'someNamedGuard'
75
- ]),
76
- actions: () => {
77
- // will be executed if all guards in `and(...)`
78
- // evaluate to true
79
- }
80
- }
81
- }
82
- });
83
- ```
65
+ *
66
+ * ```ts
67
+ * import { setup, and } from 'xstate';
68
+ *
69
+ * const machine = setup({
70
+ * guards: {
71
+ * someNamedGuard: () => true
72
+ * }
73
+ * }).createMachine({
74
+ * on: {
75
+ * someEvent: {
76
+ * guard: and([({ context }) => context.value > 0, 'someNamedGuard']),
77
+ * actions: () => {
78
+ * // will be executed if all guards in `and(...)`
79
+ * // evaluate to true
80
+ * }
81
+ * }
82
+ * }
83
+ * });
84
+ * ```
85
+ *
84
86
  * @returns A guard action object
85
87
  */
86
88
  export declare function and<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg extends unknown[]>(guards: readonly [
@@ -89,33 +91,32 @@ export declare function and<TContext extends MachineContext, TExpressionEvent ex
89
91
  }
90
92
  ]): GuardPredicate<TContext, TExpressionEvent, unknown, NormalizeGuardArgArray<DoNotInfer<TArg>>>;
91
93
  /**
92
- * Higher-order guard that evaluates to `true` if any of the `guards` passed to it
93
- * evaluate to `true`.
94
+ * Higher-order guard that evaluates to `true` if any of the `guards` passed to
95
+ * it evaluate to `true`.
94
96
  *
95
97
  * @category Guards
96
98
  * @example
97
- ```ts
98
- import { setup, or } from 'xstate';
99
-
100
- const machine = setup({
101
- guards: {
102
- someNamedGuard: () => true
103
- }
104
- }).createMachine({
105
- on: {
106
- someEvent: {
107
- guard: or([
108
- ({ context }) => context.value > 0,
109
- 'someNamedGuard'
110
- ]),
111
- actions: () => {
112
- // will be executed if any of the guards in `or(...)`
113
- // evaluate to true
114
- }
115
- }
116
- }
117
- });
118
- ```
99
+ *
100
+ * ```ts
101
+ * import { setup, or } from 'xstate';
102
+ *
103
+ * const machine = setup({
104
+ * guards: {
105
+ * someNamedGuard: () => true
106
+ * }
107
+ * }).createMachine({
108
+ * on: {
109
+ * someEvent: {
110
+ * guard: or([({ context }) => context.value > 0, 'someNamedGuard']),
111
+ * actions: () => {
112
+ * // will be executed if any of the guards in `or(...)`
113
+ * // evaluate to true
114
+ * }
115
+ * }
116
+ * }
117
+ * });
118
+ * ```
119
+ *
119
120
  * @returns A guard action object
120
121
  */
121
122
  export declare function or<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg extends unknown[]>(guards: readonly [
@@ -5,12 +5,11 @@ export { type Spawner } from "./spawn.js";
5
5
  export { isMachineSnapshot, type MachineSnapshot } from "./State.js";
6
6
  export { StateMachine } from "./StateMachine.js";
7
7
  export { getStateNodes } from "./stateUtils.js";
8
- export * from "./typegenTypes.js";
9
8
  export * from "./types.js";
10
9
  export { waitFor } from "./waitFor.js";
11
10
  import { createMachine } from "./createMachine.js";
12
11
  export { getInitialSnapshot, getNextSnapshot } from "./getNextSnapshot.js";
13
- import { Actor, createActor, interpret, Interpreter } from "./createActor.js";
12
+ import { Actor, createActor, interpret, type Interpreter } from "./createActor.js";
14
13
  import { StateNode } from "./StateNode.js";
15
14
  export { and, not, or, stateIn } from "./guards.js";
16
15
  export { setup } from "./setup.js";
@@ -4,6 +4,7 @@ export interface BaseInspectionEventProperties {
4
4
  rootId: string;
5
5
  /**
6
6
  * The relevant actorRef for the inspection event.
7
+ *
7
8
  * - For snapshot events, this is the `actorRef` of the snapshot.
8
9
  * - For event events, this is the target `actorRef` (recipient of event).
9
10
  * - For actor events, this is the `actorRef` of the registered actor.
@@ -1,6 +1,5 @@
1
1
  import { StateMachine } from "./StateMachine.js";
2
2
  import { GuardPredicate } from "./guards.js";
3
- import { ResolveTypegenMeta, TypegenDisabled } from "./typegenTypes.js";
4
3
  import { ActionFunction, AnyActorRef, AnyEventObject, Cast, ConditionalRequired, DelayConfig, EventObject, Invert, IsNever, MachineConfig, MachineContext, MetaObject, NonReducibleUnknown, ParameterizedObject, SetupTypes, StateSchema, ToChildren, UnknownActorLogic, Values } from "./types.js";
5
4
  type ToParameterizedObject<TParameterizedMap extends Record<string, ParameterizedObject['params'] | undefined>> = IsNever<TParameterizedMap> extends true ? never : Values<{
6
5
  [K in keyof TParameterizedMap & string]: {
@@ -51,6 +50,6 @@ TActors extends Record<string, UnknownActorLogic> = {}, TChildrenMap extends Rec
51
50
  } & {
52
51
  [K in RequiredSetupKeys<TChildrenMap>]: unknown;
53
52
  }): {
54
- createMachine: <const TConfig extends MachineConfig<TContext, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TInput, TOutput, TEmitted, TMeta, ResolveTypegenMeta<TypegenDisabled, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TEmitted>>>(config: TConfig) => StateMachine<TContext, TEvent, Cast<ToChildren<ToProvidedActor<TChildrenMap, TActors>>, Record<string, AnyActorRef | undefined>>, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, ToStateValue<TConfig>, TTag, TInput, TOutput, TEmitted, TMeta, ResolveTypegenMeta<TypegenDisabled, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TEmitted>>;
53
+ createMachine: <const TConfig extends MachineConfig<TContext, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TInput, TOutput, TEmitted, TMeta>>(config: TConfig) => StateMachine<TContext, TEvent, Cast<ToChildren<ToProvidedActor<TChildrenMap, TActors>>, Record<string, AnyActorRef | undefined>>, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, ToStateValue<TConfig>, TTag, TInput, TOutput, TEmitted, TMeta>;
55
54
  };
56
55
  export {};
@@ -1,4 +1,4 @@
1
- import { ActorRefFrom, AnyActorLogic, AnyActorRef, AnyActorScope, AnyEventObject, AnyMachineSnapshot, ConditionalRequired, InputFrom, IsLiteralString, IsNotNever, ProvidedActor, RequiredActorOptions } from "./types.js";
1
+ import { ActorRefFrom, AnyActorLogic, AnyActorRef, AnyActorScope, AnyEventObject, AnyMachineSnapshot, ConditionalRequired, GetConcreteByKey, InputFrom, IsLiteralString, IsNotNever, ProvidedActor, RequiredActorOptions } from "./types.js";
2
2
  type SpawnOptions<TActor extends ProvidedActor, TSrc extends TActor['src']> = TActor extends {
3
3
  src: TSrc;
4
4
  } ? ConditionalRequired<[
@@ -11,11 +11,8 @@ type SpawnOptions<TActor extends ProvidedActor, TSrc extends TActor['src']> = TA
11
11
  [K in RequiredActorOptions<TActor>]: unknown;
12
12
  }
13
13
  ], IsNotNever<RequiredActorOptions<TActor>>> : never;
14
- type GetConcreteLogic<TActor extends ProvidedActor, TSrc extends TActor['src']> = Extract<TActor, {
15
- src: TSrc;
16
- }>['logic'];
17
14
  export type Spawner<TActor extends ProvidedActor> = IsLiteralString<TActor['src']> extends true ? {
18
- <TSrc extends TActor['src']>(logic: TSrc, ...[options]: SpawnOptions<TActor, TSrc>): ActorRefFrom<GetConcreteLogic<TActor, TSrc>>;
15
+ <TSrc extends TActor['src']>(logic: TSrc, ...[options]: SpawnOptions<TActor, TSrc>): ActorRefFrom<GetConcreteByKey<TActor, 'src', TSrc>['logic']>;
19
16
  <TLogic extends AnyActorLogic>(src: TLogic, options?: {
20
17
  id?: never;
21
18
  systemId?: string;
@@ -11,9 +11,7 @@ export declare function getStateValue(rootNode: AnyStateNode, stateNodes: AnySta
11
11
  export declare function isInFinalState(stateNodeSet: Set<AnyStateNode>, stateNode: AnyStateNode): boolean;
12
12
  export declare const isStateId: (str: string) => boolean;
13
13
  export declare function getCandidates<TEvent extends EventObject>(stateNode: StateNode<any, TEvent>, receivedEventType: TEvent['type']): Array<TransitionDefinition<any, TEvent>>;
14
- /**
15
- * All delayed transitions from the config.
16
- */
14
+ /** All delayed transitions from the config. */
17
15
  export declare function getDelayedTransitions(stateNode: AnyStateNode): Array<DelayedTransitionDefinition<MachineContext, EventObject>>;
18
16
  export declare function formatTransition<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, descriptor: string, transitionConfig: AnyTransitionConfig): AnyTransitionDefinition;
19
17
  export declare function formatTransitions<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode): Map<string, TransitionDefinition<TContext, TEvent>[]>;
@@ -21,9 +19,7 @@ export declare function formatInitialTransition<TContext extends MachineContext,
21
19
  export declare function resolveTarget(stateNode: AnyStateNode, targets: ReadonlyArray<string | AnyStateNode> | undefined): ReadonlyArray<AnyStateNode> | undefined;
22
20
  export declare function getInitialStateNodesWithTheirAncestors(stateNode: AnyStateNode): Set<AnyStateNode>;
23
21
  export declare function getInitialStateNodes(stateNode: AnyStateNode): Set<AnyStateNode>;
24
- /**
25
- * Returns the child state node from its relative `stateKey`, or throws.
26
- */
22
+ /** Returns the child state node from its relative `stateKey`, or throws. */
27
23
  export declare function getStateNode(stateNode: AnyStateNode, stateKey: string): AnyStateNode;
28
24
  /**
29
25
  * Returns the relative state node from the given `statePath`, or throws.
@@ -42,9 +38,7 @@ export declare function transitionCompoundNode<TContext extends MachineContext,
42
38
  export declare function transitionParallelNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValueMap, snapshot: MachineSnapshot<TContext, TEvent, any, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
43
39
  export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue, snapshot: MachineSnapshot<TContext, TEvent, any, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
44
40
  export declare function removeConflictingTransitions(enabledTransitions: Array<AnyTransitionDefinition>, stateNodeSet: Set<AnyStateNode>, historyValue: AnyHistoryValue): Array<AnyTransitionDefinition>;
45
- /**
46
- * https://www.w3.org/TR/scxml/#microstepProcedure
47
- */
41
+ /** https://www.w3.org/TR/scxml/#microstepProcedure */
48
42
  export declare function microstep<TContext extends MachineContext, TEvent extends EventObject>(transitions: Array<AnyTransitionDefinition>, currentSnapshot: AnyMachineSnapshot, actorScope: AnyActorScope, event: AnyEventObject, isInitial: boolean, internalQueue: Array<AnyEventObject>): AnyMachineSnapshot;
49
43
  export declare let executingCustomAction: ActionFunction<any, any, any, any, any, any, any, any, any> | false;
50
44
  export declare function resolveActionsAndContext(currentSnapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope, actions: UnknownAction[], internalQueue: AnyEventObject[], deferredActorIds?: string[]): AnyMachineSnapshot;
@@ -53,7 +47,8 @@ export declare function macrostep(snapshot: AnyMachineSnapshot, event: EventObje
53
47
  microstates: Array<typeof snapshot>;
54
48
  };
55
49
  /**
56
- * Resolves a partial state value with its full representation in the state node's machine.
50
+ * Resolves a partial state value with its full representation in the state
51
+ * node's machine.
57
52
  *
58
53
  * @param stateValue The partial state value to resolve.
59
54
  */