Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 470
docs(repo): Generate all params and return types (hooks work)#6901
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
780cae5128df3ca5849058d2e9e270c5908d49447e7b9b11bb6535393f1f9203cc87f964da46016f9663febc294c32a435263dba2316c86140dbc8bbc7873c2ebb4f2906c42c113bb22d58bcbd3bde171ecd1435326252711d35066bdc23db6b7f80f0ebf2e1cfd43a038c99d45f698d9f9ce0e4cd4165b1888f9912fa9c5c297796b4f9309df0c279430645c0b8e1932a4c45db76fb79ff65e9a8c4ada9e4f1209b369543029aa3623e24bb6e0a0e7c7ddb61996e7e7b37cee6afd5597389079574c1804e0957259328839e58a57f5a92f98ab9fe7a2e578aad4cef7File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@clerk/shared': minor | ||
| '@clerk/types': minor | ||
| --- | ||
| Ensure all hooks use typedoc for clerk docs | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| // @ts-check | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
| /** | ||
| * Extracts the "## Returns" section from a markdown file and writes it to a separate file. | ||
| * @param {string} filePath - The path to the markdown file | ||
| * @returns {boolean} True if a file was created | ||
| */ | ||
| function extractReturnsSection(filePath) { | ||
| const content = fs.readFileSync(filePath, 'utf-8'); | ||
| // Find the "## Returns" section | ||
| const returnsStart = content.indexOf('## Returns'); | ||
| if (returnsStart === -1) { | ||
| return false; // No Returns section found | ||
| } | ||
| // Find the next heading after "## Returns" (or end of file) | ||
| const afterReturns = content.slice(returnsStart + 10); // Skip past "## Returns" | ||
| const nextHeadingMatch = afterReturns.match(/\n## /); | ||
| const returnsEnd = | ||
| nextHeadingMatch && typeof nextHeadingMatch.index === 'number' | ||
| ? returnsStart + 10 + nextHeadingMatch.index | ||
| : content.length; | ||
| // Extract the Returns section and trim trailing whitespace | ||
| const returnsContent = content.slice(returnsStart, returnsEnd).trimEnd(); | ||
| // Generate the new filename: use-auth.mdx -> use-auth-return.mdx | ||
| const fileName = path.basename(filePath, '.mdx'); | ||
| const dirName = path.dirname(filePath); | ||
| const newFilePath = path.join(dirName, `${fileName}-return.mdx`); | ||
| // Write the extracted Returns section to the new file | ||
| fs.writeFileSync(newFilePath, returnsContent, 'utf-8'); | ||
| console.log(`[extract-returns] Created ${path.relative(process.cwd(), newFilePath)}`); | ||
| return true; | ||
| } | ||
| /** | ||
| * Replaces generic type names in the parameters table with expanded types. | ||
| * @param {string} content | ||
| * @returns {string} | ||
| */ | ||
| function replaceGenericTypesInParamsTable(content) { | ||
| // Replace Fetcher in the parameters table | ||
| content = content.replace( | ||
| /(\|\s*`fetcher`\s*\|\s*)`Fetcher`(\s*\|)/g, | ||
| '$1`Fetcher extends (...args: any[]) => Promise<any>`$2', | ||
| ); | ||
| return content; | ||
| } | ||
| /** | ||
| * Extracts the "## Parameters" section from a markdown file and writes it to a separate file. | ||
| * @param {string} filePath - The path to the markdown file | ||
| * @returns {boolean} True if a file was created | ||
| */ | ||
| function extractParametersSection(filePath) { | ||
| const content = fs.readFileSync(filePath, 'utf-8'); | ||
| const fileName = path.basename(filePath, '.mdx'); | ||
| const dirName = path.dirname(filePath); | ||
Comment on lines
+62
to
+70
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Params written to wrong directory; props deletion path wrong (critical). extractParametersSection writes -params.mdx at the package root and deletes -props.mdx there, not next to the source file. This will misplace files for nested MDX and fail to delete the actual props file. Align with extractReturnsSection by using the file’s own directory and drop the extra dirName param. Apply these diffs: - * @param {string} dirName - The directory containing the files
* @returns {boolean} True if a file was created
*/
-function extractParametersSection(filePath, dirName) {+function extractParametersSection(filePath) {- // Delete any existing -props file (TypeDoc-generated)- const propsFilePath = path.join(dirName, propsFileName);+ // Delete any existing -props file (TypeDoc-generated)+ const dirForFile = path.dirname(filePath);+ const propsFilePath = path.join(dirForFile, propsFileName);- // Write to new file- const newFilePath = path.join(dirName, targetFileName);+ // Write to new file (next to source)+ const newFilePath = path.join(dirForFile, targetFileName);
fs.writeFileSync(newFilePath, paramsContent, 'utf-8');- // Extract Parameters sections- if (extractParametersSection(filePath, dir)) {+ // Extract Parameters sections+ if (extractParametersSection(filePath)) {
paramsCount++;
}Also applies to: 62-67, 87-90, 154-156 🤖 Prompt for AI Agents | ||
| // Always use -params suffix | ||
| const suffix = '-params'; | ||
| const targetFileName = `${fileName}${suffix}.mdx`; | ||
| const propsFileName = `${fileName}-props.mdx`; | ||
| // Delete any existing -props file (TypeDoc-generated) | ||
| const propsFilePath = path.join(dirName, propsFileName); | ||
| if (fs.existsSync(propsFilePath)) { | ||
| fs.unlinkSync(propsFilePath); | ||
| console.log(`[extract-returns] Deleted ${path.relative(process.cwd(), propsFilePath)}`); | ||
| } | ||
| // Find the "## Parameters" section | ||
| const paramsStart = content.indexOf('## Parameters'); | ||
| if (paramsStart === -1) { | ||
| return false; // No Parameters section found | ||
| } | ||
| // Find the next heading after "## Parameters" (or end of file) | ||
| const afterParams = content.slice(paramsStart + 13); // Skip past "## Parameters" | ||
| const nextHeadingMatch = afterParams.match(/\n## /); | ||
| const paramsEnd = | ||
| nextHeadingMatch && typeof nextHeadingMatch.index === 'number' | ||
| ? paramsStart + 13 + nextHeadingMatch.index | ||
| : content.length; | ||
| // Extract the Parameters section and trim trailing whitespace | ||
| const paramsContent = content.slice(paramsStart, paramsEnd).trimEnd(); | ||
| const processedParams = replaceGenericTypesInParamsTable(paramsContent); | ||
| // Write to new file | ||
| const newFilePath = path.join(dirName, targetFileName); | ||
| fs.writeFileSync(newFilePath, processedParams, 'utf-8'); | ||
| console.log(`[extract-returns] Created ${path.relative(process.cwd(), newFilePath)}`); | ||
| return true; | ||
| } | ||
| /** | ||
| * Recursively reads all .mdx files in a directory, excluding generated files | ||
| * @param {string} dir - The directory to read | ||
| * @returns {string[]} Array of file paths | ||
| */ | ||
| function getAllMdxFiles(dir) { | ||
| /** @type {string[]} */ | ||
| const files = []; | ||
| if (!fs.existsSync(dir)) { | ||
| return files; | ||
| } | ||
| const entries = fs.readdirSync(dir, { withFileTypes: true }); | ||
| for (const entry of entries) { | ||
| const fullPath = path.join(dir, entry.name); | ||
| if (entry.isDirectory()) { | ||
| files.push(...getAllMdxFiles(fullPath)); | ||
| } else if (entry.isFile() && entry.name.endsWith('.mdx')) { | ||
| // Exclude generated files | ||
| const isGenerated = | ||
| entry.name.endsWith('-return.mdx') || entry.name.endsWith('-params.mdx') || entry.name.endsWith('-props.mdx'); | ||
| if (!isGenerated) { | ||
| files.push(fullPath); | ||
| } | ||
| } | ||
| } | ||
| return files; | ||
| } | ||
| /** | ||
| * Main function to process all clerk-react files | ||
| */ | ||
| function main() { | ||
| const packages = ['clerk-react']; | ||
| const dirs = packages.map(folder => path.join(__dirname, 'temp-docs', folder)); | ||
| for (const dir of dirs) { | ||
| if (!fs.existsSync(dir)) { | ||
| console.log(`[extract-returns] ${dir} directory not found, skipping extraction`); | ||
| continue; | ||
| } | ||
| const mdxFiles = getAllMdxFiles(dir); | ||
| console.log(`[extract-returns] Processing ${mdxFiles.length} files in ${dir}/`); | ||
| let returnsCount = 0; | ||
| let paramsCount = 0; | ||
| for (const filePath of mdxFiles) { | ||
| // Extract Returns sections | ||
| if (extractReturnsSection(filePath)) { | ||
| returnsCount++; | ||
| } | ||
| // Extract Parameters sections | ||
| if (extractParametersSection(filePath)) { | ||
| paramsCount++; | ||
| } | ||
| } | ||
| console.log(`[extract-returns] Extracted ${returnsCount} Returns sections`); | ||
| console.log(`[extract-returns] Extracted ${paramsCount} Parameters sections`); | ||
| } | ||
| } | ||
| main(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -11,6 +11,9 @@ interface ClerkAPIResponseOptions extends Omit<ClerkErrorParams, 'message' | 'co | ||
| retryAfter?: number; | ||
| } | ||
| /** | ||
| * Class representing a Clerk API Response Error. | ||
| */ | ||
Comment on lines
+14
to
+16
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major 🧩 Analysis chainJSDoc mismatch: refers to “Interface” but documents a class; enrich for Typedoc Replace the summary and add basic tags to align with the PR goal (Typedoc metadata). Apply this diff: -/**- * Interface representing a Clerk API Response Error.- */+/**+ * Class representing a Clerk API response error thrown when the Clerk API returns an error payload.+ * @public+ * @remarks Use `status`, `errors`, `clerkTraceId`, and `retryAfter` to inspect details.+ * @see isClerkApiResponseError+ */Additionally (outside this range), consider:
Example snippet: exportclassClerkAPIResponseErrorextendsClerkErrorimplementsClerkAPIResponseErrorInterface{/** HTTP status code returned by the API. */publicstatus: number;/** Unique trace identifier for support/debugging. */publicclerkTraceId?: string;/** Retry-After value (in seconds) when rate limited or similar. */publicretryAfter?: number;/** Parsed list of API errors. */publicerrors: ClerkAPIError[];/** Returns a stringified representation of this error. */publictoString(): string{/* unchanged body */}// Keeps message unformatted for backward compatibilityprotectedstaticoverrideformatMessage(name: string,msg: string,_: string,__: string|undefined): string{returnmsg;}}Please re-run your Typedoc flow (pnpm run typedoc:generate) to confirm the class and its members render with the updated descriptions, and that constructor params/fields appear as expected. As per coding guidelines. 🏁 Script executed: #!/bin/bash
file=$(fd clerkApiResponseError.ts)echo"Found file: $file"
sed -n '1,30p'"$file"Length of output: 1203 🏁 Script executed: #!/bin/bash
file="packages/shared/src/errors/clerkApiResponseError.ts"
sed -n '30,100p'"$file"Length of output: 1081 Fix JSDoc header and document public API Replace at packages/shared/src/errors/clerkApiResponseError.ts (lines 15–17): -/**- * Interface representing a Clerk API Response Error.- */+/**+ * Class representing a Clerk API response error thrown when the Clerk API returns an error payload.+ * @public+ * @remarks Use `status`, `errors`, `clerkTraceId`, and `retryAfter` to inspect details.+ * @see isClerkApiResponseError+ */
🤖 Prompt for AI Agents | ||
| export class ClerkAPIResponseError extends ClerkError implements ClerkAPIResponseErrorInterface { | ||
| static kind = 'ClerkAPIResponseError'; | ||
| status: number; | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.