mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
chore(deps): bump discord-api-types (#10841)
* chore(deps): bump discord-api-types * chore: tests * chore: tests 2 * chore: replace ImageSize type with dtypes type
This commit is contained in:
@@ -2,7 +2,7 @@ import {
|
||||
ButtonStyle,
|
||||
ComponentType,
|
||||
type APIActionRowComponent,
|
||||
type APIMessageActionRowComponent,
|
||||
type APIComponentInMessageActionRow,
|
||||
} from 'discord-api-types/v10';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import {
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
StringSelectMenuOptionBuilder,
|
||||
} from '../../src/index.js';
|
||||
|
||||
const rowWithButtonData: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
const rowWithButtonData: APIActionRowComponent<APIComponentInMessageActionRow> = {
|
||||
type: ComponentType.ActionRow,
|
||||
components: [
|
||||
{
|
||||
@@ -25,7 +25,7 @@ const rowWithButtonData: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
],
|
||||
};
|
||||
|
||||
const rowWithSelectMenuData: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
const rowWithSelectMenuData: APIActionRowComponent<APIComponentInMessageActionRow> = {
|
||||
type: ComponentType.ActionRow,
|
||||
components: [
|
||||
{
|
||||
@@ -50,7 +50,7 @@ const rowWithSelectMenuData: APIActionRowComponent<APIMessageActionRowComponent>
|
||||
describe('Action Row Components', () => {
|
||||
describe('Assertion Tests', () => {
|
||||
test('GIVEN valid JSON input THEN valid JSON output is given', () => {
|
||||
const actionRowData: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
const actionRowData: APIActionRowComponent<APIComponentInMessageActionRow> = {
|
||||
type: ComponentType.ActionRow,
|
||||
components: [
|
||||
{
|
||||
@@ -73,7 +73,7 @@ describe('Action Row Components', () => {
|
||||
});
|
||||
|
||||
test('GIVEN valid builder options THEN valid JSON output is given', () => {
|
||||
const rowWithButtonData: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
const rowWithButtonData: APIActionRowComponent<APIComponentInMessageActionRow> = {
|
||||
type: ComponentType.ActionRow,
|
||||
components: [
|
||||
{
|
||||
@@ -85,7 +85,7 @@ describe('Action Row Components', () => {
|
||||
],
|
||||
};
|
||||
|
||||
const rowWithSelectMenuData: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
const rowWithSelectMenuData: APIActionRowComponent<APIComponentInMessageActionRow> = {
|
||||
type: ComponentType.ActionRow,
|
||||
components: [
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
ComponentType,
|
||||
TextInputStyle,
|
||||
type APIButtonComponent,
|
||||
type APIMessageActionRowComponent,
|
||||
type APIComponentInMessageActionRow,
|
||||
type APISelectMenuComponent,
|
||||
type APITextInputComponent,
|
||||
type APIActionRowComponent,
|
||||
@@ -27,7 +27,7 @@ describe('createComponentBuilder', () => {
|
||||
);
|
||||
|
||||
test('GIVEN an action row component THEN returns a ActionRowBuilder', () => {
|
||||
const actionRow: APIActionRowComponent<APIMessageActionRowComponent> = {
|
||||
const actionRow: APIActionRowComponent<APIComponentInMessageActionRow> = {
|
||||
components: [],
|
||||
type: ComponentType.ActionRow,
|
||||
};
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
"funding": "https://github.com/discordjs/discord.js?sponsor",
|
||||
"dependencies": {
|
||||
"@discordjs/util": "workspace:^",
|
||||
"discord-api-types": "^0.37.120",
|
||||
"discord-api-types": "^0.38.1",
|
||||
"ts-mixer": "^6.0.4",
|
||||
"tslib": "^2.8.1",
|
||||
"zod": "^3.24.2",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import type {
|
||||
APITextInputComponent,
|
||||
APIActionRowComponent,
|
||||
APIActionRowComponentTypes,
|
||||
APIComponentInActionRow,
|
||||
APIChannelSelectComponent,
|
||||
APIMentionableSelectComponent,
|
||||
APIRoleSelectComponent,
|
||||
@@ -37,7 +37,7 @@ import { UserSelectMenuBuilder } from './selectMenu/UserSelectMenu.js';
|
||||
import { TextInputBuilder } from './textInput/TextInput.js';
|
||||
|
||||
export interface ActionRowBuilderData
|
||||
extends Partial<Omit<APIActionRowComponent<APIActionRowComponentTypes>, 'components'>> {
|
||||
extends Partial<Omit<APIActionRowComponent<APIComponentInActionRow>, 'components'>> {
|
||||
components: AnyActionRowComponentBuilder[];
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export interface ActionRowBuilderData
|
||||
*
|
||||
* @typeParam ComponentType - The types of components this action row holds
|
||||
*/
|
||||
export class ActionRowBuilder extends ComponentBuilder<APIActionRowComponent<APIActionRowComponentTypes>> {
|
||||
export class ActionRowBuilder extends ComponentBuilder<APIActionRowComponent<APIComponentInActionRow>> {
|
||||
private readonly data: ActionRowBuilderData;
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ export class ActionRowBuilder extends ComponentBuilder<APIActionRowComponent<API
|
||||
* .addComponents(button2, button3);
|
||||
* ```
|
||||
*/
|
||||
public constructor({ components = [], ...data }: Partial<APIActionRowComponent<APIActionRowComponentTypes>> = {}) {
|
||||
public constructor({ components = [], ...data }: Partial<APIActionRowComponent<APIComponentInActionRow>> = {}) {
|
||||
super();
|
||||
this.data = {
|
||||
...structuredClone(data),
|
||||
@@ -328,7 +328,7 @@ export class ActionRowBuilder extends ComponentBuilder<APIActionRowComponent<API
|
||||
/**
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public override toJSON(validationOverride?: boolean): APIActionRowComponent<APIActionRowComponentTypes> {
|
||||
public override toJSON(validationOverride?: boolean): APIActionRowComponent<APIComponentInActionRow> {
|
||||
const { components, ...rest } = this.data;
|
||||
|
||||
const data = {
|
||||
@@ -338,6 +338,6 @@ export class ActionRowBuilder extends ComponentBuilder<APIActionRowComponent<API
|
||||
|
||||
validate(actionRowPredicate, data, validationOverride);
|
||||
|
||||
return data as APIActionRowComponent<APIActionRowComponentTypes>;
|
||||
return data as APIActionRowComponent<APIComponentInActionRow>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { JSONEncodable } from '@discordjs/util';
|
||||
import type { APIActionRowComponent, APIActionRowComponentTypes } from 'discord-api-types/v10';
|
||||
import type { APIActionRowComponent, APIComponentInActionRow } from 'discord-api-types/v10';
|
||||
|
||||
/**
|
||||
* Any action row component data represented as an object.
|
||||
*/
|
||||
export type AnyAPIActionRowComponent = APIActionRowComponent<APIActionRowComponentTypes> | APIActionRowComponentTypes;
|
||||
export type AnyAPIActionRowComponent = APIActionRowComponent<APIComponentInActionRow> | APIComponentInActionRow;
|
||||
|
||||
/**
|
||||
* The base component builder that contains common symbols for all sorts of components.
|
||||
|
||||
@@ -144,6 +144,36 @@ export function createComponentBuilder(
|
||||
return new MentionableSelectMenuBuilder(data);
|
||||
case ComponentType.ChannelSelect:
|
||||
return new ChannelSelectMenuBuilder(data);
|
||||
|
||||
// Will be handled later
|
||||
case ComponentType.Section: {
|
||||
throw new Error('Not implemented yet: ComponentType.Section case');
|
||||
}
|
||||
|
||||
case ComponentType.TextDisplay: {
|
||||
throw new Error('Not implemented yet: ComponentType.TextDisplay case');
|
||||
}
|
||||
|
||||
case ComponentType.Thumbnail: {
|
||||
throw new Error('Not implemented yet: ComponentType.Thumbnail case');
|
||||
}
|
||||
|
||||
case ComponentType.MediaGallery: {
|
||||
throw new Error('Not implemented yet: ComponentType.MediaGallery case');
|
||||
}
|
||||
|
||||
case ComponentType.File: {
|
||||
throw new Error('Not implemented yet: ComponentType.File case');
|
||||
}
|
||||
|
||||
case ComponentType.Separator: {
|
||||
throw new Error('Not implemented yet: ComponentType.Separator case');
|
||||
}
|
||||
|
||||
case ComponentType.Container: {
|
||||
throw new Error('Not implemented yet: ComponentType.Container case');
|
||||
}
|
||||
|
||||
default:
|
||||
// @ts-expect-error This case can still occur if we get a newer unsupported component type
|
||||
throw new Error(`Cannot properly serialize component type: ${data.type}`);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import type { JSONEncodable } from '@discordjs/util';
|
||||
import type {
|
||||
APIActionRowComponent,
|
||||
APIModalActionRowComponent,
|
||||
APIComponentInModalActionRow,
|
||||
APIModalInteractionResponseCallbackData,
|
||||
} from 'discord-api-types/v10';
|
||||
import { ActionRowBuilder } from '../../components/ActionRow.js';
|
||||
@@ -73,7 +73,7 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
|
||||
public addActionRows(
|
||||
...components: RestOrArray<
|
||||
| ActionRowBuilder
|
||||
| APIActionRowComponent<APIModalActionRowComponent>
|
||||
| APIActionRowComponent<APIComponentInModalActionRow>
|
||||
| ((builder: ActionRowBuilder) => ActionRowBuilder)
|
||||
>
|
||||
) {
|
||||
@@ -93,7 +93,7 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
|
||||
public setActionRows(
|
||||
...components: RestOrArray<
|
||||
| ActionRowBuilder
|
||||
| APIActionRowComponent<APIModalActionRowComponent>
|
||||
| APIActionRowComponent<APIComponentInModalActionRow>
|
||||
| ((builder: ActionRowBuilder) => ActionRowBuilder)
|
||||
>
|
||||
) {
|
||||
@@ -137,7 +137,7 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
|
||||
deleteCount: number,
|
||||
...rows: (
|
||||
| ActionRowBuilder
|
||||
| APIActionRowComponent<APIModalActionRowComponent>
|
||||
| APIActionRowComponent<APIComponentInModalActionRow>
|
||||
| ((builder: ActionRowBuilder) => ActionRowBuilder)
|
||||
)[]
|
||||
): this {
|
||||
|
||||
@@ -4,12 +4,13 @@ import type {
|
||||
APIAllowedMentions,
|
||||
APIAttachment,
|
||||
APIEmbed,
|
||||
APIMessageActionRowComponent,
|
||||
APIComponentInMessageActionRow,
|
||||
APIMessageReference,
|
||||
APIPoll,
|
||||
RESTPostAPIChannelMessageJSONBody,
|
||||
Snowflake,
|
||||
MessageFlags,
|
||||
APIComponentInActionRow,
|
||||
} from 'discord-api-types/v10';
|
||||
import { ActionRowBuilder } from '../components/ActionRow.js';
|
||||
import { normalizeArray, type RestOrArray } from '../util/normalizeArray.js';
|
||||
@@ -76,7 +77,10 @@ export class MessageBuilder implements JSONEncodable<RESTPostAPIChannelMessageJS
|
||||
attachments: data.attachments?.map((attachment) => new AttachmentBuilder(attachment)) ?? [],
|
||||
embeds: data.embeds?.map((embed) => new EmbedBuilder(embed)) ?? [],
|
||||
poll: data.poll ? new PollBuilder(data.poll) : undefined,
|
||||
components: data.components?.map((component) => new ActionRowBuilder(component)) ?? [],
|
||||
components:
|
||||
data.components?.map(
|
||||
(component) => new ActionRowBuilder(component as unknown as APIActionRowComponent<APIComponentInActionRow>),
|
||||
) ?? [],
|
||||
message_reference: data.message_reference ? new MessageReferenceBuilder(data.message_reference) : undefined,
|
||||
};
|
||||
}
|
||||
@@ -271,7 +275,7 @@ export class MessageBuilder implements JSONEncodable<RESTPostAPIChannelMessageJS
|
||||
public addComponents(
|
||||
...components: RestOrArray<
|
||||
| ActionRowBuilder
|
||||
| APIActionRowComponent<APIMessageActionRowComponent>
|
||||
| APIActionRowComponent<APIComponentInMessageActionRow>
|
||||
| ((builder: ActionRowBuilder) => ActionRowBuilder)
|
||||
>
|
||||
): this {
|
||||
@@ -316,7 +320,7 @@ export class MessageBuilder implements JSONEncodable<RESTPostAPIChannelMessageJS
|
||||
deleteCount: number,
|
||||
...components: RestOrArray<
|
||||
| ActionRowBuilder
|
||||
| APIActionRowComponent<APIMessageActionRowComponent>
|
||||
| APIActionRowComponent<APIComponentInMessageActionRow>
|
||||
| ((builder: ActionRowBuilder) => ActionRowBuilder)
|
||||
>
|
||||
): this {
|
||||
@@ -335,7 +339,7 @@ export class MessageBuilder implements JSONEncodable<RESTPostAPIChannelMessageJS
|
||||
public setComponents(
|
||||
...components: RestOrArray<
|
||||
| ActionRowBuilder
|
||||
| APIActionRowComponent<APIMessageActionRowComponent>
|
||||
| APIActionRowComponent<APIComponentInMessageActionRow>
|
||||
| ((builder: ActionRowBuilder) => ActionRowBuilder)
|
||||
>
|
||||
): this {
|
||||
|
||||
Reference in New Issue
Block a user