@ascribed/astro 0.2.0 → 0.2.1-next.10
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 +2 -0
- package/dist/attributes.js +6 -5
- package/dist/attributes.js.map +1 -1
- package/dist/content.d.ts +1 -1
- package/dist/content.js +1 -1
- package/dist/content.js.map +1 -1
- package/dist/names.d.ts +95 -0
- package/dist/names.js +99 -0
- package/dist/names.js.map +1 -0
- package/dist/review/diff.d.ts +3 -3
- package/dist/review/diff.js +1 -0
- package/dist/review/diff.js.map +1 -1
- package/dist/review/protocol.d.ts +12 -30
- package/dist/review/protocol.js.map +1 -1
- package/dist/review/routes.d.ts +3 -0
- package/dist/review/routes.js +49 -35
- package/dist/review/routes.js.map +1 -1
- package/dist/review/server.d.ts +2 -0
- package/dist/review/server.js +14 -7
- package/dist/review/server.js.map +1 -1
- package/dist/satteri.js +2 -0
- package/dist/satteri.js.map +1 -1
- package/dist/shapes.d.ts +158 -0
- package/dist/shapes.js +8 -0
- package/dist/shapes.js.map +1 -0
- package/dist/toolbar/app.js +14 -13
- package/dist/toolbar/app.js.map +1 -1
- package/dist/toolbar/page.d.ts +3 -5
- package/dist/toolbar/page.js +7 -6
- package/dist/toolbar/page.js.map +1 -1
- package/dist/toolbar/text.d.ts +3 -3
- package/dist/toolbar/text.js.map +1 -1
- package/package.json +16 -5
package/dist/review/routes.js
CHANGED
|
@@ -15,8 +15,14 @@ export function normalizeRoute(route) {
|
|
|
15
15
|
const trimmed = (decoded.split(/[?#]/)[0] ?? "").replace(/\/+$/, "");
|
|
16
16
|
return trimmed === "" ? "/" : trimmed;
|
|
17
17
|
}
|
|
18
|
-
/** How much of a page's JSON to read
|
|
19
|
-
const
|
|
18
|
+
/** How much of a page's JSON to read at a time. */
|
|
19
|
+
const CHUNK_BYTES = 4096;
|
|
20
|
+
/**
|
|
21
|
+
* Where the page's own keys end in the JSON output, which writes it
|
|
22
|
+
* pretty-printed: `availability` comes after `path`, `route`, `title`,
|
|
23
|
+
* `frontmatter`, and `formatted`, and before the page's blocks.
|
|
24
|
+
*/
|
|
25
|
+
const AFTER_HEAD = Buffer.from('\n "availability":');
|
|
20
26
|
/**
|
|
21
27
|
* Every page of the build's JSON output (`<output-dir>/<build>/json/`), by
|
|
22
28
|
* normalized route. Empty when there's no JSON output.
|
|
@@ -35,20 +41,43 @@ export async function readRoutes(jsonRoot) {
|
|
|
35
41
|
if (entry.kind !== "page" || typeof entry.path !== "string")
|
|
36
42
|
return;
|
|
37
43
|
const page = await readHead(path.join(jsonRoot, ...entry.path.split("/")));
|
|
38
|
-
if (page)
|
|
39
|
-
|
|
44
|
+
if (page) {
|
|
45
|
+
const { route, ...routed } = page;
|
|
46
|
+
routes.set(normalizeRoute(route), routed);
|
|
47
|
+
}
|
|
40
48
|
}));
|
|
41
49
|
return routes;
|
|
42
50
|
}
|
|
43
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* A page's `path`, `route`, `title`, and formatted title, from the start of
|
|
53
|
+
* its JSON up to `availability`, or the whole of it if need be.
|
|
54
|
+
*/
|
|
44
55
|
async function readHead(file) {
|
|
45
|
-
let
|
|
56
|
+
let text;
|
|
46
57
|
try {
|
|
47
58
|
const handle = await open(file, "r");
|
|
48
59
|
try {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
const chunks = [];
|
|
61
|
+
let read = 0;
|
|
62
|
+
let end = -1;
|
|
63
|
+
for (;;) {
|
|
64
|
+
const buffer = Buffer.alloc(CHUNK_BYTES);
|
|
65
|
+
const { bytesRead } = await handle.read(buffer, 0, CHUNK_BYTES, read);
|
|
66
|
+
if (bytesRead === 0)
|
|
67
|
+
break;
|
|
68
|
+
chunks.push(buffer.subarray(0, bytesRead));
|
|
69
|
+
read += bytesRead;
|
|
70
|
+
// The marker may straddle two chunks, so look from just before this one.
|
|
71
|
+
end = Buffer.concat(chunks).indexOf(AFTER_HEAD, Math.max(0, read - bytesRead - AFTER_HEAD.length));
|
|
72
|
+
if (end >= 0)
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
const all = Buffer.concat(chunks);
|
|
76
|
+
// The keys before `availability`, closed as an object of their own.
|
|
77
|
+
text =
|
|
78
|
+
end >= 0
|
|
79
|
+
? `${all.subarray(0, end).toString("utf8").replace(/,\s*$/, "")}}`
|
|
80
|
+
: all.toString("utf8");
|
|
52
81
|
}
|
|
53
82
|
finally {
|
|
54
83
|
await handle.close();
|
|
@@ -57,36 +86,21 @@ async function readHead(file) {
|
|
|
57
86
|
catch {
|
|
58
87
|
return undefined;
|
|
59
88
|
}
|
|
60
|
-
|
|
61
|
-
const match = new RegExp(`"${name}"\\s*:\\s*("(?:[^"\\\\]|\\\\.)*")`).exec(head);
|
|
62
|
-
if (!match?.[1])
|
|
63
|
-
return undefined;
|
|
64
|
-
try {
|
|
65
|
-
return JSON.parse(match[1]);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
// The page's own keys come before `frontmatter`, so the first of each is the page's.
|
|
72
|
-
const pagePath = field("path");
|
|
73
|
-
const route = field("route");
|
|
74
|
-
const title = field("title");
|
|
75
|
-
if (pagePath !== undefined && route !== undefined && title !== undefined) {
|
|
76
|
-
return { path: pagePath, route, title };
|
|
77
|
-
}
|
|
89
|
+
let page;
|
|
78
90
|
try {
|
|
79
|
-
|
|
80
|
-
return typeof page.path === "string" && typeof page.route === "string"
|
|
81
|
-
? {
|
|
82
|
-
path: page.path,
|
|
83
|
-
route: page.route,
|
|
84
|
-
title: typeof page.title === "string" ? page.title : null,
|
|
85
|
-
}
|
|
86
|
-
: undefined;
|
|
91
|
+
page = JSON.parse(text);
|
|
87
92
|
}
|
|
88
93
|
catch {
|
|
89
94
|
return undefined;
|
|
90
95
|
}
|
|
96
|
+
if (typeof page.path !== "string" || typeof page.route !== "string")
|
|
97
|
+
return undefined;
|
|
98
|
+
const formatted = page.formatted?.title;
|
|
99
|
+
return {
|
|
100
|
+
path: page.path,
|
|
101
|
+
route: page.route,
|
|
102
|
+
title: typeof page.title === "string" ? page.title : null,
|
|
103
|
+
formatted_title: Array.isArray(formatted) ? formatted : null,
|
|
104
|
+
};
|
|
91
105
|
}
|
|
92
106
|
//# sourceMappingURL=routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/review/routes.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,yEAAyE;AACzE,sBAAsB;AACtB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/review/routes.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,yEAAyE;AACzE,sBAAsB;AACtB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,gFAAgF;AAChF,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,IAAI,OAAe,CAAC;IACpB,IAAI,CAAC;QACH,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,KAAK,CAAC;IAClB,CAAC;IACD,MAAM,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACrE,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC;AACxC,CAAC;AAWD,mDAAmD;AACnD,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB;;;;GAIG;AACH,MAAM,UAAU,GAAG,MAAM,CAAC,IA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EAAE,CAAC;QACvB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,IAA2F,CAAC;IAChG,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAgB,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACtF,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC;IACxC,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,KAAK,EAAE,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;QACzD,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAE,SAA8B,CAAC,CAAC,CAAC,IAAI;KACnF,CAAC;AACJ,CAAC","sourcesContent":["// Which page of the build is at a route, and its title: read from the JSON\n// output, which the dev server writes while review is on, since the site\n// output doesn't say.\nimport { open, readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { FormattedPiece } from \"@ascribed/review/overlay\";\n\n/** A route as compared: decoded, without a trailing `/` (except the root's). */\nexport function normalizeRoute(route: string): string {\n let decoded: string;\n try {\n decoded = decodeURI(route);\n } catch {\n decoded = route;\n }\n const trimmed = (decoded.split(/[?#]/)[0] ?? \"\").replace(/\\/+$/, \"\");\n return trimmed === \"\" ? \"/\" : trimmed;\n}\n\n/** A page of the build, as its JSON output names it. */\nexport interface RoutedPage {\n /** The content path. */\n path: string;\n title: string | null;\n /** The title formatted, when its field sets `inline = \"code\"`. */\n formatted_title: FormattedPiece[] | null;\n}\n\n/** How much of a page's JSON to read at a time. */\nconst CHUNK_BYTES = 4096;\n\n/**\n * Where the page's own keys end in the JSON output, which writes it\n * pretty-printed: `availability` comes after `path`, `route`, `title`,\n * `frontmatter`, and `formatted`, and before the page's blocks.\n */\nconst AFTER_HEAD = Buffer.from('\\n \"availability\":');\n\n/**\n * Every page of the build's JSON output (`<output-dir>/<build>/json/`), by\n * normalized route. Empty when there's no JSON output.\n */\nexport async function readRoutes(jsonRoot: string): Promise<Map<string, RoutedPage>> {\n const routes = new Map<string, RoutedPage>();\n let files: { path?: unknown; kind?: unknown }[];\n try {\n const manifest = JSON.parse(\n await readFile(path.join(path.dirname(jsonRoot), \"json.manifest.json\"), \"utf8\"),\n ) as { files?: unknown };\n files = Array.isArray(manifest.files) ? (manifest.files as typeof files) : [];\n } catch {\n return routes;\n }\n await Promise.all(\n files.map(async (entry) => {\n if (entry.kind !== \"page\" || typeof entry.path !== \"string\") return;\n const page = await readHead(path.join(jsonRoot, ...entry.path.split(\"/\")));\n if (page) {\n const { route, ...routed } = page;\n routes.set(normalizeRoute(route), routed);\n }\n }),\n );\n return routes;\n}\n\n/**\n * A page's `path`, `route`, `title`, and formatted title, from the start of\n * its JSON up to `availability`, or the whole of it if need be.\n */\nasync function readHead(file: string): Promise<(RoutedPage & { route: string }) | undefined> {\n let text: string;\n try {\n const handle = await open(file, \"r\");\n try {\n const chunks: Buffer[] = [];\n let read = 0;\n let end = -1;\n for (;;) {\n const buffer = Buffer.alloc(CHUNK_BYTES);\n const { bytesRead } = await handle.read(buffer, 0, CHUNK_BYTES, read);\n if (bytesRead === 0) break;\n chunks.push(buffer.subarray(0, bytesRead));\n read += bytesRead;\n // The marker may straddle two chunks, so look from just before this one.\n end = Buffer.concat(chunks).indexOf(\n AFTER_HEAD,\n Math.max(0, read - bytesRead - AFTER_HEAD.length),\n );\n if (end >= 0) break;\n }\n const all = Buffer.concat(chunks);\n // The keys before `availability`, closed as an object of their own.\n text =\n end >= 0\n ? `${all.subarray(0, end).toString(\"utf8\").replace(/,\\s*$/, \"\")}}`\n : all.toString(\"utf8\");\n } finally {\n await handle.close();\n }\n } catch {\n return undefined;\n }\n let page: { path?: unknown; route?: unknown; title?: unknown; formatted?: { title?: unknown } };\n try {\n page = JSON.parse(text) as typeof page;\n } catch {\n return undefined;\n }\n if (typeof page.path !== \"string\" || typeof page.route !== \"string\") return undefined;\n const formatted = page.formatted?.title;\n return {\n path: page.path,\n route: page.route,\n title: typeof page.title === \"string\" ? page.title : null,\n formatted_title: Array.isArray(formatted) ? (formatted as FormattedPiece[]) : null,\n };\n}\n"]}
|
package/dist/review/server.d.ts
CHANGED
|
@@ -75,6 +75,8 @@ export declare class ReviewServer {
|
|
|
75
75
|
private changes;
|
|
76
76
|
private compare;
|
|
77
77
|
private pageView;
|
|
78
|
+
/** The build's pages by route, read once until the next rebuild. */
|
|
79
|
+
private readRoutes;
|
|
78
80
|
/** Tells every page the threads or the changes changed; `from` is the page that did it. */
|
|
79
81
|
private changed;
|
|
80
82
|
}
|
package/dist/review/server.js
CHANGED
|
@@ -133,8 +133,10 @@ export class ReviewServer {
|
|
|
133
133
|
page: pagePath === undefined ? undefined : { build: this.options.build, path: pagePath },
|
|
134
134
|
lastPage: pagePath === undefined ? undefined : this.pages.get(pagePath),
|
|
135
135
|
changedPages: async () => {
|
|
136
|
-
const changes = await this.changes();
|
|
137
|
-
|
|
136
|
+
const [changes, routes] = await Promise.all([this.changes(), this.readRoutes()]);
|
|
137
|
+
if (!("result" in changes))
|
|
138
|
+
return [];
|
|
139
|
+
return changes.result.pages.map((p) => listed(p, routes.get(normalizeRoute(p.route))));
|
|
138
140
|
},
|
|
139
141
|
}, method, params);
|
|
140
142
|
if (answer.page)
|
|
@@ -245,11 +247,10 @@ export class ReviewServer {
|
|
|
245
247
|
throw new Error("Review is off.");
|
|
246
248
|
const route = normalizeRoute(typeof params["route"] === "string" ? params["route"] : "/");
|
|
247
249
|
const fromPage = typeof params["path"] === "string" ? params["path"] : null;
|
|
248
|
-
this.routes ??= this.options.readRoutes().catch(() => new Map());
|
|
249
250
|
const [changes, connection, routes] = await Promise.all([
|
|
250
251
|
this.changes(),
|
|
251
252
|
this.connected(),
|
|
252
|
-
this.
|
|
253
|
+
this.readRoutes(),
|
|
253
254
|
]);
|
|
254
255
|
const pages = "result" in changes ? changes.result.pages : [];
|
|
255
256
|
const shown = pages.filter((p) => p.status !== "removed");
|
|
@@ -265,20 +266,26 @@ export class ReviewServer {
|
|
|
265
266
|
problem: "error" in changes ? changes.error : null,
|
|
266
267
|
errors: "result" in changes ? changes.result.errors : 0,
|
|
267
268
|
threads: threadsState(connection),
|
|
268
|
-
changedPages: pages.map((p) => listed(p, routes.get(normalizeRoute(p.route))
|
|
269
|
+
changedPages: pages.map((p) => listed(p, routes.get(normalizeRoute(p.route)))),
|
|
269
270
|
contentRoot: this.options.contentRoot,
|
|
270
271
|
separator: path.sep,
|
|
271
272
|
};
|
|
272
273
|
}
|
|
274
|
+
/** The build's pages by route, read once until the next rebuild. */
|
|
275
|
+
readRoutes() {
|
|
276
|
+
this.routes ??= this.options.readRoutes().catch(() => new Map());
|
|
277
|
+
return this.routes;
|
|
278
|
+
}
|
|
273
279
|
/** Tells every page the threads or the changes changed; `from` is the page that did it. */
|
|
274
280
|
changed(from) {
|
|
275
281
|
this.options.channel.send(CHANGED_EVENT, { from });
|
|
276
282
|
}
|
|
277
283
|
}
|
|
278
284
|
/** A changed page as the list shows it: without its changes, with its title. */
|
|
279
|
-
function listed(page,
|
|
285
|
+
function listed(page, routed) {
|
|
280
286
|
return {
|
|
281
|
-
title,
|
|
287
|
+
title: routed?.title ?? null,
|
|
288
|
+
formatted_title: routed?.formatted_title ?? null,
|
|
282
289
|
path: page.path,
|
|
283
290
|
route: page.route,
|
|
284
291
|
status: page.status,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/review/server.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE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I,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAC5D,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,KAAK,IAAI,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpF,CAAC","sourcesContent":["// Review in the site preview, on the dev server's side: everything the\n// toolbar app asks for, answered over Astro's dev toolbar channel. Every\n// `git`, `ascribe`, and `gh` call happens here; the page gets the changes and\n// the threads, never a token. There are no HTTP routes: any page open in the\n// same browser could call a route on localhost, while the toolbar's channel\n// takes only clients that have the dev server's token (`channelProblem`).\n//\n// Nothing runs until the reviewer turns the app on. Then the server opens\n// the pull request's review (when the GitHub CLI finds one), compares the\n// build with the pull request's base (or the default branch), and compares\n// again after each rebuild.\nimport path from \"node:path\";\nimport type { OverlayMethod, ReviewSession } from \"@ascribed/review/github\";\nimport type { PageRef } from \"@ascribed/review/place\";\nimport type { DiffResult } from \"./diff.js\";\nimport { messageOf, type Connection } from \"./github.js\";\nimport {\n CHANGED_EVENT,\n REQUEST_EVENT,\n RESULT_EVENT,\n type ChangedPage,\n type DiffPage,\n type PageView,\n type Request,\n type Result,\n type Status,\n type ThreadsState,\n} from \"./protocol.js\";\nimport { normalizeRoute, type RoutedPage } from \"./routes.js\";\n\n/** A page's end of the channel: the server answers it alone. */\nexport interface ChannelClient {\n send(event: string, payload?: unknown): void;\n}\n\n/**\n * The toolbar's channel, as `astro:server:setup`'s `toolbar` has it. Its\n * listeners get the sending page's client too (it is Vite's `server.hot`);\n * without one, an answer goes to every page, which tell theirs by `tab`.\n */\nexport interface ToolbarChannel {\n on(event: string, callback: (data: unknown, client?: ChannelClient) => void): void;\n send(event: string, payload: unknown): void;\n}\n\nexport interface ReviewServerOptions {\n channel: ToolbarChannel;\n logger: { info(message: string): void; warn(message: string): void };\n build: string;\n /** The content root, absolute. */\n contentRoot: string;\n /** Why someone else could use the channel, if they could: then GitHub stays off. */\n channelProblem: string | undefined;\n /** Compares the build with `base` (the default branch when `undefined`). */\n diff(base: string | undefined): Promise<DiffResult>;\n /** Opens the pull request's review. */\n connect(): Promise<Connection>;\n /** Writes the build's JSON output, in turn with the dev server's builds: it has the routes. */\n writeRoutes(): Promise<void>;\n /** Every page of the build, by normalized route. */\n readRoutes(): Promise<Map<string, RoutedPage>>;\n /** How long to wait after a rebuild before comparing again. Default 150 ms. */\n debounceMs?: number;\n}\n\n/** The overlay's requests, which go to the session. */\nconst OVERLAY: ReadonlySet<string> = new Set<OverlayMethod>([\n \"load\",\n \"commentTarget\",\n \"comment\",\n \"reply\",\n \"allThreads\",\n \"resolve\",\n \"submit\",\n \"discard\",\n]);\n\nexport class ReviewServer {\n private on = false;\n private problem: string | undefined;\n private connection: Connection | undefined;\n private connecting: Promise<Connection> | undefined;\n private diffed: { result: DiffResult } | { error: string } | undefined;\n private diffing: Promise<void> | undefined;\n private stale = false;\n private timer: ReturnType<typeof setTimeout> | undefined;\n private routes: Promise<Map<string, RoutedPage>> | undefined;\n /** The page each overlay last read, by content path: comments are made on it. */\n private readonly pages = new Map<string, PageRef>();\n /** How long the last comparison took, in milliseconds. */\n lastDiffMs: number | undefined;\n\n constructor(private readonly options: ReviewServerOptions) {\n this.problem = options.channelProblem;\n options.channel.on(REQUEST_EVENT, (data, client) => {\n void this.receive(data, client);\n });\n }\n\n /**\n * The address the dev server listens on, once it does: one other machines\n * can reach turns comments off, as `server.host` does.\n */\n listening(address: string): void {\n if (this.problem !== undefined || isLoopback(address)) return;\n this.problem = NETWORK_PROBLEM;\n this.connection = undefined;\n this.connecting = undefined;\n }\n\n /** Whether review is on: then the dev server's builds write JSON output too. */\n get active(): boolean {\n return this.on;\n }\n\n /** The dev server rebuilt: compare again soon, and read the routes again when asked. */\n rebuilt(): void {\n if (!this.on) return;\n this.stale = true;\n this.routes = undefined;\n if (this.timer) clearTimeout(this.timer);\n this.timer = setTimeout(() => {\n this.timer = undefined;\n void this.changes();\n }, this.options.debounceMs ?? 150);\n }\n\n /** The dev server stopped. */\n dispose(): void {\n if (this.timer) clearTimeout(this.timer);\n this.on = false;\n }\n\n private async receive(data: unknown, client: ChannelClient | undefined): Promise<void> {\n const request = data as Partial<Request> | null;\n if (typeof request?.id !== \"number\" || typeof request.method !== \"string\") return;\n const params =\n typeof request.params === \"object\" && request.params !== null ? request.params : {};\n const tab = typeof request.tab === \"string\" ? request.tab : \"\";\n const answer: Result = { tab, id: request.id };\n try {\n answer.result = await this.handle(request.method, params, tab);\n } catch (error) {\n const code = (error as { code?: unknown }).code;\n answer.error =\n typeof code === \"string\"\n ? { message: messageOf(error), code }\n : { message: messageOf(error) };\n }\n if (typeof client?.send === \"function\") client.send(RESULT_EVENT, answer);\n else this.options.channel.send(RESULT_EVENT, answer);\n }\n\n /** Answers one request. Rejects with a sentence to show. */\n async handle(method: string, params: Record<string, unknown>, tab = \"\"): Promise<unknown> {\n switch (method) {\n case \"status\":\n return { on: this.on } satisfies Status;\n case \"start\":\n await this.start();\n return { on: true } satisfies Status;\n case \"stop\":\n this.stop();\n this.changed(tab);\n return { on: false } satisfies Status;\n case \"page\":\n return this.pageView(params);\n case \"refresh\":\n await this.refresh();\n this.changed(tab);\n return null;\n }\n if (!OVERLAY.has(method)) throw new Error(`Unknown request: ${method}.`);\n const connection = this.on ? await this.connected() : undefined;\n if (connection?.state !== \"on\") throw new Error(\"Review comments aren't on.\");\n const github = await import(\"@ascribed/review/github\");\n const pagePath = typeof params[\"path\"] === \"string\" ? params[\"path\"] : undefined;\n const answer = await github.answerRequest(\n {\n session: connection.session,\n page: pagePath === undefined ? undefined : { build: this.options.build, path: pagePath },\n lastPage: pagePath === undefined ? undefined : this.pages.get(pagePath),\n changedPages: async () => {\n const changes = await this.changes();\n return \"result\" in changes ? changes.result.pages : [];\n },\n },\n method as OverlayMethod,\n params,\n );\n if (answer.page) this.pages.set(answer.page.path, answer.page);\n if (answer.changed) this.changed(tab);\n return answer.result;\n }\n\n private async start(): Promise<void> {\n if (this.on) return;\n this.on = true;\n this.stale = true;\n this.routes = undefined;\n this.connection = undefined;\n const started = Date.now();\n // The routes come from the JSON output, which the next builds write too.\n const routes = this.options.writeRoutes().catch((error: unknown) => {\n this.options.logger.warn(`couldn't write the routes for review: ${messageOf(error)}`);\n });\n await this.connected();\n const changes = await this.changes();\n await routes;\n if (\"result\" in changes) {\n const base = changes.result.base;\n this.options.logger.info(\n `review: compared \"${this.options.build}\" with ${base.requested} in ${this.lastDiffMs ?? 0} ms (started in ${Date.now() - started} ms)`,\n );\n } else {\n this.options.logger.warn(`review: ${changes.error}`);\n }\n }\n\n private stop(): void {\n this.on = false;\n this.connection = undefined;\n this.connecting = undefined;\n this.diffed = undefined;\n this.routes = undefined;\n this.pages.clear();\n if (this.timer) clearTimeout(this.timer);\n this.timer = undefined;\n }\n\n private async refresh(): Promise<void> {\n if (!this.on) return;\n const connection = await this.connected();\n if (connection.state === \"on\") await connection.session.refresh();\n else this.connection = undefined;\n // A pull request found now changes the base.\n await this.connected();\n this.stale = true;\n await this.changes();\n }\n\n /** The pull request's review, opened once while review is on. */\n private connected(): Promise<Connection> {\n if (this.connection) return Promise.resolve(this.connection);\n if (this.problem !== undefined) {\n this.connection = {\n state: \"unprotected\",\n message: `Showing changes only. Comments are off because ${this.problem}.`,\n };\n return Promise.resolve(this.connection);\n }\n this.connecting ??= this.options\n .connect()\n .catch((error: unknown): Connection => ({ state: \"error\", message: messageOf(error) }))\n .then((connection) => {\n this.connecting = undefined;\n // The server turned out to listen on the network meanwhile.\n if (this.problem !== undefined) return this.connected();\n if (this.on) this.connection = connection;\n return connection;\n });\n return this.connecting;\n }\n\n /** The build's changes, compared again first if a rebuild made them stale. */\n private async changes(): Promise<{ result: DiffResult } | { error: string }> {\n while (this.diffing) await this.diffing;\n if (this.stale || this.diffed === undefined) {\n this.stale = false;\n this.diffing = this.compare().finally(() => {\n this.diffing = undefined;\n });\n await this.diffing;\n }\n return this.diffed ?? { error: \"Review is off.\" };\n }\n\n private async compare(): Promise<void> {\n const connection = await this.connected();\n const base = connection.state === \"on\" ? connection.base : undefined;\n const started = Date.now();\n try {\n this.diffed = { result: await this.options.diff(base) };\n } catch (error) {\n this.diffed = { error: messageOf(error) };\n }\n this.lastDiffMs = Date.now() - started;\n }\n\n private async pageView(params: Record<string, unknown>): Promise<PageView> {\n if (!this.on) throw new Error(\"Review is off.\");\n const route = normalizeRoute(typeof params[\"route\"] === \"string\" ? params[\"route\"] : \"/\");\n const fromPage = typeof params[\"path\"] === \"string\" ? params[\"path\"] : null;\n this.routes ??= this.options.readRoutes().catch(() => new Map<string, RoutedPage>());\n const [changes, connection, routes] = await Promise.all([\n this.changes(),\n this.connected(),\n this.routes,\n ]);\n const pages = \"result\" in changes ? changes.result.pages : [];\n const shown = pages.filter((p) => p.status !== \"removed\");\n let page = shown.find((p) => normalizeRoute(p.route) === route) ?? null;\n const pagePath = page?.path ?? fromPage ?? routes.get(route)?.path ?? null;\n if (page === null && pagePath !== null) page = shown.find((p) => p.path === pagePath) ?? null;\n return {\n kind: pagePath === null ? \"not-page\" : \"page\",\n path: pagePath,\n page,\n base: \"result\" in changes ? changes.result.base : null,\n problem: \"error\" in changes ? changes.error : null,\n errors: \"result\" in changes ? changes.result.errors : 0,\n threads: threadsState(connection),\n changedPages: pages.map((p) => listed(p, routes.get(normalizeRoute(p.route))?.title ?? null)),\n contentRoot: this.options.contentRoot,\n separator: path.sep,\n };\n }\n\n /** Tells every page the threads or the changes changed; `from` is the page that did it. */\n private changed(from: string): void {\n this.options.channel.send(CHANGED_EVENT, { from });\n }\n}\n\n/** A changed page as the list shows it: without its changes, with its title. */\nfunction listed(page: DiffPage, title: string | null): ChangedPage {\n return {\n title,\n path: page.path,\n route: page.route,\n status: page.status,\n own_file_changed: page.own_file_changed,\n because: page.because,\n page_changed: page.page_changed,\n counts: page.counts,\n };\n}\n\n/** What the page shows about the threads. */\nfunction threadsState(connection: Connection): ThreadsState {\n if (connection.state !== \"on\") return connection;\n const pr: ReviewSession[\"pullRequest\"] = connection.session.pullRequest;\n return {\n state: \"on\",\n pullRequest: { number: pr.number, url: pr.url, baseRefName: pr.baseRefName },\n local: connection.local,\n };\n}\n\n/**\n * Why someone other than the developer could use the dev server's toolbar\n * channel, or `undefined` when they can't. Vite takes a browser's connection\n * only with the token in its client script, which the page's own origin can\n * read and, by default, only localhost origins can fetch. These settings undo\n * that, and a server listening on the network gives its pages, token and all,\n * to anyone who can reach it.\n */\nexport function channelProblem(config: {\n server: { cors?: unknown; allowedHosts?: unknown; host?: unknown };\n legacy?: { skipWebSocketTokenCheck?: unknown } | undefined;\n}): string | undefined {\n const pages = \"other web pages could talk to this dev server\";\n if (config.legacy?.skipWebSocketTokenCheck === true) {\n return `${pages}: \\`legacy.skipWebSocketTokenCheck\\` is on`;\n }\n if (config.server.allowedHosts === true) return `${pages}: \\`server.allowedHosts\\` is \\`true\\``;\n const cors = config.server.cors;\n const origin =\n typeof cors === \"object\" && cors !== null ? (cors as { origin?: unknown }).origin : undefined;\n if (cors === true || origin === true || origin === \"*\") {\n return `${pages}: \\`server.cors\\` lets any origin read its pages`;\n }\n if (!isLoopback(config.server.host)) return NETWORK_PROBLEM;\n return undefined;\n}\n\nconst NETWORK_PROBLEM =\n \"the dev server is listening on the network (`--host`), so anyone who can reach it could comment as you\";\n\n/** Whether Vite's `server.host`, or the address the server listens on, keeps the server on this machine: unset, `false`, or a loopback name. */\nfunction isLoopback(host: unknown): boolean {\n if (host === undefined || host === false) return true;\n if (typeof host !== \"string\") return false;\n const name = host.toLowerCase().replace(/^\\[(.*)\\]$/, \"$1\");\n return name === \"localhost\" || name === \"::1\" || /^127(\\.\\d{1,3}){3}$/.test(name);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/review/server.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yEAAyE;AACzE,8EAA8E;AAC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M,KAAK,GAAG,EAAE,CAAC;QACvD,OAAO,GAAG,KAAK,kDAAkD,CAAC;IACpE,CAAC;IACD,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QAAE,OAAO,eAAe,CAAC;IAC5D,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,eAAe,GACnB,wGAAwG,CAAC;AAE3G,gJAAgJ;AAChJ,SAAS,UAAU,CAAC,IAAa;IAC/B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IACtD,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAC5D,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,KAAK,IAAI,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpF,CAAC","sourcesContent":["// Review in the site preview, on the dev server's side: everything the\n// toolbar app asks for, answered over Astro's dev toolbar channel. Every\n// `git`, `ascribe`, and `gh` call happens here; the page gets the changes and\n// the threads, never a token. There are no HTTP routes: any page open in the\n// same browser could call a route on localhost, while the toolbar's channel\n// takes only clients that have the dev server's token (`channelProblem`).\n//\n// Nothing runs until the reviewer turns the app on. Then the server opens\n// the pull request's review (when the GitHub CLI finds one), compares the\n// build with the pull request's base (or the default branch), and compares\n// again after each rebuild.\nimport path from \"node:path\";\nimport type { OverlayMethod, ReviewSession } from \"@ascribed/review/github\";\nimport type { PageRef } from \"@ascribed/review/place\";\nimport type { DiffResult } from \"./diff.js\";\nimport { messageOf, type Connection } from \"./github.js\";\nimport {\n CHANGED_EVENT,\n REQUEST_EVENT,\n RESULT_EVENT,\n type ChangedPage,\n type PageDiff,\n type PageView,\n type Request,\n type Result,\n type Status,\n type ThreadsState,\n} from \"./protocol.js\";\nimport { normalizeRoute, type RoutedPage } from \"./routes.js\";\n\n/** A page's end of the channel: the server answers it alone. */\nexport interface ChannelClient {\n send(event: string, payload?: unknown): void;\n}\n\n/**\n * The toolbar's channel, as `astro:server:setup`'s `toolbar` has it. Its\n * listeners get the sending page's client too (it is Vite's `server.hot`);\n * without one, an answer goes to every page, which tell theirs by `tab`.\n */\nexport interface ToolbarChannel {\n on(event: string, callback: (data: unknown, client?: ChannelClient) => void): void;\n send(event: string, payload: unknown): void;\n}\n\nexport interface ReviewServerOptions {\n channel: ToolbarChannel;\n logger: { info(message: string): void; warn(message: string): void };\n build: string;\n /** The content root, absolute. */\n contentRoot: string;\n /** Why someone else could use the channel, if they could: then GitHub stays off. */\n channelProblem: string | undefined;\n /** Compares the build with `base` (the default branch when `undefined`). */\n diff(base: string | undefined): Promise<DiffResult>;\n /** Opens the pull request's review. */\n connect(): Promise<Connection>;\n /** Writes the build's JSON output, in turn with the dev server's builds: it has the routes. */\n writeRoutes(): Promise<void>;\n /** Every page of the build, by normalized route. */\n readRoutes(): Promise<Map<string, RoutedPage>>;\n /** How long to wait after a rebuild before comparing again. Default 150 ms. */\n debounceMs?: number;\n}\n\n/** The overlay's requests, which go to the session. */\nconst OVERLAY: ReadonlySet<string> = new Set<OverlayMethod>([\n \"load\",\n \"commentTarget\",\n \"comment\",\n \"reply\",\n \"allThreads\",\n \"resolve\",\n \"submit\",\n \"discard\",\n]);\n\nexport class ReviewServer {\n private on = false;\n private problem: string | undefined;\n private connection: Connection | undefined;\n private connecting: Promise<Connection> | undefined;\n private diffed: { result: DiffResult } | { error: string } | undefined;\n private diffing: Promise<void> | undefined;\n private stale = false;\n private timer: ReturnType<typeof setTimeout> | undefined;\n private routes: Promise<Map<string, RoutedPage>> | undefined;\n /** The page each overlay last read, by content path: comments are made on it. */\n private readonly pages = new Map<string, PageRef>();\n /** How long the last comparison took, in milliseconds. */\n lastDiffMs: number | undefined;\n\n constructor(private readonly options: ReviewServerOptions) {\n this.problem = options.channelProblem;\n options.channel.on(REQUEST_EVENT, (data, client) => {\n void this.receive(data, client);\n });\n }\n\n /**\n * The address the dev server listens on, once it does: one other machines\n * can reach turns comments off, as `server.host` does.\n */\n listening(address: string): void {\n if (this.problem !== undefined || isLoopback(address)) return;\n this.problem = NETWORK_PROBLEM;\n this.connection = undefined;\n this.connecting = undefined;\n }\n\n /** Whether review is on: then the dev server's builds write JSON output too. */\n get active(): boolean {\n return this.on;\n }\n\n /** The dev server rebuilt: compare again soon, and read the routes again when asked. */\n rebuilt(): void {\n if (!this.on) return;\n this.stale = true;\n this.routes = undefined;\n if (this.timer) clearTimeout(this.timer);\n this.timer = setTimeout(() => {\n this.timer = undefined;\n void this.changes();\n }, this.options.debounceMs ?? 150);\n }\n\n /** The dev server stopped. */\n dispose(): void {\n if (this.timer) clearTimeout(this.timer);\n this.on = false;\n }\n\n private async receive(data: unknown, client: ChannelClient | undefined): Promise<void> {\n const request = data as Partial<Request> | null;\n if (typeof request?.id !== \"number\" || typeof request.method !== \"string\") return;\n const params =\n typeof request.params === \"object\" && request.params !== null ? request.params : {};\n const tab = typeof request.tab === \"string\" ? request.tab : \"\";\n const answer: Result = { tab, id: request.id };\n try {\n answer.result = await this.handle(request.method, params, tab);\n } catch (error) {\n const code = (error as { code?: unknown }).code;\n answer.error =\n typeof code === \"string\"\n ? { message: messageOf(error), code }\n : { message: messageOf(error) };\n }\n if (typeof client?.send === \"function\") client.send(RESULT_EVENT, answer);\n else this.options.channel.send(RESULT_EVENT, answer);\n }\n\n /** Answers one request. Rejects with a sentence to show. */\n async handle(method: string, params: Record<string, unknown>, tab = \"\"): Promise<unknown> {\n switch (method) {\n case \"status\":\n return { on: this.on } satisfies Status;\n case \"start\":\n await this.start();\n return { on: true } satisfies Status;\n case \"stop\":\n this.stop();\n this.changed(tab);\n return { on: false } satisfies Status;\n case \"page\":\n return this.pageView(params);\n case \"refresh\":\n await this.refresh();\n this.changed(tab);\n return null;\n }\n if (!OVERLAY.has(method)) throw new Error(`Unknown request: ${method}.`);\n const connection = this.on ? await this.connected() : undefined;\n if (connection?.state !== \"on\") throw new Error(\"Review comments aren't on.\");\n const github = await import(\"@ascribed/review/github\");\n const pagePath = typeof params[\"path\"] === \"string\" ? params[\"path\"] : undefined;\n const answer = await github.answerRequest(\n {\n session: connection.session,\n page: pagePath === undefined ? undefined : { build: this.options.build, path: pagePath },\n lastPage: pagePath === undefined ? undefined : this.pages.get(pagePath),\n changedPages: async () => {\n const [changes, routes] = await Promise.all([this.changes(), this.readRoutes()]);\n if (!(\"result\" in changes)) return [];\n return changes.result.pages.map((p) => listed(p, routes.get(normalizeRoute(p.route))));\n },\n },\n method as OverlayMethod,\n params,\n );\n if (answer.page) this.pages.set(answer.page.path, answer.page);\n if (answer.changed) this.changed(tab);\n return answer.result;\n }\n\n private async start(): Promise<void> {\n if (this.on) return;\n this.on = true;\n this.stale = true;\n this.routes = undefined;\n this.connection = undefined;\n const started = Date.now();\n // The routes come from the JSON output, which the next builds write too.\n const routes = this.options.writeRoutes().catch((error: unknown) => {\n this.options.logger.warn(`couldn't write the routes for review: ${messageOf(error)}`);\n });\n await this.connected();\n const changes = await this.changes();\n await routes;\n if (\"result\" in changes) {\n const base = changes.result.base;\n this.options.logger.info(\n `review: compared \"${this.options.build}\" with ${base.requested} in ${this.lastDiffMs ?? 0} ms (started in ${Date.now() - started} ms)`,\n );\n } else {\n this.options.logger.warn(`review: ${changes.error}`);\n }\n }\n\n private stop(): void {\n this.on = false;\n this.connection = undefined;\n this.connecting = undefined;\n this.diffed = undefined;\n this.routes = undefined;\n this.pages.clear();\n if (this.timer) clearTimeout(this.timer);\n this.timer = undefined;\n }\n\n private async refresh(): Promise<void> {\n if (!this.on) return;\n const connection = await this.connected();\n if (connection.state === \"on\") await connection.session.refresh();\n else this.connection = undefined;\n // A pull request found now changes the base.\n await this.connected();\n this.stale = true;\n await this.changes();\n }\n\n /** The pull request's review, opened once while review is on. */\n private connected(): Promise<Connection> {\n if (this.connection) return Promise.resolve(this.connection);\n if (this.problem !== undefined) {\n this.connection = {\n state: \"unprotected\",\n message: `Showing changes only. Comments are off because ${this.problem}.`,\n };\n return Promise.resolve(this.connection);\n }\n this.connecting ??= this.options\n .connect()\n .catch((error: unknown): Connection => ({ state: \"error\", message: messageOf(error) }))\n .then((connection) => {\n this.connecting = undefined;\n // The server turned out to listen on the network meanwhile.\n if (this.problem !== undefined) return this.connected();\n if (this.on) this.connection = connection;\n return connection;\n });\n return this.connecting;\n }\n\n /** The build's changes, compared again first if a rebuild made them stale. */\n private async changes(): Promise<{ result: DiffResult } | { error: string }> {\n while (this.diffing) await this.diffing;\n if (this.stale || this.diffed === undefined) {\n this.stale = false;\n this.diffing = this.compare().finally(() => {\n this.diffing = undefined;\n });\n await this.diffing;\n }\n return this.diffed ?? { error: \"Review is off.\" };\n }\n\n private async compare(): Promise<void> {\n const connection = await this.connected();\n const base = connection.state === \"on\" ? connection.base : undefined;\n const started = Date.now();\n try {\n this.diffed = { result: await this.options.diff(base) };\n } catch (error) {\n this.diffed = { error: messageOf(error) };\n }\n this.lastDiffMs = Date.now() - started;\n }\n\n private async pageView(params: Record<string, unknown>): Promise<PageView> {\n if (!this.on) throw new Error(\"Review is off.\");\n const route = normalizeRoute(typeof params[\"route\"] === \"string\" ? params[\"route\"] : \"/\");\n const fromPage = typeof params[\"path\"] === \"string\" ? params[\"path\"] : null;\n const [changes, connection, routes] = await Promise.all([\n this.changes(),\n this.connected(),\n this.readRoutes(),\n ]);\n const pages = \"result\" in changes ? changes.result.pages : [];\n const shown = pages.filter((p) => p.status !== \"removed\");\n let page = shown.find((p) => normalizeRoute(p.route) === route) ?? null;\n const pagePath = page?.path ?? fromPage ?? routes.get(route)?.path ?? null;\n if (page === null && pagePath !== null) page = shown.find((p) => p.path === pagePath) ?? null;\n return {\n kind: pagePath === null ? \"not-page\" : \"page\",\n path: pagePath,\n page,\n base: \"result\" in changes ? changes.result.base : null,\n problem: \"error\" in changes ? changes.error : null,\n errors: \"result\" in changes ? changes.result.errors : 0,\n threads: threadsState(connection),\n changedPages: pages.map((p) => listed(p, routes.get(normalizeRoute(p.route)))),\n contentRoot: this.options.contentRoot,\n separator: path.sep,\n };\n }\n\n /** The build's pages by route, read once until the next rebuild. */\n private readRoutes(): Promise<Map<string, RoutedPage>> {\n this.routes ??= this.options.readRoutes().catch(() => new Map<string, RoutedPage>());\n return this.routes;\n }\n\n /** Tells every page the threads or the changes changed; `from` is the page that did it. */\n private changed(from: string): void {\n this.options.channel.send(CHANGED_EVENT, { from });\n }\n}\n\n/** A changed page as the list shows it: without its changes, with its title. */\nfunction listed(page: PageDiff, routed: RoutedPage | undefined): ChangedPage {\n return {\n title: routed?.title ?? null,\n formatted_title: routed?.formatted_title ?? null,\n path: page.path,\n route: page.route,\n status: page.status,\n own_file_changed: page.own_file_changed,\n because: page.because,\n page_changed: page.page_changed,\n counts: page.counts,\n };\n}\n\n/** What the page shows about the threads. */\nfunction threadsState(connection: Connection): ThreadsState {\n if (connection.state !== \"on\") return connection;\n const pr: ReviewSession[\"pullRequest\"] = connection.session.pullRequest;\n return {\n state: \"on\",\n pullRequest: { number: pr.number, url: pr.url, baseRefName: pr.baseRefName },\n local: connection.local,\n };\n}\n\n/**\n * Why someone other than the developer could use the dev server's toolbar\n * channel, or `undefined` when they can't. Vite takes a browser's connection\n * only with the token in its client script, which the page's own origin can\n * read and, by default, only localhost origins can fetch. These settings undo\n * that, and a server listening on the network gives its pages, token and all,\n * to anyone who can reach it.\n */\nexport function channelProblem(config: {\n server: { cors?: unknown; allowedHosts?: unknown; host?: unknown };\n legacy?: { skipWebSocketTokenCheck?: unknown } | undefined;\n}): string | undefined {\n const pages = \"other web pages could talk to this dev server\";\n if (config.legacy?.skipWebSocketTokenCheck === true) {\n return `${pages}: \\`legacy.skipWebSocketTokenCheck\\` is on`;\n }\n if (config.server.allowedHosts === true) return `${pages}: \\`server.allowedHosts\\` is \\`true\\``;\n const cors = config.server.cors;\n const origin =\n typeof cors === \"object\" && cors !== null ? (cors as { origin?: unknown }).origin : undefined;\n if (cors === true || origin === true || origin === \"*\") {\n return `${pages}: \\`server.cors\\` lets any origin read its pages`;\n }\n if (!isLoopback(config.server.host)) return NETWORK_PROBLEM;\n return undefined;\n}\n\nconst NETWORK_PROBLEM =\n \"the dev server is listening on the network (`--host`), so anyone who can reach it could comment as you\";\n\n/** Whether Vite's `server.host`, or the address the server listens on, keeps the server on this machine: unset, `false`, or a loopback name. */\nfunction isLoopback(host: unknown): boolean {\n if (host === undefined || host === false) return true;\n if (typeof host !== \"string\") return false;\n const name = host.toLowerCase().replace(/^\\[(.*)\\]$/, \"$1\");\n return name === \"localhost\" || name === \"::1\" || /^127(\\.\\d{1,3}){3}$/.test(name);\n}\n"]}
|
package/dist/satteri.js
CHANGED
|
@@ -11,6 +11,8 @@ import { findAnchors, findEdits, toProperty } from "./attributes.js";
|
|
|
11
11
|
/** Applies the site output's attribute markers (`ascribe-attributes`) and source anchors. */
|
|
12
12
|
export function satteriAscribeAttributes() {
|
|
13
13
|
return {
|
|
14
|
+
// The plugin's own name, shown in Astro's errors; it's spelled like the
|
|
15
|
+
// marker (ELEMENT_ATTRIBUTES) but isn't it, so it stays a literal.
|
|
14
16
|
name: "ascribe-attributes",
|
|
15
17
|
before(root, ctx) {
|
|
16
18
|
for (const edit of findEdits(root)) {
|
package/dist/satteri.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"satteri.js","sourceRoot":"","sources":["../src/satteri.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,kEAAkE;AAClE,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,2EAA2E;AAC3E,2EAA2E;AAC3E,8EAA8E;AAC9E,+CAA+C;AAG/C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAiB,MAAM,iBAAiB,CAAC;AAEpF,6FAA6F;AAC7F,MAAM,UAAU,wBAAwB;IACtC,OAAO;QACL,IAAI,EAAE,oBAAoB;QAC1B,MAA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,OAAO,CAAC,IAA8B,EAAE;wBAC7D,IAAI,EAAE,KAAK;wBACX,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK;qBAC5B,CAAC,CAAC;gBACL,CAAC;gBACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM;oBAAE,GAAG,CAAC,UAAU,CAAC,IAA8B,CAAC,CAAC;YACnF,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// The attribute marker and source anchors as a Sätteri hast plugin, for Astro\n// 7.3's default markdown processor (`@astrojs/markdown-satteri`).\n//\n// Astro runs that processor's hast plugins in this order: highlighting, the\n// user's plugins, its image marker (which reads an `<img>`'s properties), and\n// its heading ids (which keeps an id a heading already has). A user plugin\n// therefore runs before both, and sees a marker as two `raw` nodes, as the\n// unified processor's plugin does, and an anchor comment as a `raw` node. The\n// rules are `findEdits`'s and `findAnchors`'s.\n\nimport type { HastNode as SatteriNode, HastVisitorInstance } from \"satteri\";\nimport { findAnchors, findEdits, toProperty, type HastNode } from \"./attributes.js\";\n\n/** Applies the site output's attribute markers (`ascribe-attributes`) and source anchors. */\nexport function satteriAscribeAttributes(): HastVisitorInstance & { name: string } {\n return {\n name: \"ascribe-attributes\",\n before(root, ctx) {\n for (const edit of findEdits(root as HastNode)) {\n const target = edit.target as unknown as SatteriNode;\n for (const attribute of edit.attributes) {\n const [name, value] = toProperty(attribute);\n ctx.setProperty(target, name, value);\n }\n for (const node of edit.remove) ctx.removeNode(node as unknown as SatteriNode);\n for (const { node, value } of edit.trim) {\n if (value === \"\") ctx.removeNode(node as unknown as SatteriNode);\n else ctx.replaceNode(node as unknown as SatteriNode, { type: \"text\", value });\n }\n }\n for (const anchor of findAnchors(root as HastNode)) {\n for (const { node, attributes } of anchor.targets) {\n for (const attribute of attributes) {\n const [name, value] = toProperty(attribute);\n ctx.setProperty(node as unknown as SatteriNode, name, value);\n }\n }\n if (anchor.replace) {\n ctx.replaceNode(anchor.replace.node as unknown as SatteriNode, {\n type: \"raw\",\n value: anchor.replace.value,\n });\n }\n for (const node of anchor.remove) ctx.removeNode(node as unknown as SatteriNode);\n }\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"satteri.js","sourceRoot":"","sources":["../src/satteri.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,kEAAkE;AAClE,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,2EAA2E;AAC3E,2EAA2E;AAC3E,8EAA8E;AAC9E,+CAA+C;AAG/C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAiB,MAAM,iBAAiB,CAAC;AAEpF,6FAA6F;AAC7F,MAAM,UAAU,wBAAwB;IACtC,OAAO;QACL,wEAAwE;QACxE,mEAAmE;QACnE,IAAI,EAAE,oBAAoB;QAC1B,MAAM,CAAC,IAAI,EAAE,GAAG;YACd,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,IAAgB,CAAC,EAAE,CAAC;gBAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAgC,CAAC;gBACrD,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;oBACxC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;oBAC5C,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;gBACvC,CAAC;gBACD,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM;oBAAE,GAAG,CAAC,UAAU,CAAC,IAA8B,CAAC,CAAC;gBAC/E,KAAK,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;oBACxC,IAAI,KAAK,KAAK,EAAE;wBAAE,GAAG,CAAC,UAAU,CAAC,IAA8B,CAAC,CAAC;;wBAC5D,GAAG,CAAC,WAAW,CAAC,IAA8B,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;gBAChF,CAAC;YACH,CAAC;YACD,KAAK,MAAM,MAAM,IAAI,WAAW,CAAC,IAAgB,CAAC,EAAE,CAAC;gBACnD,KAAK,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;oBAClD,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;wBACnC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;wBAC5C,GAAG,CAAC,WAAW,CAAC,IAA8B,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;oBAC/D,CAAC;gBACH,CAAC;gBACD,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;oBACnB,GAAG,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,IAA8B,EAAE;wBAC7D,IAAI,EAAE,KAAK;wBACX,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK;qBAC5B,CAAC,CAAC;gBACL,CAAC;gBACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM;oBAAE,GAAG,CAAC,UAAU,CAAC,IAA8B,CAAC,CAAC;YACnF,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// The attribute marker and source anchors as a Sätteri hast plugin, for Astro\n// 7.3's default markdown processor (`@astrojs/markdown-satteri`).\n//\n// Astro runs that processor's hast plugins in this order: highlighting, the\n// user's plugins, its image marker (which reads an `<img>`'s properties), and\n// its heading ids (which keeps an id a heading already has). A user plugin\n// therefore runs before both, and sees a marker as two `raw` nodes, as the\n// unified processor's plugin does, and an anchor comment as a `raw` node. The\n// rules are `findEdits`'s and `findAnchors`'s.\n\nimport type { HastNode as SatteriNode, HastVisitorInstance } from \"satteri\";\nimport { findAnchors, findEdits, toProperty, type HastNode } from \"./attributes.js\";\n\n/** Applies the site output's attribute markers (`ascribe-attributes`) and source anchors. */\nexport function satteriAscribeAttributes(): HastVisitorInstance & { name: string } {\n return {\n // The plugin's own name, shown in Astro's errors; it's spelled like the\n // marker (ELEMENT_ATTRIBUTES) but isn't it, so it stays a literal.\n name: \"ascribe-attributes\",\n before(root, ctx) {\n for (const edit of findEdits(root as HastNode)) {\n const target = edit.target as unknown as SatteriNode;\n for (const attribute of edit.attributes) {\n const [name, value] = toProperty(attribute);\n ctx.setProperty(target, name, value);\n }\n for (const node of edit.remove) ctx.removeNode(node as unknown as SatteriNode);\n for (const { node, value } of edit.trim) {\n if (value === \"\") ctx.removeNode(node as unknown as SatteriNode);\n else ctx.replaceNode(node as unknown as SatteriNode, { type: \"text\", value });\n }\n }\n for (const anchor of findAnchors(root as HastNode)) {\n for (const { node, attributes } of anchor.targets) {\n for (const attribute of attributes) {\n const [name, value] = toProperty(attribute);\n ctx.setProperty(node as unknown as SatteriNode, name, value);\n }\n }\n if (anchor.replace) {\n ctx.replaceNode(anchor.replace.node as unknown as SatteriNode, {\n type: \"raw\",\n value: anchor.replace.value,\n });\n }\n for (const node of anchor.remove) ctx.removeNode(node as unknown as SatteriNode);\n }\n },\n };\n}\n"]}
|
package/dist/shapes.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a block's text is written: the README's anchor grammar, the same
|
|
3
|
+
* string the rendered page carries in `data-ascribe-source` and
|
|
4
|
+
* `data-ascribe-via`.
|
|
5
|
+
*/
|
|
6
|
+
export interface Anchor {
|
|
7
|
+
/**
|
|
8
|
+
* `<path>:<first>-<last>`: the file's content path, percent-encoded by
|
|
9
|
+
* segment, and the block's first and last lines, from 1.
|
|
10
|
+
*/
|
|
11
|
+
source: string;
|
|
12
|
+
/**
|
|
13
|
+
* The includes the block came through, outermost first, each
|
|
14
|
+
* `<path>:<line>`. Empty for a block written in the page itself.
|
|
15
|
+
*/
|
|
16
|
+
via: string[];
|
|
17
|
+
}
|
|
18
|
+
/** The base of a comparison, in the report. */
|
|
19
|
+
export interface BaseInfo {
|
|
20
|
+
/** The revision asked for, or the default branch used. */
|
|
21
|
+
requested: string;
|
|
22
|
+
/** The commit it names. */
|
|
23
|
+
commit: string;
|
|
24
|
+
/**
|
|
25
|
+
* The merge base of that commit and `HEAD`, which the comparison reads;
|
|
26
|
+
* `null` with `--base-exact`, which reads `commit`.
|
|
27
|
+
*/
|
|
28
|
+
merge_base: string | null;
|
|
29
|
+
}
|
|
30
|
+
/** What changed in one build. */
|
|
31
|
+
export interface BuildDiff {
|
|
32
|
+
/** The build's name. */
|
|
33
|
+
build: string;
|
|
34
|
+
/** The pages that changed, in path order. */
|
|
35
|
+
pages: PageDiff[];
|
|
36
|
+
}
|
|
37
|
+
/** One block's change. */
|
|
38
|
+
export interface Change {
|
|
39
|
+
/** What happened to it. */
|
|
40
|
+
kind: ChangeKind;
|
|
41
|
+
/**
|
|
42
|
+
* For a removed block, and a moved block's old place: the block of the
|
|
43
|
+
* new version it came after, among its siblings. Absent when it was
|
|
44
|
+
* first.
|
|
45
|
+
*/
|
|
46
|
+
after?: Anchor;
|
|
47
|
+
/** Where it's written now: every kind but `removed`. */
|
|
48
|
+
now?: Anchor;
|
|
49
|
+
/**
|
|
50
|
+
* For a removed block, and a moved block's old place: the block of the
|
|
51
|
+
* new version it was inside. Absent at the top of the page.
|
|
52
|
+
*/
|
|
53
|
+
parent?: Anchor;
|
|
54
|
+
/**
|
|
55
|
+
* For a removed block, its text, whitespace collapsed, so it can be
|
|
56
|
+
* shown where it was.
|
|
57
|
+
*/
|
|
58
|
+
text?: string;
|
|
59
|
+
/** Where it was written: every kind but `added`. */
|
|
60
|
+
was?: Anchor;
|
|
61
|
+
/** For changed prose, the words that differ. */
|
|
62
|
+
words?: Words;
|
|
63
|
+
}
|
|
64
|
+
/** The kinds of block change. */
|
|
65
|
+
export type ChangeKind = "changed" | "added" | "removed" | "moved";
|
|
66
|
+
/** How many changes of each kind a page has. */
|
|
67
|
+
export interface Counts {
|
|
68
|
+
/** Blocks whose content changed. */
|
|
69
|
+
changed: number;
|
|
70
|
+
/** Blocks only in the new version. */
|
|
71
|
+
added: number;
|
|
72
|
+
/** Blocks only in the old version. */
|
|
73
|
+
removed: number;
|
|
74
|
+
/** Blocks in both, somewhere else. */
|
|
75
|
+
moved: number;
|
|
76
|
+
}
|
|
77
|
+
/** The whole report, as `ascribe diff --format json` writes it. */
|
|
78
|
+
export interface DiffReport {
|
|
79
|
+
/** `SCHEMA_VERSION`. */
|
|
80
|
+
schema_version: number;
|
|
81
|
+
/** The version of Ascribe that wrote it. */
|
|
82
|
+
ascribe_version: string;
|
|
83
|
+
/** What was compared with. */
|
|
84
|
+
base: BaseInfo;
|
|
85
|
+
/** Where the project is. */
|
|
86
|
+
repository: RepositoryInfo;
|
|
87
|
+
/**
|
|
88
|
+
* How many errors `ascribe check` finds in the working tree, for the
|
|
89
|
+
* builds compared. The comparison runs regardless, but a page with an
|
|
90
|
+
* error may not render as it will once it's fixed, so a reviewer should
|
|
91
|
+
* know. `diff_project` sets it; `Report::new` leaves it zero.
|
|
92
|
+
*/
|
|
93
|
+
working_tree_errors: number;
|
|
94
|
+
/** What changed, per build, in the order asked for. */
|
|
95
|
+
builds: BuildDiff[];
|
|
96
|
+
}
|
|
97
|
+
/** What changed on one page of a build. */
|
|
98
|
+
export interface PageDiff {
|
|
99
|
+
/** The page's content path. */
|
|
100
|
+
path: string;
|
|
101
|
+
/** Its route: the new one, or for a removed page the old one. */
|
|
102
|
+
route: string;
|
|
103
|
+
/**
|
|
104
|
+
* Whether the build publishes it only now, only before, or in both
|
|
105
|
+
* with a difference.
|
|
106
|
+
*/
|
|
107
|
+
status: PageStatus;
|
|
108
|
+
/** Whether the page's own file changed (or exists on one side only). */
|
|
109
|
+
own_file_changed: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* The other changed files the page's change can come from: fragments it
|
|
112
|
+
* includes and pages its links take a title or a heading from, in path
|
|
113
|
+
* order; then the snippets whose code changed, by address
|
|
114
|
+
* (`code:app.py#main`); and `ascribe.toml` (last) when the content model
|
|
115
|
+
* is a cause.
|
|
116
|
+
*/
|
|
117
|
+
because: string[];
|
|
118
|
+
/**
|
|
119
|
+
* What changed about the page itself besides its blocks, in this
|
|
120
|
+
* order: `title`, `frontmatter`, `availability` (the page-level one),
|
|
121
|
+
* and `route`. Empty for an added or removed page.
|
|
122
|
+
*/
|
|
123
|
+
page_changed: string[];
|
|
124
|
+
/** How many changes of each kind. */
|
|
125
|
+
counts: Counts;
|
|
126
|
+
/**
|
|
127
|
+
* The block-level changes, in the page's order, a removed block where
|
|
128
|
+
* it was. Empty for an added or removed page.
|
|
129
|
+
*/
|
|
130
|
+
changes: Change[];
|
|
131
|
+
}
|
|
132
|
+
/** Whether a page is new, gone, or different. */
|
|
133
|
+
export type PageStatus = "added" | "removed" | "changed";
|
|
134
|
+
/** The repository, in the report. */
|
|
135
|
+
export interface RepositoryInfo {
|
|
136
|
+
/** The repository's top-level directory, as git prints it. */
|
|
137
|
+
root: string;
|
|
138
|
+
/**
|
|
139
|
+
* The project's folder inside it, with a trailing `/`, or empty when
|
|
140
|
+
* the project is at the repository's root.
|
|
141
|
+
*/
|
|
142
|
+
project_prefix: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The words that differ inside a changed block of prose. Ranges are
|
|
146
|
+
* `[start, end)` in characters (Unicode scalar values) of each side's
|
|
147
|
+
* `text`, which is the block's text with whitespace collapsed.
|
|
148
|
+
*/
|
|
149
|
+
export interface Words {
|
|
150
|
+
/** Ranges in `now_text`: words added or replacing others. */
|
|
151
|
+
now: [number, number][];
|
|
152
|
+
/** Ranges in `was_text`: words removed or replaced. */
|
|
153
|
+
was: [number, number][];
|
|
154
|
+
/** The block's text now. */
|
|
155
|
+
now_text: string;
|
|
156
|
+
/** The block's text before. */
|
|
157
|
+
was_text: string;
|
|
158
|
+
}
|
package/dist/shapes.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The JSON Ascribe writes that this package reads, as TypeScript types.
|
|
2
|
+
// Generated from the Rust types that write it, through the JSON Schemas in
|
|
3
|
+
// schemas/, by crates/ascribe-cli/src/shapes.rs. Change the Rust types, then
|
|
4
|
+
// run `ASCRIBE_BLESS=1 cargo test -p ascribe-cli shapes`. Don't edit it.
|
|
5
|
+
//
|
|
6
|
+
// - DiffReport (`ascribe diff --format json`)
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=shapes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shapes.js","sourceRoot":"","sources":["../src/shapes.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,2EAA2E;AAC3E,6EAA6E;AAC7E,yEAAyE;AACzE,EAAE;AACF,8CAA8C","sourcesContent":["// The JSON Ascribe writes that this package reads, as TypeScript types.\n// Generated from the Rust types that write it, through the JSON Schemas in\n// schemas/, by crates/ascribe-cli/src/shapes.rs. Change the Rust types, then\n// run `ASCRIBE_BLESS=1 cargo test -p ascribe-cli shapes`. Don't edit it.\n//\n// - DiffReport (`ascribe diff --format json`)\n\n/**\n * Where a block's text is written: the README's anchor grammar, the same\n * string the rendered page carries in `data-ascribe-source` and\n * `data-ascribe-via`.\n */\nexport interface Anchor {\n /**\n * `<path>:<first>-<last>`: the file's content path, percent-encoded by\n * segment, and the block's first and last lines, from 1.\n */\n source: string;\n /**\n * The includes the block came through, outermost first, each\n * `<path>:<line>`. Empty for a block written in the page itself.\n */\n via: string[];\n}\n\n/** The base of a comparison, in the report. */\nexport interface BaseInfo {\n /** The revision asked for, or the default branch used. */\n requested: string;\n /** The commit it names. */\n commit: string;\n /**\n * The merge base of that commit and `HEAD`, which the comparison reads;\n * `null` with `--base-exact`, which reads `commit`.\n */\n merge_base: string | null;\n}\n\n/** What changed in one build. */\nexport interface BuildDiff {\n /** The build's name. */\n build: string;\n /** The pages that changed, in path order. */\n pages: PageDiff[];\n}\n\n/** One block's change. */\nexport interface Change {\n /** What happened to it. */\n kind: ChangeKind;\n /**\n * For a removed block, and a moved block's old place: the block of the\n * new version it came after, among its siblings. Absent when it was\n * first.\n */\n after?: Anchor;\n /** Where it's written now: every kind but `removed`. */\n now?: Anchor;\n /**\n * For a removed block, and a moved block's old place: the block of the\n * new version it was inside. Absent at the top of the page.\n */\n parent?: Anchor;\n /**\n * For a removed block, its text, whitespace collapsed, so it can be\n * shown where it was.\n */\n text?: string;\n /** Where it was written: every kind but `added`. */\n was?: Anchor;\n /** For changed prose, the words that differ. */\n words?: Words;\n}\n\n/** The kinds of block change. */\nexport type ChangeKind = \"changed\" | \"added\" | \"removed\" | \"moved\";\n\n/** How many changes of each kind a page has. */\nexport interface Counts {\n /** Blocks whose content changed. */\n changed: number;\n /** Blocks only in the new version. */\n added: number;\n /** Blocks only in the old version. */\n removed: number;\n /** Blocks in both, somewhere else. */\n moved: number;\n}\n\n/** The whole report, as `ascribe diff --format json` writes it. */\nexport interface DiffReport {\n /** `SCHEMA_VERSION`. */\n schema_version: number;\n /** The version of Ascribe that wrote it. */\n ascribe_version: string;\n /** What was compared with. */\n base: BaseInfo;\n /** Where the project is. */\n repository: RepositoryInfo;\n /**\n * How many errors `ascribe check` finds in the working tree, for the\n * builds compared. The comparison runs regardless, but a page with an\n * error may not render as it will once it's fixed, so a reviewer should\n * know. `diff_project` sets it; `Report::new` leaves it zero.\n */\n working_tree_errors: number;\n /** What changed, per build, in the order asked for. */\n builds: BuildDiff[];\n}\n\n/** What changed on one page of a build. */\nexport interface PageDiff {\n /** The page's content path. */\n path: string;\n /** Its route: the new one, or for a removed page the old one. */\n route: string;\n /**\n * Whether the build publishes it only now, only before, or in both\n * with a difference.\n */\n status: PageStatus;\n /** Whether the page's own file changed (or exists on one side only). */\n own_file_changed: boolean;\n /**\n * The other changed files the page's change can come from: fragments it\n * includes and pages its links take a title or a heading from, in path\n * order; then the snippets whose code changed, by address\n * (`code:app.py#main`); and `ascribe.toml` (last) when the content model\n * is a cause.\n */\n because: string[];\n /**\n * What changed about the page itself besides its blocks, in this\n * order: `title`, `frontmatter`, `availability` (the page-level one),\n * and `route`. Empty for an added or removed page.\n */\n page_changed: string[];\n /** How many changes of each kind. */\n counts: Counts;\n /**\n * The block-level changes, in the page's order, a removed block where\n * it was. Empty for an added or removed page.\n */\n changes: Change[];\n}\n\n/** Whether a page is new, gone, or different. */\nexport type PageStatus = \"added\" | \"removed\" | \"changed\";\n\n/** The repository, in the report. */\nexport interface RepositoryInfo {\n /** The repository's top-level directory, as git prints it. */\n root: string;\n /**\n * The project's folder inside it, with a trailing `/`, or empty when\n * the project is at the repository's root.\n */\n project_prefix: string;\n}\n\n/**\n * The words that differ inside a changed block of prose. Ranges are\n * `[start, end)` in characters (Unicode scalar values) of each side's\n * `text`, which is the block's text with whitespace collapsed.\n */\nexport interface Words {\n /** Ranges in `now_text`: words added or replacing others. */\n now: [number, number][];\n /** Ranges in `was_text`: words removed or replaced. */\n was: [number, number][];\n /** The block's text now. */\n now_text: string;\n /** The block's text before. */\n was_text: string;\n}\n"]}
|