Skip to content

Commit 196dcb4

Browse files
authored
chore(repo): Add @unionReturnHeadings Typedoc blockTag (#5596)
1 parent c8c50a9 commit 196dcb4

26 files changed

+202
-34
lines changed

.changeset/whole-wasps-know.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@clerk/backend': patch
3+
'@clerk/nextjs': patch
4+
'@clerk/shared': patch
5+
'@clerk/clerk-react': patch
6+
'@clerk/types': patch
7+
'@clerk/vue': patch
8+
---
9+
10+
Improve JSDoc comments

.typedoc/__tests__/__snapshots__/file-structure.test.ts.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,16 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
2727
"types/localization-resource.mdx",
2828
"types/multi-domain-and-or-proxy.mdx",
2929
"types/organization-custom-role-key.mdx",
30+
"types/organization-domain-resource.mdx",
3031
"types/organization-domain-verification-status.mdx",
3132
"types/organization-enrollment-mode.mdx",
33+
"types/organization-invitation-resource.mdx",
3234
"types/organization-invitation-status.mdx",
35+
"types/organization-membership-request-resource.mdx",
36+
"types/organization-membership-resource.mdx",
3337
"types/organization-permission-key.mdx",
38+
"types/organization-resource.mdx",
39+
"types/organization-suggestion-resource.mdx",
3440
"types/organization-suggestion-status.mdx",
3541
"types/organizations-jwt-claim.mdx",
3642
"types/override.mdx",
@@ -57,6 +63,7 @@ exports[`Typedoc output > should have a deliberate file structure 1`] = `
5763
"types/use-sign-in-return.mdx",
5864
"types/use-sign-up-return.mdx",
5965
"types/use-user-return.mdx",
66+
"types/user-organization-invitation-resource.mdx",
6067
"types/user-resource.mdx",
6168
"types/without.mdx",
6269
"shared/build-clerk-js-script-attributes.mdx",

.typedoc/custom-plugin.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const FILES_WITHOUT_HEADINGS = [
1414
'paginated-hook-config.mdx',
1515
'use-organization-list-return.mdx',
1616
'use-organization-list-params.mdx',
17+
'create-organization-params.mdx',
1718
];
1819

1920
/**
@@ -28,6 +29,13 @@ const LINK_REPLACEMENTS = [
2829
['sign-up-resource', '/docs/references/javascript/sign-up'],
2930
['user-resource', '/docs/references/javascript/user'],
3031
['session-status-claim', '/docs/references/javascript/types/session-status'],
32+
['user-organization-invitation-resource', '/docs/references/javascript/types/organization-invitation'],
33+
['organization-membership-resource', '/docs/references/javascript/types/organization-membership'],
34+
['organization-suggestion-resource', '/docs/references/javascript/types/organization-suggestion'],
35+
['organization-resource', '/docs/references/javascript/organization'],
36+
['organization-domain-resource', '/docs/references/javascript/types/organization-domain'],
37+
['organization-invitation-resource', '/docs/references/javascript/types/organization-invitation'],
38+
['organization-membership-request-resource', '/docs/references/javascript/types/organization-membership-request'],
3139
];
3240

3341
/**
@@ -69,8 +77,8 @@ function getUnlinkedTypesReplacements() {
6977
replace: '[Clerk](/docs/references/javascript/clerk)',
7078
},
7179
{
72-
pattern: /`OrganizationCustomRoleKey`/g,
73-
replace: '[OrganizationCustomRoleKey](/docs/references/javascript/types/organization-custom-role-key)',
80+
pattern: /\(CreateOrganizationParams\)/g,
81+
replace: '([CreateOrganizationParams](#create-organization-params))',
7482
},
7583
];
7684
}

.typedoc/custom-theme.mjs

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ class ClerkMarkdownTheme extends MarkdownTheme {
1818
}
1919
}
2020

21+
/**
22+
* This map stores the comment for the first item in a union type.
23+
* It'll be used to add that comment to the other items of the union type.
24+
* This way the comment only has to be added once.
25+
* @type {Map<string, import('typedoc').Comment>}
26+
*
27+
* The key is a concenation of the model's type name and the union type's declaration name.
28+
* The value is the comment
29+
*/
30+
const unionCommentMap = new Map();
31+
2132
/**
2233
* Our custom Clerk theme
2334
* @extends MarkdownThemeContext
@@ -88,6 +99,30 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext {
8899

89100
return output;
90101
},
102+
/**
103+
* This ensures that everything is wrapped in a single codeblock
104+
* @param {import('typedoc').DeclarationReflection} model
105+
* @param {{ forceCollapse?: boolean }} [options]
106+
*/
107+
declarationType: (model, options) => {
108+
const defaultOutput = superPartials.declarationType(model, options);
109+
110+
// Ensure that the output starts with `\{ `. Some strings will do, some will have e.g. `\{<code>` or `\{[]`
111+
const withCorrectWhitespaceAtStart = defaultOutput.startsWith('\\{ ')
112+
? defaultOutput
113+
: defaultOutput.startsWith('\\{')
114+
? defaultOutput.replace('\\{', '\\{ ')
115+
: defaultOutput;
116+
117+
const output = withCorrectWhitespaceAtStart
118+
// Remove any backticks
119+
.replace(/`/g, '')
120+
// Remove any `<code>` and `</code>` tags
121+
.replace(/<code>/g, '')
122+
.replace(/<\/code>/g, '');
123+
124+
return `<code>${output}</code>`;
125+
},
91126
/**
92127
* This modifies the output of union types by wrapping everything in a single `<code>foo | bar</code>` tag instead of doing `<code>foo</code>` | `<code>bar</code>`
93128
* @param {import('typedoc').UnionType} model
@@ -107,7 +142,7 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext {
107142
return `<code>${output}</code>`;
108143
},
109144
/**
110-
* This ensures that everything is wrapped in a single codeblock (not individual ones)
145+
* This ensures that everything is wrapped in a single codeblock
111146
* @param {import('typedoc').SignatureReflection[]} model
112147
* @param {{ forceParameterType?: boolean; typeSeparator?: string }} [options]
113148
*/
@@ -132,7 +167,7 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext {
132167
/**
133168
* Copied from original theme.
134169
* Changes:
135-
* - Remove summaries over tables (TODO: Use elementSummaries instead)
170+
* - Remove summaries over tables and instead use `@unionReturnHeadings` to add headings
136171
* - Only use one newline between items
137172
* https://github.com/typedoc2md/typedoc-plugin-markdown/blob/7032ebd3679aead224cf23bffd0f3fb98443d16e/packages/typedoc-plugin-markdown/src/theme/context/partials/member.typeDeclarationUnionContainer.ts
138173
* @param {import('typedoc').DeclarationReflection} model
@@ -143,10 +178,51 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext {
143178
* @type {string[]}
144179
*/
145180
const md = [];
181+
/**
182+
* @type {string[]}
183+
*/
184+
const headings = [];
185+
/**
186+
* Search for the `@unionReturnHeadings` tag in the comment of the model
187+
*/
188+
const unionReturnHeadings = model.comment?.getTag('@unionReturnHeadings');
189+
146190
if (model.type instanceof UnionType) {
147191
const elementSummaries = model.type?.elementSummaries;
148192
model.type.types.forEach((type, i) => {
149193
if (type instanceof ReflectionType) {
194+
if (unionReturnHeadings && unionReturnHeadings.content.length > 0) {
195+
const content = this.helpers.getCommentParts(unionReturnHeadings.content);
196+
const unionHeadings = JSON.parse(content);
197+
198+
/**
199+
* While iterating over the union types, the headings are pulled from `@unionReturnHeadings` and added to the array
200+
*/
201+
headings.push(unionHeadings[i]);
202+
203+
/**
204+
* The `model.type.types` is the array of the individual items of the union type.
205+
* We're documenting our code by only adding the comment to the first item of the union type.
206+
*
207+
* In this block, we're doing the following:
208+
* 1. Generate an ID for the item in the unionCommentMap
209+
* 2. Check if the union type has a comment (truthy for the first item)
210+
* 3. Add the comment to the map
211+
* 4. If the union doesn't have a comment for the given ID, add the comment from the map to the item
212+
*/
213+
if (type.declaration.children) {
214+
for (const decl of type.declaration.children) {
215+
const id = `${model.name}-${decl.name}`;
216+
217+
if (decl.comment && !unionCommentMap.has(id)) {
218+
unionCommentMap.set(id, decl.comment);
219+
} else if (!decl.comment && unionCommentMap.has(id)) {
220+
decl.comment = unionCommentMap.get(id);
221+
}
222+
}
223+
}
224+
}
225+
150226
md.push(this.partials.typeDeclarationContainer(model, type.declaration, options));
151227
} else {
152228
md.push(`${this.partials.someType(type)}`);
@@ -156,7 +232,33 @@ class ClerkMarkdownThemeContext extends MarkdownThemeContext {
156232
}
157233
});
158234
}
159-
return md.join('\n');
235+
236+
if (!unionReturnHeadings) {
237+
return md.join('\n');
238+
}
239+
240+
const items = headings.map(i => `'${i}'`).join(', ');
241+
const tabs = md.map(i => `<Tab>${i}</Tab>`).join('\n');
242+
243+
return `<Tabs items={[${items}]}>
244+
${tabs}
245+
</Tabs>`;
246+
},
247+
/**
248+
* This ensures that everything is wrapped in a single codeblock
249+
* @param {import('typedoc').ArrayType} model
250+
*/
251+
arrayType: model => {
252+
const defaultOutput = superPartials.arrayType(model);
253+
254+
const output = defaultOutput
255+
// Remove any backticks
256+
.replace(/`/g, '')
257+
// Remove any `<code>` and `</code>` tags
258+
.replace(/<code>/g, '')
259+
.replace(/<\/code>/g, '');
260+
261+
return `<code>${output}</code>`;
160262
},
161263
};
162264
}

packages/backend/src/tokens/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type AuthenticateRequestOptions = {
3535
*/
3636
afterSignUpUrl?: string;
3737
/**
38-
* Used to activate a specific [organization](https://clerk.com/docs/organizations/overview) or [personal account](https://clerk.com/docs/organizations/organization-workspaces#organization-workspaces-in-the-clerk-dashboard:~:text=Personal%20account) based on URL path parameters. If there's a mismatch between the active organization in the session (e.g., as reported by `auth()`) and the organization indicated by the URL, an attempt to activate the organization specified in the URL will be made.
38+
* Used to activate a specific [organization](https://clerk.com/docs/organizations/overview) or [personal account](https://clerk.com/docs/organizations/organization-workspaces) based on URL path parameters. If there's a mismatch between the active organization in the session (e.g., as reported by `auth()`) and the organization indicated by the URL, an attempt to activate the organization specified in the URL will be made.
3939
*
4040
* If the activation can't be performed, either because an organization doesn't exist or the user lacks access, the active organization in the session won't be changed. Ultimately, it's the responsibility of the page to verify that the resources are appropriate to render given the URL and handle mismatches appropriately (e.g., by returning a 404).
4141
*/

packages/backend/src/tokens/verify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { loadClerkJWKFromLocal, loadClerkJWKFromRemote } from './keys';
1010
export type VerifyTokenOptions = Omit<VerifyJwtOptions, 'key'> &
1111
Omit<LoadClerkJWKFromRemoteOptions, 'kid'> & {
1212
/**
13-
* Used to verify the session token in a networkless manner. Supply the PEM public key from the **[**API keys**](https://dashboard.clerk.com/last-active?path=api-keys) page -> Show JWT public key -> PEM Public Key** section in the Clerk Dashboard. **It's recommended to use [the environment variable](https://clerk.com/docs/deployments/clerk-environment-variables) instead.** For more information, refer to [Manual JWT verification](https://clerk.com/docs/backend-requests/handling/manual-jwt).
13+
* Used to verify the session token in a networkless manner. Supply the PEM public key from the **[**API keys**](https://dashboard.clerk.com/last-active?path=api-keys) page -> Show JWT public key -> PEM Public Key** section in the Clerk Dashboard. **It's recommended to use [the environment variable](https://clerk.com/docs/deployments/clerk-environment-variables) instead.** For more information, refer to [Manual JWT verification](https://clerk.com/docs/backend-requests/manual-jwt).
1414
*/
1515
jwtKey?: string;
1616
};

packages/nextjs/src/app-router/server/currentUser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { auth } from './auth';
99
* Under the hood, this helper:
1010
* - calls `fetch()`, so it is automatically deduped per request.
1111
* - uses the [`GET /v1/users/{user_id}`](https://clerk.com/docs/reference/backend-api/tag/Users#operation/GetUser) endpoint.
12-
* - counts towards the [Backend API request rate limit](https://clerk.com/docs/backend-requests/resources/rate-limits#rate-limits).
12+
* - counts towards the [Backend API request rate limit](https://clerk.com/docs/backend-requests/resources/rate-limits).
1313
*
1414
* @example
1515
* ```tsx {{ filename: 'app/page.tsx' }}

packages/react/src/components/controlComponents.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export const RedirectToSignUp = withClerk(({ clerk, ...props }: WithClerkProp<Re
198198

199199
/**
200200
* @function
201-
* @deprecated Use [`redirectToUserProfile()`](https://clerk.com/docs/references/javascript/clerk/redirect-methods#redirect-to-user-profile) instead, will be removed in the next major version.
201+
* @deprecated Use [`redirectToUserProfile()`](https://clerk.com/docs/references/javascript/clerk#redirect-to-user-profile) instead, will be removed in the next major version.
202202
*/
203203
export const RedirectToUserProfile = withClerk(({ clerk }) => {
204204
React.useEffect(() => {
@@ -211,7 +211,7 @@ export const RedirectToUserProfile = withClerk(({ clerk }) => {
211211

212212
/**
213213
* @function
214-
* @deprecated Use [`redirectToOrganizationProfile()`](https://clerk.com/docs/references/javascript/clerk/redirect-methods#redirect-to-organization-profile) instead, will be removed in the next major version.
214+
* @deprecated Use [`redirectToOrganizationProfile()`](https://clerk.com/docs/references/javascript/clerk#redirect-to-organization-profile) instead, will be removed in the next major version.
215215
*/
216216
export const RedirectToOrganizationProfile = withClerk(({ clerk }) => {
217217
React.useEffect(() => {
@@ -224,7 +224,7 @@ export const RedirectToOrganizationProfile = withClerk(({ clerk }) => {
224224

225225
/**
226226
* @function
227-
* @deprecated Use [`redirectToCreateOrganization()`](https://clerk.com/docs/references/javascript/clerk/redirect-methods#redirect-to-create-organization) instead, will be removed in the next major version.
227+
* @deprecated Use [`redirectToCreateOrganization()`](https://clerk.com/docs/references/javascript/clerk#redirect-to-create-organization) instead, will be removed in the next major version.
228228
*/
229229
export const RedirectToCreateOrganization = withClerk(({ clerk }) => {
230230
React.useEffect(() => {

packages/react/src/hooks/useAuth.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ type UseAuthOptions = Nullish<InitialAuthState | PendingSessionOptions>;
3131
* By default, Next.js opts all routes into static rendering. If you need to opt a route or routes into dynamic rendering because you need to access the authentication data at request time, you can create a boundary by passing the `dynamic` prop to `<ClerkProvider>`. See the [guide on rendering modes](https://clerk.com/docs/references/nextjs/rendering-modes) for more information, including code examples.
3232
* </If>
3333
*
34+
* @unionReturnHeadings
35+
* ["Initialization", "Signed out", "Signed in (no active organization)", "Signed in (with active organization)"]
36+
*
3437
* @param [initialAuthStateOrOptions] - An object containing the initial authentication state. If not provided, the hook will attempt to derive the state from the context.
3538
*
3639
* @function

packages/react/src/hooks/useSignIn.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import { useIsomorphicClerkContext } from '../contexts/IsomorphicClerkContext';
66
import { useAssertWrappedByClerkProvider } from './useAssertWrappedByClerkProvider';
77

88
/**
9-
* The `useSignIn()` hook provides access to the [`SignIn`](https://clerk.com/docs/references/javascript/sign-in/sign-in) object, which allows you to check the current state of a sign-in attempt and manage the sign-in flow. You can use this to create a [custom sign-in flow](https://clerk.com/docs/custom-flows/overview#sign-in-flow).
9+
* The `useSignIn()` hook provides access to the [`SignIn`](https://clerk.com/docs/references/javascript/sign-in) object, which allows you to check the current state of a sign-in attempt and manage the sign-in flow. You can use this to create a [custom sign-in flow](https://clerk.com/docs/custom-flows/overview#sign-in-flow).
10+
*
11+
* @unionReturnHeadings
12+
* ["Initialization", "Loaded"]
1013
*
1114
* @example
1215
* ### Check the current state of a sign-in
1316
*
14-
* The following example uses the `useSignIn()` hook to access the [`SignIn`](https://clerk.com/docs/references/javascript/sign-in/sign-in) object, which contains the current sign-in attempt status and methods to create a new sign-in attempt. The `isLoaded` property is used to handle the loading state.
17+
* The following example uses the `useSignIn()` hook to access the [`SignIn`](https://clerk.com/docs/references/javascript/sign-in) object, which contains the current sign-in attempt status and methods to create a new sign-in attempt. The `isLoaded` property is used to handle the loading state.
1518
*
1619
* <Tabs items='React,Next.js'>
1720
* <Tab>

0 commit comments

Comments
 (0)