xstate 5.0.0-beta.43 → 5.0.0-beta.45
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 +98 -10
- package/actors/dist/xstate-actors.development.cjs.js +98 -10
- package/actors/dist/xstate-actors.development.esm.js +93 -5
- package/actors/dist/xstate-actors.esm.js +93 -5
- 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 +14 -18
- package/dist/declarations/src/StateMachine.d.ts +1 -1
- package/dist/declarations/src/actions/choose.d.ts +3 -3
- package/dist/declarations/src/actions/pure.d.ts +4 -4
- package/dist/declarations/src/actions/spawn.d.ts +11 -16
- package/dist/declarations/src/actors/observable.d.ts +39 -0
- package/dist/declarations/src/actors/transition.d.ts +53 -4
- package/dist/declarations/src/{Machine.d.ts → createMachine.d.ts} +1 -1
- package/dist/declarations/src/guards.d.ts +27 -5
- package/dist/declarations/src/index.d.ts +3 -2
- package/dist/declarations/src/interpreter.d.ts +1 -0
- package/dist/declarations/src/setup.d.ts +32 -0
- package/dist/declarations/src/spawn.d.ts +9 -13
- package/dist/declarations/src/stateUtils.d.ts +11 -11
- package/dist/declarations/src/types.d.ts +31 -29
- package/dist/declarations/src/utils.d.ts +1 -3
- package/dist/{raise-8dc8e1aa.esm.js → raise-2b5a4e4c.esm.js} +934 -103
- package/dist/{raise-f4ad5a87.development.esm.js → raise-90139fbc.development.esm.js} +945 -103
- package/dist/{raise-23dea0d7.development.cjs.js → raise-b3fb3c65.development.cjs.js} +999 -137
- package/dist/{raise-e0fe5c2d.cjs.js → raise-fabffc3d.cjs.js} +986 -135
- package/dist/{send-5d129d95.development.esm.js → send-24cc8018.development.esm.js} +4 -30
- package/dist/{send-84e2e742.esm.js → send-8e7e41e7.esm.js} +4 -30
- package/dist/{send-87bbaaab.cjs.js → send-c124176f.cjs.js} +13 -39
- package/dist/{send-0174c155.development.cjs.js → send-d0bc7eed.development.cjs.js} +13 -39
- package/dist/xstate.cjs.js +67 -35
- package/dist/xstate.cjs.mjs +2 -0
- package/dist/xstate.development.cjs.js +67 -35
- package/dist/xstate.development.cjs.mjs +2 -0
- package/dist/xstate.development.esm.js +42 -13
- package/dist/xstate.esm.js +42 -13
- 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 +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/interpreter-36d5556e.cjs.js +0 -887
- package/dist/interpreter-4e8e2a0d.development.cjs.js +0 -898
- package/dist/interpreter-63c80754.esm.js +0 -857
- package/dist/interpreter-80eb3bec.development.esm.js +0 -868
|
@@ -5,13 +5,62 @@ export type TransitionSnapshot<TContext> = Snapshot<undefined> & {
|
|
|
5
5
|
export type TransitionActorLogic<TContext, TEvent extends EventObject, TInput> = ActorLogic<TransitionSnapshot<TContext>, TEvent, TInput, AnyActorSystem>;
|
|
6
6
|
export type TransitionActorRef<TContext, TEvent extends EventObject> = ActorRefFrom<TransitionActorLogic<TransitionSnapshot<TContext>, TEvent, unknown>>;
|
|
7
7
|
/**
|
|
8
|
-
* Returns actor logic
|
|
8
|
+
* Returns actor logic given a transition function and its initial state.
|
|
9
9
|
*
|
|
10
|
-
* A transition function is a function that takes the current state and
|
|
10
|
+
* A “transition function” is a function that takes the current `state` and received `event` object as arguments, and returns the next state, similar to a reducer.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Actors created from transition logic (“transition actors”) can:
|
|
13
|
+
*
|
|
14
|
+
* - Receive events
|
|
15
|
+
* - Emit snapshots of its state
|
|
16
|
+
*
|
|
17
|
+
* The transition function’s `state` is used as its transition actor’s `context`.
|
|
18
|
+
*
|
|
19
|
+
* Note that the "state" for a transition function is provided by the initial state argument, and is not the same as the State object of an actor or a state within a machine configuration.
|
|
20
|
+
*
|
|
21
|
+
* @param transition The transition function used to describe the transition logic. It should return the next state given the current state and event. It receives the following arguments:
|
|
22
|
+
* - `state` - the current state.
|
|
23
|
+
* - `event` - the received event.
|
|
24
|
+
* - `actorScope` - the actor scope object, with properties like `self` and `system`.
|
|
25
|
+
* @param initialContext The initial state of the transition function, either an object representing the state, or a function which returns a state object. If a function, it will receive as its only argument an object with the following properties:
|
|
26
|
+
* - `input` - the `input` provided to its parent transition actor.
|
|
27
|
+
* - `self` - a reference to its parent transition actor.
|
|
28
|
+
* @see {@link https://stately.ai/docs/input | Input docs} for more information about how input is passed
|
|
14
29
|
* @returns Actor logic
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const transitionLogic = fromTransition(
|
|
34
|
+
* (state, event) => {
|
|
35
|
+
* if (event.type === 'increment') {
|
|
36
|
+
* return {
|
|
37
|
+
* ...state,
|
|
38
|
+
* count: state.count + 1,
|
|
39
|
+
* };
|
|
40
|
+
* }
|
|
41
|
+
* return state;
|
|
42
|
+
* },
|
|
43
|
+
* { count: 0 },
|
|
44
|
+
* );
|
|
45
|
+
*
|
|
46
|
+
* const transitionActor = createActor(transitionLogic);
|
|
47
|
+
* transitionActor.subscribe((snapshot) => {
|
|
48
|
+
* console.log(snapshot);
|
|
49
|
+
* });
|
|
50
|
+
* transitionActor.start();
|
|
51
|
+
* // => {
|
|
52
|
+
* // status: 'active',
|
|
53
|
+
* // context: { count: 0 },
|
|
54
|
+
* // ...
|
|
55
|
+
* // }
|
|
56
|
+
*
|
|
57
|
+
* transitionActor.send({ type: 'increment' });
|
|
58
|
+
* // => {
|
|
59
|
+
* // status: 'active',
|
|
60
|
+
* // context: { count: 1 },
|
|
61
|
+
* // ...
|
|
62
|
+
* // }
|
|
63
|
+
* ```
|
|
15
64
|
*/
|
|
16
65
|
export declare function fromTransition<TContext, TEvent extends EventObject, TSystem extends ActorSystem<any>, TInput>(transition: (state: TContext, event: TEvent, actorScope: ActorScope<TransitionSnapshot<TContext>, TEvent, TSystem>) => TContext, initialContext: TContext | (({ input, self }: {
|
|
17
66
|
input: TInput;
|
|
@@ -2,4 +2,4 @@ import { MachineConfig, MachineContext, InternalMachineImplementations, Paramete
|
|
|
2
2
|
import { TypegenConstraint, ResolveTypegenMeta, TypegenDisabled } from "./typegenTypes.js";
|
|
3
3
|
import { StateMachine } from "./StateMachine.js";
|
|
4
4
|
export declare function createMachine<TContext extends MachineContext, TEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
|
|
5
|
-
TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TTypesMeta>, implementations?: InternalMachineImplementations<TContext,
|
|
5
|
+
TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, TEvent, TActor, TAction, TGuard, TDelay, TTag, TInput, TOutput, TTypesMeta>, implementations?: InternalMachineImplementations<TContext, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>): StateMachine<TContext, TEvent, TActor, TAction, TGuard, TDelay, Prop<ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>['resolved'], 'tags'> & string, TInput, TOutput, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>;
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import type { EventObject, StateValue, MachineContext, ParameterizedObject,
|
|
1
|
+
import type { EventObject, StateValue, MachineContext, ParameterizedObject, AnyMachineSnapshot, NoRequiredParams, NoInfer, WithDynamicParams, Identity, Elements } from "./types.js";
|
|
2
|
+
type SingleGuardArg<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TGuardArg> = [TGuardArg] extends [{
|
|
3
|
+
type: string;
|
|
4
|
+
}] ? Identity<TGuardArg> : [TGuardArg] extends [string] ? TGuardArg : GuardPredicate<TContext, TExpressionEvent, TParams, ParameterizedObject>;
|
|
5
|
+
type NormalizeGuardArg<TGuardArg> = TGuardArg extends {
|
|
6
|
+
type: string;
|
|
7
|
+
} ? Identity<TGuardArg> & {
|
|
8
|
+
params: unknown;
|
|
9
|
+
} : TGuardArg extends string ? {
|
|
10
|
+
type: TGuardArg;
|
|
11
|
+
params: undefined;
|
|
12
|
+
} : '_out_TGuard' extends keyof TGuardArg ? TGuardArg['_out_TGuard'] & ParameterizedObject : never;
|
|
13
|
+
type NormalizeGuardArgArray<TArg extends unknown[]> = Elements<{
|
|
14
|
+
[K in keyof TArg]: NormalizeGuardArg<TArg[K]>;
|
|
15
|
+
}>;
|
|
2
16
|
export type GuardPredicate<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined, TGuard extends ParameterizedObject> = {
|
|
3
17
|
(args: GuardArgs<TContext, TExpressionEvent>, params: TParams): boolean;
|
|
4
18
|
_out_TGuard?: TGuard;
|
|
@@ -12,8 +26,16 @@ export type UnknownGuard = UnknownReferencedGuard | UnknownInlineGuard;
|
|
|
12
26
|
type UnknownReferencedGuard = Guard<MachineContext, EventObject, ParameterizedObject['params'], ParameterizedObject>;
|
|
13
27
|
type UnknownInlineGuard = Guard<MachineContext, EventObject, undefined, ParameterizedObject>;
|
|
14
28
|
export declare function stateIn<TContext extends MachineContext, TExpressionEvent extends EventObject, TParams extends ParameterizedObject['params'] | undefined>(stateValue: StateValue): GuardPredicate<TContext, TExpressionEvent, TParams, any>;
|
|
15
|
-
export declare function not<TContext extends MachineContext, TExpressionEvent extends EventObject,
|
|
16
|
-
export declare function and<TContext extends MachineContext, TExpressionEvent extends EventObject,
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
export declare function not<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg>(guard: SingleGuardArg<TContext, TExpressionEvent, unknown, TArg>): GuardPredicate<TContext, TExpressionEvent, unknown, NormalizeGuardArg<NoInfer<TArg>>>;
|
|
30
|
+
export declare function and<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg extends unknown[]>(guards: readonly [
|
|
31
|
+
...{
|
|
32
|
+
[K in keyof TArg]: SingleGuardArg<TContext, TExpressionEvent, unknown, TArg[K]>;
|
|
33
|
+
}
|
|
34
|
+
]): GuardPredicate<TContext, TExpressionEvent, unknown, NormalizeGuardArgArray<NoInfer<TArg>>>;
|
|
35
|
+
export declare function or<TContext extends MachineContext, TExpressionEvent extends EventObject, TArg extends unknown[]>(guards: readonly [
|
|
36
|
+
...{
|
|
37
|
+
[K in keyof TArg]: SingleGuardArg<TContext, TExpressionEvent, unknown, TArg[K]>;
|
|
38
|
+
}
|
|
39
|
+
]): GuardPredicate<TContext, TExpressionEvent, unknown, NormalizeGuardArgArray<NoInfer<TArg>>>;
|
|
40
|
+
export declare function evaluateGuard<TContext extends MachineContext, TExpressionEvent extends EventObject>(guard: UnknownGuard | UnknownInlineGuard, context: TContext, event: TExpressionEvent, state: AnyMachineSnapshot): boolean;
|
|
19
41
|
export {};
|
|
@@ -8,13 +8,14 @@ export * from "./typegenTypes.js";
|
|
|
8
8
|
export * from "./types.js";
|
|
9
9
|
export { waitFor } from "./waitFor.js";
|
|
10
10
|
import { Actor, createActor, interpret, Interpreter } from "./interpreter.js";
|
|
11
|
-
import { createMachine } from "./
|
|
12
|
-
export { type MachineSnapshot } from "./State.js";
|
|
11
|
+
import { createMachine } from "./createMachine.js";
|
|
12
|
+
export { type MachineSnapshot, isMachineSnapshot } from "./State.js";
|
|
13
13
|
import { StateNode } from "./StateNode.js";
|
|
14
14
|
export { matchesState, pathToStateValue, toObserver } from "./utils.js";
|
|
15
15
|
export { Actor, createActor, createMachine, interpret, StateNode, type Interpreter };
|
|
16
16
|
export type { InspectedActorEvent, InspectedEventEvent, InspectedSnapshotEvent, InspectionEvent } from "./system.js";
|
|
17
17
|
export { and, not, or, stateIn } from "./guards.js";
|
|
18
|
+
export { setup } from "./setup.js";
|
|
18
19
|
declare global {
|
|
19
20
|
interface SymbolConstructor {
|
|
20
21
|
readonly observable: symbol;
|
|
@@ -39,6 +39,7 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorRef<Eve
|
|
|
39
39
|
private observers;
|
|
40
40
|
private logger;
|
|
41
41
|
_parent?: ActorRef<any, any>;
|
|
42
|
+
_syncSnapshot?: boolean;
|
|
42
43
|
ref: ActorRef<EventFromLogic<TLogic>, SnapshotFrom<TLogic>>;
|
|
43
44
|
private _actorScope;
|
|
44
45
|
private _systemId;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ResolveTypegenMeta, StateMachine, TypegenDisabled } from "./index.js";
|
|
2
|
+
import { GuardPredicate } from "./guards.js";
|
|
3
|
+
import { AnyActorLogic, MachineContext, AnyEventObject, NonReducibleUnknown, MachineConfig, Values, ParameterizedObject, ActionFunction, SetupTypes, DelayConfig } from "./types.js";
|
|
4
|
+
type ToParameterizedObject<TParameterizedMap extends Record<string, ParameterizedObject['params'] | undefined>> = Values<{
|
|
5
|
+
[K in keyof TParameterizedMap & string]: {
|
|
6
|
+
type: K;
|
|
7
|
+
params: TParameterizedMap[K];
|
|
8
|
+
};
|
|
9
|
+
}>;
|
|
10
|
+
type ToProvidedActor<TActors extends Record<string, AnyActorLogic>> = Values<{
|
|
11
|
+
[K in keyof TActors & string]: {
|
|
12
|
+
src: K;
|
|
13
|
+
logic: TActors[K];
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
16
|
+
export declare function setup<TContext extends MachineContext, TEvent extends AnyEventObject, // TODO: consider using a stricter `EventObject` here
|
|
17
|
+
TActors extends Record<string, AnyActorLogic>, TActions extends Record<string, ParameterizedObject['params'] | undefined>, TGuards extends Record<string, ParameterizedObject['params'] | undefined>, TDelay extends string, TTag extends string, TInput, TOutput extends NonReducibleUnknown>({ actors, actions, guards, delays }: {
|
|
18
|
+
types?: SetupTypes<TContext, TEvent, TTag, TInput, TOutput>;
|
|
19
|
+
actors?: TActors;
|
|
20
|
+
actions?: {
|
|
21
|
+
[K in keyof TActions]: ActionFunction<TContext, TEvent, TEvent, TActions[K], ToProvidedActor<TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay>;
|
|
22
|
+
};
|
|
23
|
+
guards?: {
|
|
24
|
+
[K in keyof TGuards]: GuardPredicate<TContext, TEvent, TGuards[K], ToParameterizedObject<TGuards>>;
|
|
25
|
+
};
|
|
26
|
+
delays?: {
|
|
27
|
+
[K in TDelay]: DelayConfig<TContext, TEvent, ToParameterizedObject<TActions>['params'], TEvent>;
|
|
28
|
+
};
|
|
29
|
+
}): {
|
|
30
|
+
createMachine: (config: MachineConfig<TContext, TEvent, ToProvidedActor<TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TInput, TOutput, ResolveTypegenMeta<TypegenDisabled, TEvent, ToProvidedActor<TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag>>) => StateMachine<TContext, TEvent, ToProvidedActor<TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TInput, TOutput, ResolveTypegenMeta<TypegenDisabled, TEvent, ToProvidedActor<TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag>>;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
import { ActorRefFrom, AnyActorScope, AnyActorLogic, AnyActorRef, AnyEventObject,
|
|
2
|
-
|
|
1
|
+
import { ActorRefFrom, AnyActorScope, AnyActorLogic, AnyActorRef, AnyEventObject, AnyMachineSnapshot, InputFrom, IsLiteralString, ProvidedActor, RequiredActorOptions, IsNotNever, ConditionalRequired } from "./types.js";
|
|
2
|
+
type SpawnOptions<TActor extends ProvidedActor, TSrc extends TActor['src']> = TActor extends {
|
|
3
3
|
src: TSrc;
|
|
4
|
-
} ?
|
|
5
|
-
options: {
|
|
6
|
-
id: TActor['id'];
|
|
7
|
-
systemId?: string;
|
|
8
|
-
input?: InputFrom<TActor['logic']>;
|
|
9
|
-
syncSnapshot?: boolean;
|
|
10
|
-
}
|
|
11
|
-
] : [
|
|
4
|
+
} ? ConditionalRequired<[
|
|
12
5
|
options?: {
|
|
13
|
-
id?:
|
|
6
|
+
id?: TActor['id'];
|
|
14
7
|
systemId?: string;
|
|
15
8
|
input?: InputFrom<TActor['logic']>;
|
|
16
9
|
syncSnapshot?: boolean;
|
|
10
|
+
} & {
|
|
11
|
+
[K in RequiredActorOptions<TActor>]: unknown;
|
|
17
12
|
}
|
|
18
|
-
] : never;
|
|
13
|
+
], IsNotNever<RequiredActorOptions<TActor>>> : never;
|
|
19
14
|
export type Spawner<TActor extends ProvidedActor> = IsLiteralString<TActor['src']> extends true ? <TSrc extends TActor['src']>(logic: TSrc, ...[options]: SpawnOptions<TActor, TSrc>) => ActorRefFrom<(TActor & {
|
|
20
15
|
src: TSrc;
|
|
21
16
|
})['logic']> : <TLogic extends AnyActorLogic | string>(src: TLogic, options?: {
|
|
@@ -24,4 +19,5 @@ export type Spawner<TActor extends ProvidedActor> = IsLiteralString<TActor['src'
|
|
|
24
19
|
input?: unknown;
|
|
25
20
|
syncSnapshot?: boolean;
|
|
26
21
|
}) => TLogic extends string ? AnyActorRef : ActorRefFrom<TLogic>;
|
|
27
|
-
export declare function createSpawner(actorScope: AnyActorScope, { machine, context }:
|
|
22
|
+
export declare function createSpawner(actorScope: AnyActorScope, { machine, context }: AnyMachineSnapshot, event: AnyEventObject, spawnedChildren: Record<string, AnyActorRef>): Spawner<any>;
|
|
23
|
+
export {};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { MachineSnapshot } from "./State.js";
|
|
2
2
|
import type { StateNode } from "./StateNode.js";
|
|
3
|
-
import { AnyEventObject, AnyHistoryValue,
|
|
4
|
-
type
|
|
5
|
-
type
|
|
3
|
+
import { AnyEventObject, AnyHistoryValue, AnyMachineSnapshot, AnyStateNode, AnyTransitionDefinition, DelayedTransitionDefinition, EventObject, InitialTransitionConfig, InitialTransitionDefinition, MachineContext, StateValue, StateValueMap, TransitionDefinition, TODO, UnknownAction, AnyTransitionConfig, AnyActorScope } from "./types.js";
|
|
4
|
+
type StateNodeIterable<TContext extends MachineContext, TE extends EventObject> = Iterable<StateNode<TContext, TE>>;
|
|
5
|
+
type AnyStateNodeIterable = StateNodeIterable<any, any>;
|
|
6
6
|
type AdjList = Map<AnyStateNode, Array<AnyStateNode>>;
|
|
7
7
|
export declare const isAtomicStateNode: (stateNode: StateNode<any, any>) => boolean;
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function getAdjList<TContext extends MachineContext, TE extends EventObject>(
|
|
10
|
-
export declare function getStateValue(rootNode: AnyStateNode,
|
|
11
|
-
export declare function isInFinalState(
|
|
8
|
+
export declare function getAllStateNodes(stateNodes: Iterable<AnyStateNode>): Set<AnyStateNode>;
|
|
9
|
+
export declare function getAdjList<TContext extends MachineContext, TE extends EventObject>(stateNodes: StateNodeIterable<TContext, TE>): AdjList;
|
|
10
|
+
export declare function getStateValue(rootNode: AnyStateNode, stateNodes: AnyStateNodeIterable): StateValue;
|
|
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
14
|
/**
|
|
@@ -41,13 +41,13 @@ export declare function transitionAtomicNode<TContext extends MachineContext, TE
|
|
|
41
41
|
export declare function transitionCompoundNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValueMap, state: MachineSnapshot<TContext, TEvent, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
42
42
|
export declare function transitionParallelNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValueMap, state: MachineSnapshot<TContext, TEvent, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
43
43
|
export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue, state: MachineSnapshot<TContext, TEvent, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
44
|
-
export declare function removeConflictingTransitions(enabledTransitions: Array<AnyTransitionDefinition>,
|
|
44
|
+
export declare function removeConflictingTransitions(enabledTransitions: Array<AnyTransitionDefinition>, stateNodeSet: Set<AnyStateNode>, historyValue: AnyHistoryValue): Array<AnyTransitionDefinition>;
|
|
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
|
};
|
|
@@ -8,6 +8,9 @@ import { Guard, GuardPredicate, UnknownGuard } from "./guards.js";
|
|
|
8
8
|
import { Spawner } from "./spawn.js";
|
|
9
9
|
import { AssignArgs } from "./actions/assign.js";
|
|
10
10
|
import { InspectionEvent } from './system.js';
|
|
11
|
+
export type Identity<T> = {
|
|
12
|
+
[K in keyof T]: T[K];
|
|
13
|
+
};
|
|
11
14
|
export type HomomorphicPick<T, K extends keyof any> = {
|
|
12
15
|
[P in keyof T as P & K]: T[P];
|
|
13
16
|
};
|
|
@@ -33,11 +36,13 @@ export type NonReducibleUnknown = {} | null | undefined;
|
|
|
33
36
|
export type AnyFunction = (...args: any[]) => any;
|
|
34
37
|
type ReturnTypeOrValue<T> = T extends AnyFunction ? ReturnType<T> : T;
|
|
35
38
|
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
39
|
+
export type IsNotNever<T> = [T] extends [never] ? false : true;
|
|
36
40
|
export type Compute<A extends any> = {
|
|
37
41
|
[K in keyof A]: A[K];
|
|
38
42
|
} & unknown;
|
|
39
43
|
export type Prop<T, K> = K extends keyof T ? T[K] : never;
|
|
40
44
|
export type Values<T> = T[keyof T];
|
|
45
|
+
export type Elements<T> = T[keyof T & `${number}`];
|
|
41
46
|
export type Merge<M, N> = Omit<M, keyof N> & N;
|
|
42
47
|
export type IndexByProp<T extends Record<P, string>, P extends keyof T> = {
|
|
43
48
|
[E in T as E[P]]: E;
|
|
@@ -67,7 +72,7 @@ export interface AnyEventObject extends EventObject {
|
|
|
67
72
|
}
|
|
68
73
|
export interface ParameterizedObject {
|
|
69
74
|
type: string;
|
|
70
|
-
params?:
|
|
75
|
+
params?: NonReducibleUnknown;
|
|
71
76
|
}
|
|
72
77
|
export interface UnifiedArg<TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject> {
|
|
73
78
|
context: TContext;
|
|
@@ -94,10 +99,8 @@ export interface ChooseBranch<TContext extends MachineContext, TExpressionEvent
|
|
|
94
99
|
guard?: Guard<TContext, TExpressionEvent, undefined, TGuard>;
|
|
95
100
|
actions: Actions<TContext, TExpressionEvent, TEvent, undefined, TActor, TAction, TGuard, TDelay>;
|
|
96
101
|
}
|
|
97
|
-
export type NoRequiredParams<T extends ParameterizedObject> = T extends any ?
|
|
98
|
-
|
|
99
|
-
} extends T ? T['type'] : never : never;
|
|
100
|
-
type ConditionalRequired<T, Condition extends boolean> = Condition extends true ? Required<T> : T;
|
|
102
|
+
export type NoRequiredParams<T extends ParameterizedObject> = T extends any ? undefined extends T['params'] ? T['type'] : never : never;
|
|
103
|
+
export type ConditionalRequired<T, Condition extends boolean> = Condition extends true ? Required<T> : T;
|
|
101
104
|
export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent extends EventObject, T extends ParameterizedObject> = T extends any ? ConditionalRequired<{
|
|
102
105
|
type: T['type'];
|
|
103
106
|
params?: T['params'] | (({ context, event }: {
|
|
@@ -108,7 +111,7 @@ export type WithDynamicParams<TContext extends MachineContext, TExpressionEvent
|
|
|
108
111
|
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
112
|
export type UnknownAction = Action<MachineContext, EventObject, EventObject, ParameterizedObject['params'] | undefined, ProvidedActor, ParameterizedObject, ParameterizedObject, string>;
|
|
110
113
|
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 |
|
|
114
|
+
export type StateKey = string | AnyMachineSnapshot;
|
|
112
115
|
export interface StateValueMap {
|
|
113
116
|
[key: string]: StateValue;
|
|
114
117
|
}
|
|
@@ -186,6 +189,11 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
186
189
|
* The source of the machine to be invoked, or the machine itself.
|
|
187
190
|
*/
|
|
188
191
|
src: TSrc;
|
|
192
|
+
/**
|
|
193
|
+
* The unique identifier for the invoked machine. If not specified, this
|
|
194
|
+
* will be the machine's own `id`, or the URL (from `src`).
|
|
195
|
+
*/
|
|
196
|
+
id?: TSpecificActor['id'];
|
|
189
197
|
input?: Mapper<TContext, TEvent, InputFrom<TSpecificActor['logic']>, TEvent> | InputFrom<TSpecificActor['logic']>;
|
|
190
198
|
/**
|
|
191
199
|
* The transition to take upon the invoked child machine reaching its final top-level state.
|
|
@@ -196,19 +204,9 @@ type DistributeActors<TContext extends MachineContext, TEvent extends EventObjec
|
|
|
196
204
|
*/
|
|
197
205
|
onError?: string | SingleOrArray<TransitionConfigOrTarget<TContext, ErrorActorEvent, TEvent, TActor, TAction, TGuard, TDelay>>;
|
|
198
206
|
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;
|
|
207
|
+
} & {
|
|
208
|
+
[K in RequiredActorOptions<TSpecificActor>]: unknown;
|
|
209
|
+
}> : never;
|
|
212
210
|
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
211
|
/**
|
|
214
212
|
* The unique identifier for the invoked machine. If not specified, this
|
|
@@ -347,7 +345,9 @@ export interface StateMachineDefinition<TContext extends MachineContext, TEvent
|
|
|
347
345
|
}
|
|
348
346
|
export type AnyStateNode = StateNode<any, any>;
|
|
349
347
|
export type AnyStateNodeDefinition = StateNodeDefinition<any, any>;
|
|
350
|
-
export type
|
|
348
|
+
export type AnyMachineSnapshot = MachineSnapshot<any, any, any, any, any, any>;
|
|
349
|
+
/** @deprecated use `AnyMachineSnapshot` instead */
|
|
350
|
+
export type AnyState = AnyMachineSnapshot;
|
|
351
351
|
export type AnyStateMachine = StateMachine<any, any, any, any, any, any, any, any, any, // delays
|
|
352
352
|
any>;
|
|
353
353
|
export type AnyStateConfig = StateConfig<any, AnyEventObject>;
|
|
@@ -414,8 +414,8 @@ type GenerateDelaysImplementationsPart<TContext extends MachineContext, TResolve
|
|
|
414
414
|
type GenerateGuardsImplementationsPart<TContext extends MachineContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> = Compute<MaybeMakeMissingImplementationsRequired<'guards', Prop<TMissingImplementations, 'guards'>, TRequireMissingImplementations> & {
|
|
415
415
|
guards?: MachineImplementationsGuards<TContext, TResolvedTypesMeta>;
|
|
416
416
|
}>;
|
|
417
|
-
export type InternalMachineImplementations<TContext extends MachineContext,
|
|
418
|
-
export type MachineImplementations<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string, TTag extends string = string, TTypesMeta extends TypegenConstraint = TypegenDisabled> = InternalMachineImplementations<TContext,
|
|
417
|
+
export type InternalMachineImplementations<TContext extends MachineContext, TResolvedTypesMeta, TRequireMissingImplementations extends boolean = false, TMissingImplementations = Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'missingImplementations'>> = Compute<GenerateActionsImplementationsPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateActorsImplementationsPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateDelaysImplementationsPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations> & GenerateGuardsImplementationsPart<TContext, TResolvedTypesMeta, TRequireMissingImplementations, TMissingImplementations>>;
|
|
418
|
+
export type MachineImplementations<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor = ProvidedActor, TAction extends ParameterizedObject = ParameterizedObject, TGuard extends ParameterizedObject = ParameterizedObject, TDelay extends string = string, TTag extends string = string, TTypesMeta extends TypegenConstraint = TypegenDisabled> = InternalMachineImplementations<TContext, ResolveTypegenMeta<TTypesMeta, TEvent, TActor, TAction, TGuard, TDelay, TTag>>;
|
|
419
419
|
type InitialContext<TContext extends MachineContext, TActor extends ProvidedActor, TInput> = TContext | ContextFactory<TContext, TActor, TInput>;
|
|
420
420
|
export type ContextFactory<TContext extends MachineContext, TActor extends ProvidedActor, TInput> = ({ spawn, input }: {
|
|
421
421
|
spawn: Spawner<TActor>;
|
|
@@ -441,16 +441,18 @@ export interface ProvidedActor {
|
|
|
441
441
|
logic: AnyActorLogic;
|
|
442
442
|
id?: string;
|
|
443
443
|
}
|
|
444
|
-
export interface
|
|
444
|
+
export interface SetupTypes<TContext extends MachineContext, TEvent extends EventObject, TTag extends string, TInput, TOutput> {
|
|
445
445
|
context?: TContext;
|
|
446
446
|
events?: TEvent;
|
|
447
|
+
tags?: TTag;
|
|
448
|
+
input?: TInput;
|
|
449
|
+
output?: TOutput;
|
|
450
|
+
}
|
|
451
|
+
export interface MachineTypes<TContext extends MachineContext, TEvent extends EventObject, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TTag extends string, TInput, TOutput, TTypesMeta = TypegenDisabled> extends SetupTypes<TContext, TEvent, TTag, TInput, TOutput> {
|
|
447
452
|
actors?: TActor;
|
|
448
453
|
actions?: TAction;
|
|
449
454
|
guards?: TGuard;
|
|
450
455
|
delays?: TDelay;
|
|
451
|
-
tags?: TTag;
|
|
452
|
-
input?: TInput;
|
|
453
|
-
output?: TOutput;
|
|
454
456
|
typegen?: TTypesMeta;
|
|
455
457
|
}
|
|
456
458
|
export interface HistoryStateNode<TContext extends MachineContext> extends StateNode<TContext> {
|
|
@@ -541,7 +543,6 @@ export interface StateLike<TContext extends MachineContext> {
|
|
|
541
543
|
export interface StateConfig<TContext extends MachineContext, TEvent extends EventObject> {
|
|
542
544
|
context: TContext;
|
|
543
545
|
historyValue?: HistoryValue<TContext, TEvent>;
|
|
544
|
-
configuration: Array<StateNode<TContext, TEvent>>;
|
|
545
546
|
children: Record<string, ActorRef<any, any>>;
|
|
546
547
|
status: 'active' | 'done' | 'error' | 'stopped';
|
|
547
548
|
output?: any;
|
|
@@ -601,7 +602,7 @@ export interface ActorOptions<TLogic extends AnyActorLogic> {
|
|
|
601
602
|
*
|
|
602
603
|
* @see https://stately.ai/docs/persistence
|
|
603
604
|
*/
|
|
604
|
-
state?:
|
|
605
|
+
state?: Snapshot<unknown>;
|
|
605
606
|
/**
|
|
606
607
|
* The source definition.
|
|
607
608
|
*/
|
|
@@ -736,7 +737,7 @@ export type DevToolsAdapter = (service: AnyActor) => void;
|
|
|
736
737
|
* @deprecated Use `Actor<T>` instead.
|
|
737
738
|
*/
|
|
738
739
|
export type InterpreterFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine)> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer TEvent, infer TActor, infer _TAction, infer _TGuard, infer _TDelay, infer TTag, infer TInput, infer TOutput, infer TResolvedTypesMeta> ? Actor<ActorLogic<MachineSnapshot<TContext, TEvent, TActor, TTag, TOutput, TResolvedTypesMeta>, TEvent, TInput, ActorSystem<any>>> : never;
|
|
739
|
-
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer
|
|
740
|
+
export type MachineImplementationsFrom<T extends AnyStateMachine | ((...args: any[]) => AnyStateMachine), TRequireMissingImplementations extends boolean = false> = ReturnTypeOrValue<T> extends StateMachine<infer TContext, infer _TEvent, infer _TActor, infer _TAction, infer _TGuard, infer _TDelay, infer _TTag, infer _TInput, infer _TOutput, infer TResolvedTypesMeta> ? InternalMachineImplementations<TContext, TResolvedTypesMeta, TRequireMissingImplementations> : never;
|
|
740
741
|
export type __ResolvedTypesMetaFrom<T> = T extends StateMachine<any, // context
|
|
741
742
|
any, // event
|
|
742
743
|
any, // actor
|
|
@@ -850,4 +851,5 @@ export interface ActorSystem<T extends ActorSystemInfo> {
|
|
|
850
851
|
inspect: (observer: Observer<InspectionEvent>) => void;
|
|
851
852
|
}
|
|
852
853
|
export type AnyActorSystem = ActorSystem<any>;
|
|
854
|
+
export type RequiredActorOptions<TActor extends ProvidedActor> = ('id' extends keyof TActor ? 'id' : never) | (undefined extends InputFrom<TActor['logic']> ? never : 'input');
|
|
853
855
|
export {};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { 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;
|