Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Routes } from 'discord-api-types/v10';
import { glob, readFile } from 'node:fs/promises';

const usedRoutes = new Set();
const usedRoutes = new Set<string>();

const ignoredRoutes = new Set([
// Deprecated
Expand All @@ -13,12 +13,14 @@ const ignoredRoutes = new Set([
'nitroStickerPacks',
]);

for await (const file of glob('src/api/*.ts')) {
const content = await readFile(file, 'utf-8');
const cwd = new URL('../src/api/', import.meta.url);

for await (const file of glob('**/*.ts', { cwd })) {
const content = await readFile(new URL(file, cwd), 'utf-8');

const routes = content.matchAll(/Routes\.([\w\d_]+)/g);
for (const route of routes) {
usedRoutes.add(route[1]);
usedRoutes.add(route[1]!);
}
}

Expand Down
28 changes: 28 additions & 0 deletions packages/core/scripts/find-returns-not-return-type.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { glob, readFile } from 'node:fs/promises';

const cwd = new URL('../src/api/', import.meta.url);
const results: string[] = [];

for await (const file of glob('**/*.ts', { cwd })) {
const content = await readFile(new URL(file, cwd), { encoding: 'utf-8' });

const matches = content.matchAll(/as Promise<(?<returnType>\w+)>/g);

for (const match of matches) {
const returnType = match.groups!.returnType!;

if (!returnType.startsWith('REST') || !returnType.includes('Result')) {
results.push(`in file core/src/api/${file}: ${returnType}`);
}
}
}

if (results.length > 0) {
console.warn('Found return types that are not REST return types:');

for (const result of results) {
console.warn(` - ${result}`);
}
} else {
console.log('No return types that are not REST return types found');
}
3 changes: 1 addition & 2 deletions packages/core/src/api/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { makeURLSearchParams, type RawFile, type RequestData, type REST } from '@discordjs/rest';
import {
Routes,
type APIThreadChannel,
type RESTDeleteAPIChannelResult,
type RESTGetAPIChannelInvitesResult,
type RESTGetAPIChannelMessageReactionUsersQuery,
Expand Down Expand Up @@ -566,7 +565,7 @@ export class ChannelsAPI {
body,
reason,
signal,
}) as Promise<APIThreadChannel>;
}) as Promise<RESTPostAPIChannelThreadsResult>;
}

/**
Expand Down