xstate 5.19.4 → 5.20.0
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 +0 -1
- package/actions/dist/xstate-actions.cjs.d.ts +1 -1
- package/actions/dist/xstate-actions.cjs.js +8 -7
- package/actions/dist/xstate-actions.development.cjs.js +8 -7
- package/actions/dist/xstate-actions.development.esm.js +3 -2
- package/actions/dist/xstate-actions.esm.js +3 -2
- package/actions/dist/xstate-actions.umd.min.js +1 -1
- package/actions/dist/xstate-actions.umd.min.js.map +1 -1
- package/actors/dist/xstate-actors.cjs.d.ts +1 -1
- package/actors/dist/xstate-actors.development.esm.js +1 -1
- package/actors/dist/xstate-actors.esm.js +1 -1
- package/actors/dist/xstate-actors.umd.min.js.map +1 -1
- package/dev/dist/xstate-dev.cjs.d.ts +1 -1
- package/dev/dist/xstate-dev.umd.min.js.map +1 -1
- package/dist/StateMachine-1cda96d3.cjs.js +560 -0
- package/dist/StateMachine-38b5bb3f.development.cjs.js +566 -0
- package/dist/StateMachine-b4e94439.development.esm.js +563 -0
- package/dist/StateMachine-c88ea5dd.esm.js +557 -0
- package/dist/assign-6313ccb3.development.esm.js +133 -0
- package/dist/assign-c3259787.esm.js +127 -0
- package/dist/assign-c84786ab.development.cjs.js +135 -0
- package/dist/assign-e9c344ea.cjs.js +129 -0
- package/dist/declarations/src/StateMachine.d.ts +2 -2
- package/dist/declarations/src/graph/TestModel.d.ts +71 -0
- package/dist/declarations/src/graph/adjacency.d.ts +8 -0
- package/dist/declarations/src/graph/graph.d.ts +14 -0
- package/dist/declarations/src/graph/index.d.ts +9 -0
- package/dist/declarations/src/graph/pathFromEvents.d.ts +3 -0
- package/dist/declarations/src/graph/pathGenerators.d.ts +4 -0
- package/dist/declarations/src/graph/shortestPaths.d.ts +3 -0
- package/dist/declarations/src/graph/simplePaths.d.ts +3 -0
- package/dist/declarations/src/graph/types.d.ts +159 -0
- package/dist/{log-655aa404.esm.js → log-1c257a58.esm.js} +3 -126
- package/dist/{log-fa2e731a.cjs.js → log-215998b6.cjs.js} +2 -126
- package/dist/{log-fadc8808.development.cjs.js → log-2c8d7f98.development.cjs.js} +2 -132
- package/dist/{log-5a7b5528.development.esm.js → log-ef959da6.development.esm.js} +3 -132
- package/dist/{raise-59549771.development.esm.js → raise-78b8dcb8.development.esm.js} +1 -1
- package/dist/{raise-3e01e82a.esm.js → raise-b0a4e862.esm.js} +1 -1
- package/dist/xstate.cjs.d.ts +1 -1
- package/dist/xstate.cjs.js +7 -558
- package/dist/xstate.development.cjs.js +7 -564
- package/dist/xstate.development.esm.js +7 -564
- package/dist/xstate.esm.js +7 -558
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/graph/dist/xstate-graph.cjs.d.mts +2 -0
- package/graph/dist/xstate-graph.cjs.d.ts +2 -0
- package/graph/dist/xstate-graph.cjs.js +901 -0
- package/graph/dist/xstate-graph.cjs.mjs +15 -0
- package/graph/dist/xstate-graph.development.cjs.js +901 -0
- package/graph/dist/xstate-graph.development.cjs.mjs +15 -0
- package/graph/dist/xstate-graph.development.esm.js +885 -0
- package/graph/dist/xstate-graph.esm.js +885 -0
- package/graph/dist/xstate-graph.umd.min.js +2 -0
- package/graph/dist/xstate-graph.umd.min.js.map +1 -0
- package/graph/package.json +8 -0
- package/guards/dist/xstate-guards.cjs.d.ts +1 -1
- package/guards/dist/xstate-guards.development.esm.js +1 -1
- package/guards/dist/xstate-guards.esm.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js +1 -1
- package/guards/dist/xstate-guards.umd.min.js.map +1 -1
- package/package.json +22 -6
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { V as ProcessingStatus, R as resolveReferencedActor, c as createActor, W as cloneMachineSnapshot } from './raise-b0a4e862.esm.js';
|
|
2
|
+
|
|
3
|
+
function createSpawner(actorScope, {
|
|
4
|
+
machine,
|
|
5
|
+
context
|
|
6
|
+
}, event, spawnedChildren) {
|
|
7
|
+
const spawn = (src, options) => {
|
|
8
|
+
if (typeof src === 'string') {
|
|
9
|
+
const logic = resolveReferencedActor(machine, src);
|
|
10
|
+
if (!logic) {
|
|
11
|
+
throw new Error(`Actor logic '${src}' not implemented in machine '${machine.id}'`);
|
|
12
|
+
}
|
|
13
|
+
const actorRef = createActor(logic, {
|
|
14
|
+
id: options?.id,
|
|
15
|
+
parent: actorScope.self,
|
|
16
|
+
syncSnapshot: options?.syncSnapshot,
|
|
17
|
+
input: typeof options?.input === 'function' ? options.input({
|
|
18
|
+
context,
|
|
19
|
+
event,
|
|
20
|
+
self: actorScope.self
|
|
21
|
+
}) : options?.input,
|
|
22
|
+
src,
|
|
23
|
+
systemId: options?.systemId
|
|
24
|
+
});
|
|
25
|
+
spawnedChildren[actorRef.id] = actorRef;
|
|
26
|
+
return actorRef;
|
|
27
|
+
} else {
|
|
28
|
+
const actorRef = createActor(src, {
|
|
29
|
+
id: options?.id,
|
|
30
|
+
parent: actorScope.self,
|
|
31
|
+
syncSnapshot: options?.syncSnapshot,
|
|
32
|
+
input: options?.input,
|
|
33
|
+
src,
|
|
34
|
+
systemId: options?.systemId
|
|
35
|
+
});
|
|
36
|
+
return actorRef;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
return (src, options) => {
|
|
40
|
+
const actorRef = spawn(src, options); // TODO: fix types
|
|
41
|
+
spawnedChildren[actorRef.id] = actorRef;
|
|
42
|
+
actorScope.defer(() => {
|
|
43
|
+
if (actorRef._processingStatus === ProcessingStatus.Stopped) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
actorRef.start();
|
|
47
|
+
});
|
|
48
|
+
return actorRef;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
53
|
+
assignment
|
|
54
|
+
}) {
|
|
55
|
+
if (!snapshot.context) {
|
|
56
|
+
throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
|
|
57
|
+
}
|
|
58
|
+
const spawnedChildren = {};
|
|
59
|
+
const assignArgs = {
|
|
60
|
+
context: snapshot.context,
|
|
61
|
+
event: actionArgs.event,
|
|
62
|
+
spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
|
|
63
|
+
self: actorScope.self,
|
|
64
|
+
system: actorScope.system
|
|
65
|
+
};
|
|
66
|
+
let partialUpdate = {};
|
|
67
|
+
if (typeof assignment === 'function') {
|
|
68
|
+
partialUpdate = assignment(assignArgs, actionParams);
|
|
69
|
+
} else {
|
|
70
|
+
for (const key of Object.keys(assignment)) {
|
|
71
|
+
const propAssignment = assignment[key];
|
|
72
|
+
partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const updatedContext = Object.assign({}, snapshot.context, partialUpdate);
|
|
76
|
+
return [cloneMachineSnapshot(snapshot, {
|
|
77
|
+
context: updatedContext,
|
|
78
|
+
children: Object.keys(spawnedChildren).length ? {
|
|
79
|
+
...snapshot.children,
|
|
80
|
+
...spawnedChildren
|
|
81
|
+
} : snapshot.children
|
|
82
|
+
}), undefined, undefined];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Updates the current context of the machine.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
*
|
|
89
|
+
* ```ts
|
|
90
|
+
* import { createMachine, assign } from 'xstate';
|
|
91
|
+
*
|
|
92
|
+
* const countMachine = createMachine({
|
|
93
|
+
* context: {
|
|
94
|
+
* count: 0,
|
|
95
|
+
* message: ''
|
|
96
|
+
* },
|
|
97
|
+
* on: {
|
|
98
|
+
* inc: {
|
|
99
|
+
* actions: assign({
|
|
100
|
+
* count: ({ context }) => context.count + 1
|
|
101
|
+
* })
|
|
102
|
+
* },
|
|
103
|
+
* updateMessage: {
|
|
104
|
+
* actions: assign(({ context, event }) => {
|
|
105
|
+
* return {
|
|
106
|
+
* message: event.message.trim()
|
|
107
|
+
* };
|
|
108
|
+
* })
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @param assignment An object that represents the partial context to update, or
|
|
115
|
+
* a function that returns an object that represents the partial context to
|
|
116
|
+
* update.
|
|
117
|
+
*/
|
|
118
|
+
function assign(assignment) {
|
|
119
|
+
function assign(_args, _params) {
|
|
120
|
+
}
|
|
121
|
+
assign.type = 'xstate.assign';
|
|
122
|
+
assign.assignment = assignment;
|
|
123
|
+
assign.resolve = resolveAssign;
|
|
124
|
+
return assign;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export { assign as a };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-7a84f9f0.development.cjs.js');
|
|
4
|
+
|
|
5
|
+
function createSpawner(actorScope, {
|
|
6
|
+
machine,
|
|
7
|
+
context
|
|
8
|
+
}, event, spawnedChildren) {
|
|
9
|
+
const spawn = (src, options) => {
|
|
10
|
+
if (typeof src === 'string') {
|
|
11
|
+
const logic = guards_dist_xstateGuards.resolveReferencedActor(machine, src);
|
|
12
|
+
if (!logic) {
|
|
13
|
+
throw new Error(`Actor logic '${src}' not implemented in machine '${machine.id}'`);
|
|
14
|
+
}
|
|
15
|
+
const actorRef = guards_dist_xstateGuards.createActor(logic, {
|
|
16
|
+
id: options?.id,
|
|
17
|
+
parent: actorScope.self,
|
|
18
|
+
syncSnapshot: options?.syncSnapshot,
|
|
19
|
+
input: typeof options?.input === 'function' ? options.input({
|
|
20
|
+
context,
|
|
21
|
+
event,
|
|
22
|
+
self: actorScope.self
|
|
23
|
+
}) : options?.input,
|
|
24
|
+
src,
|
|
25
|
+
systemId: options?.systemId
|
|
26
|
+
});
|
|
27
|
+
spawnedChildren[actorRef.id] = actorRef;
|
|
28
|
+
return actorRef;
|
|
29
|
+
} else {
|
|
30
|
+
const actorRef = guards_dist_xstateGuards.createActor(src, {
|
|
31
|
+
id: options?.id,
|
|
32
|
+
parent: actorScope.self,
|
|
33
|
+
syncSnapshot: options?.syncSnapshot,
|
|
34
|
+
input: options?.input,
|
|
35
|
+
src,
|
|
36
|
+
systemId: options?.systemId
|
|
37
|
+
});
|
|
38
|
+
return actorRef;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return (src, options) => {
|
|
42
|
+
const actorRef = spawn(src, options); // TODO: fix types
|
|
43
|
+
spawnedChildren[actorRef.id] = actorRef;
|
|
44
|
+
actorScope.defer(() => {
|
|
45
|
+
if (actorRef._processingStatus === guards_dist_xstateGuards.ProcessingStatus.Stopped) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
actorRef.start();
|
|
49
|
+
});
|
|
50
|
+
return actorRef;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
55
|
+
assignment
|
|
56
|
+
}) {
|
|
57
|
+
if (!snapshot.context) {
|
|
58
|
+
throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
|
|
59
|
+
}
|
|
60
|
+
const spawnedChildren = {};
|
|
61
|
+
const assignArgs = {
|
|
62
|
+
context: snapshot.context,
|
|
63
|
+
event: actionArgs.event,
|
|
64
|
+
spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
|
|
65
|
+
self: actorScope.self,
|
|
66
|
+
system: actorScope.system
|
|
67
|
+
};
|
|
68
|
+
let partialUpdate = {};
|
|
69
|
+
if (typeof assignment === 'function') {
|
|
70
|
+
partialUpdate = assignment(assignArgs, actionParams);
|
|
71
|
+
} else {
|
|
72
|
+
for (const key of Object.keys(assignment)) {
|
|
73
|
+
const propAssignment = assignment[key];
|
|
74
|
+
partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const updatedContext = Object.assign({}, snapshot.context, partialUpdate);
|
|
78
|
+
return [guards_dist_xstateGuards.cloneMachineSnapshot(snapshot, {
|
|
79
|
+
context: updatedContext,
|
|
80
|
+
children: Object.keys(spawnedChildren).length ? {
|
|
81
|
+
...snapshot.children,
|
|
82
|
+
...spawnedChildren
|
|
83
|
+
} : snapshot.children
|
|
84
|
+
}), undefined, undefined];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Updates the current context of the machine.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { createMachine, assign } from 'xstate';
|
|
93
|
+
*
|
|
94
|
+
* const countMachine = createMachine({
|
|
95
|
+
* context: {
|
|
96
|
+
* count: 0,
|
|
97
|
+
* message: ''
|
|
98
|
+
* },
|
|
99
|
+
* on: {
|
|
100
|
+
* inc: {
|
|
101
|
+
* actions: assign({
|
|
102
|
+
* count: ({ context }) => context.count + 1
|
|
103
|
+
* })
|
|
104
|
+
* },
|
|
105
|
+
* updateMessage: {
|
|
106
|
+
* actions: assign(({ context, event }) => {
|
|
107
|
+
* return {
|
|
108
|
+
* message: event.message.trim()
|
|
109
|
+
* };
|
|
110
|
+
* })
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @param assignment An object that represents the partial context to update, or
|
|
117
|
+
* a function that returns an object that represents the partial context to
|
|
118
|
+
* update.
|
|
119
|
+
*/
|
|
120
|
+
function assign(assignment) {
|
|
121
|
+
if (guards_dist_xstateGuards.executingCustomAction) {
|
|
122
|
+
console.warn('Custom actions should not call `assign()` directly, as it is not imperative. See https://stately.ai/docs/actions#built-in-actions for more details.');
|
|
123
|
+
}
|
|
124
|
+
function assign(_args, _params) {
|
|
125
|
+
{
|
|
126
|
+
throw new Error(`This isn't supposed to be called`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
assign.type = 'xstate.assign';
|
|
130
|
+
assign.assignment = assignment;
|
|
131
|
+
assign.resolve = resolveAssign;
|
|
132
|
+
return assign;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
exports.assign = assign;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var guards_dist_xstateGuards = require('./raise-5872b9e8.cjs.js');
|
|
4
|
+
|
|
5
|
+
function createSpawner(actorScope, {
|
|
6
|
+
machine,
|
|
7
|
+
context
|
|
8
|
+
}, event, spawnedChildren) {
|
|
9
|
+
const spawn = (src, options) => {
|
|
10
|
+
if (typeof src === 'string') {
|
|
11
|
+
const logic = guards_dist_xstateGuards.resolveReferencedActor(machine, src);
|
|
12
|
+
if (!logic) {
|
|
13
|
+
throw new Error(`Actor logic '${src}' not implemented in machine '${machine.id}'`);
|
|
14
|
+
}
|
|
15
|
+
const actorRef = guards_dist_xstateGuards.createActor(logic, {
|
|
16
|
+
id: options?.id,
|
|
17
|
+
parent: actorScope.self,
|
|
18
|
+
syncSnapshot: options?.syncSnapshot,
|
|
19
|
+
input: typeof options?.input === 'function' ? options.input({
|
|
20
|
+
context,
|
|
21
|
+
event,
|
|
22
|
+
self: actorScope.self
|
|
23
|
+
}) : options?.input,
|
|
24
|
+
src,
|
|
25
|
+
systemId: options?.systemId
|
|
26
|
+
});
|
|
27
|
+
spawnedChildren[actorRef.id] = actorRef;
|
|
28
|
+
return actorRef;
|
|
29
|
+
} else {
|
|
30
|
+
const actorRef = guards_dist_xstateGuards.createActor(src, {
|
|
31
|
+
id: options?.id,
|
|
32
|
+
parent: actorScope.self,
|
|
33
|
+
syncSnapshot: options?.syncSnapshot,
|
|
34
|
+
input: options?.input,
|
|
35
|
+
src,
|
|
36
|
+
systemId: options?.systemId
|
|
37
|
+
});
|
|
38
|
+
return actorRef;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return (src, options) => {
|
|
42
|
+
const actorRef = spawn(src, options); // TODO: fix types
|
|
43
|
+
spawnedChildren[actorRef.id] = actorRef;
|
|
44
|
+
actorScope.defer(() => {
|
|
45
|
+
if (actorRef._processingStatus === guards_dist_xstateGuards.ProcessingStatus.Stopped) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
actorRef.start();
|
|
49
|
+
});
|
|
50
|
+
return actorRef;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function resolveAssign(actorScope, snapshot, actionArgs, actionParams, {
|
|
55
|
+
assignment
|
|
56
|
+
}) {
|
|
57
|
+
if (!snapshot.context) {
|
|
58
|
+
throw new Error('Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.');
|
|
59
|
+
}
|
|
60
|
+
const spawnedChildren = {};
|
|
61
|
+
const assignArgs = {
|
|
62
|
+
context: snapshot.context,
|
|
63
|
+
event: actionArgs.event,
|
|
64
|
+
spawn: createSpawner(actorScope, snapshot, actionArgs.event, spawnedChildren),
|
|
65
|
+
self: actorScope.self,
|
|
66
|
+
system: actorScope.system
|
|
67
|
+
};
|
|
68
|
+
let partialUpdate = {};
|
|
69
|
+
if (typeof assignment === 'function') {
|
|
70
|
+
partialUpdate = assignment(assignArgs, actionParams);
|
|
71
|
+
} else {
|
|
72
|
+
for (const key of Object.keys(assignment)) {
|
|
73
|
+
const propAssignment = assignment[key];
|
|
74
|
+
partialUpdate[key] = typeof propAssignment === 'function' ? propAssignment(assignArgs, actionParams) : propAssignment;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const updatedContext = Object.assign({}, snapshot.context, partialUpdate);
|
|
78
|
+
return [guards_dist_xstateGuards.cloneMachineSnapshot(snapshot, {
|
|
79
|
+
context: updatedContext,
|
|
80
|
+
children: Object.keys(spawnedChildren).length ? {
|
|
81
|
+
...snapshot.children,
|
|
82
|
+
...spawnedChildren
|
|
83
|
+
} : snapshot.children
|
|
84
|
+
}), undefined, undefined];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Updates the current context of the machine.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { createMachine, assign } from 'xstate';
|
|
93
|
+
*
|
|
94
|
+
* const countMachine = createMachine({
|
|
95
|
+
* context: {
|
|
96
|
+
* count: 0,
|
|
97
|
+
* message: ''
|
|
98
|
+
* },
|
|
99
|
+
* on: {
|
|
100
|
+
* inc: {
|
|
101
|
+
* actions: assign({
|
|
102
|
+
* count: ({ context }) => context.count + 1
|
|
103
|
+
* })
|
|
104
|
+
* },
|
|
105
|
+
* updateMessage: {
|
|
106
|
+
* actions: assign(({ context, event }) => {
|
|
107
|
+
* return {
|
|
108
|
+
* message: event.message.trim()
|
|
109
|
+
* };
|
|
110
|
+
* })
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @param assignment An object that represents the partial context to update, or
|
|
117
|
+
* a function that returns an object that represents the partial context to
|
|
118
|
+
* update.
|
|
119
|
+
*/
|
|
120
|
+
function assign(assignment) {
|
|
121
|
+
function assign(_args, _params) {
|
|
122
|
+
}
|
|
123
|
+
assign.type = 'xstate.assign';
|
|
124
|
+
assign.assignment = assignment;
|
|
125
|
+
assign.resolve = resolveAssign;
|
|
126
|
+
return assign;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
exports.assign = assign;
|
|
@@ -25,8 +25,8 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
25
25
|
/**
|
|
26
26
|
* Clones this state machine with the provided implementations.
|
|
27
27
|
*
|
|
28
|
-
* @param implementations Options (`actions`, `guards`, `actors`, `delays`)
|
|
29
|
-
*
|
|
28
|
+
* @param implementations Options (`actions`, `guards`, `actors`, `delays`) to
|
|
29
|
+
* recursively merge with the existing options.
|
|
30
30
|
* @returns A new `StateMachine` instance with the provided implementations.
|
|
31
31
|
*/
|
|
32
32
|
provide(implementations: InternalMachineImplementations<ResolvedStateMachineTypes<TContext, DoNotInfer<TEvent>, TActor, TAction, TGuard, TDelay, TTag, TEmitted>>): StateMachine<TContext, TEvent, TChildren, TActor, TAction, TGuard, TDelay, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta, TConfig>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { AdjacencyMap, StatePath, Step, TraversalOptions } from "./types.js";
|
|
2
|
+
import { EventObject, ActorLogic, Snapshot, AnyStateMachine, EventFromLogic, SnapshotFrom, InputFrom } from "../index.js";
|
|
3
|
+
import type { PathGenerator, TestModelOptions, TestParam, TestPath, TestPathResult } from "./types.js";
|
|
4
|
+
type GetPathOptions<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput> = Partial<TraversalOptions<TSnapshot, TEvent, TInput>> & {
|
|
5
|
+
/**
|
|
6
|
+
* Whether to allow deduplicate paths so that paths that are contained by
|
|
7
|
+
* longer paths are included.
|
|
8
|
+
*
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
allowDuplicatePaths?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates a test model that represents an abstract model of a system under test
|
|
15
|
+
* (SUT).
|
|
16
|
+
*
|
|
17
|
+
* The test model is used to generate test paths, which are used to verify that
|
|
18
|
+
* states in the model are reachable in the SUT.
|
|
19
|
+
*/
|
|
20
|
+
export declare class TestModel<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput> {
|
|
21
|
+
testLogic: ActorLogic<TSnapshot, TEvent, TInput>;
|
|
22
|
+
options: TestModelOptions<TSnapshot, TEvent, TInput>;
|
|
23
|
+
defaultTraversalOptions?: TraversalOptions<TSnapshot, TEvent, TInput>;
|
|
24
|
+
getDefaultOptions(): TestModelOptions<TSnapshot, TEvent, TInput>;
|
|
25
|
+
constructor(testLogic: ActorLogic<TSnapshot, TEvent, TInput>, options?: Partial<TestModelOptions<TSnapshot, TEvent, TInput>>);
|
|
26
|
+
getPaths(pathGenerator: PathGenerator<TSnapshot, TEvent, TInput>, options?: GetPathOptions<TSnapshot, TEvent, TInput>): Array<TestPath<TSnapshot, TEvent>>;
|
|
27
|
+
getShortestPaths(options?: GetPathOptions<TSnapshot, TEvent, TInput>): Array<TestPath<TSnapshot, TEvent>>;
|
|
28
|
+
getShortestPathsFrom(paths: Array<TestPath<TSnapshot, TEvent>>, options?: GetPathOptions<TSnapshot, TEvent, TInput>): Array<TestPath<TSnapshot, TEvent>>;
|
|
29
|
+
getSimplePaths(options?: GetPathOptions<TSnapshot, TEvent, TInput>): Array<TestPath<TSnapshot, TEvent>>;
|
|
30
|
+
getSimplePathsFrom(paths: Array<TestPath<TSnapshot, TEvent>>, options?: GetPathOptions<TSnapshot, TEvent, TInput>): Array<TestPath<TSnapshot, TEvent>>;
|
|
31
|
+
private _toTestPath;
|
|
32
|
+
getPathsFromEvents(events: TEvent[], options?: GetPathOptions<TSnapshot, TEvent, TInput>): Array<TestPath<TSnapshot, TEvent>>;
|
|
33
|
+
/**
|
|
34
|
+
* An array of adjacencies, which are objects that represent each `state` with
|
|
35
|
+
* the `nextState` given the `event`.
|
|
36
|
+
*/
|
|
37
|
+
getAdjacencyMap(): AdjacencyMap<TSnapshot, TEvent>;
|
|
38
|
+
testPath(path: StatePath<TSnapshot, TEvent>, params: TestParam<TSnapshot, TEvent>, options?: Partial<TestModelOptions<TSnapshot, TEvent, TInput>>): Promise<TestPathResult>;
|
|
39
|
+
testState(params: TestParam<TSnapshot, TEvent>, state: TSnapshot, options?: Partial<TestModelOptions<TSnapshot, TEvent, TInput>>): Promise<void>;
|
|
40
|
+
private _getStateTestKeys;
|
|
41
|
+
private _getEventExec;
|
|
42
|
+
testTransition(params: TestParam<TSnapshot, TEvent>, step: Step<TSnapshot, TEvent>): Promise<void>;
|
|
43
|
+
private _resolveOptions;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates a test model that represents an abstract model of a system under test
|
|
47
|
+
* (SUT).
|
|
48
|
+
*
|
|
49
|
+
* The test model is used to generate test paths, which are used to verify that
|
|
50
|
+
* states in the `machine` are reachable in the SUT.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
*
|
|
54
|
+
* ```js
|
|
55
|
+
* const toggleModel = createModel(toggleMachine).withEvents({
|
|
56
|
+
* TOGGLE: {
|
|
57
|
+
* exec: async (page) => {
|
|
58
|
+
* await page.click('input');
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @param machine The state machine used to represent the abstract model.
|
|
65
|
+
* @param options Options for the created test model:
|
|
66
|
+
*
|
|
67
|
+
* - `events`: an object mapping string event types (e.g., `SUBMIT`) to an event
|
|
68
|
+
* test config (e.g., `{exec: () => {...}, cases: [...]}`)
|
|
69
|
+
*/
|
|
70
|
+
export declare function createTestModel<TMachine extends AnyStateMachine>(machine: TMachine, options?: Partial<TestModelOptions<SnapshotFrom<TMachine>, EventFromLogic<TMachine>, InputFrom<TMachine>>>): TestModel<SnapshotFrom<TMachine>, EventFromLogic<TMachine>, unknown>;
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ActorLogic, ActorSystem, EventObject, Snapshot } from "../index.js";
|
|
2
|
+
import { TraversalOptions, AdjacencyMap } from "./types.js";
|
|
3
|
+
export declare function getAdjacencyMap<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput, TSystem extends ActorSystem<any> = ActorSystem<any>>(logic: ActorLogic<TSnapshot, TEvent, TInput, TSystem>, options: TraversalOptions<TSnapshot, TEvent, TInput>): AdjacencyMap<TSnapshot, TEvent>;
|
|
4
|
+
export declare function adjacencyMapToArray<TSnapshot, TEvent>(adjMap: AdjacencyMap<TSnapshot, TEvent>): Array<{
|
|
5
|
+
state: TSnapshot;
|
|
6
|
+
event: TEvent;
|
|
7
|
+
nextState: TSnapshot;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EventObject, AnyStateMachine, AnyActorLogic, EventFromLogic, Snapshot, InputFrom } from "../index.js";
|
|
2
|
+
import type { SerializedSnapshot, StatePath, DirectedGraphNode, TraversalOptions, AnyStateNode, TraversalConfig } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns all state nodes of the given `node`.
|
|
5
|
+
*
|
|
6
|
+
* @param stateNode State node to recursively get child state nodes from
|
|
7
|
+
*/
|
|
8
|
+
export declare function getStateNodes(stateNode: AnyStateNode | AnyStateMachine): AnyStateNode[];
|
|
9
|
+
export declare function serializeSnapshot(snapshot: Snapshot<any>): SerializedSnapshot;
|
|
10
|
+
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
|
+
export declare function createDefaultLogicOptions(): TraversalOptions<any, any, any>;
|
|
12
|
+
export declare function toDirectedGraph(stateMachine: AnyStateNode | AnyStateMachine): DirectedGraphNode;
|
|
13
|
+
export declare function resolveTraversalOptions<TLogic extends AnyActorLogic>(logic: TLogic, traversalOptions?: TraversalOptions<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>, InputFrom<TLogic>>, defaultOptions?: TraversalOptions<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>, InputFrom<TLogic>>): TraversalConfig<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>>;
|
|
14
|
+
export declare function joinPaths<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject>(headPath: StatePath<TSnapshot, TEvent>, tailPath: StatePath<TSnapshot, TEvent>): StatePath<TSnapshot, TEvent>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { TestModel, createTestModel } from "./TestModel.js";
|
|
2
|
+
export { adjacencyMapToArray, getAdjacencyMap } from "./adjacency.js";
|
|
3
|
+
export { getStateNodes, joinPaths, serializeSnapshot, toDirectedGraph } from "./graph.js";
|
|
4
|
+
export type { AdjacencyMap, AdjacencyValue } from "./types.js";
|
|
5
|
+
export { getPathsFromEvents } from "./pathFromEvents.js";
|
|
6
|
+
export * from "./pathGenerators.js";
|
|
7
|
+
export { getShortestPaths } from "./shortestPaths.js";
|
|
8
|
+
export { getSimplePaths } from "./simplePaths.js";
|
|
9
|
+
export * from "./types.js";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ActorLogic, ActorSystem, EventObject, Snapshot } from "../index.js";
|
|
2
|
+
import { StatePath, TraversalOptions } from "./types.js";
|
|
3
|
+
export declare function getPathsFromEvents<TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput, TSystem extends ActorSystem<any> = ActorSystem<any>>(logic: ActorLogic<TSnapshot, TEvent, TInput, TSystem>, events: TEvent[], options?: TraversalOptions<TSnapshot, TEvent, TInput>): Array<StatePath<TSnapshot, TEvent>>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { EventObject, Snapshot } from "../index.js";
|
|
2
|
+
import { PathGenerator } from "./types.js";
|
|
3
|
+
export declare const createShortestPathsGen: <TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput>() => PathGenerator<TSnapshot, TEvent, TInput>;
|
|
4
|
+
export declare const createSimplePathsGen: <TSnapshot extends Snapshot<unknown>, TEvent extends EventObject, TInput>() => PathGenerator<TSnapshot, TEvent, TInput>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AnyActorLogic, EventFromLogic, InputFrom } from "../index.js";
|
|
2
|
+
import { StatePath, TraversalOptions } from "./types.js";
|
|
3
|
+
export declare function getShortestPaths<TLogic extends AnyActorLogic>(logic: TLogic, options?: TraversalOptions<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>, InputFrom<TLogic>>): Array<StatePath<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>>>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AnyActorLogic, EventFromLogic, InputFrom } from "../index.js";
|
|
2
|
+
import { StatePath, TraversalOptions } from "./types.js";
|
|
3
|
+
export declare function getSimplePaths<TLogic extends AnyActorLogic>(logic: TLogic, options?: TraversalOptions<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>, InputFrom<TLogic>>): Array<StatePath<ReturnType<TLogic['transition']>, EventFromLogic<TLogic>>>;
|