Repository navigation
feat(plugin-gateway): add component structures like discord.js - #151
Conversation
Add one structure per component type, a createComponent factory, and findComponentByCustomId. Message#components now returns the structures.
◈ PR LensPR Lens could not render |
There was a problem hiding this comment.
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 asMessage#embeds. createComponent()/findComponentByCustomId():util/components.tsadds aswitch-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 bycustomIdthrough 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 throughMessagePayload. Aminorchangeset documents the break.- Tests:
tests/components.test.tscoverscreateComponentdispatch for every component type, nested building/patching/equality onActionRow, container/section/media-gallery wiring, modal components, andfindComponentByCustomIdon 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.
Claude Sonnet | 𝕏
@wolfstar/plugin-api
@wolfstar/plugin-broker
@wolfstar/plugin-cache
@wolfstar/plugin-gateway
@wolfstar/plugin-i18next
@wolfstar/plugin-logger
@wolfstar/plugin-sharder
@wolfstar/plugin-subcommands-advanced
commit: |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior Pullfrog review (b073260 → 01b9f83), a single fixup commit.
- Fixed
CheckboxGroupComponent.minValues/.maxValuesdefaults: the getters now return1andthis.options.lengthrespectively whenmin_values/max_valuesare absent, matching Discord's documented defaults instead of the previousnull. - Updated
tests/components.test.ts: added a case asserting the new defaults (minValuesis1,maxValuesisoptions.lengthwhen 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.
Claude Sonnet | 𝕏

🔗 Linked issue
N/A
🧭 Context
Message#componentsreturned the raw API data, while discord.js wraps received components in structures (ActionRow,Component,createComponentinutil/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/structuresalready has a base class, the new class extends it and mixes inStructureMixin, the same pattern the channels use. Label, radio group, checkbox group and checkbox have no upstream base, so they extend the newComponentdirectly.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 tosend/editthroughMessagePayload. Nested children (components,accessory,component,items,media,file) are built on access, likeMessage#embeds, so they always reflectkPatch.createComponent()picks the class for a raw component. It is typed throughComponentOf<Data>, and types it doesn't know (e.g.ContentInventoryEntry) fall back to a plainComponent. It uses aswitchinstead of a lookup table to avoid a circular-import TDZ.Key changes
Message#componentsAPIMessageTopLevelComponent[]MessageTopLevelComponent[]structures (toJSON()for raw)Component,ActionRow, 3 buttons (interactive/link/premium), 5 select menus,TextInputComponent,ContainerComponent,SectionComponent,TextDisplayComponent,ThumbnailComponent,MediaGalleryComponent+MediaGalleryItem+UnfurledMediaItem,FileComponent,SeparatorComponent,LabelComponent,FileUploadComponent,RadioGroupComponent,CheckboxGroupComponent,CheckboxComponentcreateComponent(),findComponentByCustomId(), unions (ButtonComponent,SelectMenuComponent,ComponentInContainer, …)Default values follow discord.js:
disabledisfalse,spacingisSmall,divideristrue,spoilerisfalse, andaccentColorisnull. One difference: buttons follow the per-style split from@discordjs/structuresinstead of discord.js' singleButtonComponentclass, which exists here only as a union type.Type of Change
Pre-flight Checklist
pnpm changeset(orpnpm changeset add --emptyif no release is needed). See .changeset/README.md.