Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types(ApplicationCommandManager): Deprecate old *Data type usages and allow camel cased dapi types to be used #6959

Merged
merged 14 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from 10 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
53 changes: 28 additions & 25 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@types/ws": "^8.2.0",
"discord-api-types": "^0.24.0",
"node-fetch": "^2.6.1",
"type-fest": "^2.5.3",
"ws": "^8.2.3"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"array-type": [true, "array"],
"one-line": false,
"no-any-union": false,
"void-return": false
"void-return": false,
"unified-signatures": false
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved
}
}
64 changes: 49 additions & 15 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
APIUser,
GatewayVoiceServerUpdateDispatchData,
GatewayVoiceStateUpdateDispatchData,
RESTPatchAPIApplicationCommandJSONBody,
RESTPostAPIApplicationCommandsJSONBody,
Snowflake,
} from 'discord-api-types/v9';
Expand Down Expand Up @@ -137,6 +138,7 @@ import {
RawWidgetData,
RawWidgetMemberData,
} from './rawDataTypes';
import type { CamelCasedPropertiesDeep } from 'type-fest';
suneettipirneni marked this conversation as resolved.
Show resolved Hide resolved

//#region Classes

Expand Down Expand Up @@ -213,7 +215,7 @@ export class ApplicationCommand<PermissionsFetchType = {}> extends Base {
public readonly manager: ApplicationCommandManager;
public id: Snowflake;
public name: string;
public options: ApplicationCommandOption[];
public options: Camelize<APIApplicationCommandOption>[];
public permissions: ApplicationCommandPermissionsManager<
PermissionsFetchType,
PermissionsFetchType,
Expand All @@ -224,23 +226,29 @@ export class ApplicationCommand<PermissionsFetchType = {}> extends Base {
public type: ApplicationCommandType;
public version: Snowflake;
public delete(): Promise<ApplicationCommand<PermissionsFetchType>>;
/** @deprecated use `edit(Camelize<RESTPatchAPIApplicationCommandJSONBody>)` instead */
public edit(data: ApplicationCommandData): Promise<ApplicationCommand<PermissionsFetchType>>;
public edit(
data: Camelize<RESTPatchAPIApplicationCommandJSONBody>,
): Promise<ApplicationCommand<PermissionsFetchType>>;
public equals(
command: ApplicationCommand | ApplicationCommandData | RawApplicationCommandData,
command: ApplicationCommand | Camelize<RESTPatchAPIApplicationCommandJSONBody> | RawApplicationCommandData,
enforceOptionorder?: boolean,
): boolean;
public static optionsEqual(
existing: ApplicationCommandOption[],
options: ApplicationCommandOption[] | ApplicationCommandOptionData[] | APIApplicationCommandOption[],
existing: Camelize<APIApplicationCommandOption>[],
options: Camelize<APIApplicationCommandOption>[] | APIApplicationCommandOption[],
enforceOptionorder?: boolean,
): boolean;
private static _optionEquals(
existing: ApplicationCommandOption,
options: ApplicationCommandOption | ApplicationCommandOptionData | APIApplicationCommandOption,
existing: Camelize<APIApplicationCommandOption>[],
options: Camelize<APIApplicationCommandOption>[] | APIApplicationCommandOption,
enforceOptionorder?: boolean,
): boolean;
private static transformOption(option: ApplicationCommandOptionData, received?: boolean): unknown;
private static transformCommand(command: ApplicationCommandData): RESTPostAPIApplicationCommandsJSONBody;
private static transformOption(option: Camelize<APIApplicationCommandOption>, received?: boolean): unknown;
private static transformCommand(
command: Camelize<RESTPostAPIApplicationCommandsJSONBody>,
): RESTPostAPIApplicationCommandsJSONBody;
private static isAPICommandData(command: object): command is RESTPostAPIApplicationCommandsJSONBody;
}

Expand Down Expand Up @@ -2317,10 +2325,8 @@ export class WebhookClient extends WebhookMixin(BaseClient) {
options: string | MessagePayload | WebhookEditMessageOptions,
): Promise<APIMessage>;
public fetchMessage(message: Snowflake, options?: WebhookFetchMessageOptions): Promise<APIMessage>;
/* tslint:disable:unified-signatures */
/** @deprecated */
public fetchMessage(message: Snowflake, cache?: boolean): Promise<APIMessage>;
/* tslint:enable:unified-signatures */
public send(options: string | MessagePayload | WebhookMessageOptions): Promise<APIMessage>;
}

Expand Down Expand Up @@ -2613,7 +2619,9 @@ export abstract class CachedManager<K, Holds, R> extends DataManager<K, Holds, R
private _add(data: unknown, cache?: boolean, { id, extras }?: { id: K; extras: unknown[] }): Holds;
}

export type ApplicationCommandDataResolvable = ApplicationCommandData | RESTPostAPIApplicationCommandsJSONBody;
export type ApplicationCommandDataResolvable =
| Camelize<RESTPostAPIApplicationCommandsJSONBody>
| RESTPostAPIApplicationCommandsJSONBody;

