@delurio/cli 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/NOTICE +7 -0
  3. package/README.md +38 -22
  4. package/SPEC.md +8 -1
  5. package/js/changes.d.ts +17 -0
  6. package/js/cli.js +6 -0
  7. package/{dist → js}/edges.d.ts +2 -2
  8. package/js/edges.js +40 -0
  9. package/js/expr.js +25 -0
  10. package/{dist → js}/graph.d.ts +3 -0
  11. package/js/graph.js +73 -0
  12. package/{dist → js}/html.d.ts +6 -6
  13. package/js/html.js +13 -0
  14. package/js/internal.js +408 -0
  15. package/js/kit.js +54 -0
  16. package/{dist → js}/model.d.ts +2 -2
  17. package/js/model.js +136 -0
  18. package/js/native.cjs +46 -0
  19. package/js/native.d.cts +328 -0
  20. package/{dist → js}/nav.d.ts +1 -1
  21. package/js/nav.js +70 -0
  22. package/js/needs.js +30 -0
  23. package/{dist → js}/spine.d.ts +3 -3
  24. package/js/spine.js +22 -0
  25. package/{dist → js}/starts.d.ts +1 -3
  26. package/{dist → js}/story.d.ts +2 -2
  27. package/js/story.js +22 -0
  28. package/{dist → js}/wireframe.d.ts +2 -2
  29. package/js/wireframe.js +29 -0
  30. package/js/yaml.d.ts +20 -0
  31. package/js/yaml.js +40 -0
  32. package/package.json +40 -24
  33. package/schemas/binding.schema.json +2211 -0
  34. package/schemas/ui.schema.json +6 -0
  35. package/dist/anchors.d.ts +0 -29
  36. package/dist/anchors.js +0 -160
  37. package/dist/changes.d.ts +0 -25
  38. package/dist/changes.js +0 -101
  39. package/dist/check.d.ts +0 -23
  40. package/dist/check.js +0 -649
  41. package/dist/cli.d.ts +0 -2
  42. package/dist/cli.js +0 -194
  43. package/dist/compare.d.ts +0 -34
  44. package/dist/compare.js +0 -143
  45. package/dist/diff-flow.d.ts +0 -33
  46. package/dist/diff-flow.js +0 -547
  47. package/dist/diff-nav.d.ts +0 -20
  48. package/dist/diff-nav.js +0 -401
  49. package/dist/diff.d.ts +0 -25
  50. package/dist/diff.js +0 -331
  51. package/dist/domain-names.d.ts +0 -18
  52. package/dist/domain-names.js +0 -124
  53. package/dist/domain.d.ts +0 -25
  54. package/dist/domain.js +0 -110
  55. package/dist/edges.js +0 -120
  56. package/dist/expr.js +0 -157
  57. package/dist/graph.js +0 -236
  58. package/dist/html.js +0 -311
  59. package/dist/index-page.d.ts +0 -12
  60. package/dist/index-page.js +0 -50
  61. package/dist/invokes.d.ts +0 -10
  62. package/dist/invokes.js +0 -67
  63. package/dist/kit.js +0 -711
  64. package/dist/mermaid.d.ts +0 -3
  65. package/dist/mermaid.js +0 -50
  66. package/dist/model.js +0 -608
  67. package/dist/nav-page.d.ts +0 -15
  68. package/dist/nav-page.js +0 -283
  69. package/dist/nav.js +0 -578
  70. package/dist/needs.js +0 -335
  71. package/dist/pan.d.ts +0 -2
  72. package/dist/pan.js +0 -252
  73. package/dist/schemas.d.ts +0 -15
  74. package/dist/schemas.js +0 -316
  75. package/dist/spine.js +0 -156
  76. package/dist/starts.js +0 -88
  77. package/dist/story.js +0 -109
  78. package/dist/tutorial-check.d.ts +0 -9
  79. package/dist/tutorial-check.js +0 -297
  80. package/dist/ui-check.d.ts +0 -8
  81. package/dist/ui-check.js +0 -142
  82. package/dist/watch.d.ts +0 -5
  83. package/dist/watch.js +0 -114
  84. package/dist/wireframe.js +0 -276
  85. package/dist/yaml.d.ts +0 -19
  86. package/dist/yaml.js +0 -134
  87. /package/{dist → js}/expr.d.ts +0 -0
  88. /package/{dist → js}/kit.d.ts +0 -0
  89. /package/{dist → js}/needs.d.ts +0 -0
