Files
discord.js/apps/website/src/util/fetchMember.ts
Qjuh 5c0fad3b2d build: package api-extractor and -model (#9920)
* fix(ExceptText): don't display import("d..-types/v10"). in return type

* Squashed 'packages/api-extractor-model/' content from commit 39ecb196c

git-subtree-dir: packages/api-extractor-model
git-subtree-split: 39ecb196ca210bdf84ba6c9cadb1bb93571849d7

* Squashed 'packages/api-extractor/' content from commit 341ad6c51

git-subtree-dir: packages/api-extractor
git-subtree-split: 341ad6c51b01656d4f73b74ad4bdb3095f9262c4

* feat(api-extractor): add api-extractor and -model

* fix: package.json docs script

* fix(SourcLink): use <> instead of function syntax

* fix: make packages private

* fix: rest params showing in docs, added labels

* fix: missed two files

* fix: cpy-cli & pnpm-lock

* fix: increase icon size

* fix: icon size again
2023-11-07 21:53:36 +01:00

42 lines
1.5 KiB
TypeScript

import { ApiModel, ApiFunction } from '@discordjs/api-extractor-model';
import { notFound } from 'next/navigation';
import { fetchModelJSON } from '~/app/docAPI';
import { addPackageToModel } from './addPackageToModel';
import { OVERLOAD_SEPARATOR, PACKAGES } from './constants';
import { findMember, findMemberByKey } from './model';
export interface ItemRouteParams {
item: string;
package: string;
version: string;
}
export async function fetchMember({ package: packageName, version: branchName = 'main', item }: ItemRouteParams) {
if (!PACKAGES.includes(packageName)) {
notFound();
}
const model = new ApiModel();
if (branchName === 'main') {
const modelJSONFiles = await Promise.all(PACKAGES.map(async (pkg) => fetchModelJSON(pkg, branchName)));
for (const modelJSONFile of modelJSONFiles) {
addPackageToModel(model, modelJSONFile);
}
} else {
const modelJSON = await fetchModelJSON(packageName, branchName);
addPackageToModel(model, modelJSON);
}
const [memberName, overloadIndex] = decodeURIComponent(item).split(OVERLOAD_SEPARATOR);
// eslint-disable-next-line prefer-const
let { containerKey, displayName: name } = findMember(model, packageName, memberName) ?? {};
if (name && overloadIndex && !Number.isNaN(Number.parseInt(overloadIndex, 10))) {
containerKey = ApiFunction.getContainerKey(name, Number.parseInt(overloadIndex, 10));
}
return memberName && containerKey ? findMemberByKey(model, packageName, containerKey) ?? null : null;
}