Skip to content

feat(plugin-gateway): add component structures like discord.js - #151

Merged
kodiakhq[bot] merged 2 commits into
mainfrom
t3code/add-serialized-message-components
Sep 28, 2026
Merged

kodiakhq[bot] merged 2 commits into
mainfrom
t3code/add-serialized-message-components

Conversation

@RedStar071

Copy link
Copy Markdown
Member

🔗 Linked issue

N/A

🧭 Context

Message#components returned the raw API data, while discord.js wraps received components in structures (ActionRow, Component, createComponent in util/Components.js). This brings the same thing to @wolfstar/plugin-gateway, for every component type, modal ones included.

📚 Description

Each component type gets its own class under src/structures/components/. Where @discordjs/structures already has a base class, the new class extends it and mixes in StructureMixin, the same pattern the channels use. Label, radio group, checkbox group and checkbox have no upstream base, so they extend the new Component directly.

Raw data is stored as received, so toJSON() gives back the full tree, nested components included. That also means the structures can be passed straight back to send/edit through MessagePayload. Nested children (components, accessory, component, items, media, file) are built on access, like Message#embeds, so they always reflect kPatch.

createComponent() picks the class for a raw component. It is typed through ComponentOf<Data>, and types it doesn't know (e.g. ContentInventoryEntry) fall back to a plain Component. It uses a switch instead of a lookup table to avoid a circular-import TDZ.

Key changes

Before After
Message#components raw APIMessageTopLevelComponent[] MessageTopLevelComponent[] structures (toJSON() for raw)
Component classes none Component, ActionRow, 3 buttons (interactive/link/premium), 5 select menus, TextInputComponent, ContainerComponent, SectionComponent, TextDisplayComponent, ThumbnailComponent, MediaGalleryComponent + MediaGalleryItem + UnfurledMediaItem, FileComponent, SeparatorComponent, LabelComponent, FileUploadComponent, RadioGroupComponent, CheckboxGroupComponent, CheckboxComponent
Helpers none createComponent(), findComponentByCustomId(), unions (ButtonComponent, SelectMenuComponent, ComponentInContainer, …)

Default values follow discord.js: disabled is false, spacing is Small, divider is true, spoiler is false, and accentColor is null. One difference: buttons follow the per-style split from @discordjs/structures instead of discord.js' single ButtonComponent class, which exists here only as a union type.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation change
  • Workflow / CI change

Pre-flight Checklist

  • I have read the Contributing Guidelines (if applicable)
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly
  • I added a changeset with pnpm changeset (or pnpm changeset add --empty if no release is needed). See .changeset/README.md.

Add one structure per component type, a createComponent factory, and
findComponentByCustomId. Message#components now returns the structures.
@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

◈ PR Lens

PR Lens could not render b073260: the analysis run did not complete. Push a new commit to try again.

@wolfstarbot wolfstarbot added the packages:plugin-gateway Changes in plugin-gateway label Sep 28, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

One getter returns a default that doesn't match Discord's actual documented behavior — see inline comment.

Reviewed changes

Reviewed the full diff: 32 files adding discord.js-style component wrapper structures to @wolfstar/plugin-gateway.

  • New component structures: one class per Discord component type under src/structures/components/ (ActionRow, three button styles, five select menus, TextInputComponent, ContainerComponent, SectionComponent, TextDisplayComponent, ThumbnailComponent, MediaGalleryComponent/MediaGalleryItem/UnfurledMediaItem, FileComponent, SeparatorComponent, LabelComponent, FileUploadComponent, RadioGroupComponent, CheckboxGroupComponent, CheckboxComponent), each wrapping raw API data and building children lazily on access, the same pattern as Message#embeds.
  • createComponent() / findComponentByCustomId(): util/components.ts adds a switch-based factory (deliberately not a lookup table, to avoid a circular-import TDZ) that picks the matching class for raw component data, plus a tree-walking helper that locates a component by customId through action rows, sections, containers, and labels.
  • Message#components (breaking): now returns the new structures instead of raw API data; toJSON() recovers the raw shape, and built structures can be passed straight back through MessagePayload. A minor changeset documents the break.
  • Tests: tests/components.test.ts covers createComponent dispatch for every component type, nested building/patching/equality on ActionRow, container/section/media-gallery wiring, modal components, and findComponentByCustomId on both built and raw trees.

I verified the field names, enum members, and stated defaults (required ?? true, spacing ?? Small, divider ?? true, disabled ?? false, etc.) against the [email protected] types actually installed in this workspace — all accurate except the one flagged below. I also checked for export * collisions between the new util/components.ts exports and the rest of the package's barrel files — none found.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using Claude Sonnet | 𝕏

@pkg-pr-new

pkg-pr-new Bot commented Sep 28, 2026

Copy link
Copy Markdown

Open in StackBlitz

@wolfstar/plugin-api

pnpm add https://pkg.pr.new/@wolfstar/plugin-api@151

@wolfstar/plugin-broker

pnpm add https://pkg.pr.new/@wolfstar/plugin-broker@151

@wolfstar/plugin-cache

pnpm add https://pkg.pr.new/@wolfstar/plugin-cache@151

@wolfstar/plugin-gateway

pnpm add https://pkg.pr.new/@wolfstar/plugin-gateway@151

@wolfstar/plugin-i18next

pnpm add https://pkg.pr.new/@wolfstar/plugin-i18next@151

@wolfstar/plugin-logger

pnpm add https://pkg.pr.new/@wolfstar/plugin-logger@151

@wolfstar/plugin-sharder

pnpm add https://pkg.pr.new/@wolfstar/plugin-sharder@151

@wolfstar/plugin-subcommands-advanced

pnpm add https://pkg.pr.new/@wolfstar/plugin-subcommands-advanced@151

commit: 01b9f83

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Reviewed the delta since the prior Pullfrog review (b073260 → 01b9f83), a single fixup commit.

  • Fixed CheckboxGroupComponent.minValues/.maxValues defaults: the getters now return 1 and this.options.length respectively when min_values/max_values are absent, matching Discord's documented defaults instead of the previous null.
  • Updated tests/components.test.ts: added a case asserting the new defaults (minValues is 1, maxValues is options.length when omitted) alongside the existing explicit-values case.

This resolves the one finding from the prior review exactly as suggested — verified the getters and the updated test both match the intended behavior.

Pullfrog  | View workflow run | Using Claude Sonnet | 𝕏

@kodiakhq
kodiakhq Bot merged commit 8d75381 into main Sep 28, 2026
17 checks passed
@kodiakhq
kodiakhq Bot deleted the t3code/add-serialized-message-components branch September 28, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages:plugin-gateway Changes in plugin-gateway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants