xstate 4.32.1 → 5.0.0-alpha.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/CHANGELOG.md +483 -0
- package/actions/ExecutableAction.ts +58 -0
- package/actions/dist/xstate-actions.cjs.d.ts +1 -0
- package/actions/dist/xstate-actions.cjs.dev.js +32 -0
- package/actions/dist/xstate-actions.cjs.js +7 -0
- package/actions/dist/xstate-actions.cjs.prod.js +32 -0
- package/actions/dist/xstate-actions.esm.js +2 -0
- package/actions/dynamicAction.ts +34 -0
- package/actions/package.json +4 -0
- package/actors/dist/xstate-actors.cjs.d.ts +1 -0
- package/actors/dist/xstate-actors.cjs.dev.js +21 -0
- package/actors/dist/xstate-actors.cjs.js +7 -0
- package/actors/dist/xstate-actors.cjs.prod.js +21 -0
- package/actors/dist/xstate-actors.esm.js +2 -0
- package/actors/package.json +4 -0
- package/dev/dist/xstate-dev.cjs.d.ts +1 -0
- package/dev/dist/xstate-dev.cjs.dev.js +11 -0
- package/dev/dist/xstate-dev.cjs.js +7 -0
- package/{lib/devTools.js → dev/dist/xstate-dev.cjs.prod.js} +17 -10
- package/dev/dist/xstate-dev.esm.js +1 -0
- package/dev/package.json +4 -0
- package/dist/Machine-9ce74c11.cjs.dev.js +755 -0
- package/dist/Machine-dca041dc.cjs.prod.js +749 -0
- package/dist/Machine-fb2f47f5.esm.js +751 -0
- package/dist/actions-6b86876d.cjs.dev.js +4815 -0
- package/dist/actions-70094c93.cjs.prod.js +4765 -0
- package/dist/actions-ff512f16.esm.js +4757 -0
- package/dist/declarations/actions/ExecutableAction.d.ts +23 -0
- package/dist/declarations/actions/dynamicAction.d.ts +3 -0
- package/dist/declarations/src/Machine.d.ts +4 -0
- package/dist/declarations/src/Mailbox.d.ts +12 -0
- package/dist/declarations/src/ObservableActorRef.d.ts +25 -0
- package/{lib → dist/declarations/src}/SimulatedClock.d.ts +0 -1
- package/dist/declarations/src/State.d.ts +104 -0
- package/dist/declarations/src/StateMachine.d.ts +112 -0
- package/dist/declarations/src/StateNode.d.ts +127 -0
- package/{es → dist/declarations/src}/actionTypes.d.ts +0 -3
- package/dist/declarations/src/actions/assign.d.ts +7 -0
- package/dist/declarations/src/actions/cancel.d.ts +10 -0
- package/dist/declarations/src/actions/choose.d.ts +3 -0
- package/dist/declarations/src/actions/invoke.d.ts +3 -0
- package/dist/declarations/src/actions/log.d.ts +11 -0
- package/dist/declarations/src/actions/pure.d.ts +3 -0
- package/dist/declarations/src/actions/raise.d.ts +9 -0
- package/dist/declarations/src/actions/send.d.ts +55 -0
- package/dist/declarations/src/actions/stop.d.ts +8 -0
- package/dist/declarations/src/actions.d.ts +44 -0
- package/dist/declarations/src/actors.d.ts +38 -0
- package/dist/declarations/src/constants.d.ts +5 -0
- package/{lib/devTools.d.ts → dist/declarations/src/dev/index.d.ts} +2 -2
- package/{es → dist/declarations/src}/environment.d.ts +0 -1
- package/dist/declarations/src/guards.d.ts +9 -0
- package/dist/declarations/src/index.d.ts +47 -0
- package/dist/declarations/src/interpreter.d.ts +147 -0
- package/{es → dist/declarations/src}/mapState.d.ts +0 -1
- package/dist/declarations/src/match.d.ts +5 -0
- package/dist/declarations/src/memo.d.ts +1 -0
- package/dist/declarations/src/model.d.ts +5 -0
- package/{lib → dist/declarations/src}/model.types.d.ts +6 -9
- package/dist/declarations/src/registry.d.ts +8 -0
- package/{es → dist/declarations/src}/schema.d.ts +0 -1
- package/dist/declarations/src/spawn.d.ts +2 -0
- package/dist/declarations/src/stateUtils.d.ts +85 -0
- package/{lib → dist/declarations/src}/typegenTypes.d.ts +16 -17
- package/dist/declarations/src/types.d.ts +1026 -0
- package/dist/declarations/src/utils.d.ts +56 -0
- package/{es/devTools.js → dist/index-20b364c4.esm.js} +18 -6
- package/dist/index-2a564d03.cjs.dev.js +64 -0
- package/dist/xstate.cjs.d.ts +1 -0
- package/dist/xstate.cjs.dev.js +217 -0
- package/dist/xstate.cjs.js +7 -0
- package/dist/xstate.cjs.prod.js +217 -0
- package/dist/xstate.esm.js +172 -0
- package/guards/dist/xstate-guards.cjs.d.ts +1 -0
- package/guards/dist/xstate-guards.cjs.dev.js +15 -0
- package/guards/dist/xstate-guards.cjs.js +7 -0
- package/guards/dist/xstate-guards.cjs.prod.js +15 -0
- package/guards/dist/xstate-guards.esm.js +2 -0
- package/guards/package.json +4 -0
- package/invoke/package.json +4 -0
- package/model/dist/xstate-model.cjs.d.ts +1 -0
- package/model/dist/xstate-model.cjs.dev.js +41 -0
- package/model/dist/xstate-model.cjs.js +7 -0
- package/model/dist/xstate-model.cjs.prod.js +41 -0
- package/model/dist/xstate-model.esm.js +37 -0
- package/model/package.json +4 -0
- package/package.json +21 -30
- package/dist/xstate.interpreter.js +0 -15
- package/dist/xstate.js +0 -15
- package/dist/xstate.web.js +0 -15
- package/es/Actor.d.ts +0 -25
- package/es/Actor.js +0 -99
- package/es/Machine.d.ts +0 -12
- package/es/Machine.js +0 -14
- package/es/SimulatedClock.d.ts +0 -17
- package/es/SimulatedClock.js +0 -81
- package/es/State.d.ts +0 -123
- package/es/State.js +0 -274
- package/es/StateNode.d.ts +0 -287
- package/es/StateNode.js +0 -1566
- package/es/_virtual/_tslib.js +0 -78
- package/es/actionTypes.js +0 -22
- package/es/actions.d.ts +0 -154
- package/es/actions.js +0 -520
- package/es/behaviors.d.ts +0 -37
- package/es/behaviors.js +0 -131
- package/es/constants.d.ts +0 -6
- package/es/constants.js +0 -6
- package/es/devTools.d.ts +0 -14
- package/es/each.d.ts +0 -4
- package/es/each.js +0 -13
- package/es/environment.js +0 -3
- package/es/index.d.ts +0 -22
- package/es/index.js +0 -23
- package/es/interpreter.d.ts +0 -209
- package/es/interpreter.js +0 -1402
- package/es/invoke.d.ts +0 -11
- package/es/invokeUtils.d.ts +0 -7
- package/es/invokeUtils.js +0 -40
- package/es/json.d.ts +0 -31
- package/es/json.js +0 -86
- package/es/mapState.js +0 -32
- package/es/match.d.ts +0 -9
- package/es/match.js +0 -34
- package/es/model.d.ts +0 -5
- package/es/model.js +0 -50
- package/es/model.types.d.ts +0 -56
- package/es/patterns.d.ts +0 -14
- package/es/patterns.js +0 -48
- package/es/registry.d.ts +0 -9
- package/es/registry.js +0 -19
- package/es/scheduler.d.ts +0 -17
- package/es/scheduler.js +0 -79
- package/es/schema.js +0 -6
- package/es/scxml.d.ts +0 -6
- package/es/serviceScope.d.ts +0 -4
- package/es/serviceScope.js +0 -16
- package/es/stateUtils.d.ts +0 -17
- package/es/stateUtils.js +0 -259
- package/es/typegenTypes.d.ts +0 -133
- package/es/types.d.ts +0 -1031
- package/es/types.js +0 -33
- package/es/utils.d.ts +0 -72
- package/es/utils.js +0 -626
- package/es/waitFor.d.ts +0 -32
- package/es/waitFor.js +0 -71
- package/lib/Actor.d.ts +0 -25
- package/lib/Actor.js +0 -108
- package/lib/Machine.d.ts +0 -12
- package/lib/Machine.js +0 -19
- package/lib/SimulatedClock.js +0 -85
- package/lib/State.d.ts +0 -123
- package/lib/State.js +0 -282
- package/lib/StateNode.d.ts +0 -287
- package/lib/StateNode.js +0 -1570
- package/lib/_virtual/_tslib.js +0 -85
- package/lib/actionTypes.d.ts +0 -20
- package/lib/actionTypes.js +0 -43
- package/lib/actions.d.ts +0 -154
- package/lib/actions.js +0 -552
- package/lib/behaviors.d.ts +0 -37
- package/lib/behaviors.js +0 -137
- package/lib/constants.d.ts +0 -6
- package/lib/constants.js +0 -13
- package/lib/each.d.ts +0 -4
- package/lib/each.js +0 -17
- package/lib/environment.d.ts +0 -2
- package/lib/environment.js +0 -7
- package/lib/index.d.ts +0 -22
- package/lib/index.js +0 -60
- package/lib/interpreter.d.ts +0 -209
- package/lib/interpreter.js +0 -1408
- package/lib/invoke.d.ts +0 -11
- package/lib/invoke.js +0 -20
- package/lib/invokeUtils.d.ts +0 -7
- package/lib/invokeUtils.js +0 -45
- package/lib/json.d.ts +0 -31
- package/lib/json.js +0 -94
- package/lib/mapState.d.ts +0 -4
- package/lib/mapState.js +0 -36
- package/lib/match.d.ts +0 -9
- package/lib/match.js +0 -38
- package/lib/model.d.ts +0 -5
- package/lib/model.js +0 -54
- package/lib/model.types.js +0 -2
- package/lib/patterns.d.ts +0 -14
- package/lib/patterns.js +0 -53
- package/lib/registry.d.ts +0 -9
- package/lib/registry.js +0 -23
- package/lib/scheduler.d.ts +0 -17
- package/lib/scheduler.js +0 -83
- package/lib/schema.d.ts +0 -3
- package/lib/schema.js +0 -11
- package/lib/scxml.d.ts +0 -6
- package/lib/scxml.js +0 -350
- package/lib/serviceScope.d.ts +0 -4
- package/lib/serviceScope.js +0 -21
- package/lib/stateUtils.d.ts +0 -17
- package/lib/stateUtils.js +0 -273
- package/lib/typegenTypes.js +0 -2
- package/lib/types.d.ts +0 -1031
- package/lib/types.js +0 -35
- package/lib/utils.d.ts +0 -72
- package/lib/utils.js +0 -673
- package/lib/waitFor.d.ts +0 -32
- package/lib/waitFor.js +0 -75
package/lib/scxml.js
DELETED
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
|
-
var __values = (this && this.__values) || function(o) {
|
|
39
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
-
if (m) return m.call(o);
|
|
41
|
-
if (o && typeof o.length === "number") return {
|
|
42
|
-
next: function () {
|
|
43
|
-
if (o && i >= o.length) o = void 0;
|
|
44
|
-
return { value: o && o[i++], done: !o };
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.toMachine = void 0;
|
|
51
|
-
var xml_js_1 = require("xml-js");
|
|
52
|
-
var index_1 = require("./index");
|
|
53
|
-
var utils_1 = require("./utils");
|
|
54
|
-
var actions = require("./actions");
|
|
55
|
-
function getAttribute(element, attribute) {
|
|
56
|
-
return element.attributes ? element.attributes[attribute] : undefined;
|
|
57
|
-
}
|
|
58
|
-
function indexedRecord(items, identifier) {
|
|
59
|
-
var record = {};
|
|
60
|
-
var identifierFn = (0, utils_1.isString)(identifier)
|
|
61
|
-
? function (item) { return item[identifier]; }
|
|
62
|
-
: identifier;
|
|
63
|
-
items.forEach(function (item) {
|
|
64
|
-
var key = identifierFn(item);
|
|
65
|
-
record[key] = item;
|
|
66
|
-
});
|
|
67
|
-
return record;
|
|
68
|
-
}
|
|
69
|
-
function executableContent(elements) {
|
|
70
|
-
var transition = {
|
|
71
|
-
actions: mapActions(elements)
|
|
72
|
-
};
|
|
73
|
-
return transition;
|
|
74
|
-
}
|
|
75
|
-
function getTargets(targetAttr) {
|
|
76
|
-
// return targetAttr ? [`#${targetAttr}`] : undefined;
|
|
77
|
-
return targetAttr
|
|
78
|
-
? "".concat(targetAttr).split(/\s+/).map(function (target) { return "#".concat(target); })
|
|
79
|
-
: undefined;
|
|
80
|
-
}
|
|
81
|
-
function delayToMs(delay) {
|
|
82
|
-
if (!delay) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
if (typeof delay === 'number') {
|
|
86
|
-
return delay;
|
|
87
|
-
}
|
|
88
|
-
var millisecondsMatch = delay.match(/(\d+)ms/);
|
|
89
|
-
if (millisecondsMatch) {
|
|
90
|
-
return parseInt(millisecondsMatch[1], 10);
|
|
91
|
-
}
|
|
92
|
-
var secondsMatch = delay.match(/(\d*)(\.?)(\d+)s/);
|
|
93
|
-
if (secondsMatch) {
|
|
94
|
-
var hasDecimal = !!secondsMatch[2];
|
|
95
|
-
if (!hasDecimal) {
|
|
96
|
-
return parseInt(secondsMatch[3], 10) * 1000;
|
|
97
|
-
}
|
|
98
|
-
var secondsPart = !!secondsMatch[1]
|
|
99
|
-
? parseInt(secondsMatch[1], 10) * 1000
|
|
100
|
-
: 0;
|
|
101
|
-
var millisecondsPart = parseInt(secondsMatch[3].padEnd(3, '0'), 10);
|
|
102
|
-
if (millisecondsPart >= 1000) {
|
|
103
|
-
throw new Error("Can't parse \"".concat(delay, " delay.\""));
|
|
104
|
-
}
|
|
105
|
-
return secondsPart + millisecondsPart;
|
|
106
|
-
}
|
|
107
|
-
throw new Error("Can't parse \"".concat(delay, " delay.\""));
|
|
108
|
-
}
|
|
109
|
-
var evaluateExecutableContent = function (context, _ev, meta, body) {
|
|
110
|
-
var datamodel = context
|
|
111
|
-
? Object.keys(context)
|
|
112
|
-
.map(function (key) { return "const ".concat(key, " = context['").concat(key, "'];"); })
|
|
113
|
-
.join('\n')
|
|
114
|
-
: '';
|
|
115
|
-
var scope = ['const _sessionid = "NOT_IMPLEMENTED";', datamodel]
|
|
116
|
-
.filter(Boolean)
|
|
117
|
-
.join('\n');
|
|
118
|
-
var args = ['context', '_event'];
|
|
119
|
-
var fnBody = "\n ".concat(scope, "\n ").concat(body, "\n ");
|
|
120
|
-
var fn = new (Function.bind.apply(Function, __spreadArray(__spreadArray([void 0], __read(args), false), [fnBody], false)))();
|
|
121
|
-
return fn(context, meta._event);
|
|
122
|
-
};
|
|
123
|
-
function createCond(cond) {
|
|
124
|
-
return function (context, _event, meta) {
|
|
125
|
-
return evaluateExecutableContent(context, _event, meta, "return ".concat(cond, ";"));
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
function mapAction(element) {
|
|
129
|
-
var e_1, _a;
|
|
130
|
-
switch (element.name) {
|
|
131
|
-
case 'raise': {
|
|
132
|
-
return actions.raise(element.attributes.event);
|
|
133
|
-
}
|
|
134
|
-
case 'assign': {
|
|
135
|
-
return actions.assign(function (context, e, meta) {
|
|
136
|
-
var fnBody = "\n return {'".concat(element.attributes.location, "': ").concat(element.attributes.expr, "};\n ");
|
|
137
|
-
return evaluateExecutableContent(context, e, meta, fnBody);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
case 'send': {
|
|
141
|
-
var _b = element.attributes, event_1 = _b.event, eventexpr_1 = _b.eventexpr, target = _b.target;
|
|
142
|
-
var convertedEvent = void 0;
|
|
143
|
-
var convertedDelay = void 0;
|
|
144
|
-
var params_1 = element.elements &&
|
|
145
|
-
element.elements.reduce(function (acc, child) {
|
|
146
|
-
if (child.name === 'content') {
|
|
147
|
-
throw new Error('Conversion of <content/> inside <send/> not implemented.');
|
|
148
|
-
}
|
|
149
|
-
return "".concat(acc).concat(child.attributes.name, ":").concat(child.attributes.expr, ",\n");
|
|
150
|
-
}, '');
|
|
151
|
-
if (event_1 && !params_1) {
|
|
152
|
-
convertedEvent = event_1;
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
convertedEvent = function (context, _ev, meta) {
|
|
156
|
-
var fnBody = "\n return { type: ".concat(event_1 ? "\"".concat(event_1, "\"") : eventexpr_1, ", ").concat(params_1 ? params_1 : '', " }\n ");
|
|
157
|
-
return evaluateExecutableContent(context, _ev, meta, fnBody);
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
if ('delay' in element.attributes) {
|
|
161
|
-
convertedDelay = delayToMs(element.attributes.delay);
|
|
162
|
-
}
|
|
163
|
-
else if (element.attributes.delayexpr) {
|
|
164
|
-
convertedDelay = function (context, _ev, meta) {
|
|
165
|
-
var fnBody = "\n return (".concat(delayToMs, ")(").concat(element.attributes.delayexpr, ");\n ");
|
|
166
|
-
return evaluateExecutableContent(context, _ev, meta, fnBody);
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
return actions.send(convertedEvent, {
|
|
170
|
-
delay: convertedDelay,
|
|
171
|
-
to: target
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
case 'log': {
|
|
175
|
-
var label = element.attributes.label;
|
|
176
|
-
return actions.log(function (context, e, meta) {
|
|
177
|
-
var fnBody = "\n return ".concat(element.attributes.expr, ";\n ");
|
|
178
|
-
return evaluateExecutableContent(context, e, meta, fnBody);
|
|
179
|
-
}, label !== undefined ? String(label) : undefined);
|
|
180
|
-
}
|
|
181
|
-
case 'if': {
|
|
182
|
-
var conds = [];
|
|
183
|
-
var current = {
|
|
184
|
-
cond: createCond(element.attributes.cond),
|
|
185
|
-
actions: []
|
|
186
|
-
};
|
|
187
|
-
try {
|
|
188
|
-
for (var _c = __values(element.elements), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
189
|
-
var el = _d.value;
|
|
190
|
-
if (el.type === 'comment') {
|
|
191
|
-
continue;
|
|
192
|
-
}
|
|
193
|
-
switch (el.name) {
|
|
194
|
-
case 'elseif':
|
|
195
|
-
conds.push(current);
|
|
196
|
-
current = {
|
|
197
|
-
cond: createCond(el.attributes.cond),
|
|
198
|
-
actions: []
|
|
199
|
-
};
|
|
200
|
-
break;
|
|
201
|
-
case 'else':
|
|
202
|
-
conds.push(current);
|
|
203
|
-
current = { actions: [] };
|
|
204
|
-
break;
|
|
205
|
-
default:
|
|
206
|
-
current.actions.push(mapAction(el));
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
212
|
-
finally {
|
|
213
|
-
try {
|
|
214
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
215
|
-
}
|
|
216
|
-
finally { if (e_1) throw e_1.error; }
|
|
217
|
-
}
|
|
218
|
-
conds.push(current);
|
|
219
|
-
return actions.choose(conds);
|
|
220
|
-
}
|
|
221
|
-
default:
|
|
222
|
-
throw new Error("Conversion of \"".concat(element.name, "\" elements is not implemented yet."));
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
function mapActions(elements) {
|
|
226
|
-
var e_2, _a;
|
|
227
|
-
var mapped = [];
|
|
228
|
-
try {
|
|
229
|
-
for (var elements_1 = __values(elements), elements_1_1 = elements_1.next(); !elements_1_1.done; elements_1_1 = elements_1.next()) {
|
|
230
|
-
var element = elements_1_1.value;
|
|
231
|
-
if (element.type === 'comment') {
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
mapped.push(mapAction(element));
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
238
|
-
finally {
|
|
239
|
-
try {
|
|
240
|
-
if (elements_1_1 && !elements_1_1.done && (_a = elements_1.return)) _a.call(elements_1);
|
|
241
|
-
}
|
|
242
|
-
finally { if (e_2) throw e_2.error; }
|
|
243
|
-
}
|
|
244
|
-
return mapped;
|
|
245
|
-
}
|
|
246
|
-
function toConfig(nodeJson, id, options) {
|
|
247
|
-
var parallel = nodeJson.name === 'parallel';
|
|
248
|
-
var initial = parallel ? undefined : nodeJson.attributes.initial;
|
|
249
|
-
var elements = nodeJson.elements;
|
|
250
|
-
switch (nodeJson.name) {
|
|
251
|
-
case 'history': {
|
|
252
|
-
if (!elements) {
|
|
253
|
-
return {
|
|
254
|
-
id: id,
|
|
255
|
-
history: nodeJson.attributes.type || 'shallow'
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
var _a = __read(elements.filter(function (element) { return element.name === 'transition'; }), 1), transitionElement = _a[0];
|
|
259
|
-
var target = getAttribute(transitionElement, 'target');
|
|
260
|
-
var history_1 = getAttribute(nodeJson, 'type') || 'shallow';
|
|
261
|
-
return {
|
|
262
|
-
id: id,
|
|
263
|
-
history: history_1,
|
|
264
|
-
target: target ? "#".concat(target) : undefined
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
case 'final': {
|
|
268
|
-
return __assign(__assign({}, nodeJson.attributes), { type: 'final' });
|
|
269
|
-
}
|
|
270
|
-
default:
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
273
|
-
if (nodeJson.elements) {
|
|
274
|
-
var stateElements = nodeJson.elements.filter(function (element) {
|
|
275
|
-
return element.name === 'state' ||
|
|
276
|
-
element.name === 'parallel' ||
|
|
277
|
-
element.name === 'final' ||
|
|
278
|
-
element.name === 'history';
|
|
279
|
-
});
|
|
280
|
-
var transitionElements = nodeJson.elements.filter(function (element) { return element.name === 'transition'; });
|
|
281
|
-
var invokeElements = nodeJson.elements.filter(function (element) { return element.name === 'invoke'; });
|
|
282
|
-
var onEntryElement = nodeJson.elements.find(function (element) { return element.name === 'onentry'; });
|
|
283
|
-
var onExitElement = nodeJson.elements.find(function (element) { return element.name === 'onexit'; });
|
|
284
|
-
var states = indexedRecord(stateElements, function (item) { return "".concat(item.attributes.id); });
|
|
285
|
-
var initialElement = !initial
|
|
286
|
-
? nodeJson.elements.find(function (element) { return element.name === 'initial'; })
|
|
287
|
-
: undefined;
|
|
288
|
-
if (initialElement && initialElement.elements.length) {
|
|
289
|
-
initial = initialElement.elements.find(function (element) { return element.name === 'transition'; }).attributes.target;
|
|
290
|
-
}
|
|
291
|
-
else if (!initialElement && stateElements.length) {
|
|
292
|
-
initial = stateElements[0].attributes.id;
|
|
293
|
-
}
|
|
294
|
-
var on = transitionElements.map(function (value) {
|
|
295
|
-
var event = getAttribute(value, 'event') || '';
|
|
296
|
-
var targets = getAttribute(value, 'target');
|
|
297
|
-
var internal = getAttribute(value, 'type') === 'internal';
|
|
298
|
-
return __assign(__assign(__assign({ event: event, target: getTargets(targets) }, (value.elements ? executableContent(value.elements) : undefined)), (value.attributes && value.attributes.cond
|
|
299
|
-
? {
|
|
300
|
-
cond: createCond(value.attributes.cond)
|
|
301
|
-
}
|
|
302
|
-
: undefined)), { internal: internal });
|
|
303
|
-
});
|
|
304
|
-
var onEntry = onEntryElement
|
|
305
|
-
? mapActions(onEntryElement.elements)
|
|
306
|
-
: undefined;
|
|
307
|
-
var onExit = onExitElement
|
|
308
|
-
? mapActions(onExitElement.elements)
|
|
309
|
-
: undefined;
|
|
310
|
-
var invoke = invokeElements.map(function (element) {
|
|
311
|
-
if (!['scxml', 'http://www.w3.org/TR/scxml/'].includes(element.attributes.type)) {
|
|
312
|
-
throw new Error('Currently only converting invoke elements of type SCXML is supported.');
|
|
313
|
-
}
|
|
314
|
-
var content = element.elements.find(function (el) { return el.name === 'content'; });
|
|
315
|
-
return scxmlToMachine(content, options);
|
|
316
|
-
});
|
|
317
|
-
return __assign(__assign(__assign(__assign(__assign(__assign(__assign({ id: id }, (initial ? { initial: initial } : undefined)), (parallel ? { type: 'parallel' } : undefined)), (stateElements.length
|
|
318
|
-
? {
|
|
319
|
-
states: (0, utils_1.mapValues)(states, function (state, key) {
|
|
320
|
-
return toConfig(state, key, options);
|
|
321
|
-
})
|
|
322
|
-
}
|
|
323
|
-
: undefined)), (transitionElements.length ? { on: on } : undefined)), (onEntry ? { onEntry: onEntry } : undefined)), (onExit ? { onExit: onExit } : undefined)), (invoke.length ? { invoke: invoke } : undefined));
|
|
324
|
-
}
|
|
325
|
-
return { id: id };
|
|
326
|
-
}
|
|
327
|
-
function scxmlToMachine(scxmlJson, options) {
|
|
328
|
-
var machineElement = scxmlJson.elements.find(function (element) { return element.name === 'scxml'; });
|
|
329
|
-
var dataModelEl = machineElement.elements.filter(function (element) { return element.name === 'datamodel'; })[0];
|
|
330
|
-
var extState = dataModelEl
|
|
331
|
-
? dataModelEl
|
|
332
|
-
.elements.filter(function (element) { return element.name === 'data'; })
|
|
333
|
-
.reduce(function (acc, element) {
|
|
334
|
-
if (element.attributes.src) {
|
|
335
|
-
throw new Error("Conversion of `src` attribute on datamodel's <data> elements is not supported.");
|
|
336
|
-
}
|
|
337
|
-
acc[element.attributes.id] = element.attributes.expr
|
|
338
|
-
? // tslint:disable-next-line:no-eval
|
|
339
|
-
eval("(".concat(element.attributes.expr, ")"))
|
|
340
|
-
: undefined;
|
|
341
|
-
return acc;
|
|
342
|
-
}, {})
|
|
343
|
-
: undefined;
|
|
344
|
-
return (0, index_1.Machine)(__assign(__assign({}, toConfig(machineElement, '(machine)', options)), { context: extState, delimiter: options.delimiter }));
|
|
345
|
-
}
|
|
346
|
-
function toMachine(xml, options) {
|
|
347
|
-
var json = (0, xml_js_1.xml2js)(xml);
|
|
348
|
-
return scxmlToMachine(json, options);
|
|
349
|
-
}
|
|
350
|
-
exports.toMachine = toMachine;
|
package/lib/serviceScope.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { AnyInterpreter } from './types';
|
|
2
|
-
export declare const provide: <T, TService extends AnyInterpreter>(service: TService | undefined, fn: (service: TService | undefined) => T) => T;
|
|
3
|
-
export declare const consume: <T, TService extends AnyInterpreter>(fn: (service: TService) => T) => T;
|
|
4
|
-
//# sourceMappingURL=serviceScope.d.ts.map
|
package/lib/serviceScope.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Maintains a stack of the current service in scope.
|
|
7
|
-
* This is used to provide the correct service to spawn().
|
|
8
|
-
*/
|
|
9
|
-
var serviceStack = [];
|
|
10
|
-
var provide = function (service, fn) {
|
|
11
|
-
serviceStack.push(service);
|
|
12
|
-
var result = fn(service);
|
|
13
|
-
serviceStack.pop();
|
|
14
|
-
return result;
|
|
15
|
-
};
|
|
16
|
-
var consume = function (fn) {
|
|
17
|
-
return fn(serviceStack[serviceStack.length - 1]);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
exports.consume = consume;
|
|
21
|
-
exports.provide = provide;
|
package/lib/stateUtils.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { EventObject, StateValue } from './types';
|
|
2
|
-
import { StateNode } from './StateNode';
|
|
3
|
-
declare type Configuration<TC, TE extends EventObject> = Iterable<StateNode<TC, any, TE>>;
|
|
4
|
-
declare type AdjList<TC, TE extends EventObject> = Map<StateNode<TC, any, TE>, Array<StateNode<TC, any, TE>>>;
|
|
5
|
-
export declare const isLeafNode: (stateNode: StateNode<any, any, any, any, any, any>) => boolean;
|
|
6
|
-
export declare function getChildren<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE>): Array<StateNode<TC, any, TE>>;
|
|
7
|
-
export declare function getAllStateNodes<TC, TE extends EventObject>(stateNode: StateNode<TC, any, TE, any, any, any>): Array<StateNode<TC, any, TE, any, any, any>>;
|
|
8
|
-
export declare function getConfiguration<TC, TE extends EventObject>(prevStateNodes: Iterable<StateNode<TC, any, TE, any, any, any>>, stateNodes: Iterable<StateNode<TC, any, TE, any, any, any>>): Set<StateNode<TC, any, TE, any, any, any>>;
|
|
9
|
-
export declare function getAdjList<TC, TE extends EventObject>(configuration: Configuration<TC, TE>): AdjList<TC, TE>;
|
|
10
|
-
export declare function getValue<TC, TE extends EventObject>(rootNode: StateNode<TC, any, TE, any>, configuration: Configuration<TC, TE>): StateValue;
|
|
11
|
-
export declare function has<T>(iterable: Iterable<T>, item: T): boolean;
|
|
12
|
-
export declare function nextEvents<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE>>): Array<TE['type']>;
|
|
13
|
-
export declare function isInFinalState<TC, TE extends EventObject>(configuration: Array<StateNode<TC, any, TE, any, any, any>>, stateNode: StateNode<TC, any, TE, any, any, any>): boolean;
|
|
14
|
-
export declare function getMeta(configuration?: StateNode[]): Record<string, any>;
|
|
15
|
-
export declare function getTagsFromConfiguration(configuration: StateNode<any, any, any, any>[]): Set<string>;
|
|
16
|
-
export {};
|
|
17
|
-
//# sourceMappingURL=stateUtils.d.ts.map
|
package/lib/stateUtils.js
DELETED
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _tslib = require('./_virtual/_tslib.js');
|
|
6
|
-
var utils = require('./utils.js');
|
|
7
|
-
|
|
8
|
-
var isLeafNode = function (stateNode) {
|
|
9
|
-
return stateNode.type === 'atomic' || stateNode.type === 'final';
|
|
10
|
-
};
|
|
11
|
-
function getChildren(stateNode) {
|
|
12
|
-
return Object.keys(stateNode.states).map(function (key) {
|
|
13
|
-
return stateNode.states[key];
|
|
14
|
-
}).filter(function (sn) {
|
|
15
|
-
return sn.type !== 'history';
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
function getAllStateNodes(stateNode) {
|
|
19
|
-
var stateNodes = [stateNode];
|
|
20
|
-
|
|
21
|
-
if (isLeafNode(stateNode)) {
|
|
22
|
-
return stateNodes;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return stateNodes.concat(utils.flatten(getChildren(stateNode).map(getAllStateNodes)));
|
|
26
|
-
}
|
|
27
|
-
function getConfiguration(prevStateNodes, stateNodes) {
|
|
28
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
29
|
-
|
|
30
|
-
var prevConfiguration = new Set(prevStateNodes);
|
|
31
|
-
var prevAdjList = getAdjList(prevConfiguration);
|
|
32
|
-
var configuration = new Set(stateNodes);
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
// add all ancestors
|
|
36
|
-
for (var configuration_1 = _tslib.__values(configuration), configuration_1_1 = configuration_1.next(); !configuration_1_1.done; configuration_1_1 = configuration_1.next()) {
|
|
37
|
-
var s = configuration_1_1.value;
|
|
38
|
-
var m = s.parent;
|
|
39
|
-
|
|
40
|
-
while (m && !configuration.has(m)) {
|
|
41
|
-
configuration.add(m);
|
|
42
|
-
m = m.parent;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
} catch (e_1_1) {
|
|
46
|
-
e_1 = {
|
|
47
|
-
error: e_1_1
|
|
48
|
-
};
|
|
49
|
-
} finally {
|
|
50
|
-
try {
|
|
51
|
-
if (configuration_1_1 && !configuration_1_1.done && (_a = configuration_1.return)) _a.call(configuration_1);
|
|
52
|
-
} finally {
|
|
53
|
-
if (e_1) throw e_1.error;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
var adjList = getAdjList(configuration);
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
// add descendants
|
|
61
|
-
for (var configuration_2 = _tslib.__values(configuration), configuration_2_1 = configuration_2.next(); !configuration_2_1.done; configuration_2_1 = configuration_2.next()) {
|
|
62
|
-
var s = configuration_2_1.value; // if previously active, add existing child nodes
|
|
63
|
-
|
|
64
|
-
if (s.type === 'compound' && (!adjList.get(s) || !adjList.get(s).length)) {
|
|
65
|
-
if (prevAdjList.get(s)) {
|
|
66
|
-
prevAdjList.get(s).forEach(function (sn) {
|
|
67
|
-
return configuration.add(sn);
|
|
68
|
-
});
|
|
69
|
-
} else {
|
|
70
|
-
s.initialStateNodes.forEach(function (sn) {
|
|
71
|
-
return configuration.add(sn);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
if (s.type === 'parallel') {
|
|
76
|
-
try {
|
|
77
|
-
for (var _e = (e_3 = void 0, _tslib.__values(getChildren(s))), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
78
|
-
var child = _f.value;
|
|
79
|
-
|
|
80
|
-
if (!configuration.has(child)) {
|
|
81
|
-
configuration.add(child);
|
|
82
|
-
|
|
83
|
-
if (prevAdjList.get(child)) {
|
|
84
|
-
prevAdjList.get(child).forEach(function (sn) {
|
|
85
|
-
return configuration.add(sn);
|
|
86
|
-
});
|
|
87
|
-
} else {
|
|
88
|
-
child.initialStateNodes.forEach(function (sn) {
|
|
89
|
-
return configuration.add(sn);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
} catch (e_3_1) {
|
|
95
|
-
e_3 = {
|
|
96
|
-
error: e_3_1
|
|
97
|
-
};
|
|
98
|
-
} finally {
|
|
99
|
-
try {
|
|
100
|
-
if (_f && !_f.done && (_c = _e.return)) _c.call(_e);
|
|
101
|
-
} finally {
|
|
102
|
-
if (e_3) throw e_3.error;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
} catch (e_2_1) {
|
|
109
|
-
e_2 = {
|
|
110
|
-
error: e_2_1
|
|
111
|
-
};
|
|
112
|
-
} finally {
|
|
113
|
-
try {
|
|
114
|
-
if (configuration_2_1 && !configuration_2_1.done && (_b = configuration_2.return)) _b.call(configuration_2);
|
|
115
|
-
} finally {
|
|
116
|
-
if (e_2) throw e_2.error;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
// add all ancestors
|
|
122
|
-
for (var configuration_3 = _tslib.__values(configuration), configuration_3_1 = configuration_3.next(); !configuration_3_1.done; configuration_3_1 = configuration_3.next()) {
|
|
123
|
-
var s = configuration_3_1.value;
|
|
124
|
-
var m = s.parent;
|
|
125
|
-
|
|
126
|
-
while (m && !configuration.has(m)) {
|
|
127
|
-
configuration.add(m);
|
|
128
|
-
m = m.parent;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
} catch (e_4_1) {
|
|
132
|
-
e_4 = {
|
|
133
|
-
error: e_4_1
|
|
134
|
-
};
|
|
135
|
-
} finally {
|
|
136
|
-
try {
|
|
137
|
-
if (configuration_3_1 && !configuration_3_1.done && (_d = configuration_3.return)) _d.call(configuration_3);
|
|
138
|
-
} finally {
|
|
139
|
-
if (e_4) throw e_4.error;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return configuration;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function getValueFromAdj(baseNode, adjList) {
|
|
147
|
-
var childStateNodes = adjList.get(baseNode);
|
|
148
|
-
|
|
149
|
-
if (!childStateNodes) {
|
|
150
|
-
return {}; // todo: fix?
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (baseNode.type === 'compound') {
|
|
154
|
-
var childStateNode = childStateNodes[0];
|
|
155
|
-
|
|
156
|
-
if (childStateNode) {
|
|
157
|
-
if (isLeafNode(childStateNode)) {
|
|
158
|
-
return childStateNode.key;
|
|
159
|
-
}
|
|
160
|
-
} else {
|
|
161
|
-
return {};
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
var stateValue = {};
|
|
166
|
-
childStateNodes.forEach(function (csn) {
|
|
167
|
-
stateValue[csn.key] = getValueFromAdj(csn, adjList);
|
|
168
|
-
});
|
|
169
|
-
return stateValue;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function getAdjList(configuration) {
|
|
173
|
-
var e_5, _a;
|
|
174
|
-
|
|
175
|
-
var adjList = new Map();
|
|
176
|
-
|
|
177
|
-
try {
|
|
178
|
-
for (var configuration_4 = _tslib.__values(configuration), configuration_4_1 = configuration_4.next(); !configuration_4_1.done; configuration_4_1 = configuration_4.next()) {
|
|
179
|
-
var s = configuration_4_1.value;
|
|
180
|
-
|
|
181
|
-
if (!adjList.has(s)) {
|
|
182
|
-
adjList.set(s, []);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (s.parent) {
|
|
186
|
-
if (!adjList.has(s.parent)) {
|
|
187
|
-
adjList.set(s.parent, []);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
adjList.get(s.parent).push(s);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
} catch (e_5_1) {
|
|
194
|
-
e_5 = {
|
|
195
|
-
error: e_5_1
|
|
196
|
-
};
|
|
197
|
-
} finally {
|
|
198
|
-
try {
|
|
199
|
-
if (configuration_4_1 && !configuration_4_1.done && (_a = configuration_4.return)) _a.call(configuration_4);
|
|
200
|
-
} finally {
|
|
201
|
-
if (e_5) throw e_5.error;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return adjList;
|
|
206
|
-
}
|
|
207
|
-
function getValue(rootNode, configuration) {
|
|
208
|
-
var config = getConfiguration([rootNode], configuration);
|
|
209
|
-
return getValueFromAdj(rootNode, getAdjList(config));
|
|
210
|
-
}
|
|
211
|
-
function has(iterable, item) {
|
|
212
|
-
if (Array.isArray(iterable)) {
|
|
213
|
-
return iterable.some(function (member) {
|
|
214
|
-
return member === item;
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (iterable instanceof Set) {
|
|
219
|
-
return iterable.has(item);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return false; // TODO: fix
|
|
223
|
-
}
|
|
224
|
-
function nextEvents(configuration) {
|
|
225
|
-
return _tslib.__spreadArray([], _tslib.__read(new Set(utils.flatten(_tslib.__spreadArray([], _tslib.__read(configuration.map(function (sn) {
|
|
226
|
-
return sn.ownEvents;
|
|
227
|
-
})), false)))), false);
|
|
228
|
-
}
|
|
229
|
-
function isInFinalState(configuration, stateNode) {
|
|
230
|
-
if (stateNode.type === 'compound') {
|
|
231
|
-
return getChildren(stateNode).some(function (s) {
|
|
232
|
-
return s.type === 'final' && has(configuration, s);
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (stateNode.type === 'parallel') {
|
|
237
|
-
return getChildren(stateNode).every(function (sn) {
|
|
238
|
-
return isInFinalState(configuration, sn);
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
function getMeta(configuration) {
|
|
245
|
-
if (configuration === void 0) {
|
|
246
|
-
configuration = [];
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return configuration.reduce(function (acc, stateNode) {
|
|
250
|
-
if (stateNode.meta !== undefined) {
|
|
251
|
-
acc[stateNode.id] = stateNode.meta;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return acc;
|
|
255
|
-
}, {});
|
|
256
|
-
}
|
|
257
|
-
function getTagsFromConfiguration(configuration) {
|
|
258
|
-
return new Set(utils.flatten(configuration.map(function (sn) {
|
|
259
|
-
return sn.tags;
|
|
260
|
-
})));
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
exports.getAdjList = getAdjList;
|
|
264
|
-
exports.getAllStateNodes = getAllStateNodes;
|
|
265
|
-
exports.getChildren = getChildren;
|
|
266
|
-
exports.getConfiguration = getConfiguration;
|
|
267
|
-
exports.getMeta = getMeta;
|
|
268
|
-
exports.getTagsFromConfiguration = getTagsFromConfiguration;
|
|
269
|
-
exports.getValue = getValue;
|
|
270
|
-
exports.has = has;
|
|
271
|
-
exports.isInFinalState = isInFinalState;
|
|
272
|
-
exports.isLeafNode = isLeafNode;
|
|
273
|
-
exports.nextEvents = nextEvents;
|
package/lib/typegenTypes.js
DELETED