@delurio/cli 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/NOTICE +7 -0
- package/README.md +16 -15
- package/SPEC.md +37 -11
- package/js/changes.d.ts +17 -0
- package/js/cli.js +6 -0
- package/{dist → js}/edges.d.ts +2 -2
- package/js/edges.js +40 -0
- package/js/expr.js +25 -0
- package/js/graph.js +59 -0
- package/{dist → js}/html.d.ts +6 -6
- package/js/html.js +13 -0
- package/js/internal.js +408 -0
- package/js/kit.js +54 -0
- package/{dist → js}/model.d.ts +2 -2
- package/js/model.js +136 -0
- package/js/native.cjs +46 -0
- package/js/native.d.cts +322 -0
- package/{dist → js}/nav.d.ts +1 -1
- package/js/nav.js +70 -0
- package/{dist → js}/needs.d.ts +3 -2
- package/js/needs.js +30 -0
- package/{dist → js}/spine.d.ts +3 -3
- package/js/spine.js +22 -0
- package/{dist → js}/starts.d.ts +1 -3
- package/{dist → js}/story.d.ts +2 -2
- package/js/story.js +22 -0
- package/{dist → js}/wireframe.d.ts +4 -2
- package/js/wireframe.js +29 -0
- package/js/yaml.d.ts +20 -0
- package/js/yaml.js +40 -0
- package/package.json +41 -25
- package/schemas/domain.schema.json +3 -0
- package/dist/changes.d.ts +0 -25
- package/dist/changes.js +0 -101
- package/dist/check.d.ts +0 -23
- package/dist/check.js +0 -574
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -194
- package/dist/compare.d.ts +0 -34
- package/dist/compare.js +0 -143
- package/dist/diff-flow.d.ts +0 -33
- package/dist/diff-flow.js +0 -547
- package/dist/diff-nav.d.ts +0 -20
- package/dist/diff-nav.js +0 -401
- package/dist/diff.d.ts +0 -25
- package/dist/diff.js +0 -331
- package/dist/domain-names.d.ts +0 -18
- package/dist/domain-names.js +0 -124
- package/dist/domain.d.ts +0 -25
- package/dist/domain.js +0 -110
- package/dist/edges.js +0 -120
- package/dist/expr.js +0 -157
- package/dist/graph.js +0 -236
- package/dist/html.js +0 -311
- package/dist/index-page.d.ts +0 -12
- package/dist/index-page.js +0 -50
- package/dist/invokes.d.ts +0 -10
- package/dist/invokes.js +0 -67
- package/dist/kit.js +0 -710
- package/dist/mermaid.d.ts +0 -3
- package/dist/mermaid.js +0 -50
- package/dist/model.js +0 -608
- package/dist/nav-page.d.ts +0 -15
- package/dist/nav-page.js +0 -283
- package/dist/nav.js +0 -578
- package/dist/needs.js +0 -311
- package/dist/pan.d.ts +0 -2
- package/dist/pan.js +0 -252
- package/dist/schemas.d.ts +0 -10
- package/dist/schemas.js +0 -266
- package/dist/spine.js +0 -156
- package/dist/starts.js +0 -88
- package/dist/story.js +0 -109
- package/dist/tutorial-check.d.ts +0 -9
- package/dist/tutorial-check.js +0 -297
- package/dist/ui-check.d.ts +0 -8
- package/dist/ui-check.js +0 -136
- package/dist/watch.d.ts +0 -5
- package/dist/watch.js +0 -114
- package/dist/wireframe.js +0 -273
- package/dist/yaml.d.ts +0 -19
- package/dist/yaml.js +0 -134
- /package/{dist → js}/expr.d.ts +0 -0
- /package/{dist → js}/graph.d.ts +0 -0
- /package/{dist → js}/kit.d.ts +0 -0
package/dist/cli.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// delurio: the open checker and page of delurio-graph/0 (SPEC.md). Reads graph files and nothing else: no network, no
|
|
3
|
-
// account, no model.
|
|
4
|
-
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
5
|
-
import { existsSync, statSync } from 'node:fs';
|
|
6
|
-
import { basename, join, relative, resolve, sep } from 'node:path';
|
|
7
|
-
import { GraphError, humanize, load } from './graph.js';
|
|
8
|
-
import { checkAssertions, explore, finalPaths, Model, ModelError } from './model.js';
|
|
9
|
-
import { renderMermaid } from './mermaid.js';
|
|
10
|
-
import { renderSpine } from './spine.js';
|
|
11
|
-
import { renderScreens } from './wireframe.js';
|
|
12
|
-
import { renderPage } from './html.js';
|
|
13
|
-
import { checkChanges, flowDomain } from './changes.js';
|
|
14
|
-
import { checkStarts } from './starts.js';
|
|
15
|
-
import { mainStoryIndex, narrate, stepsByEvents, stepsTo } from './story.js';
|
|
16
|
-
import { checkGoals, findings, loadNav, menuRows, viewOf } from './nav.js';
|
|
17
|
-
import { renderNavMermaid, renderNavPage } from './nav-page.js';
|
|
18
|
-
import { DIFF_USAGE, diffMain } from './diff.js';
|
|
19
|
-
import { KitError, resolveKit } from './kit.js';
|
|
20
|
-
import { CHECK_USAGE, checkMain, count, graphDirs } from './check.js';
|
|
21
|
-
import { renderIndexPage } from './index-page.js';
|
|
22
|
-
import { watchPages } from './watch.js';
|
|
23
|
-
const USAGE = [
|
|
24
|
-
'usage:',
|
|
25
|
-
CHECK_USAGE,
|
|
26
|
-
' delurio page <graph dir | graphs folder> [--out <dir>] [--kit <kit>] [--locale <code>] [--strict] [--watch] [--serve [--port <n>]]',
|
|
27
|
-
' writes the graph\'s page: <out>/index.html and its diagram (default out: <graph dir>/viz); on a folder of graphs,',
|
|
28
|
-
' the page of each at <out>/<its path> and an index of them all at <out>/index.html (default out: <folder>/viz);',
|
|
29
|
-
' --watch writes them again on every change under the folder; --serve also shows them at http://127.0.0.1:<port>/',
|
|
30
|
-
' (default 4600) and reloads the open page after each write',
|
|
31
|
-
DIFF_USAGE.replaceAll('node src/cli.ts', 'delurio'),
|
|
32
|
-
].join('\n').replaceAll('node src/cli.ts', 'delurio');
|
|
33
|
-
const flag = (args, name) => {
|
|
34
|
-
const i = args.indexOf(name);
|
|
35
|
-
return i >= 0 ? args[i + 1] : undefined;
|
|
36
|
-
};
|
|
37
|
-
function navPage(dir, out, args) {
|
|
38
|
-
const { g, warnings } = loadNav(dir, flag(args, '--locale'));
|
|
39
|
-
const views = g.personas.map((p) => viewOf(g, p));
|
|
40
|
-
const rows = menuRows(g, views);
|
|
41
|
-
const goals = checkGoals(g, views);
|
|
42
|
-
const found = findings(g, views, goals);
|
|
43
|
-
mkdirSync(out, { recursive: true });
|
|
44
|
-
writeFileSync(join(out, 'index.html'), renderNavPage({ g, views, rows, goals, found, repo: null, warnings }));
|
|
45
|
-
writeFileSync(join(out, 'nav.mmd'), renderNavMermaid(g));
|
|
46
|
-
const problems = found.filter((f) => f.level === 'problem');
|
|
47
|
-
console.log(`${g.id}: ${count(Object.keys(g.pages).length, 'page')}, ${count(g.specs.length, 'way')} to move, ${g.personas.length} ${g.personas.length === 1 ? 'kind' : 'kinds'} of user; ${count(problems.length, 'problem')}, ${count(found.length - problems.length, 'note')}`);
|
|
48
|
-
for (const w of warnings)
|
|
49
|
-
console.error(`warning: ${w}`);
|
|
50
|
-
return {
|
|
51
|
-
code: args.includes('--strict') && (warnings.length > 0 || problems.length > 0) ? 2 : 0,
|
|
52
|
-
entry: { path: '', kind: 'nav', id: g.id, title: `${g.title}: where people go`, status: g.status, holds: 0, total: problems.length, warnings, error: null },
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
async function flowPage(dir, out, args) {
|
|
56
|
-
const warnings = [];
|
|
57
|
-
const warn = (m) => {
|
|
58
|
-
if (!warnings.includes(m))
|
|
59
|
-
warnings.push(m);
|
|
60
|
-
};
|
|
61
|
-
const g = load(dir);
|
|
62
|
-
const kit = resolveKit(dir, g.ui.kit, flag(args, '--kit'));
|
|
63
|
-
const model = new Model(g.flow);
|
|
64
|
-
const ex = explore(model);
|
|
65
|
-
const assertions = checkAssertions(model, ex);
|
|
66
|
-
const finals = finalPaths(model, ex);
|
|
67
|
-
const mainIndex = mainStoryIndex(g, ex);
|
|
68
|
-
const declared = g.flow.main === undefined ? null : stepsByEvents(model, g.flow.main);
|
|
69
|
-
if (g.flow.main !== undefined && declared === null)
|
|
70
|
-
warn('the declared main story cannot be walked: an event is not possible where it is sent');
|
|
71
|
-
const mainSteps = declared ?? (mainIndex === null ? null : stepsTo(model, ex, mainIndex));
|
|
72
|
-
const main = mainSteps === null ? null : narrate(g, model, mainSteps);
|
|
73
|
-
const spineMain = await renderSpine(g, ex, 'main', mainSteps);
|
|
74
|
-
const spineFull = await renderSpine(g, ex, 'full', mainSteps);
|
|
75
|
-
const screens = renderScreens(g, warn, kit);
|
|
76
|
-
const handOvers = checkStarts(g, model, ex);
|
|
77
|
-
for (const h of handOvers)
|
|
78
|
-
for (const p of h.problems)
|
|
79
|
-
warn(`${h.from} starts ${h.flow}: ${p}`);
|
|
80
|
-
for (const p of checkChanges(g)?.problems ?? [])
|
|
81
|
-
warn(p);
|
|
82
|
-
mkdirSync(out, { recursive: true });
|
|
83
|
-
writeFileSync(join(out, 'index.html'), renderPage({ g, m: model, ex, assertions, finals, main, spineMain, spineFull, screens, kit, handOvers, domain: flowDomain(g) }));
|
|
84
|
-
writeFileSync(join(out, 'flow.mmd'), renderMermaid(g, ex));
|
|
85
|
-
const violated = assertions.filter((a) => a.violation !== undefined);
|
|
86
|
-
console.log(`${g.flow.id}: ${count(Object.keys(g.flow.states).length, 'state')}, ${count(ex.configs.length, 'configuration')} from ${count(ex.starts, 'start')}, ${assertions.length - violated.length}/${assertions.length} assertions hold`);
|
|
87
|
-
for (const a of violated)
|
|
88
|
-
console.log(` violated: ${a.id}`);
|
|
89
|
-
for (const w of warnings)
|
|
90
|
-
console.error(`warning: ${w}`);
|
|
91
|
-
return {
|
|
92
|
-
code: args.includes('--strict') && (violated.length > 0 || warnings.length > 0) ? 2 : 0,
|
|
93
|
-
entry: { path: '', kind: 'flow', id: g.flow.id, title: g.flow.title ?? humanize(g.flow.id), status: g.flow.status ?? null, holds: assertions.length - violated.length, total: assertions.length, warnings, error: null },
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
const isGraph = (dir) => existsSync(join(dir, 'flow.yaml')) || existsSync(join(dir, 'nav.yaml'));
|
|
97
|
-
// every graph under the folder, each into <out>/<its path>, and the index of them all. A graph that cannot be loaded
|
|
98
|
-
// is listed as such and the rest are still written: exit 1 when one cannot be loaded, else 2 under --strict when one
|
|
99
|
-
// would fail on its own, else 0.
|
|
100
|
-
async function treePages(root, out, args) {
|
|
101
|
-
const dirs = graphDirs(root);
|
|
102
|
-
if (dirs.length === 0) {
|
|
103
|
-
const message = `${root} is not a graph and holds none: there is no flow.yaml or nav.yaml in it or under it`;
|
|
104
|
-
console.error(`error: ${message}`);
|
|
105
|
-
return { code: 1, message };
|
|
106
|
-
}
|
|
107
|
-
const entries = [];
|
|
108
|
-
let broken = false;
|
|
109
|
-
let failing = false;
|
|
110
|
-
for (const dir of dirs) {
|
|
111
|
-
const path = relative(root, dir).split(sep).join('/');
|
|
112
|
-
const nav = !existsSync(join(dir, 'flow.yaml'));
|
|
113
|
-
try {
|
|
114
|
-
const { code, entry } = nav ? navPage(dir, join(out, path), args) : await flowPage(dir, join(out, path), args);
|
|
115
|
-
entries.push({ ...entry, path });
|
|
116
|
-
failing ||= code !== 0;
|
|
117
|
-
}
|
|
118
|
-
catch (err) {
|
|
119
|
-
if (!loadError(err))
|
|
120
|
-
throw err;
|
|
121
|
-
broken = true;
|
|
122
|
-
const message = err.message.split('\n')[0].replace(/:$/, '');
|
|
123
|
-
console.error(`error: ${path}: ${message}`);
|
|
124
|
-
entries.push({ path, kind: nav ? 'nav' : 'flow', id: null, title: path, status: null, holds: 0, total: 0, warnings: [], error: message });
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
mkdirSync(out, { recursive: true });
|
|
128
|
-
writeFileSync(join(out, 'index.html'), renderIndexPage(basename(resolve(root)), entries));
|
|
129
|
-
console.log(`wrote ${join(out, 'index.html')} and the pages of ${count(entries.length - entries.filter((e) => e.error !== null).length, 'graph')} under ${out}`);
|
|
130
|
-
const firstError = entries.find((e) => e.error !== null);
|
|
131
|
-
return { code: broken ? 1 : failing ? 2 : 0, message: firstError === undefined ? '' : `${firstError.path}: ${firstError.error}` };
|
|
132
|
-
}
|
|
133
|
-
const loadError = (err) => err instanceof GraphError || err instanceof ModelError || err instanceof KitError || (err instanceof Error && err.name === 'YAMLParseError');
|
|
134
|
-
// one graph's page, or the pages of every graph under the folder
|
|
135
|
-
async function writePages(dir, out, args) {
|
|
136
|
-
if (!isGraph(dir))
|
|
137
|
-
return treePages(dir, out, args);
|
|
138
|
-
try {
|
|
139
|
-
const flow = existsSync(join(dir, 'flow.yaml'));
|
|
140
|
-
const { code } = flow ? await flowPage(dir, out, args) : navPage(dir, out, args);
|
|
141
|
-
console.log(`wrote ${join(out, 'index.html')} and ${join(out, flow ? 'flow.mmd' : 'nav.mmd')}`);
|
|
142
|
-
return { code, message: '' };
|
|
143
|
-
}
|
|
144
|
-
catch (err) {
|
|
145
|
-
if (!loadError(err))
|
|
146
|
-
throw err;
|
|
147
|
-
const message = err.message.split('\n')[0].replace(/:$/, '');
|
|
148
|
-
console.error(`error: ${message}`);
|
|
149
|
-
return { code: 1, message };
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
async function main() {
|
|
153
|
-
const args = process.argv.slice(2);
|
|
154
|
-
if (args[0] === 'check')
|
|
155
|
-
return checkMain(args.slice(1));
|
|
156
|
-
if (args[0] === 'diff')
|
|
157
|
-
return diffMain(args.slice(1));
|
|
158
|
-
if (args[0] === 'page') {
|
|
159
|
-
const rest = args.slice(1);
|
|
160
|
-
const withValue = ['--out', '--kit', '--locale', '--port'];
|
|
161
|
-
const dir = rest.find((a, i) => !a.startsWith('--') && !withValue.includes(rest[i - 1] ?? ''));
|
|
162
|
-
if (dir === undefined) {
|
|
163
|
-
console.error(USAGE);
|
|
164
|
-
return 1;
|
|
165
|
-
}
|
|
166
|
-
if (!existsSync(dir) || !statSync(dir).isDirectory()) {
|
|
167
|
-
console.error(`error: ${dir} is not a folder`);
|
|
168
|
-
return 1;
|
|
169
|
-
}
|
|
170
|
-
const out = resolve(flag(rest, '--out') ?? join(dir, 'viz'));
|
|
171
|
-
const first = await writePages(dir, out, rest);
|
|
172
|
-
const serve = rest.includes('--serve');
|
|
173
|
-
if (!serve && !rest.includes('--watch'))
|
|
174
|
-
return first.code;
|
|
175
|
-
const port = Number(flag(rest, '--port') ?? 4600);
|
|
176
|
-
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
177
|
-
console.error(`error: --port is a port number, not ${flag(rest, '--port')}`);
|
|
178
|
-
return 1;
|
|
179
|
-
}
|
|
180
|
-
return watchPages(dir, out, async () => {
|
|
181
|
-
const again = await writePages(dir, out, rest);
|
|
182
|
-
return { ok: again.code !== 1, message: again.message };
|
|
183
|
-
}, serve ? port : null);
|
|
184
|
-
}
|
|
185
|
-
console.error(USAGE);
|
|
186
|
-
return args.length === 0 || args.includes('--help') ? 0 : 1;
|
|
187
|
-
}
|
|
188
|
-
main().then((code) => process.exit(code), (err) => {
|
|
189
|
-
if (err instanceof GraphError || err instanceof ModelError || err instanceof KitError) {
|
|
190
|
-
console.error(`error: ${err.message}`);
|
|
191
|
-
process.exit(1);
|
|
192
|
-
}
|
|
193
|
-
throw err;
|
|
194
|
-
});
|
package/dist/compare.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export type Op = 'added' | 'removed' | 'changed' | 'moved';
|
|
2
|
-
export interface Change {
|
|
3
|
-
area: string;
|
|
4
|
-
key: string;
|
|
5
|
-
op: Op;
|
|
6
|
-
field?: string;
|
|
7
|
-
before?: unknown;
|
|
8
|
-
after?: unknown;
|
|
9
|
-
say: string | null;
|
|
10
|
-
}
|
|
11
|
-
export interface Shift {
|
|
12
|
-
topic: string;
|
|
13
|
-
key: string;
|
|
14
|
-
persona?: string;
|
|
15
|
-
before: unknown;
|
|
16
|
-
after: unknown;
|
|
17
|
-
say: string;
|
|
18
|
-
detail: string[];
|
|
19
|
-
worse: boolean;
|
|
20
|
-
}
|
|
21
|
-
export declare function canon(v: unknown): string;
|
|
22
|
-
export declare const same: (a: unknown, b: unknown) => boolean;
|
|
23
|
-
export declare function union(before: object | undefined, after: object | undefined): string[];
|
|
24
|
-
export declare const quote: (s: string) => string;
|
|
25
|
-
export declare const joinWords: (xs: string[]) => string;
|
|
26
|
-
export declare function matchOrdered<T>(before: T[], after: T[], keys: Array<(x: T) => string | null>): Array<[number, number]>;
|
|
27
|
-
export declare function moved(pairs: Array<[number, number]>): Array<[number, number]>;
|
|
28
|
-
export declare function deepDiff(area: string, key: string, before: unknown, after: unknown, out: Change[], path?: string[]): void;
|
|
29
|
-
export declare function fieldChanges(area: string, key: string, before: Record<string, unknown>, after: Record<string, unknown>, fields: string[], say: (field: string, b: unknown, a: unknown) => string | null): Change[];
|
|
30
|
-
export declare function otherKeys(key: string, before: Record<string, unknown>, after: Record<string, unknown>, known: string[], out: Change[]): void;
|
|
31
|
-
export declare function listChanges(before: string[] | undefined, after: string[] | undefined): {
|
|
32
|
-
added: string[];
|
|
33
|
-
removed: string[];
|
|
34
|
-
};
|
package/dist/compare.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
// What the revision diff is made of, for both kinds of graph: structural changes keyed by id, and changes in behaviour.
|
|
2
|
-
// Nothing here knows what a flow or a page is; diff-flow.ts and diff-nav.ts do.
|
|
3
|
-
const own = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
|
4
|
-
const isMap = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
5
|
-
// a value as text with sorted keys, so two values written in a different key order compare equal
|
|
6
|
-
export function canon(v) {
|
|
7
|
-
if (v === undefined)
|
|
8
|
-
return '~';
|
|
9
|
-
if (Array.isArray(v))
|
|
10
|
-
return `[${v.map(canon).join(',')}]`;
|
|
11
|
-
if (isMap(v)) {
|
|
12
|
-
const keys = Object.keys(v).filter((k) => v[k] !== undefined).sort();
|
|
13
|
-
return `{${keys.map((k) => `${JSON.stringify(k)}:${canon(v[k])}`).join(',')}}`;
|
|
14
|
-
}
|
|
15
|
-
return JSON.stringify(v);
|
|
16
|
-
}
|
|
17
|
-
export const same = (a, b) => canon(a) === canon(b);
|
|
18
|
-
// the keys of both maps: the new order first, then the keys only the old one has, in its order
|
|
19
|
-
export function union(before, after) {
|
|
20
|
-
const out = Object.keys(after ?? {});
|
|
21
|
-
for (const k of Object.keys(before ?? {}))
|
|
22
|
-
if (!own(after ?? {}, k))
|
|
23
|
-
out.push(k);
|
|
24
|
-
return out;
|
|
25
|
-
}
|
|
26
|
-
export const quote = (s) => `“${s}”`;
|
|
27
|
-
export const joinWords = (xs) => (xs.length <= 1 ? xs.join('') : `${xs.slice(0, -1).join(', ')} and ${xs[xs.length - 1]}`);
|
|
28
|
-
// Pairs the items of two ordered lists (the rules of an `always`, the alternatives of one event, the entries of a nav graph).
|
|
29
|
-
// The first key pairs items in the order they occur (the n-th with the n-th); a later key pairs what is left only when it is
|
|
30
|
-
// unique on both sides, so nothing is paired by guesswork. Returns [before index, after index] pairs, sorted by before index.
|
|
31
|
-
export function matchOrdered(before, after, keys) {
|
|
32
|
-
const pairs = [];
|
|
33
|
-
const usedB = new Set();
|
|
34
|
-
const usedA = new Set();
|
|
35
|
-
keys.forEach((key, round) => {
|
|
36
|
-
const group = (xs, used) => {
|
|
37
|
-
const m = new Map();
|
|
38
|
-
xs.forEach((x, i) => {
|
|
39
|
-
if (used.has(i))
|
|
40
|
-
return;
|
|
41
|
-
const k = key(x);
|
|
42
|
-
if (k !== null)
|
|
43
|
-
m.set(k, [...(m.get(k) ?? []), i]);
|
|
44
|
-
});
|
|
45
|
-
return m;
|
|
46
|
-
};
|
|
47
|
-
const gb = group(before, usedB);
|
|
48
|
-
const ga = group(after, usedA);
|
|
49
|
-
for (const [k, bs] of gb) {
|
|
50
|
-
const as = ga.get(k);
|
|
51
|
-
if (as === undefined)
|
|
52
|
-
continue;
|
|
53
|
-
if (round > 0 && (bs.length > 1 || as.length > 1))
|
|
54
|
-
continue;
|
|
55
|
-
for (let j = 0; j < Math.min(bs.length, as.length); j++) {
|
|
56
|
-
pairs.push([bs[j], as[j]]);
|
|
57
|
-
usedB.add(bs[j]);
|
|
58
|
-
usedA.add(as[j]);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
return pairs.sort((x, y) => x[0] - y[0]);
|
|
63
|
-
}
|
|
64
|
-
// The pairs that changed place relative to the others: the pairs outside the longest run that keeps its order.
|
|
65
|
-
// An item that only shifted because something was added or removed before it is not moved.
|
|
66
|
-
export function moved(pairs) {
|
|
67
|
-
const sorted = [...pairs].sort((x, y) => x[0] - y[0]);
|
|
68
|
-
const n = sorted.length;
|
|
69
|
-
const len = new Array(n).fill(1);
|
|
70
|
-
const prev = new Array(n).fill(-1);
|
|
71
|
-
for (let i = 0; i < n; i++) {
|
|
72
|
-
for (let j = 0; j < i; j++) {
|
|
73
|
-
if (sorted[j][1] < sorted[i][1] && len[j] + 1 > len[i]) {
|
|
74
|
-
len[i] = len[j] + 1;
|
|
75
|
-
prev[i] = j;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
let best = -1;
|
|
80
|
-
for (let i = 0; i < n; i++)
|
|
81
|
-
if (best < 0 || len[i] > len[best])
|
|
82
|
-
best = i;
|
|
83
|
-
const keep = new Set();
|
|
84
|
-
for (let i = best; i >= 0; i = prev[i])
|
|
85
|
-
keep.add(i);
|
|
86
|
-
return sorted.filter((_, i) => !keep.has(i));
|
|
87
|
-
}
|
|
88
|
-
// A field-by-field comparison for data graph-viz does not interpret (domain.yaml, unknown keys): maps by key, lists whose
|
|
89
|
-
// items all carry an `id` by id, anything else as one value. A field called `source` or `evidence` is a citation.
|
|
90
|
-
export function deepDiff(area, key, before, after, out, path = []) {
|
|
91
|
-
if (same(before, after))
|
|
92
|
-
return;
|
|
93
|
-
if (isMap(before) && isMap(after)) {
|
|
94
|
-
for (const k of union(before, after))
|
|
95
|
-
deepDiff(area, key, before[k], after[k], out, [...path, k]);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const byId = (v) => Array.isArray(v) && v.every((x) => isMap(x) && typeof x.id === 'string');
|
|
99
|
-
if (byId(before) && byId(after) && before.length + after.length > 0) {
|
|
100
|
-
const mb = Object.fromEntries(before.map((x) => [x.id, x]));
|
|
101
|
-
const ma = Object.fromEntries(after.map((x) => [x.id, x]));
|
|
102
|
-
if (Object.keys(mb).length === before.length && Object.keys(ma).length === after.length) {
|
|
103
|
-
for (const id of union(mb, ma))
|
|
104
|
-
deepDiff(area, key, mb[id], ma[id], out, [...path, id]);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const last = path[path.length - 1];
|
|
109
|
-
out.push({
|
|
110
|
-
area: last === 'source' || last === 'evidence' ? 'citations' : area,
|
|
111
|
-
key,
|
|
112
|
-
op: before === undefined ? 'added' : after === undefined ? 'removed' : 'changed',
|
|
113
|
-
field: path.length === 0 ? undefined : path.join('.'),
|
|
114
|
-
before,
|
|
115
|
-
after,
|
|
116
|
-
say: null,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
// the plain old → new comparison of named fields of one item; `say` words the change for people, or gives null
|
|
120
|
-
export function fieldChanges(area, key, before, after, fields, say) {
|
|
121
|
-
const out = [];
|
|
122
|
-
for (const f of fields) {
|
|
123
|
-
if (same(before[f], after[f]))
|
|
124
|
-
continue;
|
|
125
|
-
const citation = f === 'source' || f === 'evidence';
|
|
126
|
-
out.push({ area: citation ? 'citations' : area, key, op: 'changed', field: f, before: before[f], after: after[f], say: citation ? null : say(f, before[f], after[f]) });
|
|
127
|
-
}
|
|
128
|
-
return out;
|
|
129
|
-
}
|
|
130
|
-
// the keys of an item that are not in `known`, compared as data
|
|
131
|
-
export function otherKeys(key, before, after, known, out) {
|
|
132
|
-
for (const k of union(before, after)) {
|
|
133
|
-
if (known.includes(k))
|
|
134
|
-
continue;
|
|
135
|
-
deepDiff('other', key, before[k], after[k], out, [k]);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
// added and removed items of two lists of plain words
|
|
139
|
-
export function listChanges(before, after) {
|
|
140
|
-
const b = before ?? [];
|
|
141
|
-
const a = after ?? [];
|
|
142
|
-
return { added: a.filter((x) => !b.includes(x)), removed: b.filter((x) => !a.includes(x)) };
|
|
143
|
-
}
|
package/dist/diff-flow.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { Graph } from './graph.ts';
|
|
2
|
-
import { Model } from './model.ts';
|
|
3
|
-
import type { Exploration } from './model.ts';
|
|
4
|
-
import type { PathStep } from './story.ts';
|
|
5
|
-
import type { Change, Shift } from './compare.ts';
|
|
6
|
-
export interface FlowSide {
|
|
7
|
-
g: Graph;
|
|
8
|
-
domain: {
|
|
9
|
-
file: string;
|
|
10
|
-
doc: unknown;
|
|
11
|
-
} | null;
|
|
12
|
-
}
|
|
13
|
-
export interface FlowStructure {
|
|
14
|
-
changes: Change[];
|
|
15
|
-
ways: Array<[string, string]>;
|
|
16
|
-
added: string[];
|
|
17
|
-
}
|
|
18
|
-
export declare function flowStructure(b: FlowSide, a: FlowSide): FlowStructure;
|
|
19
|
-
interface Run {
|
|
20
|
-
g: Graph;
|
|
21
|
-
m: Model;
|
|
22
|
-
ex: Exploration;
|
|
23
|
-
violations: Map<string, number>;
|
|
24
|
-
exits: Map<string, number>;
|
|
25
|
-
moves: number;
|
|
26
|
-
main: PathStep[] | null;
|
|
27
|
-
mainBroken: boolean;
|
|
28
|
-
reached: Set<string>;
|
|
29
|
-
}
|
|
30
|
-
export declare function runSide(g: Graph, side: string): Run;
|
|
31
|
-
export declare function flowBehaviour(rb: Run, ra: Run, s: FlowStructure): Shift[];
|
|
32
|
-
export declare function flowSameBehaviour(r: Run): string;
|
|
33
|
-
export {};
|