-
Notifications
You must be signed in to change notification settings - Fork 473
fix(repo): flatten Pick parameters in TypeDoc output #9701
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
11 commits
Select commit
Hold shift + click to select a range
0887de9
fix(repo): flatten Pick parameters in TypeDoc output
SarahSoutoul ceb7a34
fix(repo): unlink flattened Pick source types
SarahSoutoul 178f59c
Merge branch 'main' into ss/DOCS-11879
SarahSoutoul 0bbd87e
fix(repo): guard Pick source reflection kinds
SarahSoutoul c0af671
test(repo): cover Pick parameter flattening resolvers
manovotny c6fd683
Merge remote-tracking branch 'origin/main' into ss/DOCS-11879
SarahSoutoul 1492197
Merge branch 'main' into ss/DOCS-11879
SarahSoutoul 5568fb7
fix(localizations): format Hebrew OAuth consent messages
SarahSoutoul fe3a2f3
fix(localizations): regenerate Hebrew localization
SarahSoutoul e07caea
fix(repo): avoid flattening generic Pick sources
SarahSoutoul 1f322e1
Merge branch 'main' into ss/DOCS-11879
SarahSoutoul 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- |
21 changes: 21 additions & 0 deletions
21
.typedoc/__tests__/__snapshots__/organization-resource-methods-create-domain.mdx
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,21 @@ | ||
| ### `createDomain()` | ||
|
|
||
| Creates a new domain. | ||
|
|
||
| Returns an [`OrganizationDomainResource`](/docs/reference/types/organization-domain-resource) object. | ||
|
|
||
| > [!WARNING] | ||
| > You must have [**Verified domains**](/docs/guides/organizations/add-members/verified-domains) enabled in your app's settings in the Clerk Dashboard. | ||
|
|
||
| ```typescript | ||
| function createDomain(domainName: string, params?: Pick<CreateOrganizationDomainParams, "enrollmentMode">): Promise<OrganizationDomainResource> | ||
| ``` | ||
|
|
||
| #### Parameters | ||
|
|
||
|
|
||
| | Parameter | Type | Description | | ||
| | ------ | ------ | ------ | | ||
| | `domainName` | `string` | The name of the domain to create. | | ||
| | `params?` | `Pick`\<`CreateOrganizationDomainParams`, `"enrollmentMode"`\> | Optional parameters, including the `enrollmentMode` to assign to the new domain. | | ||
| | `params?.enrollmentMode?` | <code>"manual_invitation" \| "automatic_invitation" \| "automatic_suggestion" \| "enterprise_sso"</code> | The enrollment mode that determines how matching users are added to the Organization. Defaults to `manual_invitation`. | |
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,121 @@ | ||
| import { ReflectionKind, type Type } from 'typedoc'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { getParameterObjectShapeDeclaration, getPickPropertyNames } from '../custom-theme.mjs'; | ||
|
|
||
| const literal = (value: unknown) => ({ type: 'literal', value }) as unknown as Type; | ||
| const union = (...types: unknown[]) => ({ type: 'union', types }) as unknown as Type; | ||
|
|
||
| describe('getPickPropertyNames', () => { | ||
| it('returns the single key for a string literal', () => { | ||
| expect(getPickPropertyNames(literal('enrollmentMode'))).toEqual(['enrollmentMode']); | ||
| }); | ||
|
|
||
| it('flattens a union of string literals', () => { | ||
| expect(getPickPropertyNames(union(literal('a'), literal('b')))).toEqual(['a', 'b']); | ||
| }); | ||
|
|
||
| it('recurses into nested unions', () => { | ||
| expect(getPickPropertyNames(union(literal('a'), union(literal('b'), literal('c'))))).toEqual(['a', 'b', 'c']); | ||
| }); | ||
|
|
||
| it('bails on a non-string literal key', () => { | ||
| expect(getPickPropertyNames(literal(0))).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('bails when any union arm is not a string literal', () => { | ||
| expect(getPickPropertyNames(union(literal('a'), { type: 'reference', name: 'Foo' }))).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getParameterObjectShapeDeclaration', () => { | ||
| const sourceInterface = (...names: string[]) => ({ | ||
| reflection: { | ||
| kind: ReflectionKind.Interface, | ||
| name: 'Src', | ||
| children: names.map(name => ({ name })), | ||
| }, | ||
| }); | ||
|
|
||
| const pick = (source: unknown, keys: unknown) => | ||
| ({ | ||
| type: 'reference', | ||
| name: 'Pick', | ||
| package: 'typescript', | ||
| typeArguments: [{ type: 'reference', ...(source as object) }, keys], | ||
| }) as unknown as Type; | ||
|
|
||
| it('does not resolve Pick sources whose declaration kind is unsupported', () => { | ||
| const sourceType = { | ||
| type: 'reference', | ||
| name: 'ExampleClass', | ||
| reflection: { | ||
| kind: ReflectionKind.Class, | ||
| children: [ | ||
| { | ||
| name: 'someMethodName', | ||
| kind: ReflectionKind.Method, | ||
| signatures: [{}], | ||
| }, | ||
| ], | ||
| }, | ||
| } as unknown as Type; | ||
| const pickType = { | ||
| type: 'reference', | ||
| name: 'Pick', | ||
| package: 'typescript', | ||
| typeArguments: [sourceType, { type: 'literal', value: 'someMethodName' }], | ||
| } as unknown as Type; | ||
|
|
||
| expect(getParameterObjectShapeDeclaration(pickType)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('selects only the picked properties from a multi-key Pick', () => { | ||
| const decl = getParameterObjectShapeDeclaration( | ||
| pick(sourceInterface('name', 'enrollmentMode', 'other'), union(literal('name'), literal('enrollmentMode'))), | ||
| ); | ||
| expect(decl?.children?.map(child => child.name)).toEqual(['name', 'enrollmentMode']); | ||
| }); | ||
|
|
||
| it('does not mutate the source declaration', () => { | ||
| const source = sourceInterface('name', 'enrollmentMode'); | ||
| getParameterObjectShapeDeclaration(pick(source, literal('enrollmentMode'))); | ||
| expect(source.reflection.children.map(child => child.name)).toEqual(['name', 'enrollmentMode']); | ||
| }); | ||
|
|
||
| it('fails closed when a picked key is not a property of the source', () => { | ||
| expect(getParameterObjectShapeDeclaration(pick(sourceInterface('name'), literal('missing')))).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('fails closed for non-literal keys', () => { | ||
| expect( | ||
| getParameterObjectShapeDeclaration( | ||
| pick(sourceInterface('name', 'enrollmentMode'), { type: 'reference', name: 'keyof Src' }), | ||
| ), | ||
| ).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('fails closed for generic source instantiations', () => { | ||
| const source = { | ||
| ...sourceInterface('value'), | ||
| name: 'Box', | ||
| typeArguments: [{ type: 'intrinsic', name: 'string' }], | ||
| }; | ||
|
|
||
| expect(getParameterObjectShapeDeclaration(pick(source, literal('value')))).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('does not treat Omit as a flattenable builtin', () => { | ||
| const omit = { | ||
| type: 'reference', | ||
| name: 'Omit', | ||
| package: 'typescript', | ||
| reflection: undefined, | ||
| typeArguments: [ | ||
| { type: 'reference', ...sourceInterface('name', 'enrollmentMode') }, | ||
| { type: 'literal', value: 'name' }, | ||
| ], | ||
| } as unknown as Type; | ||
| expect(getParameterObjectShapeDeclaration(omit)).toBeUndefined(); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a generic source like
Pick<Box<string>, 'value'>, this reusesBox<T>'s child reflections, so the flattened row documents the property's type asTrather thanstring— TypeDoc keeps the instantiation in the use-sitetypeArgumentsand doesn't rewrite the referenced declaration's children.Nothing in the entry points hits this today (
CreateOrganizationDomainParamsisn't generic), and it's a pre-existing trait of the reference-flatten path, not something this PR introduces. The one wrinkle: this branch fails open (a wrong type) rather than closed.Worth bailing to the opaque output when the source is a generic instantiation — returning
undefinedhere whensourceType.typeArguments?.length— so it degrades instead of documentingT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch -
Pick<Box<string>, 'value'>could otherwise flatten the unspecialized declaration and surface T instead of string. I added a fail-closed guard for generic source instantiations and regression coverage in e07caea.