Repository navigation
feat: resolve gateway structure relations through the cache with _add - #102
Conversation
◈ PR LensPR Lens paused analysis for this repository — the fair-use limit was reached. It resumes automatically at 2026-09-25T18:00:00.000Z. |
There was a problem hiding this comment.
ℹ️ No critical issues — one minor observation inline.
Reviewed changes
Reviewed the full diff porting discord.js's CachedManager#_add/DataManager#resolve pattern to plugin-gateway.
CachedManagergrows_add,hydrate,resolve,resolveData, and an abstractkeyOf:_addshallow-merges an API payload into the cached entry (like_patch) and writes it unlesscache: false;hydratebuilds a structure and resolves its relations from other entity caches;keyOfreplaces the oldArgs-tuple-basedstoreRawkey derivation so relation resolution can derive a cache key from raw data alone.- Every manager's private
storehelper now goes through_add, and managers with relations (GuildEmojiManager,GuildStickerManager,GuildMemberManager,GuildInviteManager,MessageManager) override_add/hydrateto also write/resolve their nested user relation (uploader, member's user, inviter/target user, author/member). - Structures (
Message,GuildMember,GuildEmoji,Sticker,BaseInvite) take an optionalrelationsconstructor param and reset the resolved field in[kPatch]when the raw payload repatches that relation — a deliberate, documented tradeoff (a patch carrying the relation "drops" the earlier resolved one). - Gateway dispatch handlers (
util/dispatch.ts) build structures withhydrateinstead ofcreateStructure, relying onapplyGatewayDispatch(unmodified, in@wolfstar/plugin-cache) having already written the dispatch's cache entries earlier inGatewayClient.handleDispatch. - Webhook message authors are deliberately excluded from
client.usersviacache && !data.webhook_idinMessageManager._add, andhydratebypasses cache resolution for webhook authors entirely — covered by a new test. - New
tests/cached-manager.test.tscovers merge-on-partial-payload,cache: false, no-cache-configured fallback,resolve, message author/member relation resolution, and webhook non-caching.
Verified locally: tsc --noEmit is clean, the full plugin-gateway suite passes (138/138, including the 8 new tests), and oxlint reports 0 issues. Traced applyGatewayDispatch's dispatch-time cache writes (MessageCreate, GuildMemberAdd/Update, etc.) to confirm hydrate's relation lookups see fresh data, and confirmed every CachedManager subclass implements the new abstract keyOf with call sites that can't hit GuildMemberManager.keyOf's userless-member throw.
ℹ️ Nitpicks
GuildEmojiManager/GuildStickerManager's_addwrites the uploader toclient.users, but theGuildEmojisUpdate/GuildStickersUpdategateway path only callshydrate(no_add), so an emoji/sticker uploader is cached toclient.userson REST calls but not on that gateway event. Minor and likely matches how sparse that payload'suserfield already is in practice — not blocking.
Claude Sonnet | 𝕏
@wolfstar/plugin-api
@wolfstar/plugin-cache
@wolfstar/plugin-gateway
@wolfstar/plugin-i18next
@wolfstar/plugin-logger
@wolfstar/plugin-subcommands-advanced
commit: |
a186024 to
d8558bc
Compare
d8558bc to
83e8add
Compare
|
Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an Add repo secret → · Model settings → · Setup docs → · Ask in Discord →
|
83e8add to
88b5ae2
Compare
|
Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an Add repo secret → · Model settings → · Setup docs → · Ask in Discord →
|

Stacked on #101.
🔗 Linked issue
Related to #54.
🧭 Context
Structures built their relations straight from the payload:
message.authorwasnew User(data.author),member.userwasnew User(data.user), and so on. discord.js does it differently. Its managers go throughCachedManager#_add, which patches the cached entry, andmessage.authoris the entry ofclient.users. So a user's latest known data shows up on every message they sent. Qjuh's@discordjs/nextkeeps the same_add, made asynchronous for a pluggable cache.📚 Description
Every manager now has discord.js's
_addandresolve:_add(data, cache = true, { key })shallowly merges the payload into the cached entry, like discord.js's_patch, so fields a partial payload lacks keep their cached value. It writes the result unlesscacheisfalse, then builds the structure. It's asynchronous, since the cache can be Redis. Every REST path that used to write the cache by hand now goes through it.hydrate(data)builds a structure and resolves its relations from the cache.get,fetch,_addand the gateway events all use it, so amessageCreatemessage has the cached author and member.resolve(structureOrKey)works likeDataManager#resolve.resolveData(data)returns the cached structure for a payload, or builds one from it. The relations use it.The resolved relations are
message.author,message.member,member.user,emoji.author,sticker.user,invite.inviterandinvite.targetUser. Managers pass them to the constructor. A structure built by hand (new Message(data)) falls back to the copy in its payload, so structures still don't need a client.Two choices worth a look:
client.users, following discord.js (_add(data.author, !data.webhook_id)). A webhook's author only holds for its own message.message.edit()returns a newauthor. The structure then reads the fresh payload instead of a user resolved earlier.MessageMentions, DM recipients andTypingstill read their payload. They are synchronous getters over embedded lists, and resolving them would make every access asynchronous.no-underscore-danglenow allows_addin plugin-gateway. I kept the name on purpose for discord.js parity. It is@internal, so typedoc leaves it out.Key changes
CachedManager_add,hydrate,resolve,resolveData, abstractkeyOf;storeRawtakes a keystorehelpers go through_add; members, messages, emojis, stickers and invites add their usersMessage,GuildMember,GuildEmoji,Sticker,BaseInvitetake resolved relationshydrateinstead ofcreateStructureType of Change
Pre-flight Checklist
pnpm changeset(orpnpm changeset add --emptyif no release is needed). See .changeset/README.md.