You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
plugin-gateway: add ClientApplication and client.application (discord.js parity) #208
@wolfstar/plugin-gateway has no Application/ClientApplication structure, so there is no client.application. In discord.js it is the entry point for everything owned by the application rather than by a guild, and #207 (ApplicationEmoji, ApplicationCommand and their managers) cannot land without it. This issue tracks the structure on its own, as the prerequisite of #207.
Proposal
Application base and ClientApplication, like discord.js:
ClientApplication: flags, tags, installParams, integrationTypesConfig, customInstallURL, owner (user or team), botPublic, botRequireCodeGrant, guildId/guild, approximateGuildCount, approximateUserInstallCount, interactionsEndpointURL, roleConnectionsVerificationURL, eventWebhooksURL/eventWebhooksStatus/eventWebhooksTypes, and partial.
client.application. Decide where it comes from:
the READY payload carries a partial application (id and flags), which is what discord.js starts from;
the client already knows its clientId from the options, so a partial ClientApplication could exist before READY, or without a gateway connection at all.
Methods.fetch() (GET /applications/@me), edit() (PATCH /applications/@me), fetchRoleConnectionMetadataRecords() and editRoleConnectionMetadataRecords().
Cache. The application is a single object per client: decide whether it lives on the client like discord.js, or goes through @wolfstar/plugin-cache so that every process of a sharded or brokered deployment sees the same data.
Questions
Team and TeamMember are needed for owner when the application belongs to a team. Port them here, or expose the raw owner first?
Does @wolfstar/http-framework already expose application data (ID, public key) that this should reuse instead of duplicating?
Is a partial client.application available before READY acceptable, given clientId is a required option?
Out of scope
The managers and structures of #207, entitlements and SKUs, and interaction structures.
Actionable, and a good prerequisite split from #207. Nothing exists yet: READY (packages/plugin-gateway/src/util/dispatch.ts:151) builds client.user and drops data.application, and GatewayClient has no application field. ApplicationFlagsBitField already exists in util/flags.ts, @discordjs/core covers every route needed (api.applications.getCurrent and editCurrent, plus the role connection metadata API), and @wolfstar/http-framework's Client already exposes id (see the client.id fallback in the USER_UPDATE handler).
Proposed design
1. Structures (new src/structures/applications/, exported from structures/index.ts)
Application<Data> extends Structure, in the shape of AnonymousGuild: id, name, description, icon, iconURL(), coverURL(), createdTimestamp/createdAt, toString(). CDN URLs go through util/cdn.ts (appIcon for both, as discord.js does; to confirm against @discordjs/rest).
ClientApplication extends Application: the getters listed in the issue, typed from APIApplication. flags is an ApplicationFlagsBitField. partial is true while name is absent.
Data type: Pick<APIApplication, "id"> & Partial<Omit<APIApplication, "id">>, so the same class holds the { id } seed, the READY payload (id and flags) and a full GET /applications/@me.
Methods follow the repo's two-line edit() shape (await this.client.api…; return this[kPatch](data)): fetch(), edit(), fetchRoleConnectionMetadataRecords(), editRoleConnectionMetadataRecords(). edit() options resolve icon and coverImage through resolveImageOption, as ClientUser#edit does.
2. Where client.application comes from
Create new ClientApplication({ id: this.id }) in the GatewayClient constructor. It exists before READY and without a gateway connection, which answers question 3: yes, acceptable. clientId is required, so client.application is typed non-null (discord.js types it nullable). That is a deliberate, superset-compatible deviation and should be documented.
READY patches the same instance in place (client.application[kPatch](data.application)) instead of replacing it, so references held by user code stay valid.
This also works for broker workers that replay dispatches without ever seeing READY themselves.
READY has no before hook, so no DispatchStateCodecs entry is needed. tests/dispatch-state.test.ts only requires one for handlers that define before.
3. Cache (point 5)
Recommend keeping it on the client, like discord.js and like client.user, and not adding a plugin-cache entity.
It is one tiny object per client. It has no gateway update event, and each process gets the same READY payload anyway.
A new store would mean a plugin-cache change and changeset, a READY op, a codec and StructureStoreAdapter wiring, all for a value that fetch() can refresh.
Revisit only if cross-process freshness of fetch()/edit() results turns out to matter.
4. Team / TeamMember (question 1)
Recommend porting a small Team and TeamMember here, so owner is a typed User | Team | null and not a raw union. They are small (APITeam plus members) and teamIcon is available in the CDN helper.
Fall back to exposing the raw APITeam if it grows. Team can't be a standalone issue because owner depends on it.
A User owner goes through client.users._build (not new User) so it binds the client.
This is the same non-cached, REST-only approach recorded for application emojis and commands in the repo notes.
6. http-framework overlap (question 2)
Reuse client.id as the application ID.
I did not verify whether the framework exposes the public key, so check its .d.ts first. Otherwise verify_key comes from fetch() and is not duplicated.
Activity
pullfrog commentedon Oct 5, 2026
Assessment
Actionable, and a good prerequisite split from #207. Nothing exists yet:
READY(packages/plugin-gateway/src/util/dispatch.ts:151) buildsclient.userand dropsdata.application, andGatewayClienthas noapplicationfield.ApplicationFlagsBitFieldalready exists inutil/flags.ts,@discordjs/corecovers every route needed (api.applications.getCurrentandeditCurrent, plus the role connection metadata API), and@wolfstar/http-framework'sClientalready exposesid(see theclient.idfallback in theUSER_UPDATEhandler).Proposed design
1. Structures (new
src/structures/applications/, exported fromstructures/index.ts)Application<Data>extendsStructure, in the shape ofAnonymousGuild:id,name,description,icon,iconURL(),coverURL(),createdTimestamp/createdAt,toString(). CDN URLs go throughutil/cdn.ts(appIconfor both, as discord.js does; to confirm against@discordjs/rest).ClientApplication extends Application: the getters listed in the issue, typed fromAPIApplication.flagsis anApplicationFlagsBitField.partialis true whilenameis absent.Pick<APIApplication, "id"> & Partial<Omit<APIApplication, "id">>, so the same class holds the{ id }seed, theREADYpayload (idandflags) and a fullGET /applications/@me.edit()shape (await this.client.api…; return this[kPatch](data)):fetch(),edit(),fetchRoleConnectionMetadataRecords(),editRoleConnectionMetadataRecords().edit()options resolveiconandcoverImagethroughresolveImageOption, asClientUser#editdoes.2. Where
client.applicationcomes fromnew ClientApplication({ id: this.id })in theGatewayClientconstructor. It exists beforeREADYand without a gateway connection, which answers question 3: yes, acceptable.clientIdis required, soclient.applicationis typed non-null (discord.js types it nullable). That is a deliberate, superset-compatible deviation and should be documented.READYpatches the same instance in place (client.application[kPatch](data.application)) instead of replacing it, so references held by user code stay valid.READYthemselves.READYhas nobeforehook, so noDispatchStateCodecsentry is needed.tests/dispatch-state.test.tsonly requires one for handlers that definebefore.3. Cache (point 5)
client.user, and not adding aplugin-cacheentity.READYpayload anyway.plugin-cachechange and changeset, aREADYop, a codec andStructureStoreAdapterwiring, all for a value thatfetch()can refresh.fetch()/edit()results turns out to matter.4.
Team/TeamMember(question 1)TeamandTeamMemberhere, soowneris a typedUser | Team | nulland not a raw union. They are small (APITeamplus members) andteamIconis available in the CDN helper.APITeamif it grows.Teamcan't be a standalone issue becauseownerdepends on it.Userowner goes throughclient.users._build(notnew User) so it binds the client.5. Manager slots (point 4)
commands/emojis/entitlementsproperties now, since placeholders would be dead public API. State the contract in docs instead: plugin-gateway: port ApplicationEmoji (with its manager) and ApplicationCommand (discord.js parity) #207 and the entitlements work add the getters onClientApplication(each a plainBaseManager, likeWebhookManager).6. http-framework overlap (question 2)
client.idas the application ID..d.tsfirst. Otherwiseverify_keycomes fromfetch()and is not duplicated.ApplicationCommandRegistry.pushGlobalCommands()vs a futurecommands.set(), which belongs in plugin-gateway: port ApplicationEmoji (with its manager) and ApplicationCommand (discord.js parity) #207.Work breakdown
Application,ClientApplication,Team,TeamMemberstructures, plus exports andGatewayClient#applicationwith theREADYpatch.fetch,editand the role connection metadata methods, with typed options.tests/applications.test.tsand the style ofwebhooks.test.ts/client-ready.test.ts:READYREADYpatchfetchandeditagainst a mocked RESTpartialtests/types/minorchangeset for@wolfstar/plugin-gateway, then the quality gates:pnpm lint,pnpm build,pnpm typecheck,pnpm test.Open points for the author
client.application(vs discord.js's nullable).Team/TeamMembership in this issue.I haven't started implementation. Say the word (or answer the open points) and I'll proceed.
claude-sonnet-5-5| 𝕏