Skip to content

docs: add missing, fix existing #10842

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

Merged
merged 7 commits into from
Jun 2, 2025
Merged
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
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export default tseslint.config(
files: [`packages/builders/**/*${commonFiles}`],
rules: {
'@typescript-eslint/no-empty-object-type': 0,
'jsdoc/valid-types': 0,
},
},
{
Expand Down
18 changes: 10 additions & 8 deletions packages/builders/src/components/ActionRow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable jsdoc/check-param-names */

import type {
APITextInputComponent,
APIActionRowComponent,
Expand Down Expand Up @@ -43,10 +41,11 @@ export interface ActionRowBuilderData

/**
* A builder that creates API-compatible JSON data for action rows.
*
* @typeParam ComponentType - The types of components this action row holds
*/
export class ActionRowBuilder extends ComponentBuilder<APIActionRowComponent<APIComponentInActionRow>> {
/**
* @internal
*/
protected readonly data: ActionRowBuilderData;

/**
Expand All @@ -57,7 +56,7 @@ export class ActionRowBuilder extends ComponentBuilder<APIActionRowComponent<API
}

/**
* Creates a new action row from API data.
* Creates a new action row.
*
* @param data - The API data to create this action row with
* @example
Expand Down Expand Up @@ -90,12 +89,15 @@ export class ActionRowBuilder extends ComponentBuilder<APIActionRowComponent<API
* .addComponents(button2, button3);
* ```
*/
public constructor({ components = [], ...data }: Partial<APIActionRowComponent<APIComponentInActionRow>> = {}) {
public constructor(data: Partial<APIActionRowComponent<APIComponentInActionRow>> = {}) {
super();

const { components = [], ...rest } = data;

this.data = {
...structuredClone(data),
type: ComponentType.ActionRow,
...structuredClone(rest),
components: components.map((component) => createComponentBuilder(component)),
type: ComponentType.ActionRow,
};
}

Expand Down
3 changes: 3 additions & 0 deletions packages/builders/src/components/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export interface ComponentBuilderBaseData {
export abstract class ComponentBuilder<Component extends APIBaseComponent<ComponentType>>
implements JSONEncodable<Component>
{
/**
* @internal
*/
protected abstract readonly data: ComponentBuilderBaseData;

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/builders/src/components/button/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { ComponentBuilder } from '../Component.js';
* A builder that creates API-compatible JSON data for buttons.
*/
export abstract class BaseButtonBuilder<ButtonData extends APIButtonComponent> extends ComponentBuilder<ButtonData> {
/**
* @internal
*/
declare protected readonly data: Partial<ButtonData>;

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/builders/src/components/button/CustomIdButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export type CustomIdButtonStyle = APIButtonComponentWithCustomId['style'];

/**
* A builder that creates API-compatible JSON data for buttons with custom IDs.
*
* @mixes {@link BaseButtonBuilder}\<{@link discord-api-types/v10#(APIButtonComponentWithCustomId:interface)}\>
* @mixes {@link EmojiOrLabelButtonMixin}
*/
export abstract class CustomIdButtonBuilder extends Mixin(
BaseButtonBuilder<APIButtonComponentWithCustomId>,
Expand Down
3 changes: 3 additions & 0 deletions packages/builders/src/components/button/LinkButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { EmojiOrLabelButtonMixin } from './mixins/EmojiOrLabelButtonMixin.js';

/**
* A builder that creates API-compatible JSON data for buttons with links.
*
* @mixes {@link BaseButtonBuilder}\<{@link discord-api-types/v10#(APIButtonComponentWithURL:interface)}\>
* @mixes {@link EmojiOrLabelButtonMixin}
*/
export class LinkButtonBuilder extends Mixin(BaseButtonBuilder<APIButtonComponentWithURL>, EmojiOrLabelButtonMixin) {
protected override readonly data: Partial<APIButtonComponentWithURL>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import type { APIButtonComponent, APIButtonComponentWithSKUId, APIMessageCompone
export interface EmojiOrLabelButtonData
extends Pick<Exclude<APIButtonComponent, APIButtonComponentWithSKUId>, 'emoji' | 'label'> {}

/**
* A mixin that adds emoji and label symbols to a button builder.
*/
export class EmojiOrLabelButtonMixin {
/**
* @internal
*/
declare protected readonly data: EmojiOrLabelButtonData;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import { ComponentBuilder } from '../Component.js';
/**
* The base select menu builder that contains common symbols for select menu builders.
*
* @typeParam SelectMenuType - The type of select menu this would be instantiated for.
* @typeParam Data - The type of API data that is stored within the builder
*/
export abstract class BaseSelectMenuBuilder<Data extends APISelectMenuComponent>
extends ComponentBuilder<Data>
implements JSONEncodable<APISelectMenuComponent>
{
/**
* @internal
*/
protected abstract override readonly data: Partial<
Pick<Data, 'custom_id' | 'disabled' | 'id' | 'max_values' | 'min_values' | 'placeholder'>
>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export class ChannelSelectMenuBuilder extends BaseSelectMenuBuilder<APIChannelSe
protected override readonly data: Partial<APIChannelSelectComponent>;

/**
* Creates a new select menu from API data.
* Creates a new channel select menu.
*
* @param data - The API data to create this select menu with
* @param data - The API data to create this channel select menu with
* @example
* Creating a select menu from an API data object:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export class MentionableSelectMenuBuilder extends BaseSelectMenuBuilder<APIMenti
protected override readonly data: Partial<APIMentionableSelectComponent>;

/**
* Creates a new select menu from API data.
* Creates a new mentionable select menu.
*
* @param data - The API data to create this select menu with
* @param data - The API data to create this mentionable select menu with
* @example
* Creating a select menu from an API data object:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export class RoleSelectMenuBuilder extends BaseSelectMenuBuilder<APIRoleSelectCo
protected override readonly data: Partial<APIRoleSelectComponent>;

/**
* Creates a new select menu from API data.
* Creates a new role select menu.
*
* @param data - The API data to create this select menu with
* @param data - The API data to create this role select menu with
* @example
* Creating a select menu from an API data object:
* ```ts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable jsdoc/check-param-names */

import { ComponentType } from 'discord-api-types/v10';
import type { APIStringSelectComponent, APISelectMenuOption } from 'discord-api-types/v10';
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';
Expand Down Expand Up @@ -27,9 +25,9 @@ export class StringSelectMenuBuilder extends BaseSelectMenuBuilder<APIStringSele
}

/**
* Creates a new select menu from API data.
* Creates a new string select menu.
*
* @param data - The API data to create this select menu with
* @param data - The API data to create this string select menu with
* @example
* Creating a select menu from an API data object:
* ```ts
Expand Down Expand Up @@ -57,10 +55,13 @@ export class StringSelectMenuBuilder extends BaseSelectMenuBuilder<APIStringSele
* });
* ```
*/
public constructor({ options = [], ...data }: Partial<APIStringSelectComponent> = {}) {
public constructor(data: Partial<APIStringSelectComponent> = {}) {
super();

const { options = [], ...rest } = data;

this.data = {
...structuredClone(data),
...structuredClone(rest),
options: options.map((option) => new StringSelectMenuOptionBuilder(option)),
type: ComponentType.StringSelect,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class StringSelectMenuOptionBuilder implements JSONEncodable<APISelectMen
private readonly data: Partial<APISelectMenuOption>;

/**
* Creates a new string select menu option from API data.
* Creates a new string select menu option.
*
* @param data - The API data to create this string select menu option with
* @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export class UserSelectMenuBuilder extends BaseSelectMenuBuilder<APIUserSelectCo
protected override readonly data: Partial<APIUserSelectComponent>;

/**
* Creates a new select menu from API data.
* Creates a new user select menu.
*
* @param data - The API data to create this select menu with
* @param data - The API data to create this user select menu with
* @example
* Creating a select menu from an API data object:
* ```ts
Expand Down
5 changes: 4 additions & 1 deletion packages/builders/src/components/textInput/TextInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import { textInputPredicate } from './Assertions.js';
* A builder that creates API-compatible JSON data for text inputs.
*/
export class TextInputBuilder extends ComponentBuilder<APITextInputComponent> {
/**
* @internal
*/
protected readonly data: Partial<APITextInputComponent>;

/**
* Creates a new text input from API data.
* Creates a new text input.
*
* @param data - The API data to create this text input with
* @example
Expand Down
23 changes: 22 additions & 1 deletion packages/builders/src/components/v2/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,32 @@ export interface ContainerBuilderData extends Partial<Omit<APIContainerComponent
components: ContainerComponentBuilders[];
}

/**
* A builder that creates API-compatible JSON data for containers.
*/
export class ContainerBuilder extends ComponentBuilder<APIContainerComponent> {
/**
* @internal
*/
protected readonly data: ContainerBuilderData;

public constructor({ components = [], ...rest }: Partial<APIContainerComponent> = {}) {
/**
* Gets the components within this container.
*/
public get components(): readonly ContainerComponentBuilders[] {
return this.data.components;
}

/**
* Creates a new container builder.
*
* @param data - The API data to create the container with
*/
public constructor(data: Partial<APIContainerComponent> = {}) {
super();

const { components = [], ...rest } = data;

this.data = {
...structuredClone(rest),
components: components.map((component) => createComponentBuilder(component)),
Expand Down
15 changes: 12 additions & 3 deletions packages/builders/src/components/v2/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ import { validate } from '../../util/validation.js';
import { ComponentBuilder } from '../Component.js';
import { filePredicate } from './Assertions.js';

/**
* A builder that creates API-compatible JSON data for files.
*/
export class FileBuilder extends ComponentBuilder<APIFileComponent> {
/**
* @internal
*/
protected readonly data: Partial<APIFileComponent>;

/**
* Creates a new file from API data.
* Creates a new file.
*
* @param data - The API data to create this file with
* @example
Expand All @@ -33,9 +39,12 @@ export class FileBuilder extends ComponentBuilder<APIFileComponent> {
*/
public constructor(data: Partial<APIFileComponent> = {}) {
super();

const { file, ...rest } = data;

this.data = {
...structuredClone(data),
file: data.file ? { url: data.file.url } : undefined,
...structuredClone(rest),
file: file && { url: file.url },
type: ComponentType.File,
};
}
Expand Down
28 changes: 19 additions & 9 deletions packages/builders/src/components/v2/MediaGallery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,24 @@ export interface MediaGalleryBuilderData extends Partial<Omit<APIMediaGalleryCom
items: MediaGalleryItemBuilder[];
}

/**
* A builder that creates API-compatible JSON data for media galleries.
*/
export class MediaGalleryBuilder extends ComponentBuilder<APIMediaGalleryComponent> {
/**
* @internal
*/
protected readonly data: MediaGalleryBuilderData;

/**
* Creates a new media gallery from API data.
* The items in this media gallery.
*/
public get items(): readonly MediaGalleryItemBuilder[] {
return this.data.items;
}

/**
* Creates a new media gallery.
*
* @param data - The API data to create this container with
* @example
Expand Down Expand Up @@ -49,19 +62,16 @@ export class MediaGalleryBuilder extends ComponentBuilder<APIMediaGalleryCompone
*/
public constructor(data: Partial<APIMediaGalleryComponent> = {}) {
super();

const { items = [], ...rest } = data;

this.data = {
items: data?.items?.map((item) => new MediaGalleryItemBuilder(item)) ?? [],
...structuredClone(rest),
items: items.map((item) => new MediaGalleryItemBuilder(item)),
type: ComponentType.MediaGallery,
};
}

/**
* The items in this media gallery.
*/
public get items(): readonly MediaGalleryItemBuilder[] {
return this.data.items;
}

/**
* Adds a media gallery item to this media gallery.
*
Expand Down
6 changes: 2 additions & 4 deletions packages/builders/src/components/v2/MediaGalleryItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class MediaGalleryItemBuilder implements JSONEncodable<APIMediaGalleryIte
private readonly data: Partial<APIMediaGalleryItem>;

/**
* Creates a new media gallery item from API data.
* Creates a new media gallery item.
*
* @param data - The API data to create this media gallery item with
* @example
Expand All @@ -32,9 +32,7 @@ export class MediaGalleryItemBuilder implements JSONEncodable<APIMediaGalleryIte
* ```
*/
public constructor(data: Partial<APIMediaGalleryItem> = {}) {
this.data = {
...structuredClone(data),
};
this.data = structuredClone(data);
}

/**
Expand Down
Loading