Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: deprecate .deleted getters #7107

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/structures/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const SnowflakeUtil = require('../util/SnowflakeUtil');
* @internal
*/
const deletedChannels = new WeakSet();
let deprecationEmittedForDeleted = false;

/**
* Represents any channel on Discord.
Expand Down Expand Up @@ -67,12 +68,29 @@ class Channel extends Base {
/**
* Whether or not the structure has been deleted
* @type {boolean}
* @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091
*/
get deleted() {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Channel#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

return deletedChannels.has(this);
}

set deleted(value) {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Channel#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

if (value) deletedChannels.add(this);
else deletedChannels.delete(this);
}
Expand Down
18 changes: 18 additions & 0 deletions src/structures/Emoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const SnowflakeUtil = require('../util/SnowflakeUtil');
* @internal
*/
const deletedEmojis = new WeakSet();
let deprecationEmittedForDeleted = false;

/**
* Represents raw emoji data from the API
Expand Down Expand Up @@ -47,12 +48,29 @@ class Emoji extends Base {
/**
* Whether or not the structure has been deleted
* @type {boolean}
* @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091
*/
get deleted() {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Emoji#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

return deletedEmojis.has(this);
}

set deleted(value) {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Emoji#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

if (value) deletedEmojis.add(this);
else deletedEmojis.delete(this);
}
Expand Down
18 changes: 18 additions & 0 deletions src/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const Util = require('../util/Util');

let deprecationEmittedForSetChannelPositions = false;
let deprecationEmittedForSetRolePositions = false;
let deprecationEmittedForDeleted = false;

/**
* @type {WeakSet<Guild>}
Expand Down Expand Up @@ -130,12 +131,29 @@ class Guild extends AnonymousGuild {
/**
* Whether or not the structure has been deleted
* @type {boolean}
* @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091
*/
get deleted() {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Guild#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

return deletedGuilds.has(this);
}

set deleted(value) {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Guild#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

if (value) deletedGuilds.add(this);
else deletedGuilds.delete(this);
}
Expand Down
18 changes: 18 additions & 0 deletions src/structures/GuildMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Permissions = require('../util/Permissions');
* @internal
*/
const deletedGuildMembers = new WeakSet();
let deprecationEmittedForDeleted = false;

/**
* Represents a member of a guild on Discord.
Expand Down Expand Up @@ -93,12 +94,29 @@ class GuildMember extends Base {
/**
* Whether or not the structure has been deleted
* @type {boolean}
* @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091
*/
get deleted() {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'GuildMember#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

return deletedGuildMembers.has(this);
}

set deleted(value) {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'GuildMember#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

if (value) deletedGuildMembers.add(this);
else deletedGuildMembers.delete(this);
}
Expand Down
18 changes: 18 additions & 0 deletions src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const Util = require('../util/Util');
* @internal
*/
const deletedMessages = new WeakSet();
let deprecationEmittedForDeleted = false;

/**
* Represents a message on Discord.
Expand Down Expand Up @@ -352,12 +353,29 @@ class Message extends Base {
/**
* Whether or not the structure has been deleted
* @type {boolean}
* @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091
*/
get deleted() {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Message#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

return deletedMessages.has(this);
}

set deleted(value) {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Message#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

if (value) deletedMessages.add(this);
else deletedMessages.delete(this);
}
Expand Down
18 changes: 18 additions & 0 deletions src/structures/Role.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Util = require('../util/Util');
* @internal
*/
const deletedRoles = new WeakSet();
let deprecationEmittedForDeleted = false;

/**
* Represents a role on Discord.
Expand Down Expand Up @@ -150,12 +151,29 @@ class Role extends Base {
/**
* Whether or not the role has been deleted
* @type {boolean}
* @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091
*/
get deleted() {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Role#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

return deletedRoles.has(this);
}

set deleted(value) {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Role#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

if (value) deletedRoles.add(this);
else deletedRoles.delete(this);
}
Expand Down
18 changes: 18 additions & 0 deletions src/structures/StageInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const SnowflakeUtil = require('../util/SnowflakeUtil');
* @internal
*/
const deletedStageInstances = new WeakSet();
let deprecationEmittedForDeleted = false;

/**
* Represents a stage instance.
Expand Down Expand Up @@ -84,12 +85,29 @@ class StageInstance extends Base {
/**
* Whether or not the stage instance has been deleted
* @type {boolean}
* @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091
*/
get deleted() {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'StageInstance#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

return deletedStageInstances.has(this);
}

