discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.44k stars 3.97k forks source link

refactor(PermissionOverwrites)!: cache-independent resolve #10528

Open Renegade334 opened 1 month ago

Renegade334 commented 1 month ago

Please describe the changes this PR makes and why it should be merged:

Resolves #10450.

The linked issue relates to the current cache-dependent behaviour of PermissionOverwrites.resolve(), specifically that passing identical parameters to .resolve() can conditionally pass or fail validation depending on the state of the cache.

This isn't ideal, and the function would be better placed resolving the target via .resolveId() in a cache-independent manner.

This approach doesn't allow for overwrite.type to be optional if overwrite.id is a Snowflake, since it would no longer attempt to seek the respective member/role object from the cache to identify it as one or the other. There are two options for how to handle this:

  1. always enforce overwrite.type as mandatory, even if overwrite.id is a member object or role object;
  2. keep overwrite.type as optional if overwrite.id is a member object or role object (current behaviour), but enforce it as mandatory if overwrite.id is a Snowflake.

This PR implements the latter approach. It validates overwrite.id and overwrite.type as GuildMemberResolvable|RoleResolvable and OverwriteType|undefined respectively, then:

The same cache-dependent type behaviour is also present on PermissionOverwriteManager#upsert(), and the behaviour of PermissionOverwriteManager#edit() is also seemingly unnecessarily cache-dependent. Think these should also be updated, but will wait for feedback on the PR so far.

Status and versioning classification:

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **discord-js** | ⬜️ Ignored ([Inspect](https://vercel.com/discordjs/discord-js/5ib8by1xZspieuFBL1ugEcmnKtMd)) | [Visit Preview](https://discord-js-git-fork-renegade334-permissionover-dfbfb2-discordjs.vercel.app) | | Oct 1, 2024 10:49pm | | **discord-js-guide** | ⬜️ Ignored ([Inspect](https://vercel.com/discordjs/discord-js-guide/EZWa9fXneUqsZUnQQZS8ubQeaXjq)) | [Visit Preview](https://discord-js-guide-git-fork-renegade334-permissi-ee9f81-discordjs.vercel.app) | | Oct 1, 2024 10:49pm |
Renegade334 commented 4 days ago

If this approach is kosher, then just wanted to check the following: