xstate 5.0.0-beta.42 → 5.0.0-beta.44
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 +2 -3
- package/actions/dist/xstate-actions.development.cjs.js +2 -3
- package/actions/dist/xstate-actions.development.esm.js +2 -3
- package/actions/dist/xstate-actions.esm.js +2 -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 +50 -6
- package/actors/dist/xstate-actors.development.cjs.js +50 -6
- package/actors/dist/xstate-actors.development.esm.js +45 -1
- package/actors/dist/xstate-actors.esm.js +45 -1
- package/actors/dist/xstate-actors.umd.min.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/declarations/src/State.d.ts +8 -12
- package/dist/declarations/src/actions/spawn.d.ts +11 -16
- package/dist/declarations/src/actors/promise.d.ts +53 -0
- package/dist/declarations/src/guards.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +1 -1
- package/dist/declarations/src/spawn.d.ts +9 -13
- package/dist/declarations/src/stateUtils.d.ts +4 -4
- package/dist/declarations/src/types.d.ts +56 -22
- package/dist/declarations/src/utils.d.ts +2 -10
- package/dist/{raise-6b64c553.cjs.js → raise-348cc74e.development.esm.js} +1007 -116
- package/dist/{raise-51ae36e5.development.esm.js → raise-5854eaca.esm.js} +925 -101
- package/dist/{raise-8f482ce9.development.cjs.js → raise-ed700d14.development.cjs.js} +986 -87
- package/dist/{raise-d2084327.esm.js → raise-fb6f017b.cjs.js} +972 -54
- package/dist/{send-cc8f864e.development.cjs.js → send-00466e37.development.cjs.js} +14 -17
- package/dist/{send-85b562d8.cjs.js → send-53e5693c.cjs.js} +14 -17
- package/dist/{send-7a350091.development.esm.js → send-a0193bdb.development.esm.js} +7 -10
- package/dist/{send-4e732fa5.esm.js → send-b7b4befa.esm.js} +7 -10
- package/dist/xstate.cjs.js +25 -25
- package/dist/xstate.cjs.mjs +1 -0
- package/dist/xstate.development.cjs.js +25 -25
- package/dist/xstate.development.cjs.mjs +1 -0
- package/dist/xstate.development.esm.js +5 -7
- package/dist/xstate.esm.js +5 -7
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/guards/dist/xstate-guards.cjs.js +1 -2
- package/guards/dist/xstate-guards.development.cjs.js +1 -2
- package/guards/dist/xstate-guards.development.esm.js +1 -2
- package/guards/dist/xstate-guards.esm.js +1 -2
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/interpreter-23e4041c.development.cjs.js +0 -905
- package/dist/interpreter-3d0c0ff2.esm.js +0 -864
- package/dist/interpreter-b6bdd134.cjs.js +0 -894
- package/dist/interpreter-f2620ea7.development.esm.js +0 -875
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MachineSnapshot } from "./State.js";
|
|
2
2
|
import type { StateNode } from "./StateNode.js";
|
|
3
|
-
import { AnyEventObject, AnyHistoryValue,
|
|
3
|
+
import { AnyEventObject, AnyHistoryValue, AnyMachineSnapshot, AnyStateNode, AnyTransitionDefinition, DelayedTransitionDefinition, EventObject, InitialTransitionConfig, InitialTransitionDefinition, MachineContext, StateValue, StateValueMap, TransitionDefinition, TODO, UnknownAction, AnyTransitionConfig, AnyActorScope } from "./types.js";
|
|
4
4
|
type Configuration<TContext extends MachineContext, TE extends EventObject> = Iterable<StateNode<TContext, TE>>;
|
|
5
5
|
type AnyConfiguration = Configuration<any, any>;
|
|
6
6
|
type AdjList = Map<AnyStateNode, Array<AnyStateNode>>;
|
|
@@ -45,9 +45,9 @@ export declare function removeConflictingTransitions(enabledTransitions: Array<A
|
|
|
45
45
|
/**
|
|
46
46
|
* https://www.w3.org/TR/scxml/#microstepProcedure
|
|
47
47
|
*/
|
|
48
|
-
export declare function microstep<TContext extends MachineContext, TEvent extends EventObject>(transitions: Array<AnyTransitionDefinition>, currentState:
|
|
49
|
-
export declare function resolveActionsAndContext(currentState:
|
|
50
|
-
export declare function macrostep(state:
|
|
48
|
+
export declare function microstep<TContext extends MachineContext, TEvent extends EventObject>(transitions: Array<AnyTransitionDefinition>, currentState: AnyMachineSnapshot, actorScope: AnyActorScope, event: AnyEventObject, isInitial: boolean, internalQueue: Array<AnyEventObject>): AnyMachineSnapshot;
|
|
49
|
+
export declare function resolveActionsAndContext(currentState: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope, actions: UnknownAction[], internalQueue: AnyEventObject[], deferredActorIds?: string[]): AnyMachineSnapshot;
|
|
50
|
+
export declare function macrostep(state: AnyMachineSnapshot, event: EventObject, actorScope: AnyActorScope, internalQueue?: AnyEventObject[]): {
|
|
51
51
|
state: typeof state;
|
|
52
52
|
microstates: Array<typeof state>;
|
|
53
53
|
};
|
|
@@ -33,6 +33,7 @@ export type NonReducibleUnknown = {} | null | undefined;
|
|
|
33
33
|
export type AnyFunction = (...args: any[]) => any;
|
|
34
34
|
type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
|
|
35
35
|
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
36
|
+
export type IsNotNever<T> = [T] extends [never] ? false : true;
|
|
36
37
|
export type Compute<A extends any> = {
|
|
37
38
|
[K in keyof A]: A[K];
|
|
38
39
|
} & unknown;
|
|
@@ -97,7 +98,7 @@ export interface ChooseBranch<TContext extends MachineContext, TExpressionEvent
|
|
|
97
98
|
export type NoRequiredParams<T extends ParameterizedObject> = T extends any ? {
|
|
98
99
|
type: T['type'];
|
|
99
100
|
} extends T ? T['type'] : never : never;
|
|
100
|
-
type ConditionalRequired<T, Condition extends boolean> = Condition extends true ? Required<T> : T;
|
|
101
|
+
export type ConditionalRequired<T, Condition extends boolean> = Condition extends true ? Required<T> : T;
|
|
101
102
|
export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent extends EventObject, T extends ParameterizedObject> = T extends any ? ConditionalRequired<{
|
|
102
103
|
type: T['type'];
|
|
103
104
|
params?: T['params'] | (({ context, event }: {
|
|
@@ -108,7 +109,7 @@ export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent
|
|
|
108
109
|
export type Action<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = NoRequiredParams<TAction> | WithDynamicParams<TContext, TExpressionEvent, TAction> | ActionFunction<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay>;
|
|
109
110
|
export type UnknownAction = Action<MachineContext, EventObject, EventObject, ParameterizedObject['params'] | undefined, ProvidedActor, ParameterizedObject, ParameterizedObject, string>;
|
|
110
111
|
export type Actions<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = SingleOrArray<Action<TContext, TExpressionEvent, TEvent, TParams, TActor, TAction, TGuard, TDelay>>;
|
|
111
|
-
export type StateKey = string |
|
|
112
|
+
export type StateKey = string | AnyMachineSnapshot;
|
|
112
113
|
export interface StateValueMap {
|
|
113
114
|
[key: string]: StateValue;
|
|
114
115
|
}
|
|
@@ -186,6 +187,11 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
186
187
|
* The source of the machine to be invoked, or the machine itself.
|
|
187
188
|
*/
|
|
188
189
|
src: TSrc;
|
|
190
|
+
/**
|
|
191
|
+
* The unique identifier for the invoked machine. If not specified, this
|
|
192
|
+
* will be the machine's own `id`, or the URL (from `src`).
|
|
193
|
+
*/
|
|
194
|
+
id?: TSpecificActor['id'];
|
|
189
195
|
input?: Mapper<TContext, TEvent, InputFrom<TSpecificActor['logic']>, TEvent> | InputFrom<TSpecificActor['logic']>;
|
|
190
196
|
/**
|
|
191
197
|
* The transition to take upon the invoked child machine reaching its final top-level state.
|
|
@@ -196,19 +202,9 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
196
202
|
*/
|
|
197
203
|
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
198
204
|
onSnapshot?: string | SingleOrArray<TransitionConfigOrTarget<TContext, SnapshotEvent<SnapshotFrom<TSpecificActor['logic']>>, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
199
|
-
} &
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
* will be the machine's own `id`, or the URL (from `src`).
|
|
203
|
-
*/
|
|
204
|
-
id: TSpecificActor['id'];
|
|
205
|
-
} : {
|
|
206
|
-
/**
|
|
207
|
-
* The unique identifier for the invoked machine. If not specified, this
|
|
208
|
-
* will be the machine's own `id`, or the URL (from `src`).
|
|
209
|
-
*/
|
|
210
|
-
id?: string;
|
|
211
|
-
})> : never;
|
|
205
|
+
} & {
|
|
206
|
+
[K in RequiredActorOptions<TSpecificActor>]: unknown;
|
|
207
|
+
}> : never;
|
|
212
208
|
export type InvokeConfig<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string> = IsLiteralString<TActor['src']> extends true ? DistributeActors<TContext, TEvent, TActor, TAction, TGuard, TDelay, TActor> : {
|
|
213
209
|
/**
|
|
214
210
|
* The unique identifier for the invoked machine. If not specified, this
|
|
@@ -347,7 +343,9 @@ export interface StateMachineDefinition<TContext extends MachineContext, TEvent
|
|
|
347
343
|
}
|
|
348
344
|
export type AnyStateNode = StateNode<any, any>;
|
|
349
345
|
export type AnyStateNodeDefinition = StateNodeDefinition<any, any>;
|
|
350
|
-
export type
|
|
346
|
+
export type AnyMachineSnapshot = MachineSnapshot<any, any, any, any, any, any>;
|
|
347
|
+
/** @deprecated use `AnyMachineSnapshot` instead */
|
|
348
|
+
export type AnyState = AnyMachineSnapshot;
|
|
351
349
|
export type AnyStateMachine = StateMachine<any, any, any, any, any, any, any, any, any, // delays
|
|
352
350
|
any>;
|
|
353
351
|
export type AnyStateConfig = StateConfig<any, AnyEventObject>;
|
|
@@ -387,11 +385,8 @@ type MaybeNarrowedEvent<TIndexedEvents, TCausingLookup, K> = Cast<Prop<TIndexedE
|
|
|
387
385
|
type MachineImplementationsActions<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingActions'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActors'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>, TIndexedGuards = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedGuards'>, TIndexedDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedDelays'>> = {
|
|
388
386
|
[K in keyof TIndexedActions]?: ActionFunction<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingActions, K>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>, GetParameterizedParams<Cast<TIndexedActions[K], ParameterizedObject>>, Cast<Prop<TIndexedActors, keyof TIndexedActors>, ProvidedActor>, Cast<Prop<TIndexedActions, keyof TIndexedActions>, ParameterizedObject>, Cast<Prop<TIndexedGuards, keyof TIndexedGuards>, ParameterizedObject>, Cast<Prop<TIndexedDelays, keyof TIndexedDelays>, ParameterizedObject>['type']>;
|
|
389
387
|
};
|
|
390
|
-
type MachineImplementationsActors<
|
|
391
|
-
[K in keyof TIndexedActors]?: Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic
|
|
392
|
-
src: Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>;
|
|
393
|
-
input: Mapper<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingActors, K>, InputFrom<Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>>, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>> | InputFrom<Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>>;
|
|
394
|
-
};
|
|
388
|
+
type MachineImplementationsActors<_TContext extends MachineContext, TResolvedTypesMeta, TIndexedActors = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActors'>, _TInvokeSrcNameMap = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'invokeSrcNameMap'>> = {
|
|
389
|
+
[K in keyof TIndexedActors]?: Cast<Prop<TIndexedActors[K], 'logic'>, AnyActorLogic>;
|
|
395
390
|
};
|
|
396
391
|
type MachineImplementationsDelays<TContext extends MachineContext, TResolvedTypesMeta, TEventsCausingDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'eventsCausingDelays'>, TIndexedEvents = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedEvents'>, TIndexedActions = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedActions'>, TIndexedDelays = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'indexedDelays'>> = {
|
|
397
392
|
[K in keyof TIndexedDelays]?: DelayConfig<TContext, MaybeNarrowedEvent<TIndexedEvents, TEventsCausingDelays, K>, Cast<Prop<Prop<TIndexedActions, keyof TIndexedActions>, 'params'>, ParameterizedObject['params'] | undefined> | undefined, Cast<Prop<TIndexedEvents, keyof TIndexedEvents>, EventObject>>;
|
|
@@ -777,14 +772,52 @@ export type Snapshot<TOutput> = {
|
|
|
777
772
|
output: undefined;
|
|
778
773
|
error: undefined;
|
|
779
774
|
};
|
|
775
|
+
/**
|
|
776
|
+
* Represents logic which can be used by an actor.
|
|
777
|
+
*
|
|
778
|
+
* @template TSnapshot - The type of the snapshot.
|
|
779
|
+
* @template TEvent - The type of the event object.
|
|
780
|
+
* @template TInput - The type of the input.
|
|
781
|
+
* @template TSystem - The type of the actor system.
|
|
782
|
+
*/
|
|
780
783
|
export interface ActorLogic<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput = unknown, TSystem extends ActorSystem<any> = ActorSystem<any>> {
|
|
784
|
+
/** The initial setup/configuration used to create the actor logic. */
|
|
781
785
|
config?: unknown;
|
|
786
|
+
/**
|
|
787
|
+
* Transition function that processes the current state and an incoming message
|
|
788
|
+
* to produce a new state.
|
|
789
|
+
* @param state - The current state.
|
|
790
|
+
* @param message - The incoming message.
|
|
791
|
+
* @param ctx - The actor scope.
|
|
792
|
+
* @returns The new state.
|
|
793
|
+
*/
|
|
782
794
|
transition: (state: TSnapshot, message: TEvent, ctx: ActorScope<TSnapshot, TEvent, TSystem>) => TSnapshot;
|
|
795
|
+
/**
|
|
796
|
+
* Called to provide the initial state of the actor.
|
|
797
|
+
* @param actorScope - The actor scope.
|
|
798
|
+
* @param input - The input for the initial state.
|
|
799
|
+
* @returns The initial state.
|
|
800
|
+
*/
|
|
783
801
|
getInitialState: (actorScope: ActorScope<TSnapshot, TEvent, TSystem>, input: TInput) => TSnapshot;
|
|
802
|
+
/**
|
|
803
|
+
* Called when Actor is created to restore the internal state of the actor given a persisted state.
|
|
804
|
+
* The persisted state can be created by `getPersistedState`.
|
|
805
|
+
* @param persistedState - The persisted state to restore from.
|
|
806
|
+
* @param actorScope - The actor scope.
|
|
807
|
+
* @returns The restored state.
|
|
808
|
+
*/
|
|
784
809
|
restoreState?: (persistedState: Snapshot<unknown>, actorScope: ActorScope<TSnapshot, TEvent>) => TSnapshot;
|
|
810
|
+
/**
|
|
811
|
+
* Called when the actor is started.
|
|
812
|
+
* @param state - The starting state.
|
|
813
|
+
* @param actorScope - The actor scope.
|
|
814
|
+
*/
|
|
785
815
|
start?: (state: TSnapshot, actorScope: ActorScope<TSnapshot, TEvent>) => void;
|
|
786
816
|
/**
|
|
787
|
-
*
|
|
817
|
+
* Obtains the internal state of the actor in a representation which can be be persisted.
|
|
818
|
+
* The persisted state can be restored by `restoreState`.
|
|
819
|
+
* @param state - The current state.
|
|
820
|
+
* @returns The a representation of the internal state to be persisted.
|
|
788
821
|
*/
|
|
789
822
|
getPersistedState: (state: TSnapshot, options?: unknown) => Snapshot<unknown>;
|
|
790
823
|
}
|
|
@@ -815,4 +848,5 @@ export interface ActorSystem<T extends ActorSystemInfo> {
|
|
|
815
848
|
inspect: (observer: Observer<InspectionEvent>) => void;
|
|
816
849
|
}
|
|
817
850
|
export type AnyActorSystem = ActorSystem<any>;
|
|
851
|
+
export type RequiredActorOptions<TActor extends ProvidedActor> = ('id' extends keyof TActor ? 'id' : never) | (undefined extends InputFrom<TActor['logic']> ? never : 'input');
|
|
818
852
|
export {};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { AnyActorLogic, AnyState } from "./index.js";
|
|
2
1
|
import type { StateNode } from "./StateNode.js";
|
|
3
2
|
import type { ActorLogic, AnyEventObject, EventObject, MachineContext, Mapper, Observer, ErrorActorEvent, SingleOrArray, StateLike, StateValue, Subscribable, TransitionConfigTarget, AnyActorRef, AnyTransitionConfig, NonReducibleUnknown, AnyStateMachine } from "./types.js";
|
|
4
3
|
export declare function keys<T extends object>(value: T): Array<keyof T & string>;
|
|
5
4
|
export declare function matchesState(parentStateId: StateValue, childStateId: StateValue): boolean;
|
|
6
5
|
export declare function toStatePath(stateId: string | string[]): string[];
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function toStateValue(stateValue: StateLike<any> | StateValue | string[]): StateValue;
|
|
6
|
+
export declare function toStateValue(stateValue: StateLike<any> | StateValue): StateValue;
|
|
9
7
|
export declare function pathToStateValue(statePath: string[]): StateValue;
|
|
10
8
|
export declare function mapValues<P, O extends Record<string, unknown>>(collection: O, iteratee: (item: O[keyof O], key: keyof O, collection: O, i: number) => P): {
|
|
11
9
|
[key in keyof O]: P;
|
|
@@ -39,10 +37,4 @@ export declare function normalizeTarget<TContext extends MachineContext, TEvent
|
|
|
39
37
|
export declare function reportUnhandledExceptionOnInvocation(originalError: any, currentError: any, id: string): void;
|
|
40
38
|
export declare function toObserver<T>(nextHandler?: Observer<T> | ((value: T) => void), errorHandler?: (error: any) => void, completionHandler?: () => void): Observer<T>;
|
|
41
39
|
export declare function createInvokeId(stateNodeId: string, index: number): string;
|
|
42
|
-
export declare function resolveReferencedActor(machine: AnyStateMachine, src: string):
|
|
43
|
-
src: AnyActorLogic;
|
|
44
|
-
input: NonReducibleUnknown | Mapper<any, any, unknown, any>;
|
|
45
|
-
} | {
|
|
46
|
-
src: any;
|
|
47
|
-
input: undefined;
|
|
48
|
-
} | undefined;
|
|
40
|
+
export declare function resolveReferencedActor(machine: AnyStateMachine, src: string): any;
|