@delurio/cli 0.10.0 → 0.11.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/NOTICE +7 -0
  3. package/README.md +14 -13
  4. package/js/changes.d.ts +17 -0
  5. package/js/cli.js +6 -0
  6. package/{dist → js}/edges.d.ts +2 -2
  7. package/js/edges.js +40 -0
  8. package/js/expr.js +25 -0
  9. package/js/graph.js +59 -0
  10. package/{dist → js}/html.d.ts +6 -6
  11. package/js/html.js +13 -0
  12. package/js/internal.js +408 -0
  13. package/js/kit.js +54 -0
  14. package/{dist → js}/model.d.ts +2 -2
  15. package/js/model.js +136 -0
  16. package/js/native.cjs +46 -0
  17. package/js/native.d.cts +322 -0
  18. package/{dist → js}/nav.d.ts +1 -1
  19. package/js/nav.js +70 -0
  20. package/js/needs.js +30 -0
  21. package/{dist → js}/spine.d.ts +3 -3
  22. package/js/spine.js +22 -0
  23. package/{dist → js}/starts.d.ts +1 -3
  24. package/{dist → js}/story.d.ts +2 -2
  25. package/js/story.js +22 -0
  26. package/{dist → js}/wireframe.d.ts +2 -2
  27. package/js/wireframe.js +29 -0
  28. package/js/yaml.d.ts +20 -0
  29. package/js/yaml.js +40 -0
  30. package/package.json +40 -24
  31. package/dist/anchors.d.ts +0 -29
  32. package/dist/anchors.js +0 -160
  33. package/dist/changes.d.ts +0 -25
  34. package/dist/changes.js +0 -101
  35. package/dist/check.d.ts +0 -23
  36. package/dist/check.js +0 -649
  37. package/dist/cli.d.ts +0 -2
  38. package/dist/cli.js +0 -194
  39. package/dist/compare.d.ts +0 -34
  40. package/dist/compare.js +0 -143
  41. package/dist/diff-flow.d.ts +0 -33
  42. package/dist/diff-flow.js +0 -547
  43. package/dist/diff-nav.d.ts +0 -20
  44. package/dist/diff-nav.js +0 -401
  45. package/dist/diff.d.ts +0 -25
  46. package/dist/diff.js +0 -331
  47. package/dist/domain-names.d.ts +0 -18
  48. package/dist/domain-names.js +0 -124
  49. package/dist/domain.d.ts +0 -25
  50. package/dist/domain.js +0 -110
  51. package/dist/edges.js +0 -120
  52. package/dist/expr.js +0 -157
  53. package/dist/graph.js +0 -236
  54. package/dist/html.js +0 -311
  55. package/dist/index-page.d.ts +0 -12
  56. package/dist/index-page.js +0 -50
  57. package/dist/invokes.d.ts +0 -10
  58. package/dist/invokes.js +0 -67
  59. package/dist/kit.js +0 -711
  60. package/dist/mermaid.d.ts +0 -3
  61. package/dist/mermaid.js +0 -50
  62. package/dist/model.js +0 -608
  63. package/dist/nav-page.d.ts +0 -15
  64. package/dist/nav-page.js +0 -283
  65. package/dist/nav.js +0 -578
  66. package/dist/needs.js +0 -335
  67. package/dist/pan.d.ts +0 -2
  68. package/dist/pan.js +0 -252
  69. package/dist/schemas.d.ts +0 -15
  70. package/dist/schemas.js +0 -316
  71. package/dist/spine.js +0 -156
  72. package/dist/starts.js +0 -88
  73. package/dist/story.js +0 -109
  74. package/dist/tutorial-check.d.ts +0 -9
  75. package/dist/tutorial-check.js +0 -297
  76. package/dist/ui-check.d.ts +0 -8
  77. package/dist/ui-check.js +0 -142
  78. package/dist/watch.d.ts +0 -5
  79. package/dist/watch.js +0 -114
  80. package/dist/wireframe.js +0 -276
  81. package/dist/yaml.d.ts +0 -19
  82. package/dist/yaml.js +0 -134
  83. /package/{dist → js}/expr.d.ts +0 -0
  84. /package/{dist → js}/graph.d.ts +0 -0
  85. /package/{dist → js}/kit.d.ts +0 -0
  86. /package/{dist → js}/needs.d.ts +0 -0
