scjson 0.3.3 → 0.3.5
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 +35 -1
- package/dist/harness.d.ts +8 -0
- package/dist/harness.js +96 -0
- package/package.json +19 -4
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<p align="center"><img src="
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/SoftOboros/scjson/main/scjson.png" alt="scjson logo" width="200"/></p>
|
|
2
2
|
|
|
3
3
|
# scjson JavaScript Package
|
|
4
4
|
|
|
@@ -47,6 +47,40 @@ scjson xml path/to/machine.scjson
|
|
|
47
47
|
scjson validate path/to/dir -r
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
## Harness CLI (SCION)
|
|
51
|
+
|
|
52
|
+
The package also ships a harness CLI that executes SCXML using the SCION engine
|
|
53
|
+
and emits JSONL traces compatible with compare tooling.
|
|
54
|
+
|
|
55
|
+
Install peer dependency:
|
|
56
|
+
```bash
|
|
57
|
+
npm i scion-core
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Usage:
|
|
61
|
+
```bash
|
|
62
|
+
npx scjson-scion-trace -I path/to/chart.(scxml|scjson) -e path/to/events.jsonl [--xml]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Quick check (from this repo):
|
|
66
|
+
```bash
|
|
67
|
+
cd js
|
|
68
|
+
npm ci
|
|
69
|
+
npm run harness:sample
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Flags:
|
|
73
|
+
- `--leaf-only` – emit leaf-only configurations (SCION already reports atomic states)
|
|
74
|
+
- `--omit-delta` – clear `datamodelDelta`
|
|
75
|
+
- `--omit-transitions` – clear `firedTransitions`
|
|
76
|
+
- `--strip-step0-noise` – at step 0, clear `datamodelDelta` and `firedTransitions`
|
|
77
|
+
- `--strip-step0-states` – at step 0, clear `enteredStates` and `exitedStates`
|
|
78
|
+
|
|
79
|
+
Notes:
|
|
80
|
+
- `.scjson` input is converted to SCXML internally before execution.
|
|
81
|
+
- SCION does not model time; `{"advance_time": N}` control tokens emit a
|
|
82
|
+
synthetic step to keep streams progressing.
|
|
83
|
+
|
|
50
84
|
## Conversion Functions
|
|
51
85
|
```js
|
|
52
86
|
/**
|
package/dist/harness.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agent Name: js-scion-harness
|
|
4
|
+
*
|
|
5
|
+
* Part of the scjson project.
|
|
6
|
+
* Developed by Softoboros Technology Inc.
|
|
7
|
+
* Licensed under the BSD 1-Clause License.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const node_child_process_1 = require("node:child_process");
|
|
11
|
+
const node_readline_1 = require("node:readline");
|
|
12
|
+
const node_path_1 = require("node:path");
|
|
13
|
+
function parseArgs(argv) {
|
|
14
|
+
const norm = {
|
|
15
|
+
leafOnly: false,
|
|
16
|
+
omitDelta: false,
|
|
17
|
+
omitTransitions: false,
|
|
18
|
+
stripStep0Noise: false,
|
|
19
|
+
stripStep0States: false,
|
|
20
|
+
};
|
|
21
|
+
const pass = [];
|
|
22
|
+
for (let i = 0; i < argv.length; i++) {
|
|
23
|
+
const a = argv[i];
|
|
24
|
+
switch (a) {
|
|
25
|
+
case '--leaf-only':
|
|
26
|
+
norm.leafOnly = true;
|
|
27
|
+
break;
|
|
28
|
+
case '--omit-delta':
|
|
29
|
+
norm.omitDelta = true;
|
|
30
|
+
break;
|
|
31
|
+
case '--omit-transitions':
|
|
32
|
+
norm.omitTransitions = true;
|
|
33
|
+
break;
|
|
34
|
+
case '--strip-step0-noise':
|
|
35
|
+
norm.stripStep0Noise = true;
|
|
36
|
+
break;
|
|
37
|
+
case '--strip-step0-states':
|
|
38
|
+
norm.stripStep0States = true;
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
pass.push(a);
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return { pass, norm };
|
|
46
|
+
}
|
|
47
|
+
function normalizeStep(obj, norm) {
|
|
48
|
+
if (!obj || typeof obj !== 'object')
|
|
49
|
+
return obj;
|
|
50
|
+
const out = { ...obj };
|
|
51
|
+
const step = typeof out.step === 'number' ? out.step : -1;
|
|
52
|
+
if (norm.omitDelta)
|
|
53
|
+
out.datamodelDelta = {};
|
|
54
|
+
if (norm.omitTransitions)
|
|
55
|
+
out.firedTransitions = [];
|
|
56
|
+
if (step === 0 && norm.stripStep0Noise) {
|
|
57
|
+
out.datamodelDelta = {};
|
|
58
|
+
out.firedTransitions = [];
|
|
59
|
+
}
|
|
60
|
+
if (step === 0 && norm.stripStep0States) {
|
|
61
|
+
out.enteredStates = [];
|
|
62
|
+
out.exitedStates = [];
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
async function main() {
|
|
67
|
+
const argv = process.argv.slice(2);
|
|
68
|
+
const { pass, norm } = parseArgs(argv);
|
|
69
|
+
const runner = (0, node_path_1.resolve)(__dirname, '../../tools/scion-runner/scion-trace.cjs');
|
|
70
|
+
const runPipe = (cmd, args) => new Promise((resolve) => {
|
|
71
|
+
const proc = (0, node_child_process_1.spawn)(cmd, args, { stdio: ['inherit', 'pipe', 'inherit'] });
|
|
72
|
+
const rl = (0, node_readline_1.createInterface)({ input: proc.stdout });
|
|
73
|
+
let failed = false;
|
|
74
|
+
rl.on('line', (line) => {
|
|
75
|
+
const s = line.trim();
|
|
76
|
+
if (!s)
|
|
77
|
+
return;
|
|
78
|
+
try {
|
|
79
|
+
const obj = JSON.parse(s);
|
|
80
|
+
const normed = normalizeStep(obj, norm);
|
|
81
|
+
process.stdout.write(JSON.stringify(normed) + '\n');
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
failed = true;
|
|
85
|
+
process.stderr.write(String(e) + '\n');
|
|
86
|
+
process.stdout.write(line + '\n');
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
proc.on('close', (code) => resolve(code !== null && code !== void 0 ? code : (failed ? 1 : 0)));
|
|
90
|
+
});
|
|
91
|
+
const code = await runPipe('node', [runner, ...pass]);
|
|
92
|
+
if (code !== 0) {
|
|
93
|
+
await runPipe('python', ['-m', 'scjson.cli', 'engine-trace', ...pass]);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
void main();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scjson",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "A JSON-based serialization of SCXML (State Chart XML).",
|
|
3
|
+
"version": "0.3.5",
|
|
4
|
+
"description": "A JSON-based serialization of SCXML (State Chart XML) with SCXML/SCML execution tooling and converters.",
|
|
5
5
|
"author": "Softoboros Technology Inc. <ira@softoboros.com>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -41,12 +41,24 @@
|
|
|
41
41
|
"LICENSE"
|
|
42
42
|
],
|
|
43
43
|
"bin": {
|
|
44
|
-
"scjson": "bin/scjson.js"
|
|
44
|
+
"scjson": "bin/scjson.js",
|
|
45
|
+
"scjson-scion-trace": "dist/harness.js"
|
|
45
46
|
},
|
|
47
|
+
"keywords": [
|
|
48
|
+
"scxml",
|
|
49
|
+
"statecharts",
|
|
50
|
+
"state-machine",
|
|
51
|
+
"scjson",
|
|
52
|
+
"scml",
|
|
53
|
+
"execution"
|
|
54
|
+
],
|
|
46
55
|
"scripts": {
|
|
47
56
|
"build": "tsc",
|
|
57
|
+
"postbuild": "node ../tools/scion-runner/extract.cjs",
|
|
48
58
|
"test": "jest",
|
|
49
|
-
"lint": "eslint"
|
|
59
|
+
"lint": "eslint",
|
|
60
|
+
"harness:sample": "node dist/harness.js -I ../tests/exec/toggle.scxml -e ../tests/exec/toggle.events.jsonl --xml --leaf-only --omit-delta --strip-step0-noise",
|
|
61
|
+
"ci:harness": "npm run build && npm run harness:sample"
|
|
50
62
|
},
|
|
51
63
|
"dependencies": {
|
|
52
64
|
"ajv": "^8.17.1",
|
|
@@ -54,6 +66,9 @@
|
|
|
54
66
|
"eslint": "^9.31.0",
|
|
55
67
|
"fast-xml-parser": "^5.2.5"
|
|
56
68
|
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"scion-core": "^2.6.0"
|
|
71
|
+
},
|
|
57
72
|
"devDependencies": {
|
|
58
73
|
"@babel/parser": "^7.28.0",
|
|
59
74
|
"@babel/types": "^7.28.2",
|