@delurio/cli 0.8.0 → 0.10.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 +51 -0
- package/README.md +37 -6
- package/SPEC.md +203 -34
- package/dist/anchors.d.ts +29 -0
- package/dist/anchors.js +160 -0
- package/dist/changes.d.ts +4 -2
- package/dist/changes.js +32 -10
- package/dist/check.d.ts +1 -1
- package/dist/check.js +288 -32
- package/dist/diff-nav.js +15 -5
- package/dist/domain-names.d.ts +18 -0
- package/dist/domain-names.js +124 -0
- package/dist/domain.js +1 -1
- package/dist/graph.d.ts +21 -2
- package/dist/graph.js +149 -30
- package/dist/html.d.ts +1 -1
- package/dist/html.js +1 -1
- package/dist/invokes.d.ts +10 -0
- package/dist/invokes.js +67 -0
- package/dist/kit.d.ts +2 -1
- package/dist/kit.js +3 -2
- package/dist/model.d.ts +9 -1
- package/dist/model.js +89 -33
- package/dist/nav-page.js +15 -3
- package/dist/nav.d.ts +20 -1
- package/dist/nav.js +37 -25
- package/dist/needs.d.ts +51 -0
- package/dist/needs.js +335 -0
- package/dist/schemas.d.ts +6 -1
- package/dist/schemas.js +54 -2
- package/dist/starts.js +8 -1
- package/dist/tutorial-check.d.ts +9 -0
- package/dist/tutorial-check.js +297 -0
- package/dist/ui-check.d.ts +1 -1
- package/dist/ui-check.js +64 -13
- package/dist/wireframe.d.ts +2 -0
- package/dist/wireframe.js +31 -4
- package/dist/yaml.d.ts +1 -0
- package/dist/yaml.js +36 -5
- package/package.json +5 -4
- package/schemas/domain.schema.json +10 -7
- package/schemas/gaps.schema.json +49 -0
- package/schemas/nav.schema.json +34 -3
- package/schemas/needs.schema.json +189 -0
- package/schemas/ui.schema.json +42 -9
package/dist/needs.js
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
// A flow's needs and a product's gaps (SPEC.md §13). needs.yaml, beside a flow, is a closed list of what must exist for
|
|
2
|
+
// the flow's users: each need names the evidence that it does, or says `missing` and why. needs.gaps.yaml, at the root
|
|
3
|
+
// of a product's graphs, lists every need of its flows that is missing. `checkNeeds` holds each piece of evidence to
|
|
4
|
+
// what it names, each missing need to the gaps file above it, and each entry of a gaps file to a need under its folder
|
|
5
|
+
// that is still missing, so the list only shrinks on its own. `planned` gives a tool that walks a flow on the app the
|
|
6
|
+
// states and nodes that only missing needs are drawn as, for it to leave out.
|
|
7
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
8
|
+
import { basename, dirname, isAbsolute, join } from 'node:path';
|
|
9
|
+
import { keyAt, readYaml } from './yaml.js';
|
|
10
|
+
import { AppFiles } from './anchors.js';
|
|
11
|
+
export const NEEDS_FILE = 'needs.yaml';
|
|
12
|
+
export const GAPS_FILE = 'needs.gaps.yaml';
|
|
13
|
+
const FORMAT = 'delurio-graph/0';
|
|
14
|
+
const KINDS = ['source', 'test', 'scenario', 'state', 'node', 'setting'];
|
|
15
|
+
// what the graph draws: it shows where a need is, and alone meets nothing
|
|
16
|
+
const IN_GRAPH = new Set(['state', 'node']);
|
|
17
|
+
const isMap = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
18
|
+
const text = (v) => (typeof v === 'string' && v.trim() !== '' ? v : null);
|
|
19
|
+
const kindOf = (e) => KINDS.find((k) => typeof e[k] === 'string');
|
|
20
|
+
const isMissing = (n) => text(n.missing) !== null;
|
|
21
|
+
// the value of a graph file, or null when it cannot be read: the schema rule says why
|
|
22
|
+
function readDoc(file) {
|
|
23
|
+
try {
|
|
24
|
+
const raw = readFileSync(file, 'utf8');
|
|
25
|
+
const doc = readYaml(raw);
|
|
26
|
+
if (!isMap(doc))
|
|
27
|
+
return null;
|
|
28
|
+
if (typeof doc.schema === 'string' && doc.schema !== FORMAT)
|
|
29
|
+
return null;
|
|
30
|
+
return { text: raw, doc };
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// the needs.yaml beside a flow, read; null when there is none
|
|
37
|
+
export function readNeeds(dir) {
|
|
38
|
+
const file = join(dir, NEEDS_FILE);
|
|
39
|
+
if (!existsSync(file))
|
|
40
|
+
return null;
|
|
41
|
+
const doc = readYaml(readFileSync(file, 'utf8'));
|
|
42
|
+
return isMap(doc) && Array.isArray(doc.needs) ? doc : null;
|
|
43
|
+
}
|
|
44
|
+
// what a tool that walks the flow on the app leaves out (SPEC.md §13): the states and the nodes that missing needs are
|
|
45
|
+
// drawn as and that no met need names, each with the ids of those needs
|
|
46
|
+
export function planned(needs) {
|
|
47
|
+
const out = { states: new Map(), nodes: new Map() };
|
|
48
|
+
const built = { states: new Set(), nodes: new Set() };
|
|
49
|
+
for (const n of (needs?.needs ?? [])) {
|
|
50
|
+
if (!isMap(n) || typeof n.id !== 'string')
|
|
51
|
+
continue;
|
|
52
|
+
for (const e of Array.isArray(n.evidence) ? n.evidence : []) {
|
|
53
|
+
if (!isMap(e))
|
|
54
|
+
continue;
|
|
55
|
+
for (const [key, into] of [['state', 'states'], ['node', 'nodes']]) {
|
|
56
|
+
const name = e[key];
|
|
57
|
+
if (typeof name !== 'string')
|
|
58
|
+
continue;
|
|
59
|
+
if (!isMissing(n))
|
|
60
|
+
built[into].add(name);
|
|
61
|
+
else
|
|
62
|
+
out[into].set(name, [...(out[into].get(name) ?? []), n.id]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (const into of ['states', 'nodes'])
|
|
67
|
+
for (const name of built[into])
|
|
68
|
+
out[into].delete(name);
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
// the nearest gaps file at or above a folder, up to the repository's root (the first folder that holds .git)
|
|
72
|
+
function nearestGaps(dir) {
|
|
73
|
+
for (let d = dir;; d = dirname(d)) {
|
|
74
|
+
if (existsSync(join(d, GAPS_FILE)))
|
|
75
|
+
return join(d, GAPS_FILE);
|
|
76
|
+
if (existsSync(join(d, '.git')) || dirname(d) === d)
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
81
|
+
// the text holds the name, not as a part of a longer word: an identifier, or a test's name in quotes
|
|
82
|
+
const holds = (body, name) => new RegExp(`(?<![\\w$])${escapeRe(name)}(?![\\w$])`).test(body);
|
|
83
|
+
// a line of the file sets the variable and is not commented out: NAME=, export NAME=, NAME: or - NAME=
|
|
84
|
+
const sets = (body, name) => new RegExp(`^[ \\t]*(?:-[ \\t]*)?(?:export[ \\t]+)?${escapeRe(name)}[ \\t]*[=:]`, 'm').test(body);
|
|
85
|
+
const fileAt = (ctx, path) => {
|
|
86
|
+
const abs = isAbsolute(path) ? path : join(ctx.app, path);
|
|
87
|
+
return existsSync(abs) && statSync(abs).isFile() ? abs : null;
|
|
88
|
+
};
|
|
89
|
+
// a binding's scenarios, those of the bindings it extends included (each named relative to the one that extends it)
|
|
90
|
+
function scenariosOf(file, seen = new Set()) {
|
|
91
|
+
const out = new Set();
|
|
92
|
+
if (seen.has(file) || !existsSync(file))
|
|
93
|
+
return out;
|
|
94
|
+
seen.add(file);
|
|
95
|
+
const read = readDoc(file);
|
|
96
|
+
if (read === null)
|
|
97
|
+
return out;
|
|
98
|
+
if (isMap(read.doc.scenarios))
|
|
99
|
+
for (const s of Object.keys(read.doc.scenarios))
|
|
100
|
+
out.add(s);
|
|
101
|
+
if (typeof read.doc.extends === 'string')
|
|
102
|
+
for (const s of scenariosOf(join(dirname(file), read.doc.extends), seen))
|
|
103
|
+
out.add(s);
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
// whether a piece of evidence names a file of the application by its path from the repository's root: a source, a test,
|
|
107
|
+
// the file a setting is set in, a binding named by its path (SPEC.md §13)
|
|
108
|
+
const namesAppFile = (kind, e) => kind === 'source' || kind === 'test' || kind === 'setting' || (kind === 'scenario' && text(e.binding) !== null);
|
|
109
|
+
// why a piece of evidence does not resolve, or null when it does (or when what it names cannot be read, which is
|
|
110
|
+
// reported where it is)
|
|
111
|
+
function unresolved(ctx, kind, e) {
|
|
112
|
+
const value = e[kind];
|
|
113
|
+
const name = text(e.name);
|
|
114
|
+
switch (kind) {
|
|
115
|
+
case 'source': {
|
|
116
|
+
const why = ctx.code.unresolved(value);
|
|
117
|
+
if (why !== null)
|
|
118
|
+
return `source ${why.subject} ${why.reason}`;
|
|
119
|
+
const path = /^(.*?)(?::\d+)?$/.exec(value)[1];
|
|
120
|
+
return name !== null && !holds(readFileSync(ctx.code.abs(path), 'utf8'), name) ? `source ${path} holds no ${name}` : null;
|
|
121
|
+
}
|
|
122
|
+
case 'test': {
|
|
123
|
+
const abs = fileAt(ctx, value);
|
|
124
|
+
if (abs === null)
|
|
125
|
+
return `test ${value} does not exist`;
|
|
126
|
+
return name !== null && !holds(readFileSync(abs, 'utf8'), name) ? `test ${value} holds no test named "${name}"` : null;
|
|
127
|
+
}
|
|
128
|
+
case 'scenario': {
|
|
129
|
+
const given = text(e.binding);
|
|
130
|
+
const abs = given === null ? join(ctx.dir, 'binding.yaml') : fileAt(ctx, given);
|
|
131
|
+
const said = given === null ? "the flow's own binding.yaml" : `the binding ${given}`;
|
|
132
|
+
if (abs === null || !existsSync(abs))
|
|
133
|
+
return `scenario ${value}: ${said} does not exist`;
|
|
134
|
+
const read = readDoc(abs);
|
|
135
|
+
if (read === null)
|
|
136
|
+
return `scenario ${value}: ${said} cannot be read`;
|
|
137
|
+
if (read.doc.kind !== 'binding')
|
|
138
|
+
return `scenario ${value}: ${said} is not a binding (kind: binding)`;
|
|
139
|
+
if (ctx.flowId !== null && read.doc.flow !== ctx.flowId)
|
|
140
|
+
return `scenario ${value}: ${said} binds ${String(read.doc.flow ?? 'no flow')}, not ${ctx.flowId}`;
|
|
141
|
+
const scenarios = scenariosOf(abs);
|
|
142
|
+
return scenarios.has(value) ? null : `scenario ${value} is not a scenario of ${said}${scenarios.size > 0 ? ` (it has ${[...scenarios].sort().join(', ')})` : ''}`;
|
|
143
|
+
}
|
|
144
|
+
case 'state':
|
|
145
|
+
return ctx.states === null || ctx.states.has(value) ? null : `state ${value} is not a state of ${ctx.flowId ?? 'the flow'}`;
|
|
146
|
+
case 'node':
|
|
147
|
+
if (ctx.nodes === 'none')
|
|
148
|
+
return `node ${value}: the flow has no screens, as there is no ui.yaml beside it`;
|
|
149
|
+
return ctx.nodes === null || ctx.nodes.has(value) ? null : `node ${value} is not a node of the flow's ui.yaml`;
|
|
150
|
+
case 'setting': {
|
|
151
|
+
const where = text(e.in);
|
|
152
|
+
if (where === null)
|
|
153
|
+
return null; // the schema says it is missing
|
|
154
|
+
const abs = fileAt(ctx, where);
|
|
155
|
+
if (abs === null)
|
|
156
|
+
return `setting ${value}: ${where} does not exist`;
|
|
157
|
+
return sets(readFileSync(abs, 'utf8'), value) ? null : `setting ${value} is not set in ${where}: no line sets it, or the one that does is commented out`;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// the states of a captured flow that name their code (SPEC.md §9), which are therefore built, each with its anchor
|
|
162
|
+
function builtStates(flow) {
|
|
163
|
+
const out = new Map();
|
|
164
|
+
if (flow?.status !== 'captured' || !isMap(flow.states))
|
|
165
|
+
return out;
|
|
166
|
+
for (const [name, st] of Object.entries(flow.states))
|
|
167
|
+
if (isMap(st) && typeof st.source === 'string')
|
|
168
|
+
out.set(name, st.source);
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
// the nodes of a ui.yaml, or null when it cannot be read
|
|
172
|
+
function nodesOf(file) {
|
|
173
|
+
const read = readDoc(file);
|
|
174
|
+
return read === null ? null : new Set(isMap(read.doc.nodes) ? Object.keys(read.doc.nodes) : []);
|
|
175
|
+
}
|
|
176
|
+
// a gaps file, read once per run; null when it cannot be read (the schema rule says why)
|
|
177
|
+
function gapsReader() {
|
|
178
|
+
const seen = new Map();
|
|
179
|
+
return (file) => {
|
|
180
|
+
if (!seen.has(file)) {
|
|
181
|
+
const read = readDoc(file);
|
|
182
|
+
const gaps = new Map();
|
|
183
|
+
if (read !== null && isMap(read.doc.gaps)) {
|
|
184
|
+
for (const [flow, ids] of Object.entries(read.doc.gaps))
|
|
185
|
+
gaps.set(flow, Array.isArray(ids) ? ids.filter((x) => typeof x === 'string') : []);
|
|
186
|
+
}
|
|
187
|
+
seen.set(file, read === null ? null : { id: typeof read.doc.id === 'string' ? read.doc.id : basename(dirname(file)), gaps, text: read.text });
|
|
188
|
+
}
|
|
189
|
+
return seen.get(file) ?? null;
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
// every needs file and gaps file among `files` (the graph files under the folders checked), with the application's
|
|
193
|
+
// repository root that evidence paths are relative to; with `app` null (--no-app), evidence that names a file of the
|
|
194
|
+
// application is counted and not looked for, and the rest is held as before
|
|
195
|
+
export function checkNeeds(files, app) {
|
|
196
|
+
const out = { problems: [], files: 0, needs: 0, gaps: 0, notLookedFor: 0 };
|
|
197
|
+
const gapsOf = gapsReader();
|
|
198
|
+
const code = new AppFiles(app ?? '.');
|
|
199
|
+
// each needs file's flow and the state of each of its needs, by the gaps file that covers it; null for a needs file
|
|
200
|
+
// that cannot be read, whose entries are then not judged
|
|
201
|
+
const covered = new Map();
|
|
202
|
+
const cover = (gapsFile, flow, states) => {
|
|
203
|
+
if (gapsFile === null)
|
|
204
|
+
return;
|
|
205
|
+
const byFlow = covered.get(gapsFile) ?? new Map();
|
|
206
|
+
byFlow.set(flow, states);
|
|
207
|
+
covered.set(gapsFile, byFlow);
|
|
208
|
+
};
|
|
209
|
+
const problem = (rule, file, body, path, message, graph, element) => {
|
|
210
|
+
out.problems.push({ rule, file, ...keyAt(body, path), message, graph, element });
|
|
211
|
+
};
|
|
212
|
+
for (const file of files.filter((f) => basename(f) === NEEDS_FILE)) {
|
|
213
|
+
const read = readDoc(file);
|
|
214
|
+
if (read === null || !Array.isArray(read.doc.needs)) {
|
|
215
|
+
const beside = readDoc(join(dirname(file), 'flow.yaml'))?.doc.id;
|
|
216
|
+
if (typeof beside === 'string')
|
|
217
|
+
cover(nearestGaps(dirname(file)), beside, null);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
out.files++;
|
|
221
|
+
const { doc, text: body } = read;
|
|
222
|
+
const dir = dirname(file);
|
|
223
|
+
const flowFile = join(dir, 'flow.yaml');
|
|
224
|
+
const flow = existsSync(flowFile) ? readDoc(flowFile) : null;
|
|
225
|
+
const flowId = typeof flow?.doc.id === 'string' ? flow.doc.id : null;
|
|
226
|
+
const ownId = typeof doc.id === 'string' ? doc.id : null;
|
|
227
|
+
const graph = flowId ?? ownId ?? basename(dir);
|
|
228
|
+
if (!existsSync(flowFile)) {
|
|
229
|
+
problem('needs-place', file, body, ['id'], `needs.yaml is beside no flow: it sits in a flow's folder, beside its flow.yaml, and lists that flow's needs (SPEC.md §13)`, graph, 'needs');
|
|
230
|
+
}
|
|
231
|
+
else if (flowId !== null && ownId !== null && ownId !== flowId) {
|
|
232
|
+
problem('needs-place', file, body, ['id'], `needs.yaml is the needs of ${ownId}, and the flow beside it is ${flowId}: its id is the id of the flow beside it (SPEC.md §13)`, graph, 'needs/id');
|
|
233
|
+
}
|
|
234
|
+
const uiFile = join(dir, 'ui.yaml');
|
|
235
|
+
const ctx = {
|
|
236
|
+
app: app ?? '.',
|
|
237
|
+
code,
|
|
238
|
+
lookFor: app !== null,
|
|
239
|
+
dir,
|
|
240
|
+
flowId,
|
|
241
|
+
states: flow === null ? null : new Set(isMap(flow.doc.states) ? Object.keys(flow.doc.states) : []),
|
|
242
|
+
built: builtStates(flow?.doc ?? null),
|
|
243
|
+
nodes: !existsSync(flowFile) ? null : existsSync(uiFile) ? nodesOf(uiFile) : 'none',
|
|
244
|
+
};
|
|
245
|
+
const key = flowId ?? ownId ?? graph; // the flow, as the gaps name it
|
|
246
|
+
const gapsFile = nearestGaps(dir);
|
|
247
|
+
const listed = gapsFile === null ? null : gapsOf(gapsFile);
|
|
248
|
+
const states = new Map();
|
|
249
|
+
const firstAt = new Map();
|
|
250
|
+
read.doc.needs.forEach((item, i) => {
|
|
251
|
+
if (!isMap(item) || typeof item.id !== 'string')
|
|
252
|
+
return;
|
|
253
|
+
const id = item.id;
|
|
254
|
+
out.needs++;
|
|
255
|
+
const at = ['needs', String(i)];
|
|
256
|
+
const first = firstAt.get(id);
|
|
257
|
+
if (first !== undefined) {
|
|
258
|
+
problem('need-twice', file, body, [...at, 'id'], `need ${id} is given twice: it is given first at line ${keyAt(body, ['needs', String(first), 'id']).line}, and a need's id comes once in its flow (SPEC.md §13)`, graph, `needs/${id}/twice`);
|
|
259
|
+
}
|
|
260
|
+
else
|
|
261
|
+
firstAt.set(id, i);
|
|
262
|
+
const evidence = Array.isArray(item.evidence) ? item.evidence : [];
|
|
263
|
+
let outside = false;
|
|
264
|
+
let kinds = 0;
|
|
265
|
+
evidence.forEach((e, j) => {
|
|
266
|
+
if (!isMap(e))
|
|
267
|
+
return;
|
|
268
|
+
const kind = kindOf(e);
|
|
269
|
+
if (kind === undefined)
|
|
270
|
+
return; // the schema says it names no kind
|
|
271
|
+
kinds++;
|
|
272
|
+
if (!IN_GRAPH.has(kind))
|
|
273
|
+
outside = true;
|
|
274
|
+
if (!ctx.lookFor && namesAppFile(kind, e)) {
|
|
275
|
+
out.notLookedFor++;
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const why = unresolved(ctx, kind, e);
|
|
279
|
+
if (why !== null)
|
|
280
|
+
problem('evidence-unresolved', file, body, [...at, 'evidence', String(j), kind], `need ${id}: ${why} (SPEC.md §13)`, graph, `needs/${id}/evidence/${kind}:${String(e[kind])}`);
|
|
281
|
+
// a missing need names only what is not built: a walk leaves out a state that only missing needs name
|
|
282
|
+
const built = kind === 'state' && isMissing(item) ? ctx.built.get(e.state) : undefined;
|
|
283
|
+
if (built !== undefined) {
|
|
284
|
+
problem('need-names-built', file, body, [...at, 'evidence', String(j), kind], `need ${id} is missing, and names state ${String(e.state)}, which is built: it names its code (source: ${built}). A walk on the app leaves out a state that only missing needs name, so a missing need names only what is not built yet; say in its note that it is about ${String(e.state)} (SPEC.md §13)`, graph, `needs/${id}/built/state:${String(e.state)}`);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
const missing = isMissing(item);
|
|
288
|
+
const state = missing ? 'missing' : outside ? 'met' : 'unproven';
|
|
289
|
+
if (first === undefined)
|
|
290
|
+
states.set(id, state);
|
|
291
|
+
if (state === 'unproven' && kinds > 0 && kinds === evidence.length) {
|
|
292
|
+
problem('need-no-evidence', file, body, [...at, 'evidence'], `need ${id} is not missing and names no evidence outside the graph: what it is drawn as shows nothing built; name a source, a test, a scenario or a setting, or say why it is missing (SPEC.md §13)`, graph, `needs/${id}`);
|
|
293
|
+
}
|
|
294
|
+
if (!missing)
|
|
295
|
+
return;
|
|
296
|
+
out.gaps++;
|
|
297
|
+
const why = text(item.missing);
|
|
298
|
+
if (listed === null) {
|
|
299
|
+
problem('need-unlisted', file, body, [...at, 'missing'], `need ${id} is missing, and there is no ${GAPS_FILE} above it: list it in the product's gaps, at the root of its graphs (SPEC.md §13)`, graph, `needs/${id}`);
|
|
300
|
+
}
|
|
301
|
+
else if (!(listed.gaps.get(key) ?? []).includes(id)) {
|
|
302
|
+
problem('need-unlisted', file, body, [...at, 'missing'], `need ${id} is missing, and ${GAPS_FILE} does not list it under ${key}: list it there, or name its evidence and take out missing (SPEC.md §13)`, graph, `needs/${id}`);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
problem('need-gap', file, body, [...at, 'missing'], `need ${id} is missing: ${why}`, graph, `needs/${id}`);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
cover(gapsFile, key, states);
|
|
309
|
+
}
|
|
310
|
+
// each gaps file among the files checked, held to the needs under its folder that it covers
|
|
311
|
+
for (const file of files.filter((f) => basename(f) === GAPS_FILE)) {
|
|
312
|
+
const listed = gapsOf(file);
|
|
313
|
+
if (listed === null)
|
|
314
|
+
continue;
|
|
315
|
+
const byFlow = covered.get(file) ?? new Map();
|
|
316
|
+
for (const [flow, ids] of listed.gaps) {
|
|
317
|
+
const states = byFlow.get(flow);
|
|
318
|
+
if (states === null)
|
|
319
|
+
continue;
|
|
320
|
+
if (states === undefined) {
|
|
321
|
+
problem('gap-unknown', file, listed.text, ['gaps', flow], `${GAPS_FILE} lists gaps of ${flow}, which is no flow with a needs.yaml under its folder: take them out, or name the flow by its id (SPEC.md §13)`, listed.id, `gaps/${flow}`);
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
ids.forEach((id, k) => {
|
|
325
|
+
const state = states.get(id);
|
|
326
|
+
const at = ['gaps', flow, String(k)];
|
|
327
|
+
if (state === undefined)
|
|
328
|
+
problem('gap-unknown', file, listed.text, at, `${GAPS_FILE} lists ${id} of ${flow}, which is no need of its needs.yaml: take it out, or name the need by its id (SPEC.md §13)`, listed.id, `gaps/${flow}/${id}`);
|
|
329
|
+
else if (state === 'met')
|
|
330
|
+
problem('gap-met', file, listed.text, at, `${GAPS_FILE} lists ${id} of ${flow}, which is met now: take it out, as the list only shrinks (SPEC.md §13)`, listed.id, `gaps/${flow}/${id}`);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return out;
|
|
335
|
+
}
|
package/dist/schemas.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type SchemaKind = 'flow' | 'ui' | 'domain' | 'nav' | 'catalog';
|
|
1
|
+
export type SchemaKind = 'flow' | 'ui' | 'domain' | 'nav' | 'catalog' | 'needs' | 'gaps';
|
|
2
2
|
export interface SchemaFinding {
|
|
3
3
|
line: number;
|
|
4
4
|
column: number;
|
|
@@ -7,4 +7,9 @@ export interface SchemaFinding {
|
|
|
7
7
|
element: string;
|
|
8
8
|
}
|
|
9
9
|
export declare function schemaKindOf(file: string): SchemaKind | null;
|
|
10
|
+
export interface AnchorPlace {
|
|
11
|
+
path: string[];
|
|
12
|
+
value: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function anchorsIn(kind: SchemaKind, data: unknown): AnchorPlace[];
|
|
10
15
|
export declare function validateFile(file: string): SchemaFinding[];
|
package/dist/schemas.js
CHANGED
|
@@ -11,15 +11,17 @@ import { isMap, isSeq, LineCounter, parseDocument } from 'yaml';
|
|
|
11
11
|
import { readYaml, unsupported } from './yaml.js';
|
|
12
12
|
import { isDomainText, mayBeDomain } from './domain.js';
|
|
13
13
|
const FORMAT = 'delurio-graph/0';
|
|
14
|
-
const KINDS = ['flow', 'ui', 'domain', 'nav', 'catalog'];
|
|
14
|
+
const KINDS = ['flow', 'ui', 'domain', 'nav', 'catalog', 'needs', 'gaps'];
|
|
15
15
|
// the kind of graph file, by its name, and a domain also by its `kind` (a domain may be split across files, SPEC.md
|
|
16
16
|
// §5): null for a file no schema covers (binding, tutorial, kit, anchors.lock)
|
|
17
17
|
export function schemaKindOf(file) {
|
|
18
18
|
const name = basename(file);
|
|
19
|
-
if (name === 'flow.yaml' || name === 'ui.yaml' || name === 'domain.yaml')
|
|
19
|
+
if (name === 'flow.yaml' || name === 'ui.yaml' || name === 'domain.yaml' || name === 'needs.yaml')
|
|
20
20
|
return name.slice(0, -'.yaml'.length);
|
|
21
21
|
if (name === 'nav.yaml' || name === 'nav.extracted.yaml')
|
|
22
22
|
return 'nav';
|
|
23
|
+
if (name === 'needs.gaps.yaml')
|
|
24
|
+
return 'gaps';
|
|
23
25
|
if (name.endsWith('.json') && basename(dirname(file)) === 'catalog')
|
|
24
26
|
return 'catalog';
|
|
25
27
|
if (mayBeDomain(name) && existsSync(file) && isDomainText(readFileSync(file, 'utf8')))
|
|
@@ -71,6 +73,56 @@ function chain(root, schema) {
|
|
|
71
73
|
}
|
|
72
74
|
return out;
|
|
73
75
|
}
|
|
76
|
+
const ANCHOR = '#/$defs/sourceAnchor';
|
|
77
|
+
const patterns = new Map();
|
|
78
|
+
const matches = (pattern, name) => {
|
|
79
|
+
let re = patterns.get(pattern);
|
|
80
|
+
if (re === undefined)
|
|
81
|
+
patterns.set(pattern, (re = new RegExp(pattern, 'u')));
|
|
82
|
+
return re.test(name);
|
|
83
|
+
};
|
|
84
|
+
const refAt = (root, ref) => ref.slice(2).split('/').reduce((x, k) => x?.[k], root);
|
|
85
|
+
// every source anchor in a graph file's value (SPEC.md §9): each `source` whose schema is the kind's `sourceAnchor`,
|
|
86
|
+
// found by walking the value along its schema, so a key `source` that the schema gives another meaning (a nav graph's
|
|
87
|
+
// `source`, a sample value or a parameter of ui.yaml, a field of a record) is none. Where the schema has alternatives,
|
|
88
|
+
// every one that the value's shape reaches is walked.
|
|
89
|
+
export function anchorsIn(kind, data) {
|
|
90
|
+
const root = schemas().roots[kind];
|
|
91
|
+
const out = new Map();
|
|
92
|
+
const visit = (schema, value, path, seen) => {
|
|
93
|
+
if (schema === null || typeof schema !== 'object' || seen.has(schema))
|
|
94
|
+
return;
|
|
95
|
+
seen.add(schema);
|
|
96
|
+
const s = schema;
|
|
97
|
+
if (s.$ref === ANCHOR) {
|
|
98
|
+
if (typeof value === 'string')
|
|
99
|
+
out.set(path.join('\0'), { path, value });
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (typeof s.$ref === 'string' && s.$ref.startsWith('#/'))
|
|
103
|
+
visit(refAt(root, s.$ref), value, path, seen);
|
|
104
|
+
for (const k of ['allOf', 'anyOf', 'oneOf'])
|
|
105
|
+
for (const branch of s[k] ?? [])
|
|
106
|
+
visit(branch, value, path, seen);
|
|
107
|
+
for (const k of ['then', 'else'])
|
|
108
|
+
visit(s[k], value, path, seen);
|
|
109
|
+
if (Array.isArray(value)) {
|
|
110
|
+
const prefix = s.prefixItems ?? [];
|
|
111
|
+
value.forEach((x, i) => visit(i < prefix.length ? prefix[i] : s.items, x, [...path, String(i)], new Set()));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (value === null || typeof value !== 'object')
|
|
115
|
+
return;
|
|
116
|
+
const properties = (s.properties ?? {});
|
|
117
|
+
const byPattern = Object.entries((s.patternProperties ?? {}));
|
|
118
|
+
for (const [k, x] of Object.entries(value)) {
|
|
119
|
+
const sub = Object.hasOwn(properties, k) ? properties[k] : (byPattern.find(([p]) => matches(p, k))?.[1] ?? s.additionalProperties);
|
|
120
|
+
visit(sub, x, [...path, k], new Set());
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
visit(root, data, [], new Set());
|
|
124
|
+
return [...out.values()];
|
|
125
|
+
}
|
|
74
126
|
// edits between two names, a swap of two neighbours counting as one (titel, title)
|
|
75
127
|
function distance(a, b) {
|
|
76
128
|
const d = Array.from({ length: a.length + 1 }, (_, i) => [i, ...Array(b.length).fill(0)]);
|
package/dist/starts.js
CHANGED
|
@@ -13,10 +13,17 @@ function rootOf(dir) {
|
|
|
13
13
|
return d;
|
|
14
14
|
return dirname(dir);
|
|
15
15
|
}
|
|
16
|
+
// every flow under root by its id; a flow.yaml that cannot be read is left out, as its own check reports it
|
|
16
17
|
function flowsUnder(root, depth = 4, out = new Map()) {
|
|
17
18
|
const file = join(root, 'flow.yaml');
|
|
18
19
|
if (existsSync(file)) {
|
|
19
|
-
|
|
20
|
+
let f = null;
|
|
21
|
+
try {
|
|
22
|
+
f = readYaml(readFileSync(file, 'utf8'));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
f = null;
|
|
26
|
+
}
|
|
20
27
|
if (typeof f?.id === 'string')
|
|
21
28
|
out.set(f.id, { ...f, context: f.context ?? {} });
|
|
22
29
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Graph } from './graph.ts';
|
|
2
|
+
import type { Exploration, Model } from './model.ts';
|
|
3
|
+
export interface TutorialProblem {
|
|
4
|
+
path: string[];
|
|
5
|
+
line?: number;
|
|
6
|
+
column?: number;
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function checkTutorial(g: Graph, m: Model, ex: Exploration, text: string): TutorialProblem[];
|