package/dist/edges.js DELETED
@@ -1,120 +0,0 @@
1
- import { alternatives, humanize } from './graph.js';
2
- export const BY = { human: 'person', ai: 'AI', agent: 'agent', ci: 'CI' };
3
- export function kindOf(g, name) {
4
- const st = g.flow.states[name];
5
- if (st.type === 'final')
6
- return 'exit';
7
- if (st.invoke?.flow !== undefined)
8
- return 'subflow';
9
- const shown = Object.values(g.ui.nodes).some((n) => (n.in ?? []).includes(name) && !(n.unless ?? []).includes(name));
10
- return shown ? 'screen' : 'server';
11
- }
12
- export function exitLine(st) {
13
- if (st.leavesPage === true)
14
- return 'user leaves the page';
15
- if (st.redirect === 'never')
16
- return 'no redirect, page shown';
17
- if (st.redirect === 'success')
18
- return `redirect with ${(st.carries ?? []).join(' + ')}`;
19
- if (st.redirect === undefined && st.code === undefined)
20
- return 'ends here';
21
- const codes = (st.code ?? '').split('|').map((c) => c.trim()).filter((c) => c !== '');
22
- return codes.length === 1 ? `redirect, error=${codes[0]}` : `redirect, error (${codes.length} codes)`;
23
- }
24
- // a step's `response` in one line: the status, the code and the redirect first, then the other fields
25
- export function responseLine(r) {
26
- const first = ['status', 'code', 'redirect'].filter((k) => r[k] !== undefined).map((k) => (k === 'redirect' ? `redirect ${String(r[k])}` : String(r[k])));
27
- const rest = Object.entries(r)
28
- .filter(([k]) => !['status', 'code', 'redirect'].includes(k))
29
- .map(([k, v]) => `${k}: ${typeof v === 'string' ? v : JSON.stringify(v)}`);
30
- return [...first, ...rest].join(' · ');
31
- }
32
- export function nodeLine(g, name) {
33
- const st = g.flow.states[name];
34
- const kind = kindOf(g, name);
35
- if (kind === 'exit')
36
- return exitLine(st);
37
- if (kind === 'subflow')
38
- return `sign-in flow · ${st.invoke?.flow}`;
39
- const by = st.by === undefined ? null : BY[st.by];
40
- if (st.goal === true)
41
- return `${name} · goal`;
42
- return `${name} · ${by ?? (kind === 'screen' ? 'screen' : 'server step')}`;
43
- }
44
- // visible text for a catalog key, with {placeholders} filled from the samples
45
- export function plain(g, key) {
46
- const raw = g.catalog[key] ?? key;
47
- return raw.replace(/\{(\w+)\}/g, (_m, p) => g.ui.samples[p] ?? p);
48
- }
49
- // the button or link text a person presses to send `event` while in `state`, if there is one
50
- export function pressLabel(g, state, event) {
51
- for (const n of Object.values(g.ui.nodes)) {
52
- if (n.emits !== event || !(n.in ?? []).includes(state))
53
- continue;
54
- if (n.text?.key !== undefined)
55
- return plain(g, n.text.key);
56
- }
57
- return null;
58
- }
59
- export function wrap(text, max) {
60
- const lines = [];
61
- let line = '';
62
- for (const word of text.split(' ')) {
63
- if (line !== '' && line.length + 1 + word.length > max) {
64
- lines.push(line);
65
- line = word;
66
- }
67
- else {
68
- line = line === '' ? word : `${line} ${word}`;
69
- }
70
- }
71
- if (line !== '')
72
- lines.push(line);
73
- return lines;
74
- }
75
- export function collectEdges(g, ex) {
76
- const groups = new Map();
77
- const add = (from, to, label, kind, used) => {
78
- const key = `${from}>${to}`;
79
- const grp = groups.get(key) ?? { from, to, labels: [], kinds: new Set(), used: false };
80
- if (label !== null && !grp.labels.includes(label))
81
- grp.labels.push(label);
82
- grp.kinds.add(kind);
83
- grp.used = grp.used || used;
84
- groups.set(key, grp);
85
- };
86
- for (const [name, st] of Object.entries(g.flow.states)) {
87
- (st.always ?? []).forEach((a, i) => add(name, a.target, a.say ?? a.guard ?? 'otherwise', 'route', ex.taken.has(`${name}|always|${i}`)));
88
- for (const [event, spec] of Object.entries(st.on ?? {})) {
89
- alternatives(spec).forEach((a, i) => {
90
- const press = pressLabel(g, name, event);
91
- let label;
92
- let kind;
93
- if (press !== null) {
94
- label = `“${press}”`;
95
- kind = 'user';
96
- }
97
- else if (event.startsWith('FAIL')) {
98
- label = a.say !== undefined ? `fails: ${a.say}` : humanize(event);
99
- kind = 'fail';
100
- }
101
- else {
102
- label = a.say ?? null;
103
- kind = 'system';
104
- }
105
- add(name, a.target, label, kind, ex.taken.has(`${name}|${event}|${i}`));
106
- if (a.starts !== undefined)
107
- add(name, a.target, `starts ${a.starts.flow}`, kind, ex.taken.has(`${name}|${event}|${i}`));
108
- });
109
- }
110
- }
111
- const order = ['user', 'system', 'route', 'fail'];
112
- return [...groups.values()].map((grp) => ({
113
- from: grp.from,
114
- to: grp.to,
115
- labels: grp.labels,
116
- kind: order.find((k) => grp.kinds.has(k)) ?? 'system',
117
- leave: g.flow.states[grp.to].leavesPage === true,
118
- unused: !grp.used,
119
- }));
120
- }
package/dist/expr.js DELETED
@@ -1,157 +0,0 @@
1
- const cache = new Map();
2
- function tokenize(src) {
3
- const out = [];
4
- const re = /\s*(?:==|!=|[()[\],]|'[^']*'|"[^"]*"|-?\d+(?:\.\d+)?|[A-Za-z_][A-Za-z0-9_.]*)/y;
5
- let i = 0;
6
- while (i < src.length) {
7
- re.lastIndex = i;
8
- const m = re.exec(src);
9
- if (m === null) {
10
- if (src.slice(i).trim() === '')
11
- break;
12
- throw new Error(`cannot read "${src.slice(i)}" in: ${src}`);
13
- }
14
- out.push(m[0].trim());
15
- i = re.lastIndex;
16
- }
17
- return out;
18
- }
19
- export function parseExpr(src) {
20
- const hit = cache.get(src);
21
- if (hit !== undefined)
22
- return hit;
23
- const toks = tokenize(src);
24
- let i = 0;
25
- const peek = () => toks[i];
26
- const next = () => toks[i++];
27
- const expect = (t) => {
28
- if (next() !== t)
29
- throw new Error(`expected "${t}" in: ${src}`);
30
- };
31
- const atom = () => {
32
- const t = next();
33
- if (t === undefined)
34
- throw new Error(`unexpected end in: ${src}`);
35
- if (t === '(') {
36
- const e = orExpr();
37
- expect(')');
38
- return e;
39
- }
40
- if (t === '[') {
41
- const items = [];
42
- while (peek() !== ']') {
43
- items.push(atom());
44
- if (peek() === ',')
45
- next();
46
- }
47
- expect(']');
48
- return { k: 'list', items };
49
- }
50
- if (t.startsWith("'") || t.startsWith('"'))
51
- return { k: 'lit', v: t.slice(1, -1) };
52
- if (/^-?\d/.test(t))
53
- return { k: 'lit', v: Number(t) };
54
- if (t === 'true')
55
- return { k: 'lit', v: true };
56
- if (t === 'false')
57
- return { k: 'lit', v: false };
58
- if (t === 'null')
59
- return { k: 'lit', v: null };
60
- if (/^[A-Za-z_]/.test(t) && !['and', 'or', 'not', 'in'].includes(t))
61
- return { k: 'id', name: t };
62
- throw new Error(`unexpected "${t}" in: ${src}`);
63
- };
64
- const cmpExpr = () => {
65
- const l = atom();
66
- const p = peek();
67
- if (p === '==' || p === '!=') {
68
- next();
69
- return { k: 'cmp', op: p, l, r: atom() };
70
- }
71
- if (p === 'in') {
72
- next();
73
- return { k: 'cmp', op: 'in', l, r: atom() };
74
- }
75
- if (p === 'not' && toks[i + 1] === 'in') {
76
- i += 2;
77
- return { k: 'cmp', op: 'not in', l, r: atom() };
78
- }
79
- return l;
80
- };
81
- const notExpr = () => {
82
- if (peek() === 'not') {
83
- next();
84
- return { k: 'not', e: notExpr() };
85
- }
86
- return cmpExpr();
87
- };
88
- const andExpr = () => {
89
- let l = notExpr();
90
- while (peek() === 'and') {
91
- next();
92
- l = { k: 'and', l, r: notExpr() };
93
- }
94
- return l;
95
- };
96
- const orExpr = () => {
97
- let l = andExpr();
98
- while (peek() === 'or') {
99
- next();
100
- l = { k: 'or', l, r: andExpr() };
101
- }
102
- return l;
103
- };
104
- const e = orExpr();
105
- if (i !== toks.length)
106
- throw new Error(`unexpected "${toks[i]}" in: ${src}`);
107
- cache.set(src, e);
108
- return e;
109
- }
110
- export function evaluate(e, lookup) {
111
- switch (e.k) {
112
- case 'lit':
113
- return e.v;
114
- case 'id':
115
- return lookup(e.name);
116
- case 'list':
117
- return e.items.map((x) => evaluate(x, lookup));
118
- case 'not':
119
- return !evaluate(e.e, lookup);
120
- case 'and':
121
- return Boolean(evaluate(e.l, lookup)) && Boolean(evaluate(e.r, lookup));
122
- case 'or':
123
- return Boolean(evaluate(e.l, lookup)) || Boolean(evaluate(e.r, lookup));
124
- case 'cmp': {
125
- const l = evaluate(e.l, lookup);
126
- const r = evaluate(e.r, lookup);
127
- if (e.op === '==')
128
- return l === r;
129
- if (e.op === '!=')
130
- return l !== r;
131
- const inList = Array.isArray(r) && r.some((x) => x === l);
132
- return e.op === 'in' ? inList : !inList;
133
- }
134
- }
135
- }
136
- export function identifiers(e, out = new Set()) {
137
- switch (e.k) {
138
- case 'id':
139
- out.add(e.name);
140
- break;
141
- case 'list':
142
- e.items.forEach((x) => identifiers(x, out));
143
- break;
144
- case 'not':
145
- identifiers(e.e, out);
146
- break;
147
- case 'and':
148
- case 'or':
149
- case 'cmp':
150
- identifiers(e.l, out);
151
- identifiers(e.r, out);
152
- break;
153
- case 'lit':
154
- break;
155
- }
156
- return out;
157
- }
package/dist/graph.js DELETED
@@ -1,236 +0,0 @@
1
- import { existsSync, readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { lineAndColumn, readYaml } from './yaml.js';
4
- import { identifiers, parseExpr } from './expr.js';
5
- // in a returnsFocus, the node that was pressed to open the dialog, whichever it is (SPEC.md §4); no node is called so
6
- export const OPENER = 'opener';
7
- // the roles whose node may say whether it is `checked` (WAI-ARIA 1.2: the roles that support aria-checked)
8
- export const CHECKABLE = ['checkbox', 'menuitemcheckbox', 'menuitemradio', 'option', 'radio', 'switch'];
9
- // a page node drawn over another page, whose closing `returnsFocus` may give the focus back (SPEC.md §4)
10
- export const isDialog = (n) => n?.type === 'page' && (n.role === 'dialog' || n.role === 'alertdialog');
11
- export class GraphError extends Error {
12
- place;
13
- constructor(message, place) {
14
- super(message);
15
- this.place = place;
16
- }
17
- }
18
- // the place of an error that a reader of the graph's files threw, given to it when it has none yet: a YAML error of
19
- // ui.yaml then says it is in ui.yaml, and the line the parser gave is kept
20
- export function placed(err, place) {
21
- if (err instanceof Error && err.place === undefined)
22
- Object.assign(err, { place });
23
- return err;
24
- }
25
- // the file a graph names, read as YAML, a YAML error carrying the file it is in
26
- function readGraphFile(read, file) {
27
- try {
28
- return readYaml(read(file));
29
- }
30
- catch (err) {
31
- throw placed(err, { file });
32
- }
33
- }
34
- const isMapValue = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
35
- // the place of a transition in flow.yaml: `on.<event>`, the item of a list of alternatives, or an item of `always`
36
- export function transitionPath(state, st, event, i) {
37
- if (event === null)
38
- return ['states', state, 'always', String(i)];
39
- return Array.isArray(st.on?.[event]) ? ['states', state, 'on', event, String(i)] : ['states', state, 'on', event];
40
- }
41
- // a catalog: a JSON object, read from the file ui.yaml names; one that is not there, or is not JSON, keeps the graph
42
- // from loading, at the place that names it or at the place the JSON parser gave
43
- function readCatalog(read, exists, ui) {
44
- if (typeof ui.catalog !== 'string' || ui.catalog === '') {
45
- throw new GraphError('ui.yaml names no catalog: it gives the words of its screens as catalog: catalog/<locale>.json (SPEC.md §4)', { file: 'ui.yaml', path: [] });
46
- }
47
- if (!exists(ui.catalog))
48
- throw new GraphError(`the catalog ${ui.catalog} that ui.yaml names does not exist`, { file: 'ui.yaml', path: ['catalog'] });
49
- let text;
50
- try {
51
- text = read(ui.catalog);
52
- }
53
- catch (err) {
54
- throw new GraphError(`the catalog ${ui.catalog} that ui.yaml names cannot be read: ${err.message}`, { file: 'ui.yaml', path: ['catalog'] });
55
- }
56
- try {
57
- return JSON.parse(text);
58
- }
59
- catch (err) {
60
- const message = err.message;
61
- const at = /line (\d+) column (\d+)/.exec(message);
62
- const offset = /position (\d+)/.exec(message);
63
- const place = { file: ui.catalog };
64
- if (at !== null)
65
- Object.assign(place, { line: Number(at[1]), column: Number(at[2]) });
66
- else if (offset !== null)
67
- Object.assign(place, lineAndColumn(text, Number(offset[1])));
68
- throw new GraphError(`the catalog ${ui.catalog} is not JSON: ${message}`, place);
69
- }
70
- }
71
- // 'silentRedirect' -> 'silent redirect'; used only when the graph gives no title
72
- export function humanize(id) {
73
- const words = id.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/[_.-]+/g, ' ').toLowerCase();
74
- return words.charAt(0).toUpperCase() + words.slice(1);
75
- }
76
- export function titleOf(flow, state) {
77
- return flow.states[state].title ?? humanize(state);
78
- }
79
- // a node is shown in a state when the state is in its `in` and not in its `unless`; `when` is read over the context
80
- export function shownIn(n, state) {
81
- return (n.in ?? []).includes(state) && !(n.unless ?? []).includes(state);
82
- }
83
- // The node that has focus once the flow has moved from the state `from` (null when it starts) into another state `to`,
84
- // both states the flow stops in (SPEC.md §4, Focus): a dialog that closes gives it back to its `returnsFocus` node when
85
- // `to` shows that node; else a page that opens gives it to its `initialFocus`, a dialog's before the page it covers;
86
- // else `focus.<to>`. null when the graph does not say, and on a move from a state to itself. `pressed` is the node that
87
- // was pressed to open the dialog, which a replay knows and the graph does not: a returnsFocus that lists several
88
- // nodes, or says OPENER, gives the focus to it. Without it, a list gives the one node of it that `to` shows, and
89
- // OPENER, or a list of which `to` shows several, gives null.
90
- export function focusAfter(ui, from, to, pressed) {
91
- if (from === to)
92
- return null;
93
- const nodes = ui.nodes;
94
- const shown = (id, state) => state !== null && nodes[id] !== undefined && shownIn(nodes[id], state);
95
- for (const e of ui.edges ?? []) {
96
- const [dialog, target] = e.returnsFocus ?? [];
97
- if (dialog === undefined || target === undefined || !isDialog(nodes[dialog]))
98
- continue;
99
- if (!shown(dialog, from) || shown(dialog, to))
100
- continue;
101
- if (typeof target === 'string' && target !== OPENER) {
102
- if (shown(target, to))
103
- return { node: target, by: 'returnsFocus', from: dialog };
104
- continue;
105
- }
106
- // the node that opened the dialog: the one pressed, when the caller knows it, among those a list allows
107
- const allowed = (id) => target === OPENER || (Array.isArray(target) && target.includes(id));
108
- if (pressed !== undefined) {
109
- if (allowed(pressed) && shown(pressed, to))
110
- return { node: pressed, by: 'returnsFocus', from: dialog };
111
- continue;
112
- }
113
- const candidates = Array.isArray(target) ? target.filter((id) => shown(id, to)) : [];
114
- if (candidates.length === 1)
115
- return { node: candidates[0], by: 'returnsFocus', from: dialog };
116
- return null;
117
- }
118
- const opened = Object.entries(nodes).filter(([id, n]) => n.type === 'page' && n.initialFocus !== undefined && shown(id, to) && !shown(id, from));
119
- const page = opened.find(([, n]) => isDialog(n)) ?? opened[0];
120
- if (page !== undefined)
121
- return { node: page[1].initialFocus, by: 'initialFocus', from: page[0] };
122
- const node = from === null ? undefined : ui.focus?.[to];
123
- return node === undefined ? null : { node, by: 'focus' };
124
- }
125
- export function alternatives(spec) {
126
- const list = Array.isArray(spec) ? spec : [spec];
127
- return list.map((a) => (typeof a === 'string' ? { target: a } : a));
128
- }
129
- // `read` and `exists` take a path relative to `dir`; the revision diff passes ones that read a git revision instead of the disk
130
- export function load(dir, read = (file) => readFileSync(join(dir, file), 'utf8'), exists = (file) => existsSync(join(dir, file))) {
131
- const flow = readGraphFile(read, 'flow.yaml');
132
- if (!isMapValue(flow))
133
- throw new GraphError('flow.yaml is not a map of keys (SPEC.md §2)', { file: 'flow.yaml', path: [] });
134
- if (!isMapValue(flow.states))
135
- throw new GraphError('flow.yaml has no states: a flow gives them as states: { <state>: { .. } } (SPEC.md §2)', { file: 'flow.yaml', path: ['states'] });
136
- // a flow with no context, guards or effects leaves the key out; every reader expects an object
137
- flow.context ??= {};
138
- flow.guards ??= {};
139
- flow.effects ??= {};
140
- // a flow with no screens (an endpoint, a webhook, a CI job) has no ui.yaml and no catalog
141
- const ui = exists('ui.yaml') ? readGraphFile(read, 'ui.yaml') : { absent: true, id: flow.id, catalog: '', samples: {}, nodes: {} };
142
- if (!isMapValue(ui))
143
- throw new GraphError('ui.yaml is not a map of keys (SPEC.md §4)', { file: 'ui.yaml', path: [] });
144
- ui.nodes ??= {};
145
- ui.samples ??= {};
146
- const catalog = ui.absent === true ? {} : readCatalog(read, exists, ui);
147
- if (flow.states[flow.initial] === undefined)
148
- throw new GraphError(`initial state ${flow.initial} does not exist`, { file: 'flow.yaml', path: ['initial'] });
149
- for (const [name, st] of Object.entries(flow.states)) {
150
- if (!isMapValue(st))
151
- throw new GraphError(`state ${name} is not a map of keys: write it as ${name}: { .. } (SPEC.md §2)`, { file: 'flow.yaml', path: ['states', name] });
152
- if (st.states !== undefined || st.type === 'parallel' || st.type === 'history') {
153
- throw new GraphError(`state ${name}: nested, parallel and history states are not supported by graph-viz yet`, { file: 'flow.yaml', path: ['states', name, st.states !== undefined ? 'states' : 'type'] });
154
- }
155
- const ways = [
156
- ...(st.always ?? []).map((a, i) => [null, i, a]),
157
- ...Object.entries(st.on ?? {}).flatMap(([event, spec]) => alternatives(spec).map((a, i) => [event, i, a])),
158
- ];
159
- for (const [event, i, w] of ways) {
160
- const path = transitionPath(name, st, event, i);
161
- if (flow.states[w.target] === undefined)
162
- throw new GraphError(`state ${name} goes to ${w.target}, which does not exist`, { file: 'flow.yaml', path });
163
- if (w.starts === undefined)
164
- continue;
165
- if (typeof w.starts.flow !== 'string')
166
- throw new GraphError(`state ${name}: \`starts\` names no flow`, { file: 'flow.yaml', path: [...path, 'starts'] });
167
- for (const [k, v] of Object.entries(w.starts.given ?? {})) {
168
- if (typeof v !== 'string')
169
- continue;
170
- const at = { file: 'flow.yaml', path: [...path, 'starts', 'given', k] };
171
- let names;
172
- try {
173
- names = identifiers(parseExpr(v));
174
- }
175
- catch (err) {
176
- throw new GraphError(`state ${name} starts ${w.starts.flow} with ${k} = ${v}: ${err.message}`, at);
177
- }
178
- for (const id of names) {
179
- if (id !== 'state' && flow.context[id] === undefined && flow.guards[id] === undefined) {
180
- throw new GraphError(`state ${name} starts ${w.starts.flow} with ${k} = ${v}: ${id} is not a variable or a guard of this flow (a value is quoted: '${id}')`, at);
181
- }
182
- }
183
- }
184
- }
185
- }
186
- for (const [id, node] of Object.entries(ui.nodes)) {
187
- for (const key of ['in', 'unless', 'disabledIn']) {
188
- (node[key] ?? []).forEach((s, i) => {
189
- if (flow.states[s] === undefined)
190
- throw new GraphError(`ui node ${id} names the unknown state ${s}`, { file: 'ui.yaml', path: ['nodes', id, key, String(i)] });
191
- });
192
- }
193
- // `checked` is an expression over the context (SPEC.md §3), read when the node is shown
194
- if (typeof node.checked === 'string') {
195
- const at = { file: 'ui.yaml', path: ['nodes', id, 'checked'] };
196
- let names;
197
- try {
198
- names = identifiers(parseExpr(node.checked));
199
- }
200
- catch (err) {
201
- throw new GraphError(`ui node ${id}: checked: ${err.message}`, at);
202
- }
203
- for (const n of names) {
204
- if (n !== 'state' && flow.context[n] === undefined && flow.guards[n] === undefined) {
205
- throw new GraphError(`ui node ${id}: checked: ${node.checked} names ${n}, which is not a variable or a guard of the flow`, at);
206
- }
207
- }
208
- }
209
- }
210
- for (const s of Object.keys(ui.focus ?? {})) {
211
- if (flow.states[s] === undefined)
212
- throw new GraphError(`ui focus names the unknown state ${s}`, { file: 'ui.yaml', path: ['focus', s] });
213
- }
214
- disabledWhenReads(flow, ui);
215
- return { dir, flow, ui, catalog };
216
- }
217
- // a node's `disabledWhen` is an expression over the context (SPEC.md §3, §4), read where the node is shown: one that
218
- // does not parse, or names what is not a variable, a guard or `state`, keeps the graph from loading, as `checked` does
219
- function disabledWhenReads(flow, ui) {
220
- for (const [id, node] of Object.entries(ui.nodes)) {
221
- if (typeof node.disabledWhen !== 'string')
222
- continue;
223
- let names;
224
- try {
225
- names = identifiers(parseExpr(node.disabledWhen));
226
- }
227
- catch (err) {
228
- throw new GraphError(`ui node ${id}: disabledWhen: ${err.message}`);
229
- }
230
- for (const n of names) {
231
- if (n !== 'state' && flow.context[n] === undefined && flow.guards[n] === undefined) {
232
- throw new GraphError(`ui node ${id}: disabledWhen: ${node.disabledWhen} names ${n}, which is not a variable or a guard of the flow`);
233
- }
234
- }
235
- }
236
- }