From b3d4259f8a11668164745faa2e50b8496fea315d Mon Sep 17 00:00:00 2001 From: Almeida Date: Mon, 9 Dec 2024 06:58:47 +0000 Subject: [PATCH] refactor!: remove deprecated CDN method overloads (#10649) BREAKING CHANGE: Removed user avatar decoration overload from `CDN#avatarDecoration()` BREAKING CHANGE: Removed non-object options overload from `CDN#emoji()` Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- packages/rest/__tests__/CDN.test.ts | 4 -- packages/rest/src/lib/CDN.ts | 66 ++---------------------- packages/rest/src/lib/utils/constants.ts | 7 --- packages/rest/src/lib/utils/utils.ts | 16 ------ 4 files changed, 5 insertions(+), 88 deletions(-) diff --git a/packages/rest/__tests__/CDN.test.ts b/packages/rest/__tests__/CDN.test.ts index 10537bd6d..e590cf3fc 100644 --- a/packages/rest/__tests__/CDN.test.ts +++ b/packages/rest/__tests__/CDN.test.ts @@ -30,10 +30,6 @@ test('avatar dynamic-not-animated', () => { expect(cdn.avatar(id, hash)).toEqual(`${baseCDN}/avatars/${id}/${hash}.webp`); }); -test('avatar decoration default', () => { - expect(cdn.avatarDecoration(id, hash)).toEqual(`${baseCDN}/avatar-decorations/${id}/${hash}.webp`); -}); - test('avatar decoration preset', () => { expect(cdn.avatarDecoration(hash)).toEqual(`${baseCDN}/avatar-decoration-presets/${hash}.png`); }); diff --git a/packages/rest/src/lib/CDN.ts b/packages/rest/src/lib/CDN.ts index 46cd17080..5b874e265 100644 --- a/packages/rest/src/lib/CDN.ts +++ b/packages/rest/src/lib/CDN.ts @@ -8,9 +8,6 @@ import { type ImageSize, type StickerExtension, } from './utils/constants.js'; -import { deprecationWarning } from './utils/utils.js'; - -let deprecationEmittedForEmoji = false; /** * The options used for image URLs @@ -111,33 +108,8 @@ export class CDN { * * @param asset - The avatar decoration hash */ - public avatarDecoration(asset: string): string; - - /** - * Generates a user avatar decoration URL. - * - * @deprecated This overload is deprecated. Pass a hash instead. - * @param userId - The id of the user - * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration - * @param options - Optional options for the avatar decoration - */ - public avatarDecoration( - userId: string, - userAvatarDecoration: string, - // eslint-disable-next-line @typescript-eslint/unified-signatures - options?: Readonly, - ): string; - - public avatarDecoration( - userIdOrAsset: string, - userAvatarDecoration?: string, - options?: Readonly, - ): string { - if (userAvatarDecoration) { - return this.makeURL(`/avatar-decorations/${userIdOrAsset}/${userAvatarDecoration}`, options); - } - - return this.makeURL(`/avatar-decoration-presets/${userIdOrAsset}`, { extension: 'png' }); + public avatarDecoration(asset: string): string { + return this.makeURL(`/avatar-decoration-presets/${asset}`, { extension: 'png' }); } /** @@ -186,41 +158,13 @@ export class CDN { } /** - * Generates an emoji's URL for an emoji. + * Generates an emoji's URL. * * @param emojiId - The emoji id * @param options - Optional options for the emoji */ - public emoji(emojiId: string, options?: Readonly): string; - - /** - * Generates an emoji's URL for an emoji. - * - * @param emojiId - The emoji id - * @param extension - The extension of the emoji - * @deprecated This overload is deprecated. Pass an object containing the extension instead. - */ - // eslint-disable-next-line @typescript-eslint/unified-signatures - public emoji(emojiId: string, extension?: ImageExtension): string; - - public emoji(emojiId: string, options?: ImageExtension | Readonly): string { - let resolvedOptions; - - if (typeof options === 'string') { - if (!deprecationEmittedForEmoji) { - deprecationWarning( - 'Passing a string for the second parameter of CDN#emoji() is deprecated. Use an object instead.', - ); - - deprecationEmittedForEmoji = true; - } - - resolvedOptions = { extension: options }; - } else { - resolvedOptions = options; - } - - return this.makeURL(`/emojis/${emojiId}`, resolvedOptions); + public emoji(emojiId: string, options?: Readonly): string { + return this.makeURL(`/emojis/${emojiId}`, options); } /** diff --git a/packages/rest/src/lib/utils/constants.ts b/packages/rest/src/lib/utils/constants.ts index 91375b5a6..73a12255e 100644 --- a/packages/rest/src/lib/utils/constants.ts +++ b/packages/rest/src/lib/utils/constants.ts @@ -60,10 +60,3 @@ export const OverwrittenMimeTypes = { } as const satisfies Readonly>; export const BurstHandlerMajorIdKey = 'burst'; - -/** - * Prefix for deprecation warnings. - * - * @internal - */ -export const DEPRECATION_WARNING_PREFIX = 'DeprecationWarning' as const; diff --git a/packages/rest/src/lib/utils/utils.ts b/packages/rest/src/lib/utils/utils.ts index 8395d3e87..815d4b19c 100644 --- a/packages/rest/src/lib/utils/utils.ts +++ b/packages/rest/src/lib/utils/utils.ts @@ -1,7 +1,6 @@ import type { RESTPatchAPIChannelJSONBody, Snowflake } from 'discord-api-types/v10'; import type { REST } from '../REST.js'; import { RateLimitError } from '../errors/RateLimitError.js'; -import { DEPRECATION_WARNING_PREFIX } from './constants.js'; import { RequestMethod } from './types.js'; import type { GetRateLimitOffsetFunction, RateLimitData, ResponseLike } from './types.js'; @@ -143,21 +142,6 @@ export function isBufferLike(value: unknown): value is ArrayBuffer | Buffer | Ui return value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray; } -/** - * Irrespective environment warning. - * - * @remarks Only the message is needed. The deprecation prefix is handled already. - * @param message - A string the warning will emit with - * @internal - */ -export function deprecationWarning(message: string) { - if (typeof globalThis.process === 'undefined') { - console.warn(`${DEPRECATION_WARNING_PREFIX}: ${message}`); - } else { - process.emitWarning(message, DEPRECATION_WARNING_PREFIX); - } -} - /** * Normalizes the offset for rate limits. Applies a Math.max(0, N) to prevent negative offsets, * also deals with callbacks.