@delurio/cli 0.5.2 → 0.6.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 +10 -0
- package/README.md +1 -1
- package/SPEC.md +6 -4
- package/dist/check.js +13 -2
- package/dist/domain.js +3 -28
- package/dist/graph.d.ts +1 -0
- package/dist/graph.js +3 -3
- package/dist/kit.js +2 -2
- package/dist/mermaid.js +7 -3
- package/dist/nav.js +3 -3
- package/dist/schemas.js +7 -3
- package/dist/starts.js +2 -2
- package/dist/yaml.d.ts +18 -0
- package/dist/yaml.js +103 -0
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
While the version is 0.x, a release that can judge the same graphs differently (a new check, a stricter schema) bumps the minor; a fix that judges nothing differently bumps the patch.
|
|
4
4
|
|
|
5
|
+
## 0.6.0 (2026-11-10)
|
|
6
|
+
|
|
7
|
+
- A graph file with an anchor (`&name`), an alias (`*name`), a tag (`!name`) or a key that is a list or a map cannot be loaded (SPEC.md §1): `check` gives `load` and `schema` errors at its line, "unsupported YAML", and exits 1; `page`, `diff` and the other commands stop the same way. The yaml library resolves these in time far beyond a file's size. On a 40 KB file, maps used as keys kept it busy for more than 30 seconds, and aliases of an anchor that holds only aliases of an empty list for more than two minutes. Its alias limit does not catch these cases. Every reader of a graph file now looks for them first, in one pass that resolves nothing: such a file is refused in under a second. A value is written where it is used, and a key is a string. Of the graphs of delurio, Medaris and QAuth, only QAuth's has them: seven flows use anchors for a `response` they repeat.
|
|
8
|
+
- `@delurio/cli/yaml` exports that reader, `readYaml`, and `unsupported`, which names the first such place. A server that reads graphs it was sent should read them with it.
|
|
9
|
+
- New rule of `check`, which fails `--strict`: `source-missing`, a state of a captured flow (`status: captured`) that names no code (SPEC.md §9). An exit may leave it out, as the transition into it names the code. Flows that are not captured are judged as before.
|
|
10
|
+
|
|
11
|
+
## 0.5.3 (2026-11-06)
|
|
12
|
+
|
|
13
|
+
- `page`: the `flow.mmd` it writes now reads whole in Mermaid. Mermaid ends a statement at a `;`, even inside a transition's label, so a label with one lost its rest: those words were drawn as stray states, or, when a `-` or `{` came after the `;`, the diagram did not render at all ("Parse error on line …", QAuth's sign-in in an editor's preview). A `;` in a label is now written as a comma. A transition never taken and with no label of its own now carries "(never taken)" as its label: before, those two words were drawn as two more states. Of the 106 flow diagrams of QAuth, Medaris and delurio, 86 were drawn wrong (36 did not render, 50 had stray states) and none is now, in Mermaid 10.9 and 12.3; their 5 navigation diagrams were right before and are unchanged. `index.html` draws its own diagram and was not affected. Nothing is judged differently.
|
|
14
|
+
|
|
5
15
|
## 0.5.2 (2026-11-03)
|
|
6
16
|
|
|
7
17
|
- `page`: the flow's diagram opens fitted to a box as wide as the window, and moves like a design tool's canvas: drag it to move (the hand), Ctrl or ⌘ with the wheel, or a pinch, to zoom at the pointer, and the wheel alone to move it until its edge, after which the page scrolls on. Buttons and keys: − and + (zoom), the zoom level (click: 100%, Shift+0), Fit (Shift+1), Full window (F; Esc leaves it); arrows move it. A click that does not drag still opens a step's screen. Before, a large flow was shrunk into the page's column (QAuth's consent flow to 7%) or scrolled sideways at full size. Without scripts the page keeps the old diagram. Nothing is judged differently.
|
package/README.md
CHANGED
|
@@ -112,7 +112,7 @@ const g = load('graphs/billing/billing.payment');
|
|
|
112
112
|
const configurations = explore(new Model(g.flow)).configs.length;
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
The entry points are `graph`, `model`, `story`, `wireframe`, `kit`, `edges`, `html`, `nav` and `
|
|
115
|
+
The entry points are `graph`, `model`, `story`, `wireframe`, `kit`, `edges`, `html`, `nav`, `expr` and `yaml`, each with its types. `yaml` reads a graph file's text as the CLI does (`readYaml`), refusing what SPEC.md §1 rules out before the text is resolved; a server that reads graphs it was sent should read them with it. While the version is 0.x their API may change in any minor release: pin an exact version.
|
|
116
116
|
|
|
117
117
|
## Licence
|
|
118
118
|
|
package/SPEC.md
CHANGED
|
@@ -30,6 +30,8 @@ id: learning.enrollment
|
|
|
30
30
|
|
|
31
31
|
A flow directory holds `flow.yaml`; a flow with screens also holds `ui.yaml` and the catalog that `ui.yaml` names. It may hold `domain.yaml`, `binding.yaml` and `tutorial.yaml`. A domain shared by several flows sits in its own directory and each flow names it by id (`domain: learning.api`). A directory holds one domain and a domain sits in one directory, in `domain.yaml` or split across several files (§5). A navigation graph is a directory with `nav.yaml` and its catalog.
|
|
32
32
|
|
|
33
|
+
A graph file is YAML 1.2 without anchors (`&name`), aliases (`*name`), tags (`!name`) or keys that are lists or maps: a value is written where it is used, and a key is a string. No graph needs them, and a YAML reader can take minutes over a small file that uses them, so a file with one cannot be loaded ("unsupported YAML", at its line). `@delurio/cli/yaml` reads a file this way.
|
|
34
|
+
|
|
33
35
|
A flow with no screen (an HTTP endpoint, a webhook, an MCP tool, a CI job) has no `ui.yaml`: it loads and is checked without one, and its page draws no screens. What such a step answers the outside world is written on its state as `response` (§2).
|
|
34
36
|
|
|
35
37
|
### Common keys
|
|
@@ -37,7 +39,7 @@ A flow with no screen (an HTTP endpoint, a webhook, an MCP tool, a CI job) has n
|
|
|
37
39
|
| Key | Meaning |
|
|
38
40
|
|---|---|
|
|
39
41
|
| `title`, `summary` | the graph in plain words, for people |
|
|
40
|
-
| `status` | `proposed`: written before or apart from the code, nobody has approved it. `captured`: read from existing code (capture mode, every element carries `source
|
|
42
|
+
| `status` | `proposed`: written before or apart from the code, nobody has approved it. `captured`: read from existing code (capture mode, every element carries `source:`, §9). `approved`: the owner reviewed and accepted it |
|
|
41
43
|
| `source` | on any element: `<repo-relative path>:<line>` or a bare `<path>`, the code that makes the element true. See §9 |
|
|
42
44
|
|
|
43
45
|
### Text
|
|
@@ -289,7 +291,7 @@ A kit says how the components of `ui.yaml` look in one product: `tokens` and `da
|
|
|
289
291
|
|
|
290
292
|
## 9. Source anchors
|
|
291
293
|
|
|
292
|
-
`source: <path>:<line>` on a state, a transition, a guard, a node, an entity or an action names the code that makes it true, relative to the application's repository root. A bare `<path>` anchors a whole file. In capture mode every element carries one; in create mode an element carries one when the code already exists.
|
|
294
|
+
`source: <path>:<line>` on a state, a transition, a guard, a node, an entity or an action names the code that makes it true, relative to the application's repository root. A bare `<path>` anchors a whole file. In capture mode every element carries one; in create mode an element carries one when the code already exists. `check` reports a state of a captured flow that names no code (`source-missing`). An exit may leave it out: the transition into it names the code, and an exit such as the person leaving the page has no code of its own.
|
|
293
295
|
|
|
294
296
|
`anchors.lock.yaml`, generated beside the graph, records what each anchor pointed at (the line, its neighbours' hashes, the commit). The check finds every line again and says whether it is unchanged, moved, changed, gone or ambiguous. A `file:line` in a description or a comment is not an anchor.
|
|
295
297
|
|
|
@@ -298,8 +300,8 @@ A kit says how the components of `ui.yaml` look in one product: `tokens` and `da
|
|
|
298
300
|
| Exit | Meaning |
|
|
299
301
|
|---|---|
|
|
300
302
|
| 0 | the graph loads and, under `--strict`, nothing is wrong |
|
|
301
|
-
| 1 | the graph cannot be loaded: a YAML error, an unknown state, an unknown name in an expression, a non-exhaustive `always`, an unsupported construct |
|
|
302
|
-
| 2 | under `--strict`: an assertion is violated, a catalog key or a sample value is missing, a component has no renderer, the kit does not cover a component, the main story cannot be walked,
|
|
303
|
+
| 1 | the graph cannot be loaded: a YAML error, unsupported YAML (§1), an unknown state, an unknown name in an expression, a non-exhaustive `always`, an unsupported construct |
|
|
304
|
+
| 2 | under `--strict`: an assertion is violated, a catalog key or a sample value is missing, a component has no renderer, the kit does not cover a component, the main story cannot be walked, a domain's files clash (§5), or a state of a captured flow names no code (§9) |
|
|
303
305
|
|
|
304
306
|
**As text.** A finding is one line in the GNU error format, which compilers, editors and most CI logs read:
|
|
305
307
|
|
package/dist/check.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { createHash } from 'node:crypto';
|
|
6
6
|
import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import { basename, dirname, join, relative, resolve } from 'node:path';
|
|
8
|
-
import {
|
|
8
|
+
import { keyAt, readYaml } from './yaml.js';
|
|
9
9
|
import { GraphError, load } from './graph.js';
|
|
10
10
|
import { checkAssertions, explore, Model, ModelError } from './model.js';
|
|
11
11
|
import { stepsByEvents } from './story.js';
|
|
@@ -39,6 +39,7 @@ const RULES = [
|
|
|
39
39
|
{ id: 'hand-over', text: 'A started flow cannot begin with what it is given', level: 'error' },
|
|
40
40
|
{ id: 'changes-note-missing', text: 'A flow whose steps write has no changes note (SPEC.md §4)', level: 'error' },
|
|
41
41
|
{ id: 'changes-note-locale', text: "The changes note is missing from a locale's catalog", level: 'error' },
|
|
42
|
+
{ id: 'source-missing', text: 'A state of a captured flow names no code (SPEC.md §9)', level: 'error' },
|
|
42
43
|
{ id: 'graph-warning', text: 'Another warning of the graph', level: 'error' },
|
|
43
44
|
{ id: 'nav-problem', text: 'A problem of the navigation graph', level: 'error' },
|
|
44
45
|
{ id: 'nav-note', text: 'A note on the navigation graph', level: 'warning' },
|
|
@@ -85,7 +86,7 @@ function graphFiles(root, out = []) {
|
|
|
85
86
|
}
|
|
86
87
|
// the format the file says it is written in: null when it is this one
|
|
87
88
|
function newerFormat(abs) {
|
|
88
|
-
const doc =
|
|
89
|
+
const doc = readYaml(readFileSync(abs, 'utf8'));
|
|
89
90
|
const s = typeof doc?.schema === 'string' ? doc.schema : FORMAT;
|
|
90
91
|
return s === FORMAT ? null : s;
|
|
91
92
|
}
|
|
@@ -152,6 +153,16 @@ function checkFlow(dir) {
|
|
|
152
153
|
warn(p);
|
|
153
154
|
for (const w of warnings)
|
|
154
155
|
out.push(fromWarning(dir, g.flow.id, w));
|
|
156
|
+
// a captured flow is read from code, so every state names the code that makes it true; an exit may leave it out, as
|
|
157
|
+
// the transition into it names that code (SPEC.md §9)
|
|
158
|
+
if (g.flow.status === 'captured') {
|
|
159
|
+
const text = readFileSync(file, 'utf8');
|
|
160
|
+
for (const [name, st] of Object.entries(g.flow.states)) {
|
|
161
|
+
if (st.source !== undefined || st.type === 'final')
|
|
162
|
+
continue;
|
|
163
|
+
out.push(result('source-missing', file, keyAt(text, ['states', name]), `state ${name} names no code: in a captured flow every state but an exit carries source: <path>:<line> (SPEC.md §9)`, g.flow.id, `states/${name}`));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
155
166
|
return out;
|
|
156
167
|
}
|
|
157
168
|
// the domains under root, each the domain files of one directory read as one (SPEC.md §5): a value given in two of
|
package/dist/domain.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// then the others by name. `schema`, `kind` and `id` open every file and the id is the same in all; maps merge key by
|
|
3
3
|
// key at any depth; the top-level lists `policies` and `invariants` join in that order; any other value (a string, a
|
|
4
4
|
// number, a list) is given in one file only. A split lets a generated part and a hand-written part sit side by side.
|
|
5
|
-
import {
|
|
5
|
+
import { keyAt, readYaml } from './yaml.js';
|
|
6
6
|
// the files whose name says another kind (SPEC.md §1); only the others are read to see whether they are a domain
|
|
7
7
|
export const OTHER_KINDS = new Set(['flow.yaml', 'ui.yaml', 'nav.yaml', 'nav.extracted.yaml', 'binding.yaml', 'tutorial.yaml', 'kit.yaml', 'anchors.lock.yaml']);
|
|
8
8
|
const OWN = new Set(['schema', 'kind', 'id']);
|
|
@@ -18,33 +18,8 @@ export function inReadingOrder(names) {
|
|
|
18
18
|
return [...names].sort((a, b) => (base(a) === 'domain.yaml' ? -1 : base(b) === 'domain.yaml' ? 1 : a < b ? -1 : a > b ? 1 : 0));
|
|
19
19
|
}
|
|
20
20
|
const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
21
|
-
const keyOf = (pair) => String(pair.key?.value ?? pair.key);
|
|
22
21
|
const pointer = (path) => path.map((s) => `/${s.replace(/~/g, '~0').replace(/\//g, '~1')}`).join('');
|
|
23
22
|
const nameOf = (file) => file.slice(file.lastIndexOf('/') + 1);
|
|
24
|
-
// the 1-based line and column of the key at `path` in a YAML text (of the item, for a list index), else the file's start
|
|
25
|
-
function placeOf(text, path) {
|
|
26
|
-
const lineCounter = new LineCounter();
|
|
27
|
-
const doc = parseDocument(text, { lineCounter, prettyErrors: false });
|
|
28
|
-
let node = doc.contents;
|
|
29
|
-
let at;
|
|
30
|
-
for (const step of path) {
|
|
31
|
-
if (isMap(node)) {
|
|
32
|
-
const pair = node.items.find((p) => keyOf(p) === step);
|
|
33
|
-
if (pair === undefined)
|
|
34
|
-
break;
|
|
35
|
-
at = pair.key?.range?.[0] ?? at;
|
|
36
|
-
node = pair.value;
|
|
37
|
-
}
|
|
38
|
-
else if (isSeq(node)) {
|
|
39
|
-
node = node.items[Number(step)];
|
|
40
|
-
at = node?.range?.[0] ?? at;
|
|
41
|
-
}
|
|
42
|
-
else
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
const { line, col } = lineCounter.linePos(at ?? 0);
|
|
46
|
-
return { line, column: col };
|
|
47
|
-
}
|
|
48
23
|
// the files of one directory, read as one domain; a file that is not YAML, or not a map, is left to its schema check
|
|
49
24
|
export function mergeDomain(parts) {
|
|
50
25
|
const doc = {};
|
|
@@ -53,7 +28,7 @@ export function mergeDomain(parts) {
|
|
|
53
28
|
const invariants = new Map();
|
|
54
29
|
let id = null;
|
|
55
30
|
let idFrom = -1;
|
|
56
|
-
const where = (i, path) => ({ file: parts[i].file, ...
|
|
31
|
+
const where = (i, path) => ({ file: parts[i].file, ...keyAt(parts[i].text, path) });
|
|
57
32
|
// the part that gave the value at `path`, or the map it sits in
|
|
58
33
|
const giver = (path) => {
|
|
59
34
|
for (let n = path.length; n > 0; n--) {
|
|
@@ -85,7 +60,7 @@ export function mergeDomain(parts) {
|
|
|
85
60
|
parts.forEach((part, i) => {
|
|
86
61
|
let data;
|
|
87
62
|
try {
|
|
88
|
-
data =
|
|
63
|
+
data = readYaml(part.text);
|
|
89
64
|
}
|
|
90
65
|
catch {
|
|
91
66
|
return;
|
package/dist/graph.d.ts
CHANGED
package/dist/graph.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { readYaml } from './yaml.js';
|
|
4
4
|
import { identifiers, parseExpr } from './expr.js';
|
|
5
5
|
export class GraphError extends Error {
|
|
6
6
|
}
|
|
@@ -18,13 +18,13 @@ export function alternatives(spec) {
|
|
|
18
18
|
}
|
|
19
19
|
// `read` and `exists` take a path relative to `dir`; the revision diff passes ones that read a git revision instead of the disk
|
|
20
20
|
export function load(dir, read = (file) => readFileSync(join(dir, file), 'utf8'), exists = (file) => existsSync(join(dir, file))) {
|
|
21
|
-
const flow =
|
|
21
|
+
const flow = readYaml(read('flow.yaml'));
|
|
22
22
|
// a flow with no context, guards or effects leaves the key out; every reader expects an object
|
|
23
23
|
flow.context ??= {};
|
|
24
24
|
flow.guards ??= {};
|
|
25
25
|
flow.effects ??= {};
|
|
26
26
|
// a flow with no screens (an endpoint, a webhook, a CI job) has no ui.yaml and no catalog
|
|
27
|
-
const ui = exists('ui.yaml') ?
|
|
27
|
+
const ui = exists('ui.yaml') ? readYaml(read('ui.yaml')) : { absent: true, id: flow.id, catalog: '', samples: {}, nodes: {} };
|
|
28
28
|
const catalog = ui.absent === true ? {} : JSON.parse(read(ui.catalog));
|
|
29
29
|
if (flow.states[flow.initial] === undefined)
|
|
30
30
|
throw new GraphError(`initial state ${flow.initial} does not exist`);
|
package/dist/kit.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// the kit loads.
|
|
5
5
|
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
6
6
|
import { dirname, join, resolve } from 'node:path';
|
|
7
|
-
import {
|
|
7
|
+
import { readYaml } from './yaml.js';
|
|
8
8
|
export class KitError extends Error {
|
|
9
9
|
}
|
|
10
10
|
const esc = (s) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
@@ -589,7 +589,7 @@ export function loadKit(path) {
|
|
|
589
589
|
if (!existsSync(file))
|
|
590
590
|
throw new KitError(`kit ${path} has no kit.yaml`);
|
|
591
591
|
const dir = dirname(file);
|
|
592
|
-
const raw =
|
|
592
|
+
const raw = readYaml(readFileSync(file, 'utf8'));
|
|
593
593
|
if (raw === null || typeof raw !== 'object')
|
|
594
594
|
throw new KitError(`${file}: empty`);
|
|
595
595
|
if (raw.kind !== 'kit')
|
package/dist/mermaid.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { collectEdges, exitLine, kindOf } from './edges.js';
|
|
2
2
|
import { titleOf } from './graph.js';
|
|
3
|
-
|
|
3
|
+
// Mermaid ends a statement at `;` even inside a transition's label: the rest of the label became stray states,
|
|
4
|
+
// or, with a `-` or `{` after it, a parse error. A label keeps its words with a comma in its place.
|
|
5
|
+
const clean = (s) => s.replace(/"/g, "'").replace(/:/g, ' -').replace(/;/g, ',');
|
|
4
6
|
// Mermaid's ids, which take no dot: an exit named `<error>.<cause>` is written `<error>__<cause>`
|
|
5
7
|
function mermaidIds(names) {
|
|
6
8
|
const ids = new Map();
|
|
@@ -30,8 +32,10 @@ export function renderMermaid(g, ex) {
|
|
|
30
32
|
}
|
|
31
33
|
lines.push(` [*] --> ${id(g.flow.initial)}`);
|
|
32
34
|
for (const e of collectEdges(g, ex)) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
// "never taken" belongs in the label: after an arrow with no `:` Mermaid read its words as two more states
|
|
36
|
+
const said = e.labels.map(clean).join(', ');
|
|
37
|
+
const label = e.unused ? `${said} (never taken)`.trim() : said;
|
|
38
|
+
lines.push(` ${id(e.from)} --> ${id(e.to)}${label === '' ? '' : `: ${label}`}`);
|
|
35
39
|
}
|
|
36
40
|
lines.push(' classDef server fill:#eeeeec,stroke:#6b6560,stroke-dasharray:4 3');
|
|
37
41
|
lines.push(' classDef screen fill:#ffffff,stroke:#1c1917,stroke-width:2px');
|
package/dist/nav.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { readYaml } from './yaml.js';
|
|
4
4
|
import { evaluate, identifiers, parseExpr } from './expr.js';
|
|
5
5
|
import { GraphError } from './graph.js';
|
|
6
6
|
const PAGE_KINDS = ['screen', 'placeholder', 'missing', 'redirect', 'external'];
|
|
@@ -32,8 +32,8 @@ function mergeDocs(base, hand) {
|
|
|
32
32
|
}
|
|
33
33
|
// `read` takes a path relative to `dir`; the revision diff passes one that reads a git revision instead of the disk
|
|
34
34
|
export function loadNav(dir, locale, read = (file) => readFileSync(join(dir, file), 'utf8')) {
|
|
35
|
-
const raw =
|
|
36
|
-
const doc = raw.extends === undefined ? raw : mergeDocs(
|
|
35
|
+
const raw = readYaml(read('nav.yaml'));
|
|
36
|
+
const doc = raw.extends === undefined ? raw : mergeDocs(readYaml(read(raw.extends)), raw);
|
|
37
37
|
const warnings = [];
|
|
38
38
|
if (doc.kind !== 'nav')
|
|
39
39
|
throw new GraphError(`${join(dir, 'nav.yaml')} is not a navigation graph (kind: nav is missing)`);
|
package/dist/schemas.js
CHANGED
|
@@ -7,7 +7,8 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
7
7
|
import { basename, dirname, join } from 'node:path';
|
|
8
8
|
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
9
9
|
import addFormatsModule from 'ajv-formats';
|
|
10
|
-
import { isMap, isSeq, LineCounter,
|
|
10
|
+
import { isMap, isSeq, LineCounter, parseDocument } from 'yaml';
|
|
11
|
+
import { readYaml, unsupported } from './yaml.js';
|
|
11
12
|
import { isDomainText, mayBeDomain } from './domain.js';
|
|
12
13
|
const FORMAT = 'delurio-graph/0';
|
|
13
14
|
const KINDS = ['flow', 'ui', 'domain', 'nav', 'catalog'];
|
|
@@ -182,7 +183,7 @@ function graphIdBeside(dir) {
|
|
|
182
183
|
if (!existsSync(file))
|
|
183
184
|
continue;
|
|
184
185
|
try {
|
|
185
|
-
const id =
|
|
186
|
+
const id = readYaml(readFileSync(file, 'utf8'))?.id;
|
|
186
187
|
if (typeof id === 'string')
|
|
187
188
|
return id;
|
|
188
189
|
}
|
|
@@ -199,6 +200,7 @@ export function validateFile(file) {
|
|
|
199
200
|
if (kind === null)
|
|
200
201
|
return [];
|
|
201
202
|
const text = readFileSync(file, 'utf8');
|
|
203
|
+
const refused = kind === 'catalog' ? null : unsupported(text);
|
|
202
204
|
const lineCounter = new LineCounter();
|
|
203
205
|
const doc = parseDocument(text, { lineCounter, prettyErrors: false });
|
|
204
206
|
const at = (offset) => {
|
|
@@ -211,7 +213,9 @@ export function validateFile(file) {
|
|
|
211
213
|
graph ??= graphIdBeside(kind === 'catalog' ? dirname(dirname(file)) : dirname(file));
|
|
212
214
|
return { ...where, message: said, graph, element: `${ownFile}#${pointer}` };
|
|
213
215
|
};
|
|
214
|
-
// the first YAML error only: the ones after it mostly follow from it
|
|
216
|
+
// the first YAML error only: the ones after it mostly follow from it; one before the unsupported place comes first
|
|
217
|
+
if (refused !== null && (doc.errors.length === 0 || refused.offset < doc.errors[0].pos[0]))
|
|
218
|
+
return [failure(refused, refused.message, '')];
|
|
215
219
|
if (doc.errors.length > 0)
|
|
216
220
|
return [failure(at(doc.errors[0].pos[0]), `not YAML: ${doc.errors[0].message.split('\n')[0]}`, '')];
|
|
217
221
|
let data;
|
package/dist/starts.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// transition is taken must give it a beginning it accepts; when it is not written yet, that is a note, not a failure.
|
|
4
4
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
5
5
|
import { basename, dirname, join } from 'node:path';
|
|
6
|
-
import {
|
|
6
|
+
import { readYaml } from './yaml.js';
|
|
7
7
|
import { alternatives } from './graph.js';
|
|
8
8
|
const SKIP = new Set(['viz', 'video', 'node_modules', '.git']);
|
|
9
9
|
// the root to search: the nearest folder called `graphs` above the graph, else the graph's parent
|
|
@@ -16,7 +16,7 @@ function rootOf(dir) {
|
|
|
16
16
|
function flowsUnder(root, depth = 4, out = new Map()) {
|
|
17
17
|
const file = join(root, 'flow.yaml');
|
|
18
18
|
if (existsSync(file)) {
|
|
19
|
-
const f =
|
|
19
|
+
const f = readYaml(readFileSync(file, 'utf8'));
|
|
20
20
|
if (typeof f?.id === 'string')
|
|
21
21
|
out.set(f.id, { ...f, context: f.context ?? {} });
|
|
22
22
|
}
|
package/dist/yaml.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ErrorCode } from 'yaml';
|
|
2
|
+
export interface Unsupported {
|
|
3
|
+
offset: number;
|
|
4
|
+
line: number;
|
|
5
|
+
column: number;
|
|
6
|
+
code: ErrorCode;
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function lineAndColumn(text: string, offset: number): {
|
|
10
|
+
line: number;
|
|
11
|
+
column: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function unsupported(text: string): Unsupported | null;
|
|
14
|
+
export declare function readYaml(text: string): unknown;
|
|
15
|
+
export declare function keyAt(text: string, path: string[]): {
|
|
16
|
+
line: number;
|
|
17
|
+
column: number;
|
|
18
|
+
};
|
package/dist/yaml.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// YAML as delurio reads it (SPEC.md §1): YAML 1.2 without anchors, aliases, tags, or keys that are lists or maps.
|
|
2
|
+
// No graph needs them, and two of them keep the yaml library busy far beyond a file's size: on a 40 KB file, maps
|
|
3
|
+
// used as keys, or aliases inside keys, held `parse` for more than 30 seconds, which stops a server that reads the
|
|
4
|
+
// file. So the text is first read into the library's concrete syntax tree, which resolves nothing and takes time in
|
|
5
|
+
// proportion to the text, and walked once; a file that holds one of them is refused at its place, as a file that is not
|
|
6
|
+
// YAML is. Every reader of a graph file goes through `readYaml`.
|
|
7
|
+
import { isMap, isSeq, LineCounter, parse, parseDocument, Parser, YAMLParseError } from 'yaml';
|
|
8
|
+
const WHY = 'delurio reads YAML without anchors, aliases, tags or keys that are lists or maps (SPEC.md §1)';
|
|
9
|
+
const PROPS = {
|
|
10
|
+
anchor: ['BAD_ALIAS', 'an anchor', 'write the value where it is used'],
|
|
11
|
+
alias: ['BAD_ALIAS', 'an alias', 'write the value where it is used'],
|
|
12
|
+
tag: ['TAG_RESOLVE_FAILED', 'a tag', 'write the value without it'],
|
|
13
|
+
};
|
|
14
|
+
const COLLECTIONS = new Set(['block-map', 'block-seq', 'flow-collection']);
|
|
15
|
+
// the 1-based line and column of an offset into the text
|
|
16
|
+
export function lineAndColumn(text, offset) {
|
|
17
|
+
let line = 1;
|
|
18
|
+
let from = 0;
|
|
19
|
+
for (let i = text.indexOf('\n'); i >= 0 && i < offset; i = text.indexOf('\n', i + 1)) {
|
|
20
|
+
line++;
|
|
21
|
+
from = i + 1;
|
|
22
|
+
}
|
|
23
|
+
return { line, column: offset - from + 1 };
|
|
24
|
+
}
|
|
25
|
+
// the first place in the text, by offset, that delurio does not read; null when there is none. A text that is not
|
|
26
|
+
// YAML at all is left to the parser, which says why.
|
|
27
|
+
export function unsupported(text) {
|
|
28
|
+
let first = null;
|
|
29
|
+
const found = (offset, code, what) => {
|
|
30
|
+
if (first === null || offset < first.offset)
|
|
31
|
+
first = { offset, code, what };
|
|
32
|
+
};
|
|
33
|
+
// walked with a stack of its own: a deeply nested text must not overflow the call stack here
|
|
34
|
+
const stack = [...new Parser().parse(text)];
|
|
35
|
+
while (stack.length > 0) {
|
|
36
|
+
const v = stack.pop();
|
|
37
|
+
if (Array.isArray(v)) {
|
|
38
|
+
for (const x of v)
|
|
39
|
+
if (x !== null && typeof x === 'object')
|
|
40
|
+
stack.push(x);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (v === null || typeof v !== 'object')
|
|
44
|
+
continue;
|
|
45
|
+
const t = v;
|
|
46
|
+
const offset = typeof t.offset === 'number' ? t.offset : 0;
|
|
47
|
+
const prop = typeof t.type === 'string' ? PROPS[t.type] : undefined;
|
|
48
|
+
if (prop !== undefined)
|
|
49
|
+
found(offset, prop[0], `${prop[1]} (${String(t.source)}): ${prop[2]}`);
|
|
50
|
+
const key = t.key;
|
|
51
|
+
if (key !== null && key !== undefined && typeof key.type === 'string' && COLLECTIONS.has(key.type)) {
|
|
52
|
+
const list = key.type === 'block-seq' || key.start?.source === '[';
|
|
53
|
+
found(typeof key.offset === 'number' ? key.offset : offset, 'NON_STRING_KEY', `a key that is a ${list ? 'list' : 'map'}: name it with a string`);
|
|
54
|
+
}
|
|
55
|
+
for (const x of Object.values(v))
|
|
56
|
+
if (x !== null && typeof x === 'object')
|
|
57
|
+
stack.push(x);
|
|
58
|
+
}
|
|
59
|
+
if (first === null)
|
|
60
|
+
return null;
|
|
61
|
+
const { offset, code, what } = first;
|
|
62
|
+
return { offset, ...lineAndColumn(text, offset), code, message: `unsupported YAML: ${what}; ${WHY}` };
|
|
63
|
+
}
|
|
64
|
+
// the refusal as the error the yaml library throws for a text that is not YAML, so that every reader that already
|
|
65
|
+
// says "cannot be loaded" for one says it for this too, at the same place
|
|
66
|
+
function refusal(u) {
|
|
67
|
+
const err = new YAMLParseError([u.offset, u.offset + 1], u.code, `${u.message} at line ${u.line}, column ${u.column}`);
|
|
68
|
+
err.linePos = [{ line: u.line, col: u.column }];
|
|
69
|
+
return err;
|
|
70
|
+
}
|
|
71
|
+
// the value of a graph file's text: the yaml library's `parse`, once nothing unsupported is found
|
|
72
|
+
export function readYaml(text) {
|
|
73
|
+
const u = unsupported(text);
|
|
74
|
+
if (u !== null)
|
|
75
|
+
throw refusal(u);
|
|
76
|
+
return parse(text);
|
|
77
|
+
}
|
|
78
|
+
// the 1-based line and column of the key at `path` in a YAML text (of the item, for a list index), else the file's
|
|
79
|
+
// start; for a text `readYaml` has read
|
|
80
|
+
export function keyAt(text, path) {
|
|
81
|
+
const lineCounter = new LineCounter();
|
|
82
|
+
const doc = parseDocument(text, { lineCounter, prettyErrors: false });
|
|
83
|
+
const keyOf = (pair) => String(pair.key?.value ?? pair.key);
|
|
84
|
+
let node = doc.contents;
|
|
85
|
+
let at;
|
|
86
|
+
for (const step of path) {
|
|
87
|
+
if (isMap(node)) {
|
|
88
|
+
const pair = node.items.find((p) => keyOf(p) === step);
|
|
89
|
+
if (pair === undefined)
|
|
90
|
+
break;
|
|
91
|
+
at = pair.key?.range?.[0] ?? at;
|
|
92
|
+
node = pair.value;
|
|
93
|
+
}
|
|
94
|
+
else if (isSeq(node)) {
|
|
95
|
+
node = node.items[Number(step)];
|
|
96
|
+
at = node?.range?.[0] ?? at;
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
const { line, col } = lineCounter.linePos(at ?? 0);
|
|
102
|
+
return { line, column: col };
|
|
103
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delurio/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "The open checker and page of delurio-graph/0: check every graph in a project's own CI, offline, with GNU error lines and SARIF.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"./html": { "types": "./dist/html.d.ts", "default": "./dist/html.js" },
|
|
16
16
|
"./nav": { "types": "./dist/nav.d.ts", "default": "./dist/nav.js" },
|
|
17
17
|
"./expr": { "types": "./dist/expr.d.ts", "default": "./dist/expr.js" },
|
|
18
|
+
"./yaml": { "types": "./dist/yaml.d.ts", "default": "./dist/yaml.js" },
|
|
18
19
|
"./package.json": "./package.json"
|
|
19
20
|
},
|
|
20
21
|
"files": ["dist", "schemas", "SPEC.md", "NOTICE", "CHANGELOG.md"],
|