@tinyactors/node 0.1.0 → 0.2.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.
@@ -1,133 +0,0 @@
1
- 'use strict';
2
-
3
- // Expressions over an actor's data model. The JavaScript data model's data
4
- // is plain JavaScript objects (napi ADR 0001), so an expression is
5
- // JavaScript: the data's properties are in scope by name, `this` and `data`
6
- // are the data root, and `event`, `sessionID`, `name` and `inState(state)`
7
- // are what a chart's own expressions see in their context. A leading dot is
8
- // the data root, as in the jq form the test host uses: `.failures`.
9
- //
10
- // Evaluating an expression runs arbitrary code in the process that hosts
11
- // the actor. The debug session lets it only with the `evaluate` permission;
12
- // reading and writing a location by path (the Variables pane, setVariable
13
- // with a JSON value, completions) runs no code of the operator's.
14
-
15
- const { TinyactorsError } = require('../errors');
16
-
17
- const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
18
-
19
- // `.a.b` → `data.a.b`; anything else is left as it is.
20
- function source(text) {
21
- const trimmed = text.trim();
22
- return /^\.[A-Za-z_$]/.test(trimmed) ? `data${trimmed}` : trimmed;
23
- }
24
-
25
- function compile(parameters, body) {
26
- try {
27
- // A function the Function constructor makes is not strict, so `with`
28
- // puts the data's properties in scope.
29
- return new Function(...parameters, body);
30
- } catch (error) {
31
- throw new TinyactorsError(`the expression does not parse: ${error.message}`, 'invalid');
32
- }
33
- }
34
-
35
- const SCOPE = ['data', 'event', 'sessionID', 'name', 'inState'];
36
-
37
- function argumentsOf(scope) {
38
- const data = scope.data ?? {};
39
- return [data, scope.event, scope.sessionID, scope.name, (state) => scope.activeStates?.includes(state) ?? false];
40
- }
41
-
42
- /**
43
- * Evaluates `text` against `scope`: { data, event, sessionID, name,
44
- * activeStates }. Throws `invalid` when it does not parse, and rethrows what
45
- * the expression throws, as `invalid` with its message.
46
- */
47
- function evaluate(text, scope) {
48
- const fn = compile(SCOPE, `with (data) { return (${source(text)}\n); }`);
49
- const args = argumentsOf(scope);
50
- try {
51
- return fn.apply(args[0], args);
52
- } catch (error) {
53
- throw new TinyactorsError(`the expression threw: ${error?.message ?? error}`, 'invalid');
54
- }
55
- }
56
-
57
- /** Assigns `value` to the location expression `text` (`failures`, `.items[0].qty`). */
58
- function assign(text, value, scope) {
59
- const fn = compile([...SCOPE, '__value'], `with (data) { (${source(text)}) = __value; }`);
60
- const args = argumentsOf(scope);
61
- try {
62
- fn.apply(args[0], [...args, value]);
63
- } catch (error) {
64
- throw new TinyactorsError(`the assignment threw: ${error?.message ?? error}`, 'invalid');
65
- }
66
- }
67
-
68
- /**
69
- * A location as a path of keys, without running code: `failures`,
70
- * `.items[0].qty`, `data.items[0]`. Undefined when `text` is not a plain
71
- * path.
72
- */
73
- function pathOf(text) {
74
- let rest = text.trim();
75
- if (rest.startsWith('data.') || rest.startsWith('data[')) rest = rest.slice(4);
76
- else if (rest.startsWith('this.') || rest.startsWith('this[')) rest = rest.slice(4);
77
- if (!rest.startsWith('.') && !rest.startsWith('[')) rest = `.${rest}`;
78
- const path = [];
79
- const step = /^(?:\.([A-Za-z_$][\w$]*)|\[(\d+)\]|\[("(?:[^"\\]|\\.)*")\])/;
80
- while (rest !== '') {
81
- const match = step.exec(rest);
82
- if (match === null) return undefined;
83
- if (match[1] !== undefined) path.push(match[1]);
84
- else if (match[2] !== undefined) path.push(Number(match[2]));
85
- else path.push(JSON.parse(match[3]));
86
- rest = rest.slice(match[0].length);
87
- }
88
- return path.length === 0 ? undefined : path;
89
- }
90
-
91
- /** `.a.b[0]` for a path of keys. */
92
- function locationText(path) {
93
- return path.map((key) => (typeof key === 'number' ? `[${key}]`
94
- : IDENTIFIER.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`)).join('');
95
- }
96
-
97
- /** The value at `path` in `root`, or undefined. */
98
- function valueAt(root, path) {
99
- let value = root;
100
- for (const key of path) {
101
- if (value === null || typeof value !== 'object') return undefined;
102
- value = value[key];
103
- }
104
- return value;
105
- }
106
-
107
- /**
108
- * Completions for the data location that ends `text`: the keys of the
109
- * object it names that start with what was typed. [{ label, start }] with
110
- * `start` the column the typed prefix starts at.
111
- */
112
- function locations(text, root) {
113
- // `.a.b` or `a.b` (the object, then what was typed of a key), or a bare name.
114
- const dotted = /((?:\.?[A-Za-z_$][\w$]*)(?:\.[A-Za-z_$][\w$]*)*)?\.([A-Za-z_$][\w$]*)?$/;
115
- const bare = /(?:^|[^\w$.])([A-Za-z_$][\w$]*)$/;
116
- const match = new RegExp(`${dotted.source}|${bare.source}`).exec(text);
117
- if (match === null || root === null || typeof root !== 'object') return [];
118
- let container = root;
119
- let prefix;
120
- if (match[3] !== undefined) {
121
- prefix = match[3];
122
- } else {
123
- prefix = match[2] ?? '';
124
- const parent = match[1] === undefined ? [] : pathOf(match[1]);
125
- if (parent === undefined) return [];
126
- container = parent.length === 0 ? root : valueAt(root, parent);
127
- }
128
- if (container === null || typeof container !== 'object') return [];
129
- const start = text.length - prefix.length;
130
- return Object.keys(container).filter((key) => key.startsWith(prefix)).map((label) => ({ label, start }));
131
- }
132
-
133
- module.exports = { evaluate, assign, pathOf, locationText, valueAt, locations };
@@ -1,119 +0,0 @@
1
- 'use strict';
2
-
3
- // The stack of a thread, innermost first: the unit the actor runs next and
4
- // the <if> and <foreach> around it, the block (`onentry of busy`, a
5
- // transition's content), the microstep, and the macrostep with its event.
6
- // The top frame is where the actor stands, as a debugger's current line is:
7
- // what a step runs next (core ADR 0083). Between two microsteps that is
8
- // transition selection. An actor between macrosteps has one frame that says
9
- // where it rests.
10
- //
11
- // Where the actor stands comes from inspection, so an actor that paused
12
- // before the debugger attached has a position too. The transitions of its
13
- // microstep come from the trace spans the session read, and are left out
14
- // when it did not see them. Each frame's place in the JavaScript that wrote
15
- // the chart comes from its source spans (core ADR 0085), when it has them.
16
-
17
- /** The active states no other active state is inside of. */
18
- function leaves(view, labels) {
19
- const states = labels.states(view.definitionID);
20
- const parentOf = (name) => {
21
- const parent = states.find((state) => state.name === name)?.parent;
22
- return parent === undefined || parent === null ? undefined : states[parent]?.name;
23
- };
24
- const parents = new Set(view.activeStates.map(parentOf));
25
- return view.activeStates.filter((state) => !parents.has(state));
26
- }
27
-
28
- /**
29
- * [{ name, hint, place, macrostep }] for a thread. `view` is its inspection
30
- * or undefined when it is gone; `labels` names compiled IDs; `sources`
31
- * places them; `seen` is { macrostep, microstep } from the spans, or
32
- * undefined; `note` is added to an actor at rest (the mail waiting for it).
33
- */
34
- function frames({ view, labels, sources, seen, note }) {
35
- if (view === undefined) {
36
- return [{ name: 'gone', hint: 'label' }];
37
- }
38
- const definition = view.definitionID;
39
- const statePlace = (name) => sources.place(definition, 'state', labels.stateID(definition, name));
40
- if (view.residency === 'done') {
41
- return [{ name: `done in ${view.finalState ?? 'its final state'}`, hint: 'normal',
42
- place: view.finalState === null ? undefined : statePlace(view.finalState) }];
43
- }
44
- if (!view.macrostepInProgress) {
45
- const at = leaves(view, labels);
46
- return [{ name: `idle in ${at.join(' ') || 'no state'}${note ? ` (${note})` : ''}`, hint: 'normal',
47
- place: at.length === 0 ? undefined : statePlace(at[0]) }];
48
- }
49
- if (view.step.macrostep === 0) {
50
- return [{ name: view.currentEvent === null ? 'about to start (its bootstrap has not run)'
51
- : `about to take ${view.currentEvent.name} (before transition selection)`, hint: 'normal' }];
52
- }
53
- return [...unitFrames(view, labels, sources), ...stepFrames(view, seen, sources)];
54
- }
55
-
56
- function unitFrames(view, labels, sources) {
57
- const { position, definitionID: definition } = view;
58
- const macrostep = view.step.macrostep;
59
- if (position.at === 'none') {
60
- return [{ name: 'selecting transitions', hint: 'normal', macrostep }];
61
- }
62
- const out = [];
63
- const action = position.action;
64
- if (action !== null) {
65
- const info = labels.actionInfo(definition, action);
66
- const foreachNext = info?.kind === 'foreach';
67
- out.push({ name: `${labels.action(definition, action)}${foreachNext ? ` iteration ${position.iteration + 1}` : ''}`,
68
- hint: 'normal', place: sources.place(definition, 'action', action), macrostep });
69
- // The iteration is the innermost loop's: the one this action is in,
70
- // unless the action is a loop itself (core ADR 0083, open point 2).
71
- let innermost = !foreachNext;
72
- for (const owner of labels.enclosing(definition, action)) {
73
- let name = labels.action(definition, owner);
74
- if (labels.actionInfo(definition, owner)?.kind === 'foreach') {
75
- if (innermost) name += ` iteration ${position.iteration + 1}`;
76
- innermost = false;
77
- }
78
- out.push({ name, hint: 'normal', place: sources.place(definition, 'action', owner), macrostep });
79
- }
80
- }
81
- const block = position.at === 'transition' ? sources.place(definition, 'transition', position.transition)
82
- : position.state === null ? undefined : sources.place(definition, 'state', labels.stateID(definition, position.state));
83
- out.push({ name: blockName(position, definition, labels), hint: 'normal', place: block, macrostep });
84
- return out;
85
- }
86
-
87
- function blockName(position, definition, labels) {
88
- switch (position.at) {
89
- case 'exit': return `onexit of ${position.state}`;
90
- case 'transition': return `transition ${labels.transition(definition, position.transition)}`;
91
- case 'enter': {
92
- const outer = position.action === null ? undefined
93
- : labels.actionInfo(definition, labels.enclosing(definition, position.action).at(-1) ?? position.action);
94
- return outer?.block === 'onentry' ? `onentry of ${position.state}` : `entering ${position.state}`;
95
- }
96
- case 'select': return 'selecting transitions';
97
- case 'finalize': return `finalize in ${position.state}`;
98
- case 'invoke': return `starting the invocations of ${position.state}`;
99
- case 'bootstrap': return 'bootstrap';
100
- default: return position.at;
101
- }
102
- }
103
-
104
- function stepFrames(view, seen, sources) {
105
- const { macrostep, microstep } = view.step;
106
- const out = [];
107
- if (microstep > 0) {
108
- const known = seen?.microstep !== undefined && seen.macrostep === macrostep && seen.microstep.number === microstep;
109
- const taken = known ? `: ${seen.microstep.transitions.join('; ') || 'goto'}` : '';
110
- const first = known ? seen.microstep.transitionIDs[0] : undefined;
111
- out.push({ name: `microstep ${macrostep}.${microstep}${taken}`, hint: 'normal', macrostep,
112
- place: first === undefined ? undefined : sources.place(view.definitionID, 'transition', first) });
113
- }
114
- const event = view.currentEvent === null ? '' : ` on ${view.currentEvent.name}`;
115
- out.push({ name: `macrostep ${macrostep}${event}`, hint: 'normal', macrostep });
116
- return out;
117
- }
118
-
119
- module.exports = { frames, leaves };
@@ -1,142 +0,0 @@
1
- 'use strict';
2
-
3
- // Names for the compiled IDs a debugger shows, read with core's lookups by
4
- // ID (core ADRs 0042 and 0071) and cached: a definition never changes while
5
- // it is registered. Core supplies facts and the host builds labels
6
- // (core ADR 0071 section 3): `active → past_due on payment.failed` for a
7
- // transition, `assign 2` for the second action of its block.
8
-
9
- const { core } = require('../native');
10
- const { TinyactorsError } = require('../errors');
11
-
12
- const NONE = 4294967295;
13
-
14
- class Labels {
15
- #native;
16
- #cache = new Map();
17
-
18
- constructor(native) {
19
- this.#native = native;
20
- }
21
-
22
- static none(id) {
23
- return id === undefined || id === null || id === NONE;
24
- }
25
-
26
- // One lookup, cached; undefined when core does not know it.
27
- #lookup(definition, kind, id, fetch) {
28
- const key = `${definition}:${kind}:${id}`;
29
- if (this.#cache.has(key)) {
30
- return this.#cache.get(key);
31
- }
32
- let value;
33
- try {
34
- value = fetch();
35
- } catch (error) {
36
- if (!(error instanceof TinyactorsError && (error.code === 'not-found' || error.code === 'invalid'))) {
37
- throw error;
38
- }
39
- }
40
- this.#cache.set(key, value);
41
- return value;
42
- }
43
-
44
- /** { id, parent, kind } of a state by compiled ID, or undefined. */
45
- stateInfo(definition, id) {
46
- if (Labels.none(id)) return undefined;
47
- return this.#lookup(definition, 'state', id, () => core.definition_state(this.#native, definition, id));
48
- }
49
-
50
- /** A state's author ID, or undefined. */
51
- state(definition, id) {
52
- return this.stateInfo(definition, id)?.id;
53
- }
54
-
55
- /** Every state of the definition as { id, name, parent, kind }, in document order. */
56
- states(definition) {
57
- return this.#lookup(definition, 'states', 0, () => {
58
- const count = core.definition_inspect(this.#native, definition).state_count;
59
- const out = [];
60
- for (let id = 0; id < count; id += 1) {
61
- const info = core.definition_state(this.#native, definition, id);
62
- out.push({ id, name: info.id, parent: info.parent === NONE ? null : info.parent, kind: info.kind });
63
- }
64
- return out;
65
- });
66
- }
67
-
68
- /** The compiled ID of the state named `name`, or undefined. */
69
- stateID(definition, name) {
70
- return this.states(definition).find((state) => state.name === name)?.id;
71
- }
72
-
73
- /**
74
- * The text of an invocation's ID (core ADR 0049): the author's `<invoke
75
- * id>`, or the one core generated; its number when core no longer has it.
76
- */
77
- invocation(id) {
78
- try {
79
- return core.system_invoke_id_text(this.#native, id);
80
- } catch {
81
- return String(id);
82
- }
83
- }
84
-
85
- /** `source → targets on event`: the label the trace encoder writes too. */
86
- transition(definition, id) {
87
- const info = this.#lookup(definition, 'transition', id, () => core.definition_transition(this.#native, definition, id));
88
- if (info === undefined) return `transition ${id}`;
89
- const source = this.state(definition, info.source) ?? 'the document';
90
- const targets = info.targets.map((target) => this.state(definition, target));
91
- let text = targets.length === 0 ? source : `${source} → ${targets.join(' ')}`;
92
- if (info.event !== undefined && info.event !== '') text += ` on ${info.event}`;
93
- return info.type === 'internal' ? `${text} (internal)` : text;
94
- }
95
-
96
- /** { kind, block, owner, block_index, index } of an action, or undefined. */
97
- actionInfo(definition, id) {
98
- if (Labels.none(id)) return undefined;
99
- return this.#lookup(definition, 'action', id, () => core.definition_action(this.#native, definition, id));
100
- }
101
-
102
- /** `assign 2`: the element and its place in its block, from 1. */
103
- action(definition, id) {
104
- const info = this.actionInfo(definition, id);
105
- return info === undefined ? `action ${id}` : `${info.kind} ${info.index + 1}`;
106
- }
107
-
108
- /** The <if> and <foreach> actions around an action, innermost first. */
109
- enclosing(definition, id) {
110
- const chain = [];
111
- let info = this.actionInfo(definition, id);
112
- while (info !== undefined && ['then', 'else', 'foreach'].includes(info.block)) {
113
- chain.push(info.owner);
114
- info = this.actionInfo(definition, info.owner);
115
- }
116
- return chain;
117
- }
118
-
119
- /** An expression's source text, or undefined for a JavaScript function. */
120
- expression(definition, id) {
121
- if (Labels.none(id)) return undefined;
122
- const text = this.#lookup(definition, 'expression', id, () => core.definition_expression(this.#native, definition, id));
123
- return typeof text === 'string' ? text : undefined;
124
- }
125
-
126
- /** The event descriptors the definition's transitions listen for, sorted. */
127
- events(definition) {
128
- return this.#lookup(definition, 'events', 0, () => {
129
- const count = core.definition_inspect(this.#native, definition).transition_count;
130
- const names = new Set();
131
- for (let id = 0; id < count; id += 1) {
132
- const event = core.definition_transition(this.#native, definition, id).event;
133
- for (const name of (event ?? '').split(/\s+/)) {
134
- if (name !== '') names.add(name);
135
- }
136
- }
137
- return [...names].sort();
138
- });
139
- }
140
- }
141
-
142
- module.exports = { Labels, NONE };
@@ -1,207 +0,0 @@
1
- 'use strict';
2
-
3
- // Macrosteps of the sessions a debug session watches, read from the spans
4
- // of each turn (napi ADR 0016's mapping, decoded with decodeTraces()). A
5
- // macrostep's microstep spans end as the next microstep begins, possibly in
6
- // an earlier turn than the macrostep's own span, so they wait here until
7
- // the macrostep ends. Lifecycle spans (finished, destroyed, unloaded) are
8
- // passed on as they come.
9
-
10
- const { decodeTraces } = require('../otlp');
11
-
12
- const LIFECYCLE = new Set(['scxml.spawned', 'scxml.loaded', 'scxml.unloaded', 'scxml.finished', 'scxml.destroyed',
13
- 'scxml.withdrawn']);
14
-
15
- class Macrosteps {
16
- // session ID text -> Map(macrostep number -> microstep spans)
17
- #open = new Map();
18
- #wanted;
19
-
20
- /** `wanted(session)` says whether a session (decimal text) is one to follow. */
21
- constructor(wanted) {
22
- this.#wanted = wanted;
23
- }
24
-
25
- /**
26
- * Reads one turn's trace bytes. Returns { macrosteps, lifecycle }: each
27
- * macrostep that ended, as Macrosteps.record() describes it, and each
28
- * lifecycle span as { session, kind, attributes }.
29
- */
30
- read(bytes) {
31
- const out = { macrosteps: [], lifecycle: [] };
32
- if (!(bytes instanceof Uint8Array) || bytes.length === 0) {
33
- return out;
34
- }
35
- for (const span of decodeTraces(bytes)) {
36
- const session = span.attributes['scxml.session_id'];
37
- if (session === undefined || !this.#wanted(session)) {
38
- continue;
39
- }
40
- if (LIFECYCLE.has(span.name)) {
41
- out.lifecycle.push({ session, kind: span.name.slice('scxml.'.length), attributes: span.attributes });
42
- } else if (span.name.startsWith('scxml.microstep')) {
43
- this.#microsteps(session, span.attributes['scxml.macrostep']).push(span);
44
- } else if (span.name.startsWith('scxml.macrostep')) {
45
- const number = span.attributes['scxml.macrostep'];
46
- const microsteps = this.#microsteps(session, number);
47
- this.#open.get(session).delete(number);
48
- out.macrosteps.push(record(session, span, microsteps));
49
- }
50
- }
51
- return out;
52
- }
53
-
54
- /** Forgets what waits for a session that went away. */
55
- forget(session) {
56
- this.#open.delete(session);
57
- }
58
-
59
- #microsteps(session, number) {
60
- let bySession = this.#open.get(session);
61
- if (bySession === undefined) {
62
- bySession = new Map();
63
- this.#open.set(session, bySession);
64
- }
65
- let list = bySession.get(number);
66
- if (list === undefined) {
67
- list = [];
68
- bySession.set(number, list);
69
- }
70
- return list;
71
- }
72
- }
73
-
74
- const list = (value) => (Array.isArray(value) ? value : value === undefined ? [] : [value]);
75
-
76
- /*
77
- * { session, number, definition, event: { name, type, data } | null,
78
- * microsteps: [{ number, event, transitions, transitionIDs, exited, entered, jump }],
79
- * records: [{ name, attributes }] in the order they happened,
80
- * states, incomplete }
81
- */
82
- function record(session, span, microsteps) {
83
- const attributes = span.attributes;
84
- const events = [];
85
- const steps = microsteps
86
- .map((micro) => {
87
- const a = micro.attributes;
88
- for (const event of micro.events) events.push(event);
89
- const transitions = list(a['scxml.transition']);
90
- return {
91
- number: a['scxml.microstep'],
92
- event: a['scxml.event.name'],
93
- transitions,
94
- transitionIDs: list(a['scxml.transition.id']),
95
- exited: list(a['scxml.state.exited']),
96
- entered: list(a['scxml.state.entered']),
97
- // An operator transition names no chart transition (core ADR 0082).
98
- jump: transitions.length === 0 && a['scxml.microstep'] !== undefined && attributes['scxml.macrostep'] !== 1,
99
- };
100
- })
101
- .sort((left, right) => left.number - right.number);
102
- for (const event of span.events) events.push(event);
103
- events.sort((left, right) => (left.timeUnixNano < right.timeUnixNano ? -1 : left.timeUnixNano > right.timeUnixNano ? 1
104
- : (left.attributes['scxml.microstep'] ?? 0) - (right.attributes['scxml.microstep'] ?? 0)));
105
- const name = attributes['scxml.event.name'];
106
- return {
107
- session,
108
- number: attributes['scxml.macrostep'],
109
- definition: attributes['scxml.definition'],
110
- event: name === undefined ? null : {
111
- name,
112
- type: attributes['scxml.event.type'],
113
- data: attributes['scxml.event.data'],
114
- },
115
- microsteps: steps,
116
- records: events.map((event) => ({ name: event.name, attributes: event.attributes })),
117
- states: list(attributes['scxml.state']),
118
- incomplete: attributes['scxml.incomplete'] === true,
119
- error: span.status.code === 'error',
120
- };
121
- }
122
-
123
- /**
124
- * The console's summary of a macrostep, as lines: the event, each
125
- * microstep with what ran in it, and the configuration it ended in. The
126
- * session writes them as one output, as the test host's adapter does.
127
- * `location(definition, expressionID)` names an <assign>'s location.
128
- */
129
- function summarize(macrostep, label, location) {
130
- const lines = [];
131
- const event = macrostep.event;
132
- const head = event === null ? (macrostep.number === 1 ? 'bootstrap' : '(no event)')
133
- : `${event.name}${event.data === undefined ? '' : ` ${event.data}`}`;
134
- lines.push(`${label} macrostep ${macrostep.number}: ${head}${macrostep.incomplete ? ' (incomplete)' : ''}`);
135
- const byMicrostep = new Map();
136
- const before = [];
137
- for (const entry of macrostep.records) {
138
- const micro = entry.attributes['scxml.microstep'];
139
- if (micro === undefined || micro === 0) {
140
- before.push(entry);
141
- } else {
142
- if (!byMicrostep.has(micro)) byMicrostep.set(micro, []);
143
- byMicrostep.get(micro).push(entry);
144
- }
145
- }
146
- for (const entry of before) {
147
- const text = describe(entry, macrostep.definition, location);
148
- if (text !== undefined) lines.push(` ${text}`);
149
- }
150
- for (const micro of macrostep.microsteps) {
151
- let taken;
152
- if (micro.jump) {
153
- taken = `goto: exited ${micro.exited.join(' ') || 'nothing'}, entered ${micro.entered.join(' ') || 'nothing'}`;
154
- } else if (micro.transitions.length === 0) {
155
- taken = 'initial';
156
- } else {
157
- taken = micro.transitions.join('; ');
158
- }
159
- lines.push(` ${taken}`);
160
- for (const entry of byMicrostep.get(micro.number) ?? []) {
161
- const text = describe(entry, macrostep.definition, location);
162
- if (text !== undefined) lines.push(` ${text}`);
163
- }
164
- }
165
- if (macrostep.states.length > 0) {
166
- lines.push(` now in ${macrostep.states.join(' ')}`);
167
- }
168
- return lines;
169
- }
170
-
171
- // One record of a macrostep as a line, or undefined for those not shown.
172
- function describe(entry, definition, location) {
173
- const a = entry.attributes;
174
- const value = a['scxml.value'] === undefined ? '' : ` = ${a['scxml.value']}`;
175
- switch (entry.name) {
176
- case 'scxml.condition':
177
- return `${a['scxml.transition'] ?? a['scxml.action'] ?? 'condition'}: ${a['scxml.result'] === true}`;
178
- case 'scxml.assign': {
179
- const where = location(definition, a['scxml.expression.id']);
180
- return `assign ${where ?? `(${a['scxml.action'] ?? 'a location'})`}${value}`;
181
- }
182
- case 'scxml.raise':
183
- return `raise ${a['scxml.event.name']}`;
184
- case 'scxml.send':
185
- return `send ${a['scxml.event.name'] ?? ''}${a['scxml.send_id'] === undefined ? '' : ` (${a['scxml.send_id']})`}`;
186
- case 'scxml.cancel':
187
- return `cancel ${a['scxml.send_id'] ?? ''}`;
188
- case 'scxml.error': {
189
- const message = a['scxml.fault.message'] === undefined ? '' : `: ${a['scxml.fault.message']}`;
190
- return `failed: ${a['scxml.action'] ?? 'an action'}${message}`;
191
- }
192
- case 'scxml.invoke':
193
- return `invoke ${a['scxml.invoke_id'] ?? ''}`;
194
- case 'scxml.invoke.cancel':
195
- return `cancel invocation ${a['scxml.invoke_id'] ?? ''}`;
196
- case 'scxml.ignored':
197
- return `${a['scxml.event.name']} enabled no transition`;
198
- case 'scxml.abandoned':
199
- return 'abandoned by an operator';
200
- case 'scxml.stopped':
201
- return 'the run stopped: an allocation failed';
202
- default:
203
- return undefined;
204
- }
205
- }
206
-
207
- module.exports = { Macrosteps, summarize };