Compare commits

...

21 Commits

Author SHA1 Message Date
Vlad Frangu
295276a581 chore(release): 0.38.17 🎉 (#1311)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-07-25 11:59:26 +03:00
Vlad Frangu
46bb280690 chore: enable automerge for more things
cuz i am lazy
2025-07-25 11:59:04 +03:00
renovate[bot]
cda030d74e chore(deps): update patch/minor dependencies (#1313)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-07-25 11:58:15 +03:00
renovate[bot]
79534f2e9d chore(deps): update eslint/prettier to v8.38.0 (#1312)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-07-25 06:24:27 +00:00
Jiralite
e6c12634e9 ci: disallow changes to these directories (#829) 2025-07-24 14:58:31 +03:00
Jiralite
a41e646d3d feat(GuildMemberFlags): add AutoModQuarantinedGuildTag (#1309) 2025-07-24 14:57:06 +03:00
Jiralite
a72e4545a3 feat(auditLog): add AUTO_MODERATION_QUARANTINE_USER (#1310) 2025-07-24 14:56:34 +03:00
Vlad Frangu
0785436e2f chore: find replace? 2025-07-23 00:21:44 +03:00
Vlad Frangu
5cd2511798 docs: generate routes interfaces automatically on build (#1308) 2025-07-23 00:15:59 +03:00
renovate[bot]
b760be279a chore(deps): lock file maintenance (#1305)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-07-18 15:22:54 +03:00
renovate[bot]
c47e14570d chore(deps): update patch/minor dependencies (#1304)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-07-18 13:58:06 +03:00
renovate[bot]
30f95bc938 chore(deps): update eslint/prettier (#1303)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-07-18 13:57:48 +03:00
dependabot[bot]
fe220db046 chore(deps): bump on-headers and compression in /website (#1302)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-18 13:57:38 +03:00
Vlad Frangu
2f3b892feb chore(release): 0.38.16 🎉 (#1301)
Build ran for 574e5c12bd

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-07-13 19:41:15 +03:00
Jiralite
574e5c12bd fix(APIApplicationCommandChannelOption): exclude directory channels (#1300) 2025-07-13 19:33:21 +03:00
renovate[bot]
3eb77eb89e chore(deps): lock file maintenance (#1299)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-07-11 13:45:21 +03:00
renovate[bot]
cbee43cdcd chore(deps): update patch/minor dependencies (#1298)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-07-11 13:37:43 +03:00
renovate[bot]
ecb4c336c0 chore(deps): update eslint/prettier to v8.36.0 (#1297)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-07-11 13:37:36 +03:00
renovate[bot]
9b68f04fb7 chore(deps): lock file maintenance (#1296)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-07-10 14:01:32 +03:00
renovate[bot]
82f8ec4366 chore(deps): update eslint/prettier (#1294)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-07-05 22:42:26 +03:00
renovate[bot]
92b6632981 chore(deps): update patch/minor dependencies (#1295)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-07-05 22:42:16 +03:00
32 changed files with 2236 additions and 836 deletions

View File

@@ -1,33 +0,0 @@
name: Deno
on:
pull_request:
types:
- opened
- synchronize
jobs:
check_deno:
name: Ensure Deno types are in sync with the code
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
cache: 'yarn'
node-version-file: package.json
- name: Install Dependencies
run: yarn
- name: Run Check Script
run: node ./scripts/actions/report-deno-not-ran.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -0,0 +1,41 @@
name: Validate Pull Request
on:
pull_request:
jobs:
deno:
name: Ensure Deno types are synchronized
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Project
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
cache: 'yarn'
node-version-file: package.json
- name: Install Dependencies
run: yarn
- name: Run Check Script
run: node ./scripts/actions/report-deno-not-ran.mjs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
validate-supported-versions:
runs-on: ubuntu-latest
name: Disallow unsupported API versions
steps:
- name: Check for unsupported API changes
env:
GH_TOKEN: ${{ github.token }}
run: |
PATTERNS="gateway/v6.ts|gateway/v8.ts|payloads/v6/|payloads/v8/|rest/v6/|rest/v8/|rpc/v8.ts|utils/v8.ts|voice/v8.ts|^v6.ts$|^v8.ts$"
if gh pr view ${{ github.event.pull_request.number }} --repo ${{github.repository}} --json files --jq ".files[].path | select(test(\"$PATTERNS\"))" | grep -q .; then
echo "::error::Unsupported API versions modified. Please make changes to current API versions only."
exit 1
fi

2
.gitignore vendored
View File

@@ -66,3 +66,5 @@ docs/*
# djs repo clone
djs
_generated_

View File

@@ -38,3 +38,5 @@ utils/v8.ts
v8.ts
.yarn/*
djs/*
_generated_

View File

@@ -1,3 +1,22 @@
## [0.38.17](https://github.com/discordjs/discord-api-types/compare/0.38.16...0.38.17) (2025-07-24)
### Features
* **auditLog:** add `AUTO_MODERATION_QUARANTINE_USER` ([#1310](https://github.com/discordjs/discord-api-types/issues/1310)) ([a72e454](https://github.com/discordjs/discord-api-types/commit/a72e4545a3409388a9c5ec0b5555ecc258de0ac2))
* **GuildMemberFlags:** add `AutoModQuarantinedGuildTag` ([#1309](https://github.com/discordjs/discord-api-types/issues/1309)) ([a41e646](https://github.com/discordjs/discord-api-types/commit/a41e646d3d9b9f6bb15c2f6165043ef8042b26bf))
## [0.38.16](https://github.com/discordjs/discord-api-types/compare/0.38.15...0.38.16) (2025-07-13)
### Bug Fixes
* **APIApplicationCommandChannelOption:** exclude directory channels ([#1300](https://github.com/discordjs/discord-api-types/issues/1300)) ([574e5c1](https://github.com/discordjs/discord-api-types/commit/574e5c12bddd2c515fd2b96b5705b5ef9f9d2787))
## [0.38.15](https://github.com/discordjs/discord-api-types/compare/0.38.14...0.38.15) (2025-07-03)

19
deno/CHANGELOG.md generated
View File

@@ -1,3 +1,22 @@
## [0.38.17](https://github.com/discordjs/discord-api-types/compare/0.38.16...0.38.17) (2025-07-24)
### Features
* **auditLog:** add `AUTO_MODERATION_QUARANTINE_USER` ([#1310](https://github.com/discordjs/discord-api-types/issues/1310)) ([a72e454](https://github.com/discordjs/discord-api-types/commit/a72e4545a3409388a9c5ec0b5555ecc258de0ac2))
* **GuildMemberFlags:** add `AutoModQuarantinedGuildTag` ([#1309](https://github.com/discordjs/discord-api-types/issues/1309)) ([a41e646](https://github.com/discordjs/discord-api-types/commit/a41e646d3d9b9f6bb15c2f6165043ef8042b26bf))
## [0.38.16](https://github.com/discordjs/discord-api-types/compare/0.38.15...0.38.16) (2025-07-13)
### Bug Fixes
* **APIApplicationCommandChannelOption:** exclude directory channels ([#1300](https://github.com/discordjs/discord-api-types/issues/1300)) ([574e5c1](https://github.com/discordjs/discord-api-types/commit/574e5c12bddd2c515fd2b96b5705b5ef9f9d2787))
## [0.38.15](https://github.com/discordjs/discord-api-types/compare/0.38.14...0.38.15) (2025-07-03)

View File

@@ -5,7 +5,7 @@ import type { ApplicationCommandOptionType } from './shared.ts';
export interface APIApplicationCommandChannelOption
extends APIApplicationCommandOptionBase<ApplicationCommandOptionType.Channel> {
channel_types?: Exclude<ChannelType, ChannelType.DM | ChannelType.GroupDM>[];
channel_types?: Exclude<ChannelType, ChannelType.DM | ChannelType.GroupDM | ChannelType.GuildDirectory>[];
}
export type APIApplicationCommandInteractionDataChannelOption = APIInteractionDataOptionBase<

View File

@@ -207,6 +207,7 @@ export enum AuditLogEvent {
AutoModerationBlockMessage,
AutoModerationFlagToChannel,
AutoModerationUserCommunicationDisabled,
AutoModerationQuarantineUser,
CreatorMonetizationRequestCreated = 150,
CreatorMonetizationTermsAccepted,
@@ -232,6 +233,7 @@ export interface APIAuditLogOptions {
* - AUTO_MODERATION_BLOCK_MESSAGE
* - AUTO_MODERATION_FLAG_TO_CHANNEL
* - AUTO_MODERATION_USER_COMMUNICATION_DISABLED
* - AUTO_MODERATION_QUARANTINE_USER
*/
auto_moderation_rule_name?: string;
/**
@@ -241,6 +243,7 @@ export interface APIAuditLogOptions {
* - AUTO_MODERATION_BLOCK_MESSAGE
* - AUTO_MODERATION_FLAG_TO_CHANNEL
* - AUTO_MODERATION_USER_COMMUNICATION_DISABLED
* - AUTO_MODERATION_QUARANTINE_USER
*/
auto_moderation_rule_trigger_type?: AuditLogRuleTriggerType;
/**
@@ -272,6 +275,7 @@ export interface APIAuditLogOptions {
* - AUTO_MODERATION_BLOCK_MESSAGE
* - AUTO_MODERATION_FLAG_TO_CHANNEL
* - AUTO_MODERATION_USER_COMMUNICATION_DISABLED
* - AUTO_MODERATION_QUARANTINE_USER
*/
channel_id?: Snowflake;

View File

@@ -803,6 +803,10 @@ export enum GuildMemberFlags {
* Member has dismissed the DM settings upsell
*/
DmSettingsUpsellAcknowledged = 1 << 9,
/**
* Member's guild tag is blocked by AutoMod
*/
AutoModQuarantinedGuildTag = 1 << 10,
}
/**

View File

@@ -5,7 +5,7 @@ import type { ApplicationCommandOptionType } from './shared.ts';
export interface APIApplicationCommandChannelOption
extends APIApplicationCommandOptionBase<ApplicationCommandOptionType.Channel> {
channel_types?: Exclude<ChannelType, ChannelType.DM | ChannelType.GroupDM>[];
channel_types?: Exclude<ChannelType, ChannelType.DM | ChannelType.GroupDM | ChannelType.GuildDirectory>[];
}
export type APIApplicationCommandInteractionDataChannelOption = APIInteractionDataOptionBase<

View File

@@ -207,6 +207,7 @@ export enum AuditLogEvent {
AutoModerationBlockMessage,
AutoModerationFlagToChannel,
AutoModerationUserCommunicationDisabled,
AutoModerationQuarantineUser,
CreatorMonetizationRequestCreated = 150,
CreatorMonetizationTermsAccepted,
@@ -232,6 +233,7 @@ export interface APIAuditLogOptions {
* - AUTO_MODERATION_BLOCK_MESSAGE
* - AUTO_MODERATION_FLAG_TO_CHANNEL
* - AUTO_MODERATION_USER_COMMUNICATION_DISABLED
* - AUTO_MODERATION_QUARANTINE_USER
*/
auto_moderation_rule_name?: string;
/**
@@ -241,6 +243,7 @@ export interface APIAuditLogOptions {
* - AUTO_MODERATION_BLOCK_MESSAGE
* - AUTO_MODERATION_FLAG_TO_CHANNEL
* - AUTO_MODERATION_USER_COMMUNICATION_DISABLED
* - AUTO_MODERATION_QUARANTINE_USER
*/
auto_moderation_rule_trigger_type?: AuditLogRuleTriggerType;
/**
@@ -272,6 +275,7 @@ export interface APIAuditLogOptions {
* - AUTO_MODERATION_BLOCK_MESSAGE
* - AUTO_MODERATION_FLAG_TO_CHANNEL
* - AUTO_MODERATION_USER_COMMUNICATION_DISABLED
* - AUTO_MODERATION_QUARANTINE_USER
*/
channel_id?: Snowflake;

View File

@@ -795,6 +795,10 @@ export enum GuildMemberFlags {
* Member has dismissed the DM settings upsell
*/
DmSettingsUpsellAcknowledged = 1 << 9,
/**
* Member's guild tag is blocked by AutoMod
*/
AutoModQuarantinedGuildTag = 1 << 10,
}
/**

View File

@@ -250,6 +250,8 @@ export default config([
'djs/**/*',
'.yarn/*',
'_generated_/**/*',
],
},
commonRuleset,

View File

@@ -1,6 +1,6 @@
{
"name": "discord-api-types",
"version": "0.38.15",
"version": "0.38.17",
"description": "Discord API typings that are kept up to date for use in bot library creation.",
"homepage": "https://discord-api-types.dev",
"workspaces": [
@@ -96,7 +96,8 @@
"scripts": {
"build:ci": "tsc --noEmit --incremental false",
"build:deno": "node ./scripts/deno.mjs",
"build:node": "tsc && run-p 'esm:*'",
"build:generated": "tsx ./scripts/generate-prettier-routes-interface.ts",
"build:node": "yarn build:generated && tsc && run-p 'esm:*'",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"ci:pr": "run-s changelog lint build:deno && node ./scripts/bump-website-version.mjs",
"clean:deno": "rimraf deno/",
@@ -113,7 +114,7 @@
"lint": "prettier --write . && eslint --format=pretty --fix --ext mjs,ts \"{gateway,payloads,rest,rpc,voice,utils}/**/*.ts\" \"{globals,v*}.ts\" \"scripts/**/*.mjs\"",
"postinstallDev": "is-ci || husky",
"prepack": "run-s clean test:lint build:node",
"postpack": "run-s clean:node build:deno",
"postpack": "run-s clean:node build:deno && git checkout -- './deno/**/*.ts' './rest/**/*.ts'",
"test:lint": "prettier --check . && eslint --format=pretty --ext mjs,ts \"{gateway,payloads,rest,rpc,voice,utils}/**/*.ts\" \"{globals,v*}.ts\" \"scripts/**/*.mjs\"",
"test:types": "tsc -p tests"
},
@@ -126,6 +127,7 @@
"author": "Vlad Frangu <me@vladfrangu.dev>",
"license": "MIT",
"files": [
"_generated_/**/*.{js,js.map,d.ts,d.ts.map,mjs}",
"{gateway,payloads,rest,rpc,voice,utils}/**/*.{js,js.map,d.ts,d.ts.map,mjs}",
"{globals,v*}.{js,js.map,d.ts,d.ts.map,mjs}"
],
@@ -155,8 +157,9 @@
"prettier": "^3.5.3",
"pretty-quick": "^4.1.1",
"rimraf": "^6.0.1",
"ts-morph": "^26.0.0",
"tsutils": "^3.21.0",
"tsx": "^4.19.4",
"tsx": "^4.20.3",
"typescript": "^5.8.3",
"typescript-eslint": "^8.33.0"
},
@@ -206,7 +209,7 @@
},
"packageManager": "yarn@4.9.2",
"volta": {
"node": "24.3.0",
"node": "24.4.1",
"yarn": "4.9.2"
}
}

View File

@@ -5,7 +5,7 @@ import type { ApplicationCommandOptionType } from './shared';
export interface APIApplicationCommandChannelOption
extends APIApplicationCommandOptionBase<ApplicationCommandOptionType.Channel> {
channel_types?: Exclude<ChannelType, ChannelType.DM | ChannelType.GroupDM>[];
channel_types?: Exclude<ChannelType, ChannelType.DM | ChannelType.GroupDM | ChannelType.GuildDirectory>[];
}
export type APIApplicationCommandInteractionDataChannelOption = APIInteractionDataOptionBase<

View File

@@ -207,6 +207,7 @@ export enum AuditLogEvent {
AutoModerationBlockMessage,
AutoModerationFlagToChannel,
AutoModerationUserCommunicationDisabled,
AutoModerationQuarantineUser,
CreatorMonetizationRequestCreated = 150,
CreatorMonetizationTermsAccepted,
@@ -232,6 +233,7 @@ export interface APIAuditLogOptions {
* - AUTO_MODERATION_BLOCK_MESSAGE
* - AUTO_MODERATION_FLAG_TO_CHANNEL
* - AUTO_MODERATION_USER_COMMUNICATION_DISABLED
* - AUTO_MODERATION_QUARANTINE_USER
*/
auto_moderation_rule_name?: string;
/**
@@ -241,6 +243,7 @@ export interface APIAuditLogOptions {
* - AUTO_MODERATION_BLOCK_MESSAGE
* - AUTO_MODERATION_FLAG_TO_CHANNEL
* - AUTO_MODERATION_USER_COMMUNICATION_DISABLED
* - AUTO_MODERATION_QUARANTINE_USER
*/
auto_moderation_rule_trigger_type?: AuditLogRuleTriggerType;
/**
@@ -272,6 +275,7 @@ export interface APIAuditLogOptions {
* - AUTO_MODERATION_BLOCK_MESSAGE
* - AUTO_MODERATION_FLAG_TO_CHANNEL
* - AUTO_MODERATION_USER_COMMUNICATION_DISABLED
* - AUTO_MODERATION_QUARANTINE_USER
*/
channel_id?: Snowflake;

View File

@@ -803,6 +803,10 @@ export enum GuildMemberFlags {
* Member has dismissed the DM settings upsell
*/
DmSettingsUpsellAcknowledged = 1 << 9,
/**
* Member's guild tag is blocked by AutoMod
*/
AutoModQuarantinedGuildTag = 1 << 10,
}
/**

View File

@@ -5,7 +5,7 @@ import type { ApplicationCommandOptionType } from './shared';
export interface APIApplicationCommandChannelOption
extends APIApplicationCommandOptionBase<ApplicationCommandOptionType.Channel> {
channel_types?: Exclude<ChannelType, ChannelType.DM | ChannelType.GroupDM>[];
channel_types?: Exclude<ChannelType, ChannelType.DM | ChannelType.GroupDM | ChannelType.GuildDirectory>[];
}
export type APIApplicationCommandInteractionDataChannelOption = APIInteractionDataOptionBase<

View File

@@ -207,6 +207,7 @@ export enum AuditLogEvent {
AutoModerationBlockMessage,
AutoModerationFlagToChannel,
AutoModerationUserCommunicationDisabled,
AutoModerationQuarantineUser,
CreatorMonetizationRequestCreated = 150,
CreatorMonetizationTermsAccepted,
@@ -232,6 +233,7 @@ export interface APIAuditLogOptions {
* - AUTO_MODERATION_BLOCK_MESSAGE
* - AUTO_MODERATION_FLAG_TO_CHANNEL
* - AUTO_MODERATION_USER_COMMUNICATION_DISABLED
* - AUTO_MODERATION_QUARANTINE_USER
*/
auto_moderation_rule_name?: string;
/**
@@ -241,6 +243,7 @@ export interface APIAuditLogOptions {
* - AUTO_MODERATION_BLOCK_MESSAGE
* - AUTO_MODERATION_FLAG_TO_CHANNEL
* - AUTO_MODERATION_USER_COMMUNICATION_DISABLED
* - AUTO_MODERATION_QUARANTINE_USER
*/
auto_moderation_rule_trigger_type?: AuditLogRuleTriggerType;
/**
@@ -272,6 +275,7 @@ export interface APIAuditLogOptions {
* - AUTO_MODERATION_BLOCK_MESSAGE
* - AUTO_MODERATION_FLAG_TO_CHANNEL
* - AUTO_MODERATION_USER_COMMUNICATION_DISABLED
* - AUTO_MODERATION_QUARANTINE_USER
*/
channel_id?: Snowflake;

View File

@@ -795,6 +795,10 @@ export enum GuildMemberFlags {
* Member has dismissed the DM settings upsell
*/
DmSettingsUpsellAcknowledged = 1 << 9,
/**
* Member's guild tag is blocked by AutoMod
*/
AutoModQuarantinedGuildTag = 1 << 10,
}
/**

View File

@@ -4,7 +4,8 @@
"semanticCommits": "enabled",
"lockFileMaintenance": {
"enabled": true,
"schedule": ["before 1pm on friday"]
"schedule": ["before 1pm on friday"],
"automerge": true
},
"ignorePaths": ["website/"],
"packageRules": [
@@ -12,7 +13,8 @@
"matchUpdateTypes": ["patch", "minor"],
"matchCurrentVersion": "!/^0/",
"groupName": "patch/minor dependencies",
"groupSlug": "all-non-major"
"groupSlug": "all-non-major",
"automerge": true
},
{
"groupName": "eslint/prettier",

View File

@@ -0,0 +1,232 @@
import { readdirSync } from 'node:fs';
import { join } from 'node:path';
import type {
InterfaceDeclaration,
ObjectLiteralExpression,
ParameterDeclaration,
ParameterDeclarationStructure,
TypeParameterDeclaration,
TypeParameterDeclarationStructure,
} from 'ts-morph';
import { Project, SyntaxKind } from 'ts-morph';
const RoutesInterfaceName = 'RoutesDeclarations';
const CDNRoutesInterfaceName = 'CDNRoutesDeclarations';
const isInWebsite = __dirname.includes('website');
const extraPath = isInWebsite ? '../' : '';
const versions = readdirSync(join(__dirname, extraPath, '../rest')).filter((dir) => /^v\d+$/.exec(dir));
const generatedRestDirectory = join(__dirname, extraPath, '../_generated_/rest');
const globalsFilePath = join(__dirname, extraPath, '../globals.ts');
function parameterDeclarationToStructure(parameter: ParameterDeclaration): ParameterDeclarationStructure {
const obj = parameter.getStructure();
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
obj.hasQuestionToken = obj.hasQuestionToken || Boolean(obj.initializer);
delete obj.initializer;
return obj;
}
function typeParameterToStructure(typeParameter: TypeParameterDeclaration): TypeParameterDeclarationStructure {
// eslint-disable-next-line sonarjs/prefer-immediate-return
const obj = typeParameter.getStructure();
return obj;
}
function handleTypeParameter(typeParameter: TypeParameterDeclaration, allSeen: Set<string>) {
const extendsClause = typeParameter.getConstraint();
if (!extendsClause) {
return;
}
const type = extendsClause.getText();
if (allSeen.has(type)) {
return;
}
allSeen.add(type);
if (type === 'StorePageAssetFormat') {
allSeen.add('ImageFormat');
}
}
function handleObject(object: ObjectLiteralExpression, interfaceToAddTo: InterfaceDeclaration) {
const seenTypeParameters = new Set<string>();
for (const property of object.getPropertiesWithComments()) {
const castedMethod = property.asKindOrThrow(SyntaxKind.MethodDeclaration);
const methodName = castedMethod.getName();
const methodParameters = castedMethod.getParameters();
let methodReturnType = castedMethod.getReturnType().getText();
const methodDocs = castedMethod.getJsDocs();
const returnBody = castedMethod
.getChildren()
?.at(-1)
?.getChildren()
?.at(1)
?.getChildren()
?.at(-1)
?.asKindOrThrow(SyntaxKind.ReturnStatement);
const asExpression = returnBody?.getChildrenOfKind(SyntaxKind.AsExpression)[0];
const unionType = asExpression?.getChildrenOfKind(SyntaxKind.UnionType)?.[0];
// Override with union if it exists in the cast
if (unionType) {
methodReturnType = unionType
.getText()
.split('\n')
.map((line) => line.trim())
.join(' ');
}
if (methodReturnType.startsWith('| ')) {
methodReturnType = methodReturnType.slice(2);
}
const typeParameters = castedMethod.getTypeParameters();
for (const typeParameter of typeParameters) {
handleTypeParameter(typeParameter, seenTypeParameters);
}
interfaceToAddTo.addMethod({
name: methodName,
parameters: methodParameters.map(parameterDeclarationToStructure),
typeParameters: typeParameters.map(typeParameterToStructure),
returnType: methodReturnType,
leadingTrivia:
methodDocs
.map((doc) => doc.getText().replaceAll('Routes.', `${RoutesInterfaceName}.`))
.join('\n')
.replaceAll('\t', '') + '\n',
});
for (const overload of castedMethod.getOverloads()) {
const typeParameters = overload.getTypeParameters();
for (const typeParameter of typeParameters) {
handleTypeParameter(typeParameter, seenTypeParameters);
}
interfaceToAddTo.addMethod({
name: overload.getName(),
parameters: overload.getParameters().map(parameterDeclarationToStructure),
typeParameters: typeParameters.map(typeParameterToStructure),
returnType: overload.getReturnType().getText(),
leadingTrivia:
overload
.getJsDocs()
.map((doc) => doc.getText().replaceAll('Routes.', `${RoutesInterfaceName}.`))
.join('\n')
.replaceAll('\t', '') + '\n',
});
}
}
return seenTypeParameters;
}
for (const version of versions) {
console.log(`Generating interfaces for ${version}...`);
const inputFilePath = join(__dirname, extraPath, `../rest/${version}/index.ts`);
const generatedRestInterfacesFilePath = join(__dirname, extraPath, `../_generated_/rest/${version}/interfaces.ts`);
const project = new Project({});
project.addSourceFileAtPathIfExists(inputFilePath);
project.addSourceFileAtPathIfExists(globalsFilePath);
project.createDirectory(generatedRestDirectory);
const generatedRestInterfacesFile = project.createSourceFile(generatedRestInterfacesFilePath, undefined, {
overwrite: true,
});
const routesDeclarationInterface = generatedRestInterfacesFile.addInterface({
name: RoutesInterfaceName,
leadingTrivia: '// Automatically generated interface from the Routes object.\n',
isExported: true,
});
const cdnRoutesDeclarationInterface = generatedRestInterfacesFile.addInterface({
name: CDNRoutesInterfaceName,
leadingTrivia: '// Automatically generated interface from the CDN Routes object.\n',
isExported: true,
});
generatedRestInterfacesFile.addImportDeclaration({
moduleSpecifier: '../../../globals',
namedImports: ['Snowflake'],
isTypeOnly: true,
});
const routesObjectFile = project.getSourceFileOrThrow(inputFilePath);
routesObjectFile.addImportDeclaration({
moduleSpecifier: `../../_generated_/rest/${version}/interfaces`,
isTypeOnly: true,
namedImports: [RoutesInterfaceName, CDNRoutesInterfaceName],
});
routesObjectFile.addExportDeclaration({
isTypeOnly: true,
moduleSpecifier: `../../_generated_/rest/${version}/interfaces`,
leadingTrivia: '// Exports all generated interfaces from the REST API.\n',
});
const routesObject = routesObjectFile.getVariableDeclarationOrThrow('Routes');
const cdnRoutesObject = routesObjectFile.getVariableDeclaration('CDNRoutes');
if (!cdnRoutesObject) {
console.log('Skipping type generation for', version);
continue;
}
const routesObjectChildren = routesObject.getChildren();
const cdnRoutesObjectChildren = cdnRoutesObject.getChildren();
const [routesIdentifier] = routesObjectChildren;
const routesObjectDeclaration = routesObject.getInitializerOrThrow();
const [cdnRoutesIdentifier] = cdnRoutesObjectChildren;
const cdnRoutesObjectDeclaration = cdnRoutesObject.getInitializerOrThrow();
const importsNeededForRoutes = handleObject(
routesObjectDeclaration.asKindOrThrow(SyntaxKind.ObjectLiteralExpression),
routesDeclarationInterface,
);
const importsNeededForCDNRoutes = handleObject(
cdnRoutesObjectDeclaration.asKindOrThrow(SyntaxKind.ObjectLiteralExpression),
cdnRoutesDeclarationInterface,
);
const typesToImportFromOriginalFile = new Set<string>([...importsNeededForRoutes, ...importsNeededForCDNRoutes]);
if (typesToImportFromOriginalFile.size > 0) {
generatedRestInterfacesFile.addImportDeclaration({
moduleSpecifier: `../../../rest/${version}/index`,
isTypeOnly: true,
namedImports: [...typesToImportFromOriginalFile].sort((a, b) => a.localeCompare(b)),
});
}
routesIdentifier.replaceWithText(`Routes: ${RoutesInterfaceName}`);
cdnRoutesIdentifier.replaceWithText(`CDNRoutes: ${CDNRoutesInterfaceName}`);
project.saveSync();
}

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@
"scripts": {
"docusaurus": "docusaurus",
"start": "npm run clean && docusaurus start",
"build": "npm run clean && cross-env NODE_OPTIONS=\"--max_old_space_size=7500\" docusaurus build",
"build": "npm run clean && cp ../scripts/generate-prettier-routes-interface.ts ./scripts/generate-prettier-routes-interface.ts && npx tsx ./scripts/generate-prettier-routes-interface.ts && cross-env NODE_OPTIONS=\"--max_old_space_size=7500\" docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
@@ -47,7 +47,8 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sass": "^1.81.0",
"swr": "^2.2.5"
"swr": "^2.2.5",
"ts-morph": "^26.0.0"
},
"devDependencies": {
"@apify/docusaurus-plugin-typedoc-api": "^4.3.1",
@@ -66,6 +67,7 @@
"patch-package": "^8.0.0",
"prettier": "^3.4.1",
"pretty-quick": "^4.0.0",
"tsx": "^4.20.3",
"typedoc": "^0.27.1",
"typedoc-plugin-djs-links": "^2.2.1",
"typedoc-plugin-markdown": "^4.3.0",

View File

@@ -1 +1 @@
[{"entryPoints":{"v10":{"path":"v10.ts","label":"API v10"},"v9":{"path":"v9.ts","label":"API v9"},"voice/v4":{"path":"voice/v4.ts","label":"Voice v4"},"voice/v8":{"path":"voice/v8.ts","label":"Voice v8"},"globals":{"path":"globals.ts","label":"Global Types"}},"packageRoot":"/home/runner/work/discord-api-types/discord-api-types/","packagePath":"./","packageSlug":"discord-api-types","packageName":"discord-api-types","packageVersion":"0.38.15"}]
[{"entryPoints":{"v10":{"path":"v10.ts","label":"API v10"},"v9":{"path":"v9.ts","label":"API v9"},"voice/v4":{"path":"voice/v4.ts","label":"Voice v4"},"voice/v8":{"path":"voice/v8.ts","label":"Voice v8"},"globals":{"path":"globals.ts","label":"Global Types"}},"packageRoot":"/home/runner/work/discord-api-types/discord-api-types/","packagePath":"./","packageSlug":"discord-api-types","packageName":"discord-api-types","packageVersion":"0.38.17"}]

View File

@@ -1,3 +1,3 @@
[
"0.38.15"
"0.38.17"
]

1671
yarn.lock

File diff suppressed because it is too large Load Diff