set deleted(value) {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'StageInstance#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

if (value) deletedStageInstances.add(this);
else deletedStageInstances.delete(this);
}
Expand Down
18 changes: 18 additions & 0 deletions src/structures/Sticker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const SnowflakeUtil = require('../util/SnowflakeUtil');
* @internal
*/
const deletedStickers = new WeakSet();
let deprecationEmittedForDeleted = false;

/**
* Represents a Sticker.
Expand Down Expand Up @@ -147,12 +148,29 @@ class Sticker extends Base {
/**
* Whether or not the sticker has been deleted
* @type {boolean}
* @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091
*/
get deleted() {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Sticker#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

return deletedStickers.has(this);
}

set deleted(value) {
if (!deprecationEmittedForDeleted) {
deprecationEmittedForDeleted = true;
process.emitWarning(
'Sticker#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
'DeprecationWarning',
);
}

if (value) deletedStickers.add(this);
else deletedStickers.delete(this);
}
Expand Down
40 changes: 16 additions & 24 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,8 @@ export abstract class Channel extends Base {
public constructor(client: Client, data?: RawChannelData, immediatePatch?: boolean);
public readonly createdAt: Date;
public readonly createdTimestamp: number;
public get deleted(): boolean;
/** @deprecated Will be removed in v14 */
public set deleted(value: boolean);
/** @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091 */
public deleted: boolean;
public id: Snowflake;
public readonly partial: false;
public type: keyof typeof ChannelTypes;
Expand Down Expand Up @@ -834,9 +833,8 @@ export class Emoji extends Base {
public animated: boolean | null;
public readonly createdAt: Date | null;
public readonly createdTimestamp: number | null;
public get deleted(): boolean;
/** @deprecated Will be removed in v14 */
public set deleted(value: boolean);
/** @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091 */
public deleted: boolean;
public id: Snowflake | null;
public name: string | null;
public readonly identifier: string;
Expand All @@ -861,9 +859,8 @@ export class Guild extends AnonymousGuild {
public channels: GuildChannelManager;
public commands: GuildApplicationCommandManager;
public defaultMessageNotifications: DefaultMessageNotificationLevel | number;
public get deleted(): boolean;
/** @deprecated Will be removed in v14 */
public set deleted(value: boolean);
/** @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091 */
public deleted: boolean;
public discoverySplash: string | null;
public emojis: GuildEmojiManager;
public explicitContentFilter: ExplicitContentFilterLevel;
Expand Down Expand Up @@ -1067,9 +1064,8 @@ export class GuildMember extends PartialTextBasedChannel(Base) {
private constructor(client: Client, data: RawGuildMemberData, guild: Guild);
public avatar: string | null;
public readonly bannable: boolean;
public get deleted(): boolean;
/** @deprecated Will be removed in v14 */
public set deleted(value: boolean);
/** @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091 */
public deleted: boolean;
public readonly displayColor: number;
public readonly displayHexColor: HexColorString;
public readonly displayName: string;
Expand Down Expand Up @@ -1407,9 +1403,8 @@ export class Message<Cached extends boolean = boolean> extends Base {
public createdTimestamp: number;
public readonly crosspostable: boolean;
public readonly deletable: boolean;
public get deleted(): boolean;
/** @deprecated Will be removed in v14 */
public set deleted(value: boolean);
/** @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091 */
public deleted: boolean;
public readonly editable: boolean;
public readonly editedAt: Date | null;
public editedTimestamp: number | null;
Expand Down Expand Up @@ -1840,9 +1835,8 @@ export class Role extends Base {
public color: number;
public readonly createdAt: Date;
public readonly createdTimestamp: number;
public get deleted(): boolean;
/** @deprecated Will be removed in v14 */
public set deleted(value: boolean);
/** @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091 */
public deleted: boolean;
public readonly editable: boolean;
public guild: Guild;
public readonly hexColor: HexColorString;
Expand Down Expand Up @@ -2027,9 +2021,8 @@ export class StageChannel extends BaseGuildVoiceChannel {
export class StageInstance extends Base {
private constructor(client: Client, data: RawStageInstanceData, channel: StageChannel);
public id: Snowflake;
public get deleted(): boolean;
/** @deprecated Will be removed in v14 */
public set deleted(value: boolean);
/** @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091 */
public deleted: boolean;
public guildId: Snowflake;
public channelId: Snowflake;
public topic: string;
Expand All @@ -2046,9 +2039,8 @@ export class StageInstance extends Base {

export class Sticker extends Base {
private constructor(client: Client, data: RawStickerData);
public get deleted(): boolean;
/** @deprecated Will be removed in v14 */
public set deleted(value: boolean);
/** @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091 */
public deleted: boolean;
public readonly createdTimestamp: number;
public readonly createdAt: Date;
public available: boolean | null;
Expand Down
Loading