-
Notifications
You must be signed in to change notification settings - Fork 17
feat(xref): add headings lookup API for cross-spec section links #469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fac1a08
feat(xref): add headings lookup API for cross-spec section links
marcoscaceres 1b8b796
fix: address Copilot review feedback on headings API
marcoscaceres 44856c1
refactor(xref): address reviewer feedback on headings API
Copilot abb38b3
Apply suggestion from @sidvishnoi
marcoscaceres 0881359
Update routes/xref/index.ts
marcoscaceres 6f769f4
fix(xref/headings): fix specTitleMap, add query limit, harden error h…
marcoscaceres db0b1a7
refactor(xref/headings): pre-index headings by ID at scrape time
marcoscaceres ed28a35
fix(xref/headings): trim inputs, add version/series fallback in getHe…
marcoscaceres a722cce
fix: correct specmap type to match nested JSON structure
marcoscaceres a6a9f23
fix: address Sid's review comments on PR #469
marcoscaceres File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { Request, Response } from "express"; | ||
| import { store } from "./lib/store-init.js"; | ||
|
|
||
| interface HeadingsQuery { | ||
| spec: string; | ||
| id: string; | ||
| } | ||
|
|
||
| interface RequestBody { | ||
| queries: HeadingsQuery[]; | ||
| } | ||
|
|
||
| type IRequest = Request<never, any, RequestBody>; | ||
|
|
||
| /** | ||
| * POST /xref/search/headings | ||
| * | ||
| * Looks up section headings by spec shortname and fragment id. | ||
| * Used by ReSpec's [[[SPEC#id]]] syntax to get heading text for | ||
| * cross-spec section links. | ||
| * | ||
| * Request body: { queries: [{ spec: "fetch", id: "cookie-header" }] } | ||
| * Response: { result: [{ spec: "fetch", id: "cookie-header", ... }] } | ||
| */ | ||
| export default function route(req: IRequest, res: Response) { | ||
| const { queries } = req.body; | ||
| if (!Array.isArray(queries)) { | ||
| res.status(400).json({ error: "queries must be an array" }); | ||
| return; | ||
| } | ||
| if (queries.length > 1000) { | ||
| res.status(400).json({ error: "too many queries (max 1000)" }); | ||
| return; | ||
| } | ||
| for (const item of queries) { | ||
| if (typeof item?.spec !== "string" || typeof item?.id !== "string") { | ||
| res.status(400); | ||
| res.json({ error: "each query must have string fields: spec, id" }); | ||
| return; | ||
| } | ||
| if (!item.spec.trim() || !item.id.trim()) { | ||
| res.status(400); | ||
| res.json({ error: "spec and id must be non-empty strings" }); | ||
| return; | ||
| } | ||
| } | ||
| const result = queries.map(({ spec, id }) => { | ||
| const heading = store.getHeading(spec.trim(), id.trim()); | ||
| if (!heading) { | ||
| return { spec, id, error: "not found" }; | ||
| } | ||
|
sidvishnoi marked this conversation as resolved.
|
||
| return { | ||
| spec, | ||
| id, | ||
| title: heading.title, | ||
| number: heading.number || null, | ||
| href: heading.href, | ||
| level: heading.level, | ||
| specTitle: heading.specTitle, | ||
| }; | ||
| }); | ||
| res.json({ result }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.