@ascribed/astro 0.2.0 → 0.2.1-next.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/review/server.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yEAAyE;AACzE,8EAA8E;AAC9E,6EAA6E;AAC7E,4EAA4E;AAC5E,0EAA0E;AAC1E,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,2EAA2E;AAC3E,4BAA4B;AAC5B,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,OAAO,EAAE,SAAS,EAAmB,MAAM,aAAa,CAAC;AACzD,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,GAQb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAmB,MAAM,aAAa,CAAC;AAqC9D,uDAAuD;AACvD,MAAM,OAAO,GAAwB,IAAI,GAAG,CAAgB;IAC1D,MAAM;IACN,eAAe;IACf,SAAS;IACT,OAAO;IACP,YAAY;IACZ,SAAS;IACT,QAAQ;IACR,SAAS;CACV,CAAC,CAAC;AAEH,MAAM,OAAO,YAAY;IAeM,OAAO;IAd5B,EAAE,GAAG,KAAK,CAAC;IACX,OAAO,CAAqB;IAC5B,UAAU,CAAyB;IACnC,UAAU,CAAkC;IAC5C,MAAM,CAAyD;IAC/D,OAAO,CAA4B;IACnC,KAAK,GAAG,KAAK,CAAC;IACd,KAAK,CAA4C;IACjD,MAAM,CAA+C;IAC7D,iFAAiF;IAChE,KAAK,GAAG,IAAI,GAAG,EAAmB,CAAC;IACpD,0DAA0D;IAC1D,UAAU,CAAqB;IAE/B,YAA6B,OAA4B;uBAA5B,OAAO;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC;QACtC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,EAA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;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 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;AAC9E,6EAA6E;AAC7E,4EAA4E;AAC5E,0EAA0E;AAC1E,EAAE;AACF,0EAA0E;AAC1E,0EAA0E;AAC1E,2EAA2E;AAC3E,4BAA4B;AAC5B,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,OAAO,EAAE,SAAS,EAAmB,MAAM,aAAa,CAAC;AACzD,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,GAQb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAmB,MAAM,aAAa,CAAC;AAqC9D,uDAAuD;AACvD,MAAM,OAAO,GAAwB,IAAI,GAAG,CAAgB;IAC1D,MAAM;IACN,eAAe;IACf,SAAS;IACT,OAAO;IACP,YAAY;IACZ,SAAS;IACT,QAAQ;IACR,SAAS;CACV,CAAC,CAAC;AAEH,MAAM,OAAO,YAAY;IAeM,OAAO;IAd5B,EAAE,GAAG,KAAK,CAAC;IACX,OAAO,CAAqB;IAC5B,UAAU,CAAyB;IACnC,UAAU,CAAkC;IAC5C,MAAM,CAAyD;IAC/D,OAAO,CAA4B;IACnC,KAAK,GAAG,KAAK,CAAC;IACd,KAAK,CAA4C;IACjD,MAAM,CAA+C;IAC7D,iFAAiF;IAChE,KAAK,GAAG,IAAI,GAAG,EAAmB,CAAC;IACpD,0DAA0D;IAC1D,UAAU,CAAqB;IAE/B,YAA6B,OAA4B;uBAA5B,OAAO;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC;QACtC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE;YACjD,KAAK,IAAI,CAAC,OA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AC;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 = 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: PageDiff, 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"]}
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)) {
@@ -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,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 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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,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"]}
@@ -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"]}
@@ -15,6 +15,7 @@ import { APP_ID, CHANGED_EVENT, REQUEST_EVENT, RESULT_EVENT, } from "../review/p
15
15
  import { anchorOf, anchoredBlocks, anchorsArrived, contentRoot, pageFile, pageScheme, sourceLocation, } from "./page.js";
16
16
  import { PANEL_CSS } from "./style.js";
17
17
  import { againstText, buttonLabel, countsText, errorsNotice, nextChangedPage, nextPageText, pageDetail, position, THREAD_HASH, threadLocation, threadsNotice, unsentText, } from "./text.js";
18
+ import { CLASS_LABEL, CLASS_LABEL_BEFORE, CLASS_MARKS, DATA_REVIEW, DATA_SCHEME, DATA_SHOW, DATA_SOURCE, DATA_VIA, } from "../names.js";
18
19
  /** The width of the page's container from which threads show in a column beside it. */
19
20
  const COLUMN_AT = 720;
20
21
  /** The room between the panel and the window's edges, or the column of threads. */
@@ -122,7 +123,7 @@ class ReviewApp {
122
123
  this.live.setAttribute("role", "status");
123
124
  this.live.setAttribute("aria-live", "polite");
124
125
  canvas.append(style, this.panel, this.live);
125
- this.siteScheme = doc.documentElement.getAttribute("data-ascribe-scheme");
126
+ this.siteScheme = doc.documentElement.getAttribute(DATA_SCHEME);
126
127
  const win = doc.defaultView;
127
128
  win
128
129
  ?.matchMedia?.("(prefers-color-scheme: dark)")
@@ -136,7 +137,7 @@ class ReviewApp {
136
137
  this.restyleTimer = setTimeout(() => this.applyScheme(), 400);
137
138
  };
138
139
  const observer = new MutationObserver((records) => {
139
- if (records.some((r) => r.attributeName !== "data-ascribe-scheme"))
140
+ if (records.some((r) => r.attributeName !== DATA_SCHEME))
140
141
  restyle();
141
142
  });
142
143
  for (const target of [doc.documentElement, doc.body]) {
@@ -340,11 +341,11 @@ class ReviewApp {
340
341
  /** Each mark's label opens its block's source. */
341
342
  linkLabels() {
342
343
  for (const mark of this.marks) {
343
- const source = mark.element.getAttribute("data-ascribe-source");
344
+ const source = mark.element.getAttribute(DATA_SOURCE);
344
345
  const label = labelOf(mark.element);
345
346
  if (source === null || !label)
346
347
  continue;
347
- label.title = `Open ${describeSource(source, mark.element.getAttribute("data-ascribe-via"))}`;
348
+ label.title = `Open ${describeSource(source, mark.element.getAttribute(DATA_VIA))}`;
348
349
  label.tabIndex = 0;
349
350
  label.setAttribute("role", "link");
350
351
  const open = (event) => {
@@ -363,7 +364,7 @@ class ReviewApp {
363
364
  if (this.style?.isConnected)
364
365
  return;
365
366
  this.style = this.doc.createElement("style");
366
- this.style.setAttribute("data-ascribe-review", "");
367
+ this.style.setAttribute(DATA_REVIEW, "");
367
368
  this.style.textContent = marksCss;
368
369
  this.doc.head.append(this.style);
369
370
  }
@@ -373,8 +374,8 @@ class ReviewApp {
373
374
  this.stopSources = undefined;
374
375
  if (this.root) {
375
376
  clearMarks(this.root);
376
- this.root.classList.remove("ascribe-marks");
377
- this.root.removeAttribute("data-ascribe-show");
377
+ this.root.classList.remove(CLASS_MARKS);
378
+ this.root.removeAttribute(DATA_SHOW);
378
379
  }
379
380
  this.root = undefined;
380
381
  this.marked = undefined;
@@ -545,9 +546,9 @@ class ReviewApp {
545
546
  return;
546
547
  const html = this.doc.documentElement;
547
548
  if (!this.root)
548
- html.removeAttribute("data-ascribe-scheme");
549
- else if (html.getAttribute("data-ascribe-scheme") !== scheme)
550
- html.setAttribute("data-ascribe-scheme", scheme);
549
+ html.removeAttribute(DATA_SCHEME);
550
+ else if (html.getAttribute(DATA_SCHEME) !== scheme)
551
+ html.setAttribute(DATA_SCHEME, scheme);
551
552
  }
552
553
  /** Keeps the panel clear of the column of threads, over the page beside it. */
553
554
  placePanel() {
@@ -748,7 +749,7 @@ class ReviewApp {
748
749
  .join(" and ");
749
750
  body.append(this.el("b", "", anchoredBlocks(this.doc).length === 0
750
751
  ? `This page has ${what}, but its blocks carry no source anchors.`
751
- : `This page has ${what}, but most of its changed blocks carry no source anchors.`), this.el("span", "", "A layout or component is probably dropping the data-ascribe-source attributes, so nothing can be placed on the page. Everything is listed here instead."));
752
+ : `This page has ${what}, but most of its changed blocks carry no source anchors.`), this.el("span", "", `A layout or component is probably dropping the ${DATA_SOURCE} attributes, so nothing can be placed on the page. Everything is listed here instead.`));
752
753
  if (changes.length > 0) {
753
754
  body.append(this.el("span", "hint", "Changes"));
754
755
  const list = this.el("ul", "");
@@ -882,11 +883,11 @@ class ReviewApp {
882
883
  }
883
884
  /** The label the marks put on a block: inside it at its start, or just before it. */
884
885
  function labelOf(element) {
885
- const inside = element.querySelector(":scope > .ascribe-label");
886
+ const inside = element.querySelector(`:scope > .${CLASS_LABEL}`);
886
887
  if (inside)
887
888
  return inside;
888
889
  const before = element.previousElementSibling;
889
- return before instanceof HTMLElement && before.classList.contains("ascribe-label-before")
890
+ return before instanceof HTMLElement && before.classList.contains(CLASS_LABEL_BEFORE)
890
891
  ? before
891
892
  : undefined;
892
893
  }