@@ -0,0 +1,328 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * an exploration the addon holds for the JavaScript object explore() gave; V8 is told how much memory it holds, so
6
+ * that an unread exploration is collected as soon as a JavaScript one of its size would be
7
+ */
8
+ export declare class NativeExploration {
9
+ starts(): number
10
+ size(): number
11
+ taken(): Array<string>
12
+ /** `atState` as JSON entries */
13
+ atState(): string
14
+ /** `branchCounts` as JSON entries */
15
+ branchCounts(): string
16
+ configs(): ConfigsOut
17
+ }
18
+
19
+ /** a graph the addon holds for the JavaScript object it was read into (js/internal.js keeps the pair) */
20
+ export declare class NativeGraph {
21
+ /** a graph object a caller built (a copy of a loaded one, say), read from its JSON */
22
+ constructor(text: string)
23
+ /** the graph as the object `load` gave */
24
+ json(): string
25
+ }
26
+
27
+ export declare class NativeKit {
28
+ /** a kit object a caller built, read from its JSON */
29
+ constructor(text: string)
30
+ /** the kit as the object `loadKit` gives */
31
+ json(): string
32
+ }
33
+
34
+ export declare class NativeModel {
35
+ /** the model of a flow the addon holds (js/internal.js reads each flow object once) */
36
+ constructor(flow: NativeValue)
37
+ vars(): Array<string>
38
+ /** for each variable, the place of each of its values (`flow.context[v].values`) in its table */
39
+ domainCodes(): Array<Array<number>>
40
+ /** the variables that start from any of their values (`initial: any`), by position */
41
+ anyVars(): Array<number>
42
+ /** the value at a place of a variable's table, as JSON; undefined as None */
43
+ valueAt(var: number, code: number): string | null
44
+ /** the place of a value in a variable's table, added when no table holds it (undefined: None) */
45
+ codeOf(var: number, value?: string | undefined | null): number
46
+ steps(state: string, ctx: Uint16Array): StepsOut
47
+ initials(): CtxList
48
+ test(expr: string, state: string, ctx: Uint16Array): boolean
49
+ /** `value(expr, state, ctx)`, as JSON */
50
+ value(expr: string, state: string, ctx: Uint16Array): string
51
+ pure(src: string): boolean
52
+ /** `inState(src, state)`, as JSON; undefined as None */
53
+ inState(src: string, state: string): string | null
54
+ /** what `tester(expr)` throws before it is run: nothing, or the error of an expression that cannot be read */
55
+ tester(expr: string): void
56
+ /** the place `placeError` gives an error without one that `steps(state, ctx)` threw, as JSON */
57
+ placeOf(message: string, state: string, ctx: Uint16Array): string | null
58
+ }
59
+
60
+ export declare class NativeNav {
61
+ /** a navigation graph object a caller built, read from its JSON */
62
+ constructor(text: string)
63
+ /** the graph as the object `loadNav` gives */
64
+ json(): string
65
+ warnings(): Array<string>
66
+ }
67
+
68
+ /** any value of a graph file the addon holds for its JavaScript object (a flow, read once for many calls) */
69
+ export declare class NativeValue {
70
+ constructor(text: string)
71
+ }
72
+
73
+ /** `alternatives(spec)`, as JSON */
74
+ export declare function alternativesOf(spec?: string | undefined | null): string
75
+
76
+ /** `checkAssertions(m, ex)`, as JSON */
77
+ export declare function checkAssertions(m: NativeModel, ex: NativeExploration): string
78
+
79
+ /** `checkGoals(g, views)`, as JSON */
80
+ export declare function checkGoals(g: NativeNav, views: string): string
81
+
82
+ /** `checkNeeds(files, app)`, as JSON */
83
+ export declare function checkNeeds(files: Array<string>, app?: string | undefined | null): string
84
+
85
+ /** `collectEdges(g, ex)`, as JSON */
86
+ export declare function collectEdges(g: NativeGraph, ex: NativeExploration): string
87
+
88
+ /**
89
+ * an exploration's pairs, each list one entry per pair: the state and the event as places in `names` (event 0 is
90
+ * null, k is names[k - 1]), the parent as its position (-1 for a start), the contexts one after the other
91
+ */
92
+ export interface ConfigsOut {
93
+ names: Array<string>
94
+ state: Uint32Array
95
+ parent: Int32Array
96
+ event: Uint32Array
97
+ ctx: Uint16Array
98
+ }
99
+
100
+ /** `cover(m, by, from, keep)`, as JSON */
101
+ export declare function cover(m: NativeModel, by: string, from?: Uint16Array | undefined | null, count?: number | undefined | null, keep?: ((arg: KeepArgs) => number) | undefined | null): string
102
+
103
+ /** contexts, one after the other */
104
+ export interface CtxList {
105
+ count: number
106
+ ctx: Uint16Array
107
+ }
108
+
109
+ /** `drawWith(kit, component, f, warn)` */
110
+ export declare function drawWith(kit: NativeKit, component: string, fill: string, warn: (arg: string) => void): string | null
111
+
112
+ /** `BY`, as JSON */
113
+ export declare function edgesConstants(): string
114
+
115
+ /** `evaluate(e, lookup)`, as JSON: `lookup` gives each name's value as JSON (a trapped one gives null once it threw) */
116
+ export declare function evaluate(e: string, lookup: (arg: string) => string): string
117
+
118
+ /** `exitLine(st)` */
119
+ export declare function exitLine(st?: string | undefined | null): string
120
+
121
+ /** `explore(m, from, keep)` */
122
+ export declare function explore(m: NativeModel, from?: Uint16Array | undefined | null, count?: number | undefined | null, keep?: ((arg: KeepArgs) => number) | undefined | null): NativeExploration
123
+
124
+ /** `finalPaths(m, ex)`, as JSON */
125
+ export declare function finalPaths(m: NativeModel, ex: NativeExploration): string
126
+
127
+ /** `findings(g, views, goals)`, as JSON */
128
+ export declare function findings(g: NativeNav, views: string, goals: string): string
129
+
130
+ /** `focusAfter(ui, from, to, pressed)`, as JSON (null when nothing has the focus) */
131
+ export declare function focusAfterStep(ui: string, from: string | undefined | null, to: string, pressed?: string | undefined | null): string
132
+
133
+ /** `frameLevel(e)`, the entry as JSON */
134
+ export declare function frameLevel(entry: string): boolean
135
+
136
+ /** `frameReached(g, v, frame)`, the view as JSON */
137
+ export declare function frameReached(g: NativeNav, view: string, frame: string): boolean
138
+
139
+ /** OPENER and CHECKABLE */
140
+ export declare function graphConstants(): string
141
+
142
+ /** `guardCodes(g, src, depth)` */
143
+ export declare function guardCodes(g: NativeNav, src: string, depth?: number | undefined | null): Array<string>
144
+
145
+ /** `holds(g, p, expr)` */
146
+ export declare function holds(g: NativeNav, persona: string, expr?: string | undefined | null): boolean
147
+
148
+ export declare function humanize(id: string): string
149
+
150
+ /** `identifiers(e)`, in the order the expression reads them */
151
+ export declare function identifiers(e: string): Array<string>
152
+
153
+ /** `isDialog(n)` */
154
+ export declare function isDialogNode(node?: string | undefined | null): boolean
155
+
156
+ /** `keyAt(text, path)`, as JSON */
157
+ export declare function keyAt(text: string, path: Array<string>): string
158
+
159
+ /** `kindOf(g, name)` */
160
+ export declare function kindOf(g: NativeGraph, name: string): string
161
+
162
+ /** `kitCss(kit, target)` */
163
+ export declare function kitCss(kit: NativeKit, target: string): string
164
+
165
+ /** `kitStageScript(kit)` */
166
+ export declare function kitStageScript(kit: NativeKit): string
167
+
168
+ /** `lineAndColumn(text, offset)`, as JSON */
169
+ export declare function lineAndColumn(text: string, offset: number): string
170
+
171
+ /** `load(dir, read, exists)` */
172
+ export declare function load(dir: string, read: (arg: string) => ReadOut, exists: (arg: string) => number): NativeGraph
173
+
174
+ /** `loadKit(path)` */
175
+ export declare function loadKit(path: string): NativeKit
176
+
177
+ /** `loadNav(dir, locale, read)` */
178
+ export declare function loadNav(dir: string, locale: string | undefined | null, read: (arg: string) => ReadOut): NativeNav
179
+
180
+ /** `mainStoryIndex(g, ex)` */
181
+ export declare function mainStoryIndex(g: NativeGraph, ex: NativeExploration): number | null
182
+
183
+ /** `mark(html, id, chips)` */
184
+ export declare function mark(html: string, id: string, chips: string): string
185
+
186
+ /**
187
+ * `maskedNodes(g, mask)`: the nodes a recording masks, those that hold a field of the flow's domain whose sensitivity
188
+ * `mask` names (SPEC.md §4, §7), the domain looked up beside the graph as `check` finds it; graph.js checks `mask`
189
+ */
190
+ export declare function maskedNodesOf(g: NativeGraph, mask: Array<string>): Array<string>
191
+
192
+ /** `menuRows(g, views)`, as JSON */
193
+ export declare function menuRows(g: NativeNav, views: string): string
194
+
195
+ /** `narrate(g, m, steps)`, as JSON */
196
+ export declare function narrate(g: NativeGraph, m: NativeModel, steps: PathSteps): string
197
+
198
+ /** `pathTo(reach, page)`, the reach as JSON entries; the entries of the way as JSON */
199
+ export declare function navPathTo(reach: string, page: string): string
200
+
201
+ /** NEEDS_FILE and GAPS_FILE */
202
+ export declare function needsConstants(): string
203
+
204
+ /** `nodeLine(g, name)` */
205
+ export declare function nodeLine(g: NativeGraph, name: string): string
206
+
207
+ /** `nodeTexts(g, id, warn)` */
208
+ export declare function nodeTexts(g: NativeGraph, id: string, warn: (arg: string) => void): Array<string>
209
+
210
+ /** `CSS` */
211
+ export declare function pageCss(): string
212
+
213
+ /** `callLine(a)` and `renderPage(p)`: not in the npm package */
214
+ export declare function pageNotPorted(name: string): void
215
+
216
+ /** `parseExpr(src)`, as JSON */
217
+ export declare function parseExpr(src: string): string
218
+
219
+ /** `parsingOnce(run)`: `run` is a trapped callback that keeps its own result */
220
+ export declare function parsingOnce(run: () => void): void
221
+
222
+ export interface PathSteps {
223
+ state: Array<string>
224
+ event: Array<string | undefined | null>
225
+ taken: Array<string | undefined | null>
226
+ ctx: Uint16Array
227
+ }
228
+
229
+ /** `pathTo(m, ex, index)`, as JSON */
230
+ export declare function pathTo(m: NativeModel, ex: NativeExploration, index: number): string
231
+
232
+ /** `plain(g, key)` */
233
+ export declare function plain(g: NativeGraph, key: string): string
234
+
235
+ /** `planned(needs)`, as JSON entries of its two Maps */
236
+ export declare function planned(needs?: string | undefined | null): string
237
+
238
+ /** `pressLabel(g, state, event)` */
239
+ export declare function pressLabel(g: NativeGraph, state: string, event: string): string | null
240
+
241
+ /** `readNeeds(dir)`, as JSON (null when the folder has none) */
242
+ export declare function readNeeds(dir: string): string
243
+
244
+ /** what a trapped reader gives: the text it read, or the message of what it threw */
245
+ export interface ReadOut {
246
+ ok?: string
247
+ thrown?: string
248
+ }
249
+
250
+ /**
251
+ * `readYaml(text)`, as JSON. Its error is the library's YAMLParseError: the place the parser gives it (`pos`, as
252
+ * offsets, and `linePos`) is added to the error, as the library's error has it
253
+ */
254
+ export declare function readYaml(text: string): string
255
+
256
+ /** `refusedFor(g, p, page)` */
257
+ export declare function refusedFor(g: NativeNav, persona: string, page: string): boolean
258
+
259
+ /** `renderCheckScreens(g, kit, warn)`, as JSON */
260
+ export declare function renderCheckScreens(g: NativeGraph, kit: NativeKit | undefined | null, warn: (arg: string) => void): string
261
+
262
+ /** `renderScreens(g, warn, kit)` */
263
+ export declare function renderScreens(g: NativeGraph, warn: (arg: string) => void, kit?: NativeKit | undefined | null): string
264
+
265
+ /** `renderStageScreen(g, state, reveal, warn, kit)` */
266
+ export declare function renderStageScreen(g: NativeGraph, state: string, reveal: Array<string>, warn: (arg: string) => void, kit?: NativeKit | undefined | null): string
267
+
268
+ /** `resolveKit(graphDir, uiKit, flagValue)` */
269
+ export declare function resolveKit(graphDir: string, uiKit?: string | undefined | null, flagValue?: string | undefined | null): NativeKit | null
270
+
271
+ /** `responseLine(r)` */
272
+ export declare function responseLine(r: string): string
273
+
274
+ /**
275
+ * `delurio <args>`, the whole command line, in this process: its exit code. What it writes goes to the process's
276
+ * own stdout and stderr, flushed before it returns (nothing of Rust's runs after, to flush them at exit).
277
+ */
278
+ export declare function runCli(args: Array<string>): number
279
+
280
+ /** `shownIn(n, state)` */
281
+ export declare function shownInState(node: string, state: string): boolean
282
+
283
+ /** the graph `renderSpine` hands elkjs, as JSON */
284
+ export declare function spineGraph(g: NativeGraph, ex: NativeExploration, view: string, story?: Array<string> | undefined | null): string
285
+
286
+ /** the SVG `renderSpine` gives, from the layout elkjs gave back (as JSON) */
287
+ export declare function spineSvg(g: NativeGraph, ex: NativeExploration, view: string, story: Array<string> | undefined | null, laid: string): string
288
+
289
+ /** `stepsByEvents(m, main)` */
290
+ export declare function stepsByEvents(m: NativeModel, main?: string | undefined | null): PathSteps | null
291
+
292
+ /** the steps out of a pair: one entry per step in each list, the contexts one after the other */
293
+ export interface StepsOut {
294
+ event: Array<string | undefined | null>
295
+ target: Array<string>
296
+ taken: Array<string>
297
+ ctx: Uint16Array
298
+ }
299
+
300
+ /** `stepsTo(m, ex, index)` */
301
+ export declare function stepsTo(m: NativeModel, ex: NativeExploration, index: number): PathSteps
302
+
303
+ /** the warnings the YAML reader met since the last call (the library hands each to `process.emitWarning`), as JSON */
304
+ export declare function takeYamlWarnings(): string
305
+
306
+ /** `titleOf(flow, state)` */
307
+ export declare function titleOfState(flow: NativeValue, state: string): string
308
+
309
+ /** `transitionPath(state, st, event, i)` */
310
+ export declare function transitionPathOf(state: string, st: string, event: string | undefined | null, i: number): Array<string>
311
+
312
+ /** `transitionsOf(flow)` */
313
+ export declare function transitionsOf(flow: NativeValue): Array<string>
314
+
315
+ /** `unsupported(text)`, as JSON (null when nothing is) */
316
+ export declare function unsupported(text: string): string
317
+
318
+ /** the version of the checker the addon was built from */
319
+ export declare function version(): string
320
+
321
+ /** `viewOf(g, p)`, as JSON */
322
+ export declare function viewOf(g: NativeNav, persona: string): string
323
+
324
+ /** `walk(g, p)`, as JSON entries */
325
+ export declare function walk(g: NativeNav, persona: string): string
326
+
327
+ /** `wrap(text, max)` */
328
+ export declare function wrap(text: string, max: number): Array<string>
@@ -1,4 +1,4 @@
1
- import type { Value } from './expr.ts';
1
+ import type { Value } from './expr.js';
2
2
  export type PageKind = 'screen' | 'placeholder' | 'missing' | 'redirect' | 'external';
