xstate 5.32.1 → 6.0.0-alpha.2
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/README.md +7 -8
- package/dist/StateMachine-2dcdb1f5.esm.js +720 -0
- package/dist/StateMachine-2ea0a7fa.development.esm.js +737 -0
- package/dist/StateMachine-64813f46.cjs.js +723 -0
- package/dist/StateMachine-8d22a79c.development.cjs.js +740 -0
- package/dist/declarations/src/State.d.ts +11 -13
- package/dist/declarations/src/StateMachine.d.ts +27 -21
- package/dist/declarations/src/StateNode.d.ts +18 -54
- package/dist/declarations/src/actions.d.ts +14 -9
- package/dist/declarations/src/actors/callback.d.ts +42 -16
- package/dist/declarations/src/actors/index.d.ts +9 -6
- package/dist/declarations/src/actors/listener.d.ts +18 -0
- package/dist/declarations/src/actors/logic.d.ts +105 -0
- package/dist/declarations/src/actors/observable.d.ts +72 -27
- package/dist/declarations/src/actors/promise.d.ts +133 -48
- package/dist/declarations/src/actors/subscription.d.ts +22 -0
- package/dist/declarations/src/atom.d.ts +81 -0
- package/dist/declarations/src/createActor.d.ts +31 -33
- package/dist/declarations/src/createMachine.d.ts +35 -7
- package/dist/declarations/src/createMachineFromConfig.d.ts +176 -0
- package/dist/declarations/src/graph/graph.d.ts +4 -2
- package/dist/declarations/src/index.d.ts +12 -8
- package/dist/declarations/src/inspection.d.ts +84 -30
- package/dist/declarations/src/mapState.d.ts +4 -2
- package/dist/declarations/src/schema.types.d.ts +90 -0
- package/dist/declarations/src/serialize.d.ts +44 -0
- package/dist/declarations/src/setup.d.ts +251 -135
- package/dist/declarations/src/spawn.d.ts +6 -31
- package/dist/declarations/src/stateUtils.d.ts +21 -19
- package/dist/declarations/src/system.d.ts +8 -7
- package/dist/declarations/src/transition.d.ts +5 -5
- package/dist/declarations/src/types.d.ts +405 -405
- package/dist/declarations/src/types.v6.d.ts +392 -0
- package/dist/declarations/src/utils.d.ts +4 -3
- package/dist/index-93edd3bd.esm.js +4909 -0
- package/dist/index-9cb3b3a0.cjs.js +4968 -0
- package/dist/index-e61170ba.development.esm.js +4948 -0
- package/dist/index-f6ef20d1.development.cjs.js +5007 -0
- package/dist/xstate-actors.cjs.js +12 -838
- package/dist/xstate-actors.cjs.mjs +10 -5
- package/dist/xstate-actors.development.cjs.js +12 -838
- package/dist/xstate-actors.development.cjs.mjs +10 -5
- package/dist/xstate-actors.development.esm.js +1 -836
- package/dist/xstate-actors.esm.js +1 -836
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +18 -29
- package/dist/xstate-graph.development.cjs.js +18 -29
- package/dist/xstate-graph.development.esm.js +15 -26
- package/dist/xstate-graph.esm.js +15 -26
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +1316 -112
- package/dist/xstate.cjs.mjs +22 -22
- package/dist/xstate.development.cjs.js +1316 -112
- package/dist/xstate.development.cjs.mjs +22 -22
- package/dist/xstate.development.esm.js +1278 -76
- package/dist/xstate.esm.js +1278 -76
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +3 -47
- package/dist/StateMachine-45e79c35.esm.js +0 -560
- package/dist/StateMachine-be2e51a3.development.cjs.js +0 -569
- package/dist/StateMachine-e0178d48.development.esm.js +0 -566
- package/dist/StateMachine-e6732977.cjs.js +0 -563
- package/dist/assign-2aa58daa.esm.js +0 -127
- package/dist/assign-927227d6.development.cjs.js +0 -135
- package/dist/assign-e8f2bd75.cjs.js +0 -129
- package/dist/assign-f338cee3.development.esm.js +0 -133
- package/dist/declarations/src/actions/assign.d.ts +0 -45
- package/dist/declarations/src/actions/cancel.d.ts +0 -39
- package/dist/declarations/src/actions/emit.d.ts +0 -44
- package/dist/declarations/src/actions/enqueueActions.d.ts +0 -57
- package/dist/declarations/src/actions/log.d.ts +0 -16
- package/dist/declarations/src/actions/raise.d.ts +0 -21
- package/dist/declarations/src/actions/send.d.ts +0 -42
- package/dist/declarations/src/actions/spawnChild.d.ts +0 -34
- package/dist/declarations/src/actions/stopChild.d.ts +0 -19
- package/dist/declarations/src/actors/transition.d.ts +0 -143
- package/dist/declarations/src/dev/index.d.ts +0 -14
- package/dist/declarations/src/guards.d.ts +0 -128
- package/dist/log-410e5e55.development.esm.js +0 -429
- package/dist/log-7776fcf2.cjs.js +0 -409
- package/dist/log-c2e11c01.development.cjs.js +0 -437
- package/dist/log-fa75ec2d.esm.js +0 -401
- package/dist/raise-74097812.development.esm.js +0 -2823
- package/dist/raise-7c948725.cjs.js +0 -2816
- package/dist/raise-964cd4e9.development.cjs.js +0 -2878
- package/dist/raise-e974d1c9.esm.js +0 -2761
- package/dist/xstate-actions.cjs.d.mts +0 -2
- package/dist/xstate-actions.cjs.d.ts +0 -2
- package/dist/xstate-actions.cjs.js +0 -23
- package/dist/xstate-actions.cjs.mjs +0 -14
- package/dist/xstate-actions.development.cjs.js +0 -23
- package/dist/xstate-actions.development.cjs.mjs +0 -14
- package/dist/xstate-actions.development.esm.js +0 -4
- package/dist/xstate-actions.esm.js +0 -4
- package/dist/xstate-actions.umd.min.js +0 -2
- package/dist/xstate-actions.umd.min.js.map +0 -1
- package/dist/xstate-dev.cjs.d.mts +0 -2
- package/dist/xstate-dev.cjs.d.ts +0 -2
- package/dist/xstate-dev.cjs.js +0 -48
- package/dist/xstate-dev.cjs.mjs +0 -5
- package/dist/xstate-dev.development.cjs.js +0 -51
- package/dist/xstate-dev.development.cjs.mjs +0 -5
- package/dist/xstate-dev.development.esm.js +0 -45
- package/dist/xstate-dev.esm.js +0 -42
- package/dist/xstate-dev.umd.min.js +0 -2
- package/dist/xstate-dev.umd.min.js.map +0 -1
- package/dist/xstate-guards.cjs.d.mts +0 -2
- package/dist/xstate-guards.cjs.d.ts +0 -2
- package/dist/xstate-guards.cjs.js +0 -14
- package/dist/xstate-guards.cjs.mjs +0 -7
- package/dist/xstate-guards.development.cjs.js +0 -14
- package/dist/xstate-guards.development.cjs.mjs +0 -7
- package/dist/xstate-guards.development.esm.js +0 -2
- package/dist/xstate-guards.esm.js +0 -2
- package/dist/xstate-guards.umd.min.js +0 -2
- package/dist/xstate-guards.umd.min.js.map +0 -1
|
@@ -1,144 +1,260 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "./schema.types.js";
|
|
1
2
|
import { StateMachine } from "./StateMachine.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
import { AnyActorRef, EventObject, AnyEventObject, EventDescriptor, ExtractEvent, MachineContext, ProvidedActor, RoutableStateId, StateSchema, StateValue, ToChildren, MetaObject, Cast } from "./types.js";
|
|
4
|
+
import { DelayMapFromNames, Implementations, InferOutput, InferEvents, Next_MachineConfig, Next_StateNodeConfig, ValidateDelayReferences, WithDefault } from "./types.v6.js";
|
|
5
|
+
type SetupStateSchemas = {
|
|
6
|
+
context?: StandardSchemaV1;
|
|
7
|
+
input?: StandardSchemaV1;
|
|
8
|
+
};
|
|
9
|
+
type SetupSchemas = {
|
|
10
|
+
context?: StandardSchemaV1;
|
|
11
|
+
events?: Record<string, StandardSchemaV1>;
|
|
12
|
+
emitted?: Record<string, StandardSchemaV1>;
|
|
13
|
+
input?: StandardSchemaV1;
|
|
14
|
+
output?: StandardSchemaV1;
|
|
15
|
+
meta?: StandardSchemaV1;
|
|
16
|
+
tags?: StandardSchemaV1;
|
|
17
|
+
};
|
|
18
|
+
/** State schema with optional schemas.input and nested states */
|
|
19
|
+
interface SetupStateSchema {
|
|
20
|
+
schemas?: SetupStateSchemas;
|
|
21
|
+
states?: Record<string, SetupStateSchema>;
|
|
22
|
+
}
|
|
23
|
+
type SetupSchema<TSchemas, TKey extends keyof SetupSchemas> = TKey extends keyof TSchemas ? TSchemas[TKey] extends StandardSchemaV1 ? TSchemas[TKey] : never : never;
|
|
24
|
+
type SetupSchemaMap<TSchemas, TKey extends 'events' | 'emitted'> = TKey extends keyof TSchemas ? TSchemas[TKey] extends Record<string, StandardSchemaV1> ? TSchemas[TKey] : never : never;
|
|
25
|
+
type SetupOrConfigSchema<TSchemas, TKey extends Exclude<keyof SetupSchemas, 'events' | 'emitted'>, TConfigSchema extends StandardSchemaV1> = [SetupSchema<TSchemas, TKey>] extends [never] ? TConfigSchema : SetupSchema<TSchemas, TKey>;
|
|
26
|
+
type SetupOrConfigSchemaMap<TSchemas, TKey extends 'events' | 'emitted', TConfigSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, TKey>] extends [never] ? TConfigSchemaMap : SetupSchemaMap<TSchemas, TKey>;
|
|
27
|
+
type SetupStateKeys<TStateSchemas extends Record<string, SetupStateSchema>> = keyof TStateSchemas & string;
|
|
28
|
+
type SetupStateKey<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : SetupStateKeys<TStateSchemas>;
|
|
29
|
+
type SetupStateTarget<TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? string : [SetupStateKeys<TStateSchemas>] extends [never] ? string : SetupStateKeys<TStateSchemas> | `.${string}` | `#${string}`;
|
|
30
|
+
type InvalidSetupStateKeys<TConfig, TStateSchemas extends Record<string, SetupStateSchema>> = string extends SetupStateKeys<TStateSchemas> ? never : [SetupStateKeys<TStateSchemas>] extends [never] ? never : TConfig extends {
|
|
31
|
+
states: infer TStates;
|
|
32
|
+
} ? Exclude<keyof TStates & string, SetupStateKeys<TStateSchemas>> : never;
|
|
33
|
+
type ValidateSetupStateKeys<TConfig, TStateSchemas extends Record<string, SetupStateSchema>> = [InvalidSetupStateKeys<TConfig, TStateSchemas>] extends [never] ? unknown : {
|
|
34
|
+
states: {
|
|
35
|
+
[K in InvalidSetupStateKeys<TConfig, TStateSchemas>]: never;
|
|
17
36
|
};
|
|
18
|
-
}
|
|
19
|
-
type
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
37
|
+
};
|
|
38
|
+
type ValidateNestedSetupStateKeys<TConfig, TStateSchemas extends Record<string, SetupStateSchema>> = TConfig extends {
|
|
39
|
+
states: infer TConfigStates;
|
|
40
|
+
} ? TConfigStates extends Record<string, unknown> ? {
|
|
41
|
+
states: {
|
|
42
|
+
[K in keyof TConfigStates & keyof TStateSchemas & string]: TStateSchemas[K] extends {
|
|
43
|
+
states: infer TChildStateSchemas;
|
|
44
|
+
} ? TChildStateSchemas extends Record<string, SetupStateSchema> ? TConfigStates[K] & ValidateSetupStateKeys<TConfigStates[K], TChildStateSchemas> & ValidateNestedSetupStateKeys<TConfigStates[K], TChildStateSchemas> : TConfigStates[K] : TConfigStates[K];
|
|
24
45
|
};
|
|
25
|
-
}
|
|
26
|
-
type
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
46
|
+
} : unknown : unknown;
|
|
47
|
+
type SetupContext<TSchemas, TContextSchema extends StandardSchemaV1> = [
|
|
48
|
+
SetupSchema<TSchemas, 'context'>
|
|
49
|
+
] extends [never] ? unknown extends StandardSchemaV1.InferOutput<TContextSchema> ? MachineContext : StandardSchemaV1.InferOutput<TContextSchema> & MachineContext : StandardSchemaV1.InferOutput<SetupSchema<TSchemas, 'context'>> & MachineContext;
|
|
50
|
+
type SetupContextRequired<TSchemas, TContextSchema extends StandardSchemaV1> = [
|
|
51
|
+
SetupSchema<TSchemas, 'context'>
|
|
52
|
+
] extends [never] ? unknown extends StandardSchemaV1.InferOutput<TContextSchema> ? false : true : true;
|
|
53
|
+
type SetupEvents<TSchemas, TEventSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, 'events'>] extends [never] ? InferEvents<TEventSchemaMap> : InferEvents<SetupSchemaMap<TSchemas, 'events'>>;
|
|
54
|
+
type SetupTags<TSchemas, TTagSchema extends StandardSchemaV1> = [
|
|
55
|
+
SetupSchema<TSchemas, 'tags'>
|
|
56
|
+
] extends [never] ? StandardSchemaV1.InferOutput<TTagSchema> & string : StandardSchemaV1.InferOutput<SetupSchema<TSchemas, 'tags'>> & string;
|
|
57
|
+
type SetupInput<TSchemas, TInputSchema extends StandardSchemaV1> = [
|
|
58
|
+
SetupSchema<TSchemas, 'input'>
|
|
59
|
+
] extends [never] ? InferOutput<TInputSchema, unknown> : InferOutput<SetupSchema<TSchemas, 'input'>, unknown>;
|
|
60
|
+
type SetupOutput<TSchemas, TOutputSchema extends StandardSchemaV1> = [
|
|
61
|
+
SetupSchema<TSchemas, 'output'>
|
|
62
|
+
] extends [never] ? InferOutput<TOutputSchema, unknown> : InferOutput<SetupSchema<TSchemas, 'output'>, unknown>;
|
|
63
|
+
type SetupEmitted<TSchemas, TEmittedSchemaMap extends Record<string, StandardSchemaV1>> = [SetupSchemaMap<TSchemas, 'emitted'>] extends [never] ? WithDefault<InferEvents<TEmittedSchemaMap>, AnyEventObject> : WithDefault<InferEvents<SetupSchemaMap<TSchemas, 'emitted'>>, AnyEventObject>;
|
|
64
|
+
type SetupMeta<TSchemas, TMetaSchema extends StandardSchemaV1> = [
|
|
65
|
+
SetupSchema<TSchemas, 'meta'>
|
|
66
|
+
] extends [never] ? InferOutput<TMetaSchema, MetaObject> : InferOutput<SetupSchema<TSchemas, 'meta'>, MetaObject>;
|
|
67
|
+
/** Extracts input type from a state schema */
|
|
68
|
+
type StateInput<TStateSchema extends SetupStateSchema> = TStateSchema['schemas'] extends {
|
|
69
|
+
input: infer TInputSchema;
|
|
70
|
+
} ? TInputSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TInputSchema> : undefined : undefined;
|
|
71
|
+
type StateContext<TStateSchema extends SetupStateSchema, TFallbackContext extends MachineContext> = TStateSchema['schemas'] extends {
|
|
72
|
+
context: infer TContextSchema;
|
|
73
|
+
} ? TContextSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TContextSchema> & MachineContext : TFallbackContext : TFallbackContext;
|
|
74
|
+
type WithNestedStates<TConfig, TNestedStates> = TConfig extends {
|
|
75
|
+
type: 'choice';
|
|
76
|
+
} ? TConfig : Omit<TConfig, 'states'> & {
|
|
77
|
+
states?: TNestedStates;
|
|
30
78
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
type MergeChildrenMap<TExplicit extends Record<string, string>, TInferred extends Record<string, string>> = IsNever<keyof TExplicit> extends true ? TInferred : TExplicit;
|
|
44
|
-
export 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> = {
|
|
45
|
-
extend: <TExtendActions extends Record<string, ParameterizedObject['params'] | undefined> = {}, TExtendGuards extends Record<string, ParameterizedObject['params'] | undefined> = {}, TExtendDelays extends string = never>({ actions, guards, delays }: {
|
|
46
|
-
actions?: {
|
|
47
|
-
[K in keyof TExtendActions]: ActionFunction<TContext, TEvent, TEvent, TExtendActions[K], ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions & TExtendActions>, ToParameterizedObject<TGuards & TExtendGuards>, TDelay | TExtendDelays, TEmitted>;
|
|
48
|
-
};
|
|
49
|
-
guards?: {
|
|
50
|
-
[K in keyof TExtendGuards]: GuardPredicate<TContext, TEvent, TExtendGuards[K], ToParameterizedObject<TGuards & TExtendGuards>>;
|
|
51
|
-
};
|
|
52
|
-
delays?: {
|
|
53
|
-
[K in TExtendDelays]: DelayConfig<TContext, TEvent, ToParameterizedObject<TActions & TExtendActions>['params'], TEvent>;
|
|
54
|
-
};
|
|
55
|
-
}) => SetupReturn<TContext, TEvent, TActors, TChildrenMap, TActions & TExtendActions, TGuards & TExtendGuards, TDelay | TExtendDelays, TTag, TInput, TOutput, TEmitted, TMeta>;
|
|
56
|
-
/**
|
|
57
|
-
* Creates a state config that is strongly typed. This state config can be
|
|
58
|
-
* used to create a machine.
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
*
|
|
62
|
-
* ```ts
|
|
63
|
-
* const lightMachineSetup = setup({
|
|
64
|
-
* // ...
|
|
65
|
-
* });
|
|
66
|
-
*
|
|
67
|
-
* const green = lightMachineSetup.createStateConfig({
|
|
68
|
-
* on: {
|
|
69
|
-
* timer: {
|
|
70
|
-
* actions: 'doSomething'
|
|
71
|
-
* }
|
|
72
|
-
* }
|
|
73
|
-
* });
|
|
74
|
-
*
|
|
75
|
-
* const machine = lightMachineSetup.createMachine({
|
|
76
|
-
* initial: 'green',
|
|
77
|
-
* states: {
|
|
78
|
-
* green,
|
|
79
|
-
* yellow,
|
|
80
|
-
* red
|
|
81
|
-
* }
|
|
82
|
-
* });
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
createStateConfig: <TStateConfig extends StateNodeConfig<TContext, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, unknown, TEmitted, TMeta>>(config: TStateConfig) => TStateConfig;
|
|
86
|
-
/**
|
|
87
|
-
* Creates a type-safe action.
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
*
|
|
91
|
-
* ```ts
|
|
92
|
-
* const machineSetup = setup({
|
|
93
|
-
* // ...
|
|
94
|
-
* });
|
|
95
|
-
*
|
|
96
|
-
* const action = machineSetup.createAction(({ context, event }) => {
|
|
97
|
-
* console.log(context.count, event.value);
|
|
98
|
-
* });
|
|
99
|
-
*
|
|
100
|
-
* const incrementAction = machineSetup.createAction(
|
|
101
|
-
* assign({ count: ({ context }) => context.count + 1 })
|
|
102
|
-
* );
|
|
103
|
-
*
|
|
104
|
-
* const machine = machineSetup.createMachine({
|
|
105
|
-
* context: { count: 0 },
|
|
106
|
-
* entry: [action, incrementAction]
|
|
107
|
-
* });
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
createAction: (action: ActionFunction<TContext, TEvent, TEvent, unknown, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TEmitted>) => typeof action;
|
|
111
|
-
createMachine: <const TConfig extends MachineConfig<TContext, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TTag, TInput, TOutput, TEmitted, TMeta>, TResolvedChildren extends Record<string, string> = MergeChildrenMap<TChildrenMap, Cast<ExtractConfigChildren<TConfig>, Record<string, string>>>>(config: TConfig) => StateMachine<TContext, TEvent | ([RoutableStateId<TConfig>] extends [never] ? never : {
|
|
112
|
-
type: 'xstate.route';
|
|
113
|
-
to: RoutableStateId<TConfig>;
|
|
114
|
-
}), Cast<ToChildren<ToProvidedActor<TResolvedChildren, TActors>>, Record<string, AnyActorRef | undefined>>, ToProvidedActor<TResolvedChildren, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, ToStateValue<TConfig>, TTag, TInput, TOutput, TEmitted, TMeta, ToStateSchema<TConfig>>;
|
|
115
|
-
assign: typeof assign<TContext, TEvent, undefined, TEvent, ToProvidedActor<TChildrenMap, TActors>>;
|
|
116
|
-
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>>;
|
|
117
|
-
raise: typeof raise<TContext, TEvent, TEvent, undefined, TDelay, TDelay>;
|
|
118
|
-
log: typeof log<TContext, TEvent, undefined, TEvent>;
|
|
119
|
-
cancel: typeof cancel<TContext, TEvent, undefined, TEvent>;
|
|
120
|
-
stopChild: typeof stopChild<TContext, TEvent, undefined, TEvent>;
|
|
121
|
-
enqueueActions: typeof enqueueActions<TContext, TEvent, undefined, TEvent, ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TEmitted>;
|
|
122
|
-
emit: typeof emit<TContext, TEvent, undefined, TEvent, TEmitted>;
|
|
123
|
-
spawnChild: typeof spawnChild<TContext, TEvent, undefined, TEvent, ToProvidedActor<TChildrenMap, TActors>>;
|
|
79
|
+
/**
|
|
80
|
+
* Converts SetupStateSchema to StateSchema with input types included. This
|
|
81
|
+
* allows getInputs() to be strongly typed.
|
|
82
|
+
*/
|
|
83
|
+
type SetupStateSchemaToStateSchema<TSetupSchema extends SetupStateSchema> = {
|
|
84
|
+
input: StateInput<TSetupSchema>;
|
|
85
|
+
contextSchema: TSetupSchema['schemas'] extends {
|
|
86
|
+
context: infer TContextSchema;
|
|
87
|
+
} ? TContextSchema extends StandardSchemaV1 ? TContextSchema : undefined : undefined;
|
|
88
|
+
states: TSetupSchema['states'] extends Record<string, SetupStateSchema> ? {
|
|
89
|
+
[K in keyof TSetupSchema['states'] & string]: SetupStateSchemaToStateSchema<TSetupSchema['states'][K]>;
|
|
90
|
+
} : undefined;
|
|
124
91
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
actors?: {
|
|
130
|
-
[K in keyof TActors | Values<TChildrenMap>]: K extends keyof TActors ? TActors[K] : never;
|
|
131
|
-
};
|
|
132
|
-
actions?: {
|
|
133
|
-
[K in keyof TActions]: ActionFunction<TContext, TEvent, TEvent, TActions[K], ToProvidedActor<TChildrenMap, TActors>, ToParameterizedObject<TActions>, ToParameterizedObject<TGuards>, TDelay, TEmitted>;
|
|
92
|
+
/** Converts the root setup states config to a StateSchema. */
|
|
93
|
+
type SetupStatesToStateSchema<TStates extends Record<string, SetupStateSchema>> = {
|
|
94
|
+
states: {
|
|
95
|
+
[K in keyof TStates & string]: SetupStateSchemaToStateSchema<TStates[K]>;
|
|
134
96
|
};
|
|
135
|
-
|
|
136
|
-
|
|
97
|
+
};
|
|
98
|
+
type EmptyStateSchema = {
|
|
99
|
+
input: undefined;
|
|
100
|
+
states: undefined;
|
|
101
|
+
};
|
|
102
|
+
type StateSchemaInput<TConfig extends StateSchema, TSetup extends StateSchema> = TSetup extends {
|
|
103
|
+
input: infer TInput;
|
|
104
|
+
} ? TInput : TConfig extends {
|
|
105
|
+
input: infer TInput;
|
|
106
|
+
} ? TInput : undefined;
|
|
107
|
+
type StateSchemaContextSchema<TConfig extends StateSchema, TSetup extends StateSchema> = TSetup extends {
|
|
108
|
+
contextSchema: infer TContextSchema;
|
|
109
|
+
} ? TContextSchema extends StandardSchemaV1 ? TContextSchema : undefined : TConfig extends {
|
|
110
|
+
contextSchema: infer TContextSchema;
|
|
111
|
+
} ? TContextSchema extends StandardSchemaV1 ? TContextSchema : undefined : undefined;
|
|
112
|
+
type StateSchemaChild<TSetup extends StateSchema, K extends string> = TSetup extends {
|
|
113
|
+
states: infer TStates;
|
|
114
|
+
} ? K extends keyof TStates ? Cast<TStates[K], StateSchema> : EmptyStateSchema : EmptyStateSchema;
|
|
115
|
+
type MergeStateSchema<TConfig extends StateSchema, TSetup extends StateSchema> = Omit<TConfig, 'contextSchema' | 'input' | 'states'> & {
|
|
116
|
+
contextSchema: StateSchemaContextSchema<TConfig, TSetup>;
|
|
117
|
+
input: StateSchemaInput<TConfig, TSetup>;
|
|
118
|
+
states: TConfig extends {
|
|
119
|
+
states: infer TStates;
|
|
120
|
+
} ? TStates extends Record<string, StateSchema> ? {
|
|
121
|
+
[K in keyof TStates & string]: MergeStateSchema<TStates[K], StateSchemaChild<TSetup, K>>;
|
|
122
|
+
} : undefined : undefined;
|
|
123
|
+
};
|
|
124
|
+
/** Machine config with typed state input */
|
|
125
|
+
type SetupMachineConfig<TStateSchemas extends Record<string, SetupStateSchema>, TSchemas extends SetupSchemas, TContextSchema extends StandardSchemaV1, TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TContextRequired extends boolean> = Omit<Next_MachineConfig<SetupOrConfigSchema<TSchemas, 'context', TContextSchema>, SetupOrConfigSchemaMap<TSchemas, 'events', TEventSchemaMap>, SetupOrConfigSchemaMap<TSchemas, 'emitted', TEmittedSchemaMap>, SetupOrConfigSchema<TSchemas, 'input', TInputSchema>, SetupOrConfigSchema<TSchemas, 'output', TOutputSchema>, SetupOrConfigSchema<TSchemas, 'meta', TMetaSchema>, SetupOrConfigSchema<TSchemas, 'tags', TTagSchema>, TContext, TEvent, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, TContextRequired>, 'states' | 'initial'> & {
|
|
126
|
+
initial?: SetupStateKey<TStateSchemas> | InitialTransitionWithInput<TStateSchemas, TContext, TEvent> | undefined;
|
|
127
|
+
states?: StatesWithInput<TStateSchemas, TStateSchemas, TContext, TEvent, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
128
|
+
};
|
|
129
|
+
/** States config type that provides typed input for known states */
|
|
130
|
+
type StatesWithInput<TRootStateSchemas extends Record<string, SetupStateSchema>, TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = {
|
|
131
|
+
[K in keyof TStateSchemas & string]?: StateNodeConfigWithNestedInput<TRootStateSchemas, TStateSchemas[K], TContext, TEvent, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap>;
|
|
132
|
+
};
|
|
133
|
+
/** State node config that recursively applies typed input for nested states */
|
|
134
|
+
type StateNodeConfigWithNestedInput<TSiblingStateSchemas extends Record<string, SetupStateSchema>, TStateSchema extends SetupStateSchema, TContext extends MachineContext, TEvent extends EventObject, TDelays extends string, TTag extends string, TEmitted extends EventObject, TMeta extends MetaObject, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> = WithNestedStates<Omit<Next_StateNodeConfig<StateContext<TStateSchema, TContext>, TEvent, TDelays, TTag, any, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, StateInput<TStateSchema>>, 'on' | 'always' | 'initial'> & {
|
|
135
|
+
initial?: TStateSchema['states'] extends Record<string, SetupStateSchema> ? SetupStateKey<TStateSchema['states']> | InitialTransitionWithInput<TStateSchema['states'], StateContext<TStateSchema, TContext>, TEvent> : string | {
|
|
136
|
+
target: string;
|
|
137
|
+
input?: Record<string, unknown>;
|
|
138
|
+
} | undefined;
|
|
139
|
+
on?: StateTransitions<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, TEvent, TEmitted, TMeta>;
|
|
140
|
+
always?: StateTransitionConfigOrTarget<TSiblingStateSchemas, StateContext<TStateSchema, TContext>, TEvent, TEvent, TEmitted, TMeta>;
|
|
141
|
+
}, TStateSchema['states'] extends Record<string, SetupStateSchema> ? StatesWithInput<TStateSchema['states'], TStateSchema['states'], TContext, TEvent, TDelays, TTag, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap> : {
|
|
142
|
+
[K in string]?: Next_StateNodeConfig<TContext, TEvent, TDelays, TTag, any, TEmitted, TMeta, TActionMap, TActorMap, TGuardMap, TDelayMap, undefined>;
|
|
143
|
+
}>;
|
|
144
|
+
type StateTransitions<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject> = {
|
|
145
|
+
[K in EventDescriptor<TEvent>]?: StateTransitionConfigOrTarget<TStateSchemas, TContext, ExtractEvent<TEvent, K>, TEvent, TEmitted, TMeta>;
|
|
146
|
+
};
|
|
147
|
+
type StateTransitionConfigOrTarget<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TExpressionEvent extends EventObject, TEvent extends EventObject, TEmitted extends EventObject, TMeta extends MetaObject> = SetupStateTarget<TStateSchemas> | undefined | {
|
|
148
|
+
target?: SetupStateTarget<TStateSchemas> | SetupStateTarget<TStateSchemas>[];
|
|
149
|
+
description?: string;
|
|
150
|
+
reenter?: boolean;
|
|
151
|
+
meta?: TMeta;
|
|
152
|
+
input?: Record<string, unknown> | ((args: {
|
|
153
|
+
context: TContext;
|
|
154
|
+
event: TExpressionEvent;
|
|
155
|
+
}) => Record<string, unknown>);
|
|
156
|
+
} | StateTransitionFunction<TStateSchemas, TContext, TExpressionEvent, TEvent, TEmitted, TMeta>;
|
|
157
|
+
type StateTransitionFunction<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TExpressionEvent extends EventObject, _TEvent extends EventObject, _TEmitted extends EventObject, TMeta extends MetaObject> = (args: {
|
|
158
|
+
context: TContext;
|
|
159
|
+
event: TExpressionEvent;
|
|
160
|
+
self: AnyActorRef;
|
|
161
|
+
parent: AnyActorRef | undefined;
|
|
162
|
+
value: StateValue;
|
|
163
|
+
children: Record<string, AnyActorRef>;
|
|
164
|
+
actions: Implementations['actions'];
|
|
165
|
+
actors: Implementations['actors'];
|
|
166
|
+
guards: Implementations['guards'];
|
|
167
|
+
delays: Implementations['delays'];
|
|
168
|
+
}, enq: any) => StateTransitionResult<TStateSchemas, TContext, TMeta> | void;
|
|
169
|
+
type StateTransitionResult<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TMeta extends MetaObject> = {
|
|
170
|
+
target?: never;
|
|
171
|
+
context?: TContext;
|
|
172
|
+
reenter?: boolean;
|
|
173
|
+
meta?: TMeta;
|
|
174
|
+
} | {
|
|
175
|
+
[K in keyof TStateSchemas & string]: {
|
|
176
|
+
target: K;
|
|
177
|
+
context: StateContext<TStateSchemas[K], TContext>;
|
|
178
|
+
reenter?: boolean;
|
|
179
|
+
meta?: TMeta;
|
|
180
|
+
input?: StateInput<TStateSchemas[K]> | ((args: {
|
|
181
|
+
context: TContext;
|
|
182
|
+
event: EventObject;
|
|
183
|
+
}) => StateInput<TStateSchemas[K]>);
|
|
137
184
|
};
|
|
138
|
-
|
|
139
|
-
|
|
185
|
+
}[keyof TStateSchemas & string];
|
|
186
|
+
/** Initial transition with typed input based on target state */
|
|
187
|
+
type InitialTransitionWithInput<TStateSchemas extends Record<string, SetupStateSchema>, TContext extends MachineContext, TEvent extends EventObject> = {
|
|
188
|
+
[K in keyof TStateSchemas & string]: {
|
|
189
|
+
target: K;
|
|
190
|
+
input?: StateInput<TStateSchemas[K]> | ((args: {
|
|
191
|
+
context: TContext;
|
|
192
|
+
event: TEvent;
|
|
193
|
+
}) => StateInput<TStateSchemas[K]>);
|
|
140
194
|
};
|
|
141
|
-
} &
|
|
142
|
-
|
|
143
|
-
|
|
195
|
+
}[keyof TStateSchemas & string];
|
|
196
|
+
/** Return type of setup() */
|
|
197
|
+
interface SetupReturn<TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>, TSchemas extends SetupSchemas = {}> {
|
|
198
|
+
/** Creates a state machine with the setup configuration */
|
|
199
|
+
createMachine<TContextSchema extends StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, _TEvent extends EventObject, TActor extends ProvidedActor, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actors'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TDelays extends string, TTag extends SetupTags<TSchemas, TTagSchema>, TInput, TConfig extends SetupMachineConfig<TStates, TSchemas, TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap>, TDelays, TTag, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, TActionMap, TActorMap, TGuardMap, TDelayMap, SetupContextRequired<TSchemas, TContextSchema>>>(config: TConfig & ValidateSetupStateKeys<TConfig, TStates> & ValidateNestedSetupStateKeys<TConfig, TStates> & ValidateDelayReferences<TConfig> & {
|
|
200
|
+
schemas?: {
|
|
201
|
+
events?: TEventSchemaMap;
|
|
202
|
+
context?: TContextSchema;
|
|
203
|
+
emitted?: TEmittedSchemaMap;
|
|
204
|
+
input?: TInputSchema;
|
|
205
|
+
output?: TOutputSchema;
|
|
206
|
+
meta?: TMetaSchema;
|
|
207
|
+
tags?: TTagSchema;
|
|
208
|
+
};
|
|
209
|
+
}): StateMachine<SetupContext<TSchemas, TContextSchema>, SetupEvents<TSchemas, TEventSchemaMap> | ([RoutableStateId<Cast<TConfig, StateSchema>>] extends [never] ? never : {
|
|
210
|
+
type: 'xstate.route';
|
|
211
|
+
to: RoutableStateId<Cast<TConfig, StateSchema>>;
|
|
212
|
+
}), Cast<ToChildren<TActor>, Record<string, AnyActorRef | undefined>>, StateValue, TTag & string, [
|
|
213
|
+
SetupSchema<TSchemas, 'input'>
|
|
214
|
+
] extends [never] ? TInput : SetupInput<TSchemas, TInputSchema>, SetupOutput<TSchemas, TOutputSchema>, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, MergeStateSchema<Cast<TConfig, StateSchema>, SetupStatesToStateSchema<TStates>>, TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>>;
|
|
215
|
+
/** Creates a state node config with the setup configuration */
|
|
216
|
+
createStateConfig<const TConfig extends StateNodeConfigWithNestedInput<TStates, SetupStateSchema, SetupContext<TSchemas, StandardSchemaV1>, SetupEvents<TSchemas, Record<string, StandardSchemaV1>>, string, SetupTags<TSchemas, StandardSchemaV1>, SetupEmitted<TSchemas, Record<string, StandardSchemaV1>>, SetupMeta<TSchemas, StandardSchemaV1>, Implementations['actions'], Implementations['actors'], Implementations['guards'], Implementations['delays']>>(config: TConfig): TConfig;
|
|
217
|
+
/** State input schemas from setup config */
|
|
218
|
+
states: TStates;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Sets up a state machine with state input schemas and other configuration.
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
*
|
|
225
|
+
* ```ts
|
|
226
|
+
* import { setup } from 'xstate';
|
|
227
|
+
* import z from 'zod';
|
|
228
|
+
*
|
|
229
|
+
* const s = setup({
|
|
230
|
+
* states: {
|
|
231
|
+
* loading: {
|
|
232
|
+
* schemas: {
|
|
233
|
+
* input: z.object({
|
|
234
|
+
* userId: z.string()
|
|
235
|
+
* })
|
|
236
|
+
* }
|
|
237
|
+
* }
|
|
238
|
+
* }
|
|
239
|
+
* });
|
|
240
|
+
*
|
|
241
|
+
* const machine = s.createMachine({
|
|
242
|
+
* initial: {
|
|
243
|
+
* target: 'loading',
|
|
244
|
+
* input: { userId: '123' }
|
|
245
|
+
* },
|
|
246
|
+
* states: {
|
|
247
|
+
* loading: {
|
|
248
|
+
* entry: ({ input }) => {
|
|
249
|
+
* console.log(input.userId);
|
|
250
|
+
* }
|
|
251
|
+
* }
|
|
252
|
+
* }
|
|
253
|
+
* });
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
export declare function setup<const TSchemas extends SetupSchemas = {}, const TStates extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>>(config?: {
|
|
257
|
+
schemas?: TSchemas;
|
|
258
|
+
states?: TStates;
|
|
259
|
+
}): SetupReturn<TStates, TSchemas>;
|
|
144
260
|
export {};
|
|
@@ -1,37 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type
|
|
3
|
-
src: TSrc;
|
|
4
|
-
} ? ConditionalRequired<[
|
|
5
|
-
options?: {
|
|
6
|
-
id?: TActor['id'];
|
|
7
|
-
systemId?: string;
|
|
8
|
-
input?: InputFrom<TActor['logic']>;
|
|
9
|
-
syncSnapshot?: boolean;
|
|
10
|
-
} & {
|
|
11
|
-
[K in RequiredActorOptions<TActor>]: unknown;
|
|
12
|
-
}
|
|
13
|
-
], IsNotNever<RequiredActorOptions<TActor>>> : never;
|
|
14
|
-
export type Spawner<TActor extends ProvidedActor> = IsLiteralString<TActor['src']> extends true ? {
|
|
15
|
-
<TSrc extends TActor['src']>(logic: TSrc, ...[options]: SpawnOptions<TActor, TSrc>): ActorRefFromLogic<GetConcreteByKey<TActor, 'src', TSrc>['logic']>;
|
|
16
|
-
<TLogic extends AnyActorLogic>(src: TLogic, ...[options]: ConditionalRequired<[
|
|
17
|
-
options?: {
|
|
18
|
-
id?: never;
|
|
19
|
-
systemId?: string;
|
|
20
|
-
input?: InputFrom<TLogic>;
|
|
21
|
-
syncSnapshot?: boolean;
|
|
22
|
-
} & {
|
|
23
|
-
[K in RequiredLogicInput<TLogic>]: unknown;
|
|
24
|
-
}
|
|
25
|
-
], IsNotNever<RequiredLogicInput<TLogic>>>): ActorRefFromLogic<TLogic>;
|
|
26
|
-
} : <TLogic extends AnyActorLogic | string>(src: TLogic, ...[options]: ConditionalRequired<[
|
|
1
|
+
import { ActorFromLogic, AnyActorLogic, AnyActorRef, AnyActorScope, AnyEventObject, AnyMachineSnapshot, ConditionalRequired, InputFrom, IsNotNever, type RequiredLogicInput } from "./types.js";
|
|
2
|
+
export type Spawner = <TLogic extends AnyActorLogic>(src: TLogic, ...[options]: ConditionalRequired<[
|
|
27
3
|
options?: {
|
|
28
4
|
id?: string;
|
|
29
5
|
systemId?: string;
|
|
30
6
|
input?: TLogic extends string ? unknown : InputFrom<TLogic>;
|
|
31
7
|
syncSnapshot?: boolean;
|
|
32
|
-
} &
|
|
8
|
+
} & {
|
|
33
9
|
[K in RequiredLogicInput<TLogic>]: unknown;
|
|
34
|
-
}
|
|
35
|
-
], IsNotNever<
|
|
36
|
-
export declare function createSpawner(actorScope: AnyActorScope, { machine, context }: AnyMachineSnapshot, event: AnyEventObject, spawnedChildren: Record<string, AnyActorRef>): Spawner
|
|
37
|
-
export {};
|
|
10
|
+
}
|
|
11
|
+
], IsNotNever<RequiredLogicInput<TLogic>>>) => ActorFromLogic<TLogic>;
|
|
12
|
+
export declare function createSpawner(actorScope: AnyActorScope, { machine, context }: AnyMachineSnapshot, event: AnyEventObject, spawnedChildren: Record<string, AnyActorRef>): Spawner;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { MachineSnapshot } from "./State.js";
|
|
2
2
|
import type { StateNode } from "./StateNode.js";
|
|
3
|
-
import {
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
export declare function isAtomicStateNode(stateNode: StateNode<any, any>): boolean;
|
|
3
|
+
import { AnyEventObject, AnyMachineSnapshot, AnyStateNode, AnyTransitionDefinition, DelayedTransitionDefinition, EventObject, ExecutableActionObject, MachineContext, StateValue, TransitionDefinition, AnyAction, AnyTransitionConfig, AnyActor, AnyActorScope } from "./types.js";
|
|
4
|
+
type AnyStateNodeIterable = Iterable<AnyStateNode>;
|
|
5
|
+
export declare function isAtomicStateNode(stateNode: AnyStateNode): boolean;
|
|
7
6
|
export declare function getProperAncestors(stateNode: AnyStateNode, toStateNode: AnyStateNode | undefined): Array<typeof stateNode>;
|
|
8
7
|
export declare function getAllStateNodes(stateNodes: Iterable<AnyStateNode>): Set<AnyStateNode>;
|
|
9
8
|
export declare function getStateValue(rootNode: AnyStateNode, stateNodes: AnyStateNodeIterable): StateValue;
|
|
@@ -13,13 +12,11 @@ export declare function getCandidates<TEvent extends EventObject>(stateNode: Sta
|
|
|
13
12
|
/** All delayed transitions from the config. */
|
|
14
13
|
export declare function getDelayedTransitions(stateNode: AnyStateNode): Array<DelayedTransitionDefinition<MachineContext, EventObject>>;
|
|
15
14
|
export declare function formatTransition(stateNode: AnyStateNode, descriptor: string, transitionConfig: AnyTransitionConfig): AnyTransitionDefinition;
|
|
16
|
-
export declare function formatTransitions<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode): Map<string, TransitionDefinition<TContext, TEvent>[]>;
|
|
17
15
|
/**
|
|
18
16
|
* Collects route transitions from all descendants with explicit IDs. Called
|
|
19
17
|
* once on the root node to avoid O(N²) repeated traversals.
|
|
20
18
|
*/
|
|
21
19
|
export declare function formatRouteTransitions(rootStateNode: AnyStateNode): void;
|
|
22
|
-
export declare function formatInitialTransition<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, _target: string | undefined | InitialTransitionConfig<TContext, TEvent, TODO, TODO, TODO, TODO>): InitialTransitionDefinition<TContext, TEvent>;
|
|
23
20
|
/**
|
|
24
21
|
* Returns the relative state node from the given `statePath`, or throws.
|
|
25
22
|
*
|
|
@@ -32,21 +29,24 @@ export declare function getStateNodeByPath(stateNode: AnyStateNode, statePath: s
|
|
|
32
29
|
* @param stateValue The state value or State instance
|
|
33
30
|
*/
|
|
34
31
|
export declare function getStateNodes(stateNode: AnyStateNode, stateValue: StateValue): Array<AnyStateNode>;
|
|
35
|
-
export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue, snapshot: MachineSnapshot<TContext, TEvent, any, any, any, any, any, any>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
32
|
+
export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue, snapshot: MachineSnapshot<TContext, TEvent, any, any, any, any, any, any>, event: TEvent, self: AnyActor): Array<TransitionDefinition<TContext, TEvent>> | undefined;
|
|
36
33
|
type Microstep = readonly [AnyMachineSnapshot, ExecutableActionObject[]];
|
|
37
34
|
export declare function initialMicrostep(root: AnyStateNode, preInitialState: AnyMachineSnapshot, actorScope: AnyActorScope, initEvent: AnyEventObject, internalQueue: AnyEventObject[]): Microstep;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Gets the transition result for a given transition without executing the
|
|
37
|
+
* transition.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getTransitionResult(transition: Pick<AnyTransitionDefinition, 'target' | 'to' | 'source'> & {
|
|
40
|
+
reenter?: AnyTransitionDefinition['reenter'];
|
|
41
|
+
input?: AnyTransitionDefinition['input'];
|
|
42
|
+
}, snapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope): {
|
|
43
|
+
targets: Readonly<AnyStateNode[]> | undefined;
|
|
44
|
+
context: MachineContext | undefined;
|
|
45
|
+
actions: AnyAction[] | undefined;
|
|
46
|
+
reenter?: boolean;
|
|
47
|
+
internalEvents: EventObject[] | undefined;
|
|
48
|
+
input: Record<string, unknown> | undefined;
|
|
49
|
+
};
|
|
50
50
|
export declare function macrostep(snapshot: AnyMachineSnapshot, event: EventObject, actorScope: AnyActorScope, internalQueue: AnyEventObject[]): {
|
|
51
51
|
snapshot: typeof snapshot;
|
|
52
52
|
microsteps: Microstep[];
|
|
@@ -58,4 +58,6 @@ export declare function macrostep(snapshot: AnyMachineSnapshot, event: EventObje
|
|
|
58
58
|
* @param stateValue The partial state value to resolve.
|
|
59
59
|
*/
|
|
60
60
|
export declare function resolveStateValue(rootNode: AnyStateNode, stateValue: StateValue): StateValue;
|
|
61
|
+
export declare function hasEffect(transition: AnyTransitionDefinition, context: MachineContext, event: EventObject, snapshot: AnyMachineSnapshot, self: AnyActor): boolean;
|
|
62
|
+
export declare function evaluateCandidate(candidate: AnyTransitionDefinition, event: EventObject, snapshot: AnyMachineSnapshot, stateNode: AnyStateNode, self: AnyActor): boolean;
|
|
61
63
|
export {};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { InspectionEvent } from "./inspection.js";
|
|
2
|
-
import { ActorSystemInfo,
|
|
2
|
+
import { ActorSystemInfo, AnyActor, Observer, EventObject, Subscription, TimersRestoreStrategy } from "./types.js";
|
|
3
3
|
interface ScheduledEvent {
|
|
4
4
|
id: string;
|
|
5
5
|
event: EventObject;
|
|
6
6
|
startedAt: number;
|
|
7
7
|
delay: number;
|
|
8
|
-
source:
|
|
9
|
-
target:
|
|
8
|
+
source: AnyActor;
|
|
9
|
+
target: AnyActor;
|
|
10
10
|
}
|
|
11
11
|
export interface Clock {
|
|
12
12
|
setTimeout(fn: (...args: any[]) => void, timeout: number): any;
|
|
13
13
|
clearTimeout(id: any): void;
|
|
14
14
|
}
|
|
15
15
|
interface Scheduler {
|
|
16
|
-
schedule(source:
|
|
17
|
-
cancel(source:
|
|
18
|
-
cancelAll(
|
|
16
|
+
schedule(source: AnyActor, target: AnyActor, event: EventObject, delay: number, id: string | undefined): void;
|
|
17
|
+
cancel(source: AnyActor, id: string): void;
|
|
18
|
+
cancelAll(actor: AnyActor): void;
|
|
19
19
|
}
|
|
20
20
|
export interface ActorSystem<T extends ActorSystemInfo> {
|
|
21
21
|
get: <K extends keyof T['actors']>(key: K) => T['actors'][K] | undefined;
|
|
@@ -30,9 +30,10 @@ export interface ActorSystem<T extends ActorSystemInfo> {
|
|
|
30
30
|
_logger: (...args: any[]) => void;
|
|
31
31
|
}
|
|
32
32
|
export type AnyActorSystem = ActorSystem<any>;
|
|
33
|
-
export declare function createSystem<T extends ActorSystemInfo>(rootActor:
|
|
33
|
+
export declare function createSystem<T extends ActorSystemInfo>(rootActor: AnyActor, options: {
|
|
34
34
|
clock: Clock;
|
|
35
35
|
logger: (...args: any[]) => void;
|
|
36
36
|
snapshot?: unknown;
|
|
37
|
+
timers?: TimersRestoreStrategy;
|
|
37
38
|
}): ActorSystem<T>;
|
|
38
39
|
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { AnyActorLogic, AnyStateMachine, EventFromLogic, InputFrom, SnapshotFrom,
|
|
1
|
+
import { AnyActorLogic, AnyStateMachine, EventFromLogic, InputFrom, SnapshotFrom, ExecutableActionObject, AnyTransitionDefinition, AnyMachineSnapshot } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Given actor `logic`, a `snapshot`, and an `event`, returns a tuple of the
|
|
4
4
|
* `nextSnapshot` and `actions` to execute.
|
|
5
5
|
*
|
|
6
6
|
* This is a pure function that does not execute `actions`.
|
|
7
7
|
*/
|
|
8
|
-
export declare function transition<T extends AnyActorLogic>(logic: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): [nextSnapshot: SnapshotFrom<T>, actions:
|
|
8
|
+
export declare function transition<T extends AnyActorLogic>(logic: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): [nextSnapshot: SnapshotFrom<T>, actions: ExecutableActionObject[]];
|
|
9
9
|
/**
|
|
10
10
|
* Given actor `logic` and optional `input`, returns a tuple of the
|
|
11
11
|
* `nextSnapshot` and `actions` to execute from the initial transition (no
|
|
@@ -13,14 +13,14 @@ export declare function transition<T extends AnyActorLogic>(logic: T, snapshot:
|
|
|
13
13
|
*
|
|
14
14
|
* This is a pure function that does not execute `actions`.
|
|
15
15
|
*/
|
|
16
|
-
export declare function initialTransition<T extends AnyActorLogic>(logic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): [SnapshotFrom<T>,
|
|
16
|
+
export declare function initialTransition<T extends AnyActorLogic>(logic: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): [SnapshotFrom<T>, ExecutableActionObject[]];
|
|
17
17
|
/**
|
|
18
18
|
* Given a state `machine`, a `snapshot`, and an `event`, returns an array of
|
|
19
19
|
* microsteps, where each microstep is a tuple of `[snapshot, actions]`.
|
|
20
20
|
*
|
|
21
21
|
* This is a pure function that does not execute `actions`.
|
|
22
22
|
*/
|
|
23
|
-
export declare function getMicrosteps<T extends AnyStateMachine>(machine: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): Array<[SnapshotFrom<T>,
|
|
23
|
+
export declare function getMicrosteps<T extends AnyStateMachine>(machine: T, snapshot: SnapshotFrom<T>, event: EventFromLogic<T>): Array<[SnapshotFrom<T>, ExecutableActionObject[]]>;
|
|
24
24
|
/**
|
|
25
25
|
* Given a state `machine` and optional `input`, returns an array of microsteps
|
|
26
26
|
* from the initial transition, where each microstep is a tuple of `[snapshot,
|
|
@@ -28,7 +28,7 @@ export declare function getMicrosteps<T extends AnyStateMachine>(machine: T, sna
|
|
|
28
28
|
*
|
|
29
29
|
* This is a pure function that does not execute `actions`.
|
|
30
30
|
*/
|
|
31
|
-
export declare function getInitialMicrosteps<T extends AnyStateMachine>(machine: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): Array<[SnapshotFrom<T>,
|
|
31
|
+
export declare function getInitialMicrosteps<T extends AnyStateMachine>(machine: T, ...[input]: undefined extends InputFrom<T> ? [input?: InputFrom<T>] : [input: InputFrom<T>]): Array<[SnapshotFrom<T>, ExecutableActionObject[]]>;
|
|
32
32
|
/**
|
|
33
33
|
* Gets all potential next transitions from the current state.
|
|
34
34
|
*
|