-
Notifications
You must be signed in to change notification settings - Fork 0
docs(fs): document runtime trust boundary #3778
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
6c1eb1f
docs(fs): document runtime trust boundary
kojiwakayama 0f1c150
docs: fix filesystem boundary examples
kojiwakayama bfc1b94
docs(fs): read through validated adapter
kojiwakayama a7b434d
fix(docs): delimit inline code safely
kojiwakayama 419133c
fix(docs): preserve markdown delimiters
kojiwakayama ff1dcef
fix(docs): preserve fenced remarks
kojiwakayama 4f178e6
docs(fs): state concurrent-writer precondition
kojiwakayama 723ebd9
docs(fs): include Bun runtime support
kojiwakayama 85e09c4
test(docs): match Bun runtime wording
kojiwakayama 7f2f4af
docs(fs): use public confinement APIs
kojiwakayama 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
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
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,148 @@ | ||
| export interface BarrelJSDoc { | ||
| description: string; | ||
| moduleName: string; | ||
| remarks: string; | ||
| examples: Array<{ title: string; code: string }>; | ||
| } | ||
|
|
||
| const EMPTY_BARREL_JSDOC: BarrelJSDoc = { | ||
| description: "", | ||
| moduleName: "", | ||
| remarks: "", | ||
| examples: [], | ||
| }; | ||
|
|
||
| export function parseBarrelJSDoc(content: string): BarrelJSDoc { | ||
| const trimmed = content.trimStart(); | ||
| if (!trimmed.startsWith("/**")) { | ||
| return EMPTY_BARREL_JSDOC; | ||
| } | ||
|
|
||
| const endIdx = trimmed.indexOf("*/"); | ||
| if (endIdx === -1) { | ||
| return EMPTY_BARREL_JSDOC; | ||
| } | ||
|
|
||
| const block = trimmed.slice(3, endIdx); | ||
| const lines = block.split("\n").map((line) => line.replace(/^\s*\*\s?/, "")); | ||
|
|
||
| let moduleName = ""; | ||
| const descLines: string[] = []; | ||
| const remarkLines: string[] = []; | ||
| const examples: Array<{ title: string; code: string }> = []; | ||
| let inExample = false; | ||
| let inRemarks = false; | ||
| let exampleTitle = ""; | ||
| let exampleLines: string[] = []; | ||
| let codeFence: { marker: "`" | "~"; length: number } | null = null; | ||
|
|
||
| const finishExample = (): void => { | ||
| if (exampleLines.length > 0) { | ||
| examples.push({ title: exampleTitle, code: exampleLines.join("\n") }); | ||
| } | ||
| exampleTitle = ""; | ||
| exampleLines = []; | ||
| codeFence = null; | ||
| }; | ||
|
|
||
| const updateCodeFence = (line: string): void => { | ||
| const fenceMatch = line.match(/^( {0,3})(`{3,}|~{3,})(.*)$/); | ||
| if (!fenceMatch) return; | ||
| const fence = fenceMatch[2]; | ||
| const marker = fence[0] as "`" | "~"; | ||
| if (codeFence === null) { | ||
| codeFence = { marker, length: fence.length }; | ||
| } else if ( | ||
| marker === codeFence.marker && | ||
| fence.length >= codeFence.length && | ||
| fenceMatch[3].trim() === "" | ||
| ) { | ||
| codeFence = null; | ||
| } | ||
| }; | ||
|
|
||
| for (const line of lines) { | ||
| if (inExample || inRemarks) updateCodeFence(line); | ||
|
|
||
| if (codeFence === null && line.startsWith("@module")) { | ||
| moduleName = line.replace("@module", "").trim(); | ||
| inRemarks = false; | ||
| continue; | ||
| } | ||
|
|
||
| if (codeFence === null && line.startsWith("@remarks")) { | ||
| finishExample(); | ||
| inExample = false; | ||
| inRemarks = true; | ||
| const inlineRemarks = line.replace("@remarks", "").trim(); | ||
| if (inlineRemarks) remarkLines.push(inlineRemarks); | ||
| continue; | ||
| } | ||
|
|
||
| if (codeFence === null && line.startsWith("@example")) { | ||
| finishExample(); | ||
| exampleTitle = line.replace("@example", "").trim(); | ||
| exampleLines = []; | ||
| inExample = true; | ||
| inRemarks = false; | ||
| codeFence = null; | ||
| continue; | ||
| } | ||
|
|
||
| if (codeFence === null && line.startsWith("@")) { | ||
| finishExample(); | ||
| inExample = false; | ||
| inRemarks = false; | ||
| continue; | ||
| } | ||
|
|
||
| if (inExample) { | ||
| exampleLines.push(line); | ||
| } else if (inRemarks) { | ||
| remarkLines.push(line); | ||
|
kojiwakayama marked this conversation as resolved.
|
||
| } else if (!moduleName || descLines.length > 0 || line.trim()) { | ||
| if (!line.startsWith("@")) { | ||
| descLines.push(line); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| finishExample(); | ||
|
|
||
| const description = normalizePublicDocText( | ||
| descLines.join(" ").replace(/\s+/g, " ").trim(), | ||
| ); | ||
| const remarks = remarkLines.join("\n").trim(); | ||
| return { description, moduleName, remarks, examples }; | ||
| } | ||
|
|
||
| export function normalizePublicDocText(text: string): string { | ||
| const withoutInlineJsDocLinks = text.replace( | ||
| /\{@(?:link|linkcode|linkplain)\s+([^}]+)\}/g, | ||
| (_match, rawTarget: string) => { | ||
| const target = rawTarget.trim(); | ||
| const pipeIndex = target.indexOf("|"); | ||
| const display = pipeIndex >= 0 | ||
| ? target.slice(pipeIndex + 1).trim() | ||
| : target.match(/^\S+\s+(.+)$/)?.[1]?.trim() || target; | ||
| const longestBacktickRun = Math.max( | ||
| 0, | ||
| ...(display.match(/`+/g) ?? []).map((run) => run.length), | ||
| ); | ||
| const delimiter = "`".repeat(longestBacktickRun + 1); | ||
| const needsPadding = display.startsWith("`") || display.endsWith("`"); | ||
| return `${delimiter}${ | ||
| needsPadding ? ` ${display} ` : display | ||
| }${delimiter}`; | ||
| }, | ||
| ); | ||
|
|
||
| return withoutInlineJsDocLinks | ||
| .replace(/(`+)[\s\S]*?\1|[<>]/g, (token) => { | ||
| if (token.startsWith("`")) return token; | ||
| return token === "<" ? "<" : ">"; | ||
| }) | ||
| .replace(/[\u2013\u2014]/g, "-") | ||
| .replace(/\s+/g, " ") | ||
| .trim(); | ||
| } | ||
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.