3
3
  export type FrameId = string;
4
4
  export type How = 'auto' | 'menu' | 'picker' | 'user' | 'link' | 'button';
package/js/nav.js ADDED
@@ -0,0 +1,70 @@
1
+ // A navigation graph (SPEC.md §6): the pages of an app, the ways between them, who may open them, and the walks each
2
+ // persona takes. The checker is the Rust one (crates/delurio-core/src/nav.rs); a graph loadNav read stays in the
3
+ // addon for the object it gave, and what the addon gives back names the graph's own entries, goals and personas.
4
+ import { readFileSync } from 'node:fs';
5
+ import { join } from 'node:path';
6
+ import { Trap, call, json, native, nativeNav, rememberNav, warnings } from './internal.js';
7
+
8
+ export const frameLevel = (e) => native.frameLevel(json(e));
9
+
10
+ export function loadNav(dir, locale, read = (file) => readFileSync(join(dir, file), 'utf8')) {
11
+ const t = new Trap();
12
+ try {
13
+ const n = call(t, () => native.loadNav(String(dir), locale ?? undefined, t.reader(read)));
14
+ return { g: rememberNav(JSON.parse(n.json()), n), warnings: n.warnings() };
15
+ } finally {
16
+ warnings();
17
+ }
18
+ }
19
+
20
+ export function holds(g, p, expr) {
21
+ return call(null, () => native.holds(nativeNav(g), json(p), expr ?? undefined));
22
+ }
23
+
24
+ export const refusedFor = (g, p, page) => call(null, () => native.refusedFor(nativeNav(g), json(p), String(page)));
25
+
26
+ // a reach as the addon gives it, its entry the graph's own
27
+ const reachOf = (g, r) => ({ page: r.page, clicks: r.clicks, via: r.via === null ? null : (g.entries[r.via] ?? null), prev: r.prev, usesData: r.usesData, byAddress: r.byAddress });
28
+
29
+ // a view as the addon reads it: its reach as the entries of the Map
30
+ const viewJson = (v) => ({ persona: v.persona, reach: v.reach instanceof Map ? [...v.reach] : Object.entries(v.reach ?? {}), standing: v.standing, landing: v.landing });
31
+
32
+ // Fewest clicks from "start"; ties go to the entry written first.
33
+ export function walk(g, p) {
34
+ const entries = JSON.parse(call(null, () => native.walk(nativeNav(g), json(p))));
35
+ return new Map(entries.map(([k, r]) => [k, reachOf(g, r)]));
36
+ }
37
+
38
+ export function pathTo(reach, page) {
39
+ const list = [...reach];
40
+ const way = JSON.parse(native.navPathTo(JSON.stringify(list), String(page)));
41
+ return way.map((k) => (k === null ? undefined : list[k][1].via));
42
+ }
43
+
44
+ export function viewOf(g, p) {
45
+ const v = JSON.parse(call(null, () => native.viewOf(nativeNav(g), json(p))));
46
+ return { persona: p, reach: new Map(v.reach.map(([k, r]) => [k, reachOf(g, r)])), standing: Object.fromEntries(v.standing), landing: v.landing };
47
+ }
48
+
49
+ export const frameReached = (g, v, frame) => native.frameReached(nativeNav(g), JSON.stringify(viewJson(v)), String(frame));
50
+
51
+ // One row per menu entry written in the graph; a column per persona.
52
+ export function menuRows(g, views) {
53
+ const rows = JSON.parse(call(null, () => native.menuRows(nativeNav(g), JSON.stringify(views.map(viewJson)))));
54
+ return rows.map((r) => ({ spec: r.spec, frame: r.frame, entry: r.entry === null ? undefined : g.entries[r.entry], frameKnown: r.frameKnown, cells: r.cells }));
55
+ }
56
+
57
+ export function checkGoals(g, views) {
58
+ const checks = JSON.parse(call(null, () => native.checkGoals(nativeNav(g), JSON.stringify(views.map(viewJson)))));
59
+ return checks.map((c) => ({ goal: c.goal === null ? undefined : g.goals[c.goal], persona: c.persona === null ? undefined : views[c.persona].persona, outcome: c.outcome, clicks: c.clicks }));
60
+ }
61
+
62
+ export function findings(g, views, goals) {
63
+ const checks = goals.map((c) => ({ goal: c.goal, persona: c.persona, outcome: c.outcome, clicks: c.clicks }));
64
+ return JSON.parse(call(null, () => native.findings(nativeNav(g), JSON.stringify(views.map(viewJson)), JSON.stringify(checks))));
65
+ }
66
+
67
+ // the permission codes a guard asks `'code' in held` about, named guards followed
68
+ export function guardCodes(g, src, depth = 0) {
69
+ return new Set(call(null, () => native.guardCodes(nativeNav(g), String(src), depth)));
70
+ }
package/js/needs.js ADDED
@@ -0,0 +1,30 @@
1
+ // A flow's needs held to their evidence, and a product's gaps to its needs (SPEC.md §13). The checker is the Rust one
2
+ // (crates/delurio-core/src/needs.rs).
3
+ import { call, json, native, warnings } from './internal.js';
4
+
5
+ const constants = JSON.parse(native.needsConstants());
6
+
7
+ export const NEEDS_FILE = constants.NEEDS_FILE;
8
+ export const GAPS_FILE = constants.GAPS_FILE;
9
+
10
+ export function readNeeds(dir) {
11
+ try {
12
+ return JSON.parse(call(null, () => native.readNeeds(String(dir))));
13
+ } finally {
14
+ warnings();
15
+ }
16
+ }
17
+
18
+ // what only missing needs name: the states and the nodes a walk leaves out, each with the needs that name it
19
+ export function planned(needs) {
20
+ const p = JSON.parse(native.planned(needs === null || needs === undefined ? undefined : json(needs)));
21
+ return { states: new Map(p.states), nodes: new Map(p.nodes) };
22
+ }
23
+
24
+ export function checkNeeds(files, app) {
25
+ try {
26
+ return JSON.parse(native.checkNeeds([...files].map(String), app ?? undefined));
27
+ } finally {
28
+ warnings();
29
+ }
30
+ }
@@ -1,6 +1,6 @@
1
- import type { Graph } from './graph.ts';
2
- import type { Exploration } from './model.ts';
3
- import type { PathStep } from './story.ts';
1
+ import type { Graph } from './graph.js';
2
+ import type { Exploration } from './model.js';
3
+ import type { PathStep } from './story.js';
4
4
  export type View = 'main' | 'full';
