xstate 6.0.0-alpha.2 → 6.0.0-alpha.21
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 +19 -17
- package/bin/xstate.js +36 -0
- package/dist/{StateMachine-64813f46.cjs.js → StateMachine-1b155670.cjs.js} +182 -40
- package/dist/{StateMachine-2dcdb1f5.esm.js → StateMachine-3c17fe3e.esm.js} +182 -40
- package/dist/{StateMachine-8d22a79c.development.cjs.js → StateMachine-550ff7f2.development.cjs.js} +193 -36
- package/dist/{StateMachine-2ea0a7fa.development.esm.js → StateMachine-e25dd61f.development.esm.js} +193 -36
- package/dist/declarations/src/State.d.ts +13 -2
- package/dist/declarations/src/StateMachine.d.ts +23 -13
- package/dist/declarations/src/actions.d.ts +2 -1
- package/dist/declarations/src/actors/promise.d.ts +4 -2
- package/dist/declarations/src/createActor.d.ts +9 -11
- package/dist/declarations/src/createMachine.d.ts +14 -11
- package/dist/declarations/src/createMachineFromConfig.d.ts +61 -28
- package/dist/declarations/src/fsm.d.ts +74 -0
- package/dist/declarations/src/graph/graph.d.ts +3 -3
- package/dist/declarations/src/graph/shortestPaths.d.ts +2 -2
- package/dist/declarations/src/graph/simplePaths.d.ts +2 -2
- package/dist/declarations/src/index.d.ts +6 -5
- package/dist/declarations/src/serialize.d.ts +10 -18
- package/dist/declarations/src/setup.d.ts +277 -65
- package/dist/declarations/src/spawn.d.ts +3 -3
- package/dist/declarations/src/stateUtils.d.ts +4 -1
- package/dist/declarations/src/system.d.ts +1 -1
- package/dist/declarations/src/transition.d.ts +8 -5
- package/dist/declarations/src/transitionActions.d.ts +12 -0
- package/dist/declarations/src/types.d.ts +237 -102
- package/dist/declarations/src/types.v6.d.ts +132 -58
- package/dist/declarations/src/utils.d.ts +4 -3
- package/dist/{index-93edd3bd.esm.js → index-3f87408c.esm.js} +936 -1389
- package/dist/{index-e61170ba.development.esm.js → index-d39fb138.development.esm.js} +968 -1421
- package/dist/{index-9cb3b3a0.cjs.js → index-e694228c.cjs.js} +945 -1394
- package/dist/{index-f6ef20d1.development.cjs.js → index-ec7c7a2d.development.cjs.js} +977 -1426
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +1 -1
- package/dist/xstate-actors.esm.js +1 -1
- 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 +2 -2
- package/dist/xstate-graph.development.cjs.js +2 -2
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate.cjs.js +1100 -182
- package/dist/xstate.cjs.mjs +3 -5
- package/dist/xstate.development.cjs.js +1100 -182
- package/dist/xstate.development.cjs.mjs +3 -5
- package/dist/xstate.development.esm.js +1101 -181
- package/dist/xstate.esm.js +1101 -181
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +6 -2
- package/dist/declarations/src/atom.d.ts +0 -81
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./schema.types.js";
|
|
2
2
|
import { StateMachine } from "./StateMachine.js";
|
|
3
|
-
import { AnyActorRef, EventObject, AnyEventObject, Cast, MachineContext, ProvidedActor, StateValue, ToChildren, MetaObject, StateSchema, DoNotInfer, RoutableStateId } from "./types.js";
|
|
4
|
-
import { Implementations, DelayMapFromNames, InferOutput, InferEvents, Next_MachineConfig, Next_StateNodeConfig, ValidateDelayReferences, WidenLiterals, WithDefault } from "./types.v6.js";
|
|
3
|
+
import { AnyActorRef, EventObject, AnyEventObject, Cast, MachineContext, ProvidedActor, StateValue, ToChildren, MetaObject, StateSchema, DoNotInfer, RoutableStateId, Compute } from "./types.js";
|
|
4
|
+
import { Implementations, DelayMapFromNames, InferChildren, InferOutput, InferEvents, Next_MachineConfig, Next_StateNodeConfig, ValidateDelayReferences, ValidateTopLevelFinalOutputs, WidenLiterals, WithDefault } from "./types.v6.js";
|
|
5
|
+
type MergeChildren<TChildren extends Record<string, AnyActorRef | undefined>, TActor extends ProvidedActor> = [keyof TChildren] extends [never] ? Compute<ToChildren<TActor>> : Compute<TChildren>;
|
|
5
6
|
/**
|
|
6
7
|
* Creates a state machine (statechart) with the given configuration.
|
|
7
8
|
*
|
|
@@ -44,35 +45,37 @@ import { Implementations, DelayMapFromNames, InferOutput, InferEvents, Next_Mach
|
|
|
44
45
|
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })`
|
|
45
46
|
* to provide machine implementations instead.
|
|
46
47
|
*/
|
|
47
|
-
export declare function 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['
|
|
48
|
+
export declare function createMachine<TContextSchema extends StandardSchemaV1, const TEventSchemaMap extends Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, const TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1>, _TEvent extends EventObject, TActor extends ProvidedActor, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TDelays extends string, TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string, TInput, const TSS extends StateSchema>(config: TSS & ValidateDelayReferences<TSS> & Next_MachineConfig<TContextSchema, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap>, Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap> & {
|
|
48
49
|
schemas: {
|
|
49
50
|
context: TContextSchema;
|
|
51
|
+
children?: TChildrenSchemaMap;
|
|
50
52
|
};
|
|
51
|
-
}): StateMachine<InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap> | ([RoutableStateId<TSS>] extends [never] ? never : {
|
|
53
|
+
} & ValidateTopLevelFinalOutputs<TSS, InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap>>): StateMachine<InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap> | ([RoutableStateId<TSS>] extends [never] ? never : {
|
|
52
54
|
type: 'xstate.route';
|
|
53
55
|
to: RoutableStateId<TSS>;
|
|
54
|
-
}), Cast<
|
|
56
|
+
}), Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValue, TTag & string, TInput, InferOutput<TOutputSchema, unknown>, WithDefault<InferEvents<TEmittedSchemaMap>, AnyEventObject>, InferOutput<TMetaSchema, MetaObject>, // TMeta
|
|
55
57
|
TSS, // TStateSchema
|
|
56
58
|
TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>> & {
|
|
57
59
|
states: TSS;
|
|
58
60
|
};
|
|
59
|
-
export declare function createMachine<TContext extends MachineContext = never, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Implementations['actions'] = Implementations['actions'], TActorMap extends Implementations['
|
|
61
|
+
export declare function createMachine<TContext extends MachineContext = never, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, const TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Implementations['actions'] = Implementations['actions'], TActorMap extends Implementations['actorSources'] = Implementations['actorSources'], TGuardMap extends Implementations['guards'] = Implementations['guards'], TDelayMap extends Implementations['delays'] = Implementations['delays'], TDelays extends string = string, TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string = StandardSchemaV1.InferOutput<TTagSchema> & string, TInput = unknown, const TSS extends StateSchema = StateSchema>(config: TSS & ValidateDelayReferences<TSS> & Next_MachineConfig<StandardSchemaV1, TEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTagSchema, TChildrenSchemaMap, WidenLiterals<TContext>, InferEvents<TEventSchemaMap>, Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, false> & {
|
|
60
62
|
schemas?: {
|
|
61
63
|
context?: never;
|
|
62
64
|
};
|
|
63
65
|
context?: TContext | ((_: {
|
|
64
66
|
spawn: any;
|
|
65
|
-
|
|
67
|
+
actorSources: TActorMap;
|
|
66
68
|
input: InferOutput<TInputSchema, unknown>;
|
|
67
69
|
self: any;
|
|
68
70
|
}) => TContext);
|
|
69
|
-
}): StateMachine<WidenLiterals<TContext>, InferEvents<TEventSchemaMap> | ([RoutableStateId<TSS>] extends [never] ? never : {
|
|
71
|
+
} & ValidateTopLevelFinalOutputs<TSS, WidenLiterals<TContext>, InferEvents<TEventSchemaMap>>): StateMachine<WidenLiterals<TContext>, InferEvents<TEventSchemaMap> | ([RoutableStateId<TSS>] extends [never] ? never : {
|
|
70
72
|
type: 'xstate.route';
|
|
71
73
|
to: RoutableStateId<TSS>;
|
|
72
|
-
}), Cast<
|
|
74
|
+
}), Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValue, TTag & string, TInput, InferOutput<TOutputSchema, unknown>, WithDefault<InferEvents<TEmittedSchemaMap>, AnyEventObject>, InferOutput<TMetaSchema, MetaObject>, // TMeta
|
|
73
75
|
TSS, // TStateSchema
|
|
74
76
|
TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>> & {
|
|
75
77
|
states: TSS;
|
|
76
78
|
};
|
|
77
|
-
export declare function createStateConfig<TContextSchema extends StandardSchemaV1, TEventSchema extends StandardSchemaV1, TEmittedSchema extends StandardSchemaV1, _TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, _TEvent extends StandardSchemaV1.InferOutput<TEventSchema> & EventObject, // TODO: consider using a stricter `EventObject` here
|
|
78
|
-
_TActor extends ProvidedActor, TActionMap extends Implementations['actions'], TActorMap extends Implementations['
|
|
79
|
+
export declare function createStateConfig<TContextSchema extends StandardSchemaV1, TEventSchema extends StandardSchemaV1, TEmittedSchema extends StandardSchemaV1, _TInputSchema extends StandardSchemaV1, const TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, _TEvent extends StandardSchemaV1.InferOutput<TEventSchema> & EventObject, // TODO: consider using a stricter `EventObject` here
|
|
80
|
+
_TActor extends ProvidedActor, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays'], TDelays extends string, _TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string, _TInput, const TSS extends StateSchema>(config: TSS & Next_StateNodeConfig<InferOutput<TContextSchema, MachineContext>, DoNotInfer<StandardSchemaV1.InferOutput<TEventSchema> & EventObject>, DoNotInfer<TDelays>, DoNotInfer<StandardSchemaV1.InferOutput<TTagSchema> & string>, DoNotInfer<StandardSchemaV1.InferOutput<TOutputSchema>>, DoNotInfer<StandardSchemaV1.InferOutput<TEmittedSchema> & EventObject>, DoNotInfer<InferOutput<TMetaSchema, MetaObject>>, DoNotInfer<Record<string, AnyActorRef | undefined>>, DoNotInfer<TActionMap>, DoNotInfer<TActorMap>, DoNotInfer<TGuardMap>, DoNotInfer<TDelayMap>>): typeof config;
|
|
81
|
+
export {};
|
|
@@ -90,43 +90,65 @@ interface ScxmlIfJSON {
|
|
|
90
90
|
}
|
|
91
91
|
interface CustomActionJSON {
|
|
92
92
|
type: string;
|
|
93
|
-
params?:
|
|
93
|
+
params?: unknown;
|
|
94
94
|
}
|
|
95
|
-
export type ActionJSON = CustomActionJSON | RaiseJSON | CancelJSON | LogJSON | EmitJSON | AssignJSON | ScxmlAssignJSON | ScxmlRaiseJSON | ScxmlScriptJSON | ScxmlIfJSON | ScxmlForeachJSON | ScxmlCancelJSON | ScxmlBlockJSON;
|
|
95
|
+
export type ActionJSON = CustomActionJSON | RaiseJSON | CancelJSON | LogJSON | EmitJSON | AssignJSON | ScxmlAssignJSON | ScxmlRaiseJSON | ScxmlScriptJSON | ScxmlIfJSON | ScxmlForeachJSON | ScxmlCancelJSON | ScxmlBlockJSON | ExpressionJSON | CodeJSON;
|
|
96
96
|
export interface GuardJSON {
|
|
97
97
|
type: string;
|
|
98
|
-
params?:
|
|
98
|
+
params?: unknown;
|
|
99
|
+
}
|
|
100
|
+
interface ExpressionJSON {
|
|
101
|
+
'@expr': string;
|
|
102
|
+
'@lang'?: string;
|
|
103
|
+
}
|
|
104
|
+
interface CodeJSON {
|
|
105
|
+
'@code': string;
|
|
106
|
+
'@lang'?: string;
|
|
107
|
+
}
|
|
108
|
+
type ResolvableJSON = ExpressionJSON | CodeJSON;
|
|
109
|
+
type ConditionJSON = GuardJSON | ResolvableJSON;
|
|
110
|
+
interface ChoiceBranchJSON {
|
|
111
|
+
when?: ConditionJSON;
|
|
112
|
+
target: string | string[];
|
|
113
|
+
context?: MachineContext;
|
|
114
|
+
input?: unknown;
|
|
115
|
+
description?: string;
|
|
116
|
+
reenter?: boolean;
|
|
117
|
+
meta?: MetaObject;
|
|
99
118
|
}
|
|
100
119
|
export interface InvokeJSON {
|
|
101
120
|
id?: string;
|
|
102
|
-
|
|
103
|
-
src: string
|
|
121
|
+
registryKey?: string;
|
|
122
|
+
src: string;
|
|
104
123
|
input?: unknown;
|
|
105
|
-
onDone?:
|
|
106
|
-
onError?:
|
|
107
|
-
onSnapshot?:
|
|
108
|
-
timeout?: number | string;
|
|
109
|
-
onTimeout?:
|
|
124
|
+
onDone?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
125
|
+
onError?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
126
|
+
onSnapshot?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
127
|
+
timeout?: number | string | ResolvableJSON;
|
|
128
|
+
onTimeout?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
110
129
|
}
|
|
111
130
|
export interface TransitionJSON {
|
|
112
131
|
target?: string | string[];
|
|
132
|
+
context?: MachineContext;
|
|
113
133
|
actions?: ActionJSON[];
|
|
114
|
-
guard?:
|
|
134
|
+
guard?: ConditionJSON;
|
|
115
135
|
description?: string;
|
|
116
136
|
reenter?: boolean;
|
|
117
137
|
meta?: MetaObject;
|
|
118
138
|
input?: unknown;
|
|
119
139
|
}
|
|
140
|
+
type TransitionConfigJSON = TransitionJSON | ResolvableJSON;
|
|
120
141
|
export interface StateNodeJSON {
|
|
121
142
|
id?: string;
|
|
122
143
|
key?: string;
|
|
123
144
|
type?: 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | 'choice';
|
|
124
145
|
initial?: string;
|
|
125
146
|
states?: Record<string, StateNodeJSON>;
|
|
126
|
-
on?: Record<string,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
147
|
+
on?: Record<string, TransitionConfigJSON | TransitionConfigJSON[]>;
|
|
148
|
+
onError?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
149
|
+
after?: Record<string, TransitionConfigJSON | TransitionConfigJSON[]>;
|
|
150
|
+
always?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
151
|
+
choice?: ChoiceBranchJSON[] | ResolvableJSON;
|
|
130
152
|
/**
|
|
131
153
|
* JSON route config. Unlike the authoring API (a function), the JSON layer
|
|
132
154
|
* allows an object form whose `guard` may be a named guard reference (string)
|
|
@@ -138,16 +160,16 @@ export interface StateNodeJSON {
|
|
|
138
160
|
meta?: MetaObject;
|
|
139
161
|
guard?: string;
|
|
140
162
|
input?: Record<string, unknown>;
|
|
141
|
-
};
|
|
163
|
+
} | ResolvableJSON;
|
|
142
164
|
invoke?: InvokeJSON | InvokeJSON[];
|
|
143
|
-
entry?: ActionJSON[];
|
|
144
|
-
exit?: ActionJSON[];
|
|
165
|
+
entry?: ActionJSON | ActionJSON[];
|
|
166
|
+
exit?: ActionJSON | ActionJSON[];
|
|
145
167
|
meta?: MetaObject;
|
|
146
168
|
description?: string;
|
|
147
169
|
tags?: string[];
|
|
148
170
|
input?: unknown;
|
|
149
|
-
timeout?: number | string;
|
|
150
|
-
onTimeout?:
|
|
171
|
+
timeout?: number | string | ResolvableJSON;
|
|
172
|
+
onTimeout?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
151
173
|
history?: 'shallow' | 'deep';
|
|
152
174
|
target?: string;
|
|
153
175
|
output?: unknown;
|
|
@@ -155,22 +177,33 @@ export interface StateNodeJSON {
|
|
|
155
177
|
_scxmlDonedata?: ScxmlDonedataJSON;
|
|
156
178
|
}
|
|
157
179
|
export interface MachineJSON extends StateNodeJSON {
|
|
180
|
+
'@exprLang'?: string;
|
|
158
181
|
version?: string;
|
|
159
|
-
actions?: Record<string,
|
|
160
|
-
guards?: Record<string,
|
|
161
|
-
|
|
162
|
-
|
|
182
|
+
actions?: Record<string, ActionJSON | ActionJSON[]>;
|
|
183
|
+
guards?: Record<string, {
|
|
184
|
+
when: ConditionJSON;
|
|
185
|
+
}>;
|
|
186
|
+
actorSources?: Record<string, unknown>;
|
|
187
|
+
delays?: Record<string, number | string | {
|
|
188
|
+
duration: number | string | ResolvableJSON;
|
|
189
|
+
}>;
|
|
163
190
|
schemas?: Record<string, unknown>;
|
|
164
191
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
192
|
+
type EvaluatorSlot = 'context' | 'guard' | 'choice' | 'action' | 'actionParams' | 'transition' | 'input' | 'output' | 'delay' | 'transitionContext' | 'unknown';
|
|
193
|
+
type EvaluatorKind = 'expr' | 'code';
|
|
194
|
+
interface EvaluatorArgs {
|
|
195
|
+
source: string;
|
|
196
|
+
kind: EvaluatorKind;
|
|
197
|
+
slot: EvaluatorSlot;
|
|
198
|
+
scope: Record<string, unknown>;
|
|
199
|
+
path: string;
|
|
168
200
|
}
|
|
169
201
|
interface MachineImplementations {
|
|
170
202
|
actions?: Record<string, (...args: any[]) => unknown>;
|
|
171
203
|
guards?: Record<string, (...args: any[]) => boolean>;
|
|
172
|
-
|
|
204
|
+
actorSources?: Record<string, AnyActorLogic>;
|
|
173
205
|
delays?: Record<string, number | ((...args: any[]) => number)>;
|
|
206
|
+
evaluators?: Record<string, (args: EvaluatorArgs) => unknown>;
|
|
174
207
|
}
|
|
175
208
|
export declare function createMachineFromConfig(json: MachineJSON, implementations?: MachineImplementations): AnyStateMachine;
|
|
176
209
|
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createTransitionEnqueue } from "./transitionActions.js";
|
|
2
|
+
import type { ActorLogic, EventObject, MachineContext, NonReducibleUnknown, Snapshot } from "./types.js";
|
|
3
|
+
export type FSMSnapshot<TContext extends MachineContext, TState extends string, TInput = unknown> = Snapshot<undefined> & {
|
|
4
|
+
value: TState;
|
|
5
|
+
context: TContext;
|
|
6
|
+
input: TInput | undefined;
|
|
7
|
+
children: {};
|
|
8
|
+
_stateInput: Record<string, unknown> | undefined;
|
|
9
|
+
machine: {
|
|
10
|
+
id: string;
|
|
11
|
+
implementations: {
|
|
12
|
+
actions: {};
|
|
13
|
+
actorSources: {};
|
|
14
|
+
guards: {};
|
|
15
|
+
delays: {};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
type FSMArgs<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = {
|
|
20
|
+
context: TContext;
|
|
21
|
+
event: TEvent;
|
|
22
|
+
input: TInput | undefined;
|
|
23
|
+
value: TState;
|
|
24
|
+
self: any;
|
|
25
|
+
system: any;
|
|
26
|
+
parent: any;
|
|
27
|
+
children: {};
|
|
28
|
+
};
|
|
29
|
+
type FSMAction<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = (args: FSMArgs<TContext, TEvent, TState, TInput> & {
|
|
30
|
+
input: Record<string, unknown> | undefined;
|
|
31
|
+
}, enq: ReturnType<typeof createTransitionEnqueue>) => void | {
|
|
32
|
+
context?: FSMContextPatch<TContext>;
|
|
33
|
+
};
|
|
34
|
+
type FSMGuard<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = (args: FSMArgs<TContext, TEvent, TState, TInput>) => boolean;
|
|
35
|
+
type FSMContextPatch<TContext extends MachineContext> = Partial<TContext> & {
|
|
36
|
+
call?: never;
|
|
37
|
+
apply?: never;
|
|
38
|
+
bind?: never;
|
|
39
|
+
};
|
|
40
|
+
type FSMContextMapper<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = (args: FSMArgs<TContext, TEvent, TState, TInput>) => FSMContextPatch<TContext>;
|
|
41
|
+
type FSMTarget<TContext extends MachineContext> = {
|
|
42
|
+
target?: string;
|
|
43
|
+
context?: FSMContextPatch<TContext>;
|
|
44
|
+
input?: Record<string, unknown> | ((args: {
|
|
45
|
+
context: TContext;
|
|
46
|
+
event: EventObject;
|
|
47
|
+
}) => Record<string, unknown>);
|
|
48
|
+
};
|
|
49
|
+
type FSMObjectTarget<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = Omit<FSMTarget<TContext>, 'context'> & {
|
|
50
|
+
context?: FSMContextPatch<TContext> | FSMContextMapper<TContext, TEvent, TState, TInput>;
|
|
51
|
+
};
|
|
52
|
+
type FSMTransitionFunction<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = (args: FSMArgs<TContext, TEvent, TState, TInput>, enq: ReturnType<typeof createTransitionEnqueue>) => void | false | FSMTarget<TContext>;
|
|
53
|
+
type FSMTransition<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = FSMObjectTarget<TContext, TEvent, TState, TInput> | (FSMObjectTarget<TContext, TEvent, TState, TInput> & {
|
|
54
|
+
guard?: FSMGuard<TContext, TEvent, TState, TInput>;
|
|
55
|
+
actions?: FSMAction<TContext, TEvent, TState, TInput> | Array<FSMAction<TContext, TEvent, TState, TInput>>;
|
|
56
|
+
}) | FSMTransitionFunction<TContext, TEvent, TState, TInput>;
|
|
57
|
+
type FSMStateConfig<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = {
|
|
58
|
+
entry?: FSMAction<TContext, TEvent, TState, TInput> | Array<FSMAction<TContext, TEvent, TState, TInput>>;
|
|
59
|
+
exit?: FSMAction<TContext, TEvent, TState, TInput> | Array<FSMAction<TContext, TEvent, TState, TInput>>;
|
|
60
|
+
on?: Record<string, FSMTransition<TContext, TEvent, TState, TInput> | Array<FSMTransition<TContext, TEvent, TState, TInput>>>;
|
|
61
|
+
};
|
|
62
|
+
export type FSMConfig<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput = NonReducibleUnknown> = {
|
|
63
|
+
id?: string;
|
|
64
|
+
initial: TState;
|
|
65
|
+
context?: TContext | ((args: {
|
|
66
|
+
input: TInput;
|
|
67
|
+
}) => TContext);
|
|
68
|
+
states: Record<TState, FSMStateConfig<TContext, TEvent, TState, TInput>>;
|
|
69
|
+
};
|
|
70
|
+
export type FSMActorLogic<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = ActorLogic<FSMSnapshot<TContext, TState, TInput>, TEvent, TInput, any, EventObject> & {
|
|
71
|
+
id?: string;
|
|
72
|
+
};
|
|
73
|
+
export declare function createFSM<TContext extends MachineContext, TEvent extends EventObject, TInput = NonReducibleUnknown>(config: FSMConfig<TContext, TEvent, string, TInput>): FSMActorLogic<TContext, TEvent, string, TInput>;
|
|
74
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventObject, AnyStateMachine, StateNode, AnyActorLogic, EventFromLogic, Snapshot, InputFrom } from "../index.js";
|
|
1
|
+
import { EventObject, AnyStateMachine, StateNode, AnyActorLogic, EventFromLogic, Snapshot, InputFrom, SnapshotFrom } from "../index.js";
|
|
2
2
|
import type { SerializedSnapshot, StatePath, DirectedGraphNode, TraversalOptions, AnyStateNode, TraversalConfig } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Returns all state nodes of the given `node`.
|
|
@@ -9,8 +9,8 @@ export declare function getStateNodes(stateNode: {
|
|
|
9
9
|
states: Record<string, AnyStateNode | StateNode<never, EventObject>>;
|
|
10
10
|
}): AnyStateNode[];
|
|
11
11
|
export declare function serializeSnapshot(snapshot: Snapshot<any>): SerializedSnapshot;
|
|
12
|
-
export declare function createDefaultMachineOptions<TMachine extends AnyStateMachine>(machine: TMachine, options?: TraversalOptions<
|
|
12
|
+
export declare function createDefaultMachineOptions<TMachine extends AnyStateMachine>(machine: TMachine, options?: TraversalOptions<SnapshotFrom<TMachine>, EventFromLogic<TMachine>, InputFrom<TMachine>>): TraversalOptions<SnapshotFrom<TMachine>, EventFromLogic<TMachine>, InputFrom<TMachine>>;
|
|
13
13
|
export declare function createDefaultLogicOptions(): TraversalOptions<any, any, any>;
|
|
14
14
|
export declare function toDirectedGraph(stateMachine: AnyStateNode | AnyStateMachine): DirectedGraphNode;
|
|
15
|
-
export declare function resolveTraversalOptions<TLogic extends AnyActorLogic>(logic: TLogic, traversalOptions?: TraversalOptions<
|
|
15
|
+
export declare function resolveTraversalOptions<TLogic extends AnyActorLogic>(logic: TLogic, traversalOptions?: TraversalOptions<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, InputFrom<TLogic>>, defaultOptions?: TraversalOptions<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, InputFrom<TLogic>>): TraversalConfig<SnapshotFrom<TLogic>, EventFromLogic<TLogic>>;
|
|
16
16
|
export declare function joinPaths<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject>(headPath: StatePath<TSnapshot, TEvent>, tailPath: StatePath<TSnapshot, TEvent>): StatePath<TSnapshot, TEvent>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AnyActorLogic, EventFromLogic, InputFrom } from "../index.js";
|
|
1
|
+
import { AnyActorLogic, EventFromLogic, InputFrom, SnapshotFrom } from "../index.js";
|
|
2
2
|
import { StatePath, TraversalOptions } from "./types.js";
|
|
3
|
-
export declare function getShortestPaths<TLogic extends AnyActorLogic>(logic: TLogic, options?: TraversalOptions<
|
|
3
|
+
export declare function getShortestPaths<TLogic extends AnyActorLogic>(logic: TLogic, options?: TraversalOptions<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, InputFrom<TLogic>>): Array<StatePath<SnapshotFrom<TLogic>, EventFromLogic<TLogic>>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AnyActorLogic, EventFromLogic, InputFrom } from "../index.js";
|
|
1
|
+
import { AnyActorLogic, EventFromLogic, InputFrom, SnapshotFrom } from "../index.js";
|
|
2
2
|
import { StatePath, TraversalOptions } from "./types.js";
|
|
3
|
-
export declare function getSimplePaths<TLogic extends AnyActorLogic>(logic: TLogic, options?: TraversalOptions<
|
|
3
|
+
export declare function getSimplePaths<TLogic extends AnyActorLogic>(logic: TLogic, options?: TraversalOptions<SnapshotFrom<TLogic>, EventFromLogic<TLogic>, InputFrom<TLogic>>): Array<StatePath<SnapshotFrom<TLogic>, EventFromLogic<TLogic>>>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export * from "./actors/index.js";
|
|
2
|
-
export { createAtom, createAtomConfig, createAsyncAtom, createReducerAtom, isAtom } from "./atom.js";
|
|
3
|
-
export type { AnyAtom, AnyAtomConfig, AsyncAtomOptions, AsyncAtomState, Atom, AtomConfig, AtomOptions, BaseAtom, InputFromAtomConfig, ReadonlyAtom, ReducerAtom, ValueFromAtomConfig } from "./atom.js";
|
|
4
2
|
export { assertEvent } from "./assert.js";
|
|
5
3
|
export { Actor, createActor, type RequiredActorOptionsKeys as RequiredActorOptionsKeys } from "./createActor.js";
|
|
6
4
|
export { createMachine, createStateConfig } from "./createMachine.js";
|
|
5
|
+
export { createFSM, type FSMActorLogic, type FSMConfig, type FSMSnapshot } from "./fsm.js";
|
|
7
6
|
export { createMachineFromConfig } from "./createMachineFromConfig.js";
|
|
8
7
|
export type { ActionJSON, GuardJSON, InvokeJSON, MachineJSON, StateNodeJSON, TransitionJSON } from "./createMachineFromConfig.js";
|
|
9
|
-
export { machineConfigToJSON, serializeMachine, type
|
|
8
|
+
export { machineConfigToJSON, serializeMachine, type CodeExpression } from "./serialize.js";
|
|
10
9
|
export { mapState } from "./mapState.js";
|
|
11
10
|
export { types, isTypeSchema, type StandardSchemaV1, type TypeSchema } from "./schema.types.js";
|
|
12
|
-
export { setup } from "./setup.js";
|
|
11
|
+
export { createSystem, setup } from "./setup.js";
|
|
12
|
+
export type { AnySetupConfig, SetupConfig, SetupReturn, SetupReturnFromConfig, SetupSchemas, SystemActorMap, SystemConfig, SystemRuntime, SetupStateSchema, SetupStateSchemas } from "./setup.js";
|
|
13
13
|
export { getInitialSnapshot, getNextSnapshot } from "./getNextSnapshot.js";
|
|
14
14
|
export type { InspectionEvent, ActorInspectionEvent, TransitionInspectionEvent, ActionRecord, SentRecord } from "./inspection.js";
|
|
15
15
|
export { SimulatedClock } from "./SimulatedClock.js";
|
|
@@ -18,12 +18,13 @@ export { isMachineSnapshot, type MachineSnapshot } from "./State.js";
|
|
|
18
18
|
export { StateMachine } from "./StateMachine.js";
|
|
19
19
|
export { StateNode } from "./StateNode.js";
|
|
20
20
|
export { getStateNodes } from "./stateUtils.js";
|
|
21
|
-
export type { ActorSystem } from "./system.js";
|
|
21
|
+
export type { ActorSystem, AnyActorSystem } from "./system.js";
|
|
22
22
|
export { toPromise } from "./toPromise.js";
|
|
23
23
|
export * from "./types.js";
|
|
24
24
|
export type { Next_MachineConfig as MachineConfig, Next_StateNodeConfig as StateNodeConfig, Next_InvokeConfig as InvokeConfig, Next_TransitionConfigOrTarget as TransitionConfigOrTarget, Implementations, InferEvents, WidenLiterals } from "./types.v6.js";
|
|
25
25
|
export { getAllOwnEventDescriptors as __unsafe_getAllOwnEventDescriptors, matchesState, checkStateIn, pathToStateValue, toObserver } from "./utils.js";
|
|
26
26
|
export { transition, initialTransition, getMicrosteps, getInitialMicrosteps, getNextTransitions } from "./transition.js";
|
|
27
|
+
export { isBuiltInExecutableAction } from "./transitionActions.js";
|
|
27
28
|
export { waitFor } from "./waitFor.js";
|
|
28
29
|
declare global {
|
|
29
30
|
interface SymbolConstructor {
|
|
@@ -3,29 +3,21 @@
|
|
|
3
3
|
*
|
|
4
4
|
* `machineConfigToJSON` converts a machine config into a JSON-safe structure
|
|
5
5
|
* (the `MachineJSON` shape accepted by `createMachineFromConfig`). The boundary
|
|
6
|
-
* between serializable structure and runtime implementations is explicit:
|
|
7
|
-
*
|
|
8
|
-
* runtime schemas
|
|
9
|
-
* rather than silently dropped.
|
|
10
|
-
*
|
|
11
|
-
* A machine definition is fully portable iff its JSON contains no
|
|
12
|
-
* `$unserializable` markers; reviving a definition that has markers requires
|
|
13
|
-
* re-providing those implementations (e.g. via `machine.provide(...)` or the
|
|
14
|
-
* `actions`/`guards`/`actors` maps on `createMachineFromConfig` revival).
|
|
6
|
+
* between serializable structure and runtime implementations is explicit:
|
|
7
|
+
* functions are represented as `@code` source objects, while actor logic,
|
|
8
|
+
* runtime schemas, and other non-data runtime values are omitted.
|
|
15
9
|
*/
|
|
16
10
|
import type { AnyStateMachine } from "./types.js";
|
|
17
|
-
export interface
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
id?: string;
|
|
11
|
+
export interface CodeExpression {
|
|
12
|
+
'@code': string;
|
|
13
|
+
'@lang': 'ts';
|
|
21
14
|
}
|
|
22
15
|
/**
|
|
23
16
|
* Returns the JSON-serializable definition of a machine.
|
|
24
17
|
*
|
|
25
|
-
* Inline functions
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* round-trip):
|
|
18
|
+
* Inline functions are represented as `{ "@code": string, "@lang": "ts" }`. A
|
|
19
|
+
* machine created via `createMachineFromConfig` returns its original JSON
|
|
20
|
+
* config (lossless round-trip):
|
|
29
21
|
*
|
|
30
22
|
* ```ts
|
|
31
23
|
* import { serializeMachine, createMachineFromConfig } from 'xstate';
|
|
@@ -39,6 +31,6 @@ export interface UnserializableMarker {
|
|
|
39
31
|
export declare function serializeMachine(machine: AnyStateMachine): Record<string, unknown>;
|
|
40
32
|
/**
|
|
41
33
|
* Converts a machine config (as passed to `createMachine`) to its JSON-safe
|
|
42
|
-
* definition.
|
|
34
|
+
* definition.
|
|
43
35
|
*/
|
|
44
36
|
export declare function machineConfigToJSON(config: Record<string, unknown>): Record<string, unknown>;
|