mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
refactor: minify api.json by shortening keys (#9971)
* refactor: minify api.json by shortening keys * fix: links to other packages * refactor: get doclink from canonicalReference, not model * fix: types * fix: again * fix: @link tags with alt texts
This commit is contained in:
@@ -9,8 +9,6 @@ export function HierarchyText({
|
||||
readonly item: ApiClass | ApiInterface;
|
||||
readonly type: 'Extends' | 'Implements';
|
||||
}) {
|
||||
const model = item.getAssociatedModel()!;
|
||||
|
||||
if (
|
||||
(item.kind === ApiItemKind.Class &&
|
||||
(item as ApiClass).extendsType === undefined &&
|
||||
@@ -50,7 +48,7 @@ export function HierarchyText({
|
||||
<div className="flex flex-row place-items-center gap-4" key={`${type}-${idx}`}>
|
||||
<h3 className="text-xl font-bold">{type}</h3>
|
||||
<span className="break-all font-mono space-y-2">
|
||||
<ExcerptText excerpt={excerpt} model={model} />
|
||||
<ExcerptText excerpt={excerpt} />
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ApiItemKind } from '@discordjs/api-extractor-model';
|
||||
import { ApiItemKind, Meaning } from '@discordjs/api-extractor-model';
|
||||
import type {
|
||||
ApiItem,
|
||||
ApiItemContainerMixin,
|
||||
@@ -10,11 +10,25 @@ import type {
|
||||
ApiParameterListMixin,
|
||||
ApiEvent,
|
||||
} from '@discordjs/api-extractor-model';
|
||||
import type { DeclarationReference } from '@microsoft/tsdoc/lib-commonjs/beta/DeclarationReference';
|
||||
import { METHOD_SEPARATOR, OVERLOAD_SEPARATOR } from '~/util/constants';
|
||||
import { resolveMembers } from '~/util/members';
|
||||
import { resolveParameters } from '~/util/model';
|
||||
import type { TableOfContentsSerialized } from '../TableOfContentItems';
|
||||
|
||||
export type ApiItemLike = {
|
||||
[K in keyof ApiItem]?: K extends 'displayName' | 'kind'
|
||||
? ApiItem[K]
|
||||
: K extends 'parent'
|
||||
? ApiItemLike | undefined
|
||||
: ApiItem[K] | undefined;
|
||||
};
|
||||
|
||||
interface ResolvedCanonicalReference {
|
||||
item: ApiItemLike;
|
||||
package: string;
|
||||
}
|
||||
|
||||
export function hasProperties(item: ApiItemContainerMixin) {
|
||||
return resolveMembers(item, memberPredicate).some(
|
||||
({ item: member }) => member.kind === ApiItemKind.Property || member.kind === ApiItemKind.PropertySignature,
|
||||
@@ -31,12 +45,65 @@ export function hasEvents(item: ApiItemContainerMixin) {
|
||||
return resolveMembers(item, memberPredicate).some(({ item: member }) => member.kind === ApiItemKind.Event);
|
||||
}
|
||||
|
||||
export function resolveItemURI(item: ApiItem): string {
|
||||
export function resolveItemURI(item: ApiItemLike): string {
|
||||
return !item.parent || item.parent.kind === ApiItemKind.EntryPoint
|
||||
? `${item.displayName}${OVERLOAD_SEPARATOR}${item.kind}`
|
||||
: `${item.parent.displayName}${OVERLOAD_SEPARATOR}${item.parent.kind}${METHOD_SEPARATOR}${item.displayName}`;
|
||||
}
|
||||
|
||||
export function resolveCanonicalReference(canonicalReference: DeclarationReference): ResolvedCanonicalReference | null {
|
||||
if (
|
||||
canonicalReference.source &&
|
||||
'packageName' in canonicalReference.source &&
|
||||
canonicalReference.symbol?.componentPath &&
|
||||
canonicalReference.symbol.meaning
|
||||
)
|
||||
return {
|
||||
package: canonicalReference.source.unscopedPackageName,
|
||||
item: {
|
||||
kind: mapMeaningToKind(canonicalReference.symbol.meaning as unknown as Meaning),
|
||||
displayName: canonicalReference.symbol.componentPath.component.toString(),
|
||||
containerKey: `|${
|
||||
canonicalReference.symbol.meaning
|
||||
}|${canonicalReference.symbol.componentPath.component.toString()}`,
|
||||
},
|
||||
};
|
||||
return null;
|
||||
}
|
||||
|
||||
function mapMeaningToKind(meaning: Meaning): ApiItemKind {
|
||||
switch (meaning) {
|
||||
case Meaning.CallSignature:
|
||||
return ApiItemKind.CallSignature;
|
||||
case Meaning.Class:
|
||||
return ApiItemKind.Class;
|
||||
case Meaning.ComplexType:
|
||||
throw new Error('Not a valid canonicalReference: Meaning.ComplexType');
|
||||
case Meaning.ConstructSignature:
|
||||
return ApiItemKind.ConstructSignature;
|
||||
case Meaning.Constructor:
|
||||
return ApiItemKind.Constructor;
|
||||
case Meaning.Enum:
|
||||
return ApiItemKind.Enum;
|
||||
case Meaning.Event:
|
||||
return ApiItemKind.Event;
|
||||
case Meaning.Function:
|
||||
return ApiItemKind.Function;
|
||||
case Meaning.IndexSignature:
|
||||
return ApiItemKind.IndexSignature;
|
||||
case Meaning.Interface:
|
||||
return ApiItemKind.Interface;
|
||||
case Meaning.Member:
|
||||
return ApiItemKind.Property;
|
||||
case Meaning.Namespace:
|
||||
return ApiItemKind.Namespace;
|
||||
case Meaning.TypeAlias:
|
||||
return ApiItemKind.TypeAlias;
|
||||
case Meaning.Variable:
|
||||
return ApiItemKind.Variable;
|
||||
}
|
||||
}
|
||||
|
||||
export function memberPredicate(
|
||||
item: ApiItem,
|
||||
): item is ApiEvent | ApiMethod | ApiMethodSignature | ApiProperty | ApiPropertySignature {
|
||||
|
||||
Reference in New Issue
Block a user