5
5
  /**
6
6
  * The flow's diagram as an SVG. Every state's group carries `data-state`, and every edge and its label `data-from` and
package/js/spine.js ADDED
@@ -0,0 +1,22 @@
1
+ // The flow's diagram as an SVG, laid out by elkjs: the graph handed to elkjs and the SVG drawn from its layout are the
2
+ // Rust checker's (crates/delurio-page/src/spine.rs); the layout is Node's own elkjs, the one delurio's dashboard lays
3
+ // its diagrams out with, so both give the same positions.
4
+ import ElkModule from 'elkjs/lib/elk.bundled.js';
5
+ import { call, native, nativeExploration, nativeGraph } from './internal.js';
6
+
7
+ // elkjs ships CommonJS: under Node ESM the default import is module.exports, which is the constructor
8
+ const Elk = ElkModule;
9
+
10
+ /**
11
+ * The flow's diagram as an SVG. Every state's group carries `data-state`, and every edge and its label `data-from` and
12
+ * `data-to`: one edge is drawn per pair of states, its label holding every transition between them. `story`: the
13
+ * states to draw as the story (`on-main`), in order.
14
+ */
15
+ export async function renderSpine(g, ex, view, story) {
16
+ const n = nativeGraph(g);
17
+ const x = nativeExploration(ex);
18
+ const states = story === null || story === undefined ? undefined : story.map((s) => String(s.state));
19
+ const root = JSON.parse(call(null, () => native.spineGraph(n, x, String(view), states)));
20
+ const laid = await new Elk().layout(root);
21
+ return call(null, () => native.spineSvg(n, x, String(view), states, JSON.stringify(laid)));
22
+ }
@@ -1,5 +1,4 @@
1
- import type { Graph } from './graph.ts';
2
- import type { Exploration, Model } from './model.ts';
1
+ // types only, for html.d.ts: what a flow hands over when it starts another (the module is internal to the checker)
3
2
  export interface HandOver {
4
3
  from: string;
5
4
  event: string | null;
@@ -8,4 +7,3 @@ export interface HandOver {
8
7
  found: boolean;
9
8
  problems: string[];
10
9
  }
11
- export declare function checkStarts(g: Graph, m: Model, ex: Exploration): HandOver[];
@@ -1,5 +1,5 @@
1
- import type { Graph, Scalar } from './graph.ts';
2
- import type { Exploration, Model } from './model.ts';
1
+ import type { Graph, Scalar } from './graph.js';
2
+ import type { Exploration, Model } from './model.js';
3
3
  export interface PathStep {
4
4
  state: string;
5
5
  ctx: Scalar[];
package/js/story.js ADDED
@@ -0,0 +1,22 @@
1
+ // A flow's stories: the steps to a situation the exploration reached, the main story the graph declares, and either
2
+ // told in plain words. The checker is the Rust one (crates/delurio-core/src/story.rs).
3
+ import { call, json, native, nativeExploration, nativeGraph, nativeModel, pathSteps, pathStepsOf } from './internal.js';
4
+
5
+ export function stepsTo(m, ex, index) {
6
+ return pathStepsOf(m, call(null, () => native.stepsTo(nativeModel(m), nativeExploration(ex), index)));
7
+ }
8
+
9
+ // The main story the graph declares: from a starting situation, send the events in order (`always` rules run by themselves).
10
+ export function stepsByEvents(m, main) {
11
+ const p = call(null, () => native.stepsByEvents(nativeModel(m), main === undefined ? undefined : json(main)));
12
+ return p === null || p === undefined ? null : pathStepsOf(m, p);
13
+ }
14
+
15
+ // The first success exit reachable through at least one screen: the story a person expects to read first.
16
+ export function mainStoryIndex(g, ex) {
17
+ return native.mainStoryIndex(nativeGraph(g), nativeExploration(ex)) ?? null;
18
+ }
19
+
20
+ export function narrate(g, m, steps) {
21
+ return JSON.parse(native.narrate(nativeGraph(g), nativeModel(m), pathSteps(m, steps)));
22
+ }
@@ -1,5 +1,5 @@
1
- import type { Graph } from './graph.ts';
2
- import type { Kit } from './kit.ts';
1
+ import type { Graph } from './graph.js';
2
+ import type { Kit } from './kit.js';
3
3
  type Warn = (message: string) => void;
4
4
  export declare function renderScreens(g: Graph, warn: Warn, kit?: Kit | null): string;
5
5
  export declare function renderStageScreen(g: Graph, state: string, reveal: string[], warn: Warn, kit?: Kit | null): string;
@@ -0,0 +1,29 @@
1
+ // A flow's screens as wireframes, drawn with the fixed components or with a kit. The checker is the Rust one
2
+ // (crates/delurio-core/src/wireframe.rs).
3
+ import { Trap, call, native, nativeGraph, nativeKit } from './internal.js';
4
+
5
+ export function renderScreens(g, warn, kit = null) {
6
+ const t = new Trap();
7
+ return call(t, () => native.renderScreens(nativeGraph(g), t.warner(warn), nativeKit(kit)));
8
+ }
9
+
10
+ // One state's screen for the tutorial stage. Nodes that depend on a flag (`when`) appear only when named in `reveal`.
11
+ export function renderStageScreen(g, state, reveal, warn, kit = null) {
12
+ const t = new Trap();
13
+ return call(t, () => native.renderStageScreen(nativeGraph(g), String(state), [...(reveal ?? [])].map(String), t.warner(warn), nativeKit(kit)));
14
+ }
15
+
16
+ // For `kit check`: every screen with all its nodes (flags revealed, no annotations), and what each node must expose.
17
+ export function renderCheckScreens(g, kit, warn) {
18
+ const t = new Trap();
19
+ const out = JSON.parse(call(t, () => native.renderCheckScreens(nativeGraph(g), nativeKit(kit), t.warner(warn))));
20
+ return {
21
+ html: out.html,
22
+ expected: out.expected.map((e) => ({ state: e.state, id: e.id, index: e.index, role: e.role, ...('roleGiven' in e ? { roleGiven: e.roleGiven } : {}), name: e.name, disabled: e.disabled })),
23
+ };
24
+ }
25
+
26
+ export function nodeTexts(g, id, warn) {
27
+ const t = new Trap();
28
+ return call(t, () => native.nodeTexts(nativeGraph(g), String(id), t.warner(warn)));
29
+ }
package/js/yaml.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /** the code of a YAML error, as the yaml library 2.9.1 names it */
2
+ type ErrorCode = 'ALIAS_PROPS' | 'BAD_ALIAS' | 'BAD_DIRECTIVE' | 'BAD_DQ_ESCAPE' | 'BAD_INDENT' | 'BAD_PROP_ORDER' | 'BAD_SCALAR_START' | 'BLOCK_AS_IMPLICIT_KEY' | 'BLOCK_IN_FLOW' | 'DUPLICATE_KEY' | 'IMPOSSIBLE' | 'KEY_OVER_1024_CHARS' | 'MISSING_CHAR' | 'MULTILINE_IMPLICIT_KEY' | 'MULTIPLE_ANCHORS' | 'MULTIPLE_DOCS' | 'MULTIPLE_TAGS' | 'NON_STRING_KEY' | 'RESOURCE_EXHAUSTION' | 'TAB_AS_INDENT' | 'TAG_RESOLVE_FAILED' | 'UNEXPECTED_TOKEN' | 'BAD_COLLECTION_TYPE';
3
+ export interface Unsupported {
4
+ offset: number;
5
+ line: number;
6
+ column: number;
7
+ code: ErrorCode;
8
+ message: string;
9
+ }
10
+ export declare function lineAndColumn(text: string, offset: number): {
11
+ line: number;
12
+ column: number;
13
+ };
14
+ export declare function unsupported(text: string): Unsupported | null;
15
+ export declare function parsingOnce<T>(run: () => T): T;
16
+ export declare function readYaml(text: string): unknown;
17
+ export declare function keyAt(text: string, path: string[]): {
18
+ line: number;
19
+ column: number;
20
+ };
package/js/yaml.js ADDED
@@ -0,0 +1,40 @@
1
+ // YAML as delurio reads it (SPEC.md §1): YAML 1.2 without anchors, aliases, tags, or keys that are lists or maps.
2
+ // The reader is the Rust port of the yaml library 2.9.1 (crates/delurio-core/src/yaml).
3
+ import { Trap, call, native, warnings } from './internal.js';
4
+
5
+ // the 1-based line and column of an offset into the text
6
+ export function lineAndColumn(text, offset) {
7
+ return JSON.parse(native.lineAndColumn(String(text), Number(offset)));
8
+ }
9
+
10
+ // the first place in the text, by offset, that delurio does not read; null when there is none
11
+ export function unsupported(text) {
12
+ return JSON.parse(native.unsupported(String(text)));
13
+ }
14
+
15
+ // `run`, with every text it reads through `readYaml` or `keyAt` parsed once; the same as `run` alone otherwise
16
+ export function parsingOnce(run) {
17
+ const t = new Trap();
18
+ let out;
19
+ native.parsingOnce(
20
+ t.runner(() => {
21
+ out = run();
22
+ }),
23
+ );
24
+ if (t.threw) throw t.error;
25
+ return out;
26
+ }
27
+
28
+ // the value of a graph file's text: the yaml library's `parse`, once nothing unsupported is found
29
+ export function readYaml(text) {
30
+ try {
31
+ return JSON.parse(call(null, () => native.readYaml(String(text))));
32
+ } finally {
33
+ warnings();
34
+ }
35
+ }
36
+
37
+ // 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
38
+ export function keyAt(text, path) {
39
+ return JSON.parse(native.keyAt(String(text), [...path].map(String)));
40
+ }