@delurio/cli 0.8.0 → 0.9.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,6 +1,6 @@
1
1
  import type { Graph } from './graph.ts';
2
2
  export interface UiProblem {
3
- rule: 'focus-not-shown' | 'returns-focus-not-dialog';
3
+ rule: 'focus-not-shown' | 'returns-focus-not-dialog' | 'task-locale';
4
4
  path: string[];
5
5
  message: string;
6
6
  element: string;
package/dist/ui-check.js CHANGED
@@ -1,19 +1,22 @@
1
1
  // What `check` holds in ui.yaml beyond its schema (SPEC.md §4): `focus` and `returnsFocus` give the focus to a node
2
- // that is shown where the focus goes, `returnsFocus` starts at a dialog, and the words a field's `value` takes from
3
- // the catalog are there, as every other node's are. That `value`, `checked` and `script` sit only on the nodes they
2
+ // that is shown where the focus goes, `returnsFocus` starts at a dialog, the words a field's `value` takes from the
3
+ // catalog are there, as every other node's are, and the flow's name for its users (`task`) is in every locale. That `value`, `checked` and `script` sit only on the nodes they
4
4
  // are for is the schema's; that a `focus` state exists and that `checked` reads the context is the loader's.
5
- import { alternatives, isDialog, shownIn } from './graph.js';
5
+ import { readFileSync } from 'node:fs';
6
+ import { basename, dirname, join } from 'node:path';
7
+ import { alternatives, isDialog, OPENER, shownIn } from './graph.js';
6
8
  const listed = (xs) => (xs.length <= 1 ? xs.join('') : `${xs.slice(0, -1).join(', ')} and ${xs[xs.length - 1]}`);
7
- // the states the flow stops in after a transition out of `state`: its targets, and past a state with `always` the
8
- // targets of that state, as far as they go
9
- function stopsAfter(g, state) {
9
+ // the states the flow stops in after a transition out of `state` (on `event` only, when it is given): its targets, and
10
+ // past a state with `always` the targets of that state, as far as they go
11
+ function stopsAfter(g, state, event) {
10
12
  const out = [];
11
13
  const seen = new Set();
12
14
  const ways = (s) => {
13
15
  const st = g.flow.states[s];
14
16
  return [...(st.always ?? []).map((a) => a.target), ...Object.values(st.on ?? {}).flatMap((spec) => alternatives(spec).map((a) => a.target))];
15
17
  };
16
- const todo = ways(state);
18
+ const first = g.flow.states[state].on?.[event ?? ''];
19
+ const todo = event === undefined ? ways(state) : first === undefined ? [] : alternatives(first).map((a) => a.target);
17
20
  while (todo.length > 0) {
18
21
  const t = todo.shift();
19
22
  if (seen.has(t))
@@ -39,6 +42,20 @@ function closesInto(g, dialog) {
39
42
  }
40
43
  return [...out];
41
44
  }
45
+ // the nodes that open a dialog: each is shown in a state that does not show the dialog, and sends an event that leads
46
+ // from there to a state that shows it (SPEC.md §4, the node that opened a dialog)
47
+ function openersOf(g, dialog) {
48
+ const d = g.ui.nodes[dialog];
49
+ const out = [];
50
+ for (const [id, n] of Object.entries(g.ui.nodes)) {
51
+ if (n.emits === undefined)
52
+ continue;
53
+ const opens = Object.keys(g.flow.states).some((s) => shownIn(n, s) && !shownIn(d, s) && stopsAfter(g, s, n.emits).some((t) => shownIn(d, t)));
54
+ if (opens)
55
+ out.push(id);
56
+ }
57
+ return out;
58
+ }
42
59
  export function checkUi(g, warn) {
43
60
  const nodes = g.ui.nodes;
44
61
  const out = [];
@@ -61,15 +78,26 @@ export function checkUi(g, warn) {
61
78
  out.push({ rule: 'returns-focus-not-dialog', path, element, message: `returnsFocus starts at ${dialog}, which is ${what}: it starts at a page node whose role is dialog or alertdialog (SPEC.md §4)` });
62
79
  return;
63
80
  }
64
- if (nodes[node] === undefined) {
65
- out.push({ rule: 'focus-not-shown', path, element, message: `returnsFocus gives the focus of ${dialog} to ${node}, which is no node of ui.yaml` });
81
+ // one node, the nodes that open the dialog, or OPENER: whichever node opens it
82
+ const several = Array.isArray(node) || node === OPENER;
83
+ const targets = node === OPENER ? openersOf(g, dialog) : Array.isArray(node) ? node : [node];
84
+ if (node === OPENER && targets.length === 0) {
85
+ out.push({ rule: 'focus-not-shown', path, element, message: `returnsFocus gives the focus of ${dialog} back to the node that opened it, but no node opens it: none sends an event that leads from a state without the dialog to one that shows it (SPEC.md §4)` });
66
86
  return;
67
87
  }
68
88
  const into = closesInto(g, dialog);
69
- if (into.some((s) => shownIn(nodes[node], s)))
70
- return;
71
- const where = into.length === 0 ? `the dialog ${dialog} never closes into a state the flow stops in` : `no state ${dialog} closes into shows it (${listed(into)})`;
72
- out.push({ rule: 'focus-not-shown', path, element, message: `returnsFocus gives the focus of ${dialog} to ${node}, but ${where} (SPEC.md §4)` });
89
+ for (const t of targets) {
90
+ const at = several ? `${element}/${t}` : element;
91
+ if (nodes[t] === undefined) {
92
+ out.push({ rule: 'focus-not-shown', path, element: at, message: `returnsFocus gives the focus of ${dialog} to ${t}, which is no node of ui.yaml` });
93
+ continue;
94
+ }
95
+ if (into.some((s) => shownIn(nodes[t], s)))
96
+ continue;
97
+ const where = into.length === 0 ? `the dialog ${dialog} never closes into a state the flow stops in` : `no state ${dialog} closes into shows it (${listed(into)})`;
98
+ const who = node === OPENER ? `back to ${t}, which opens it,` : `to ${t},`;
99
+ out.push({ rule: 'focus-not-shown', path, element: at, message: `returnsFocus gives the focus of ${dialog} ${who} but ${where} (SPEC.md §4)` });
100
+ }
73
101
  });
74
102
  // a field's value in words of the catalog, held as every other node's words are
75
103
  const words = (v) => {
@@ -87,5 +115,22 @@ export function checkUi(g, warn) {
87
115
  for (const n of Object.values(nodes))
88
116
  if (n.value !== undefined)
89
117
  words(n.value);
118
+ // the flow's name for its users, in the catalog of every locale, as the changes note is
119
+ const task = g.ui.task?.key;
120
+ if (g.ui.absent !== true && typeof task === 'string') {
121
+ for (const locale of g.ui.locales ?? [basename(g.ui.catalog, '.json')]) {
122
+ let catalog = null;
123
+ try {
124
+ catalog = JSON.parse(readFileSync(join(g.dir, dirname(g.ui.catalog), `${locale}.json`), 'utf8'));
125
+ }
126
+ catch {
127
+ catalog = null;
128
+ }
129
+ const name = catalog?.[task];
130
+ if (typeof name === 'string' && name.trim() !== '')
131
+ continue;
132
+ out.push({ rule: 'task-locale', path: ['task'], element: `task/${locale}`, message: `the flow's name for its users, ${task}, is not in the ${locale} catalog (SPEC.md §4)` });
133
+ }
134
+ }
90
135
  return out;
91
136
  }
package/dist/wireframe.js CHANGED
@@ -40,8 +40,22 @@ function accessibleName(g, n, warn) {
40
40
  }
41
41
  if (n.role === 'button' || n.role === 'heading' || n.role === 'status' || n.role === 'alert')
42
42
  return texts(g, n, warn)[0];
43
+ // a checkbox, a radio and a select are named by their label, the words beside them (SPEC.md §4)
44
+ if (LABELLED.has(n.component ?? ''))
45
+ return texts(g, n, warn)[0];
43
46
  return undefined;
44
47
  }
48
+ const LABELLED = new Set(['Checkbox', 'Radio', 'Select']);
49
+ // the words a field holds when it is shown (`value`), for a select the option it shows chosen
50
+ function valueWords(g, n, warn) {
51
+ const v = n.value;
52
+ if (v === undefined)
53
+ return '';
54
+ if (v.literal !== undefined)
55
+ return v.literal;
56
+ const key = v.key ?? v.oneOf?.[0];
57
+ return key === undefined ? '' : fill(g, key, warn);
58
+ }
45
59
  function chips(it) {
46
60
  const n = it.node;
47
61
  const parts = [n.role ?? n.type];
@@ -49,6 +63,8 @@ function chips(it) {
49
63
  parts.push(`emits ${n.emits}`);
50
64
  if (it.disabled)
51
65
  parts.push('disabled');
66
+ else if (n.disabledWhen !== undefined)
67
+ parts.push(`disabled when ${n.disabledWhen}`);
52
68
  if (n.when !== undefined)
53
69
  parts.push(`when ${n.when}`);
54
70
  if (it.focus)
@@ -78,7 +94,7 @@ function renderWireframe(g, state, items, warn, clean = false, kit = null) {
78
94
  const name = accessibleName(g, n, warn);
79
95
  // the role the expected tree gives the node, which picks a template from the component's `roles`
80
96
  const role = n.role ?? (n.type === 'text' ? undefined : n.type);
81
- return { id: it.id, text, name: name ?? text, intent: n.intent, role, disabled: it.disabled, named: name !== undefined && name !== text, conditional: n.when !== undefined };
97
+ return { id: it.id, text, name: name ?? text, intent: n.intent, role, disabled: it.disabled, named: name !== undefined && name !== text, conditional: n.when !== undefined, checked: n.checked === true };
82
98
  };
83
99
  const drawKitList = (it, drawn) => {
84
100
  const f = { ...fill(it, texts(g, it.node, warn)[0] ?? ''), children: drawn.map((d) => `\n${d}`).join('') + '\n' };
@@ -142,6 +158,14 @@ function renderWireframe(g, state, items, warn, clean = false, kit = null) {
142
158
  // the visible text is the label; the input is named by it, as a <label> around it does
143
159
  out.push(item(it, `<label class="wf-field"><span>${text}</span><input type="text" class="wf-input" tabindex="-1"${it.disabled ? ' disabled' : ''}></label>`));
144
160
  break;
161
+ case 'Checkbox':
162
+ case 'Radio':
163
+ // the box beside its label, as a <label> around an <input> draws it
164
+ out.push(item(it, `<label class="wf-check"><input type="${n.component === 'Radio' ? 'radio' : 'checkbox'}" tabindex="-1"${n.checked === true ? ' checked' : ''}${it.disabled ? ' disabled' : ''}><span>${text}</span></label>`));
165
+ break;
166
+ case 'Select':
167
+ out.push(item(it, `<label class="wf-field"><span>${text}</span><select class="wf-input" tabindex="-1"${it.disabled ? ' disabled' : ''}><option>${esc(valueWords(g, n, warn))}</option></select></label>`));
168
+ break;
145
169
  case 'List':
146
170
  out.push(`<ul class="wf-list" data-node="${esc(it.id)}">`);
147
171
  inList = true;
@@ -172,7 +196,7 @@ function renderTree(g, items, warn) {
172
196
  for (const it of items) {
173
197
  const n = it.node;
174
198
  const depth = n.component === 'Page' ? 0 : n.component === 'ListItem' ? 2 : 1;
175
- const flags = [it.disabled ? 'disabled' : '', n.when !== undefined ? `when ${n.when}` : '', it.focus ? 'first focus' : '', n.emits !== undefined ? `→ ${n.emits}` : '']
199
+ const flags = [it.disabled ? 'disabled' : n.disabledWhen !== undefined ? `disabled when ${n.disabledWhen}` : '', n.when !== undefined ? `when ${n.when}` : '', it.focus ? 'first focus' : '', n.emits !== undefined ? `→ ${n.emits}` : '']
176
200
  .filter((f) => f !== '')
177
201
  .join(', ');
178
202
  const suffix = flags === '' ? '' : ` [${flags}]`;
package/dist/yaml.d.ts CHANGED
@@ -11,6 +11,7 @@ export declare function lineAndColumn(text: string, offset: number): {
11
11
  column: number;
12
12
  };
13
13
  export declare function unsupported(text: string): Unsupported | null;
14
+ export declare function parsingOnce<T>(run: () => T): T;
14
15
  export declare function readYaml(text: string): unknown;
15
16
  export declare function keyAt(text: string, path: string[]): {
16
17
  line: number;
package/dist/yaml.js CHANGED
@@ -68,18 +68,49 @@ function refusal(u) {
68
68
  err.linePos = [{ line: u.line, col: u.column }];
69
69
  return err;
70
70
  }
71
- // the value of a graph file's text: the yaml library's `parse`, once nothing unsupported is found
71
+ let read = null;
72
+ // `run`, with every text it reads through `readYaml` or `keyAt` parsed once; the same as `run` alone otherwise
73
+ export function parsingOnce(run) {
74
+ if (read !== null)
75
+ return run();
76
+ read = { values: new Map(), documents: new Map() };
77
+ try {
78
+ return run();
79
+ }
80
+ finally {
81
+ read = null;
82
+ }
83
+ }
84
+ // the value of a graph file's text: the yaml library's `parse`, once nothing unsupported is found. Inside
85
+ // `parsingOnce` each call gets its own copy, so a reader that changes the value changes no other reader's.
72
86
  export function readYaml(text) {
87
+ const kept = read?.values.get(text);
88
+ if (kept !== undefined) {
89
+ if ('refused' in kept)
90
+ throw refusal(kept.refused);
91
+ return structuredClone(kept.value);
92
+ }
73
93
  const u = unsupported(text);
74
- if (u !== null)
94
+ if (u !== null) {
95
+ read?.values.set(text, { refused: u });
75
96
  throw refusal(u);
76
- return parse(text);
97
+ }
98
+ const value = parse(text);
99
+ if (read === null)
100
+ return value;
101
+ read.values.set(text, { value });
102
+ return structuredClone(value);
77
103
  }
78
104
  // 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
105
  // start; for a text `readYaml` has read
80
106
  export function keyAt(text, path) {
81
- const lineCounter = new LineCounter();
82
- const doc = parseDocument(text, { lineCounter, prettyErrors: false });
107
+ let parsed = read?.documents.get(text);
108
+ if (parsed === undefined) {
109
+ const counter = new LineCounter();
110
+ parsed = { doc: parseDocument(text, { lineCounter: counter, prettyErrors: false }), lineCounter: counter };
111
+ read?.documents.set(text, parsed);
112
+ }
113
+ const { doc, lineCounter } = parsed;
83
114
  const keyOf = (pair) => String(pair.key?.value ?? pair.key);
84
115
  let node = doc.contents;
85
116
  let at;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delurio/cli",
3
- "version": "0.8.0",
3
+ "version": "0.9.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",
@@ -17,6 +17,7 @@
17
17
  "./expr": { "types": "./dist/expr.d.ts", "default": "./dist/expr.js" },
18
18
  "./spine": { "types": "./dist/spine.d.ts", "default": "./dist/spine.js" },
19
19
  "./yaml": { "types": "./dist/yaml.d.ts", "default": "./dist/yaml.js" },
20
+ "./needs": { "types": "./dist/needs.d.ts", "default": "./dist/needs.js" },
20
21
  "./package.json": "./package.json"
21
22
  },
22
23
  "files": ["dist", "schemas", "SPEC.md", "NOTICE", "CHANGELOG.md"],
@@ -72,8 +72,8 @@
72
72
  "description": "The entity's fields, by name, each a JSON Schema (2020-12) with delurio's keywords.",
73
73
  "additionalProperties": { "$ref": "#/$defs/field" }
74
74
  },
75
- "required": { "$ref": "#/$defs/names", "description": "The fields that must be present." },
76
- "key": { "$ref": "#/$defs/names", "description": "The fields that identify the entity; `[id]` when left out.", "examples": [["userId", "clientId"]] },
75
+ "required": { "$ref": "#/$defs/names", "description": "The fields that must be present, each one of its `fields`." },
76
+ "key": { "$ref": "#/$defs/names", "description": "The fields that identify the entity, each one of its `fields`; `[id]` when left out.", "examples": [["userId", "clientId"]] },
77
77
  "lifecycle": {
78
78
  "type": "array",
79
79
  "description": "The entity's states, as `from -> to: why` sentences. Quote each: an unquoted item that contains `: ` is read as a map.",
@@ -193,7 +193,7 @@
193
193
  "contentMediaType": { "type": "string", "description": "JSON Schema: the media type of the string's content.", "examples": ["text/calendar", "application/json"] },
194
194
  "contentSchema": { "$ref": "#/$defs/schema", "description": "JSON Schema: the schema of the string's decoded content." },
195
195
 
196
- "references": { "type": "string", "description": "delurio: the field holds the key of this other entity." },
196
+ "references": { "type": "string", "description": "delurio: the field holds the key of this other entity, one of the domain's own (SPEC.md §5)." },
197
197
  "unique": {
198
198
  "description": "delurio: no two entities have the same value: `true`, or `case-insensitive`.",
199
199
  "enum": [true, "case-insensitive"]
@@ -252,7 +252,7 @@
252
252
  "description": "The action's response: `returns` an entity, a `redirect`, a `status`, or a JSON Schema.",
253
253
  "$ref": "#/$defs/keywords",
254
254
  "properties": {
255
- "returns": { "type": "string", "description": "The entity the action returns." },
255
+ "returns": { "type": "string", "description": "The entity the action returns, one of the domain's own (SPEC.md §5)." },
256
256
  "redirect": { "type": "string", "description": "Where the response redirects, in words or as a path." },
257
257
  "status": { "type": "integer", "minimum": 100, "maximum": 599, "description": "The HTTP status of the response." }
258
258
  },
@@ -283,9 +283,9 @@
283
283
  "actor": { "type": "string", "description": "Who the policy is for.", "examples": ["end-user", "anyone", "agent"] },
284
284
  "needs": { "type": "string", "description": "What the actor must hold.", "examples": ["session"] },
285
285
  "where": { "type": "string", "description": "The condition under which it holds, in words." },
286
- "read": { "$ref": "#/$defs/names", "description": "The entities the actor may read." },
287
- "write": { "$ref": "#/$defs/names", "description": "The entities the actor may write." },
288
- "do": { "$ref": "#/$defs/names", "description": "The actions the actor may invoke." },
286
+ "read": { "$ref": "#/$defs/names", "description": "The entities of the domain the actor may read." },
287
+ "write": { "$ref": "#/$defs/names", "description": "The entities of the domain the actor may write." },
288
+ "do": { "$ref": "#/$defs/names", "description": "The actions of the domain the actor may invoke." },
289
289
  "source": { "$ref": "#/$defs/sourceAnchor" }
290
290
  }
291
291
  },
@@ -0,0 +1,49 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://unpkg.com/@delurio/cli@0.9.0/schemas/gaps.schema.json",
4
+ "title": "delurio gaps of a product (needs.gaps.yaml)",
5
+ "description": "Every need of a product's flows that is missing, by the flow's id and the need's id, in delurio-graph/0 (SPEC.md §13). It sits at the root of the product's graphs and covers the flows under its folder. A need that is missing and not listed here fails the check, and so does an entry whose need is met: the list only shrinks on its own.",
6
+ "type": "object",
7
+ "required": ["schema", "kind", "id", "gaps"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "schema": {
11
+ "description": "The format and its version. Every graph file starts with it.",
12
+ "const": "delurio-graph/0"
13
+ },
14
+ "kind": { "description": "The kind of graph file. A needs.gaps.yaml is `gaps`.", "const": "gaps" },
15
+ "id": {
16
+ "type": "string",
17
+ "description": "The product's id, as its flows' ids begin.",
18
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$",
19
+ "examples": ["example.notes"]
20
+ },
21
+ "title": { "type": "string", "description": "The list in plain words, for people." },
22
+ "summary": { "type": "string", "description": "What the gaps are, in a few plain sentences: the phases still to come, for instance." },
23
+ "status": {
24
+ "description": "`proposed`: written, nobody has approved it. `approved`: the owner reviewed and accepted the list.",
25
+ "enum": ["proposed", "approved"]
26
+ },
27
+ "gaps": {
28
+ "type": "object",
29
+ "description": "The needs that are missing, by flow id: each a list of need ids, every one of them a need of that flow's needs.yaml that says `missing`. Empty when every need is met.",
30
+ "propertyNames": {
31
+ "type": "string",
32
+ "description": "A flow's id, as its needs.yaml gives it.",
33
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$"
34
+ },
35
+ "additionalProperties": {
36
+ "type": "array",
37
+ "description": "The ids of the flow's needs that are missing.",
38
+ "minItems": 1,
39
+ "uniqueItems": true,
40
+ "items": {
41
+ "type": "string",
42
+ "description": "A need's id: kebab-case.",
43
+ "pattern": "^[a-z][a-z0-9]*(-[a-z0-9]+)*$"
44
+ }
45
+ },
46
+ "examples": [{ "example.restoreNote": ["says-when-it-is-erased"] }]
47
+ }
48
+ }
49
+ }
@@ -146,19 +146,46 @@
146
146
  "commit": { "type": "string", "description": "The commit the extractor read." },
147
147
  "app": { "type": "string", "description": "The application's folder in the repository." },
148
148
  "menu": { "type": "string", "description": "The file that holds the menus." },
149
- "locales": { "type": "string", "description": "The application's translation files; `{locale}` stands for the locale." }
149
+ "locales": {
150
+ "description": "The application's message file, or a list of every file it reads; `{locale}` stands for the locale in each path (SPEC.md §6).",
151
+ "anyOf": [
152
+ { "type": "string" },
153
+ { "type": "array", "minItems": 1, "items": { "type": "string" } }
154
+ ],
155
+ "examples": ["messages/{locale}.json", ["libs/i18n/locales/{locale}/web.json", "libs/i18n/locales/{locale}/common.json"]]
156
+ }
150
157
  },
151
158
  "additionalProperties": { "type": "string", "description": "Another file or folder of the application the graph was read from." }
152
159
  },
153
160
  "extract": {
154
161
  "type": "object",
155
- "description": "How the extractor reads the application: its adapter, the names it gives to pages that no menu entry names, the titles it takes, and the locales it copies into catalog/.",
162
+ "description": "How the extractor reads the application: its adapter, the names it gives to pages that no menu entry names, the titles it takes, the locales it copies into catalog/, and the fields it lays over the entries it generates.",
156
163
  "additionalProperties": false,
157
164
  "properties": {
158
165
  "adapter": { "type": "string", "description": "The extractor adapter for this application." },
159
166
  "names": { "type": "object", "description": "Route to page id, for pages that no menu entry names.", "additionalProperties": { "type": "string", "description": "The page id." } },
160
167
  "titles": { "type": "object", "description": "Page id to the catalog key of its title.", "additionalProperties": { "type": "string", "description": "The catalog key." } },
161
- "locales": { "type": "array", "description": "The locales copied into catalog/, as BCP 47 tags.", "items": { "$ref": "#/$defs/locale" } }
168
+ "locales": { "type": "array", "description": "The locales copied into catalog/, as BCP 47 tags.", "items": { "$ref": "#/$defs/locale" } },
169
+ "entries": {
170
+ "type": "object",
171
+ "description": "Fields laid over a generated entry, which nav.yaml cannot change otherwise, keyed by the entry's ends as it is cited: `<from>-><to>`, followed by its how or its label where two share their ends (SPEC.md §6).",
172
+ "propertyNames": { "pattern": "^(frame:[\\w-]+|[\\w-]+)->[\\w-]+( \\S+)?$" },
173
+ "additionalProperties": {
174
+ "type": "object",
175
+ "description": "The fields laid over the entry, or skip with the reason it is left out.",
176
+ "additionalProperties": false,
177
+ "properties": {
178
+ "when": { "$ref": "#/$defs/expression", "description": "The guard under which the entry is offered." },
179
+ "data": { "type": "boolean", "description": "`true` when it needs an item to exist (a row to click)." },
180
+ "label": { "type": "string", "description": "Its words: a catalog key, or plain words." },
181
+ "how": { "$ref": "#/$defs/entry/properties/how" },
182
+ "back": { "type": "boolean", "description": "`true` for a way back." },
183
+ "clicks": { "type": "integer", "minimum": 0, "description": "How many clicks it takes." },
184
+ "skip": { "type": "string", "minLength": 1, "description": "Why the generated entry is left out." }
185
+ }
186
+ },
187
+ "examples": [{ "home->discover": { "when": "not signedIn" }, "frame:none->privacy": { "skip": "the privacy page links to itself" } }]
188
+ }
162
189
  }
163
190
  },
164
191
  "guards": {
@@ -232,6 +259,10 @@
232
259
  "frame": { "type": "string", "description": "The frame drawn around the page." },
233
260
  "opensFor": { "$ref": "#/$defs/expression", "description": "The guard under which the page opens; it refuses everyone else." },
234
261
  "refusal": { "type": "string", "description": "How the page says no, in words." },
262
+ "byAddress": {
263
+ "type": "boolean",
264
+ "description": "People open the page by its address, typed or followed from outside the app (a link in an e-mail, a sign-in another site sends them to), as nothing in the app links to it: a persona no entry brings there reaches it so, with no clicks, and it is not unreachable (SPEC.md §6)."
265
+ },
235
266
  "pageCodes": { "type": "string", "description": "Generated: the name of the permission codes that open the page, as the application's permission table names them." },
236
267
  "evidence": { "type": "string", "description": "The code that shows the page's kind or gate, in words." },
237
268
  "source": { "$ref": "#/$defs/sourceAnchor" }
@@ -0,0 +1,189 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://unpkg.com/@delurio/cli@0.9.0/schemas/needs.schema.json",
4
+ "title": "delurio needs of a flow (needs.yaml)",
5
+ "description": "What must exist for a flow's users, in delurio-graph/0 (SPEC.md §13): a closed list beside the flow's flow.yaml, each need with the evidence that it exists, or `missing` and why it does not yet. A need that is missing is a gap of the product, listed in its needs.gaps.yaml.",
6
+ "type": "object",
7
+ "required": ["schema", "kind", "id", "needs"],
8
+ "additionalProperties": false,
9
+ "properties": {
10
+ "schema": { "$ref": "#/$defs/formatVersion" },
11
+ "kind": { "description": "The kind of graph file. A needs.yaml is `needs`.", "const": "needs" },
12
+ "id": {
13
+ "type": "string",
14
+ "description": "The id of the flow beside this file, whose needs these are.",
15
+ "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$",
16
+ "examples": ["example.restoreNote"]
17
+ },
18
+ "title": { "type": "string", "description": "The list in plain words, for people." },
19
+ "summary": { "type": "string", "description": "Where the needs come from and what they cover, in a few plain sentences." },
20
+ "status": {
21
+ "description": "`proposed`: written, nobody has approved it. `approved`: the owner reviewed and accepted the list. A list is written from what the flow's users need, never read from the code, so it is never `captured`.",
22
+ "enum": ["proposed", "approved"]
23
+ },
24
+ "needs": {
25
+ "type": "array",
26
+ "description": "The needs, in the order people read them. Each id comes once.",
27
+ "minItems": 1,
28
+ "items": { "$ref": "#/$defs/need" }
29
+ }
30
+ },
31
+ "$defs": {
32
+ "formatVersion": {
33
+ "description": "The format and its version. Every graph file starts with it.",
34
+ "const": "delurio-graph/0"
35
+ },
36
+ "need": {
37
+ "type": "object",
38
+ "description": "One thing that must exist for the flow's users. A need without `missing` is met, and names evidence outside the graph (a source, a test, a scenario or a setting); a need with `missing` is a gap, and may name what exists of it so far.",
39
+ "required": ["id", "need"],
40
+ "additionalProperties": false,
41
+ "properties": {
42
+ "id": { "$ref": "#/$defs/needId" },
43
+ "need": {
44
+ "type": "string",
45
+ "description": "What must exist, in a sentence of the graph's language, from the users' side: what they can do or what they are told.",
46
+ "minLength": 1,
47
+ "examples": ["The owner of an archived note restores it from the note's own page, and it is active again."]
48
+ },
49
+ "evidence": {
50
+ "type": "array",
51
+ "description": "What shows that the need exists: the code, a test, a scenario that walks it, the states and nodes it is drawn as, a setting a deployment gives. Every piece must resolve.",
52
+ "minItems": 1,
53
+ "items": { "$ref": "#/$defs/evidence" }
54
+ },
55
+ "missing": {
56
+ "type": "string",
57
+ "description": "That the need does not exist yet, and why or where that is tracked: words, an issue, a finding's id. Its flow and id must then be in the product's needs.gaps.yaml.",
58
+ "minLength": 1,
59
+ "examples": ["archived notes are not erased yet; the second phase erases them"]
60
+ },
61
+ "note": { "type": "string", "description": "The author's own words. No tool reads them." }
62
+ },
63
+ "anyOf": [{ "required": ["evidence"] }, { "required": ["missing"] }]
64
+ },
65
+ "needId": {
66
+ "type": "string",
67
+ "description": "A need's id in its flow: kebab-case. The gaps name it so.",
68
+ "pattern": "^[a-z][a-z0-9]*(-[a-z0-9]+)*$",
69
+ "examples": ["restore-from-its-page"]
70
+ },
71
+ "path": {
72
+ "type": "string",
73
+ "description": "A path relative to the application's repository root (SPEC.md §9).",
74
+ "pattern": "^[^\\s/][^\\s]*$"
75
+ },
76
+ "evidence": {
77
+ "type": "object",
78
+ "description": "One piece of evidence, of one kind: `source`, `test`, `scenario`, `state`, `node` or `setting`.",
79
+ "additionalProperties": false,
80
+ "properties": {
81
+ "source": {
82
+ "type": "string",
83
+ "description": "The code that makes the need true: `<path>:<line>`, or a bare `<path>` for a whole file, relative to the application's repository root (SPEC.md §9). The file must exist and have that line.",
84
+ "pattern": "^[^\\s/:][^\\s:]*(:[0-9]+)?$",
85
+ "examples": ["app/notes.js", "src/notes/restore.ts:42"]
86
+ },
87
+ "test": {
88
+ "$ref": "#/$defs/path",
89
+ "description": "A test of the need: its file, relative to the application's repository root. The file must exist.",
90
+ "examples": ["app/notes.test.js"]
91
+ },
92
+ "name": {
93
+ "type": "string",
94
+ "description": "With `source`: a name the file holds, such as the function that does it. With `test`: the test's name as it is written, in quotes or as a test function's name. The file must hold it, not as a part of a longer word.",
95
+ "minLength": 1,
96
+ "examples": ["restoreNote", "restores an archived note"]
97
+ },
98
+ "scenario": {
99
+ "type": "string",
100
+ "description": "A scenario of a binding (SPEC.md §7) that walks the need on the app. The binding is the flow's own binding.yaml, or the one `binding` names; it binds this flow and has the scenario, its `extends` included.",
101
+ "minLength": 1,
102
+ "examples": ["owner"]
103
+ },
104
+ "binding": {
105
+ "$ref": "#/$defs/path",
106
+ "description": "With `scenario`: the binding that has it, relative to the application's repository root, when it is not the flow's own binding.yaml.",
107
+ "examples": ["e2e/notes.binding.yaml"]
108
+ },
109
+ "state": {
110
+ "type": "string",
111
+ "description": "A state of the flow the need is drawn as. Where only missing needs name it, a tool that walks the flow on the app leaves it out.",
112
+ "minLength": 1,
113
+ "examples": ["restoring"]
114
+ },
115
+ "node": {
116
+ "type": "string",
117
+ "description": "A node of the flow's screens (ui.yaml) the need is drawn as. Where only missing needs name it, a tool that walks the flow on the app leaves it out.",
118
+ "minLength": 1,
119
+ "examples": ["restore"]
120
+ },
121
+ "setting": {
122
+ "type": "string",
123
+ "description": "An environment variable a deployment sets for the need. The file `in` names sets it on a line that is not commented out.",
124
+ "pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
125
+ "examples": ["NOTES_SESSION_SECRET"]
126
+ },
127
+ "in": {
128
+ "$ref": "#/$defs/path",
129
+ "description": "With `setting`: the file that tells a deployment what to set, relative to the application's repository root: a dotenv file such as .env.example, or a Compose file.",
130
+ "examples": [".env.example", "compose.yaml"]
131
+ }
132
+ },
133
+ "allOf": [
134
+ {
135
+ "$comment": "a piece of evidence names its kind",
136
+ "anyOf": [
137
+ { "required": ["source"] },
138
+ { "required": ["test"] },
139
+ { "required": ["scenario"] },
140
+ { "required": ["state"] },
141
+ { "required": ["node"] },
142
+ { "required": ["setting"] }
143
+ ]
144
+ },
145
+ {
146
+ "$comment": "a piece of evidence is of one kind: give each kind an item of its own",
147
+ "if": { "required": ["source"] },
148
+ "then": { "properties": { "test": false, "scenario": false, "state": false, "node": false, "setting": false } }
149
+ },
150
+ {
151
+ "$comment": "a piece of evidence is of one kind: give each kind an item of its own",
152
+ "if": { "required": ["test"] },
153
+ "then": { "properties": { "scenario": false, "state": false, "node": false, "setting": false } }
154
+ },
155
+ {
156
+ "$comment": "a piece of evidence is of one kind: give each kind an item of its own",
157
+ "if": { "required": ["scenario"] },
158
+ "then": { "properties": { "state": false, "node": false, "setting": false } }
159
+ },
160
+ {
161
+ "$comment": "a piece of evidence is of one kind: give each kind an item of its own",
162
+ "if": { "required": ["state"] },
163
+ "then": { "properties": { "node": false, "setting": false } }
164
+ },
165
+ {
166
+ "$comment": "a piece of evidence is of one kind: give each kind an item of its own",
167
+ "if": { "required": ["node"] },
168
+ "then": { "properties": { "setting": false } }
169
+ },
170
+ {
171
+ "$comment": "name goes with a source or a test",
172
+ "if": { "required": ["name"] },
173
+ "then": { "anyOf": [{ "required": ["source"] }, { "required": ["test"] }] }
174
+ },
175
+ {
176
+ "$comment": "binding goes with a scenario",
177
+ "if": { "required": ["binding"] },
178
+ "then": { "required": ["scenario"] }
179
+ },
180
+ {
181
+ "$comment": "a setting names the file that sets it, and in goes with a setting",
182
+ "if": { "required": ["setting"] },
183
+ "then": { "required": ["in"] },
184
+ "else": { "properties": { "in": false } }
185
+ }
186
+ ]
187
+ }
188
+ }
189
+ }