state-machine-cat 12.0.6 → 12.0.8
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/dist/cli/actions.mjs +34 -31
- package/dist/cli/attributes-parser.mjs +914 -889
- package/dist/cli/execute-command-line.mjs +98 -48
- package/dist/cli/file-name-to-stream.mjs +8 -8
- package/dist/cli/normalize.mjs +89 -70
- package/dist/cli/validations.mjs +72 -52
- package/dist/index-node.mjs +12 -9
- package/dist/index.mjs +10 -7
- package/dist/options.mjs +53 -53
- package/dist/parse/index.mjs +17 -17
- package/dist/parse/parser-helpers.mjs +159 -139
- package/dist/parse/scxml/index.mjs +152 -129
- package/dist/parse/scxml/normalize-machine.mjs +36 -35
- package/dist/parse/scxml/utl.mjs +1 -1
- package/dist/parse/smcat/smcat-parser.mjs +2794 -2844
- package/dist/parse/smcat-ast.schema.mjs +185 -168
- package/dist/render/dot/attributebuilder.mjs +40 -37
- package/dist/render/dot/counter.mjs +14 -14
- package/dist/render/dot/dot.states.template.js +1 -26
- package/dist/render/dot/dot.template.js +1 -14
- package/dist/render/dot/index.mjs +129 -82
- package/dist/render/dot/render-dot-from-ast.mjs +33 -16
- package/dist/render/dot/state-transformers.mjs +96 -85
- package/dist/render/dot/transition-transformers.mjs +39 -41
- package/dist/render/dot/utl.mjs +21 -19
- package/dist/render/index-node.mjs +16 -16
- package/dist/render/index.mjs +9 -9
- package/dist/render/scjson/index.mjs +111 -94
- package/dist/render/scjson/make-valid-event-names.mjs +21 -18
- package/dist/render/scjson/make-valid-xml-name.mjs +17 -13
- package/dist/render/scxml/index.mjs +2 -1
- package/dist/render/scxml/render-from-scjson.mjs +5 -2
- package/dist/render/scxml/scxml.states.template.js +1 -14
- package/dist/render/scxml/scxml.template.js +1 -6
- package/dist/render/smcat/index.mjs +54 -39
- package/dist/render/smcat/smcat.template.js +1 -13
- package/dist/render/vector/dot-to-vector-native.mjs +30 -26
- package/dist/render/vector/vector-native-dot-with-fallback.mjs +27 -20
- package/dist/render/vector/vector-with-wasm.mjs +13 -6
- package/dist/state-machine-model.mjs +67 -52
- package/dist/transform/desugar.mjs +115 -66
- package/dist/transform/utl.mjs +12 -12
- package/dist/version.mjs +1 -1
- package/package.json +74 -74
- package/types/state-machine-cat.d.mts +209 -209
|
@@ -7,155 +7,178 @@ import { castArray } from "./utl.mjs";
|
|
|
7
7
|
import { normalizeMachine } from "./normalize-machine.mjs";
|
|
8
8
|
const formatLabel = utl.formatLabel;
|
|
9
9
|
function extractActions(pState, pActionType) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
return castArray(pState[pActionType]).map((pAction) => ({
|
|
11
|
+
type: pActionType === "onexit" ? "exit" : "entry",
|
|
12
|
+
body: he.decode(pAction).trim(),
|
|
13
|
+
}));
|
|
14
14
|
}
|
|
15
15
|
function extractActionsFromInvokes(pInvokeTriggers) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
return castArray(pInvokeTriggers).map((pInvokeTrigger) => {
|
|
17
|
+
const lId = he.decode(pInvokeTrigger.id || "").trim();
|
|
18
|
+
return {
|
|
19
|
+
type: "activity",
|
|
20
|
+
body: lId || he.decode(pInvokeTrigger || "").trim(),
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
23
|
}
|
|
24
24
|
function deriveActions(pState) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
let lReturnValue = [];
|
|
26
|
+
if (pState.onentry) {
|
|
27
|
+
lReturnValue = lReturnValue.concat(extractActions(pState, "onentry"));
|
|
28
|
+
}
|
|
29
|
+
if (pState.invoke) {
|
|
30
|
+
lReturnValue = lReturnValue.concat(
|
|
31
|
+
extractActionsFromInvokes(pState.invoke),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
if (pState.onexit) {
|
|
35
|
+
lReturnValue = lReturnValue.concat(extractActions(pState, "onexit"));
|
|
36
|
+
}
|
|
37
|
+
return lReturnValue;
|
|
36
38
|
}
|
|
37
39
|
function deriveStateType(pType, pState) {
|
|
38
|
-
|
|
40
|
+
return pType === "history" && pState.type === "deep" ? "deephistory" : pType;
|
|
39
41
|
}
|
|
40
42
|
function mapState(pType) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
43
|
+
return (pState) => {
|
|
44
|
+
const lReturnValue = {
|
|
45
|
+
name: pState.id,
|
|
46
|
+
type: deriveStateType(pType, pState),
|
|
47
|
+
};
|
|
48
|
+
if (parserHelpers.getStateType(pState.id) !== lReturnValue.type) {
|
|
49
|
+
lReturnValue.typeExplicitlySet = true;
|
|
50
|
+
}
|
|
51
|
+
if (pState.onentry || pState.onexit || pState.invoke) {
|
|
52
|
+
lReturnValue.actions = deriveActions(pState);
|
|
53
|
+
}
|
|
54
|
+
if (
|
|
55
|
+
Object.keys(pState).some((pKey) =>
|
|
56
|
+
["initial", "state", "history", "parallel", "final"].includes(pKey),
|
|
57
|
+
)
|
|
58
|
+
) {
|
|
59
|
+
lReturnValue.statemachine = mapMachine(pState);
|
|
60
|
+
}
|
|
61
|
+
return lReturnValue;
|
|
62
|
+
};
|
|
57
63
|
}
|
|
58
64
|
function extractTransitionAttributesFromObject(pTransition) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
const lReturnValue = {};
|
|
66
|
+
if (pTransition.event) {
|
|
67
|
+
lReturnValue.event = pTransition.event.split(/\s+/).join("\n");
|
|
68
|
+
}
|
|
69
|
+
if (pTransition.cond) {
|
|
70
|
+
lReturnValue.cond = pTransition.cond;
|
|
71
|
+
}
|
|
72
|
+
if (pTransition["#text"]) {
|
|
73
|
+
lReturnValue.action = he.decode(pTransition["#text"]).trim();
|
|
74
|
+
}
|
|
75
|
+
if (pTransition.type) {
|
|
76
|
+
lReturnValue.type = pTransition.type;
|
|
77
|
+
}
|
|
78
|
+
return lReturnValue;
|
|
73
79
|
}
|
|
74
80
|
function extractTransitionAttributes(pTransition) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
const lReturnValue = {};
|
|
82
|
+
if (typeof pTransition === "string") {
|
|
83
|
+
lReturnValue.action = he.decode(pTransition).trim();
|
|
84
|
+
} else {
|
|
85
|
+
Object.assign(
|
|
86
|
+
lReturnValue,
|
|
87
|
+
extractTransitionAttributesFromObject(pTransition),
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const lLabel = formatLabel(
|
|
91
|
+
lReturnValue.event,
|
|
92
|
+
lReturnValue.cond,
|
|
93
|
+
lReturnValue.action,
|
|
94
|
+
);
|
|
95
|
+
if (lLabel) {
|
|
96
|
+
lReturnValue.label = lLabel;
|
|
97
|
+
}
|
|
98
|
+
return lReturnValue;
|
|
87
99
|
}
|
|
88
100
|
function reduceTransition(pState) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
return (pAllTransitions, pTransition) => {
|
|
102
|
+
const lTargets = (pTransition?.target ?? pState.id).split(/\s+/);
|
|
103
|
+
const lTransitionAttributes = extractTransitionAttributes(pTransition);
|
|
104
|
+
return pAllTransitions.concat(
|
|
105
|
+
lTargets.map((pTarget) => ({
|
|
106
|
+
from: pState.id,
|
|
107
|
+
to: pTarget,
|
|
108
|
+
...lTransitionAttributes,
|
|
109
|
+
})),
|
|
110
|
+
);
|
|
111
|
+
};
|
|
98
112
|
}
|
|
99
113
|
function extractTransitions(pStates) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
114
|
+
return pStates
|
|
115
|
+
.filter((pState) =>
|
|
116
|
+
Object.prototype.hasOwnProperty.call(pState, "transition"),
|
|
117
|
+
)
|
|
118
|
+
.reduce((pAllTransitions, pThisState) => {
|
|
119
|
+
const lTransitionAsArray = castArray(pThisState.transition);
|
|
120
|
+
return pAllTransitions.concat(
|
|
121
|
+
lTransitionAsArray.reduce(reduceTransition(pThisState), []),
|
|
122
|
+
);
|
|
123
|
+
}, []);
|
|
106
124
|
}
|
|
107
125
|
function mapMachine(pSCXMLStateMachine) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
126
|
+
const lNormalizedMachine = normalizeMachine(pSCXMLStateMachine);
|
|
127
|
+
const lReturnValue = {
|
|
128
|
+
states: lNormalizedMachine.initial
|
|
129
|
+
.map(mapState("initial"))
|
|
130
|
+
.concat(lNormalizedMachine.state.map(mapState("regular")))
|
|
131
|
+
.concat(lNormalizedMachine.parallel.map(mapState("parallel")))
|
|
132
|
+
.concat(lNormalizedMachine.history.map(mapState("history")))
|
|
133
|
+
.concat(lNormalizedMachine.final.map(mapState("final"))),
|
|
134
|
+
};
|
|
135
|
+
const lTransitions = extractTransitions(lNormalizedMachine.initial)
|
|
136
|
+
.concat(extractTransitions(lNormalizedMachine.state))
|
|
137
|
+
.concat(extractTransitions(lNormalizedMachine.parallel));
|
|
138
|
+
if (lTransitions.length > 0) {
|
|
139
|
+
lReturnValue.transitions = lTransitions;
|
|
140
|
+
}
|
|
141
|
+
return lReturnValue;
|
|
124
142
|
}
|
|
125
143
|
function deDuplicateAttributesAndTags(pObject, pAttributeNamePrefix) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
144
|
+
return traverse(pObject).map(function deDuplicate() {
|
|
145
|
+
if (this.key?.startsWith(pAttributeNamePrefix)) {
|
|
146
|
+
const pUnPrefixedAttributeName = this.key.slice(
|
|
147
|
+
pAttributeNamePrefix.length,
|
|
148
|
+
);
|
|
149
|
+
if (this.parent.keys.includes(pUnPrefixedAttributeName)) {
|
|
150
|
+
this.remove();
|
|
151
|
+
} else {
|
|
152
|
+
this.parent.node[pUnPrefixedAttributeName] = this.node;
|
|
153
|
+
this.remove();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
});
|
|
138
157
|
}
|
|
139
158
|
export function parse(pSCXMLString) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
const lTrimmedSCXMLString = pSCXMLString.trim();
|
|
160
|
+
const lAttributeNamePrefix = "@_";
|
|
161
|
+
let lXMLAsJSON = {};
|
|
162
|
+
const lXMLParser = new fastxml.XMLParser({
|
|
163
|
+
attributeNamePrefix: lAttributeNamePrefix,
|
|
164
|
+
ignoreAttributes: false,
|
|
165
|
+
parseTagValue: true,
|
|
166
|
+
processEntities: false,
|
|
167
|
+
tagValueProcessor: (_pTagName, pTagValue) => he.decode(pTagValue),
|
|
168
|
+
stopNodes: ["*.onentry", "*.onexit", "*.transition"],
|
|
169
|
+
});
|
|
170
|
+
try {
|
|
171
|
+
lXMLAsJSON = deDuplicateAttributesAndTags(
|
|
172
|
+
lXMLParser.parse(lTrimmedSCXMLString, true),
|
|
173
|
+
lAttributeNamePrefix,
|
|
174
|
+
);
|
|
175
|
+
} catch (pError) {
|
|
176
|
+
throw new Error("That doesn't look like valid xml ...\n");
|
|
177
|
+
}
|
|
178
|
+
return mapMachine(
|
|
179
|
+
lXMLAsJSON?.scxml ?? {
|
|
180
|
+
xmlns: "http://www.w3.org/2005/07/scxml",
|
|
181
|
+
version: "1.0",
|
|
182
|
+
},
|
|
183
|
+
);
|
|
161
184
|
}
|
|
@@ -1,44 +1,45 @@
|
|
|
1
1
|
import { castArray } from "./utl.mjs";
|
|
2
2
|
function normalizeInitialFromObject(pInitialObject, pId) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
const lReturnValue = {
|
|
4
|
+
id: pId ? `${pId}.initial` : "initial",
|
|
5
|
+
};
|
|
6
|
+
if (pInitialObject.transition) {
|
|
7
|
+
Object.assign(lReturnValue, {
|
|
8
|
+
transition: [pInitialObject.transition],
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return lReturnValue;
|
|
12
12
|
}
|
|
13
13
|
function normalizeInitialFromString(pString) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
return {
|
|
15
|
+
id: "initial",
|
|
16
|
+
transition: [
|
|
17
|
+
{
|
|
18
|
+
target: pString,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
22
|
}
|
|
23
23
|
function normalizeInitial(pMachine) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
const lReturnValue = [];
|
|
25
|
+
if (pMachine.initial) {
|
|
26
|
+
if (typeof pMachine.initial === "string") {
|
|
27
|
+
lReturnValue.push(normalizeInitialFromString(pMachine.initial));
|
|
28
|
+
} else {
|
|
29
|
+
lReturnValue.push(
|
|
30
|
+
normalizeInitialFromObject(pMachine.initial, pMachine.id),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return lReturnValue;
|
|
34
35
|
}
|
|
35
36
|
export function normalizeMachine(pMachine) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
return {
|
|
38
|
+
...pMachine,
|
|
39
|
+
initial: normalizeInitial(pMachine),
|
|
40
|
+
state: castArray(pMachine?.state ?? []),
|
|
41
|
+
parallel: castArray(pMachine?.parallel ?? []),
|
|
42
|
+
history: castArray(pMachine?.history ?? []),
|
|
43
|
+
final: castArray(pMachine?.final ?? []),
|
|
44
|
+
};
|
|
44
45
|
}
|
package/dist/parse/scxml/utl.mjs
CHANGED