@sapphire/plugin-api 7.0.0-next.08a81b1 → 7.0.0-next.1054b61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/cjs/index.cjs +23 -9
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +207 -114
- package/dist/cjs/lib/structures/Augmentations.d.cjs +1 -1
- package/dist/cjs/lib/structures/Augmentations.d.cjs.map +1 -1
- package/dist/cjs/lib/structures/MediaParser.cjs +1 -1
- package/dist/cjs/lib/structures/MediaParser.cjs.map +1 -1
- package/dist/cjs/lib/structures/MediaParserStore.cjs +1 -1
- package/dist/cjs/lib/structures/MediaParserStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/Middleware.cjs +2 -2
- package/dist/cjs/lib/structures/Middleware.cjs.map +1 -1
- package/dist/cjs/lib/structures/MiddlewareStore.cjs +4 -4
- package/dist/cjs/lib/structures/MiddlewareStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/Route.cjs +15 -12
- package/dist/cjs/lib/structures/Route.cjs.map +1 -1
- package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs +3 -11
- package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs.map +1 -1
- package/dist/cjs/lib/structures/RouteStore.cjs +4 -42
- package/dist/cjs/lib/structures/RouteStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/ApiRequest.cjs +27 -1
- package/dist/cjs/lib/structures/api/ApiRequest.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/ApiResponse.cjs +8 -2
- package/dist/cjs/lib/structures/api/ApiResponse.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/CookieStore.cjs +1 -1
- package/dist/cjs/lib/structures/api/CookieStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/Auth.cjs +2 -2
- package/dist/cjs/lib/structures/http/Auth.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/HttpCodes.cjs +1 -1
- package/dist/cjs/lib/structures/http/HttpCodes.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/HttpMethods.cjs +1 -1
- package/dist/cjs/lib/structures/http/HttpMethods.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/Server.cjs +16 -15
- package/dist/cjs/lib/structures/http/Server.cjs.map +1 -1
- package/dist/cjs/lib/structures/router/RouterBranch.cjs +184 -0
- package/dist/cjs/lib/structures/router/RouterBranch.cjs.map +1 -0
- package/dist/cjs/lib/structures/router/RouterNode.cjs +67 -0
- package/dist/cjs/lib/structures/router/RouterNode.cjs.map +1 -0
- package/dist/cjs/lib/structures/router/RouterRoot.cjs +71 -0
- package/dist/cjs/lib/structures/router/RouterRoot.cjs.map +1 -0
- package/dist/cjs/lib/utils/MimeTypes.cjs +1 -1
- package/dist/cjs/lib/utils/MimeTypes.cjs.map +1 -1
- package/dist/cjs/listeners/PluginRouteError.cjs +3 -3
- package/dist/cjs/listeners/PluginRouteError.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerMiddlewareError.cjs +3 -3
- package/dist/cjs/listeners/PluginServerMiddlewareError.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs +5 -5
- package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerRequest.cjs +42 -8
- package/dist/cjs/listeners/PluginServerRequest.cjs.map +1 -1
- package/dist/cjs/listeners/{PluginServerMatch.cjs → PluginServerRouterBranchMethodNotAllowed.cjs} +5 -10
- package/dist/cjs/listeners/PluginServerRouterBranchMethodNotAllowed.cjs.map +1 -0
- package/dist/cjs/listeners/{PluginServerNoMatch.cjs → PluginServerRouterBranchNotFound.cjs} +3 -3
- package/dist/cjs/listeners/PluginServerRouterBranchNotFound.cjs.map +1 -0
- package/dist/cjs/listeners/PluginServerRouterFound.cjs +22 -0
- package/dist/cjs/listeners/PluginServerRouterFound.cjs.map +1 -0
- package/dist/cjs/listeners/_load.cjs +7 -5
- package/dist/cjs/listeners/_load.cjs.map +1 -1
- package/dist/cjs/mediaParsers/_load.cjs +1 -1
- package/dist/cjs/mediaParsers/_load.cjs.map +1 -1
- package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs +1 -1
- package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs.map +1 -1
- package/dist/cjs/mediaParsers/applicationJson.cjs +1 -1
- package/dist/cjs/mediaParsers/applicationJson.cjs.map +1 -1
- package/dist/cjs/mediaParsers/textPlain.cjs +1 -1
- package/dist/cjs/mediaParsers/textPlain.cjs.map +1 -1
- package/dist/cjs/middlewares/_load.cjs +1 -1
- package/dist/cjs/middlewares/_load.cjs.map +1 -1
- package/dist/cjs/middlewares/auth.cjs +2 -2
- package/dist/cjs/middlewares/auth.cjs.map +1 -1
- package/dist/cjs/middlewares/body.cjs +6 -5
- package/dist/cjs/middlewares/body.cjs.map +1 -1
- package/dist/cjs/middlewares/cookies.cjs +1 -1
- package/dist/cjs/middlewares/cookies.cjs.map +1 -1
- package/dist/cjs/middlewares/headers.cjs +10 -11
- package/dist/cjs/middlewares/headers.cjs.map +1 -1
- package/dist/cjs/register.cjs +1 -1
- package/dist/cjs/register.cjs.map +1 -1
- package/dist/cjs/routes/_load.cjs +1 -1
- package/dist/cjs/routes/_load.cjs.map +1 -1
- package/dist/cjs/routes/oauth/callback.post.cjs +2 -2
- package/dist/cjs/routes/oauth/callback.post.cjs.map +1 -1
- package/dist/cjs/routes/oauth/logout.post.cjs +1 -1
- package/dist/cjs/routes/oauth/logout.post.cjs.map +1 -1
- package/dist/esm/{chunk-JTFKMR4I.mjs → chunk-S573YWRP.mjs} +4 -3
- package/dist/esm/chunk-S573YWRP.mjs.map +1 -0
- package/dist/esm/index.d.mts +207 -114
- package/dist/esm/index.mjs +6 -4
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/structures/Augmentations.d.mjs +1 -1
- package/dist/esm/lib/structures/Augmentations.d.mjs.map +1 -1
- package/dist/esm/lib/structures/MediaParser.mjs +2 -2
- package/dist/esm/lib/structures/MediaParser.mjs.map +1 -1
- package/dist/esm/lib/structures/MediaParserStore.mjs +2 -2
- package/dist/esm/lib/structures/MediaParserStore.mjs.map +1 -1
- package/dist/esm/lib/structures/Middleware.mjs +2 -2
- package/dist/esm/lib/structures/Middleware.mjs.map +1 -1
- package/dist/esm/lib/structures/MiddlewareStore.mjs +4 -4
- package/dist/esm/lib/structures/MiddlewareStore.mjs.map +1 -1
- package/dist/esm/lib/structures/Route.mjs +16 -13
- package/dist/esm/lib/structures/Route.mjs.map +1 -1
- package/dist/esm/lib/structures/RouteLoaderStrategy.mjs +4 -12
- package/dist/esm/lib/structures/RouteLoaderStrategy.mjs.map +1 -1
- package/dist/esm/lib/structures/RouteStore.mjs +4 -42
- package/dist/esm/lib/structures/RouteStore.mjs.map +1 -1
- package/dist/esm/lib/structures/api/ApiRequest.mjs +28 -2
- package/dist/esm/lib/structures/api/ApiRequest.mjs.map +1 -1
- package/dist/esm/lib/structures/api/ApiResponse.mjs +8 -2
- package/dist/esm/lib/structures/api/ApiResponse.mjs.map +1 -1
- package/dist/esm/lib/structures/api/CookieStore.mjs +2 -2
- package/dist/esm/lib/structures/api/CookieStore.mjs.map +1 -1
- package/dist/esm/lib/structures/http/Auth.mjs +2 -2
- package/dist/esm/lib/structures/http/Auth.mjs.map +1 -1
- package/dist/esm/lib/structures/http/HttpCodes.mjs +2 -2
- package/dist/esm/lib/structures/http/HttpCodes.mjs.map +1 -1
- package/dist/esm/lib/structures/http/HttpMethods.mjs +2 -2
- package/dist/esm/lib/structures/http/HttpMethods.mjs.map +1 -1
- package/dist/esm/lib/structures/http/Server.mjs +17 -16
- package/dist/esm/lib/structures/http/Server.mjs.map +1 -1
- package/dist/esm/lib/structures/router/RouterBranch.mjs +179 -0
- package/dist/esm/lib/structures/router/RouterBranch.mjs.map +1 -0
- package/dist/esm/lib/structures/router/RouterNode.mjs +56 -0
- package/dist/esm/lib/structures/router/RouterNode.mjs.map +1 -0
- package/dist/esm/lib/structures/router/RouterRoot.mjs +68 -0
- package/dist/esm/lib/structures/router/RouterRoot.mjs.map +1 -0
- package/dist/esm/lib/utils/MimeTypes.mjs +2 -2
- package/dist/esm/lib/utils/MimeTypes.mjs.map +1 -1
- package/dist/esm/listeners/PluginRouteError.mjs +5 -5
- package/dist/esm/listeners/PluginRouteError.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerMiddlewareError.mjs +5 -5
- package/dist/esm/listeners/PluginServerMiddlewareError.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs +7 -7
- package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerRequest.mjs +38 -10
- package/dist/esm/listeners/PluginServerRequest.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerRouterBranchMethodNotAllowed.mjs +18 -0
- package/dist/esm/listeners/PluginServerRouterBranchMethodNotAllowed.mjs.map +1 -0
- package/dist/esm/listeners/{PluginServerNoMatch.mjs → PluginServerRouterBranchNotFound.mjs} +5 -5
- package/dist/esm/listeners/PluginServerRouterBranchNotFound.mjs.map +1 -0
- package/dist/esm/listeners/PluginServerRouterFound.mjs +19 -0
- package/dist/esm/listeners/PluginServerRouterFound.mjs.map +1 -0
- package/dist/esm/listeners/_load.mjs +14 -12
- package/dist/esm/listeners/_load.mjs.map +1 -1
- package/dist/esm/mediaParsers/_load.mjs +2 -2
- package/dist/esm/mediaParsers/_load.mjs.map +1 -1
- package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs +2 -2
- package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs.map +1 -1
- package/dist/esm/mediaParsers/applicationJson.mjs +2 -2
- package/dist/esm/mediaParsers/applicationJson.mjs.map +1 -1
- package/dist/esm/mediaParsers/textPlain.mjs +2 -2
- package/dist/esm/mediaParsers/textPlain.mjs.map +1 -1
- package/dist/esm/middlewares/_load.mjs +2 -2
- package/dist/esm/middlewares/_load.mjs.map +1 -1
- package/dist/esm/middlewares/auth.mjs +2 -2
- package/dist/esm/middlewares/auth.mjs.map +1 -1
- package/dist/esm/middlewares/body.mjs +6 -5
- package/dist/esm/middlewares/body.mjs.map +1 -1
- package/dist/esm/middlewares/cookies.mjs +2 -2
- package/dist/esm/middlewares/cookies.mjs.map +1 -1
- package/dist/esm/middlewares/headers.mjs +11 -12
- package/dist/esm/middlewares/headers.mjs.map +1 -1
- package/dist/esm/register.mjs +2 -2
- package/dist/esm/register.mjs.map +1 -1
- package/dist/esm/routes/_load.mjs +2 -2
- package/dist/esm/routes/_load.mjs.map +1 -1
- package/dist/esm/routes/oauth/callback.post.mjs +2 -2
- package/dist/esm/routes/oauth/callback.post.mjs.map +1 -1
- package/dist/esm/routes/oauth/logout.post.mjs +2 -2
- package/dist/esm/routes/oauth/logout.post.mjs.map +1 -1
- package/package.json +8 -7
- package/dist/cjs/lib/utils/RouteData.cjs +0 -62
- package/dist/cjs/lib/utils/RouteData.cjs.map +0 -1
- package/dist/cjs/listeners/PluginServerMatch.cjs.map +0 -1
- package/dist/cjs/listeners/PluginServerNoMatch.cjs.map +0 -1
- package/dist/esm/chunk-JTFKMR4I.mjs.map +0 -1
- package/dist/esm/lib/utils/RouteData.mjs +0 -56
- package/dist/esm/lib/utils/RouteData.mjs.map +0 -1
- package/dist/esm/listeners/PluginServerMatch.mjs +0 -23
- package/dist/esm/listeners/PluginServerMatch.mjs.map +0 -1
- package/dist/esm/listeners/PluginServerNoMatch.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
**Plugin for <a href="https://github.com/sapphiredev/framework">@sapphire/framework</a> to expose a REST API.**
|
|
8
8
|
|
|
9
9
|
[](https://github.com/sapphiredev/plugins/blob/main/LICENSE.md)
|
|
10
|
-
[](https://codecov.io/gh/sapphiredev/plugins)
|
|
11
10
|
[](https://bundlephobia.com/result?p=@sapphire/plugin-api)
|
|
12
11
|
[](https://www.npmjs.com/package/@sapphire/plugin-api)
|
|
13
12
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -12,16 +12,18 @@ var MediaParserStore_cjs = require('./lib/structures/MediaParserStore.cjs');
|
|
|
12
12
|
var Middleware_cjs = require('./lib/structures/Middleware.cjs');
|
|
13
13
|
var MiddlewareStore_cjs = require('./lib/structures/MiddlewareStore.cjs');
|
|
14
14
|
var Route_cjs = require('./lib/structures/Route.cjs');
|
|
15
|
+
var RouterBranch_cjs = require('./lib/structures/router/RouterBranch.cjs');
|
|
16
|
+
var RouterNode_cjs = require('./lib/structures/router/RouterNode.cjs');
|
|
17
|
+
var RouterRoot_cjs = require('./lib/structures/router/RouterRoot.cjs');
|
|
15
18
|
var RouteStore_cjs = require('./lib/structures/RouteStore.cjs');
|
|
16
19
|
var MimeTypes_cjs = require('./lib/utils/MimeTypes.cjs');
|
|
17
|
-
var RouteData_cjs = require('./lib/utils/RouteData.cjs');
|
|
18
20
|
var _load_cjs = require('./listeners/_load.cjs');
|
|
19
21
|
var _load_cjs$1 = require('./mediaParsers/_load.cjs');
|
|
20
22
|
var _load_cjs$2 = require('./middlewares/_load.cjs');
|
|
21
23
|
var _load_cjs$3 = require('./routes/_load.cjs');
|
|
22
24
|
|
|
23
25
|
// src/index.ts
|
|
24
|
-
var version = "7.0.0-next.
|
|
26
|
+
var version = "7.0.0-next.1054b61";
|
|
25
27
|
|
|
26
28
|
Object.defineProperty(exports, "loadListeners", {
|
|
27
29
|
enumerable: true,
|
|
@@ -112,23 +114,35 @@ Object.keys(Route_cjs).forEach(function (k) {
|
|
|
112
114
|
get: function () { return Route_cjs[k]; }
|
|
113
115
|
});
|
|
114
116
|
});
|
|
115
|
-
Object.keys(
|
|
117
|
+
Object.keys(RouterBranch_cjs).forEach(function (k) {
|
|
116
118
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
117
119
|
enumerable: true,
|
|
118
|
-
get: function () { return
|
|
120
|
+
get: function () { return RouterBranch_cjs[k]; }
|
|
119
121
|
});
|
|
120
122
|
});
|
|
121
|
-
Object.keys(
|
|
123
|
+
Object.keys(RouterNode_cjs).forEach(function (k) {
|
|
122
124
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
123
125
|
enumerable: true,
|
|
124
|
-
get: function () { return
|
|
126
|
+
get: function () { return RouterNode_cjs[k]; }
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
Object.keys(RouterRoot_cjs).forEach(function (k) {
|
|
130
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
131
|
+
enumerable: true,
|
|
132
|
+
get: function () { return RouterRoot_cjs[k]; }
|
|
125
133
|
});
|
|
126
134
|
});
|
|
127
|
-
Object.keys(
|
|
135
|
+
Object.keys(RouteStore_cjs).forEach(function (k) {
|
|
136
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
get: function () { return RouteStore_cjs[k]; }
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
Object.keys(MimeTypes_cjs).forEach(function (k) {
|
|
128
142
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
129
143
|
enumerable: true,
|
|
130
|
-
get: function () { return
|
|
144
|
+
get: function () { return MimeTypes_cjs[k]; }
|
|
131
145
|
});
|
|
132
146
|
});
|
|
133
|
-
//# sourceMappingURL=
|
|
147
|
+
//# sourceMappingURL=index.cjs.map
|
|
134
148
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyDO,IAAM,OAAkB,GAAA","file":"index.cjs","sourcesContent":["import type { Server, ServerOptions } from './lib/structures/http/Server';\nimport type { MediaParserStore } from './lib/structures/MediaParserStore';\nimport type { MiddlewareStore } from './lib/structures/MiddlewareStore';\nimport type { RouteStore } from './lib/structures/RouteStore';\n\nexport * from './lib/structures/api/ApiRequest';\nexport * from './lib/structures/api/ApiResponse';\nexport * from './lib/structures/api/CookieStore';\nexport * from './lib/structures/http/Auth';\nexport * from './lib/structures/http/HttpCodes';\nexport * from './lib/structures/http/HttpMethods';\nexport * from './lib/structures/http/Server';\nexport * from './lib/structures/MediaParser';\nexport * from './lib/structures/MediaParserStore';\nexport * from './lib/structures/Middleware';\nexport * from './lib/structures/MiddlewareStore';\nexport * from './lib/structures/Route';\nexport * from './lib/structures/router/RouterBranch';\nexport * from './lib/structures/router/RouterNode';\nexport * from './lib/structures/router/RouterRoot';\nexport * from './lib/structures/RouteStore';\nexport * from './lib/utils/MimeTypes';\n\nexport { loadListeners } from './listeners/_load';\nexport { loadMediaParsers } from './mediaParsers/_load';\nexport { loadMiddlewares } from './middlewares/_load';\nexport { loadRoutes } from './routes/_load';\n\ndeclare module 'discord.js' {\n\tinterface Client {\n\t\tserver: Server;\n\t}\n\n\tinterface ClientOptions {\n\t\tapi?: ServerOptions;\n\t}\n}\n\ndeclare module '@sapphire/pieces' {\n\tinterface StoreRegistryEntries {\n\t\troutes: RouteStore;\n\t\tmediaParsers: MediaParserStore;\n\t\tmiddlewares: MiddlewareStore;\n\t}\n\n\tinterface Container {\n\t\tserver: Server;\n\t}\n}\n\n/**\n * The [@sapphire/plugin-api](https://github.com/sapphiredev/plugins/blob/main/packages/api) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '7.0.0-next.1054b61';\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
|
|
2
2
|
import { IncomingMessage, ServerResponse, Server as Server$1, ServerOptions as ServerOptions$1 } from 'node:http';
|
|
3
3
|
import { ListenOptions } from 'node:net';
|
|
4
4
|
import { Piece, Store } from '@sapphire/pieces';
|
|
5
5
|
import { Awaitable } from '@sapphire/utilities';
|
|
6
6
|
import { Gunzip } from 'zlib';
|
|
7
|
-
import { Snowflake, OAuth2Scopes, RESTGetAPICurrentUserResult, RESTGetAPICurrentUserGuildsResult, RESTGetAPICurrentUserConnectionsResult, Collection } from 'discord.js';
|
|
8
7
|
import { Readable } from 'node:stream';
|
|
8
|
+
import { Snowflake, OAuth2Scopes, RESTGetAPICurrentUserResult, RESTGetAPICurrentUserGuildsResult, RESTGetAPICurrentUserConnectionsResult } from 'discord.js';
|
|
9
|
+
|
|
10
|
+
declare enum MimeTypes {
|
|
11
|
+
ApplicationFormUrlEncoded = "application/x-www-form-urlencoded",
|
|
12
|
+
ApplicationJson = "application/json",
|
|
13
|
+
AudioOgg = "audio/ogg",
|
|
14
|
+
AudioOpus = "audio/opus",
|
|
15
|
+
AudioWebm = "audio/webm",
|
|
16
|
+
ImageGif = "image/gif",
|
|
17
|
+
ImageJpg = "image/jpeg",
|
|
18
|
+
ImagePng = "image/png",
|
|
19
|
+
ImageWebp = "image/webp",
|
|
20
|
+
ImageXIcon = "image/x-icon",
|
|
21
|
+
TextPlain = "text/plain",
|
|
22
|
+
TextHtml = "text/html",
|
|
23
|
+
VideoMp4 = "video/mp4",
|
|
24
|
+
VideoMpeg = "video/mpeg",
|
|
25
|
+
VideoOgg = "video/ogg",
|
|
26
|
+
VideoWebm = "video/webm"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type MethodName = (typeof MethodNames)[number];
|
|
30
|
+
declare const MethodNames: readonly ["ACL", "BIND", "CHECKOUT", "CONNECT", "COPY", "DELETE", "GET", "HEAD", "LINK", "LOCK", "M-SEARCH", "MERGE", "MKACTIVITY", "MKCALENDAR", "MKCOL", "MOVE", "NOTIFY", "OPTIONS", "PATCH", "POST", "PROPFIND", "PROPPATCH", "PURGE", "PUT", "REBIND", "REPORT", "SEARCH", "SOURCE", "SUBSCRIBE", "TRACE", "UNBIND", "UNLINK", "UNLOCK", "UNSUBSCRIBE"];
|
|
9
31
|
|
|
10
32
|
declare class Auth {
|
|
11
33
|
#private;
|
|
@@ -167,82 +189,6 @@ interface LoginDataTransformer<T extends LoginData = LoginData> {
|
|
|
167
189
|
(data: LoginData): Awaitable<T>;
|
|
168
190
|
}
|
|
169
191
|
|
|
170
|
-
declare class ApiRequest extends IncomingMessage {
|
|
171
|
-
/**
|
|
172
|
-
* The query parameters.
|
|
173
|
-
*/
|
|
174
|
-
query: Record<string, string | string[]>;
|
|
175
|
-
/**
|
|
176
|
-
* The URI parameters.
|
|
177
|
-
*/
|
|
178
|
-
params: Record<string, string>;
|
|
179
|
-
/**
|
|
180
|
-
* The body that was sent by the user.
|
|
181
|
-
*/
|
|
182
|
-
body?: unknown;
|
|
183
|
-
/**
|
|
184
|
-
* The authorization information. This field indicates three possible values:
|
|
185
|
-
*
|
|
186
|
-
* - `undefined`: The authorization middleware has not been executed yet.
|
|
187
|
-
* - `null`: The user is not authorized.
|
|
188
|
-
* - `AuthData`: The user is authorized.
|
|
189
|
-
*/
|
|
190
|
-
auth?: AuthData | null;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* @since 1.0.0
|
|
195
|
-
*/
|
|
196
|
-
declare enum TypeState {
|
|
197
|
-
/**
|
|
198
|
-
* @since 1.0.0
|
|
199
|
-
*/
|
|
200
|
-
Static = 0,
|
|
201
|
-
/**
|
|
202
|
-
* @since 1.0.0
|
|
203
|
-
*/
|
|
204
|
-
Dynamic = 1
|
|
205
|
-
}
|
|
206
|
-
type MatchData = Record<string, string> | null;
|
|
207
|
-
declare class RouteData {
|
|
208
|
-
readonly path: string;
|
|
209
|
-
private readonly static;
|
|
210
|
-
private readonly parts;
|
|
211
|
-
constructor(path: string);
|
|
212
|
-
match(split: readonly string[]): MatchData;
|
|
213
|
-
/**
|
|
214
|
-
* @since 1.0.0
|
|
215
|
-
*/
|
|
216
|
-
private static parsePart;
|
|
217
|
-
/**
|
|
218
|
-
* @since 1.0.0
|
|
219
|
-
*/
|
|
220
|
-
private static split;
|
|
221
|
-
}
|
|
222
|
-
interface ParsedPart {
|
|
223
|
-
value: string;
|
|
224
|
-
type: TypeState;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
declare enum MimeTypes {
|
|
228
|
-
ApplicationFormUrlEncoded = "application/x-www-form-urlencoded",
|
|
229
|
-
ApplicationJson = "application/json",
|
|
230
|
-
AudioOgg = "audio/ogg",
|
|
231
|
-
AudioOpus = "audio/opus",
|
|
232
|
-
AudioWebm = "audio/webm",
|
|
233
|
-
ImageGif = "image/gif",
|
|
234
|
-
ImageJpg = "image/jpeg",
|
|
235
|
-
ImagePng = "image/png",
|
|
236
|
-
ImageWebp = "image/webp",
|
|
237
|
-
ImageXIcon = "image/x-icon",
|
|
238
|
-
TextPlain = "text/plain",
|
|
239
|
-
TextHtml = "text/html",
|
|
240
|
-
VideoMp4 = "video/mp4",
|
|
241
|
-
VideoMpeg = "video/mpeg",
|
|
242
|
-
VideoOgg = "video/ogg",
|
|
243
|
-
VideoWebm = "video/webm"
|
|
244
|
-
}
|
|
245
|
-
|
|
246
192
|
declare class CookieStore extends Map<string, string> {
|
|
247
193
|
protected request: ApiRequest;
|
|
248
194
|
protected response: ApiResponse;
|
|
@@ -307,6 +253,10 @@ declare class ApiResponse<Request extends IncomingMessage = IncomingMessage> ext
|
|
|
307
253
|
* @since 1.0.0
|
|
308
254
|
*/
|
|
309
255
|
notFound(data?: unknown): void;
|
|
256
|
+
/**
|
|
257
|
+
* @since 7.0.0
|
|
258
|
+
*/
|
|
259
|
+
methodNotAllowed(data?: unknown): void;
|
|
310
260
|
/**
|
|
311
261
|
* @since 1.0.0
|
|
312
262
|
*/
|
|
@@ -350,9 +300,6 @@ declare class ApiResponse<Request extends IncomingMessage = IncomingMessage> ext
|
|
|
350
300
|
setContentType(contentType: MimeTypes): this;
|
|
351
301
|
}
|
|
352
302
|
|
|
353
|
-
type MethodName = (typeof MethodNames)[number];
|
|
354
|
-
declare const MethodNames: readonly ["ACL", "BIND", "CHECKOUT", "CONNECT", "COPY", "DELETE", "GET", "HEAD", "LINK", "LOCK", "M-SEARCH", "MERGE", "MKACTIVITY", "MKCALENDAR", "MKCOL", "MOVE", "NOTIFY", "OPTIONS", "PATCH", "POST", "PROPFIND", "PROPPATCH", "PURGE", "PUT", "REBIND", "REPORT", "SEARCH", "SOURCE", "SUBSCRIBE", "TRACE", "UNBIND", "UNLINK", "UNLOCK", "UNSUBSCRIBE"];
|
|
355
|
-
|
|
356
303
|
interface RouteOptions extends Piece.Options {
|
|
357
304
|
/**
|
|
358
305
|
* The route the piece should represent.
|
|
@@ -441,9 +388,9 @@ declare abstract class Route<Options extends Route.Options = Route.Options> exte
|
|
|
441
388
|
*/
|
|
442
389
|
readonly acceptedContentMimeTypes: readonly MimeTypeWithoutParameters[] | null;
|
|
443
390
|
/**
|
|
444
|
-
* The route
|
|
391
|
+
* The path this route represents.
|
|
445
392
|
*/
|
|
446
|
-
readonly
|
|
393
|
+
readonly path: readonly string[];
|
|
447
394
|
/**
|
|
448
395
|
* The methods this route accepts.
|
|
449
396
|
*/
|
|
@@ -462,6 +409,141 @@ declare namespace Route {
|
|
|
462
409
|
type Response = ApiResponse;
|
|
463
410
|
}
|
|
464
411
|
|
|
412
|
+
declare class RouterBranch {
|
|
413
|
+
/**
|
|
414
|
+
* The name of the branch.
|
|
415
|
+
*/
|
|
416
|
+
readonly name: string;
|
|
417
|
+
/**
|
|
418
|
+
* Whether or not the branch is dynamic.
|
|
419
|
+
*/
|
|
420
|
+
readonly dynamic: boolean;
|
|
421
|
+
/**
|
|
422
|
+
* The parent branch, if any.
|
|
423
|
+
*/
|
|
424
|
+
readonly parent: RouterBranch | null;
|
|
425
|
+
/**
|
|
426
|
+
* The node this branch is associated with.
|
|
427
|
+
*/
|
|
428
|
+
readonly node: RouterNode;
|
|
429
|
+
/**
|
|
430
|
+
* The methods supported by the branch's node or any of its children.
|
|
431
|
+
*/
|
|
432
|
+
supportedMethods: readonly string[];
|
|
433
|
+
private _staticChildren;
|
|
434
|
+
private _dynamicChild;
|
|
435
|
+
constructor(name: string, dynamic: boolean, parent: RouterBranch | null);
|
|
436
|
+
/**
|
|
437
|
+
* The path representing this branch
|
|
438
|
+
* @version 7.0.0
|
|
439
|
+
*/
|
|
440
|
+
get path(): string;
|
|
441
|
+
/**
|
|
442
|
+
* The branches the branch is associated with
|
|
443
|
+
* @version 7.0.0
|
|
444
|
+
*/
|
|
445
|
+
get children(): RouterBranch[];
|
|
446
|
+
/**
|
|
447
|
+
* Whether or not the branch is empty
|
|
448
|
+
* @version 7.0.0
|
|
449
|
+
*/
|
|
450
|
+
get empty(): boolean;
|
|
451
|
+
/**
|
|
452
|
+
* Tries to find a branch given a path
|
|
453
|
+
* @version 7.0.0
|
|
454
|
+
*
|
|
455
|
+
* @param parts The parts of a path to find a node from
|
|
456
|
+
* @returns The branch found, or null if not found
|
|
457
|
+
*/
|
|
458
|
+
find(parts: readonly string[]): RouterBranch | null;
|
|
459
|
+
/**
|
|
460
|
+
* Checks if the given name matches the branch
|
|
461
|
+
* @version 7.0.0
|
|
462
|
+
*
|
|
463
|
+
* @param name The name to match
|
|
464
|
+
* @returns Whether or not the branch matches the name
|
|
465
|
+
*/
|
|
466
|
+
matches(name: string): boolean;
|
|
467
|
+
/**
|
|
468
|
+
* Returns the string representation of the branch
|
|
469
|
+
* @version 7.0.0
|
|
470
|
+
*
|
|
471
|
+
* @returns The string representation of the branch
|
|
472
|
+
*/
|
|
473
|
+
toString(): string;
|
|
474
|
+
nodes(): IterableIterator<RouterNode>;
|
|
475
|
+
protected _add(parts: readonly string[], index: number, route: Route): RouterNode;
|
|
476
|
+
protected _remove(parts: readonly string[], index: number, route: Route): boolean;
|
|
477
|
+
protected _performAdd(parts: readonly string[], index: number, route: Route): RouterNode;
|
|
478
|
+
protected _performRemove(parts: readonly string[], index: number, route: Route): boolean;
|
|
479
|
+
protected _find(parts: readonly string[], index: number): RouterBranch | null;
|
|
480
|
+
protected _updateSupportedChildrenMethods(): void;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
declare class RouterNode {
|
|
484
|
+
#private;
|
|
485
|
+
/**
|
|
486
|
+
* The branch containing this node.
|
|
487
|
+
*/
|
|
488
|
+
readonly parent: RouterBranch;
|
|
489
|
+
constructor(parent: RouterBranch);
|
|
490
|
+
get path(): string;
|
|
491
|
+
extractParameters(parts: readonly string[]): Record<string, string>;
|
|
492
|
+
get(method: MethodName): Route | null;
|
|
493
|
+
set(method: MethodName, route: Route): this;
|
|
494
|
+
delete(method: MethodName, route: Route): boolean;
|
|
495
|
+
methods(): IterableIterator<MethodName>;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
declare class ApiRequest extends IncomingMessage {
|
|
499
|
+
/**
|
|
500
|
+
* The query parameters.
|
|
501
|
+
*/
|
|
502
|
+
query: Record<string, string | string[]>;
|
|
503
|
+
/**
|
|
504
|
+
* The URI parameters.
|
|
505
|
+
*/
|
|
506
|
+
params: Record<string, string>;
|
|
507
|
+
/**
|
|
508
|
+
* The body that was sent by the user.
|
|
509
|
+
*/
|
|
510
|
+
body?: unknown;
|
|
511
|
+
/**
|
|
512
|
+
* The authorization information. This field indicates three possible values:
|
|
513
|
+
*
|
|
514
|
+
* - `undefined`: The authorization middleware has not been executed yet.
|
|
515
|
+
* - `null`: The user is not authorized.
|
|
516
|
+
* - `AuthData`: The user is authorized.
|
|
517
|
+
*/
|
|
518
|
+
auth?: AuthData | null;
|
|
519
|
+
/**
|
|
520
|
+
* The router node that matched the request. The field indicates three
|
|
521
|
+
* possible values:
|
|
522
|
+
*
|
|
523
|
+
* - `undefined`: The router handler has not been executed yet.
|
|
524
|
+
* - `null`: The router handler has been executed, but no node matched the
|
|
525
|
+
* request.
|
|
526
|
+
* - `RouterNode`: The router handler has been executed and a node matched
|
|
527
|
+
* the request.
|
|
528
|
+
*
|
|
529
|
+
* @since 7.0.0
|
|
530
|
+
*/
|
|
531
|
+
routerNode?: RouterNode | null;
|
|
532
|
+
/**
|
|
533
|
+
* The route that matched the request. The field indicates three possible
|
|
534
|
+
* values:
|
|
535
|
+
*
|
|
536
|
+
* - `undefined`: The router handler has not been executed yet.
|
|
537
|
+
* - `null`: The router handler has been executed, but no route matched the
|
|
538
|
+
* request.
|
|
539
|
+
* - `Route`: The router handler has been executed and a route matched the
|
|
540
|
+
* request.
|
|
541
|
+
*
|
|
542
|
+
* @since 7.0.0
|
|
543
|
+
*/
|
|
544
|
+
route?: Route | null;
|
|
545
|
+
}
|
|
546
|
+
|
|
465
547
|
/**
|
|
466
548
|
* A media parser
|
|
467
549
|
* @since 1.3.0
|
|
@@ -554,7 +636,7 @@ declare abstract class Middleware<Options extends Middleware.Options = Middlewar
|
|
|
554
636
|
* @param response The server's response.
|
|
555
637
|
* @param route The route that matched this request, will be `null` if none matched.
|
|
556
638
|
*/
|
|
557
|
-
abstract run(request: Middleware.Request, response: Middleware.Response
|
|
639
|
+
abstract run(request: Middleware.Request, response: Middleware.Response): Awaitable<unknown>;
|
|
558
640
|
}
|
|
559
641
|
declare namespace Middleware {
|
|
560
642
|
/** @deprecated Use {@linkcode LoaderContext} instead. */
|
|
@@ -576,36 +658,68 @@ declare class MiddlewareStore extends Store<Middleware, 'middlewares'> {
|
|
|
576
658
|
*/
|
|
577
659
|
readonly sortedMiddlewares: Middleware[];
|
|
578
660
|
constructor();
|
|
579
|
-
run(request: Middleware.Request, response: Middleware.Response
|
|
661
|
+
run(request: Middleware.Request, response: Middleware.Response): Promise<void>;
|
|
580
662
|
set(key: string, value: Middleware): this;
|
|
581
663
|
delete(key: string): boolean;
|
|
582
664
|
clear(): void;
|
|
583
665
|
}
|
|
584
666
|
|
|
667
|
+
declare class RouterRoot extends RouterBranch {
|
|
668
|
+
constructor();
|
|
669
|
+
/**
|
|
670
|
+
* Adds a route to the branch
|
|
671
|
+
*
|
|
672
|
+
* @param route The route to add
|
|
673
|
+
* @returns The node the route was added to
|
|
674
|
+
*/
|
|
675
|
+
add(route: Route): RouterNode;
|
|
676
|
+
/**
|
|
677
|
+
* Removes a route from the branch
|
|
678
|
+
*
|
|
679
|
+
* @param route The route to remove
|
|
680
|
+
* @returns Whether or not the route was removed
|
|
681
|
+
*/
|
|
682
|
+
remove(route: Route): boolean;
|
|
683
|
+
get path(): string;
|
|
684
|
+
toString(): string;
|
|
685
|
+
static normalize(path: string | null | undefined): string[];
|
|
686
|
+
static extractMethod(path: readonly string[]): MethodName | null;
|
|
687
|
+
}
|
|
688
|
+
|
|
585
689
|
/**
|
|
586
690
|
* @since 1.0.0
|
|
587
691
|
*/
|
|
588
692
|
declare class RouteStore extends Store<Route, 'routes'> {
|
|
589
|
-
readonly
|
|
693
|
+
readonly router: RouterRoot;
|
|
590
694
|
constructor();
|
|
591
|
-
match(request: Route.Request): Route | null;
|
|
592
|
-
private parseURL;
|
|
593
695
|
}
|
|
594
696
|
|
|
595
|
-
declare enum
|
|
697
|
+
declare enum ServerEvent {
|
|
596
698
|
Error = "error",
|
|
597
699
|
Request = "request",
|
|
598
|
-
|
|
599
|
-
|
|
700
|
+
RouterBranchNotFound = "routerBranchNotFound",
|
|
701
|
+
RouterBranchMethodNotAllowed = "routerBranchMethodNotAllowed",
|
|
702
|
+
RouterFound = "routerFound",
|
|
600
703
|
RouteError = "routeError",
|
|
601
704
|
MiddlewareFailure = "middlewareFailure",
|
|
602
705
|
MiddlewareError = "middlewareError",
|
|
603
706
|
MiddlewareSuccess = "middlewareSuccess"
|
|
604
707
|
}
|
|
708
|
+
interface ServerEvents {
|
|
709
|
+
[ServerEvent.Error]: [error: Error, request: ApiRequest, response: ApiResponse];
|
|
710
|
+
[ServerEvent.Request]: [request: ApiRequest, response: ApiResponse];
|
|
711
|
+
[ServerEvent.RouterBranchNotFound]: [request: ApiRequest, response: ApiResponse];
|
|
712
|
+
[ServerEvent.RouterBranchMethodNotAllowed]: [request: ApiRequest, response: ApiResponse, node: RouterBranch];
|
|
713
|
+
[ServerEvent.RouterFound]: [request: ApiRequest, response: ApiResponse];
|
|
714
|
+
[ServerEvent.RouteError]: [error: Error, request: ApiRequest, response: ApiResponse];
|
|
715
|
+
[ServerEvent.MiddlewareFailure]: [request: ApiRequest, response: ApiResponse];
|
|
716
|
+
[ServerEvent.MiddlewareSuccess]: [request: Route.Request, response: Route.Response, route: Route];
|
|
717
|
+
[ServerEvent.MiddlewareError]: [error: Error, request: ApiRequest, response: ApiResponse];
|
|
718
|
+
}
|
|
605
719
|
/**
|
|
606
720
|
* @since 1.0.0
|
|
607
721
|
*/
|
|
608
|
-
declare class Server extends
|
|
722
|
+
declare class Server extends AsyncEventEmitter<ServerEvents> {
|
|
609
723
|
/**
|
|
610
724
|
* The routes this server holds.
|
|
611
725
|
* @since 1.0.0
|
|
@@ -738,27 +852,6 @@ interface ServerOptions {
|
|
|
738
852
|
* @since 1.0.0
|
|
739
853
|
*/
|
|
740
854
|
type AuthLessServerOptions = Omit<ServerOptions, 'auth'>;
|
|
741
|
-
/**
|
|
742
|
-
* The context sent in the error events.
|
|
743
|
-
* @since 1.2.0
|
|
744
|
-
*/
|
|
745
|
-
interface MiddlewareErrorContext {
|
|
746
|
-
/**
|
|
747
|
-
* The erroneous request.
|
|
748
|
-
* @since 1.2.0
|
|
749
|
-
*/
|
|
750
|
-
request: ApiRequest;
|
|
751
|
-
/**
|
|
752
|
-
* The server's response.
|
|
753
|
-
* @since 1.2.0
|
|
754
|
-
*/
|
|
755
|
-
response: ApiResponse;
|
|
756
|
-
/**
|
|
757
|
-
* The route match.
|
|
758
|
-
* @since 1.2.0
|
|
759
|
-
*/
|
|
760
|
-
route: Route;
|
|
761
|
-
}
|
|
762
855
|
|
|
763
856
|
declare enum HttpCodes {
|
|
764
857
|
/**
|
|
@@ -1172,4 +1265,4 @@ declare module '@sapphire/pieces' {
|
|
|
1172
1265
|
*/
|
|
1173
1266
|
declare const version: string;
|
|
1174
1267
|
|
|
1175
|
-
export { ApiRequest, ApiResponse, Auth, type AuthData, type AuthLessServerOptions, type ContentTypeParameter, type ContentTypeType, CookieStore, HttpCodes, type LoginData, type LoginDataTransformer,
|
|
1268
|
+
export { ApiRequest, ApiResponse, Auth, type AuthData, type AuthLessServerOptions, type ContentTypeParameter, type ContentTypeType, CookieStore, HttpCodes, type LoginData, type LoginDataTransformer, MediaParser, MediaParserStore, type MethodName, MethodNames, Middleware, type MiddlewareOptions, MiddlewareStore, type MimeType, type MimeTypeWithoutParameters, MimeTypes, Route, type RouteOptions, RouteStore, RouterBranch, RouterNode, RouterRoot, type SecureCookieStoreSetOptions, Server, ServerEvent, type ServerEvents, type ServerOptions, type ServerOptionsAuth, loadListeners, loadMediaParsers, loadMiddlewares, loadRoutes, version };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"Augmentations.d.cjs"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/MediaParser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/MediaParser.ts"],"names":["Piece","createInflate","createGunzip","createBrotliDecompress"],"mappings":";;;;;;;AAWO,IAAe,YAAA,GAAf,MAAe,YAAA,SAA+EA,YAA+B,CAAA;AAAA,EAC5H,WAAY,CAAA,OAAA,EAAoC,OAAmB,GAAA,EAAe,EAAA;AACxF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAAA,GACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,QAAQ,KAAuB,EAAA;AACrC,IAAA,OAAO,MAAM,wBAA6B,KAAA,IAAA,IAAQ,MAAM,wBAAyB,CAAA,QAAA,CAAS,KAAK,IAAiC,CAAA,CAAA;AAAA,GACjI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,OAA+C,EAAA;AACzE,IAAM,MAAA,MAAA,GAAS,IAAK,CAAA,aAAA,CAAc,OAAO,CAAA,CAAA;AACzC,IAAI,IAAA,MAAA,KAAW,MAAa,OAAA,EAAA,CAAA;AAE5B,IAAA,IAAI,IAAO,GAAA,EAAA,CAAA;AACX,IAAiB,WAAA,MAAA,KAAA,IAAS,QAAgB,IAAA,IAAA,KAAA,CAAA;AAE1C,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,OAA+C,EAAA;AACzE,IAAM,MAAA,MAAA,GAAS,IAAK,CAAA,aAAA,CAAc,OAAO,CAAA,CAAA;AACzC,IAAA,IAAI,MAAW,KAAA,IAAA,EAAa,OAAA,MAAA,CAAO,MAAM,CAAC,CAAA,CAAA;AAE1C,IAAA,MAAM,SAAmB,EAAC,CAAA;AAC1B,IAAA,WAAA,MAAiB,KAAS,IAAA,MAAA,EAAe,MAAA,CAAA,IAAA,CAAK,KAAK,CAAA,CAAA;AAEnD,IAAO,OAAA,MAAA,CAAO,OAAO,MAAM,CAAA,CAAA;AAAA,GAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,cAAc,OAAmE,EAAA;AAC1F,IAAA,QAAA,CAAS,QAAQ,OAAQ,CAAA,kBAAkB,CAAK,IAAA,UAAA,EAAY,aAAe;AAAA,MAK1E,KAAK,SAAW,EAAA;AACf,QAAA,MAAM,SAASC,kBAAc,EAAA,CAAA;AAC7B,QAAA,OAAA,CAAQ,KAAK,MAAM,CAAA,CAAA;AACnB,QAAO,OAAA,MAAA,CAAA;AAAA,OACR;AAAA,MAMA,KAAK,QAAA,CAAA;AAAA,MACL,KAAK,MAAQ,EAAA;AACZ,QAAA,MAAM,SAASC,iBAAa,EAAA,CAAA;AAC5B,QAAA,OAAA,CAAQ,KAAK,MAAM,CAAA,CAAA;AACnB,QAAO,OAAA,MAAA,CAAA;AAAA,OACR;AAAA,MAKA,KAAK,IAAM,EAAA;AACV,QAAA,MAAM,SAASC,2BAAuB,EAAA,CAAA;AACtC,QAAA,OAAA,CAAQ,KAAK,MAAM,CAAA,CAAA;AACnB,QAAO,OAAA,MAAA,CAAA;AAAA,OACR;AAAA,MAIA,KAAK,UAAY,EAAA;AAChB,QAAO,OAAA,OAAA,CAAA;AAAA,OACR;AAAA,KACD;AAEA,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AACD,CAAA,CAAA;AAhGoI,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAA7H,IAAe,WAAf,GAAA","file":"MediaParser.cjs","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport { createBrotliDecompress, createGunzip, createInflate, type Gunzip } from 'zlib';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { MimeTypeWithoutParameters } from './http/Server';\nimport type { Route } from './Route';\n\n/**\n * A media parser\n * @since 1.3.0\n */\nexport abstract class MediaParser<Options extends MediaParser.Options = MediaParser.Options> extends Piece<Options, 'mediaParsers'> {\n\tpublic constructor(context: MediaParser.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t}\n\n\t/**\n\t * Parses the body data from an API request.\n\t * @since 1.3.0\n\t */\n\tpublic abstract run(request: MediaParser.Request): Awaitable<unknown>;\n\n\t/**\n\t * Checks if a route accepts the media type from this parser.\n\t * @since 1.3.0\n\t * @param route The route to be checked.\n\t */\n\tpublic accepts(route: Route): boolean {\n\t\treturn route.acceptedContentMimeTypes === null || route.acceptedContentMimeTypes.includes(this.name as MimeTypeWithoutParameters);\n\t}\n\n\t/**\n\t * Reads the content body as a string, this is useful for parsing/reading plain-text data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readString(request: MediaParser.Request): Promise<string> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return '';\n\n\t\tlet body = '';\n\t\tfor await (const chunk of stream) body += chunk;\n\n\t\treturn body;\n\t}\n\n\t/**\n\t * Reads the content body as a buffer, this is useful for parsing/reading binary data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readBuffer(request: MediaParser.Request): Promise<Buffer> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return Buffer.alloc(0);\n\n\t\tconst bodies: Buffer[] = [];\n\t\tfor await (const chunk of stream) bodies.push(chunk);\n\n\t\treturn Buffer.concat(bodies);\n\t}\n\n\t/**\n\t * Reads the content stream from a request, piping the data through a transformer stream.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected contentStream(request: MediaParser.Request): MediaParser.Request | Gunzip | null {\n\t\tswitch ((request.headers['content-encoding'] ?? 'identity').toLowerCase()) {\n\t\t\t// RFC 7230 4.2.2:\n\t\t\t//\n\t\t\t// The \"deflate\" coding is a \"zlib\" data format (RFC 1950) containing a \"deflate\" compressed data stream\n\t\t\t// (RFC 1951) that uses a combination of the Lempel-Ziv (LZ77) compression algorithm and Huffman coding.\n\t\t\tcase 'deflate': {\n\t\t\t\tconst stream = createInflate();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7230 4.2.3\n\t\t\t//\n\t\t\t// The \"gzip\" coding is an LZ77 coding with a 32-bit Cyclic Redundancy Check (CRC) that is commonly produced\n\t\t\t// by the gzip file compression program (RFC 1952).\n\t\t\tcase 'x-gzip':\n\t\t\tcase 'gzip': {\n\t\t\t\tconst stream = createGunzip();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7932\n\t\t\t//\n\t\t\t// A format using the Brotli algorithm.\n\t\t\tcase 'br': {\n\t\t\t\tconst stream = createBrotliDecompress();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// An \"identity\" token is used as a synonym for \"no encoding\" in order to communicate when no encoding is\n\t\t\t// preferred.\n\t\t\tcase 'identity': {\n\t\t\t\treturn request;\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n}\n\nexport namespace MediaParser {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'mediaParsers'>;\n\texport type Options = Piece.Options;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n\n\texport type Request = ApiRequest;\n}\n"]}
|
|
@@ -23,5 +23,5 @@ __name(_MediaParserStore, "MediaParserStore");
|
|
|
23
23
|
var MediaParserStore = _MediaParserStore;
|
|
24
24
|
|
|
25
25
|
exports.MediaParserStore = MediaParserStore;
|
|
26
|
-
//# sourceMappingURL=
|
|
26
|
+
//# sourceMappingURL=MediaParserStore.cjs.map
|
|
27
27
|
//# sourceMappingURL=MediaParserStore.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/MediaParserStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/MediaParserStore.ts"],"names":["Store","MediaParser"],"mappings":";;;;;;;AAMO,IAAM,iBAAA,GAAN,MAAM,iBAAA,SAAyBA,YAAmC,CAAA;AAAA,EACjE,WAAc,GAAA;AACpB,IAAA,KAAA,CAAMC,2BAAa,EAAA,EAAE,IAAM,EAAA,cAAA,EAAgB,CAAA,CAAA;AAAA,GAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,iBAAiB,WAA6B,EAAA;AACpD,IAAM,MAAA,KAAA,GAAQ,WAAY,CAAA,OAAA,CAAQ,GAAG,CAAA,CAAA;AACrC,IAAA,OAAO,UAAU,CAAK,CAAA,GAAA,WAAA,GAAc,WAAY,CAAA,KAAA,CAAM,GAAG,KAAK,CAAA,CAAA;AAAA,GAC/D;AACD,CAAA,CAAA;AAdyE,MAAA,CAAA,iBAAA,EAAA,kBAAA,CAAA,CAAA;AAAlE,IAAM,gBAAN,GAAA","file":"MediaParserStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { MediaParser } from './MediaParser';\n\n/**\n * @since 1.3.0\n */\nexport class MediaParserStore extends Store<MediaParser, 'mediaParsers'> {\n\tpublic constructor() {\n\t\tsuper(MediaParser, { name: 'mediaParsers' });\n\t}\n\n\t/**\n\t * Parses a content type by getting the relevant information inside.\n\t * @since 1.3.0\n\t * @param contentType The content type to parse.\n\t */\n\tpublic parseContentType(contentType: string): string {\n\t\tconst index = contentType.indexOf(';');\n\t\treturn index === -1 ? contentType : contentType.slice(0, index);\n\t}\n}\n"]}
|
|
@@ -5,7 +5,7 @@ var pieces = require('@sapphire/pieces');
|
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
6
6
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj,
|
|
8
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
9
9
|
var _Middleware = class _Middleware extends pieces.Piece {
|
|
10
10
|
constructor(context, options = {}) {
|
|
11
11
|
super(context, options);
|
|
@@ -27,5 +27,5 @@ __name(_Middleware, "Middleware");
|
|
|
27
27
|
var Middleware = _Middleware;
|
|
28
28
|
|
|
29
29
|
exports.Middleware = Middleware;
|
|
30
|
-
//# sourceMappingURL=
|
|
30
|
+
//# sourceMappingURL=Middleware.cjs.map
|
|
31
31
|
//# sourceMappingURL=Middleware.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/Middleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/Middleware.ts"],"names":["Piece"],"mappings":";;;;;;;;AAQO,IAAe,WAAA,GAAf,MAAe,WAAA,SAA4EA,YAA8B,CAAA;AAAA,EAaxH,WAAY,CAAA,OAAA,EAAmC,OAAmB,GAAA,EAAe,EAAA;AACvF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAHvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA;AAIf,IAAK,IAAA,CAAA,QAAA,GAAW,QAAQ,QAAY,IAAA,GAAA,CAAA;AAAA,GACrC;AASD,CAAA,CAAA;AAzBgI,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA,CAAA;AAAzH,IAAe,UAAf,GAAA","file":"Middleware.cjs","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\n\n/**\n * @since 1.0.0\n */\nexport abstract class Middleware<Options extends Middleware.Options = Middleware.Options> extends Piece<Options, 'middlewares'> {\n\t/**\n\t * The position the middleware has. The {@link MiddlewareStore} will run all middlewares with lower position than\n\t * this one.\n\t *\n\t * The built-in middlewares follow the following positions:\n\t * - headers: 10\n\t * - body: 20\n\t * - cookies: 30\n\t * - auth: 40\n\t */\n\tpublic readonly position: number;\n\n\tpublic constructor(context: Middleware.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t\tthis.position = options.position ?? 1000;\n\t}\n\n\t/**\n\t * The method to be overridden by other middlewares.\n\t * @param request The client's request.\n\t * @param response The server's response.\n\t * @param route The route that matched this request, will be `null` if none matched.\n\t */\n\tpublic abstract run(request: Middleware.Request, response: Middleware.Response): Awaitable<unknown>;\n}\n\n/**\n * The options for all middlewares.\n */\nexport interface MiddlewareOptions extends Piece.Options {\n\t/**\n\t * The position to insert the middleware at.\n\t * @see Middleware#position\n\t * @default 1000\n\t */\n\tposition?: number;\n}\n\nexport namespace Middleware {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'middlewares'>;\n\texport type Options = MiddlewareOptions;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n\n\texport type Request = ApiRequest;\n\texport type Response = ApiResponse;\n}\n"]}
|
|
@@ -6,7 +6,7 @@ var Middleware_cjs = require('./Middleware.cjs');
|
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
7
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj,
|
|
9
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
10
10
|
var _MiddlewareStore = class _MiddlewareStore extends pieces.Store {
|
|
11
11
|
constructor() {
|
|
12
12
|
super(Middleware_cjs.Middleware, { name: "middlewares" });
|
|
@@ -15,10 +15,10 @@ var _MiddlewareStore = class _MiddlewareStore extends pieces.Store {
|
|
|
15
15
|
*/
|
|
16
16
|
__publicField(this, "sortedMiddlewares", []);
|
|
17
17
|
}
|
|
18
|
-
async run(request, response
|
|
18
|
+
async run(request, response) {
|
|
19
19
|
for (const middleware of this.sortedMiddlewares) {
|
|
20
20
|
if (response.writableEnded) return;
|
|
21
|
-
if (middleware.enabled) await middleware.run(request, response
|
|
21
|
+
if (middleware.enabled) await middleware.run(request, response);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
set(key, value) {
|
|
@@ -41,5 +41,5 @@ __name(_MiddlewareStore, "MiddlewareStore");
|
|
|
41
41
|
var MiddlewareStore = _MiddlewareStore;
|
|
42
42
|
|
|
43
43
|
exports.MiddlewareStore = MiddlewareStore;
|
|
44
|
-
//# sourceMappingURL=
|
|
44
|
+
//# sourceMappingURL=MiddlewareStore.cjs.map
|
|
45
45
|
//# sourceMappingURL=MiddlewareStore.cjs.map
|