Repository navigation
feat(plugin-gateway): add discord.js serializers (Transformers, DataResolver, Util) - #158
Conversation
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This PR ports discord.js's Transformers, DataResolver, and Util serializers into plugin-gateway, continuing the discord.js-parity series (#151, #152, #154, #156, #157).
util/Transformers.ts(new, 934 lines):toSnakeCase/snakeCaseplustransformAPI*/transform*pairs converting between raw snake_case API payloads and camelCased objects for auto-moderation triggers/actions, forum tags/default reactions, scheduled-event recurrence rules/entity metadata, incidents data, role tags, audit-log changes, avatar decorations/collectibles/primary guilds, and several message-related sub-objects (references, activities, calls, role subscriptions, crossposted channels, interaction metadata) and embed assets/author/footer.util/DataResolver.ts(new):resolveFile(moved out ofMessagePayloadto be shared),resolveBase64,resolveImage/resolveImageOption, andresolveInviteCode/resolveGuildTemplateCodewith their matching URL patterns, also exposed as statics onBaseInvite/GuildTemplate.util/Util.tsadditions:flatten,cleanContent,cleanCodeBlockContent,parseWebhookURL,verifyString,discordSort,moveElementInArray,getSortableGroupTypes,makeError/makePlainError,basename,findName,resolveSKUId.- Consumer updates across managers/structures: getters that used to return raw snake_case objects (auto-mod triggers/actions, forum tags, scheduled-event recurrence rule, incidents data, role tags, user/member avatar decoration & collectibles & primary guild, message reference/activity/call/interaction-metadata/role-subscription, crossposted channels, audit-log changes, embed assets) now return camelCased, transformed objects — documented as breaking in the changeset. Option-taking methods (guild/role/emoji/webhook/soundboard/template edits, auto-mod triggers/actions, scheduled-event recurrence rule) now accept either camelCased or raw shapes, and image-accepting options take paths/URLs/streams/blobs/bytes in addition to data URIs via the new
resolveImage/resolveFile. Message#messageSnapshotsnow returns realMessagestructures reconstructed frommessage_snapshots, filling inid/channelId/guildIdfrom the message's ownmessage_referencesince the raw snapshot payload doesn't carry them.
I read the full diff (38 files) and traced the null/undefined round-tripping in several option builders (e.g. GuildScheduledEventManager.toEventBody's recurrence_rule, AutoModerationRule#editTrigger's merge) — the value && transform(value) pattern correctly preserves "explicit null clears the field, undefined leaves it untouched" semantics, since && short-circuits and returns null unchanged. The extensive camelCase↔snake_case mapping is consistently applied and well covered by the new tests/serializers.test.ts suite (round-trip tests for most transformer pairs, plus DataResolver/Util coverage including path/stream/blob resolution). resolveFile's JSDoc already documents the SSRF-adjacent caveat about fetching user-supplied URLs, so that's not a gap.
No correctness issues found in this pass.
Claude Sonnet | 𝕏

🔗 Linked issue
N/A: continues the discord.js parity work in
plugin-gateway(#151, #152, #154, #156, #157).🧭 Context
discord.js serializes API payloads in both directions.
Transformers.js, the transformers inChannels.js, and each structure's_patchturn snake_case payloads into camelCase objects.DataResolver.jsresolves files, images, and invite/template codes, andUtil.jsholds the public helpers.plugin-gatewayhad almost none of this. Its getters returned raw API objects, image options only took data URIs, and invite/template codes were pulled out of URLs withsplit("/").📚 Description
This adds the missing serializers and uses them in the structures and managers.
util/Transformers.ts:toSnakeCaseplus atransformAPI*/transform*pair for:util/DataResolver.ts:resolveFile(moved out ofMessagePayload),resolveBase64,resolveImage,resolveInviteCode,resolveGuildTemplateCode, andInvitesPattern/GuildTemplatesPattern, which are also static onBaseInvite/GuildTemplatelike in discord.js.util/Util.ts:flatten,cleanContent,cleanCodeBlockContent,parseWebhookURL,verifyString,discordSort,moveElementInArray,getSortableGroupTypes,makeError/makePlainError,basename,findName,resolveSKUId. This builds on theparseEmoji/resolvePartialEmojifrom feat(plugin-gateway): add parseEmoji and resolvePartialEmoji utils #157.Deliberately not ported:
transformResolved: interactions are out of scope.resolveGuildEmoji: needs a sync cache. For the same reason,cleanContenttakes the names as a parameter instead of reading the cache.fetchRecommendedShardCount: belongs to sharding.Key changes
toJSON()is still raw)Message#messageSnapshotsMessagestructures carrying the forwarded IDscontentTypeoptionsplit("/")resolveInviteCode/resolveGuildTemplateCodeGuildScheduledEvent#entityMetadata,GuildMember#collectiblesBreaking: these getters now return camelCase objects:
AutoModerationRule#triggerMetadataand#actions,AutoModerationActionExecution#actionavailableTagsanddefaultReactionEmojion forum and media channelsGuildScheduledEvent#recurrenceRuleGuild#incidentsData, and the result ofsetIncidentActionsUser#avatarDecorationData,#collectibles,#primaryGuild, andGuildMember#avatarDecorationDataRole#tags(boolean tags becometrue)Message#reference,#activity,#interactionMetadata,#call,#roleSubscriptionDataMessageMentions#crosspostedChannelsGuildAuditLogsEntry#changes(old/new)Embed#thumbnail,#image,#video,#author,#footerThe changeset is
minorbecause the package is still 0.x.Type of Change
Pre-flight Checklist
pnpm changeset(orpnpm changeset add --emptyif no release is needed). See .changeset/README.md.