@sapphire/plugin-api 7.0.0-next.03b2a90 → 7.0.0-next.26d4b68
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/dist/cjs/index.cjs +22 -8
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +207 -114
- package/dist/cjs/lib/structures/Middleware.cjs.map +1 -1
- package/dist/cjs/lib/structures/MiddlewareStore.cjs +2 -2
- package/dist/cjs/lib/structures/MiddlewareStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/Route.cjs +14 -11
- package/dist/cjs/lib/structures/Route.cjs.map +1 -1
- package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs +2 -10
- package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs.map +1 -1
- package/dist/cjs/lib/structures/RouteStore.cjs +2 -40
- package/dist/cjs/lib/structures/RouteStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/ApiRequest.cjs +26 -0
- package/dist/cjs/lib/structures/api/ApiRequest.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/ApiResponse.cjs +6 -0
- package/dist/cjs/lib/structures/api/ApiResponse.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/Server.cjs +15 -14
- 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/listeners/PluginRouteError.cjs +2 -2
- package/dist/cjs/listeners/PluginRouteError.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerMiddlewareError.cjs +2 -2
- package/dist/cjs/listeners/PluginServerMiddlewareError.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs +4 -4
- package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerRequest.cjs +41 -7
- package/dist/cjs/listeners/PluginServerRequest.cjs.map +1 -1
- package/dist/cjs/listeners/{PluginServerMatch.cjs → PluginServerRouterBranchMethodNotAllowed.cjs} +4 -9
- package/dist/cjs/listeners/PluginServerRouterBranchMethodNotAllowed.cjs.map +1 -0
- package/dist/cjs/listeners/{PluginServerNoMatch.cjs → PluginServerRouterBranchNotFound.cjs} +2 -2
- 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 +6 -4
- package/dist/cjs/listeners/_load.cjs.map +1 -1
- package/dist/cjs/middlewares/body.cjs +4 -3
- package/dist/cjs/middlewares/body.cjs.map +1 -1
- package/dist/cjs/middlewares/headers.cjs +9 -10
- package/dist/cjs/middlewares/headers.cjs.map +1 -1
- package/dist/esm/{chunk-JTFKMR4I.mjs → chunk-S573YWRP.mjs} +3 -2
- package/dist/esm/index.d.mts +207 -114
- package/dist/esm/index.mjs +5 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/structures/MediaParser.mjs +1 -1
- package/dist/esm/lib/structures/MediaParserStore.mjs +1 -1
- package/dist/esm/lib/structures/Middleware.mjs +1 -1
- package/dist/esm/lib/structures/Middleware.mjs.map +1 -1
- package/dist/esm/lib/structures/MiddlewareStore.mjs +3 -3
- package/dist/esm/lib/structures/MiddlewareStore.mjs.map +1 -1
- package/dist/esm/lib/structures/Route.mjs +15 -12
- package/dist/esm/lib/structures/Route.mjs.map +1 -1
- package/dist/esm/lib/structures/RouteLoaderStrategy.mjs +3 -11
- package/dist/esm/lib/structures/RouteLoaderStrategy.mjs.map +1 -1
- package/dist/esm/lib/structures/RouteStore.mjs +3 -41
- package/dist/esm/lib/structures/RouteStore.mjs.map +1 -1
- package/dist/esm/lib/structures/api/ApiRequest.mjs +27 -1
- package/dist/esm/lib/structures/api/ApiRequest.mjs.map +1 -1
- package/dist/esm/lib/structures/api/ApiResponse.mjs +7 -1
- package/dist/esm/lib/structures/api/ApiResponse.mjs.map +1 -1
- package/dist/esm/lib/structures/api/CookieStore.mjs +1 -1
- package/dist/esm/lib/structures/http/Auth.mjs +1 -1
- package/dist/esm/lib/structures/http/HttpCodes.mjs +1 -1
- package/dist/esm/lib/structures/http/HttpMethods.mjs +1 -1
- package/dist/esm/lib/structures/http/Server.mjs +16 -15
- 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 +1 -1
- package/dist/esm/listeners/PluginRouteError.mjs +4 -4
- package/dist/esm/listeners/PluginRouteError.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerMiddlewareError.mjs +4 -4
- package/dist/esm/listeners/PluginServerMiddlewareError.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs +6 -6
- package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerRequest.mjs +37 -9
- 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} +4 -4
- 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 +13 -11
- package/dist/esm/listeners/_load.mjs.map +1 -1
- package/dist/esm/mediaParsers/_load.mjs +1 -1
- package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs +1 -1
- package/dist/esm/mediaParsers/applicationJson.mjs +1 -1
- package/dist/esm/mediaParsers/textPlain.mjs +1 -1
- package/dist/esm/middlewares/_load.mjs +1 -1
- package/dist/esm/middlewares/auth.mjs +1 -1
- package/dist/esm/middlewares/body.mjs +5 -4
- package/dist/esm/middlewares/body.mjs.map +1 -1
- package/dist/esm/middlewares/cookies.mjs +1 -1
- package/dist/esm/middlewares/headers.mjs +10 -11
- package/dist/esm/middlewares/headers.mjs.map +1 -1
- package/dist/esm/register.mjs +1 -1
- package/dist/esm/routes/_load.mjs +1 -1
- package/dist/esm/routes/oauth/callback.post.mjs +1 -1
- package/dist/esm/routes/oauth/logout.post.mjs +1 -1
- package/package.json +4 -3
- 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/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/{chunk-JTFKMR4I.mjs.map → chunk-S573YWRP.mjs.map} +0 -0
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.26d4b68";
|
|
25
27
|
|
|
26
28
|
Object.defineProperty(exports, "loadListeners", {
|
|
27
29
|
enumerable: true,
|
|
@@ -112,22 +114,34 @@ 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
147
|
//# sourceMappingURL=out.js.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";AAKA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AA+BpB,IAAM,UAAkB","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/
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";AAKA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AA+BpB,IAAM,UAAkB","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.26d4b68';\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":["../../../../src/lib/structures/Middleware.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/Middleware.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AAQf,IAAe,cAAf,MAAe,oBAA4E,MAA8B;AAAA,EAaxH,YAAY,SAAmC,UAAmB,CAAC,GAAc;AACvF,UAAM,SAAS,OAAO;AAHvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAIf,SAAK,WAAW,QAAQ,YAAY;AAAA,EACrC;AASD;AAzBgI;AAAzH,IAAe,aAAf","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"]}
|
|
@@ -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) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,kBAAkB;
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAKpB,IAAM,mBAAN,MAAM,yBAAwB,MAAiC;AAAA,EAM9D,cAAc;AACpB,UAAM,YAAY,EAAE,MAAM,cAAc,CAAC;AAH1C;AAAA;AAAA;AAAA,wBAAgB,qBAAkC,CAAC;AAAA,EAInD;AAAA,EAEA,MAAa,IAAI,SAA6B,UAA8C;AAC3F,eAAW,cAAc,KAAK,mBAAmB;AAChD,UAAI,SAAS,cAAe;AAC5B,UAAI,WAAW,QAAS,OAAM,WAAW,IAAI,SAAS,QAAQ;AAAA,IAC/D;AAAA,EACD;AAAA,EAEgB,IAAI,KAAa,OAAyB;AACzD,UAAM,QAAQ,KAAK,kBAAkB,UAAU,CAAC,eAAe,WAAW,YAAY,MAAM,QAAQ;AAGpG,QAAI,UAAU,GAAI,MAAK,kBAAkB,KAAK,KAAK;AAAA,QAC9C,MAAK,kBAAkB,OAAO,OAAO,GAAG,KAAK;AAElD,WAAO,MAAM,IAAI,KAAK,KAAK;AAAA,EAC5B;AAAA,EAEgB,OAAO,KAAsB;AAC5C,UAAM,QAAQ,KAAK,kBAAkB,UAAU,CAAC,eAAe,WAAW,SAAS,GAAG;AAGtF,QAAI,UAAU,GAAI,MAAK,kBAAkB,OAAO,OAAO,CAAC;AAExD,WAAO,MAAM,OAAO,GAAG;AAAA,EACxB;AAAA,EAEgB,QAAc;AAC7B,SAAK,kBAAkB,SAAS;AAChC,WAAO,MAAM,MAAM;AAAA,EACpB;AACD;AAxCsE;AAA/D,IAAM,kBAAN","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,7 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var pieces = require('@sapphire/pieces');
|
|
4
|
-
var
|
|
4
|
+
var utilities = require('@sapphire/utilities');
|
|
5
|
+
var RouterRoot_cjs = require('./router/RouterRoot.cjs');
|
|
5
6
|
|
|
6
7
|
var __defProp = Object.defineProperty;
|
|
7
8
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -19,25 +20,27 @@ var _Route = class _Route extends pieces.Piece {
|
|
|
19
20
|
*/
|
|
20
21
|
__publicField(this, "acceptedContentMimeTypes");
|
|
21
22
|
/**
|
|
22
|
-
* The route
|
|
23
|
+
* The path this route represents.
|
|
23
24
|
*/
|
|
24
|
-
__publicField(this, "
|
|
25
|
+
__publicField(this, "path");
|
|
25
26
|
/**
|
|
26
27
|
* The methods this route accepts.
|
|
27
28
|
*/
|
|
28
29
|
__publicField(this, "methods");
|
|
29
30
|
const api = this.container.server.options;
|
|
30
|
-
const
|
|
31
|
-
|
|
31
|
+
const path = [].concat(
|
|
32
|
+
RouterRoot_cjs.RouterRoot.normalize(api.prefix),
|
|
33
|
+
RouterRoot_cjs.RouterRoot.normalize(options.route ?? (this.location.virtual ? this.name : this.location.directories.concat(this.name).join("/")))
|
|
34
|
+
);
|
|
32
35
|
const methods = new Set(options.methods);
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const implied = RouterRoot_cjs.RouterRoot.extractMethod(path);
|
|
37
|
+
if (!utilities.isNullish(implied)) {
|
|
38
|
+
const lastIndex = path.length - 1;
|
|
39
|
+
path[lastIndex] = path[lastIndex].slice(0, path[lastIndex].length - implied.length - 1);
|
|
40
|
+
methods.add(implied);
|
|
38
41
|
}
|
|
42
|
+
this.path = path;
|
|
39
43
|
this.methods = methods;
|
|
40
|
-
this.router = new RouteData_cjs.RouteData(`${prefix}${path}`);
|
|
41
44
|
this.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;
|
|
42
45
|
this.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;
|
|
43
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,iBAAiC;AAK1C,SAAS,kBAAkB;AAuCpB,IAAe,SAAf,MAAe,eAA6D,MAAyB;AAAA,EAqBpG,YAAY,SAA8B,UAAmB,CAAC,GAAc;AAClF,UAAM,SAAS,OAAO;AAlBvB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB;AAKf,UAAM,MAAM,KAAK,UAAU,OAAO;AAClC,UAAM,OAAQ,CAAC,EAAe;AAAA,MAC7B,WAAW,UAAU,IAAI,MAAM;AAAA,MAC/B,WAAW,UAAU,QAAQ,UAAU,KAAK,SAAS,UAAU,KAAK,OAAO,KAAK,SAAS,YAAY,OAAO,KAAK,IAAI,EAAE,KAAK,GAAG,EAAE;AAAA,IAClI;AAEA,UAAM,UAAU,IAAI,IAAI,QAAQ,OAAO;AACvC,UAAM,UAAU,WAAW,cAAc,IAAI;AAC7C,QAAI,CAAC,UAAU,OAAO,GAAG;AACxB,YAAM,YAAY,KAAK,SAAS;AAChC,WAAK,SAAS,IAAI,KAAK,SAAS,EAAE,MAAM,GAAG,KAAK,SAAS,EAAE,SAAS,QAAQ,SAAS,CAAC;AACtF,cAAQ,IAAI,OAAqB;AAAA,IAClC;AAEA,SAAK,OAAO;AACZ,SAAK,UAAU;AACf,SAAK,oBAAoB,QAAQ,qBAAqB,IAAI,qBAAqB,OAAO,OAAO;AAC7F,SAAK,2BAA2B,QAAQ,4BAA4B,IAAI,4BAA4B;AAAA,EACrG;AAGD;AA7C4G;AAArG,IAAe,QAAf","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 type { MimeTypeWithoutParameters } from './http/Server';\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 accepted content types.\n\t */\n\tpublic readonly acceptedContentMimeTypes: readonly MimeTypeWithoutParameters[] | null;\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 = ([] as string[]).concat(\n\t\t\tRouterRoot.normalize(api.prefix),\n\t\t\tRouterRoot.normalize(options.route ?? (this.location.virtual ? this.name : this.location.directories.concat(this.name).join('/')))\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 as MethodName);\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\tthis.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;\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 accepted content types for this route. If set to null, the route will accept any data.\n\t * @since 1.3.0\n\t *\n\t * @defaultValue this.context.server.options.acceptedContentMimeTypes ?? null\n\t */\n\tacceptedContentMimeTypes?: readonly MimeTypeWithoutParameters[] | null;\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;\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"]}
|
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var pieces = require('@sapphire/pieces');
|
|
4
|
-
var discord_js = require('discord.js');
|
|
5
4
|
|
|
6
5
|
var __defProp = Object.defineProperty;
|
|
7
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
7
|
var _RouteLoaderStrategy = class _RouteLoaderStrategy extends pieces.LoaderStrategy {
|
|
9
8
|
onLoad(store, piece) {
|
|
10
|
-
|
|
11
|
-
store.methods.ensure(method, () => new discord_js.Collection()).set(piece, piece.router);
|
|
12
|
-
}
|
|
9
|
+
store.router.add(piece);
|
|
13
10
|
}
|
|
14
11
|
onUnload(store, piece) {
|
|
15
|
-
|
|
16
|
-
const methods = store.methods.get(method);
|
|
17
|
-
if (typeof methods === "undefined") continue;
|
|
18
|
-
methods.delete(piece);
|
|
19
|
-
if (methods.size === 0) store.methods.delete(method);
|
|
20
|
-
}
|
|
12
|
+
store.router.remove(piece);
|
|
21
13
|
}
|
|
22
14
|
};
|
|
23
15
|
__name(_RouteLoaderStrategy, "RouteLoaderStrategy");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/RouteLoaderStrategy.ts"],"names":[],"mappings":";;;;AAAA,SAAS,sBAAsB;
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/RouteLoaderStrategy.ts"],"names":[],"mappings":";;;;AAAA,SAAS,sBAAsB;AAIxB,IAAM,uBAAN,MAAM,6BAA4B,eAAsB;AAAA,EAC9C,OAAO,OAAmB,OAAoB;AAC7D,UAAM,OAAO,IAAI,KAAK;AAAA,EACvB;AAAA,EAEgB,SAAS,OAAmB,OAAoB;AAC/D,UAAM,OAAO,OAAO,KAAK;AAAA,EAC1B;AACD;AAR+D;AAAxD,IAAM,sBAAN","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"]}
|