xstate 5.32.0 → 6.0.0-alpha.1
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-47e60715.esm.js +720 -0
- package/dist/StateMachine-48dcad8f.cjs.js +723 -0
- package/dist/StateMachine-6e063ac1.development.cjs.js +740 -0
- package/dist/StateMachine-6ec50e21.development.esm.js +737 -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 -123
- 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 +407 -406
- package/dist/declarations/src/types.v6.d.ts +392 -0
- package/dist/declarations/src/utils.d.ts +4 -3
- package/dist/index-39259ea4.development.esm.js +4948 -0
- package/dist/index-688701ed.esm.js +4909 -0
- package/dist/index-c35824b4.development.cjs.js +5007 -0
- package/dist/index-f0d7107d.cjs.js +4968 -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 -108
- package/dist/xstate.cjs.mjs +22 -22
- package/dist/xstate.development.cjs.js +1316 -108
- package/dist/xstate.development.cjs.mjs +22 -22
- package/dist/xstate.development.esm.js +1278 -72
- package/dist/xstate.esm.js +1278 -72
- 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-029f180b.development.cjs.js +0 -433
- package/dist/log-5a37e0ee.development.esm.js +0 -425
- package/dist/log-605ef461.esm.js +0 -397
- package/dist/log-fedf0966.cjs.js +0 -405
- 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,5 +1,7 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from "./schema.types.js";
|
|
1
2
|
import { StateMachine } from "./StateMachine.js";
|
|
2
|
-
import {
|
|
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
5
|
/**
|
|
4
6
|
* Creates a state machine (statechart) with the given configuration.
|
|
5
7
|
*
|
|
@@ -42,9 +44,35 @@ import { ResolvedStateMachineTypes, TODO, AnyActorRef, EventObject, AnyEventObje
|
|
|
42
44
|
* @param options DEPRECATED: use `setup({ ... })` or `machine.provide({ ... })`
|
|
43
45
|
* to provide machine implementations instead.
|
|
44
46
|
*/
|
|
45
|
-
export declare function createMachine<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
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['actors'], 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, InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap> & {
|
|
48
|
+
schemas: {
|
|
49
|
+
context: TContextSchema;
|
|
50
|
+
};
|
|
51
|
+
}): StateMachine<InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap> | ([RoutableStateId<TSS>] extends [never] ? never : {
|
|
52
|
+
type: 'xstate.route';
|
|
53
|
+
to: RoutableStateId<TSS>;
|
|
54
|
+
}), Cast<ToChildren<TActor>, Record<string, AnyActorRef | undefined>>, StateValue, TTag & string, TInput, InferOutput<TOutputSchema, unknown>, WithDefault<InferEvents<TEmittedSchemaMap>, AnyEventObject>, InferOutput<TMetaSchema, MetaObject>, // TMeta
|
|
55
|
+
TSS, // TStateSchema
|
|
56
|
+
TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>> & {
|
|
57
|
+
states: TSS;
|
|
58
|
+
};
|
|
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['actors'] = Implementations['actors'], 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, WidenLiterals<TContext>, InferEvents<TEventSchemaMap>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, false> & {
|
|
60
|
+
schemas?: {
|
|
61
|
+
context?: never;
|
|
62
|
+
};
|
|
63
|
+
context?: TContext | ((_: {
|
|
64
|
+
spawn: any;
|
|
65
|
+
actors: TActorMap;
|
|
66
|
+
input: InferOutput<TInputSchema, unknown>;
|
|
67
|
+
self: any;
|
|
68
|
+
}) => TContext);
|
|
69
|
+
}): StateMachine<WidenLiterals<TContext>, InferEvents<TEventSchemaMap> | ([RoutableStateId<TSS>] extends [never] ? never : {
|
|
70
|
+
type: 'xstate.route';
|
|
71
|
+
to: RoutableStateId<TSS>;
|
|
72
|
+
}), Cast<ToChildren<TActor>, Record<string, AnyActorRef | undefined>>, StateValue, TTag & string, TInput, InferOutput<TOutputSchema, unknown>, WithDefault<InferEvents<TEmittedSchemaMap>, AnyEventObject>, InferOutput<TMetaSchema, MetaObject>, // TMeta
|
|
73
|
+
TSS, // TStateSchema
|
|
74
|
+
TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>> & {
|
|
75
|
+
states: TSS;
|
|
76
|
+
};
|
|
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['actors'], 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<TActionMap>, DoNotInfer<TActorMap>, DoNotInfer<TGuardMap>, DoNotInfer<TDelayMap>>): typeof config;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { AnyActorLogic, AnyEventObject, AnyStateMachine, EventObject, MachineContext, MetaObject } from "./types.js";
|
|
2
|
+
export interface RaiseJSON {
|
|
3
|
+
type: '@xstate.raise';
|
|
4
|
+
event: EventObject;
|
|
5
|
+
id?: string;
|
|
6
|
+
delay?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface CancelJSON {
|
|
9
|
+
type: '@xstate.cancel';
|
|
10
|
+
id: string;
|
|
11
|
+
}
|
|
12
|
+
export interface LogJSON {
|
|
13
|
+
type: '@xstate.log';
|
|
14
|
+
args: any[];
|
|
15
|
+
}
|
|
16
|
+
interface EmitJSON {
|
|
17
|
+
type: '@xstate.emit';
|
|
18
|
+
event: AnyEventObject;
|
|
19
|
+
}
|
|
20
|
+
interface AssignJSON {
|
|
21
|
+
type: '@xstate.assign';
|
|
22
|
+
context: MachineContext;
|
|
23
|
+
}
|
|
24
|
+
interface ScxmlAssignJSON {
|
|
25
|
+
type: 'scxml.assign';
|
|
26
|
+
/** SCXML location attribute - the context property to assign to */
|
|
27
|
+
location: string;
|
|
28
|
+
/** SCXML expr attribute - expression to evaluate */
|
|
29
|
+
expr: string;
|
|
30
|
+
}
|
|
31
|
+
export interface ScxmlRaiseJSON {
|
|
32
|
+
type: 'scxml.raise';
|
|
33
|
+
/** Event type, or undefined if using eventexpr */
|
|
34
|
+
event?: string;
|
|
35
|
+
/** Expression to evaluate for event type */
|
|
36
|
+
eventexpr?: string;
|
|
37
|
+
/** Params with expressions to evaluate */
|
|
38
|
+
params?: Array<{
|
|
39
|
+
name: string;
|
|
40
|
+
expr: string;
|
|
41
|
+
}>;
|
|
42
|
+
id?: string;
|
|
43
|
+
delay?: number;
|
|
44
|
+
/** Expression for delay */
|
|
45
|
+
delayexpr?: string;
|
|
46
|
+
/** Static target (e.g. '#_parent') */
|
|
47
|
+
target?: string;
|
|
48
|
+
/** Expression for target */
|
|
49
|
+
targetexpr?: string;
|
|
50
|
+
}
|
|
51
|
+
interface ScxmlScriptJSON {
|
|
52
|
+
type: 'scxml.script';
|
|
53
|
+
/** The script code to execute */
|
|
54
|
+
code: string;
|
|
55
|
+
}
|
|
56
|
+
export interface ScxmlForeachJSON {
|
|
57
|
+
type: 'scxml.foreach';
|
|
58
|
+
array: string;
|
|
59
|
+
item: string;
|
|
60
|
+
index?: string;
|
|
61
|
+
actions: ActionJSON[];
|
|
62
|
+
}
|
|
63
|
+
export interface ScxmlCancelJSON {
|
|
64
|
+
type: 'scxml.cancel';
|
|
65
|
+
sendidexpr: string;
|
|
66
|
+
}
|
|
67
|
+
export interface ScxmlDonedataJSON {
|
|
68
|
+
params?: Array<{
|
|
69
|
+
name: string;
|
|
70
|
+
expr: string;
|
|
71
|
+
}>;
|
|
72
|
+
contentExpr?: string;
|
|
73
|
+
contentText?: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Isolated executable-content block. Errors in nested actions stop this block
|
|
77
|
+
* but do not propagate to the surrounding action list. Used to model SCXML's
|
|
78
|
+
* separate <onentry>/<onexit> blocks: each is its own block per spec.
|
|
79
|
+
*/
|
|
80
|
+
interface ScxmlBlockJSON {
|
|
81
|
+
type: 'scxml.block';
|
|
82
|
+
actions: ActionJSON[];
|
|
83
|
+
}
|
|
84
|
+
interface ScxmlIfJSON {
|
|
85
|
+
type: 'scxml.if';
|
|
86
|
+
branches: Array<{
|
|
87
|
+
cond?: string;
|
|
88
|
+
actions: ActionJSON[];
|
|
89
|
+
}>;
|
|
90
|
+
}
|
|
91
|
+
interface CustomActionJSON {
|
|
92
|
+
type: string;
|
|
93
|
+
params?: Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
export type ActionJSON = CustomActionJSON | RaiseJSON | CancelJSON | LogJSON | EmitJSON | AssignJSON | ScxmlAssignJSON | ScxmlRaiseJSON | ScxmlScriptJSON | ScxmlIfJSON | ScxmlForeachJSON | ScxmlCancelJSON | ScxmlBlockJSON;
|
|
96
|
+
export interface GuardJSON {
|
|
97
|
+
type: string;
|
|
98
|
+
params?: Record<string, unknown>;
|
|
99
|
+
}
|
|
100
|
+
export interface InvokeJSON {
|
|
101
|
+
id?: string;
|
|
102
|
+
systemId?: string;
|
|
103
|
+
src: string | UnserializableMarker;
|
|
104
|
+
input?: unknown;
|
|
105
|
+
onDone?: TransitionJSON | TransitionJSON[];
|
|
106
|
+
onError?: TransitionJSON | TransitionJSON[];
|
|
107
|
+
onSnapshot?: TransitionJSON | TransitionJSON[];
|
|
108
|
+
timeout?: number | string;
|
|
109
|
+
onTimeout?: TransitionJSON | TransitionJSON[];
|
|
110
|
+
}
|
|
111
|
+
export interface TransitionJSON {
|
|
112
|
+
target?: string | string[];
|
|
113
|
+
actions?: ActionJSON[];
|
|
114
|
+
guard?: GuardJSON;
|
|
115
|
+
description?: string;
|
|
116
|
+
reenter?: boolean;
|
|
117
|
+
meta?: MetaObject;
|
|
118
|
+
input?: unknown;
|
|
119
|
+
}
|
|
120
|
+
export interface StateNodeJSON {
|
|
121
|
+
id?: string;
|
|
122
|
+
key?: string;
|
|
123
|
+
type?: 'atomic' | 'compound' | 'parallel' | 'final' | 'history' | 'choice';
|
|
124
|
+
initial?: string;
|
|
125
|
+
states?: Record<string, StateNodeJSON>;
|
|
126
|
+
on?: Record<string, TransitionJSON | TransitionJSON[]>;
|
|
127
|
+
after?: Record<string, TransitionJSON | TransitionJSON[]>;
|
|
128
|
+
always?: TransitionJSON | TransitionJSON[];
|
|
129
|
+
choice?: TransitionJSON;
|
|
130
|
+
/**
|
|
131
|
+
* JSON route config. Unlike the authoring API (a function), the JSON layer
|
|
132
|
+
* allows an object form whose `guard` may be a named guard reference (string)
|
|
133
|
+
* resolved against the machine's `guards` implementations.
|
|
134
|
+
*/
|
|
135
|
+
route?: {
|
|
136
|
+
description?: string;
|
|
137
|
+
reenter?: boolean;
|
|
138
|
+
meta?: MetaObject;
|
|
139
|
+
guard?: string;
|
|
140
|
+
input?: Record<string, unknown>;
|
|
141
|
+
};
|
|
142
|
+
invoke?: InvokeJSON | InvokeJSON[];
|
|
143
|
+
entry?: ActionJSON[];
|
|
144
|
+
exit?: ActionJSON[];
|
|
145
|
+
meta?: MetaObject;
|
|
146
|
+
description?: string;
|
|
147
|
+
tags?: string[];
|
|
148
|
+
input?: unknown;
|
|
149
|
+
timeout?: number | string;
|
|
150
|
+
onTimeout?: TransitionJSON | TransitionJSON[];
|
|
151
|
+
history?: 'shallow' | 'deep';
|
|
152
|
+
target?: string;
|
|
153
|
+
output?: unknown;
|
|
154
|
+
context?: Record<string, unknown>;
|
|
155
|
+
_scxmlDonedata?: ScxmlDonedataJSON;
|
|
156
|
+
}
|
|
157
|
+
export interface MachineJSON extends StateNodeJSON {
|
|
158
|
+
version?: string;
|
|
159
|
+
actions?: Record<string, unknown>;
|
|
160
|
+
guards?: Record<string, unknown>;
|
|
161
|
+
actors?: Record<string, unknown>;
|
|
162
|
+
delays?: Record<string, unknown>;
|
|
163
|
+
schemas?: Record<string, unknown>;
|
|
164
|
+
}
|
|
165
|
+
interface UnserializableMarker {
|
|
166
|
+
$unserializable: 'function' | 'actor' | 'schema' | 'value';
|
|
167
|
+
id?: string;
|
|
168
|
+
}
|
|
169
|
+
interface MachineImplementations {
|
|
170
|
+
actions?: Record<string, (...args: any[]) => unknown>;
|
|
171
|
+
guards?: Record<string, (...args: any[]) => boolean>;
|
|
172
|
+
actors?: Record<string, AnyActorLogic>;
|
|
173
|
+
delays?: Record<string, number | ((...args: any[]) => number)>;
|
|
174
|
+
}
|
|
175
|
+
export declare function createMachineFromConfig(json: MachineJSON, implementations?: MachineImplementations): AnyStateMachine;
|
|
176
|
+
export {};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { EventObject, AnyStateMachine, AnyActorLogic, EventFromLogic, Snapshot, InputFrom } from "../index.js";
|
|
1
|
+
import { EventObject, AnyStateMachine, StateNode, AnyActorLogic, EventFromLogic, Snapshot, InputFrom } 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`.
|
|
5
5
|
*
|
|
6
6
|
* @param stateNode State node to recursively get child state nodes from
|
|
7
7
|
*/
|
|
8
|
-
export declare function getStateNodes(stateNode:
|
|
8
|
+
export declare function getStateNodes(stateNode: {
|
|
9
|
+
states: Record<string, AnyStateNode | StateNode<never, EventObject>>;
|
|
10
|
+
}): AnyStateNode[];
|
|
9
11
|
export declare function serializeSnapshot(snapshot: Snapshot<any>): SerializedSnapshot;
|
|
10
12
|
export declare function createDefaultMachineOptions<TMachine extends AnyStateMachine>(machine: TMachine, options?: TraversalOptions<ReturnType<TMachine['transition']>, EventFromLogic<TMachine>, InputFrom<TMachine>>): TraversalOptions<ReturnType<TMachine['transition']>, EventFromLogic<TMachine>, InputFrom<TMachine>>;
|
|
11
13
|
export declare function createDefaultLogicOptions(): TraversalOptions<any, any, any>;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
export * from "./actions.js";
|
|
2
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";
|
|
3
4
|
export { assertEvent } from "./assert.js";
|
|
4
|
-
export { Actor, createActor,
|
|
5
|
-
export { createMachine } from "./createMachine.js";
|
|
5
|
+
export { Actor, createActor, type RequiredActorOptionsKeys as RequiredActorOptionsKeys } from "./createActor.js";
|
|
6
|
+
export { createMachine, createStateConfig } from "./createMachine.js";
|
|
7
|
+
export { createMachineFromConfig } from "./createMachineFromConfig.js";
|
|
8
|
+
export type { ActionJSON, GuardJSON, InvokeJSON, MachineJSON, StateNodeJSON, TransitionJSON } from "./createMachineFromConfig.js";
|
|
9
|
+
export { machineConfigToJSON, serializeMachine, type UnserializableMarker } from "./serialize.js";
|
|
6
10
|
export { mapState } from "./mapState.js";
|
|
11
|
+
export { types, isTypeSchema, type StandardSchemaV1, type TypeSchema } from "./schema.types.js";
|
|
12
|
+
export { setup } from "./setup.js";
|
|
7
13
|
export { getInitialSnapshot, getNextSnapshot } from "./getNextSnapshot.js";
|
|
8
|
-
export {
|
|
9
|
-
export type { GuardPredicate, GuardArgs } from "./guards.js";
|
|
10
|
-
export type { InspectedActionEvent, InspectedActorEvent, InspectedEventEvent, InspectedMicrostepEvent, InspectedSnapshotEvent, InspectedTransitionEvent, InspectionEvent } from "./inspection.js";
|
|
11
|
-
export { setup, type SetupReturn } from "./setup.js";
|
|
14
|
+
export type { InspectionEvent, ActorInspectionEvent, TransitionInspectionEvent, ActionRecord, SentRecord } from "./inspection.js";
|
|
12
15
|
export { SimulatedClock } from "./SimulatedClock.js";
|
|
13
16
|
export { type Spawner } from "./spawn.js";
|
|
14
17
|
export { isMachineSnapshot, type MachineSnapshot } from "./State.js";
|
|
@@ -18,7 +21,8 @@ export { getStateNodes } from "./stateUtils.js";
|
|
|
18
21
|
export type { ActorSystem } from "./system.js";
|
|
19
22
|
export { toPromise } from "./toPromise.js";
|
|
20
23
|
export * from "./types.js";
|
|
21
|
-
export {
|
|
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
|
+
export { getAllOwnEventDescriptors as __unsafe_getAllOwnEventDescriptors, matchesState, checkStateIn, pathToStateValue, toObserver } from "./utils.js";
|
|
22
26
|
export { transition, initialTransition, getMicrosteps, getInitialMicrosteps, getNextTransitions } from "./transition.js";
|
|
23
27
|
export { waitFor } from "./waitFor.js";
|
|
24
28
|
declare global {
|
|
@@ -1,45 +1,99 @@
|
|
|
1
|
-
import { ActorRefLike, AnyEventObject, AnyTransitionDefinition, Snapshot } from "./types.js";
|
|
2
|
-
|
|
1
|
+
import { ActorRefLike, AnyActorLogic, AnyEventObject, AnyTransitionDefinition, Snapshot } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* A record of a single action executed during a transition.
|
|
4
|
+
*
|
|
5
|
+
* Carried in {@link TransitionInspectionEvent.actions}, this replaces the v5
|
|
6
|
+
* standalone `@xstate.action` inspection event.
|
|
7
|
+
*/
|
|
8
|
+
export interface ActionRecord {
|
|
9
|
+
/** The action type (e.g. the action creator name or `'(anonymous)'`). */
|
|
10
|
+
type: string;
|
|
11
|
+
/** The resolved params for the action, if any. */
|
|
12
|
+
params: unknown;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A record of a single event relayed to another actor during a transition.
|
|
16
|
+
*
|
|
17
|
+
* Carried in {@link TransitionInspectionEvent.sent}, this captures the send on
|
|
18
|
+
* the _sender's_ transition — including delayed/scheduled sends that may never
|
|
19
|
+
* deliver — distinct from the target actor's own processed-event transition.
|
|
20
|
+
*/
|
|
21
|
+
export interface SentRecord {
|
|
22
|
+
/** The actor the event was sent to. */
|
|
23
|
+
targetRef: ActorRefLike;
|
|
24
|
+
/** The `id` of the target actor. */
|
|
25
|
+
targetId: string;
|
|
26
|
+
/** The event that was sent. */
|
|
27
|
+
event: AnyEventObject;
|
|
28
|
+
/** The delay (ms) for a scheduled send, or `undefined` for an immediate send. */
|
|
29
|
+
delay?: number;
|
|
30
|
+
/** The scheduling id for a scheduled send, used for cancellation. */
|
|
31
|
+
id?: string;
|
|
32
|
+
}
|
|
3
33
|
interface BaseInspectionEventProperties {
|
|
34
|
+
/** The session ID of the root actor. */
|
|
4
35
|
rootId: string;
|
|
5
36
|
/**
|
|
6
37
|
* The relevant actorRef for the inspection event.
|
|
7
38
|
*
|
|
8
|
-
* - For
|
|
9
|
-
* - For
|
|
10
|
-
* - For actor events, this is the `actorRef` of the registered actor.
|
|
39
|
+
* - For `@xstate.actor` events, this is the registered actor.
|
|
40
|
+
* - For `@xstate.transition` events, this is the actor that transitioned.
|
|
11
41
|
*/
|
|
12
42
|
actorRef: ActorRefLike;
|
|
13
43
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Announces that an actor was created in the system (the root actor and every
|
|
46
|
+
* spawned/invoked child). This is the single topology event — it carries the
|
|
47
|
+
* actor identity and parent relationship needed to draw the actor graph before
|
|
48
|
+
* any transitions occur.
|
|
49
|
+
*
|
|
50
|
+
* Actor _stop_ is derivable from `snapshot.status` on the actor's final
|
|
51
|
+
* `@xstate.transition` event, so there is no separate stop event.
|
|
52
|
+
*/
|
|
53
|
+
export interface ActorInspectionEvent extends BaseInspectionEventProperties {
|
|
54
|
+
type: '@xstate.actor';
|
|
55
|
+
/** The parent actor, or `undefined` for the root actor. */
|
|
56
|
+
parentRef: ActorRefLike | undefined;
|
|
57
|
+
/** The `id` of the actor. */
|
|
58
|
+
id: string;
|
|
59
|
+
/** The source logic (or its referenced string) the actor was created from. */
|
|
60
|
+
src: string | AnyActorLogic;
|
|
61
|
+
/** The initial snapshot of the actor. */
|
|
17
62
|
snapshot: Snapshot<unknown>;
|
|
18
63
|
}
|
|
19
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Announces an actor transition.
|
|
66
|
+
*
|
|
67
|
+
* All facets are flat and always present so consumers can read `event.actions`,
|
|
68
|
+
* `event.sent`, and `event.microsteps` directly without narrowing on absent
|
|
69
|
+
* properties. This is a superset of the v5
|
|
70
|
+
* `@xstate.event`/`@xstate.snapshot`/`@xstate.action`/`@xstate.microstep`
|
|
71
|
+
* events.
|
|
72
|
+
*/
|
|
73
|
+
export interface TransitionInspectionEvent extends BaseInspectionEventProperties {
|
|
20
74
|
type: '@xstate.transition';
|
|
75
|
+
eventType: string;
|
|
76
|
+
/** The event that caused the transition. */
|
|
21
77
|
event: AnyEventObject;
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
export interface InspectedMicrostepEvent extends BaseInspectionEventProperties {
|
|
25
|
-
type: '@xstate.microstep';
|
|
26
|
-
event: AnyEventObject;
|
|
27
|
-
snapshot: Snapshot<unknown>;
|
|
28
|
-
_transitions: AnyTransitionDefinition[];
|
|
29
|
-
}
|
|
30
|
-
export interface InspectedActionEvent extends BaseInspectionEventProperties {
|
|
31
|
-
type: '@xstate.action';
|
|
32
|
-
action: {
|
|
33
|
-
type: string;
|
|
34
|
-
params: unknown;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
export interface InspectedEventEvent extends BaseInspectionEventProperties {
|
|
38
|
-
type: '@xstate.event';
|
|
78
|
+
/** The source actor that sent the event, if any. */
|
|
39
79
|
sourceRef: ActorRefLike | undefined;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
80
|
+
/** The target actor of the transition (usually the same as `actorRef`). */
|
|
81
|
+
targetRef: ActorRefLike | undefined;
|
|
82
|
+
/** The resulting snapshot of the transition. */
|
|
83
|
+
snapshot: Snapshot<unknown>;
|
|
84
|
+
/** The microstep transition definitions taken (always present). */
|
|
85
|
+
microsteps: AnyTransitionDefinition[];
|
|
86
|
+
/** The actions executed during the transition (always present). */
|
|
87
|
+
actions: ActionRecord[];
|
|
88
|
+
/** The events relayed to other actors during the transition (always present). */
|
|
89
|
+
sent: SentRecord[];
|
|
44
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* A lossless, two-event inspection protocol:
|
|
93
|
+
*
|
|
94
|
+
* - `@xstate.actor` — actor topology (identity + parent), drawable up front.
|
|
95
|
+
* - `@xstate.transition` — every transition facet: event, snapshot, source,
|
|
96
|
+
* microsteps, executed actions, and sent/scheduled events.
|
|
97
|
+
*/
|
|
98
|
+
export type InspectionEvent = ActorInspectionEvent | TransitionInspectionEvent;
|
|
45
99
|
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MachineSnapshot } from "./State.js";
|
|
2
|
+
import { AnyMachineSnapshot, AnyStateNode, StateSchema } from "./types.js";
|
|
3
|
+
type StateSchemaFromSnapshot<TSnapshot extends AnyMachineSnapshot> = TSnapshot extends MachineSnapshot<infer _TContext, infer _TEvent, infer _TChildren, infer _TStateValue, infer _TTag, infer _TOutput, infer _TMeta, infer TStateSchema extends StateSchema> ? TStateSchema : StateSchema;
|
|
2
4
|
/**
|
|
3
5
|
* A mapper object that defines how to transform a snapshot based on its state.
|
|
4
6
|
* Can be nested to match the state hierarchy of the machine.
|
|
@@ -18,7 +20,7 @@ type StateSchemaMapper<TSnapshot extends AnyMachineSnapshot, T extends StateSche
|
|
|
18
20
|
* collects results from matching `map` functions in the mapper object. Results
|
|
19
21
|
* are ordered leaf-to-root (most specific state first).
|
|
20
22
|
*/
|
|
21
|
-
export declare function mapState<T extends AnyMachineSnapshot, TResult>(snapshot: T, mapper: StateSchemaMapper<T,
|
|
23
|
+
export declare function mapState<T extends AnyMachineSnapshot, TResult>(snapshot: T, mapper: StateSchemaMapper<T, StateSchemaFromSnapshot<T>, TResult>): {
|
|
22
24
|
stateNode: AnyStateNode;
|
|
23
25
|
result: TResult;
|
|
24
26
|
}[];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** The Standard Schema interface. */
|
|
2
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
3
|
+
/** The Standard Schema properties. */
|
|
4
|
+
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
5
|
+
}
|
|
6
|
+
/** A type-only Standard Schema produced by {@link types}. */
|
|
7
|
+
export interface TypeSchema<T> extends StandardSchemaV1<T, T> {
|
|
8
|
+
readonly '~standard': StandardSchemaV1.Props<T, T> & {
|
|
9
|
+
readonly vendor: 'xstate.types';
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Declares schema types for inference only — no runtime validation.
|
|
14
|
+
*
|
|
15
|
+
* Use in a machine's `schemas` when you want TypeScript types without pulling
|
|
16
|
+
* in a schema library like Zod. The returned value is a valid Standard Schema
|
|
17
|
+
* whose validation is the identity function, so it carries types but never
|
|
18
|
+
* rejects input.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { createMachine, types } from 'xstate';
|
|
24
|
+
*
|
|
25
|
+
* const machine = createMachine({
|
|
26
|
+
* schemas: {
|
|
27
|
+
* context: types<{ count: number }>(),
|
|
28
|
+
* events: {
|
|
29
|
+
* inc: types<{ by: number }>(),
|
|
30
|
+
* reset: types<{}>()
|
|
31
|
+
* }
|
|
32
|
+
* },
|
|
33
|
+
* context: { count: 0 }
|
|
34
|
+
* // ...
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function types<T>(): TypeSchema<T>;
|
|
39
|
+
/** Returns true if the value is a type-only schema created by {@link types}. */
|
|
40
|
+
export declare function isTypeSchema(value: unknown): value is TypeSchema<unknown>;
|
|
41
|
+
export declare namespace StandardSchemaV1 {
|
|
42
|
+
/** The Standard Schema properties interface. */
|
|
43
|
+
interface Props<Input = unknown, Output = Input> {
|
|
44
|
+
/** The version number of the standard. */
|
|
45
|
+
readonly version: 1;
|
|
46
|
+
/** The vendor name of the schema library. */
|
|
47
|
+
readonly vendor: string;
|
|
48
|
+
/** Validates unknown input values. */
|
|
49
|
+
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
|
|
50
|
+
/** Inferred types associated with the schema. */
|
|
51
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
52
|
+
}
|
|
53
|
+
/** The result interface of the validate function. */
|
|
54
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
55
|
+
/** The result interface if validation succeeds. */
|
|
56
|
+
interface SuccessResult<Output> {
|
|
57
|
+
/** The typed output value. */
|
|
58
|
+
readonly value: Output;
|
|
59
|
+
/** The non-existent issues. */
|
|
60
|
+
readonly issues?: undefined;
|
|
61
|
+
}
|
|
62
|
+
/** The result interface if validation fails. */
|
|
63
|
+
interface FailureResult {
|
|
64
|
+
/** The issues of failed validation. */
|
|
65
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
66
|
+
}
|
|
67
|
+
/** The issue interface of the failure output. */
|
|
68
|
+
interface Issue {
|
|
69
|
+
/** The error message of the issue. */
|
|
70
|
+
readonly message: string;
|
|
71
|
+
/** The path of the issue, if any. */
|
|
72
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
73
|
+
}
|
|
74
|
+
/** The path segment interface of the issue. */
|
|
75
|
+
interface PathSegment {
|
|
76
|
+
/** The key representing a path segment. */
|
|
77
|
+
readonly key: PropertyKey;
|
|
78
|
+
}
|
|
79
|
+
/** The Standard Schema types interface. */
|
|
80
|
+
interface Types<Input = unknown, Output = Input> {
|
|
81
|
+
/** The input type of the schema. */
|
|
82
|
+
readonly input: Input;
|
|
83
|
+
/** The output type of the schema. */
|
|
84
|
+
readonly output: Output;
|
|
85
|
+
}
|
|
86
|
+
/** Infers the input type of a Standard Schema. */
|
|
87
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
88
|
+
/** Infers the output type of a Standard Schema. */
|
|
89
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
90
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Machine-definition serialization.
|
|
3
|
+
*
|
|
4
|
+
* `machineConfigToJSON` converts a machine config into a JSON-safe structure
|
|
5
|
+
* (the `MachineJSON` shape accepted by `createMachineFromConfig`). The boundary
|
|
6
|
+
* between serializable structure and runtime implementations is explicit: any
|
|
7
|
+
* value that cannot be represented as data (inline functions, actor logic,
|
|
8
|
+
* runtime schemas) is replaced with an `{ "$unserializable": <kind> }` marker
|
|
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).
|
|
15
|
+
*/
|
|
16
|
+
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
|
+
/**
|
|
23
|
+
* Returns the JSON-serializable definition of a machine.
|
|
24
|
+
*
|
|
25
|
+
* Inline functions, actor logic, and runtime schemas cannot be represented as
|
|
26
|
+
* data; they appear as `{ "$unserializable": ... }` markers. A machine created
|
|
27
|
+
* via `createMachineFromConfig` returns its original JSON config (lossless
|
|
28
|
+
* round-trip):
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { serializeMachine, createMachineFromConfig } from 'xstate';
|
|
32
|
+
*
|
|
33
|
+
* const json = serializeMachine(machine);
|
|
34
|
+
* const revived = createMachineFromConfig(
|
|
35
|
+
* JSON.parse(JSON.stringify(json))
|
|
36
|
+
* );
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function serializeMachine(machine: AnyStateMachine): Record<string, unknown>;
|
|
40
|
+
/**
|
|
41
|
+
* Converts a machine config (as passed to `createMachine`) to its JSON-safe
|
|
42
|
+
* definition. See module docs for the `$unserializable` marker contract.
|
|
43
|
+
*/
|
|
44
|
+
export declare function machineConfigToJSON(config: Record<string, unknown>): Record<string, unknown>;
|