@sapphire/plugin-api 7.0.0-next.d27dc1c → 7.0.0-next.d2c9aaa
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 +21 -33
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +318 -212
- 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/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 +18 -40
- package/dist/cjs/lib/structures/Route.cjs.map +1 -1
- package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs +20 -0
- package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs.map +1 -0
- package/dist/cjs/lib/structures/RouteStore.cjs +6 -44
- package/dist/cjs/lib/structures/RouteStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/ApiRequest.cjs +155 -5
- package/dist/cjs/lib/structures/api/ApiRequest.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/ApiResponse.cjs +12 -7
- package/dist/cjs/lib/structures/api/ApiResponse.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/CookieStore.cjs +4 -4
- 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 +39 -7
- package/dist/cjs/lib/structures/http/HttpMethods.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/Server.cjs +17 -23
- 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 +81 -0
- package/dist/cjs/lib/structures/router/RouterRoot.cjs.map +1 -0
- package/dist/cjs/lib/utils/MimeType.cjs +4 -0
- package/dist/cjs/lib/utils/MimeType.cjs.map +1 -0
- package/dist/cjs/lib/utils/_body/RequestHeadersProxy.cjs +100 -0
- package/dist/cjs/lib/utils/_body/RequestHeadersProxy.cjs.map +1 -0
- package/dist/cjs/lib/utils/_body/RequestProxy.cjs +123 -0
- package/dist/cjs/lib/utils/_body/RequestProxy.cjs.map +1 -0
- package/dist/cjs/lib/utils/_body/RequestURLProxy.cjs +179 -0
- package/dist/cjs/lib/utils/_body/RequestURLProxy.cjs.map +1 -0
- package/dist/cjs/lib/utils/constants.cjs +8 -0
- package/dist/cjs/lib/utils/constants.cjs.map +1 -0
- 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/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 +4 -19
- 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 +19 -9
- package/dist/cjs/middlewares/headers.cjs.map +1 -1
- package/dist/cjs/register.cjs +3 -4
- package/dist/cjs/register.cjs.map +1 -1
- package/dist/cjs/register.d.cts +0 -1
- package/dist/cjs/routes/_load.cjs +5 -5
- package/dist/cjs/routes/_load.cjs.map +1 -1
- package/dist/cjs/routes/oauth/{callback.cjs → callback.post.cjs} +6 -7
- package/dist/cjs/routes/oauth/callback.post.cjs.map +1 -0
- package/dist/cjs/routes/oauth/{logout.cjs → logout.post.cjs} +6 -8
- package/dist/cjs/routes/oauth/logout.post.cjs.map +1 -0
- 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 +318 -212
- package/dist/esm/index.mjs +6 -8
- 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/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 +19 -41
- package/dist/esm/lib/structures/Route.mjs.map +1 -1
- package/dist/esm/lib/structures/RouteLoaderStrategy.mjs +17 -0
- package/dist/esm/lib/structures/RouteLoaderStrategy.mjs.map +1 -0
- package/dist/esm/lib/structures/RouteStore.mjs +6 -44
- package/dist/esm/lib/structures/RouteStore.mjs.map +1 -1
- package/dist/esm/lib/structures/api/ApiRequest.mjs +149 -6
- package/dist/esm/lib/structures/api/ApiRequest.mjs.map +1 -1
- package/dist/esm/lib/structures/api/ApiResponse.mjs +12 -7
- package/dist/esm/lib/structures/api/ApiResponse.mjs.map +1 -1
- package/dist/esm/lib/structures/api/CookieStore.mjs +5 -5
- 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 +41 -6
- package/dist/esm/lib/structures/http/HttpMethods.mjs.map +1 -1
- package/dist/esm/lib/structures/http/Server.mjs +18 -24
- 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 +78 -0
- package/dist/esm/lib/structures/router/RouterRoot.mjs.map +1 -0
- package/dist/esm/lib/utils/MimeType.mjs +3 -0
- package/dist/esm/lib/utils/MimeType.mjs.map +1 -0
- package/dist/esm/lib/utils/_body/RequestHeadersProxy.mjs +95 -0
- package/dist/esm/lib/utils/_body/RequestHeadersProxy.mjs.map +1 -0
- package/dist/esm/lib/utils/_body/RequestProxy.mjs +111 -0
- package/dist/esm/lib/utils/_body/RequestProxy.mjs.map +1 -0
- package/dist/esm/lib/utils/_body/RequestURLProxy.mjs +167 -0
- package/dist/esm/lib/utils/_body/RequestURLProxy.mjs.map +1 -0
- package/dist/esm/lib/utils/constants.mjs +8 -0
- package/dist/esm/lib/utils/constants.mjs.map +1 -0
- 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/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 +5 -18
- 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 +20 -10
- package/dist/esm/middlewares/headers.mjs.map +1 -1
- package/dist/esm/register.d.mts +0 -1
- package/dist/esm/register.mjs +4 -5
- package/dist/esm/register.mjs.map +1 -1
- package/dist/esm/routes/_load.mjs +4 -4
- package/dist/esm/routes/_load.mjs.map +1 -1
- package/dist/esm/routes/oauth/{callback.mjs → callback.post.mjs} +6 -7
- package/dist/esm/routes/oauth/callback.post.mjs.map +1 -0
- package/dist/esm/routes/oauth/{logout.mjs → logout.post.mjs} +6 -8
- package/dist/esm/routes/oauth/logout.post.mjs.map +1 -0
- package/package.json +11 -8
- package/dist/cjs/lib/structures/MediaParser.cjs +0 -79
- package/dist/cjs/lib/structures/MediaParser.cjs.map +0 -1
- package/dist/cjs/lib/structures/MediaParserStore.cjs +0 -27
- package/dist/cjs/lib/structures/MediaParserStore.cjs.map +0 -1
- package/dist/cjs/lib/utils/MimeTypes.cjs +0 -26
- package/dist/cjs/lib/utils/MimeTypes.cjs.map +0 -1
- 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/cjs/mediaParsers/_load.cjs +0 -20
- package/dist/cjs/mediaParsers/_load.cjs.map +0 -1
- package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs +0 -23
- package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs.map +0 -1
- package/dist/cjs/mediaParsers/applicationJson.cjs +0 -22
- package/dist/cjs/mediaParsers/applicationJson.cjs.map +0 -1
- package/dist/cjs/mediaParsers/textPlain.cjs +0 -22
- package/dist/cjs/mediaParsers/textPlain.cjs.map +0 -1
- package/dist/cjs/routes/oauth/callback.cjs.map +0 -1
- package/dist/cjs/routes/oauth/logout.cjs.map +0 -1
- package/dist/esm/chunk-JTFKMR4I.mjs.map +0 -1
- package/dist/esm/lib/structures/MediaParser.mjs +0 -76
- package/dist/esm/lib/structures/MediaParser.mjs.map +0 -1
- package/dist/esm/lib/structures/MediaParserStore.mjs +0 -24
- package/dist/esm/lib/structures/MediaParserStore.mjs.map +0 -1
- package/dist/esm/lib/utils/MimeTypes.mjs +0 -26
- package/dist/esm/lib/utils/MimeTypes.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/dist/esm/mediaParsers/_load.mjs +0 -17
- package/dist/esm/mediaParsers/_load.mjs.map +0 -1
- package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs +0 -20
- package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs.map +0 -1
- package/dist/esm/mediaParsers/applicationJson.mjs +0 -19
- package/dist/esm/mediaParsers/applicationJson.mjs.map +0 -1
- package/dist/esm/mediaParsers/textPlain.mjs +0 -19
- package/dist/esm/mediaParsers/textPlain.mjs.map +0 -1
- package/dist/esm/routes/oauth/callback.mjs.map +0 -1
- package/dist/esm/routes/oauth/logout.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"Augmentations.d.cjs"}
|
|
@@ -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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":["Store","Middleware"],"mappings":";;;;;;;;;AAMO,IAAM,gBAAA,GAAN,MAAM,gBAAA,SAAwBA,YAAiC,CAAA;AAAA,EAM9D,WAAc,GAAA;AACpB,IAAA,KAAA,CAAMC,yBAAY,EAAA,EAAE,IAAM,EAAA,aAAA,EAAe,CAAA,CAAA;AAH1C;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,qBAAkC,EAAC,CAAA,CAAA;AAAA,GAInD;AAAA,EAEA,MAAa,GAAI,CAAA,OAAA,EAA6B,QAA8C,EAAA;AAC3F,IAAW,KAAA,MAAA,UAAA,IAAc,KAAK,iBAAmB,EAAA;AAChD,MAAA,IAAI,SAAS,aAAe,EAAA,OAAA;AAC5B,MAAA,IAAI,WAAW,OAAS,EAAA,MAAM,UAAW,CAAA,GAAA,CAAI,SAAS,QAAQ,CAAA,CAAA;AAAA,KAC/D;AAAA,GACD;AAAA,EAEgB,GAAA,CAAI,KAAa,KAAyB,EAAA;AACzD,IAAM,MAAA,KAAA,GAAQ,KAAK,iBAAkB,CAAA,SAAA,CAAU,CAAC,UAAe,KAAA,UAAA,CAAW,QAAY,IAAA,KAAA,CAAM,QAAQ,CAAA,CAAA;AAGpG,IAAA,IAAI,KAAU,KAAA,CAAA,CAAA,EAAS,IAAA,CAAA,iBAAA,CAAkB,KAAK,KAAK,CAAA,CAAA;AAAA,SACzC,IAAA,CAAA,iBAAA,CAAkB,MAAO,CAAA,KAAA,EAAO,GAAG,KAAK,CAAA,CAAA;AAElD,IAAO,OAAA,KAAA,CAAM,GAAI,CAAA,GAAA,EAAK,KAAK,CAAA,CAAA;AAAA,GAC5B;AAAA,EAEgB,OAAO,GAAsB,EAAA;AAC5C,IAAM,MAAA,KAAA,GAAQ,KAAK,iBAAkB,CAAA,SAAA,CAAU,CAAC,UAAe,KAAA,UAAA,CAAW,SAAS,GAAG,CAAA,CAAA;AAGtF,IAAA,IAAI,UAAU,CAAI,CAAA,EAAA,IAAA,CAAK,iBAAkB,CAAA,MAAA,CAAO,OAAO,CAAC,CAAA,CAAA;AAExD,IAAO,OAAA,KAAA,CAAM,OAAO,GAAG,CAAA,CAAA;AAAA,GACxB;AAAA,EAEgB,KAAc,GAAA;AAC7B,IAAA,IAAA,CAAK,kBAAkB,MAAS,GAAA,CAAA,CAAA;AAChC,IAAA,OAAO,MAAM,KAAM,EAAA,CAAA;AAAA,GACpB;AACD,CAAA,CAAA;AAxCsE,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA,CAAA;AAA/D,IAAM,eAAN,GAAA","file":"MiddlewareStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Middleware } from './Middleware';\n\n/**\n * @since 1.0.0\n */\nexport class MiddlewareStore extends Store<Middleware, 'middlewares'> {\n\t/**\n\t * The sorted middlewares, in ascending order of see {@link Middleware.position}.\n\t */\n\tpublic readonly sortedMiddlewares: Middleware[] = [];\n\n\tpublic constructor() {\n\t\tsuper(Middleware, { name: 'middlewares' });\n\t}\n\n\tpublic async run(request: Middleware.Request, response: Middleware.Response): Promise<void> {\n\t\tfor (const middleware of this.sortedMiddlewares) {\n\t\t\tif (response.writableEnded) return;\n\t\t\tif (middleware.enabled) await middleware.run(request, response);\n\t\t}\n\t}\n\n\tpublic override set(key: string, value: Middleware): this {\n\t\tconst index = this.sortedMiddlewares.findIndex((middleware) => middleware.position >= value.position);\n\n\t\t// If a middleware with lower priority wasn't found, push to the end of the array\n\t\tif (index === -1) this.sortedMiddlewares.push(value);\n\t\telse this.sortedMiddlewares.splice(index, 0, value);\n\n\t\treturn super.set(key, value);\n\t}\n\n\tpublic override delete(key: string): boolean {\n\t\tconst index = this.sortedMiddlewares.findIndex((middleware) => middleware.name === key);\n\n\t\t// If the middleware was found, remove it\n\t\tif (index !== -1) this.sortedMiddlewares.splice(index, 1);\n\n\t\treturn super.delete(key);\n\t}\n\n\tpublic override clear(): void {\n\t\tthis.sortedMiddlewares.length = 0;\n\t\treturn super.clear();\n\t}\n}\n"]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var pieces = require('@sapphire/pieces');
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var HttpMethods_cjs = require('./http/HttpMethods.cjs');
|
|
4
|
+
var utilities = require('@sapphire/utilities');
|
|
5
|
+
var RouterRoot_cjs = require('./router/RouterRoot.cjs');
|
|
7
6
|
|
|
8
7
|
var __defProp = Object.defineProperty;
|
|
9
8
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -17,54 +16,33 @@ var _Route = class _Route extends pieces.Piece {
|
|
|
17
16
|
*/
|
|
18
17
|
__publicField(this, "maximumBodyLength");
|
|
19
18
|
/**
|
|
20
|
-
* The
|
|
19
|
+
* The path this route represents.
|
|
21
20
|
*/
|
|
22
|
-
__publicField(this, "
|
|
23
|
-
/**
|
|
24
|
-
* The route information.
|
|
25
|
-
*/
|
|
26
|
-
__publicField(this, "router");
|
|
21
|
+
__publicField(this, "path");
|
|
27
22
|
/**
|
|
28
23
|
* The methods this route accepts.
|
|
29
24
|
*/
|
|
30
|
-
__publicField(this, "methods"
|
|
25
|
+
__publicField(this, "methods");
|
|
31
26
|
const api = this.container.server.options;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
const path = [
|
|
28
|
+
...RouterRoot_cjs.RouterRoot.normalize(api.prefix),
|
|
29
|
+
...RouterRoot_cjs.RouterRoot.normalize(options.route ?? RouterRoot_cjs.RouterRoot.makeRoutePathForPiece(this.location.directories, this.name))
|
|
30
|
+
];
|
|
31
|
+
const methods = new Set(options.methods);
|
|
32
|
+
const implied = RouterRoot_cjs.RouterRoot.extractMethod(path);
|
|
33
|
+
if (!utilities.isNullish(implied)) {
|
|
34
|
+
const lastIndex = path.length - 1;
|
|
35
|
+
path[lastIndex] = path[lastIndex].slice(0, path[lastIndex].length - implied.length - 1);
|
|
36
|
+
methods.add(implied);
|
|
38
37
|
}
|
|
38
|
+
this.path = path;
|
|
39
|
+
this.methods = methods;
|
|
39
40
|
this.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;
|
|
40
|
-
this.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Per-piece listener that is called when the piece is loaded into the store.
|
|
44
|
-
* Useful to set-up asynchronous initialization tasks.
|
|
45
|
-
*/
|
|
46
|
-
onLoad() {
|
|
47
|
-
const store = this.store;
|
|
48
|
-
for (const [method, cb] of this.methods) {
|
|
49
|
-
store.table.get(method).set(this, cb.bind(this));
|
|
50
|
-
}
|
|
51
|
-
return void 0;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Per-piece listener that is called when the piece is unloaded from the store.
|
|
55
|
-
* Useful to set-up clean-up tasks.
|
|
56
|
-
*/
|
|
57
|
-
onUnload() {
|
|
58
|
-
const store = this.store;
|
|
59
|
-
for (const [method] of this.methods) {
|
|
60
|
-
store.table.get(method).delete(this);
|
|
61
|
-
}
|
|
62
|
-
return void 0;
|
|
63
41
|
}
|
|
64
42
|
};
|
|
65
43
|
__name(_Route, "Route");
|
|
66
44
|
var Route = _Route;
|
|
67
45
|
|
|
68
46
|
exports.Route = Route;
|
|
69
|
-
//# sourceMappingURL=
|
|
47
|
+
//# sourceMappingURL=Route.cjs.map
|
|
70
48
|
//# sourceMappingURL=Route.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":["Piece","RouterRoot","isNullish"],"mappings":";;;;;;;;;;AA4CO,IAAe,MAAA,GAAf,MAAe,MAAA,SAA6DA,YAAyB,CAAA;AAAA,EAgBpG,WAAY,CAAA,OAAA,EAA8B,OAAmB,GAAA,EAAe,EAAA;AAClF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAbvB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,mBAAA,CAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;AAKf,IAAM,MAAA,GAAA,GAAM,IAAK,CAAA,SAAA,CAAU,MAAO,CAAA,OAAA,CAAA;AAClC,IAAA,MAAM,IAAO,GAAA;AAAA,MACZ,GAAGC,yBAAA,CAAW,SAAU,CAAA,GAAA,CAAI,MAAM,CAAA;AAAA,MAClC,GAAGA,yBAAA,CAAW,SAAU,CAAA,OAAA,CAAQ,KAAS,IAAAA,yBAAA,CAAW,qBAAsB,CAAA,IAAA,CAAK,QAAS,CAAA,WAAA,EAAa,IAAK,CAAA,IAAI,CAAC,CAAA;AAAA,KAChH,CAAA;AAEA,IAAA,MAAM,OAAU,GAAA,IAAI,GAAI,CAAA,OAAA,CAAQ,OAAO,CAAA,CAAA;AACvC,IAAM,MAAA,OAAA,GAAUA,yBAAW,CAAA,aAAA,CAAc,IAAI,CAAA,CAAA;AAC7C,IAAI,IAAA,CAACC,mBAAU,CAAA,OAAO,CAAG,EAAA;AACxB,MAAM,MAAA,SAAA,GAAY,KAAK,MAAS,GAAA,CAAA,CAAA;AAChC,MAAA,IAAA,CAAK,SAAS,CAAA,GAAI,IAAK,CAAA,SAAS,CAAE,CAAA,KAAA,CAAM,CAAG,EAAA,IAAA,CAAK,SAAS,CAAA,CAAE,MAAS,GAAA,OAAA,CAAQ,SAAS,CAAC,CAAA,CAAA;AACtF,MAAA,OAAA,CAAQ,IAAI,OAAO,CAAA,CAAA;AAAA,KACpB;AAEA,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AACZ,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA,CAAA;AACf,IAAA,IAAA,CAAK,oBAAoB,OAAQ,CAAA,iBAAA,IAAqB,GAAI,CAAA,iBAAA,IAAqB,OAAO,IAAO,GAAA,EAAA,CAAA;AAAA,GAC9F;AAGD,CAAA,CAAA;AAvC4G,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;AAArG,IAAe,KAAf,GAAA","file":"Route.cjs","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport { isNullish, type Awaitable } from '@sapphire/utilities';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\nimport type { MethodName } from './http/HttpMethods';\nimport { RouterRoot } from './router/RouterRoot';\n\n/**\n * @since 1.0.0\n *\n * @example A simple GET route that returns a JSON response:\n * ```typescript\n * // hello.get.ts\n * import { Route } from '@sapphire/plugin-api';\n *\n * export class MyRoute extends Route {\n * public run(request: Route.Request, response: Route.Response) {\n * return response.json({ message: 'Hello, World!' });\n * }\n * }\n * ```\n *\n * ```bash\n * $ curl http://localhost:4000/hello\n * {\"message\":\"Hello, World!\"}\n * ```\n *\n * @example A simple POST route that reads the body and returns it:\n * ```typescript\n * // echo.post.ts\n * import { Route } from '@sapphire/plugin-api';\n *\n * export class MyRoute extends Route {\n * public run(request: Route.Request, response: Route.Response) {\n * return response.json(request.params);\n * }\n * }\n * ```\n *\n * ```bash\n * $ curl -X POST -H \"Content-Type: application/json\" -d '{\"hello\":\"world\"}' http://localhost:4000/echo\n * {\"hello\":\"world\"}\n * ```\n */\nexport abstract class Route<Options extends Route.Options = Route.Options> extends Piece<Options, 'routes'> {\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t */\n\tpublic readonly maximumBodyLength: number;\n\n\t/**\n\t * The path this route represents.\n\t */\n\tpublic readonly path: readonly string[];\n\n\t/**\n\t * The methods this route accepts.\n\t */\n\tpublic readonly methods: ReadonlySet<MethodName>;\n\n\tpublic constructor(context: Route.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\n\t\tconst api = this.container.server.options;\n\t\tconst path = [\n\t\t\t...RouterRoot.normalize(api.prefix),\n\t\t\t...RouterRoot.normalize(options.route ?? RouterRoot.makeRoutePathForPiece(this.location.directories, this.name))\n\t\t];\n\n\t\tconst methods = new Set(options.methods);\n\t\tconst implied = RouterRoot.extractMethod(path);\n\t\tif (!isNullish(implied)) {\n\t\t\tconst lastIndex = path.length - 1;\n\t\t\tpath[lastIndex] = path[lastIndex].slice(0, path[lastIndex].length - implied.length - 1);\n\t\t\tmethods.add(implied);\n\t\t}\n\n\t\tthis.path = path;\n\t\tthis.methods = methods;\n\t\tthis.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;\n\t}\n\n\tpublic abstract run(request: Route.Request, response: Route.Response): Awaitable<unknown>;\n}\n\nexport interface RouteOptions extends Piece.Options {\n\t/**\n\t * The route the piece should represent.\n\t * @since 1.0.0\n\t *\n\t * @defaultValue The filesystem-based path, or the name if the location is virtual.\n\t *\n\t * @example\n\t * ```typescript\n\t * '/users'\n\t * // request.params -> {}\n\t * ```\n\t * @example\n\t * ```typescript\n\t * '/guilds/[guild]/members/[member]'\n\t * // request.params -> { guild: '...', member: '...' }\n\t * ```\n\t */\n\troute?: string;\n\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t * @since 1.0.0\n\t *\n\t * @defaultValue this.context.server.options.maximumBodyLength ?? 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The methods this route accepts.\n\t * @since 7.0.0\n\t *\n\t * @defaultValue The method defined in the piece name, or none if not set.\n\t */\n\tmethods?: readonly MethodName[];\n}\n\nexport namespace Route {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext; // NOSONAR\n\texport type LoaderContext = Piece.LoaderContext<'routes'>;\n\texport type Options = RouteOptions;\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"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var pieces = require('@sapphire/pieces');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var _RouteLoaderStrategy = class _RouteLoaderStrategy extends pieces.LoaderStrategy {
|
|
8
|
+
onLoad(store, piece) {
|
|
9
|
+
store.router.add(piece);
|
|
10
|
+
}
|
|
11
|
+
onUnload(store, piece) {
|
|
12
|
+
store.router.remove(piece);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
__name(_RouteLoaderStrategy, "RouteLoaderStrategy");
|
|
16
|
+
var RouteLoaderStrategy = _RouteLoaderStrategy;
|
|
17
|
+
|
|
18
|
+
exports.RouteLoaderStrategy = RouteLoaderStrategy;
|
|
19
|
+
//# sourceMappingURL=RouteLoaderStrategy.cjs.map
|
|
20
|
+
//# sourceMappingURL=RouteLoaderStrategy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/RouteLoaderStrategy.ts"],"names":["LoaderStrategy"],"mappings":";;;;;;AAIO,IAAM,oBAAA,GAAN,MAAM,oBAAA,SAA4BA,qBAAsB,CAAA;AAAA,EAC9C,MAAA,CAAO,OAAmB,KAAoB,EAAA;AAC7D,IAAM,KAAA,CAAA,MAAA,CAAO,IAAI,KAAK,CAAA,CAAA;AAAA,GACvB;AAAA,EAEgB,QAAA,CAAS,OAAmB,KAAoB,EAAA;AAC/D,IAAM,KAAA,CAAA,MAAA,CAAO,OAAO,KAAK,CAAA,CAAA;AAAA,GAC1B;AACD,CAAA,CAAA;AAR+D,MAAA,CAAA,oBAAA,EAAA,qBAAA,CAAA,CAAA;AAAxD,IAAM,mBAAN,GAAA","file":"RouteLoaderStrategy.cjs","sourcesContent":["import { LoaderStrategy } from '@sapphire/pieces';\nimport type { Route } from './Route';\nimport type { RouteStore } from './RouteStore';\n\nexport class RouteLoaderStrategy extends LoaderStrategy<Route> {\n\tpublic override onLoad(store: RouteStore, piece: Route): void {\n\t\tstore.router.add(piece);\n\t}\n\n\tpublic override onUnload(store: RouteStore, piece: Route): void {\n\t\tstore.router.remove(piece);\n\t}\n}\n"]}
|
|
@@ -1,61 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var pieces = require('@sapphire/pieces');
|
|
4
|
-
var discord_js = require('discord.js');
|
|
5
|
-
var url = require('url');
|
|
6
|
-
var HttpMethods_cjs = require('./http/HttpMethods.cjs');
|
|
7
4
|
var Route_cjs = require('./Route.cjs');
|
|
5
|
+
var RouteLoaderStrategy_cjs = require('./RouteLoaderStrategy.cjs');
|
|
6
|
+
var RouterRoot_cjs = require('./router/RouterRoot.cjs');
|
|
8
7
|
|
|
9
8
|
var __defProp = Object.defineProperty;
|
|
10
9
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
10
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj,
|
|
13
|
-
var slash = "/".charCodeAt(0);
|
|
11
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
14
12
|
var _RouteStore = class _RouteStore extends pieces.Store {
|
|
15
13
|
constructor() {
|
|
16
|
-
super(Route_cjs.Route, { name: "routes" });
|
|
17
|
-
__publicField(this, "
|
|
18
|
-
for (const [method] of HttpMethods_cjs.methodEntries) this.table.set(method, new discord_js.Collection());
|
|
19
|
-
}
|
|
20
|
-
match(request) {
|
|
21
|
-
const { method } = request;
|
|
22
|
-
if (typeof method === "undefined") {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
const methodTable = this.table.get(method);
|
|
26
|
-
if (typeof methodTable === "undefined") {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
const { splits, querystring } = this.parseURL(request.url);
|
|
30
|
-
for (const [route, cb] of methodTable.entries()) {
|
|
31
|
-
const result = route.router.match(splits);
|
|
32
|
-
if (result === null) continue;
|
|
33
|
-
request.params = result;
|
|
34
|
-
request.query = Object.fromEntries(new url.URLSearchParams(querystring).entries());
|
|
35
|
-
return { route, cb };
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
parseURL(url = "") {
|
|
40
|
-
const index = url.indexOf("?");
|
|
41
|
-
let pathname;
|
|
42
|
-
let querystring;
|
|
43
|
-
if (index === -1) {
|
|
44
|
-
pathname = url;
|
|
45
|
-
querystring = "";
|
|
46
|
-
} else {
|
|
47
|
-
pathname = url.substring(0, index);
|
|
48
|
-
querystring = url.substring(index + 1);
|
|
49
|
-
}
|
|
50
|
-
if (pathname.charCodeAt(0) === slash) pathname = pathname.substring(1);
|
|
51
|
-
if (pathname.length > 0 && pathname.charCodeAt(pathname.length - 1) === slash) pathname = pathname.substring(0, pathname.length - 1);
|
|
52
|
-
const splits = pathname.split("/");
|
|
53
|
-
return { splits, querystring };
|
|
14
|
+
super(Route_cjs.Route, { name: "routes", strategy: new RouteLoaderStrategy_cjs.RouteLoaderStrategy() });
|
|
15
|
+
__publicField(this, "router", new RouterRoot_cjs.RouterRoot());
|
|
54
16
|
}
|
|
55
17
|
};
|
|
56
18
|
__name(_RouteStore, "RouteStore");
|
|
57
19
|
var RouteStore = _RouteStore;
|
|
58
20
|
|
|
59
21
|
exports.RouteStore = RouteStore;
|
|
60
|
-
//# sourceMappingURL=
|
|
22
|
+
//# sourceMappingURL=RouteStore.cjs.map
|
|
61
23
|
//# sourceMappingURL=RouteStore.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":["Store","Route","RouteLoaderStrategy","RouterRoot"],"mappings":";;;;;;;;;;;AAQO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmBA,YAAuB,CAAA;AAAA,EAG/C,WAAc,GAAA;AACpB,IAAM,KAAA,CAAAC,eAAA,EAAO,EAAE,IAAM,EAAA,QAAA,EAAU,UAAU,IAAIC,2CAAA,IAAuB,CAAA,CAAA;AAHrE,IAAgB,aAAA,CAAA,IAAA,EAAA,QAAA,EAAS,IAAIC,yBAAW,EAAA,CAAA,CAAA;AAAA,GAIxC;AACD,CAAA,CAAA;AANuD,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA,CAAA;AAAhD,IAAM,UAAN,GAAA","file":"RouteStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Route } from './Route';\nimport { RouteLoaderStrategy } from './RouteLoaderStrategy';\nimport { RouterRoot } from './router/RouterRoot';\n\n/**\n * @since 1.0.0\n */\nexport class RouteStore extends Store<Route, 'routes'> {\n\tpublic readonly router = new RouterRoot();\n\n\tpublic constructor() {\n\t\tsuper(Route, { name: 'routes', strategy: new RouteLoaderStrategy() });\n\t}\n}\n"]}
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var utilities = require('@sapphire/utilities');
|
|
3
4
|
var http = require('http');
|
|
5
|
+
var RequestProxy_cjs = require('../../utils/_body/RequestProxy.cjs');
|
|
4
6
|
|
|
5
7
|
var __defProp = Object.defineProperty;
|
|
8
|
+
var __typeError = (msg) => {
|
|
9
|
+
throw TypeError(msg);
|
|
10
|
+
};
|
|
6
11
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
12
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
13
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
14
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
15
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
16
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
17
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
18
|
+
var _cachedRequest, _ApiRequest_instances, isFormContentType_get;
|
|
9
19
|
var _ApiRequest = class _ApiRequest extends http.IncomingMessage {
|
|
10
20
|
constructor() {
|
|
11
21
|
super(...arguments);
|
|
22
|
+
__privateAdd(this, _ApiRequest_instances);
|
|
12
23
|
/**
|
|
13
24
|
* The query parameters.
|
|
14
25
|
*/
|
|
@@ -17,10 +28,6 @@ var _ApiRequest = class _ApiRequest extends http.IncomingMessage {
|
|
|
17
28
|
* The URI parameters.
|
|
18
29
|
*/
|
|
19
30
|
__publicField(this, "params", {});
|
|
20
|
-
/**
|
|
21
|
-
* The body that was sent by the user.
|
|
22
|
-
*/
|
|
23
|
-
__publicField(this, "body");
|
|
24
31
|
/**
|
|
25
32
|
* The authorization information. This field indicates three possible values:
|
|
26
33
|
*
|
|
@@ -29,11 +36,154 @@ var _ApiRequest = class _ApiRequest extends http.IncomingMessage {
|
|
|
29
36
|
* - `AuthData`: The user is authorized.
|
|
30
37
|
*/
|
|
31
38
|
__publicField(this, "auth");
|
|
39
|
+
/**
|
|
40
|
+
* The router node that matched the request. The field indicates three
|
|
41
|
+
* possible values:
|
|
42
|
+
*
|
|
43
|
+
* - `undefined`: The router handler has not been executed yet.
|
|
44
|
+
* - `null`: The router handler has been executed, but no node matched the
|
|
45
|
+
* request.
|
|
46
|
+
* - `RouterNode`: The router handler has been executed and a node matched
|
|
47
|
+
* the request.
|
|
48
|
+
*
|
|
49
|
+
* @since 7.0.0
|
|
50
|
+
*/
|
|
51
|
+
__publicField(this, "routerNode");
|
|
52
|
+
/**
|
|
53
|
+
* The route that matched the request. The field indicates three possible
|
|
54
|
+
* values:
|
|
55
|
+
*
|
|
56
|
+
* - `undefined`: The router handler has not been executed yet.
|
|
57
|
+
* - `null`: The router handler has been executed, but no route matched the
|
|
58
|
+
* request.
|
|
59
|
+
* - `Route`: The router handler has been executed and a route matched the
|
|
60
|
+
* request.
|
|
61
|
+
*
|
|
62
|
+
* @since 7.0.0
|
|
63
|
+
*/
|
|
64
|
+
__publicField(this, "route");
|
|
65
|
+
/**
|
|
66
|
+
* The response object. This field is cached to prevent multiple response
|
|
67
|
+
* objects from being created.
|
|
68
|
+
*/
|
|
69
|
+
__privateAdd(this, _cachedRequest, null);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The response object, used to validate the request's headers and body.
|
|
73
|
+
*/
|
|
74
|
+
asWeb() {
|
|
75
|
+
__privateGet(this, _cachedRequest) ?? __privateSet(this, _cachedRequest, new RequestProxy_cjs.RequestProxy(this));
|
|
76
|
+
return __privateGet(this, _cachedRequest);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Reads the request body and tries to parse using JSON or form-urlencoded.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const body = await request.readBody();
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @returns The result of the body parsing
|
|
87
|
+
*/
|
|
88
|
+
readBody() {
|
|
89
|
+
return __privateGet(this, _ApiRequest_instances, isFormContentType_get) ? this.readBodyFormData() : this.readBodyJson();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Reads the request body as an {@link ArrayBuffer}.
|
|
93
|
+
*
|
|
94
|
+
* @returns The result of the body parsing
|
|
95
|
+
*/
|
|
96
|
+
readBodyArrayBuffer() {
|
|
97
|
+
return this.asWeb().arrayBuffer();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Reads the request body as a {@link Blob}.
|
|
101
|
+
*
|
|
102
|
+
* @returns The result of the body parsing
|
|
103
|
+
*/
|
|
104
|
+
readBodyBlob() {
|
|
105
|
+
return this.asWeb().blob();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Reads the request body as a {@link FormData}.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
*
|
|
112
|
+
* This will throw an error if the content type is not one of the following:
|
|
113
|
+
*
|
|
114
|
+
* - `application/x-www-form-urlencoded`
|
|
115
|
+
* - `multipart/form-data`
|
|
116
|
+
*
|
|
117
|
+
* @returns The result of the body parsing
|
|
118
|
+
*/
|
|
119
|
+
readBodyFormData() {
|
|
120
|
+
return this.asWeb().formData();
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Reads the request body as text, using {@link TextDecoder}. Afterward, it
|
|
124
|
+
* parses the body as JSON with {@link JSON.parse}.
|
|
125
|
+
*
|
|
126
|
+
* @returns The result of the body parsing
|
|
127
|
+
*/
|
|
128
|
+
readBodyJson() {
|
|
129
|
+
return this.asWeb().json();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Reads the request body as text, using {@link TextDecoder}.
|
|
133
|
+
*
|
|
134
|
+
* @returns The result of the body parsing
|
|
135
|
+
*/
|
|
136
|
+
readBodyText() {
|
|
137
|
+
return this.asWeb().text();
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Identical to {@link ApiRequest.readBody}, but it validates the result.
|
|
141
|
+
*
|
|
142
|
+
* @param validator The validator function to use on the body parsing result
|
|
143
|
+
* @returns The validated body
|
|
144
|
+
*/
|
|
145
|
+
readValidatedBody(validator) {
|
|
146
|
+
return this.readBody().then(validator);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Identical to {@link ApiRequest.readBodyFormData}, but it validates the
|
|
150
|
+
* result.
|
|
151
|
+
*
|
|
152
|
+
* @param validator The validator function to use on the body parsing result
|
|
153
|
+
* @returns The validated body
|
|
154
|
+
*/
|
|
155
|
+
readValidatedBodyFormData(validator) {
|
|
156
|
+
return this.readBodyFormData().then(validator);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Identical to {@link ApiRequest.readBodyJson}, but it validates the result.
|
|
160
|
+
*
|
|
161
|
+
* @param validator The validator function to use on the body parsing result
|
|
162
|
+
* @returns The validated body
|
|
163
|
+
*/
|
|
164
|
+
readValidatedBodyJson(validator) {
|
|
165
|
+
return this.readBodyJson().then(validator);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Identical to {@link ApiRequest.readBodyText}, but it validates the result.
|
|
169
|
+
*
|
|
170
|
+
* @param validator The validator function to use on the body parsing result
|
|
171
|
+
* @returns The validated body
|
|
172
|
+
*/
|
|
173
|
+
readValidatedBodyText(validator) {
|
|
174
|
+
return this.readBodyText().then(validator);
|
|
32
175
|
}
|
|
33
176
|
};
|
|
177
|
+
_cachedRequest = new WeakMap();
|
|
178
|
+
_ApiRequest_instances = new WeakSet();
|
|
179
|
+
isFormContentType_get = /* @__PURE__ */ __name(function() {
|
|
180
|
+
const contentType = this.asWeb().headers.get("content-type");
|
|
181
|
+
if (utilities.isNullishOrEmpty(contentType)) return false;
|
|
182
|
+
return contentType.startsWith("application/x-www-form-urlencoded") || contentType.startsWith("multipart/form-data");
|
|
183
|
+
}, "#isFormContentType");
|
|
34
184
|
__name(_ApiRequest, "ApiRequest");
|
|
35
185
|
var ApiRequest = _ApiRequest;
|
|
36
186
|
|
|
37
187
|
exports.ApiRequest = ApiRequest;
|
|
38
|
-
//# sourceMappingURL=
|
|
188
|
+
//# sourceMappingURL=ApiRequest.cjs.map
|
|
39
189
|
//# sourceMappingURL=ApiRequest.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/api/ApiRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/api/ApiRequest.ts"],"names":["IncomingMessage","RequestProxy","isNullishOrEmpty"],"mappings":"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","file":"ApiRequest.cjs","sourcesContent":["import { isNullishOrEmpty } from '@sapphire/utilities';\nimport { IncomingMessage } from 'node:http';\nimport type { MimeType } from '../../utils/MimeType';\nimport { RequestProxy } from '../../utils/_body/RequestProxy';\nimport type { Route } from '../Route';\nimport type { AuthData } from '../http/Auth';\nimport type { RouterNode } from '../router/RouterNode';\n\nexport class ApiRequest extends IncomingMessage {\n\t/**\n\t * The query parameters.\n\t */\n\tpublic query: Record<string, string | string[]> = {};\n\n\t/**\n\t * The URI parameters.\n\t */\n\tpublic params: Record<string, string> = {};\n\n\t/**\n\t * The authorization information. This field indicates three possible values:\n\t *\n\t * - `undefined`: The authorization middleware has not been executed yet.\n\t * - `null`: The user is not authorized.\n\t * - `AuthData`: The user is authorized.\n\t */\n\tpublic auth?: AuthData | null;\n\n\t/**\n\t * The router node that matched the request. The field indicates three\n\t * possible values:\n\t *\n\t * - `undefined`: The router handler has not been executed yet.\n\t * - `null`: The router handler has been executed, but no node matched the\n\t * request.\n\t * - `RouterNode`: The router handler has been executed and a node matched\n\t * the request.\n\t *\n\t * @since 7.0.0\n\t */\n\tpublic routerNode?: RouterNode | null;\n\n\t/**\n\t * The route that matched the request. The field indicates three possible\n\t * values:\n\t *\n\t * - `undefined`: The router handler has not been executed yet.\n\t * - `null`: The router handler has been executed, but no route matched the\n\t * request.\n\t * - `Route`: The router handler has been executed and a route matched the\n\t * request.\n\t *\n\t * @since 7.0.0\n\t */\n\tpublic route?: Route | null;\n\n\t/**\n\t * The response object. This field is cached to prevent multiple response\n\t * objects from being created.\n\t */\n\t#cachedRequest: Request | null = null;\n\n\tget #isFormContentType() {\n\t\tconst contentType = this.asWeb().headers.get('content-type') as MimeType | null;\n\n\t\t// If Content-Type isn't sent, we can't assume it's a form.\n\t\tif (isNullishOrEmpty(contentType)) return false;\n\n\t\t// If the Content-Type is application/x-www-form-urlencoded or multipart/form-data, it's a form.\n\t\treturn contentType.startsWith('application/x-www-form-urlencoded') || contentType.startsWith('multipart/form-data');\n\t}\n\n\t/**\n\t * The response object, used to validate the request's headers and body.\n\t */\n\tpublic asWeb(): Request {\n\t\tthis.#cachedRequest ??= new RequestProxy(this);\n\t\treturn this.#cachedRequest;\n\t}\n\n\t/**\n\t * Reads the request body and tries to parse using JSON or form-urlencoded.\n\t *\n\t * @example\n\t * ```typescript\n\t * const body = await request.readBody();\n\t * ```\n\t *\n\t * @returns The result of the body parsing\n\t */\n\tpublic readBody() {\n\t\treturn this.#isFormContentType ? this.readBodyFormData() : this.readBodyJson();\n\t}\n\n\t/**\n\t * Reads the request body as an {@link ArrayBuffer}.\n\t *\n\t * @returns The result of the body parsing\n\t */\n\tpublic readBodyArrayBuffer() {\n\t\treturn this.asWeb().arrayBuffer();\n\t}\n\n\t/**\n\t * Reads the request body as a {@link Blob}.\n\t *\n\t * @returns The result of the body parsing\n\t */\n\tpublic readBodyBlob() {\n\t\treturn this.asWeb().blob();\n\t}\n\n\t/**\n\t * Reads the request body as a {@link FormData}.\n\t *\n\t * @remarks\n\t *\n\t * This will throw an error if the content type is not one of the following:\n\t *\n\t * - `application/x-www-form-urlencoded`\n\t * - `multipart/form-data`\n\t *\n\t * @returns The result of the body parsing\n\t */\n\tpublic readBodyFormData() {\n\t\treturn this.asWeb().formData(); // NOSONAR\n\t}\n\n\t/**\n\t * Reads the request body as text, using {@link TextDecoder}. Afterward, it\n\t * parses the body as JSON with {@link JSON.parse}.\n\t *\n\t * @returns The result of the body parsing\n\t */\n\tpublic readBodyJson() {\n\t\treturn this.asWeb().json();\n\t}\n\n\t/**\n\t * Reads the request body as text, using {@link TextDecoder}.\n\t *\n\t * @returns The result of the body parsing\n\t */\n\tpublic readBodyText() {\n\t\treturn this.asWeb().text();\n\t}\n\n\t/**\n\t * Identical to {@link ApiRequest.readBody}, but it validates the result.\n\t *\n\t * @param validator The validator function to use on the body parsing result\n\t * @returns The validated body\n\t */\n\tpublic readValidatedBody<Type>(validator: ValidatorFunction<unknown, Type>) {\n\t\treturn this.readBody().then(validator);\n\t}\n\n\t/**\n\t * Identical to {@link ApiRequest.readBodyFormData}, but it validates the\n\t * result.\n\t *\n\t * @param validator The validator function to use on the body parsing result\n\t * @returns The validated body\n\t */\n\tpublic readValidatedBodyFormData<Type extends FormData>(validator: ValidatorFunction<FormData, Type>) {\n\t\treturn this.readBodyFormData().then(validator);\n\t}\n\n\t/**\n\t * Identical to {@link ApiRequest.readBodyJson}, but it validates the result.\n\t *\n\t * @param validator The validator function to use on the body parsing result\n\t * @returns The validated body\n\t */\n\tpublic readValidatedBodyJson<Type>(validator: ValidatorFunction<unknown, Type>) {\n\t\treturn this.readBodyJson().then(validator);\n\t}\n\n\t/**\n\t * Identical to {@link ApiRequest.readBodyText}, but it validates the result.\n\t *\n\t * @param validator The validator function to use on the body parsing result\n\t * @returns The validated body\n\t */\n\tpublic readValidatedBodyText<Type extends string>(validator: ValidatorFunction<string, Type>) {\n\t\treturn this.readBodyText().then(validator);\n\t}\n}\n\nexport type ValidatorFunction<Data, Type extends Data> = (data: Data) => Type | ((data: Data) => data is Type);\n"]}
|
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
var http = require('http');
|
|
4
4
|
var stream = require('stream');
|
|
5
5
|
require('stream/web');
|
|
6
|
-
var MimeTypes_cjs = require('../../utils/MimeTypes.cjs');
|
|
7
6
|
var HttpCodes_cjs = require('../http/HttpCodes.cjs');
|
|
8
7
|
|
|
9
8
|
var __defProp = Object.defineProperty;
|
|
10
9
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
10
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj,
|
|
11
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
13
12
|
var _ApiResponse = class _ApiResponse extends http.ServerResponse {
|
|
14
13
|
constructor() {
|
|
15
14
|
super(...arguments);
|
|
@@ -63,6 +62,12 @@ var _ApiResponse = class _ApiResponse extends http.ServerResponse {
|
|
|
63
62
|
notFound(data) {
|
|
64
63
|
return this.error(HttpCodes_cjs.HttpCodes.NotFound, data);
|
|
65
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* @since 7.0.0
|
|
67
|
+
*/
|
|
68
|
+
methodNotAllowed(data) {
|
|
69
|
+
return this.error(HttpCodes_cjs.HttpCodes.MethodNotAllowed, data);
|
|
70
|
+
}
|
|
66
71
|
/**
|
|
67
72
|
* @since 1.0.0
|
|
68
73
|
*/
|
|
@@ -95,20 +100,20 @@ var _ApiResponse = class _ApiResponse extends http.ServerResponse {
|
|
|
95
100
|
* @since 1.0.0
|
|
96
101
|
*/
|
|
97
102
|
json(data) {
|
|
98
|
-
this.setContentType(
|
|
103
|
+
this.setContentType("application/json").end(JSON.stringify(data));
|
|
99
104
|
}
|
|
100
105
|
/**
|
|
101
106
|
* @since 1.0.0
|
|
102
107
|
*/
|
|
103
108
|
text(data) {
|
|
104
|
-
this.setContentType(
|
|
109
|
+
this.setContentType("text/plain").end(data);
|
|
105
110
|
}
|
|
106
111
|
/**
|
|
107
112
|
* @since 6.1.0
|
|
108
113
|
*
|
|
109
114
|
* Sets the image content type and sends the image data in the response.
|
|
110
115
|
*
|
|
111
|
-
* @param type - The MIME type of the image (e.g.,
|
|
116
|
+
* @param type - The MIME type of the image (e.g., 'image/png').
|
|
112
117
|
* @param data - The image data as a `string`, {@link Buffer}, {@link Uint8Array}, or {@link ReadableStream}.
|
|
113
118
|
*/
|
|
114
119
|
image(type, data) {
|
|
@@ -123,7 +128,7 @@ var _ApiResponse = class _ApiResponse extends http.ServerResponse {
|
|
|
123
128
|
* @since 5.1.0
|
|
124
129
|
*/
|
|
125
130
|
html(code, data) {
|
|
126
|
-
this.setContentType(
|
|
131
|
+
this.setContentType("text/html").status(code).end(data);
|
|
127
132
|
}
|
|
128
133
|
/**
|
|
129
134
|
* @since 1.0.0
|
|
@@ -137,5 +142,5 @@ __name(_ApiResponse, "ApiResponse");
|
|
|
137
142
|
var ApiResponse = _ApiResponse;
|
|
138
143
|
|
|
139
144
|
exports.ApiResponse = ApiResponse;
|
|
140
|
-
//# sourceMappingURL=
|
|
145
|
+
//# sourceMappingURL=ApiResponse.cjs.map
|
|
141
146
|
//# sourceMappingURL=ApiResponse.cjs.map
|