Skip to content

Commit

Permalink
refactor: remove media parsers
Browse files Browse the repository at this point in the history
Added `ApiRequest#asWeb()`
Added `ApiRequest#readBody()`
Added `ApiRequest#readBodyArrayBuffer()`
Added `ApiRequest#readBodyBlob()`
Added `ApiRequest#readBodyFormData()`
Added `ApiRequest#readBodyJson()`
Added `ApiRequest#readBodyText()`
Added `ApiRequest#readValidatedBody()`
Added `ApiRequest#readValidatedBodyFormData()`
Added `ApiRequest#readValidatedBodyJson()`
Added `ApiRequest#readValidatedBodyText()`
Added `'QUERY'` to the list of method names
Fixed issue in `Server#disconnect()`

BREAKING CHANGE: Removed `MediaParser`
BREAKING CHANGE: Removed `MediaParserStore`
BREAKING CHANGE: Removed `Route#acceptedContentMimeTypes`
BREAKING CHANGE: Removed `ApiRequest#body`, use the new methods instead
  • Loading branch information
kyranet committed Aug 27, 2024
1 parent c2464a5 commit 018c7e1
Show file tree
Hide file tree
Showing 26 changed files with 594 additions and 270 deletions.
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"dependencies": {
"@types/ws": "^8.5.12",
"@vladfrangu/async_event_emitter": "2.4.6",
"cookie-es": "^1.2.2",
"tldts": "^6.1.41",
"undici": "^6.19.8"
},
Expand Down
5 changes: 0 additions & 5 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Server, ServerOptions } from './lib/structures/http/Server';
import type { MediaParserStore } from './lib/structures/MediaParserStore';
import type { MiddlewareStore } from './lib/structures/MiddlewareStore';
import type { RouteStore } from './lib/structures/RouteStore';

Expand All @@ -10,8 +9,6 @@ export * from './lib/structures/http/Auth';
export * from './lib/structures/http/HttpCodes';
export * from './lib/structures/http/HttpMethods';
export * from './lib/structures/http/Server';
export * from './lib/structures/MediaParser';
export * from './lib/structures/MediaParserStore';
export * from './lib/structures/Middleware';
export * from './lib/structures/MiddlewareStore';
export * from './lib/structures/Route';
Expand All @@ -22,7 +19,6 @@ export * from './lib/structures/RouteStore';
export type * from './lib/utils/MimeType';

export { loadListeners } from './listeners/_load';
export { loadMediaParsers } from './mediaParsers/_load';
export { loadMiddlewares } from './middlewares/_load';
export { loadRoutes } from './routes/_load';

Expand All @@ -39,7 +35,6 @@ declare module 'discord.js' {
declare module '@sapphire/pieces' {
interface StoreRegistryEntries {
routes: RouteStore;
mediaParsers: MediaParserStore;
middlewares: MiddlewareStore;
}

Expand Down
2 changes: 0 additions & 2 deletions packages/api/src/lib/structures/Augmentations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import type { MiddlewareStore, RouteStore } from '../..';
import type { Server, ServerOptions } from './http/Server';
import type { MediaParserStore } from './MediaParserStore';

declare module 'discord.js' {
export interface Client {
Expand All @@ -21,7 +20,6 @@ declare module 'discord.js' {
declare module '@sapphire/framework' {
interface StoreRegistryEntries {
routes: RouteStore;
mediaParsers: MediaParserStore;
middlewares: MiddlewareStore;
}
}
Expand Down
119 changes: 0 additions & 119 deletions packages/api/src/lib/structures/MediaParser.ts

This file was deleted.

21 changes: 0 additions & 21 deletions packages/api/src/lib/structures/MediaParserStore.ts

This file was deleted.

19 changes: 2 additions & 17 deletions packages/api/src/lib/structures/Route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Piece } from '@sapphire/pieces';
import { isNullish, type Awaitable } from '@sapphire/utilities';
import type { MimeType } from '../utils/MimeType';
import type { ApiRequest } from './api/ApiRequest';
import type { ApiResponse } from './api/ApiResponse';
import type { MethodName } from './http/HttpMethods';
Expand Down Expand Up @@ -49,11 +48,6 @@ export abstract class Route<Options extends Route.Options = Route.Options> exten
*/
public readonly maximumBodyLength: number;

/**
* The accepted content types.
*/
public readonly acceptedContentMimeTypes: readonly MimeType[] | null;

/**
* The path this route represents.
*/
Expand All @@ -78,13 +72,12 @@ export abstract class Route<Options extends Route.Options = Route.Options> exten
if (!isNullish(implied)) {
const lastIndex = path.length - 1;
path[lastIndex] = path[lastIndex].slice(0, path[lastIndex].length - implied.length - 1);
methods.add(implied as MethodName);
methods.add(implied);
}

this.path = path;
this.methods = methods;
this.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;
this.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;
}

public abstract run(request: Route.Request, response: Route.Response): Awaitable<unknown>;
Expand Down Expand Up @@ -118,14 +111,6 @@ export interface RouteOptions extends Piece.Options {
*/
maximumBodyLength?: number;

/**
* The accepted content types for this route. If set to null, the route will accept any data.
* @since 1.3.0
*
* @defaultValue this.context.server.options.acceptedContentMimeTypes ?? null
*/
acceptedContentMimeTypes?: readonly MimeType[] | null;

/**
* The methods this route accepts.
* @since 7.0.0
Expand All @@ -137,7 +122,7 @@ export interface RouteOptions extends Piece.Options {

export namespace Route {
/** @deprecated Use {@linkcode LoaderContext} instead. */
export type Context = LoaderContext;
export type Context = LoaderContext; // NOSONAR
export type LoaderContext = Piece.LoaderContext<'routes'>;
export type Options = RouteOptions;
export type JSON = Piece.JSON;
Expand Down
Loading

0 comments on commit 018c7e1

Please sign in to comment.