refactor(REST): remove double classing (#9722)

* refactor(REST): remove double classing

BREAKING CHANGE: `REST` and `RequestManager` have been combined, most of the properties, methods, and events from both classes can now be found on `REST`
BREAKING CHANGE: `REST#raw` has been removed in favor of `REST#queueRequest`
BREAKING CHANGE: `REST#getAgent` has been removed in favor of `REST#agent`

* chore: update for /rest changes
This commit is contained in:
ckohen
2023-07-25 01:40:21 -07:00
committed by GitHub
parent 6307f81385
commit 8f4256db8a
19 changed files with 774 additions and 832 deletions

View File

@@ -1,8 +1,8 @@
import type { RequestInit } from 'undici';
import type { ResponseLike } from '../REST.js';
import type { HandlerRequestData, RequestManager, RouteData } from '../RequestManager.js';
import type { REST } from '../REST.js';
import type { IHandler } from '../interfaces/Handler.js';
import { RESTEvents } from '../utils/constants.js';
import type { ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';
import { onRateLimit, sleep } from '../utils/utils.js';
import { handleErrors, incrementInvalidCount, makeNetworkRequest } from './Shared.js';
@@ -31,7 +31,7 @@ export class BurstHandler implements IHandler {
* @param majorParameter - The major parameter for this handler
*/
public constructor(
private readonly manager: RequestManager,
private readonly manager: REST,
private readonly hash: string,
private readonly majorParameter: string,
) {

View File

@@ -1,9 +1,9 @@
import { AsyncQueue } from '@sapphire/async-queue';
import type { RequestInit } from 'undici';
import type { RateLimitData, ResponseLike } from '../REST.js';
import type { HandlerRequestData, RequestManager, RouteData } from '../RequestManager.js';
import type { REST } from '../REST.js';
import type { IHandler } from '../interfaces/Handler.js';
import { RESTEvents } from '../utils/constants.js';
import type { RateLimitData, ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';
import { hasSublimit, onRateLimit, sleep } from '../utils/utils.js';
import { handleErrors, incrementInvalidCount, makeNetworkRequest } from './Shared.js';
@@ -62,7 +62,7 @@ export class SequentialHandler implements IHandler {
* @param majorParameter - The major parameter for this handler
*/
public constructor(
private readonly manager: RequestManager,
private readonly manager: REST,
private readonly hash: string,
private readonly majorParameter: string,
) {

View File

@@ -1,10 +1,10 @@
import type { RequestInit } from 'undici';
import type { ResponseLike } from '../REST.js';
import type { HandlerRequestData, RequestManager, RouteData } from '../RequestManager.js';
import type { REST } from '../REST.js';
import type { DiscordErrorData, OAuthErrorData } from '../errors/DiscordAPIError.js';
import { DiscordAPIError } from '../errors/DiscordAPIError.js';
import { HTTPError } from '../errors/HTTPError.js';
import { RESTEvents } from '../utils/constants.js';
import type { ResponseLike, HandlerRequestData, RouteData } from '../utils/types.js';
import { parseResponse, shouldRetry } from '../utils/utils.js';
/**
@@ -22,7 +22,7 @@ let invalidCountResetTime: number | null = null;
*
* @internal
*/
export function incrementInvalidCount(manager: RequestManager) {
export function incrementInvalidCount(manager: REST) {
if (!invalidCountResetTime || invalidCountResetTime < Date.now()) {
invalidCountResetTime = Date.now() + 1_000 * 60 * 10;
invalidCount = 0;
@@ -55,7 +55,7 @@ export function incrementInvalidCount(manager: RequestManager) {
* @internal
*/
export async function makeNetworkRequest(
manager: RequestManager,
manager: REST,
routeId: RouteData,
url: string,
options: RequestInit,
@@ -118,7 +118,7 @@ export async function makeNetworkRequest(
* @returns - The response if the status code is not handled or null to request a retry
*/
export async function handleErrors(
manager: RequestManager,
manager: REST,
res: ResponseLike,
method: string,
url: string,