archidocs 1.2.0 → 1.3.1
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/README.md +62 -13
- package/dist/cli/commands.d.ts +231 -10
- package/dist/cli/commands.js +134 -9
- package/dist/cli/dev.d.ts +5 -6
- package/dist/cli/dev.js +12 -14
- package/dist/cli/diff-format.d.ts +1 -5
- package/dist/cli/init.d.ts +1 -1
- package/dist/cli/init.js +2 -2
- package/dist/cli/main.js +2 -329
- package/dist/cli/run.d.ts +18 -0
- package/dist/cli/run.js +283 -0
- package/dist/commands/build.d.ts +51 -0
- package/dist/commands/build.js +39 -0
- package/dist/commands/check.d.ts +8 -0
- package/dist/commands/check.js +5 -0
- package/dist/commands/diff.d.ts +29 -0
- package/dist/commands/diff.js +25 -0
- package/dist/commands/export.d.ts +41 -0
- package/dist/commands/export.js +47 -0
- package/dist/commands/history.d.ts +18 -0
- package/dist/commands/history.js +9 -0
- package/dist/commands/index.d.ts +11 -0
- package/dist/commands/index.js +11 -0
- package/dist/core/compare.d.ts +2 -13
- package/dist/core/compare.js +2 -35
- package/dist/core/index.d.ts +3 -6
- package/dist/core/index.js +3 -6
- package/dist/core/load.d.ts +0 -2
- package/dist/core/load.js +5 -6
- package/dist/core/rules.d.ts +10 -0
- package/dist/core/rules.js +186 -7
- package/dist/core/views/compare.d.ts +12 -0
- package/dist/core/views/compare.js +37 -0
- package/dist/core/{deployment-views.d.ts → views/deployment.d.ts} +4 -5
- package/dist/core/{deployment-views.js → views/deployment.js} +5 -7
- package/dist/core/{dynamic-views.d.ts → views/dynamic.d.ts} +1 -3
- package/dist/core/{dynamic-views.js → views/dynamic.js} +4 -8
- package/dist/core/views/generated.d.ts +18 -0
- package/dist/core/views/generated.js +92 -0
- package/dist/core/views/ids.d.ts +36 -0
- package/dist/core/views/ids.js +51 -0
- package/dist/core/views/index.d.ts +13 -0
- package/dist/core/views/index.js +12 -0
- package/dist/core/views/lens.d.ts +27 -0
- package/dist/core/views/lens.js +112 -0
- package/dist/core/views/model.d.ts +21 -0
- package/dist/core/views/model.js +69 -0
- package/dist/core/views/resolve.d.ts +42 -0
- package/dist/core/views/resolve.js +81 -0
- package/dist/core/{save-as-view.d.ts → views/save-as-view.d.ts} +2 -2
- package/dist/core/{save-as-view.js → views/save-as-view.js} +13 -10
- package/dist/core/{saved-views.d.ts → views/saved.d.ts} +4 -18
- package/dist/core/{saved-views.js → views/saved.js} +8 -103
- package/dist/core/views/types.d.ts +91 -0
- package/dist/core/views/types.js +2 -0
- package/dist/core/workspace-files.d.ts +13 -0
- package/dist/core/workspace-files.js +20 -0
- package/dist/git.d.ts +2 -0
- package/dist/git.js +14 -4
- package/dist/history/git.d.ts +0 -10
- package/dist/history/git.js +1 -30
- package/dist/history/index.d.ts +15 -31
- package/dist/history/index.js +47 -43
- package/dist/history/points.d.ts +23 -0
- package/dist/history/points.js +28 -0
- package/dist/history/site.d.ts +30 -0
- package/dist/history/site.js +37 -0
- package/dist/mcp/errors.d.ts +37 -0
- package/dist/mcp/errors.js +35 -0
- package/dist/mcp/history.d.ts +4 -4
- package/dist/mcp/history.js +56 -116
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/server.d.ts +1 -2
- package/dist/mcp/server.js +30 -29
- package/dist/mcp/site.d.ts +12 -0
- package/dist/mcp/site.js +46 -0
- package/dist/mcp/source.d.ts +14 -7
- package/dist/mcp/source.js +25 -99
- package/dist/render/layout.d.ts +20 -3
- package/dist/render/layout.js +49 -12
- package/dist/render/sequence-svg.d.ts +1 -1
- package/dist/render/sequence.d.ts +1 -1
- package/dist/render/svg.d.ts +1 -1
- package/dist/render/svg.js +4 -4
- package/dist/revisions/find.d.ts +64 -0
- package/dist/revisions/find.js +85 -0
- package/dist/revisions/index.d.ts +57 -0
- package/dist/revisions/index.js +24 -0
- package/dist/revisions/site.d.ts +82 -0
- package/dist/revisions/site.js +157 -0
- package/dist/revisions/text.d.ts +8 -0
- package/dist/revisions/text.js +17 -0
- package/dist/revisions/touching.d.ts +7 -0
- package/dist/revisions/touching.js +7 -0
- package/dist/schema/adr.js +18 -13
- package/dist/schema/workspace.js +226 -130
- package/dist/viewer/assets/index-C0lIIm8V.js +138 -0
- package/dist/viewer/assets/index-YFA-pYjQ.css +1 -0
- package/dist/viewer/assets/{layout.worker-Bg-OaLVN.js → layout.worker-BRHAGJrD.js} +1 -1
- package/dist/viewer/assets/{png-BDKIXtm5.js → png-DMwnpRCt.js} +1 -1
- package/dist/viewer/assets/{svg-Bulv5YWn.js → svg-DN6lMeZo.js} +2 -2
- package/dist/viewer/index.html +2 -2
- package/dist/workspace/index.d.ts +37 -0
- package/dist/workspace/index.js +52 -0
- package/guide/SKILL.md +1 -1
- package/guide/topics/bootstrap.md +1 -1
- package/guide/topics/relationships.md +1 -1
- package/package.json +4 -3
- package/schemas/adr.schema.json +18 -15
- package/schemas/model.schema.json +637 -1144
- package/schemas/project.schema.json +8 -4
- package/schemas/workspace.schema.json +39 -20
- package/dist/core/views.d.ts +0 -126
- package/dist/core/views.js +0 -217
- package/dist/viewer/assets/index-DvKgCpBr.css +0 -1
- package/dist/viewer/assets/index-gucix3xm.js +0 -113
- /package/dist/{history → revisions}/migrate.d.ts +0 -0
- /package/dist/{history → revisions}/migrate.js +0 -0
package/dist/mcp/source.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { gitHead } from "../git.js";
|
|
5
|
-
import { Bundle } from "../schema/bundle.js";
|
|
1
|
+
import { checkoutAt } from "../workspace/index.js";
|
|
2
|
+
import { openSite } from "../revisions/index.js";
|
|
3
|
+
import { siteAt } from "./site.js";
|
|
6
4
|
/**
|
|
7
5
|
* A local checkout: the Bundle is built in memory and rebuilt when a file
|
|
8
6
|
* under the Workspace root changes or HEAD moves. Change is detected per
|
|
@@ -10,123 +8,51 @@ import { Bundle } from "../schema/bundle.js";
|
|
|
10
8
|
* next call with no watcher to start or stop.
|
|
11
9
|
*/
|
|
12
10
|
export function checkoutSource({ root }) {
|
|
11
|
+
const checkout = checkoutAt(root);
|
|
13
12
|
let cached;
|
|
14
13
|
return {
|
|
15
14
|
kind: "checkout",
|
|
16
15
|
root,
|
|
16
|
+
checkout,
|
|
17
17
|
writesAllowed: true,
|
|
18
18
|
async snapshot() {
|
|
19
|
-
const [files, head] = await Promise.all([fingerprint(
|
|
19
|
+
const [files, head] = await Promise.all([checkout.fingerprint(), checkout.head()]);
|
|
20
20
|
const key = `${head.commit}\n${head.builtAt}\n${files}`;
|
|
21
|
-
if (cached?.key !== key)
|
|
22
|
-
cached = { key, snapshot: await load(
|
|
23
|
-
}
|
|
21
|
+
if (cached?.key !== key)
|
|
22
|
+
cached = { key, snapshot: await checkout.load() };
|
|
24
23
|
return cached.snapshot;
|
|
25
24
|
},
|
|
26
25
|
};
|
|
27
26
|
}
|
|
28
|
-
/** How long
|
|
27
|
+
/** How long the site's latest Bundle and index are trusted before the site is asked again. */
|
|
29
28
|
const RECHECK_MS = 60_000;
|
|
30
|
-
const BUNDLE_FILE = "workspace.bundle.json";
|
|
31
29
|
/**
|
|
32
30
|
* A published Workspace Bundle, read-only. `location` is a URL or a path,
|
|
33
31
|
* naming either the Bundle file or the site (folder) that holds
|
|
34
|
-
* `workspace.bundle.json`. The
|
|
35
|
-
* HTTP the re-check is a conditional
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
32
|
+
* `workspace.bundle.json`. The Bundle and the site's Revision index are
|
|
33
|
+
* re-checked at most every 60 s; over HTTP the re-check is a conditional
|
|
34
|
+
* request when the host gave an ETag or Last-Modified, so an unchanged file
|
|
35
|
+
* costs a 304. A Bundle from an older Archidocs is migrated. A source that
|
|
36
|
+
* can't be read, or doesn't hold a Bundle this version can read, rejects and
|
|
37
|
+
* the tool returns `source_unavailable`; the next call tries again.
|
|
39
38
|
*/
|
|
40
39
|
export function bundleSource({ location }) {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
let
|
|
44
|
-
const fetchUrl = async (href) => {
|
|
45
|
-
const headers = { accept: "application/json" };
|
|
46
|
-
if (cached?.etag)
|
|
47
|
-
headers["if-none-match"] = cached.etag;
|
|
48
|
-
if (cached?.lastModified)
|
|
49
|
-
headers["if-modified-since"] = cached.lastModified;
|
|
50
|
-
const response = await fetch(href, { headers, cache: "no-store" });
|
|
51
|
-
if (response.status === 304 && cached)
|
|
52
|
-
return cached;
|
|
53
|
-
if (!response.ok)
|
|
54
|
-
throw new Error(`${href} answered ${response.status} ${response.statusText}`.trim());
|
|
55
|
-
return {
|
|
56
|
-
snapshot: parse(await response.text(), href),
|
|
57
|
-
checkedAt: 0,
|
|
58
|
-
etag: response.headers.get("etag") ?? undefined,
|
|
59
|
-
lastModified: response.headers.get("last-modified") ?? undefined,
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
const readPath = async () => {
|
|
63
|
-
path ??= await bundlePath(location);
|
|
64
|
-
const s = await stat(path);
|
|
65
|
-
const fileKey = `${s.mtimeMs}\0${s.size}`;
|
|
66
|
-
if (cached?.fileKey === fileKey)
|
|
67
|
-
return cached;
|
|
68
|
-
return { snapshot: parse(await readFile(path, "utf8"), path), checkedAt: 0, fileKey };
|
|
69
|
-
};
|
|
40
|
+
const { reader, bundle } = siteAt(location);
|
|
41
|
+
const site = openSite(reader, { recheckMs: RECHECK_MS, bundle });
|
|
42
|
+
let held;
|
|
70
43
|
return {
|
|
71
44
|
kind: "bundle",
|
|
45
|
+
site,
|
|
72
46
|
get location() {
|
|
73
|
-
return
|
|
47
|
+
return site.location;
|
|
74
48
|
},
|
|
75
49
|
writesAllowed: false,
|
|
76
50
|
async snapshot() {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return cached.snapshot;
|
|
51
|
+
const latest = await site.latest();
|
|
52
|
+
// A Bundle is only ever published from a Workspace with no errors; check's warnings aren't kept in it.
|
|
53
|
+
if (held?.bundle !== latest)
|
|
54
|
+
held = { bundle: latest, issues: [] };
|
|
55
|
+
return held;
|
|
83
56
|
},
|
|
84
57
|
};
|
|
85
58
|
}
|
|
86
|
-
/** A site root URL becomes its `workspace.bundle.json`; a URL to a `.json` file is used as given. */
|
|
87
|
-
function bundleUrl(location) {
|
|
88
|
-
const url = new URL(location);
|
|
89
|
-
if (url.pathname.endsWith(".json"))
|
|
90
|
-
return url.href;
|
|
91
|
-
if (!url.pathname.endsWith("/"))
|
|
92
|
-
url.pathname += "/";
|
|
93
|
-
return new URL(BUNDLE_FILE, url).href;
|
|
94
|
-
}
|
|
95
|
-
/** A folder becomes its `workspace.bundle.json`; a file is used as given. */
|
|
96
|
-
async function bundlePath(location) {
|
|
97
|
-
const path = resolve(location);
|
|
98
|
-
return (await stat(path)).isDirectory() ? join(path, BUNDLE_FILE) : path;
|
|
99
|
-
}
|
|
100
|
-
function parse(text, from) {
|
|
101
|
-
let json;
|
|
102
|
-
try {
|
|
103
|
-
json = JSON.parse(text);
|
|
104
|
-
}
|
|
105
|
-
catch {
|
|
106
|
-
throw new Error(`${from} is not JSON.`);
|
|
107
|
-
}
|
|
108
|
-
const bundle = Bundle.safeParse(json);
|
|
109
|
-
if (!bundle.success)
|
|
110
|
-
throw new Error(`${from} is not a Workspace Bundle this version can read.`);
|
|
111
|
-
// A Bundle is only ever published from a Workspace with no errors; check's warnings aren't kept in it.
|
|
112
|
-
return { bundle: bundle.data, issues: [] };
|
|
113
|
-
}
|
|
114
|
-
/** Path, mtime and size of every `.yaml` and `.md` file (ADRs) under the root, in a stable order. */
|
|
115
|
-
async function fingerprint(root) {
|
|
116
|
-
const lines = [];
|
|
117
|
-
const dirs = [root];
|
|
118
|
-
for (let i = 0; i < dirs.length; i++) {
|
|
119
|
-
for (const entry of await readdir(dirs[i], { withFileTypes: true })) {
|
|
120
|
-
if (entry.name.startsWith(".") || entry.name === "node_modules")
|
|
121
|
-
continue;
|
|
122
|
-
const path = join(dirs[i], entry.name);
|
|
123
|
-
if (entry.isDirectory())
|
|
124
|
-
dirs.push(path);
|
|
125
|
-
else if (entry.name.endsWith(".yaml") || entry.name.endsWith(".md")) {
|
|
126
|
-
const s = await stat(path);
|
|
127
|
-
lines.push(`${path}\0${s.mtimeMs}\0${s.size}`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return lines.sort().join("\n");
|
|
132
|
-
}
|
package/dist/render/layout.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ELK } from "elkjs/lib/elk-api.js";
|
|
2
|
-
import type { ResolvedView, ViewNode } from "../core/views.ts";
|
|
2
|
+
import type { ResolvedView, ViewNode } from "../core/views/index.ts";
|
|
3
3
|
/** Which way a View's edges flow: top to bottom, bottom to top, left to right or right to left. */
|
|
4
4
|
export type Direction = "TB" | "BT" | "LR" | "RL";
|
|
5
5
|
export declare const directions: readonly Direction[];
|
|
@@ -30,16 +30,33 @@ export interface Layout {
|
|
|
30
30
|
edges: LaidOutEdge[];
|
|
31
31
|
}
|
|
32
32
|
export interface LayoutOptionsInput {
|
|
33
|
-
/**
|
|
33
|
+
/** Overrides the View's own direction, as `archidocs export --direction` and the viewer's direction control do. */
|
|
34
34
|
direction?: Direction;
|
|
35
35
|
/** The ELK instance to run, such as one backed by a web worker in the browser; defaults to the bundled, in-thread one. */
|
|
36
36
|
elk?: ELK;
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
38
|
+
/** The least size of a node per kind; `nodeSize` widens it for a long name. Containers are sized by their contents. */
|
|
39
39
|
export declare const NODE_SIZES: Record<ViewNode["kind"], {
|
|
40
40
|
width: number;
|
|
41
41
|
height: number;
|
|
42
42
|
}>;
|
|
43
|
+
/** No box grows wider than this for its name; a longer name takes a second line instead. */
|
|
44
|
+
export declare const NODE_MAX_WIDTH = 360;
|
|
45
|
+
/** The extra height a box gets for a second line of name. */
|
|
46
|
+
export declare const NAME_LINE = 18;
|
|
47
|
+
/** The width a box of `width` leaves for its name. */
|
|
48
|
+
export declare function nameRoom(n: ViewNode, width: number): number;
|
|
49
|
+
/**
|
|
50
|
+
* A box's size: its kind's size, widened in 10px steps until its name fits on one line, up to NODE_MAX_WIDTH;
|
|
51
|
+
* a name longer than that takes two lines and the box grows by one. Measured with the embedded font's advances,
|
|
52
|
+
* so the same View lays out the same everywhere.
|
|
53
|
+
*/
|
|
54
|
+
export declare function nodeSize(n: ViewNode): {
|
|
55
|
+
width: number;
|
|
56
|
+
height: number;
|
|
57
|
+
};
|
|
58
|
+
/** The least width of an open box, so its head row shows its whole name; capped like any box, past which the name is cut. */
|
|
59
|
+
export declare function containerMinWidth(n: ViewNode): number;
|
|
43
60
|
/** Room at the top of a container for its label. */
|
|
44
61
|
export declare const CONTAINER_HEADER = 40;
|
|
45
62
|
/**
|
package/dist/render/layout.js
CHANGED
|
@@ -1,18 +1,55 @@
|
|
|
1
1
|
import ElkBundled from "elkjs/lib/elk.bundled.js";
|
|
2
|
+
import { textWidth } from "./text.js";
|
|
2
3
|
export const directions = ["TB", "BT", "LR", "RL"];
|
|
3
|
-
/**
|
|
4
|
+
/** The least size of a node per kind; `nodeSize` widens it for a long name. Containers are sized by their contents. */
|
|
4
5
|
export const NODE_SIZES = {
|
|
5
|
-
// The Variant D prototype's sizes (ticket 14), 40px wider and
|
|
6
|
-
person: { width: 200, height:
|
|
7
|
-
system: { width: 230, height:
|
|
8
|
-
service: { width: 220, height:
|
|
9
|
-
component: { width: 210, height:
|
|
6
|
+
// The Variant D prototype's sizes (ticket 14), 40px wider and up to 22px taller, so names fit and boxes breathe.
|
|
7
|
+
person: { width: 200, height: 76 },
|
|
8
|
+
system: { width: 230, height: 80 },
|
|
9
|
+
service: { width: 220, height: 72 },
|
|
10
|
+
component: { width: 210, height: 68 },
|
|
10
11
|
target: { width: 240, height: 84 },
|
|
11
|
-
deployment: { width: 220, height:
|
|
12
|
+
deployment: { width: 220, height: 68 },
|
|
12
13
|
};
|
|
14
|
+
/** No box grows wider than this for its name; a longer name takes a second line instead. */
|
|
15
|
+
export const NODE_MAX_WIDTH = 360;
|
|
16
|
+
/** The extra height a box gets for a second line of name. */
|
|
17
|
+
export const NAME_LINE = 18;
|
|
18
|
+
/** What a box's head row holds beside the name: Team edge, padding, kind glyph and the Team code tile. */
|
|
19
|
+
const HEAD_CHROME = 116;
|
|
20
|
+
/** The expand toggle of a collapsed System or Service, and the way-in tile in an open box's head row. */
|
|
21
|
+
const TOGGLE_CHROME = 30;
|
|
22
|
+
const WAY_IN_CHROME = 30;
|
|
23
|
+
/** The room a box of this kind and state needs beside its name. */
|
|
24
|
+
function headChrome(n) {
|
|
25
|
+
const opens = n.kind === "system" || (n.kind === "service" && n.collapsed);
|
|
26
|
+
return HEAD_CHROME + (n.collapsed && opens ? TOGGLE_CHROME : 0) + (n.kind === "person" ? 12 : 0);
|
|
27
|
+
}
|
|
28
|
+
/** The width a box of `width` leaves for its name. */
|
|
29
|
+
export function nameRoom(n, width) {
|
|
30
|
+
return width - headChrome(n);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A box's size: its kind's size, widened in 10px steps until its name fits on one line, up to NODE_MAX_WIDTH;
|
|
34
|
+
* a name longer than that takes two lines and the box grows by one. Measured with the embedded font's advances,
|
|
35
|
+
* so the same View lays out the same everywhere.
|
|
36
|
+
*/
|
|
37
|
+
export function nodeSize(n) {
|
|
38
|
+
const base = NODE_SIZES[n.kind];
|
|
39
|
+
const wanted = Math.ceil((textWidth(n.name, 13, 700) + headChrome(n)) / 10) * 10;
|
|
40
|
+
const width = Math.min(NODE_MAX_WIDTH, Math.max(base.width, wanted));
|
|
41
|
+
return { width, height: base.height + (wanted > NODE_MAX_WIDTH ? NAME_LINE : 0) };
|
|
42
|
+
}
|
|
43
|
+
/** What an open box's head row holds beside its name: Team edge, padding, glyph, its kind in words and the Team code tile. */
|
|
44
|
+
const CONTAINER_CHROME = 210;
|
|
45
|
+
/** The least width of an open box, so its head row shows its whole name; capped like any box, past which the name is cut. */
|
|
46
|
+
export function containerMinWidth(n) {
|
|
47
|
+
const opens = n.kind === "system" || n.kind === "service";
|
|
48
|
+
return Math.min(NODE_MAX_WIDTH + 80, Math.ceil(textWidth(n.name, 13, 700) + CONTAINER_CHROME + (opens ? TOGGLE_CHROME + WAY_IN_CHROME : 0)));
|
|
49
|
+
}
|
|
13
50
|
/** Room at the top of a container for its label. */
|
|
14
51
|
export const CONTAINER_HEADER = 40;
|
|
15
|
-
const CONTAINER_PADDING = `[top=${CONTAINER_HEADER +
|
|
52
|
+
const CONTAINER_PADDING = `[top=${CONTAINER_HEADER + 12},left=24,bottom=24,right=24]`;
|
|
16
53
|
const ELK_DIRECTION = { TB: "DOWN", BT: "UP", LR: "RIGHT", RL: "LEFT" };
|
|
17
54
|
/** The border side edges leave a container by, then the side they enter one by. */
|
|
18
55
|
const PORT_SIDES = {
|
|
@@ -33,7 +70,7 @@ let sharedElk;
|
|
|
33
70
|
* sorted by id, which, with fixed node sizes, makes the Layout deterministic.
|
|
34
71
|
*/
|
|
35
72
|
export async function layoutView(view, options = {}) {
|
|
36
|
-
const direction = options.direction ??
|
|
73
|
+
const direction = options.direction ?? view.direction;
|
|
37
74
|
const elk = options.elk ?? (sharedElk ??= new ElkConstructor());
|
|
38
75
|
const graph = new ViewGraph(view);
|
|
39
76
|
const { root, routes } = toElk(graph, direction);
|
|
@@ -72,7 +109,7 @@ function toElk(graph, direction) {
|
|
|
72
109
|
"elk.direction": ELK_DIRECTION[direction],
|
|
73
110
|
"elk.edgeRouting": "ORTHOGONAL",
|
|
74
111
|
"elk.layered.nodePlacement.strategy": "BRANDES_KOEPF",
|
|
75
|
-
"elk.spacing.nodeNode": "
|
|
112
|
+
"elk.spacing.nodeNode": "48",
|
|
76
113
|
"elk.layered.spacing.nodeNodeBetweenLayers": "72",
|
|
77
114
|
"elk.spacing.edgeNode": "20",
|
|
78
115
|
"elk.spacing.edgeEdge": "12",
|
|
@@ -121,10 +158,10 @@ function toElk(graph, direction) {
|
|
|
121
158
|
const nodePorts = [...(ports.get(n.id) ?? [])].sort(([a], [b]) => cmp(a, b));
|
|
122
159
|
const node = {
|
|
123
160
|
id: n.id,
|
|
124
|
-
...(children.length > 0 ? { children } :
|
|
161
|
+
...(children.length > 0 ? { children } : nodeSize(n)),
|
|
125
162
|
...(nodePorts.length > 0 ? { ports: nodePorts.map(([id, side]) => ({ id, width: 0, height: 0, layoutOptions: { "elk.port.side": side } })) } : {}),
|
|
126
163
|
layoutOptions: {
|
|
127
|
-
...(children.length > 0 ? { ...common, "elk.padding": CONTAINER_PADDING } : {}),
|
|
164
|
+
...(children.length > 0 ? { ...common, "elk.padding": CONTAINER_PADDING, "elk.nodeSize.constraints": "MINIMUM_SIZE", "elk.nodeSize.minimum": `(${containerMinWidth(n)},0)` } : {}),
|
|
128
165
|
...(nodePorts.length > 0 ? { "elk.portConstraints": "FIXED_SIDE" } : {}),
|
|
129
166
|
},
|
|
130
167
|
edges: [],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ResolvedDynamicView } from "../core/
|
|
1
|
+
import type { ResolvedDynamicView } from "../core/views/index.ts";
|
|
2
2
|
import type { Bundle } from "../schema/bundle.ts";
|
|
3
3
|
import { type MessageStyle } from "./sequence.ts";
|
|
4
4
|
import { type RenderSource } from "./svg.ts";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ResolvedDynamicView, ResolvedStep } from "../core/
|
|
1
|
+
import type { ResolvedDynamicView, ResolvedStep } from "../core/views/index.ts";
|
|
2
2
|
/** How a message is drawn: sync is solid with a filled head, async solid with an open head, return dashed with an open head. */
|
|
3
3
|
export type MessageStyle = "sync" | "async" | "return";
|
|
4
4
|
/**
|
package/dist/render/svg.d.ts
CHANGED
package/dist/render/svg.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describeLens } from "../core/
|
|
1
|
+
import { describeLens } from "../core/views/index.js";
|
|
2
2
|
import { FONT_FAMILY, FONTS } from "./font.js";
|
|
3
3
|
import { teamStyles } from "./teams.js";
|
|
4
4
|
import { cut, fmt, text, textWidth } from "./text.js";
|
|
@@ -35,7 +35,7 @@ export function renderSvg({ bundle, view, layout, source, theme = "light", label
|
|
|
35
35
|
const containers = new Set(view.nodes.map((n) => n.parent).filter((p) => p !== null));
|
|
36
36
|
const title = view.title;
|
|
37
37
|
const subtitle = sourceLine(source, label);
|
|
38
|
-
const key = drawKey(c, view.lens);
|
|
38
|
+
const key = drawKey(c, bundle, view.lens);
|
|
39
39
|
const width = Math.ceil(Math.max(layout.width, key.width, textWidth(title, 20, 700), textWidth(subtitle, 12)) + 2 * PAD);
|
|
40
40
|
const height = Math.ceil(HEADER + layout.height + PAD + KEY);
|
|
41
41
|
const depth = (n) => (n.parent === null ? 0 : 1 + depth(view.nodes.find((p) => p.id === n.parent)));
|
|
@@ -177,7 +177,7 @@ function drawEdge(c, points, edge) {
|
|
|
177
177
|
return `<path d="${d}" fill="none" stroke="${c.edge}" stroke-width="${FRAME}" marker-end="url(#arrow)"/>`;
|
|
178
178
|
}
|
|
179
179
|
/** The key, in the canvas's own vocabulary: the Team tile, External, broker, and the Lens if there is one. */
|
|
180
|
-
function drawKey(c, lens) {
|
|
180
|
+
function drawKey(c, bundle, lens) {
|
|
181
181
|
const parts = [];
|
|
182
182
|
let x = 0;
|
|
183
183
|
const label = (s) => {
|
|
@@ -209,7 +209,7 @@ function drawKey(c, lens) {
|
|
|
209
209
|
swatch(`fill="${c.paper}" stroke="${c.muted}" stroke-width="3"`);
|
|
210
210
|
else
|
|
211
211
|
swatch(`fill="${c.pathbg}" stroke="${c.path}" stroke-width="${FRAME}"`);
|
|
212
|
-
label(`Lens: ${describeLens(lens)}`);
|
|
212
|
+
label(`Lens: ${describeLens(bundle, lens)}`);
|
|
213
213
|
}
|
|
214
214
|
return { parts, width: x - 24 };
|
|
215
215
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The point grammar: how a tag, a sha (or its prefix), a day or a time names
|
|
3
|
+
* a Revision. One reading for the viewer, MCP on a site and, through ticket
|
|
4
|
+
* 05, a checkout, so a point names the same Revision everywhere.
|
|
5
|
+
*/
|
|
6
|
+
/** What `find` needs of a Revision; the index's `RevisionEntry` is one. */
|
|
7
|
+
export interface Dated {
|
|
8
|
+
sha: string;
|
|
9
|
+
/** ISO 8601, as git's `%cI` writes it. */
|
|
10
|
+
date: string;
|
|
11
|
+
tags: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
/** The point grammar in one sentence, for every reference that takes a point. */
|
|
14
|
+
export declare const POINT_GRAMMAR = "a tag, a commit sha or its first 4 or more characters, or a date (`YYYY-MM-DD`) or time (ISO 8601, UTC unless it gives a zone)";
|
|
15
|
+
/** The Revision a point names, or why it names none. */
|
|
16
|
+
export type Found<R extends Dated> = {
|
|
17
|
+
ok: true;
|
|
18
|
+
revision: R;
|
|
19
|
+
}
|
|
20
|
+
/** `tags` to suggest; `first` is the first Revision when the point is a date or time before it. */
|
|
21
|
+
| {
|
|
22
|
+
ok: false;
|
|
23
|
+
kind: "not_found";
|
|
24
|
+
tags: string[];
|
|
25
|
+
first?: R;
|
|
26
|
+
}
|
|
27
|
+
/** `count` Revisions' shas start with the point; `candidates` are the newest 5 of them. */
|
|
28
|
+
| {
|
|
29
|
+
ok: false;
|
|
30
|
+
kind: "ambiguous";
|
|
31
|
+
count: number;
|
|
32
|
+
candidates: R[];
|
|
33
|
+
};
|
|
34
|
+
/** A stretch of time in ms since the epoch: from `start` up to, but not including, `end`. */
|
|
35
|
+
export interface Span {
|
|
36
|
+
start: number;
|
|
37
|
+
end: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The span a day or a time stands for, or undefined when the point is
|
|
41
|
+
* neither. A day (`YYYY-MM-DD`) is the UTC day `[00:00Z, next 00:00Z)`; a
|
|
42
|
+
* time is its one instant, read as UTC when it gives no zone.
|
|
43
|
+
*/
|
|
44
|
+
export declare function timeSpan(point: string): Span | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* The Revision a point names, over Revisions listed newest first. In order:
|
|
47
|
+
* 1. an exact tag: the newest Revision carrying it;
|
|
48
|
+
* 2. a day or a time: the last Revision dated before the span's end;
|
|
49
|
+
* 3. hex of 4 to 64 characters, any case: the one Revision whose sha starts with it.
|
|
50
|
+
* Anything else, or nothing found, is `not_found`; hex that starts several shas is `ambiguous`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function find<R extends Dated>(revisions: readonly R[], point: string): Found<R>;
|
|
53
|
+
/**
|
|
54
|
+
* The time a point spans, for `since`/`until`/`at` filters: a tag or a sha
|
|
55
|
+
* spans its Revision's one instant, a day its whole UTC day, a time its one
|
|
56
|
+
* instant. A day or time spans itself even with no Revision in or before it.
|
|
57
|
+
* Keep a Revision dated `>=` the `since` span's start and `<` the `until` span's end.
|
|
58
|
+
*/
|
|
59
|
+
export declare function span<R extends Dated>(revisions: readonly R[], point: string): {
|
|
60
|
+
ok: true;
|
|
61
|
+
span: Span;
|
|
62
|
+
} | Exclude<Found<R>, {
|
|
63
|
+
ok: true;
|
|
64
|
+
}>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The point grammar: how a tag, a sha (or its prefix), a day or a time names
|
|
3
|
+
* a Revision. One reading for the viewer, MCP on a site and, through ticket
|
|
4
|
+
* 05, a checkout, so a point names the same Revision everywhere.
|
|
5
|
+
*/
|
|
6
|
+
/** The point grammar in one sentence, for every reference that takes a point. */
|
|
7
|
+
export const POINT_GRAMMAR = "a tag, a commit sha or its first 4 or more characters, or a date (`YYYY-MM-DD`) or time (ISO 8601, UTC unless it gives a zone)";
|
|
8
|
+
/** How many candidates or tags a failure carries. */
|
|
9
|
+
const MAX_LISTED = 5;
|
|
10
|
+
const DAY = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
11
|
+
const TIME = /^(\d{4}-\d{2}-\d{2})[Tt ](\d{2}:\d{2})(:\d{2}(?:\.\d+)?)?([Zz]|[+-]\d{2}:?\d{2})?$/;
|
|
12
|
+
const HEX = /^[0-9a-f]{4,64}$/i;
|
|
13
|
+
const DAY_MS = 86_400_000;
|
|
14
|
+
/**
|
|
15
|
+
* The span a day or a time stands for, or undefined when the point is
|
|
16
|
+
* neither. A day (`YYYY-MM-DD`) is the UTC day `[00:00Z, next 00:00Z)`; a
|
|
17
|
+
* time is its one instant, read as UTC when it gives no zone.
|
|
18
|
+
*/
|
|
19
|
+
export function timeSpan(point) {
|
|
20
|
+
const day = DAY.exec(point);
|
|
21
|
+
if (day) {
|
|
22
|
+
const start = Date.parse(`${point}T00:00:00Z`);
|
|
23
|
+
// Date.parse takes 2026-02-30 as March 2nd; a day must read back as itself.
|
|
24
|
+
if (Number.isNaN(start) || new Date(start).toISOString().slice(0, 10) !== point)
|
|
25
|
+
return undefined;
|
|
26
|
+
return { start, end: start + DAY_MS };
|
|
27
|
+
}
|
|
28
|
+
const time = TIME.exec(point);
|
|
29
|
+
if (!time)
|
|
30
|
+
return undefined;
|
|
31
|
+
const [, date, minutes, seconds = ":00", zone = "Z"] = time;
|
|
32
|
+
const offset = zone.toUpperCase() === "Z" ? "Z" : `${zone.slice(0, 3)}:${zone.slice(-2)}`;
|
|
33
|
+
const at = Date.parse(`${date}T${minutes}${seconds}${offset}`);
|
|
34
|
+
if (Number.isNaN(at) || !timeSpan(date))
|
|
35
|
+
return undefined;
|
|
36
|
+
return instant(at);
|
|
37
|
+
}
|
|
38
|
+
const instant = (at) => ({ start: at, end: at + 1 });
|
|
39
|
+
/**
|
|
40
|
+
* The Revision a point names, over Revisions listed newest first. In order:
|
|
41
|
+
* 1. an exact tag: the newest Revision carrying it;
|
|
42
|
+
* 2. a day or a time: the last Revision dated before the span's end;
|
|
43
|
+
* 3. hex of 4 to 64 characters, any case: the one Revision whose sha starts with it.
|
|
44
|
+
* Anything else, or nothing found, is `not_found`; hex that starts several shas is `ambiguous`.
|
|
45
|
+
*/
|
|
46
|
+
export function find(revisions, point) {
|
|
47
|
+
const tagged = revisions.find((r) => r.tags.includes(point));
|
|
48
|
+
if (tagged)
|
|
49
|
+
return { ok: true, revision: tagged };
|
|
50
|
+
const span = timeSpan(point);
|
|
51
|
+
if (span) {
|
|
52
|
+
const last = revisions.find((r) => Date.parse(r.date) < span.end);
|
|
53
|
+
if (last)
|
|
54
|
+
return { ok: true, revision: last };
|
|
55
|
+
return notFound(revisions, revisions.at(-1));
|
|
56
|
+
}
|
|
57
|
+
if (HEX.test(point)) {
|
|
58
|
+
const prefix = point.toLowerCase();
|
|
59
|
+
const matches = revisions.filter((r) => r.sha.toLowerCase().startsWith(prefix));
|
|
60
|
+
if (matches.length === 1)
|
|
61
|
+
return { ok: true, revision: matches[0] };
|
|
62
|
+
if (matches.length > 1)
|
|
63
|
+
return { ok: false, kind: "ambiguous", count: matches.length, candidates: matches.slice(0, MAX_LISTED) };
|
|
64
|
+
}
|
|
65
|
+
return notFound(revisions);
|
|
66
|
+
}
|
|
67
|
+
function notFound(revisions, first) {
|
|
68
|
+
return { ok: false, kind: "not_found", tags: revisions.flatMap((r) => r.tags).slice(0, MAX_LISTED), ...(first ? { first } : {}) };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The time a point spans, for `since`/`until`/`at` filters: a tag or a sha
|
|
72
|
+
* spans its Revision's one instant, a day its whole UTC day, a time its one
|
|
73
|
+
* instant. A day or time spans itself even with no Revision in or before it.
|
|
74
|
+
* Keep a Revision dated `>=` the `since` span's start and `<` the `until` span's end.
|
|
75
|
+
*/
|
|
76
|
+
export function span(revisions, point) {
|
|
77
|
+
const tagged = revisions.find((r) => r.tags.includes(point));
|
|
78
|
+
if (!tagged) {
|
|
79
|
+
const own = timeSpan(point);
|
|
80
|
+
if (own)
|
|
81
|
+
return { ok: true, span: own };
|
|
82
|
+
}
|
|
83
|
+
const found = find(revisions, point);
|
|
84
|
+
return found.ok ? { ok: true, span: instant(Date.parse(found.revision.date)) } : found;
|
|
85
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Revision index and the layout of a published site. Browser-safe: the
|
|
3
|
+
* viewer imports it as MCP and the CLI do, so nothing here may import from
|
|
4
|
+
* `node:`. This file is the module's only entry.
|
|
5
|
+
*/
|
|
6
|
+
import type { ChangeCounts } from "../core/diff.ts";
|
|
7
|
+
/**
|
|
8
|
+
* The Revision index's own version, written under the JSON key
|
|
9
|
+
* `schemaVersion`. It is independent of the Bundle's `SCHEMA_VERSION`,
|
|
10
|
+
* though both are 1 today: either can change without the other.
|
|
11
|
+
*/
|
|
12
|
+
export declare const INDEX_VERSION = 1;
|
|
13
|
+
/** One Revision as the index records it; `bundle: false` marks a Revision whose Bundle was dropped. */
|
|
14
|
+
export interface RevisionEntry {
|
|
15
|
+
sha: string;
|
|
16
|
+
date: string;
|
|
17
|
+
subject: string;
|
|
18
|
+
author: string;
|
|
19
|
+
tags: string[];
|
|
20
|
+
/** Changes against the previous Revision (or an empty Model for the first). */
|
|
21
|
+
counts: ChangeCounts;
|
|
22
|
+
changedIds: string[];
|
|
23
|
+
bundle: boolean;
|
|
24
|
+
}
|
|
25
|
+
/** What a preview site's index adds: the base branch and both sides' shas, so the viewer opens with Compare "base → PR". */
|
|
26
|
+
export interface PreviewMark {
|
|
27
|
+
base: string;
|
|
28
|
+
baseSha: string;
|
|
29
|
+
headSha: string;
|
|
30
|
+
}
|
|
31
|
+
/** The Revision index, as `bundles/index.json` and a checkout's cache hold it. */
|
|
32
|
+
export interface RevisionIndex {
|
|
33
|
+
/** {@link INDEX_VERSION}, not the Bundle's schema version. */
|
|
34
|
+
schemaVersion: number;
|
|
35
|
+
/** Newest first. */
|
|
36
|
+
revisions: RevisionEntry[];
|
|
37
|
+
/** Set by `build --preview`. */
|
|
38
|
+
preview?: PreviewMark;
|
|
39
|
+
}
|
|
40
|
+
/** A site's paths, relative to its root with `/` separators. */
|
|
41
|
+
export declare const LATEST_BUNDLE_PATH = "workspace.bundle.json";
|
|
42
|
+
/** The file that names the Workspace for the viewer's exports. */
|
|
43
|
+
export declare const SITE_FILE_PATH = "site.json";
|
|
44
|
+
/** The folder of past Bundles and the Revision index. */
|
|
45
|
+
export declare const BUNDLES_DIR = "bundles";
|
|
46
|
+
export declare const INDEX_PATH = "bundles/index.json";
|
|
47
|
+
/** A past Bundle's path: `bundles/<sha>.json`. */
|
|
48
|
+
export declare const pastBundlePath: (sha: string) => string;
|
|
49
|
+
/** A past Bundle's file name within `bundles/`. */
|
|
50
|
+
export declare const pastBundleFile: (sha: string) => string;
|
|
51
|
+
/** Whether a file name in `bundles/` is a past Bundle's, named by its full sha. */
|
|
52
|
+
export declare const isPastBundleFile: (name: string) => boolean;
|
|
53
|
+
export { find, span, timeSpan, POINT_GRAMMAR, type Dated, type Found, type Span } from "./find.ts";
|
|
54
|
+
export { touching } from "./touching.ts";
|
|
55
|
+
export { migrateBundle, migrations, type Migration } from "./migrate.ts";
|
|
56
|
+
export { fetchReader, openSite, readBundle, readIndex, type HistoryUnavailable, type Site, type SiteOptions, type SiteRead, type SiteReader, type UnavailableReason, type Validators, } from "./site.ts";
|
|
57
|
+
export { serializeBundle, serializeIndex, serializeSiteFile } from "./text.ts";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Revision index's own version, written under the JSON key
|
|
3
|
+
* `schemaVersion`. It is independent of the Bundle's `SCHEMA_VERSION`,
|
|
4
|
+
* though both are 1 today: either can change without the other.
|
|
5
|
+
*/
|
|
6
|
+
export const INDEX_VERSION = 1;
|
|
7
|
+
/** A site's paths, relative to its root with `/` separators. */
|
|
8
|
+
export const LATEST_BUNDLE_PATH = "workspace.bundle.json";
|
|
9
|
+
/** The file that names the Workspace for the viewer's exports. */
|
|
10
|
+
export const SITE_FILE_PATH = "site.json";
|
|
11
|
+
/** The folder of past Bundles and the Revision index. */
|
|
12
|
+
export const BUNDLES_DIR = "bundles";
|
|
13
|
+
export const INDEX_PATH = `${BUNDLES_DIR}/index.json`;
|
|
14
|
+
/** A past Bundle's path: `bundles/<sha>.json`. */
|
|
15
|
+
export const pastBundlePath = (sha) => `${BUNDLES_DIR}/${pastBundleFile(sha)}`;
|
|
16
|
+
/** A past Bundle's file name within `bundles/`. */
|
|
17
|
+
export const pastBundleFile = (sha) => `${sha}.json`;
|
|
18
|
+
/** Whether a file name in `bundles/` is a past Bundle's, named by its full sha. */
|
|
19
|
+
export const isPastBundleFile = (name) => /^[0-9a-f]{40,64}\.json$/.test(name);
|
|
20
|
+
export { find, span, timeSpan, POINT_GRAMMAR } from "./find.js";
|
|
21
|
+
export { touching } from "./touching.js";
|
|
22
|
+
export { migrateBundle, migrations } from "./migrate.js";
|
|
23
|
+
export { fetchReader, openSite, readBundle, readIndex, } from "./site.js";
|
|
24
|
+
export { serializeBundle, serializeIndex, serializeSiteFile } from "./text.js";
|