Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor!: consolidated options parameters#11102

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
almeidx wants to merge2 commits intomain
base:main
Choose a base branch
Loading
fromrefactor/core-consolidated-options
Draft
Show file tree
Hide file tree
Changes from1 commit
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
NextNext commit
refactor!: consolidated options parameters
  • Loading branch information
@almeidx
almeidx committedSep 17, 2025
commite28c7104912f027bd8aa66731600512406a5915d
3 changes: 2 additions & 1 deletionpackages/core/package.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,7 +70,8 @@
"@discordjs/ws": "workspace:^",
"@sapphire/snowflake": "^3.5.5",
"@vladfrangu/async_event_emitter": "^2.4.6",
"discord-api-types": "^0.38.23"
"discord-api-types": "^0.38.23",
"type-fest": "^5.0.0"
},
"devDependencies": {
"@discordjs/api-extractor": "workspace:^",
Expand Down
21 changes: 12 additions & 9 deletionspackages/core/src/api/applicationCommands.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,7 @@ import {
type RESTPutAPIApplicationGuildCommandsResult,
type Snowflake,
} from 'discord-api-types/v10';
import type { APIOptions } from '../util/api-options.js';

export class ApplicationCommandsAPI {
public constructor(private readonly rest: REST) {}
Expand All@@ -35,19 +36,21 @@ export class ApplicationCommandsAPI {
* Fetches all global commands for a application
*
* @see {@link https://discord.com/developers/docs/interactions/application-commands#get-global-application-commands}
* @param applicationId - The application id to fetch commands for
* @param query - The query options for fetching commands
* @param options - The options for fetching commands
*/
public async getGlobalCommands(
applicationId: Snowflake,
query: RESTGetAPIApplicationCommandsQuery = {},
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
) {
public async getGlobalCommands({
query,
route: { applicationId },
options,
}: APIOptions<
Pick<RequestData, 'auth' | 'signal'>,
{ applicationId: Snowflake },
never,
RESTGetAPIApplicationCommandsQuery
>) {
return this.rest.get(Routes.applicationCommands(applicationId), {
auth,
...options,
query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIApplicationCommandsResult>;
}

Expand Down
5 changes: 3 additions & 2 deletionspackages/core/src/api/voice.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,7 @@ import {
type RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody,
type RESTPatchAPIGuildVoiceStateUserResult,
} from 'discord-api-types/v10';
import type { APIOptions } from '../util/api-options.js';

export class VoiceAPI {
public constructor(private readonly rest: REST) {}
Expand All@@ -22,8 +23,8 @@ export class VoiceAPI {
* @see {@link https://discord.com/developers/docs/resources/voice#list-voice-regions}
* @param options - The options for fetching the voice regions
*/
public async getVoiceRegions({auth, signal}: Pick<RequestData, 'auth' | 'signal'> = {}) {
return this.rest.get(Routes.voiceRegions(),{ auth, signal }) as Promise<RESTGetAPIVoiceRegionsResult>;
public async getVoiceRegions({options}:APIOptions<Pick<RequestData, 'auth' | 'signal'>> = {}) {
return this.rest.get(Routes.voiceRegions(),options) as Promise<RESTGetAPIVoiceRegionsResult>;
}

/**
Expand Down
19 changes: 19 additions & 0 deletionspackages/core/src/util/api-options.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
import type { RequestData } from '@discordjs/rest';
import type { If, IsNever, RequiredKeysOf } from 'type-fest';

/**
* Creates the input type for an API method with optional properties based on the provided type parameters.
*
* @typeParam Options - Options for the request.
* @typeParam Route - Route parameters for the endpoint.
* @typeParam Body - Body for the request.
* @typeParam Query - Query parameters for the endpoint.
*/
export type APIOptions<
Options extends RequestData,
Route extends object = never,
Body extends object = never,
Query extends object = never,
> = If<IsNever<Body>, object, If<IsNever<RequiredKeysOf<Body>>, { body?: Body }, { body: Body }>> &
If<IsNever<Query>, object, If<IsNever<RequiredKeysOf<Query>>, { query?: Query }, { query: Query }>> &
If<IsNever<Route>, object, { route: Route }> & { options?: Options };
44 changes: 31 additions & 13 deletionspnpm-lock.yaml
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.


[8]ページ先頭

©2009-2025 Movatter.jp