export class ApplicationCommandManager<
ApplicationCommandScope = ApplicationCommand<{ guild: GuildResolvable }>,
Expand All @@ -2629,7 +2637,18 @@ export class ApplicationCommandManager<
null
>;
private commandPath({ id, guildId }: { id?: Snowflake; guildId?: Snowflake }): unknown;
/** @deprecated use `create(ApplicationCommandDataResolvable)` instead */
public create(
command: ApplicationCommandData | RESTPostAPIApplicationCommandsJSONBody,
): Promise<ApplicationCommandScope>;
/** @deprecated use `create(ApplicationCommandDataResolvable, Snowflake)` instead */
public create(
command: ApplicationCommandData | RESTPostAPIApplicationCommandsJSONBody,
guildId: Snowflake,
): Promise<ApplicationCommand>;
public create(command: ApplicationCommandDataResolvable, guildId?: Snowflake): Promise<ApplicationCommandScope>;
/** @deprecated use `delete(ApplicationCommandDataResolvable, Snowflake?)` instead */
public delete(command: ApplicationCommandData, guildId?: Snowflake): Promise<ApplicationCommandScope | null>;
public delete(command: ApplicationCommandResolvable, guildId?: Snowflake): Promise<ApplicationCommandScope | null>;
public edit(
command: ApplicationCommandResolvable,
Expand All @@ -2650,13 +2669,20 @@ export class ApplicationCommandManager<
id?: Snowflake,
options?: FetchApplicationCommandOptions,
): Promise<Collection<Snowflake, ApplicationCommandScope>>;
/** @deprecated Use `set(ApplicationCommandResolvable)` instead */
public set(commands: ApplicationCommandData[]): Promise<Collection<Snowflake, ApplicationCommandScope>>;
/** @deprecated Use `set(ApplicationCommandResolvable, Snowflake)` instead */
public set(
commands: ApplicationCommandData[],
guildId: Snowflake,
): Promise<Collection<Snowflake, ApplicationCommand>>;
public set(commands: ApplicationCommandDataResolvable[]): Promise<Collection<Snowflake, ApplicationCommandScope>>;
public set(
commands: ApplicationCommandDataResolvable[],
guildId: Snowflake,
): Promise<Collection<Snowflake, ApplicationCommand>>;
private static transformCommand(
command: ApplicationCommandData,
command: Camelize<RESTPostAPIApplicationCommandsJSONBody>,
): Omit<APIApplicationCommand, 'id' | 'application_id' | 'guild_id'>;
}

Expand Down Expand Up @@ -2721,14 +2747,18 @@ export class GuildApplicationCommandManager extends ApplicationCommandManager<Ap
private constructor(guild: Guild, iterable?: Iterable<RawApplicationCommandData>);
public guild: Guild;
public create(command: ApplicationCommandDataResolvable): Promise<ApplicationCommand>;
public delete(command: ApplicationCommandResolvable): Promise<ApplicationCommand | null>;
/** @deprecated use `delete(ApplicationCommandDataResolvable, Snowflake?)` instead */
public delete(command: ApplicationCommandData, guildId?: Snowflake): Promise<ApplicationCommand | null>;
public delete(command: ApplicationCommandResolvable, guildId?: Snowflake): Promise<ApplicationCommand | null>;
public edit(
command: ApplicationCommandResolvable,
data: ApplicationCommandDataResolvable,
): Promise<ApplicationCommand>;
public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<ApplicationCommand>;
public fetch(options: BaseFetchOptions): Promise<Collection<Snowflake, ApplicationCommand>>;
public fetch(id?: undefined, options?: BaseFetchOptions): Promise<Collection<Snowflake, ApplicationCommand>>;
/** @deprecated Use `set(ApplicationCommandResolvable)` instead */
public set(commands: ApplicationCommandData[]): Promise<Collection<Snowflake, ApplicationCommand>>;
public set(commands: ApplicationCommandDataResolvable[]): Promise<Collection<Snowflake, ApplicationCommand>>;
}

Expand Down Expand Up @@ -3047,10 +3077,8 @@ export interface PartialWebhookFields {
options: string | MessagePayload | WebhookEditMessageOptions,
): Promise<Message | APIMessage>;
fetchMessage(message: Snowflake | '@original', options?: WebhookFetchMessageOptions): Promise<Message | APIMessage>;
/* tslint:disable:unified-signatures */
/** @deprecated */
fetchMessage(message: Snowflake | '@original', cache?: boolean): Promise<Message | APIMessage>;
/* tslint:enable:unified-signatures */
send(options: string | MessagePayload | WebhookMessageOptions): Promise<Message | APIMessage>;
}

Expand Down Expand Up @@ -3316,6 +3344,7 @@ export interface ChatInputApplicationCommandData extends BaseApplicationCommandD
options?: ApplicationCommandOptionData[];
}

/** @deprecated use `Camelize<RESTPostApplicationCommandBody>` instead */
export type ApplicationCommandData =
| UserApplicationCommandData
| MessageApplicationCommandData
Expand Down Expand Up @@ -3403,6 +3432,10 @@ export interface ApplicationCommandNonOptions extends BaseApplicationCommandOpti
type: Exclude<CommandOptionNonChoiceResolvableType, ApplicationCommandOptionTypes>;
}

// Type alias since the lib name is very long.
export type Camelize<T> = CamelCasedPropertiesDeep<T>;

/** @deprecated Use `Camelize<APIApplicationCommandsOption>` instead. */
export type ApplicationCommandOptionData =
| ApplicationCommandSubGroupData
| ApplicationCommandNonOptionsData
Expand All @@ -3412,6 +3445,7 @@ export type ApplicationCommandOptionData =
| ApplicationCommandNumericOptionData
| ApplicationCommandSubCommandData;

/** @deprecated use `Camelize<APIApplicationCommandOption>` instead */
export type ApplicationCommandOption =
| ApplicationCommandSubGroup
| ApplicationCommandNonOptions
Expand Down
Loading