xstate 5.24.0 → 5.25.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.
- package/actions/dist/xstate-actions.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.cjs.js +3 -3
- package/actions/dist/xstate-actions.development.esm.js +3 -3
- package/actions/dist/xstate-actions.esm.js +3 -3
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.js +4 -1
- package/actors/dist/xstate-actors.development.cjs.js +4 -1
- package/actors/dist/xstate-actors.development.esm.js +4 -1
- package/actors/dist/xstate-actors.esm.js +4 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/{StateMachine-37bc3882.esm.js → StateMachine-6c48f805.esm.js} +4 -3
- package/dist/{StateMachine-4f3286fa.development.cjs.js → StateMachine-6d24a98f.development.cjs.js} +4 -3
- package/dist/{StateMachine-d6caf9f3.development.esm.js → StateMachine-d0e98d09.development.esm.js} +4 -3
- package/dist/{StateMachine-30081029.cjs.js → StateMachine-fee05db8.cjs.js} +4 -3
- package/dist/{assign-ab9cc19e.esm.js → assign-37a2fc1e.esm.js} +1 -1
- package/dist/{assign-445527dc.development.esm.js → assign-541a432d.development.esm.js} +1 -1
- package/dist/{assign-9e730107.development.cjs.js → assign-577bb842.development.cjs.js} +1 -1
- package/dist/{assign-dea9f7c8.cjs.js → assign-592716a8.cjs.js} +1 -1
- package/dist/declarations/src/State.d.ts +5 -5
- package/dist/declarations/src/StateMachine.d.ts +10 -10
- package/dist/declarations/src/assert.d.ts +2 -4
- package/dist/declarations/src/setup.d.ts +13 -8
- package/dist/declarations/src/types.d.ts +1 -1
- package/dist/declarations/src/utils.d.ts +13 -0
- package/dist/{log-cbac1abc.development.cjs.js → log-3827c227.development.cjs.js} +2 -2
- package/dist/{log-ec8d4df4.cjs.js → log-9c9f917d.cjs.js} +2 -2
- package/dist/{log-2aa3642a.development.esm.js → log-b8ca474e.development.esm.js} +2 -2
- package/dist/{log-7cbae384.esm.js → log-ce14fc9a.esm.js} +2 -2
- package/dist/{raise-c096f887.development.esm.js → raise-13a60c49.development.esm.js} +61 -32
- package/dist/{raise-da5b247f.cjs.js → raise-577e4163.cjs.js} +55 -25
- package/dist/{raise-f777a9e8.development.cjs.js → raise-ed7c6f3d.development.cjs.js} +61 -31
- package/dist/{raise-9ad1c5c6.esm.js → raise-f5c7cb5b.esm.js} +55 -26
- package/dist/xstate.cjs.js +10 -6
- package/dist/xstate.development.cjs.js +10 -6
- package/dist/xstate.development.esm.js +14 -10
- package/dist/xstate.esm.js +14 -10
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/graph/dist/xstate-graph.cjs.js +3 -3
- package/graph/dist/xstate-graph.development.cjs.js +3 -3
- package/graph/dist/xstate-graph.development.esm.js +3 -3
- package/graph/dist/xstate-graph.esm.js +3 -3
- package/graph/dist/xstate-graph.umd.min.js +1 -1
- package/graph/dist/xstate-graph.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.cjs.js +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -68,27 +68,27 @@ interface MachineSnapshotBase<TContext extends MachineContext, TEvent extends Ev
|
|
|
68
68
|
getMeta: () => Record<StateId<TStateSchema> & string, TMeta | undefined>;
|
|
69
69
|
toJSON: () => unknown;
|
|
70
70
|
}
|
|
71
|
-
interface ActiveMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject,
|
|
71
|
+
interface ActiveMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject, TStateSchema extends StateSchema> extends MachineSnapshotBase<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema> {
|
|
72
72
|
status: 'active';
|
|
73
73
|
output: undefined;
|
|
74
74
|
error: undefined;
|
|
75
75
|
}
|
|
76
|
-
interface DoneMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject,
|
|
76
|
+
interface DoneMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject, TStateSchema extends StateSchema> extends MachineSnapshotBase<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema> {
|
|
77
77
|
status: 'done';
|
|
78
78
|
output: TOutput;
|
|
79
79
|
error: undefined;
|
|
80
80
|
}
|
|
81
|
-
interface ErrorMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject,
|
|
81
|
+
interface ErrorMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject, TStateSchema extends StateSchema> extends MachineSnapshotBase<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema> {
|
|
82
82
|
status: 'error';
|
|
83
83
|
output: undefined;
|
|
84
84
|
error: unknown;
|
|
85
85
|
}
|
|
86
|
-
interface StoppedMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject,
|
|
86
|
+
interface StoppedMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject, TStateSchema extends StateSchema> extends MachineSnapshotBase<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema> {
|
|
87
87
|
status: 'stopped';
|
|
88
88
|
output: undefined;
|
|
89
89
|
error: undefined;
|
|
90
90
|
}
|
|
91
|
-
export type MachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject,
|
|
91
|
+
export type MachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject, TStateSchema extends StateSchema> = ActiveMachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema> | DoneMachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema> | ErrorMachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema> | StoppedMachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>;
|
|
92
92
|
export declare function createMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TMeta extends MetaObject, TStateSchema extends StateSchema>(config: StateConfig<TContext, TEvent>, machine: AnyStateMachine): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, undefined, TMeta, TStateSchema>;
|
|
93
93
|
export declare function cloneMachineSnapshot<TState extends AnyMachineSnapshot>(snapshot: TState, config?: Partial<StateConfig<any, any>>): TState;
|
|
94
94
|
export declare function getPersistedSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject>(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, any>, options?: unknown): Snapshot<unknown>;
|
|
@@ -2,7 +2,7 @@ import { MachineSnapshot } from "./State.js";
|
|
|
2
2
|
import { StateNode } from "./StateNode.js";
|
|
3
3
|
import { AnyActorSystem } from "./system.js";
|
|
4
4
|
import type { ActorLogic, ActorScope, AnyActorRef, AnyActorScope, DoNotInfer, Equals, EventDescriptor, EventObject, HistoryValue, InternalMachineImplementations, MachineConfig, MachineContext, MachineImplementationsSimplified, MetaObject, ParameterizedObject, ProvidedActor, Snapshot, StateMachineDefinition, StateValue, TransitionDefinition, ResolvedStateMachineTypes, StateSchema, SnapshotStatus } from "./types.js";
|
|
5
|
-
export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TStateValue extends StateValue, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject,
|
|
5
|
+
export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TStateValue extends StateValue, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TStateSchema extends StateSchema> implements ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>, TEvent, TInput, AnyActorSystem, TEmitted> {
|
|
6
6
|
/** The raw config used to create the machine. */
|
|
7
7
|
config: MachineConfig<TContext, TEvent, any, any, any, any, any, any, TOutput, any, // TEmitted
|
|
8
8
|
any> & {
|
|
@@ -29,7 +29,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
29
29
|
* recursively merge with the existing options.
|
|
30
30
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
31
31
|
*/
|
|
32
|
-
provide(implementations: InternalMachineImplementations<ResolvedStateMachineTypes<TContext, DoNotInfer<TEvent>, TActor, TAction, TGuard, TDelay, TTag, TEmitted>>): StateMachine<TContext, TEvent, TChildren, TActor, TAction, TGuard, TDelay, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta,
|
|
32
|
+
provide(implementations: InternalMachineImplementations<ResolvedStateMachineTypes<TContext, DoNotInfer<TEvent>, TActor, TAction, TGuard, TDelay, TTag, TEmitted>>): StateMachine<TContext, TEvent, TChildren, TActor, TAction, TGuard, TDelay, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta, TStateSchema>;
|
|
33
33
|
resolveState(config: {
|
|
34
34
|
value: StateValue;
|
|
35
35
|
context?: TContext;
|
|
@@ -39,7 +39,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
39
39
|
error?: unknown;
|
|
40
40
|
} & (Equals<TContext, MachineContext> extends false ? {
|
|
41
41
|
context: unknown;
|
|
42
|
-
} : {})): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta,
|
|
42
|
+
} : {})): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>;
|
|
43
43
|
/**
|
|
44
44
|
* Determines the next snapshot given the current `snapshot` and received
|
|
45
45
|
* `event`. Calculates a full macrostep from all microsteps.
|
|
@@ -47,7 +47,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
47
47
|
* @param snapshot The current snapshot
|
|
48
48
|
* @param event The received event
|
|
49
49
|
*/
|
|
50
|
-
transition(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta,
|
|
50
|
+
transition(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>, event: TEvent, actorScope: ActorScope<typeof snapshot, TEvent, AnyActorSystem, TEmitted>): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>;
|
|
51
51
|
/**
|
|
52
52
|
* Determines the next state given the current `state` and `event`. Calculates
|
|
53
53
|
* a microstep.
|
|
@@ -55,8 +55,8 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
55
55
|
* @param state The current state
|
|
56
56
|
* @param event The received event
|
|
57
57
|
*/
|
|
58
|
-
microstep(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta,
|
|
59
|
-
getTransitionData(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta,
|
|
58
|
+
microstep(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>, event: TEvent, actorScope: AnyActorScope): Array<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>>;
|
|
59
|
+
getTransitionData(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>>;
|
|
60
60
|
/**
|
|
61
61
|
* The initial state _before_ evaluating any microsteps. This "pre-initial"
|
|
62
62
|
* state is provided to initial actions executed in the initial state.
|
|
@@ -66,11 +66,11 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
66
66
|
* Returns the initial `State` instance, with reference to `self` as an
|
|
67
67
|
* `ActorRef`.
|
|
68
68
|
*/
|
|
69
|
-
getInitialSnapshot(actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta,
|
|
70
|
-
start(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta,
|
|
69
|
+
getInitialSnapshot(actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>, TEvent, AnyActorSystem, TEmitted>, input?: TInput): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>;
|
|
70
|
+
start(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>): void;
|
|
71
71
|
getStateNodeById(stateId: string): StateNode<TContext, TEvent>;
|
|
72
72
|
get definition(): StateMachineDefinition<TContext, TEvent>;
|
|
73
73
|
toJSON(): StateMachineDefinition<TContext, TEvent>;
|
|
74
|
-
getPersistedSnapshot(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta,
|
|
75
|
-
restoreSnapshot(snapshot: Snapshot<unknown>, _actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta,
|
|
74
|
+
getPersistedSnapshot(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>, options?: unknown): Snapshot<unknown>;
|
|
75
|
+
restoreSnapshot(snapshot: Snapshot<unknown>, _actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>, TEvent, AnyActorSystem, TEmitted>): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>;
|
|
76
76
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventObject } from "./types.js";
|
|
1
|
+
import { EventDescriptor, EventObject, ExtractEvent } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Asserts that the given event object is of the specified type or types. Throws
|
|
4
4
|
* an error if the event object is not of the specified types.
|
|
@@ -22,6 +22,4 @@ import { EventObject } from "./types.js";
|
|
|
22
22
|
* },
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
export declare function assertEvent<TEvent extends EventObject,
|
|
26
|
-
type: TAssertedType;
|
|
27
|
-
};
|
|
25
|
+
export declare function assertEvent<TEvent extends EventObject, TAssertedDescriptor extends EventDescriptor<TEvent>>(event: TEvent, type: TAssertedDescriptor | readonly TAssertedDescriptor[]): asserts event is ExtractEvent<TEvent, TAssertedDescriptor>;
|
|
@@ -9,20 +9,25 @@ import { sendTo } from "./actions/send.js";
|
|
|
9
9
|
import { spawnChild } from "./actions/spawnChild.js";
|
|
10
10
|
import { stopChild } from "./actions/stopChild.js";
|
|
11
11
|
import { GuardPredicate } from "./guards.js";
|
|
12
|
-
import { ActionFunction, AnyActorRef, AnyEventObject, Cast, DelayConfig, EventObject, Invert, IsNever, MachineConfig, MachineContext, MetaObject, NonReducibleUnknown, ParameterizedObject, SetupTypes, StateNodeConfig, ToChildren, ToStateValue, UnknownActorLogic, Values } from "./types.js";
|
|
13
|
-
type ToParameterizedObject<TParameterizedMap extends Record<string, ParameterizedObject['params'] | undefined>> =
|
|
14
|
-
[K in keyof TParameterizedMap & string]: {
|
|
15
|
-
type: K;
|
|
12
|
+
import { ActionFunction, AnyActorRef, AnyEventObject, Cast, DelayConfig, EventObject, Invert, IsNever, MachineConfig, MachineContext, MetaObject, NonReducibleUnknown, ParameterizedObject, SetupTypes, StateNodeConfig, StateSchema, ToChildren, ToStateValue, UnknownActorLogic, Values } from "./types.js";
|
|
13
|
+
type ToParameterizedObject<TParameterizedMap extends Record<string, ParameterizedObject['params'] | undefined>> = Values<{
|
|
14
|
+
[K in keyof TParameterizedMap as K & string]: {
|
|
15
|
+
type: K & string;
|
|
16
16
|
params: TParameterizedMap[K];
|
|
17
17
|
};
|
|
18
18
|
}>;
|
|
19
|
-
type ToProvidedActor<TChildrenMap extends Record<string, string>, TActors extends Record<string, UnknownActorLogic>> =
|
|
20
|
-
[K in keyof TActors & string]: {
|
|
21
|
-
src: K;
|
|
19
|
+
type ToProvidedActor<TChildrenMap extends Record<string, string>, TActors extends Record<string, UnknownActorLogic>> = Values<{
|
|
20
|
+
[K in keyof TActors as K & string]: {
|
|
21
|
+
src: K & string;
|
|
22
22
|
logic: TActors[K];
|
|
23
23
|
id: IsNever<TChildrenMap> extends true ? string | undefined : K extends keyof Invert<TChildrenMap> ? Invert<TChildrenMap>[K] & string : string | undefined;
|
|
24
24
|
};
|
|
25
25
|
}>;
|
|
26
|
+
type ToStateSchema<TSchema extends StateSchema> = {
|
|
27
|
+
-readonly [K in keyof TSchema as K & ('id' | 'states')]: K extends 'states' ? {
|
|
28
|
+
[SK in keyof TSchema['states']]: ToStateSchema<NonNullable<TSchema['states'][SK]>>;
|
|
29
|
+
} : TSchema[K];
|
|
30
|
+
};
|
|
26
31
|
type RequiredSetupKeys<TChildrenMap> = IsNever<keyof TChildrenMap> extends true ? never : 'actors';
|
|
27
32
|
type SetupReturn<TContext extends MachineContext, TEvent extends AnyEventObject, TActors extends Record<string, UnknownActorLogic>, TChildrenMap extends Record<string, string>, TActions extends Record<string, ParameterizedObject['params'] | undefined>, TGuards extends Record<string, ParameterizedObject['params'] | undefined>, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TEmitted extends EventObject, TMeta extends MetaObject> = {
|
|
28
33
|
extend: <TExtendActions extends Record<string, ParameterizedObject['params'] | undefined> = {}, TExtendGuards extends Record<string, ParameterizedObject['params'] | undefined> = {}, TExtendDelays extends string = never>({ actions, guards, delays }: {
|
|
@@ -91,7 +96,7 @@ type SetupReturn<TContext extends MachineContext, TEvent extends AnyEventObject,
|
|
|
91
96
|
* ```
|
|
92
97
|
*/
|
|
93
98
|
createAction: (action: ActionFunction<TContext, TEvent, TEvent, unknown, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TEmitted>) => typeof action;
|
|
94
|
-
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, TConfig
|
|
99
|
+
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, ToStateSchema<TConfig>>;
|
|
95
100
|
assign: typeof assign<TContext, TEvent, undefined, TEvent, ToProvidedActor<TChildrenMap, TActors>>;
|
|
96
101
|
sendTo: <TTargetActor extends AnyActorRef>(...args: Parameters<typeof sendTo<TContext, TEvent, undefined, TTargetActor, TEvent, TDelay, TDelay>>) => ReturnType<typeof sendTo<TContext, TEvent, undefined, TTargetActor, TEvent, TDelay, TDelay>>;
|
|
97
102
|
raise: typeof raise<TContext, TEvent, TEvent, undefined, TDelay, TDelay>;
|
|
@@ -989,7 +989,7 @@ export interface ExecutableSpawnAction extends ExecutableActionObject {
|
|
|
989
989
|
};
|
|
990
990
|
}
|
|
991
991
|
export type SpecialExecutableAction = ExecutableSpawnAction | ExecutableRaiseAction | ExecutableSendToAction;
|
|
992
|
-
export type ExecutableActionsFrom<T extends AnyActorLogic> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TActor, infer TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer
|
|
992
|
+
export type ExecutableActionsFrom<T extends AnyActorLogic> = T extends StateMachine<infer _TContext, infer _TEvent, infer _TChildren, infer _TActor, infer TAction, infer _TGuard, infer _TDelay, infer _TStateValue, infer _TTag, infer _TInput, infer _TOutput, infer _TEmitted, infer _TMeta, infer _TStateSchema> ? SpecialExecutableAction | (string extends TAction['type'] ? never : ToExecutableAction<TAction>) : never;
|
|
993
993
|
export type ActionExecutor = (actionToExecute: ExecutableActionObject) => void;
|
|
994
994
|
export type BuiltinActionResolution = [
|
|
995
995
|
AnyMachineSnapshot,
|
|
@@ -15,3 +15,16 @@ export declare function toObserver<T>(nextHandler?: Observer<T> | ((value: T) =>
|
|
|
15
15
|
export declare function createInvokeId(stateNodeId: string, index: number): string;
|
|
16
16
|
export declare function resolveReferencedActor(machine: AnyStateMachine, src: string): any;
|
|
17
17
|
export declare function getAllOwnEventDescriptors(snapshot: AnyMachineSnapshot): any[];
|
|
18
|
+
/**
|
|
19
|
+
* Checks if an event type matches an event descriptor, supporting wildcards.
|
|
20
|
+
* Event descriptors can be:
|
|
21
|
+
*
|
|
22
|
+
* - Exact matches: "event.type"
|
|
23
|
+
* - Wildcard: "*"
|
|
24
|
+
* - Partial matches: "event.*"
|
|
25
|
+
*
|
|
26
|
+
* @param eventType - The actual event type string
|
|
27
|
+
* @param descriptor - The event descriptor to match against
|
|
28
|
+
* @returns True if the event type matches the descriptor
|
|
29
|
+
*/
|
|
30
|
+
export declare function matchesEventDescriptor(eventType: string, descriptor: string): boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
4
|
-
var assign = require('./assign-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-ed7c6f3d.development.cjs.js');
|
|
4
|
+
var assign = require('./assign-577bb842.development.cjs.js');
|
|
5
5
|
|
|
6
6
|
function resolveEmit(_, snapshot, args, actionParams, {
|
|
7
7
|
event: eventOrExpr
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var guards_dist_xstateGuards = require('./raise-
|
|
4
|
-
var assign = require('./assign-
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-577e4163.cjs.js');
|
|
4
|
+
var assign = require('./assign-592716a8.cjs.js');
|
|
5
5
|
|
|
6
6
|
function resolveEmit(_, snapshot, args, actionParams, {
|
|
7
7
|
event: eventOrExpr
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as assign } from './assign-
|
|
1
|
+
import { U as executingCustomAction, V as XSTATE_ERROR, W as createErrorActorEvent, x as evaluateGuard, a as cancel, r as raise, b as spawnChild, s as stopChild } from './raise-13a60c49.development.esm.js';
|
|
2
|
+
import { a as assign } from './assign-541a432d.development.esm.js';
|
|
3
3
|
|
|
4
4
|
function resolveEmit(_, snapshot, args, actionParams, {
|
|
5
5
|
event: eventOrExpr
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as assign } from './assign-
|
|
1
|
+
import { U as XSTATE_ERROR, V as createErrorActorEvent, x as evaluateGuard, a as cancel, r as raise, b as spawnChild, s as stopChild } from './raise-f5c7cb5b.esm.js';
|
|
2
|
+
import { a as assign } from './assign-37a2fc1e.esm.js';
|
|
3
3
|
|
|
4
4
|
function resolveEmit(_, snapshot, args, actionParams, {
|
|
5
5
|
event: eventOrExpr
|
|
@@ -286,6 +286,50 @@ function getAllOwnEventDescriptors(snapshot) {
|
|
|
286
286
|
return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
+
/**
|
|
290
|
+
* Checks if an event type matches an event descriptor, supporting wildcards.
|
|
291
|
+
* Event descriptors can be:
|
|
292
|
+
*
|
|
293
|
+
* - Exact matches: "event.type"
|
|
294
|
+
* - Wildcard: "*"
|
|
295
|
+
* - Partial matches: "event.*"
|
|
296
|
+
*
|
|
297
|
+
* @param eventType - The actual event type string
|
|
298
|
+
* @param descriptor - The event descriptor to match against
|
|
299
|
+
* @returns True if the event type matches the descriptor
|
|
300
|
+
*/
|
|
301
|
+
function matchesEventDescriptor(eventType, descriptor) {
|
|
302
|
+
if (descriptor === eventType) {
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
if (descriptor === WILDCARD) {
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
if (!descriptor.endsWith('.*')) {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
if (/.*\*.+/.test(descriptor)) {
|
|
312
|
+
console.warn(`Wildcards can only be the last token of an event descriptor (e.g., "event.*") or the entire event descriptor ("*"). Check the "${descriptor}" event.`);
|
|
313
|
+
}
|
|
314
|
+
const partialEventTokens = descriptor.split('.');
|
|
315
|
+
const eventTokens = eventType.split('.');
|
|
316
|
+
for (let tokenIndex = 0; tokenIndex < partialEventTokens.length; tokenIndex++) {
|
|
317
|
+
const partialEventToken = partialEventTokens[tokenIndex];
|
|
318
|
+
const eventToken = eventTokens[tokenIndex];
|
|
319
|
+
if (partialEventToken === '*') {
|
|
320
|
+
const isLastToken = tokenIndex === partialEventTokens.length - 1;
|
|
321
|
+
if (!isLastToken) {
|
|
322
|
+
console.warn(`Infix wildcards in transition events are not allowed. Check the "${descriptor}" transition.`);
|
|
323
|
+
}
|
|
324
|
+
return isLastToken;
|
|
325
|
+
}
|
|
326
|
+
if (partialEventToken !== eventToken) {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
|
|
289
333
|
function createScheduledEventId(actorRef, id) {
|
|
290
334
|
return `${actorRef.sessionId}.${id}`;
|
|
291
335
|
}
|
|
@@ -924,12 +968,14 @@ class Actor {
|
|
|
924
968
|
}
|
|
925
969
|
}
|
|
926
970
|
this.observers.clear();
|
|
971
|
+
this.eventListeners.clear();
|
|
927
972
|
}
|
|
928
973
|
_reportError(err) {
|
|
929
974
|
if (!this.observers.size) {
|
|
930
975
|
if (!this._parent) {
|
|
931
976
|
reportUnhandledError(err);
|
|
932
977
|
}
|
|
978
|
+
this.eventListeners.clear();
|
|
933
979
|
return;
|
|
934
980
|
}
|
|
935
981
|
let reportError = false;
|
|
@@ -943,6 +989,7 @@ class Actor {
|
|
|
943
989
|
}
|
|
944
990
|
}
|
|
945
991
|
this.observers.clear();
|
|
992
|
+
this.eventListeners.clear();
|
|
946
993
|
if (reportError) {
|
|
947
994
|
reportUnhandledError(err);
|
|
948
995
|
}
|
|
@@ -1271,6 +1318,16 @@ function resolveStop(_, snapshot, args, actionParams, {
|
|
|
1271
1318
|
children
|
|
1272
1319
|
}), resolvedActorRef, undefined];
|
|
1273
1320
|
}
|
|
1321
|
+
function unregisterRecursively(actorScope, actorRef) {
|
|
1322
|
+
// unregister children first (depth-first)
|
|
1323
|
+
const snapshot = actorRef.getSnapshot();
|
|
1324
|
+
if (snapshot && 'children' in snapshot) {
|
|
1325
|
+
for (const child of Object.values(snapshot.children)) {
|
|
1326
|
+
unregisterRecursively(actorScope, child);
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
actorScope.system._unregister(actorRef);
|
|
1330
|
+
}
|
|
1274
1331
|
function executeStop(actorScope, actorRef) {
|
|
1275
1332
|
if (!actorRef) {
|
|
1276
1333
|
return;
|
|
@@ -1279,7 +1336,8 @@ function executeStop(actorScope, actorRef) {
|
|
|
1279
1336
|
// we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
|
|
1280
1337
|
// since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
|
|
1281
1338
|
// this could throw on `systemId` collision, for example, when dealing with reentering transitions
|
|
1282
|
-
|
|
1339
|
+
// we also need to recursively unregister all nested children's systemIds
|
|
1340
|
+
unregisterRecursively(actorScope, actorRef);
|
|
1283
1341
|
|
|
1284
1342
|
// this allows us to prevent an actor from being started if it gets stopped within the same macrostep
|
|
1285
1343
|
// this can happen, for example, when the invoking state is being exited immediately by an always transition
|
|
@@ -1622,36 +1680,7 @@ function isInFinalState(stateNodeSet, stateNode) {
|
|
|
1622
1680
|
}
|
|
1623
1681
|
const isStateId = str => str[0] === STATE_IDENTIFIER;
|
|
1624
1682
|
function getCandidates(stateNode, receivedEventType) {
|
|
1625
|
-
const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(eventDescriptor =>
|
|
1626
|
-
// check if transition is a wildcard transition,
|
|
1627
|
-
// which matches any non-transient events
|
|
1628
|
-
if (eventDescriptor === WILDCARD) {
|
|
1629
|
-
return true;
|
|
1630
|
-
}
|
|
1631
|
-
if (!eventDescriptor.endsWith('.*')) {
|
|
1632
|
-
return false;
|
|
1633
|
-
}
|
|
1634
|
-
if (/.*\*.+/.test(eventDescriptor)) {
|
|
1635
|
-
console.warn(`Wildcards can only be the last token of an event descriptor (e.g., "event.*") or the entire event descriptor ("*"). Check the "${eventDescriptor}" event.`);
|
|
1636
|
-
}
|
|
1637
|
-
const partialEventTokens = eventDescriptor.split('.');
|
|
1638
|
-
const eventTokens = receivedEventType.split('.');
|
|
1639
|
-
for (let tokenIndex = 0; tokenIndex < partialEventTokens.length; tokenIndex++) {
|
|
1640
|
-
const partialEventToken = partialEventTokens[tokenIndex];
|
|
1641
|
-
const eventToken = eventTokens[tokenIndex];
|
|
1642
|
-
if (partialEventToken === '*') {
|
|
1643
|
-
const isLastToken = tokenIndex === partialEventTokens.length - 1;
|
|
1644
|
-
if (!isLastToken) {
|
|
1645
|
-
console.warn(`Infix wildcards in transition events are not allowed. Check the "${eventDescriptor}" transition.`);
|
|
1646
|
-
}
|
|
1647
|
-
return isLastToken;
|
|
1648
|
-
}
|
|
1649
|
-
if (partialEventToken !== eventToken) {
|
|
1650
|
-
return false;
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
return true;
|
|
1654
|
-
}).sort((a, b) => b.length - a.length).flatMap(key => stateNode.transitions.get(key));
|
|
1683
|
+
const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(eventDescriptor => matchesEventDescriptor(receivedEventType, eventDescriptor)).sort((a, b) => b.length - a.length).flatMap(key => stateNode.transitions.get(key));
|
|
1655
1684
|
return candidates;
|
|
1656
1685
|
}
|
|
1657
1686
|
|
|
@@ -2712,4 +2741,4 @@ function raise(eventOrExpr, options) {
|
|
|
2712
2741
|
return raise;
|
|
2713
2742
|
}
|
|
2714
2743
|
|
|
2715
|
-
export { $$ACTOR_TYPE as $, Actor as A,
|
|
2744
|
+
export { $$ACTOR_TYPE as $, Actor as A, formatInitialTransition as B, getCandidates as C, resolveStateValue as D, getAllStateNodes as E, createMachineSnapshot as F, isInFinalState as G, macrostep as H, transitionNode as I, resolveActionsAndContext as J, createInitEvent as K, microstep as L, getInitialStateNodes as M, NULL_EVENT as N, toStatePath as O, isStateId as P, getStateNodeByPath as Q, getPersistedSnapshot as R, STATE_DELIMITER as S, resolveReferencedActor as T, executingCustomAction as U, XSTATE_ERROR as V, createErrorActorEvent as W, XSTATE_STOP as X, ProcessingStatus as Y, cloneMachineSnapshot as Z, cancel as a, spawnChild as b, createActor as c, and as d, stateIn as e, isMachineSnapshot as f, getStateNodes as g, getAllOwnEventDescriptors as h, interpret as i, matchesState as j, toObserver as k, stop as l, matchesEventDescriptor as m, not as n, or as o, pathToStateValue as p, mapValues as q, raise as r, stopChild as s, toArray as t, formatTransitions as u, toTransitionConfigArray as v, formatTransition as w, evaluateGuard as x, createInvokeId as y, getDelayedTransitions as z };
|
|
@@ -285,6 +285,44 @@ function getAllOwnEventDescriptors(snapshot) {
|
|
|
285
285
|
return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
|
|
286
286
|
}
|
|
287
287
|
|
|
288
|
+
/**
|
|
289
|
+
* Checks if an event type matches an event descriptor, supporting wildcards.
|
|
290
|
+
* Event descriptors can be:
|
|
291
|
+
*
|
|
292
|
+
* - Exact matches: "event.type"
|
|
293
|
+
* - Wildcard: "*"
|
|
294
|
+
* - Partial matches: "event.*"
|
|
295
|
+
*
|
|
296
|
+
* @param eventType - The actual event type string
|
|
297
|
+
* @param descriptor - The event descriptor to match against
|
|
298
|
+
* @returns True if the event type matches the descriptor
|
|
299
|
+
*/
|
|
300
|
+
function matchesEventDescriptor(eventType, descriptor) {
|
|
301
|
+
if (descriptor === eventType) {
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
if (descriptor === WILDCARD) {
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
if (!descriptor.endsWith('.*')) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
const partialEventTokens = descriptor.split('.');
|
|
311
|
+
const eventTokens = eventType.split('.');
|
|
312
|
+
for (let tokenIndex = 0; tokenIndex < partialEventTokens.length; tokenIndex++) {
|
|
313
|
+
const partialEventToken = partialEventTokens[tokenIndex];
|
|
314
|
+
const eventToken = eventTokens[tokenIndex];
|
|
315
|
+
if (partialEventToken === '*') {
|
|
316
|
+
const isLastToken = tokenIndex === partialEventTokens.length - 1;
|
|
317
|
+
return isLastToken;
|
|
318
|
+
}
|
|
319
|
+
if (partialEventToken !== eventToken) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
|
|
288
326
|
function createScheduledEventId(actorRef, id) {
|
|
289
327
|
return `${actorRef.sessionId}.${id}`;
|
|
290
328
|
}
|
|
@@ -923,12 +961,14 @@ class Actor {
|
|
|
923
961
|
}
|
|
924
962
|
}
|
|
925
963
|
this.observers.clear();
|
|
964
|
+
this.eventListeners.clear();
|
|
926
965
|
}
|
|
927
966
|
_reportError(err) {
|
|
928
967
|
if (!this.observers.size) {
|
|
929
968
|
if (!this._parent) {
|
|
930
969
|
reportUnhandledError(err);
|
|
931
970
|
}
|
|
971
|
+
this.eventListeners.clear();
|
|
932
972
|
return;
|
|
933
973
|
}
|
|
934
974
|
let reportError = false;
|
|
@@ -942,6 +982,7 @@ class Actor {
|
|
|
942
982
|
}
|
|
943
983
|
}
|
|
944
984
|
this.observers.clear();
|
|
985
|
+
this.eventListeners.clear();
|
|
945
986
|
if (reportError) {
|
|
946
987
|
reportUnhandledError(err);
|
|
947
988
|
}
|
|
@@ -1248,6 +1289,16 @@ function resolveStop(_, snapshot, args, actionParams, {
|
|
|
1248
1289
|
children
|
|
1249
1290
|
}), resolvedActorRef, undefined];
|
|
1250
1291
|
}
|
|
1292
|
+
function unregisterRecursively(actorScope, actorRef) {
|
|
1293
|
+
// unregister children first (depth-first)
|
|
1294
|
+
const snapshot = actorRef.getSnapshot();
|
|
1295
|
+
if (snapshot && 'children' in snapshot) {
|
|
1296
|
+
for (const child of Object.values(snapshot.children)) {
|
|
1297
|
+
unregisterRecursively(actorScope, child);
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
actorScope.system._unregister(actorRef);
|
|
1301
|
+
}
|
|
1251
1302
|
function executeStop(actorScope, actorRef) {
|
|
1252
1303
|
if (!actorRef) {
|
|
1253
1304
|
return;
|
|
@@ -1256,7 +1307,8 @@ function executeStop(actorScope, actorRef) {
|
|
|
1256
1307
|
// we need to eagerly unregister it here so a new actor with the same systemId can be registered immediately
|
|
1257
1308
|
// since we defer actual stopping of the actor but we don't defer actor creations (and we can't do that)
|
|
1258
1309
|
// this could throw on `systemId` collision, for example, when dealing with reentering transitions
|
|
1259
|
-
|
|
1310
|
+
// we also need to recursively unregister all nested children's systemIds
|
|
1311
|
+
unregisterRecursively(actorScope, actorRef);
|
|
1260
1312
|
|
|
1261
1313
|
// this allows us to prevent an actor from being started if it gets stopped within the same macrostep
|
|
1262
1314
|
// this can happen, for example, when the invoking state is being exited immediately by an always transition
|
|
@@ -1588,30 +1640,7 @@ function isInFinalState(stateNodeSet, stateNode) {
|
|
|
1588
1640
|
}
|
|
1589
1641
|
const isStateId = str => str[0] === STATE_IDENTIFIER;
|
|
1590
1642
|
function getCandidates(stateNode, receivedEventType) {
|
|
1591
|
-
const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(eventDescriptor =>
|
|
1592
|
-
// check if transition is a wildcard transition,
|
|
1593
|
-
// which matches any non-transient events
|
|
1594
|
-
if (eventDescriptor === WILDCARD) {
|
|
1595
|
-
return true;
|
|
1596
|
-
}
|
|
1597
|
-
if (!eventDescriptor.endsWith('.*')) {
|
|
1598
|
-
return false;
|
|
1599
|
-
}
|
|
1600
|
-
const partialEventTokens = eventDescriptor.split('.');
|
|
1601
|
-
const eventTokens = receivedEventType.split('.');
|
|
1602
|
-
for (let tokenIndex = 0; tokenIndex < partialEventTokens.length; tokenIndex++) {
|
|
1603
|
-
const partialEventToken = partialEventTokens[tokenIndex];
|
|
1604
|
-
const eventToken = eventTokens[tokenIndex];
|
|
1605
|
-
if (partialEventToken === '*') {
|
|
1606
|
-
const isLastToken = tokenIndex === partialEventTokens.length - 1;
|
|
1607
|
-
return isLastToken;
|
|
1608
|
-
}
|
|
1609
|
-
if (partialEventToken !== eventToken) {
|
|
1610
|
-
return false;
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
return true;
|
|
1614
|
-
}).sort((a, b) => b.length - a.length).flatMap(key => stateNode.transitions.get(key));
|
|
1643
|
+
const candidates = stateNode.transitions.get(receivedEventType) || [...stateNode.transitions.keys()].filter(eventDescriptor => matchesEventDescriptor(receivedEventType, eventDescriptor)).sort((a, b) => b.length - a.length).flatMap(key => stateNode.transitions.get(key));
|
|
1615
1644
|
return candidates;
|
|
1616
1645
|
}
|
|
1617
1646
|
|
|
@@ -2685,6 +2714,7 @@ exports.isMachineSnapshot = isMachineSnapshot;
|
|
|
2685
2714
|
exports.isStateId = isStateId;
|
|
2686
2715
|
exports.macrostep = macrostep;
|
|
2687
2716
|
exports.mapValues = mapValues;
|
|
2717
|
+
exports.matchesEventDescriptor = matchesEventDescriptor;
|
|
2688
2718
|
exports.matchesState = matchesState;
|
|
2689
2719
|
exports.microstep = microstep;
|
|
2690
2720
|
exports.not = not;
|