xstate 6.0.0-alpha.3 → 6.0.0-alpha.32
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-33eec203.development.esm.js +1112 -0
- package/dist/StateMachine-d073209c.esm.js +1080 -0
- package/dist/StateMachine-d3243bd1.development.cjs.js +1120 -0
- package/dist/StateMachine-ff580dd5.cjs.js +1088 -0
- package/dist/declarations/src/State.d.ts +16 -3
- package/dist/declarations/src/StateMachine.d.ts +30 -16
- package/dist/declarations/src/StateNode.d.ts +5 -2
- package/dist/declarations/src/actions.d.ts +10 -7
- package/dist/declarations/src/actors/callback.d.ts +2 -0
- package/dist/declarations/src/actors/logic.d.ts +7 -21
- package/dist/declarations/src/actors/observable.d.ts +3 -0
- package/dist/declarations/src/actors/promise.d.ts +6 -2
- package/dist/declarations/src/createActor.d.ts +21 -14
- package/dist/declarations/src/createMachine.d.ts +24 -13
- package/dist/declarations/src/createMachineFromConfig.d.ts +64 -30
- package/dist/declarations/src/fsm.d.ts +76 -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 +9 -4
- package/dist/declarations/src/machineVersions.d.ts +51 -0
- package/dist/declarations/src/schema.types.d.ts +5 -0
- package/dist/declarations/src/serialize.d.ts +9 -22
- package/dist/declarations/src/setup.d.ts +361 -70
- package/dist/declarations/src/spawn.d.ts +5 -5
- package/dist/declarations/src/stateUtils.d.ts +17 -5
- package/dist/declarations/src/system.d.ts +38 -11
- package/dist/declarations/src/transition.d.ts +8 -5
- package/dist/declarations/src/transitionActions.d.ts +16 -0
- package/dist/declarations/src/types.d.ts +346 -144
- package/dist/declarations/src/types.v6.d.ts +294 -58
- package/dist/declarations/src/utils.d.ts +5 -3
- package/dist/declarations/src/validation/index.d.ts +37 -0
- package/dist/declarations/src/validation.types.d.ts +22 -0
- package/dist/{index-269d256d.development.cjs.js → index-691f27b9.development.cjs.js} +2358 -1116
- package/dist/{index-66ff64a6.development.esm.js → index-92227865.development.esm.js} +2335 -1115
- package/dist/{index-dda021d5.cjs.js → index-9939f02a.cjs.js} +2356 -1114
- package/dist/{index-a7e3d8b3.esm.js → index-ab93831d.esm.js} +2333 -1113
- 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 +10 -14
- package/dist/xstate-graph.development.cjs.js +10 -14
- package/dist/xstate-graph.development.esm.js +10 -14
- package/dist/xstate-graph.esm.js +10 -14
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate-validation.cjs.d.mts +2 -0
- package/dist/xstate-validation.cjs.d.ts +2 -0
- package/dist/xstate-validation.cjs.js +277 -0
- package/dist/xstate-validation.cjs.mjs +5 -0
- package/dist/xstate-validation.development.cjs.js +277 -0
- package/dist/xstate-validation.development.cjs.mjs +5 -0
- package/dist/xstate-validation.development.esm.js +271 -0
- package/dist/xstate-validation.esm.js +271 -0
- package/dist/xstate-validation.umd.min.js +2 -0
- package/dist/xstate-validation.umd.min.js.map +1 -0
- package/dist/xstate.cjs.js +1299 -294
- package/dist/xstate.cjs.mjs +6 -0
- package/dist/xstate.development.cjs.js +1299 -294
- package/dist/xstate.development.cjs.mjs +6 -0
- package/dist/xstate.development.esm.js +1293 -294
- package/dist/xstate.esm.js +1293 -294
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +23 -3
- package/validation/package.json +8 -0
- package/dist/StateMachine-0770ac71.development.cjs.js +0 -740
- package/dist/StateMachine-8249d511.esm.js +0 -720
- package/dist/StateMachine-e1048cd6.cjs.js +0 -723
- package/dist/StateMachine-e6ad61d0.development.esm.js +0 -737
|
@@ -90,47 +90,70 @@ 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
|
+
matches?: Record<string, unknown>;
|
|
133
|
+
context?: MachineContext;
|
|
113
134
|
actions?: ActionJSON[];
|
|
114
|
-
guard?:
|
|
135
|
+
guard?: ConditionJSON;
|
|
115
136
|
description?: string;
|
|
116
137
|
reenter?: boolean;
|
|
117
138
|
meta?: MetaObject;
|
|
118
139
|
input?: unknown;
|
|
119
140
|
}
|
|
141
|
+
type TransitionConfigJSON = TransitionJSON | ResolvableJSON;
|
|
120
142
|
export interface StateNodeJSON {
|
|
121
143
|
id?: string;
|
|
122
144
|
key?: string;
|
|
123
145
|
type?: 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | 'choice';
|
|
124
146
|
initial?: string;
|
|
125
147
|
states?: Record<string, StateNodeJSON>;
|
|
126
|
-
on?: Record<string,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
148
|
+
on?: Record<string, TransitionConfigJSON | TransitionConfigJSON[]>;
|
|
149
|
+
onError?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
150
|
+
after?: Record<string, TransitionConfigJSON | TransitionConfigJSON[]>;
|
|
151
|
+
always?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
152
|
+
choice?: ChoiceBranchJSON[] | ResolvableJSON;
|
|
130
153
|
/**
|
|
131
154
|
* JSON route config. Unlike the authoring API (a function), the JSON layer
|
|
132
155
|
* allows an object form whose `guard` may be a named guard reference (string)
|
|
133
|
-
* resolved against the machine's `guards`
|
|
156
|
+
* resolved against the machine's `guards` sources.
|
|
134
157
|
*/
|
|
135
158
|
route?: {
|
|
136
159
|
description?: string;
|
|
@@ -138,39 +161,50 @@ export interface StateNodeJSON {
|
|
|
138
161
|
meta?: MetaObject;
|
|
139
162
|
guard?: string;
|
|
140
163
|
input?: Record<string, unknown>;
|
|
141
|
-
};
|
|
164
|
+
} | ResolvableJSON;
|
|
142
165
|
invoke?: InvokeJSON | InvokeJSON[];
|
|
143
|
-
entry?: ActionJSON[];
|
|
144
|
-
exit?: ActionJSON[];
|
|
166
|
+
entry?: ActionJSON | ActionJSON[];
|
|
167
|
+
exit?: ActionJSON | ActionJSON[];
|
|
145
168
|
meta?: MetaObject;
|
|
146
169
|
description?: string;
|
|
147
170
|
tags?: string[];
|
|
148
171
|
input?: unknown;
|
|
149
|
-
timeout?: number | string;
|
|
150
|
-
onTimeout?:
|
|
172
|
+
timeout?: number | string | ResolvableJSON;
|
|
173
|
+
onTimeout?: TransitionConfigJSON | TransitionConfigJSON[];
|
|
151
174
|
history?: 'shallow' | 'deep';
|
|
152
|
-
target?: string;
|
|
175
|
+
target?: string | [string, ...string[]];
|
|
153
176
|
output?: unknown;
|
|
154
177
|
context?: Record<string, unknown>;
|
|
155
178
|
_scxmlDonedata?: ScxmlDonedataJSON;
|
|
156
179
|
}
|
|
157
180
|
export interface MachineJSON extends StateNodeJSON {
|
|
181
|
+
'@exprLang'?: string;
|
|
158
182
|
version?: string;
|
|
159
|
-
actions?: Record<string,
|
|
160
|
-
guards?: Record<string,
|
|
183
|
+
actions?: Record<string, ActionJSON | ActionJSON[]>;
|
|
184
|
+
guards?: Record<string, {
|
|
185
|
+
when: ConditionJSON;
|
|
186
|
+
}>;
|
|
161
187
|
actors?: Record<string, unknown>;
|
|
162
|
-
delays?: Record<string,
|
|
188
|
+
delays?: Record<string, number | string | {
|
|
189
|
+
duration: number | string | ResolvableJSON;
|
|
190
|
+
}>;
|
|
163
191
|
schemas?: Record<string, unknown>;
|
|
164
192
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
193
|
+
type EvaluatorSlot = 'context' | 'guard' | 'choice' | 'action' | 'actionParams' | 'transition' | 'input' | 'output' | 'delay' | 'transitionContext' | 'unknown';
|
|
194
|
+
type EvaluatorKind = 'expr' | 'code';
|
|
195
|
+
interface EvaluatorArgs {
|
|
196
|
+
source: string;
|
|
197
|
+
kind: EvaluatorKind;
|
|
198
|
+
slot: EvaluatorSlot;
|
|
199
|
+
scope: Record<string, unknown>;
|
|
200
|
+
path: string;
|
|
168
201
|
}
|
|
169
|
-
interface
|
|
202
|
+
interface MachineSources {
|
|
170
203
|
actions?: Record<string, (...args: any[]) => unknown>;
|
|
171
204
|
guards?: Record<string, (...args: any[]) => boolean>;
|
|
172
205
|
actors?: Record<string, AnyActorLogic>;
|
|
173
206
|
delays?: Record<string, number | ((...args: any[]) => number)>;
|
|
207
|
+
evaluators?: Record<string, (args: EvaluatorArgs) => unknown>;
|
|
174
208
|
}
|
|
175
|
-
export declare function createMachineFromConfig(json: MachineJSON,
|
|
209
|
+
export declare function createMachineFromConfig(json: MachineJSON, sources?: MachineSources): AnyStateMachine;
|
|
176
210
|
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { createTransitionEnqueue } from "./transitionActions.js";
|
|
2
|
+
import type { ActorLogic, EventObject, MachineContext, LogicalTimer, 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
|
+
timers: Record<string, LogicalTimer>;
|
|
9
|
+
_nextTimerId: number;
|
|
10
|
+
_stateInput: Record<string, unknown> | undefined;
|
|
11
|
+
machine: {
|
|
12
|
+
id: string;
|
|
13
|
+
sources: {
|
|
14
|
+
actions: {};
|
|
15
|
+
actors: {};
|
|
16
|
+
guards: {};
|
|
17
|
+
delays: {};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
type FSMArgs<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = {
|
|
22
|
+
context: TContext;
|
|
23
|
+
event: TEvent;
|
|
24
|
+
input: TInput | undefined;
|
|
25
|
+
value: TState;
|
|
26
|
+
self: any;
|
|
27
|
+
system: any;
|
|
28
|
+
parent: any;
|
|
29
|
+
children: {};
|
|
30
|
+
};
|
|
31
|
+
type FSMAction<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = (args: FSMArgs<TContext, TEvent, TState, TInput> & {
|
|
32
|
+
input: Record<string, unknown> | undefined;
|
|
33
|
+
}, enq: ReturnType<typeof createTransitionEnqueue>) => void | {
|
|
34
|
+
context?: FSMContextPatch<TContext>;
|
|
35
|
+
};
|
|
36
|
+
type FSMGuard<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = (args: FSMArgs<TContext, TEvent, TState, TInput>) => boolean;
|
|
37
|
+
type FSMContextPatch<TContext extends MachineContext> = Partial<TContext> & {
|
|
38
|
+
call?: never;
|
|
39
|
+
apply?: never;
|
|
40
|
+
bind?: never;
|
|
41
|
+
};
|
|
42
|
+
type FSMContextMapper<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = (args: FSMArgs<TContext, TEvent, TState, TInput>) => FSMContextPatch<TContext>;
|
|
43
|
+
type FSMTarget<TContext extends MachineContext> = {
|
|
44
|
+
target?: string;
|
|
45
|
+
context?: FSMContextPatch<TContext>;
|
|
46
|
+
input?: Record<string, unknown> | ((args: {
|
|
47
|
+
context: TContext;
|
|
48
|
+
event: EventObject;
|
|
49
|
+
}) => Record<string, unknown>);
|
|
50
|
+
};
|
|
51
|
+
type FSMObjectTarget<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = Omit<FSMTarget<TContext>, 'context'> & {
|
|
52
|
+
context?: FSMContextPatch<TContext> | FSMContextMapper<TContext, TEvent, TState, TInput>;
|
|
53
|
+
};
|
|
54
|
+
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>;
|
|
55
|
+
type FSMTransition<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = FSMObjectTarget<TContext, TEvent, TState, TInput> | (FSMObjectTarget<TContext, TEvent, TState, TInput> & {
|
|
56
|
+
guard?: FSMGuard<TContext, TEvent, TState, TInput>;
|
|
57
|
+
actions?: FSMAction<TContext, TEvent, TState, TInput> | Array<FSMAction<TContext, TEvent, TState, TInput>>;
|
|
58
|
+
}) | FSMTransitionFunction<TContext, TEvent, TState, TInput>;
|
|
59
|
+
type FSMStateConfig<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = {
|
|
60
|
+
entry?: FSMAction<TContext, TEvent, TState, TInput> | Array<FSMAction<TContext, TEvent, TState, TInput>>;
|
|
61
|
+
exit?: FSMAction<TContext, TEvent, TState, TInput> | Array<FSMAction<TContext, TEvent, TState, TInput>>;
|
|
62
|
+
on?: Record<string, FSMTransition<TContext, TEvent, TState, TInput> | Array<FSMTransition<TContext, TEvent, TState, TInput>>>;
|
|
63
|
+
};
|
|
64
|
+
export type FSMConfig<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput = NonReducibleUnknown> = {
|
|
65
|
+
id?: string;
|
|
66
|
+
initial: TState;
|
|
67
|
+
context?: TContext | ((args: {
|
|
68
|
+
input: TInput;
|
|
69
|
+
}) => TContext);
|
|
70
|
+
states: Record<TState, FSMStateConfig<TContext, TEvent, TState, TInput>>;
|
|
71
|
+
};
|
|
72
|
+
export type FSMActorLogic<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TInput> = ActorLogic<FSMSnapshot<TContext, TState, TInput>, TEvent, TInput, any, EventObject> & {
|
|
73
|
+
id?: string;
|
|
74
|
+
};
|
|
75
|
+
export declare function createFSM<TContext extends MachineContext, TEvent extends EventObject, TInput = NonReducibleUnknown>(config: FSMConfig<TContext, TEvent, string, TInput>): FSMActorLogic<TContext, TEvent, string, TInput>;
|
|
76
|
+
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>>>;
|
|
@@ -2,12 +2,16 @@ export * from "./actors/index.js";
|
|
|
2
2
|
export { assertEvent } from "./assert.js";
|
|
3
3
|
export { Actor, createActor, type RequiredActorOptionsKeys as RequiredActorOptionsKeys } from "./createActor.js";
|
|
4
4
|
export { createMachine, createStateConfig } from "./createMachine.js";
|
|
5
|
+
export { createFSM, type FSMActorLogic, type FSMConfig, type FSMSnapshot } from "./fsm.js";
|
|
5
6
|
export { createMachineFromConfig } from "./createMachineFromConfig.js";
|
|
6
7
|
export type { ActionJSON, GuardJSON, InvokeJSON, MachineJSON, StateNodeJSON, TransitionJSON } from "./createMachineFromConfig.js";
|
|
7
|
-
export { machineConfigToJSON, serializeMachine, type CodeExpression
|
|
8
|
+
export { machineConfigToJSON, serializeMachine, type CodeExpression } from "./serialize.js";
|
|
8
9
|
export { mapState } from "./mapState.js";
|
|
10
|
+
export { machineVersions, migrateSnapshot, type MachineVersionsOptions, type ParsedPersistedSnapshot, type PersistedMachineIdentity, type PersistedSnapshotDataFrom, type SnapshotMigrationHandlers, type PersistedSnapshotFrom } from "./machineVersions.js";
|
|
9
11
|
export { types, isTypeSchema, type StandardSchemaV1, type TypeSchema } from "./schema.types.js";
|
|
10
|
-
export {
|
|
12
|
+
export type { ActorValidationBoundary, ActorValidationEventOrigin, ActorValidationRequest, ActorLogicValidator } from "./validation.types.js";
|
|
13
|
+
export { createSystem, setup } from "./setup.js";
|
|
14
|
+
export type { AnySetupConfig, SetupConfig, SetupReturn, SetupReturnFromConfig, SetupSchemas, SystemActorMap, SystemConfig, SystemRuntime, SetupStateSchema, SetupStateSchemas } from "./setup.js";
|
|
11
15
|
export { getInitialSnapshot, getNextSnapshot } from "./getNextSnapshot.js";
|
|
12
16
|
export type { InspectionEvent, ActorInspectionEvent, TransitionInspectionEvent, ActionRecord, SentRecord } from "./inspection.js";
|
|
13
17
|
export { SimulatedClock } from "./SimulatedClock.js";
|
|
@@ -16,12 +20,13 @@ export { isMachineSnapshot, type MachineSnapshot } from "./State.js";
|
|
|
16
20
|
export { StateMachine } from "./StateMachine.js";
|
|
17
21
|
export { StateNode } from "./StateNode.js";
|
|
18
22
|
export { getStateNodes } from "./stateUtils.js";
|
|
19
|
-
export type { ActorSystem } from "./system.js";
|
|
23
|
+
export type { ActorSystem, ActorSystemRuntime, AnyActorSystem } from "./system.js";
|
|
20
24
|
export { toPromise } from "./toPromise.js";
|
|
21
25
|
export * from "./types.js";
|
|
22
|
-
export type { Next_MachineConfig as MachineConfig, Next_StateNodeConfig as StateNodeConfig, Next_InvokeConfig as InvokeConfig, Next_TransitionConfigOrTarget as TransitionConfigOrTarget,
|
|
26
|
+
export type { Next_MachineConfig as MachineConfig, Next_StateNodeConfig as StateNodeConfig, Next_InvokeConfig as InvokeConfig, Next_TransitionConfigOrTarget as TransitionConfigOrTarget, Sources, InferEvents, WidenLiterals } from "./types.v6.js";
|
|
23
27
|
export { getAllOwnEventDescriptors as __unsafe_getAllOwnEventDescriptors, matchesState, checkStateIn, pathToStateValue, toObserver } from "./utils.js";
|
|
24
28
|
export { transition, initialTransition, getMicrosteps, getInitialMicrosteps, getNextTransitions } from "./transition.js";
|
|
29
|
+
export { executeEffects, isBuiltInExecutableAction } from "./transitionActions.js";
|
|
25
30
|
export { waitFor } from "./waitFor.js";
|
|
26
31
|
declare global {
|
|
27
32
|
interface SymbolConstructor {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { AnyMachineSchemas } from "./types.v6.js";
|
|
2
|
+
import type { AnyStateMachine, ContextFrom, PersistedSnapshotFor, Snapshot } from "./types.js";
|
|
3
|
+
export type PersistedMachineIdentity<TMachine extends AnyStateMachine = AnyStateMachine> = {
|
|
4
|
+
id: TMachine['id'];
|
|
5
|
+
version: NonNullable<TMachine['version']>;
|
|
6
|
+
};
|
|
7
|
+
type VersionedStateMachine = AnyStateMachine & {
|
|
8
|
+
version: string;
|
|
9
|
+
schemas?: AnyMachineSchemas;
|
|
10
|
+
};
|
|
11
|
+
export type PersistedSnapshotFrom<TMachine extends AnyStateMachine> = Snapshot<unknown> & PersistedSnapshotFor<TMachine> & {
|
|
12
|
+
context: ContextFrom<TMachine>;
|
|
13
|
+
machine: PersistedMachineIdentity<TMachine>;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
export type PersistedSnapshotDataFrom<TMachine extends AnyStateMachine> = Snapshot<unknown> & {
|
|
17
|
+
context: ContextFrom<TMachine>;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
};
|
|
20
|
+
export type ParsedPersistedSnapshot<TMachines extends readonly AnyStateMachine[]> = {
|
|
21
|
+
[K in keyof TMachines]: TMachines[K] extends AnyStateMachine ? {
|
|
22
|
+
machine: TMachines[K];
|
|
23
|
+
snapshot: PersistedSnapshotFrom<TMachines[K]>;
|
|
24
|
+
} : never;
|
|
25
|
+
}[number];
|
|
26
|
+
export type MachineVersionsOptions<TMachines extends readonly AnyStateMachine[]> = {
|
|
27
|
+
unversioned?: NonNullable<TMachines[number]['version']>;
|
|
28
|
+
};
|
|
29
|
+
type ParsedSnapshotSource = {
|
|
30
|
+
machine: VersionedStateMachine;
|
|
31
|
+
snapshot: Snapshot<unknown> & {
|
|
32
|
+
context: unknown;
|
|
33
|
+
machine: PersistedMachineIdentity;
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
type SourceVersion<TSource extends ParsedSnapshotSource> = TSource extends unknown ? NonNullable<TSource['machine']['version']> : never;
|
|
38
|
+
type SourceForVersion<TSource extends ParsedSnapshotSource, TVersion extends string> = TSource extends unknown ? TSource['machine']['version'] extends TVersion ? TSource : never : never;
|
|
39
|
+
export type SnapshotMigrationHandlers<TSource extends ParsedSnapshotSource, TTarget extends AnyStateMachine> = {
|
|
40
|
+
[TVersion in SourceVersion<TSource>]?: (snapshot: SourceForVersion<TSource, TVersion>['snapshot']) => PersistedSnapshotDataFrom<TTarget>;
|
|
41
|
+
};
|
|
42
|
+
/** Creates parsers backed by retained versions of one machine. */
|
|
43
|
+
export declare function machineVersions<const TMachines extends readonly [
|
|
44
|
+
VersionedStateMachine,
|
|
45
|
+
...VersionedStateMachine[]
|
|
46
|
+
]>(machines: TMachines, options?: MachineVersionsOptions<TMachines>): {
|
|
47
|
+
parseSnapshot(raw: unknown): Promise<ParsedPersistedSnapshot<TMachines>>;
|
|
48
|
+
};
|
|
49
|
+
/** Migrates a parsed persisted snapshot directly to a target machine. */
|
|
50
|
+
export declare function migrateSnapshot<TSource extends ParsedSnapshotSource, TTarget extends VersionedStateMachine>(source: TSource, target: TTarget, migrations: SnapshotMigrationHandlers<TSource, TTarget>): Promise<PersistedSnapshotFrom<TTarget>>;
|
|
51
|
+
export {};
|
|
@@ -3,6 +3,11 @@ export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
|
3
3
|
/** The Standard Schema properties. */
|
|
4
4
|
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
5
5
|
}
|
|
6
|
+
/** Schemas that can be declared for an individual state node. */
|
|
7
|
+
export type SetupStateSchemas = {
|
|
8
|
+
context?: StandardSchemaV1;
|
|
9
|
+
input?: StandardSchemaV1;
|
|
10
|
+
};
|
|
6
11
|
/** A type-only Standard Schema produced by {@link types}. */
|
|
7
12
|
export interface TypeSchema<T> extends StandardSchemaV1<T, T> {
|
|
8
13
|
readonly '~standard': StandardSchemaV1.Props<T, T> & {
|
|
@@ -3,34 +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
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* "$unserializable": <kind> }` marker 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 sources is explicit: functions are
|
|
7
|
+
* represented as `@code` source objects, while actor logic, runtime schemas,
|
|
8
|
+
* and other non-data runtime values are omitted.
|
|
15
9
|
*/
|
|
16
10
|
import type { AnyStateMachine } from "./types.js";
|
|
17
|
-
export interface UnserializableMarker {
|
|
18
|
-
$unserializable: 'function' | 'actor' | 'schema' | 'value';
|
|
19
|
-
/** Best-effort identifier (function name, actor logic id) for diagnostics. */
|
|
20
|
-
id?: string;
|
|
21
|
-
}
|
|
22
11
|
export interface CodeExpression {
|
|
23
|
-
'@
|
|
24
|
-
lang: 'ts';
|
|
25
|
-
expr: string;
|
|
12
|
+
'@code': string;
|
|
13
|
+
'@lang': 'ts';
|
|
26
14
|
}
|
|
27
15
|
/**
|
|
28
16
|
* Returns the JSON-serializable definition of a machine.
|
|
29
17
|
*
|
|
30
|
-
* Inline functions are represented as `{ "@
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* JSON config (lossless 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):
|
|
34
21
|
*
|
|
35
22
|
* ```ts
|
|
36
23
|
* import { serializeMachine, createMachineFromConfig } from 'xstate';
|
|
@@ -44,6 +31,6 @@ export interface CodeExpression {
|
|
|
44
31
|
export declare function serializeMachine(machine: AnyStateMachine): Record<string, unknown>;
|
|
45
32
|
/**
|
|
46
33
|
* Converts a machine config (as passed to `createMachine`) to its JSON-safe
|
|
47
|
-
* definition.
|
|
34
|
+
* definition.
|
|
48
35
|
*/
|
|
49
36
|
export declare function machineConfigToJSON(config: Record<string, unknown>): Record<string, unknown>;
|