@sapphire/plugin-api 8.3.2-next.83a86a1 → 8.3.2-next.83d2d44
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 +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/lib/structures/Middleware.cjs.map +1 -1
- package/dist/cjs/lib/structures/MiddlewareStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/Route.cjs.map +1 -1
- package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs.map +1 -1
- package/dist/cjs/lib/structures/RouteStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/ApiRequest.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/ApiResponse.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/CookieStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/Auth.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/HttpCodes.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/HttpMethods.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/Server.cjs.map +1 -1
- package/dist/cjs/lib/structures/router/RouterBranch.cjs.map +1 -1
- package/dist/cjs/lib/structures/router/RouterNode.cjs.map +1 -1
- package/dist/cjs/lib/structures/router/RouterRoot.cjs.map +1 -1
- package/dist/cjs/lib/utils/_body/RequestHeadersProxy.cjs.map +1 -1
- package/dist/cjs/lib/utils/_body/RequestProxy.cjs.map +1 -1
- package/dist/cjs/lib/utils/_body/RequestURLProxy.cjs.map +1 -1
- package/dist/cjs/lib/utils/constants.cjs.map +1 -1
- package/dist/cjs/listeners/PluginRouteError.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerMiddlewareError.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerRequest.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerRouterBranchMethodNotAllowed.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerRouterBranchNotFound.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerRouterFound.cjs.map +1 -1
- package/dist/cjs/listeners/_load.cjs.map +1 -1
- package/dist/cjs/middlewares/_load.cjs.map +1 -1
- package/dist/cjs/middlewares/auth.cjs.map +1 -1
- package/dist/cjs/middlewares/body.cjs.map +1 -1
- package/dist/cjs/middlewares/cookies.cjs.map +1 -1
- package/dist/cjs/middlewares/headers.cjs.map +1 -1
- package/dist/cjs/register.cjs.map +1 -1
- package/dist/cjs/routes/_load.cjs.map +1 -1
- package/dist/cjs/routes/oauth/callback.post.cjs.map +1 -1
- package/dist/cjs/routes/oauth/logout.post.cjs.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/structures/Middleware.mjs.map +1 -1
- package/dist/esm/lib/structures/MiddlewareStore.mjs.map +1 -1
- package/dist/esm/lib/structures/Route.mjs.map +1 -1
- package/dist/esm/lib/structures/RouteLoaderStrategy.mjs.map +1 -1
- package/dist/esm/lib/structures/RouteStore.mjs.map +1 -1
- package/dist/esm/lib/structures/api/ApiRequest.mjs.map +1 -1
- package/dist/esm/lib/structures/api/ApiResponse.mjs.map +1 -1
- package/dist/esm/lib/structures/api/CookieStore.mjs.map +1 -1
- package/dist/esm/lib/structures/http/Auth.mjs.map +1 -1
- package/dist/esm/lib/structures/http/HttpCodes.mjs.map +1 -1
- package/dist/esm/lib/structures/http/HttpMethods.mjs.map +1 -1
- package/dist/esm/lib/structures/http/Server.mjs.map +1 -1
- package/dist/esm/lib/structures/router/RouterBranch.mjs.map +1 -1
- package/dist/esm/lib/structures/router/RouterNode.mjs.map +1 -1
- package/dist/esm/lib/structures/router/RouterRoot.mjs.map +1 -1
- package/dist/esm/lib/utils/_body/RequestHeadersProxy.mjs.map +1 -1
- package/dist/esm/lib/utils/_body/RequestProxy.mjs.map +1 -1
- package/dist/esm/lib/utils/_body/RequestURLProxy.mjs.map +1 -1
- package/dist/esm/lib/utils/constants.mjs.map +1 -1
- package/dist/esm/listeners/PluginRouteError.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerMiddlewareError.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerRequest.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerRouterBranchMethodNotAllowed.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerRouterBranchNotFound.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerRouterFound.mjs.map +1 -1
- package/dist/esm/listeners/_load.mjs.map +1 -1
- package/dist/esm/middlewares/_load.mjs.map +1 -1
- package/dist/esm/middlewares/auth.mjs.map +1 -1
- package/dist/esm/middlewares/body.mjs.map +1 -1
- package/dist/esm/middlewares/cookies.mjs.map +1 -1
- package/dist/esm/middlewares/headers.mjs.map +1 -1
- package/dist/esm/register.mjs.map +1 -1
- package/dist/esm/routes/_load.mjs.map +1 -1
- package/dist/esm/routes/oauth/callback.post.mjs.map +1 -1
- package/dist/esm/routes/oauth/logout.post.mjs.map +1 -1
- package/package.json +5 -5
package/dist/cjs/index.cjs
CHANGED
|
@@ -19,7 +19,7 @@ var _load_cjs$1 = require('./middlewares/_load.cjs');
|
|
|
19
19
|
var _load_cjs$2 = require('./routes/_load.cjs');
|
|
20
20
|
|
|
21
21
|
// src/index.ts
|
|
22
|
-
var version = "8.3.2-next.
|
|
22
|
+
var version = "8.3.2-next.83d2d44";
|
|
23
23
|
|
|
24
24
|
Object.defineProperty(exports, "loadListeners", {
|
|
25
25
|
enumerable: true,
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoDO,IAAM,
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoDO,IAAM,OAAA,GAAkB","file":"index.cjs","sourcesContent":["import type { Server, ServerOptions } from './lib/structures/http/Server';\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/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 type * from '@sapphire/iana-mime-types';\n\nexport { loadListeners } from './listeners/_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\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 = '8.3.2-next.83d2d44';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/Middleware.ts"],"names":["Piece"],"mappings":";;;;;;;;AAQO,IAAe,WAAA,GAAf,MAAe,WAAA,SAA4EA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/Middleware.ts"],"names":["Piece"],"mappings":";;;;;;;;AAQO,IAAe,WAAA,GAAf,MAAe,WAAA,SAA4EA,YAAA,CAA8B;AAAA,EAaxH,WAAA,CAAY,OAAA,EAAmC,OAAA,GAAmB,EAAC,EAAc;AACvF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAHvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,UAAA,CAAA;AAIf,IAAA,IAAA,CAAK,QAAA,GAAW,QAAQ,QAAA,IAAY,GAAA;AAAA,EACrC;AASD,CAAA;AAzBgI,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAAzH,IAAe,UAAA,GAAf","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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":["Store","Middleware"],"mappings":";;;;;;;;;AAMO,IAAM,gBAAA,GAAN,MAAM,gBAAA,SAAwBA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":["Store","Middleware"],"mappings":";;;;;;;;;AAMO,IAAM,gBAAA,GAAN,MAAM,gBAAA,SAAwBA,YAAA,CAAiC;AAAA,EAM9D,WAAA,GAAc;AACpB,IAAA,KAAA,CAAMC,yBAAA,EAAY,EAAE,IAAA,EAAM,aAAA,EAAe,CAAA;AAH1C;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,qBAAkC,EAAC,CAAA;AAAA,EAInD;AAAA,EAEA,MAAa,GAAA,CAAI,OAAA,EAA6B,QAAA,EAA8C;AAC3F,IAAA,KAAA,MAAW,UAAA,IAAc,KAAK,iBAAA,EAAmB;AAChD,MAAA,IAAI,SAAS,aAAA,EAAe;AAC5B,MAAA,IAAI,WAAW,OAAA,EAAS,MAAM,UAAA,CAAW,GAAA,CAAI,SAAS,QAAQ,CAAA;AAAA,IAC/D;AAAA,EACD;AAAA,EAEgB,GAAA,CAAI,KAAa,KAAA,EAAyB;AACzD,IAAA,MAAM,KAAA,GAAQ,KAAK,iBAAA,CAAkB,SAAA,CAAU,CAAC,UAAA,KAAe,UAAA,CAAW,QAAA,IAAY,KAAA,CAAM,QAAQ,CAAA;AAGpG,IAAA,IAAI,KAAA,KAAU,EAAA,EAAI,IAAA,CAAK,iBAAA,CAAkB,KAAK,KAAK,CAAA;AAAA,SAC9C,IAAA,CAAK,iBAAA,CAAkB,MAAA,CAAO,KAAA,EAAO,GAAG,KAAK,CAAA;AAElD,IAAA,OAAO,KAAA,CAAM,GAAA,CAAI,GAAA,EAAK,KAAK,CAAA;AAAA,EAC5B;AAAA,EAEgB,OAAO,GAAA,EAAsB;AAC5C,IAAA,MAAM,KAAA,GAAQ,KAAK,iBAAA,CAAkB,SAAA,CAAU,CAAC,UAAA,KAAe,UAAA,CAAW,SAAS,GAAG,CAAA;AAGtF,IAAA,IAAI,UAAU,EAAA,EAAI,IAAA,CAAK,iBAAA,CAAkB,MAAA,CAAO,OAAO,CAAC,CAAA;AAExD,IAAA,OAAO,KAAA,CAAM,OAAO,GAAG,CAAA;AAAA,EACxB;AAAA,EAEgB,KAAA,GAAc;AAC7B,IAAA,IAAA,CAAK,kBAAkB,MAAA,GAAS,CAAA;AAChC,IAAA,OAAO,MAAM,KAAA,EAAM;AAAA,EACpB;AACD,CAAA;AAxCsE,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA;AAA/D,IAAM,eAAA,GAAN","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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":["Piece","RouterRoot","isNullish"],"mappings":";;;;;;;;;;AA4CO,IAAe,MAAA,GAAf,MAAe,MAAA,SAA6DA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":["Piece","RouterRoot","isNullish"],"mappings":";;;;;;;;;;AA4CO,IAAe,MAAA,GAAf,MAAe,MAAA,SAA6DA,YAAA,CAAyB;AAAA,EAgBpG,WAAA,CAAY,OAAA,EAA8B,OAAA,GAAmB,EAAC,EAAc;AAClF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAbvB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,mBAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,SAAA,CAAA;AAKf,IAAA,MAAM,GAAA,GAAM,IAAA,CAAK,SAAA,CAAU,MAAA,CAAO,OAAA;AAElC,IAAA,MAAM,IAAA,GAAOC,yBAAA,CAAW,SAAA,CAAU,GAAA,CAAI,MAAM,CAAA;AAC5C,IAAA,MAAM,OAAA,GAAU,IAAI,GAAA,CAAI,OAAA,CAAQ,OAAO,CAAA;AACvC,IAAA,IAAI,QAAQ,KAAA,EAAO;AAElB,MAAA,IAAA,CAAK,KAAK,GAAGA,yBAAA,CAAW,SAAA,CAAU,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IACjD,CAAA,MAAO;AAGN,MAAA,IAAI,WAAW,OAAA,CAAQ,IAAA;AACvB,MAAA,MAAM,OAAA,GAAUA,yBAAA,CAAW,aAAA,CAAc,QAAQ,CAAA;AACjD,MAAA,IAAI,CAACC,mBAAA,CAAU,OAAO,CAAA,EAAG;AACxB,QAAA,QAAA,GAAW,SAAS,KAAA,CAAM,CAAA,EAAG,SAAS,MAAA,GAAS,OAAA,CAAQ,SAAS,CAAC,CAAA;AACjE,QAAA,OAAA,CAAQ,IAAI,OAAO,CAAA;AAAA,MACpB;AAEA,MAAA,IAAA,CAAK,IAAA,CAAK,GAAGD,yBAAA,CAAW,SAAA,CAAUA,yBAAA,CAAW,qBAAA,CAAsB,IAAA,CAAK,QAAA,CAAS,WAAA,EAAa,QAAQ,CAAC,CAAC,CAAA;AAAA,IACzG;AAEA,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,oBAAoB,OAAA,CAAQ,iBAAA,IAAqB,GAAA,CAAI,iBAAA,IAAqB,OAAO,IAAA,GAAO,EAAA;AAAA,EAC9F;AAGD,CAAA;AA7C4G,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA;AAArG,IAAe,KAAA,GAAf","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\n\t\tconst path = RouterRoot.normalize(api.prefix);\n\t\tconst methods = new Set(options.methods);\n\t\tif (options.route) {\n\t\t\t// If a route is specified, no extra processing is made:\n\t\t\tpath.push(...RouterRoot.normalize(options.route));\n\t\t} else {\n\t\t\t// If a route is not specified, extra processing is made to calculate\n\t\t\t// one from the file system if it's possible:\n\t\t\tlet lastPart = context.name;\n\t\t\tconst implied = RouterRoot.extractMethod(lastPart);\n\t\t\tif (!isNullish(implied)) {\n\t\t\t\tlastPart = lastPart.slice(0, lastPart.length - implied.length - 1);\n\t\t\t\tmethods.add(implied);\n\t\t\t}\n\n\t\t\tpath.push(...RouterRoot.normalize(RouterRoot.makeRoutePathForPiece(this.location.directories, lastPart)));\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/RouteLoaderStrategy.ts"],"names":["LoaderStrategy"],"mappings":";;;;;;AAIO,IAAM,oBAAA,GAAN,MAAM,oBAAA,SAA4BA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/RouteLoaderStrategy.ts"],"names":["LoaderStrategy"],"mappings":";;;;;;AAIO,IAAM,oBAAA,GAAN,MAAM,oBAAA,SAA4BA,qBAAA,CAAsB;AAAA,EAC9C,MAAA,CAAO,OAAmB,KAAA,EAAoB;AAC7D,IAAA,KAAA,CAAM,MAAA,CAAO,IAAI,KAAK,CAAA;AAAA,EACvB;AAAA,EAEgB,QAAA,CAAS,OAAmB,KAAA,EAAoB;AAC/D,IAAA,KAAA,CAAM,MAAA,CAAO,OAAO,KAAK,CAAA;AAAA,EAC1B;AACD,CAAA;AAR+D,MAAA,CAAA,oBAAA,EAAA,qBAAA,CAAA;AAAxD,IAAM,mBAAA,GAAN","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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":["Store","Route","RouteLoaderStrategy","RouterRoot"],"mappings":";;;;;;;;;;;AAQO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmBA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":["Store","Route","RouteLoaderStrategy","RouterRoot"],"mappings":";;;;;;;;;;;AAQO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmBA,YAAA,CAAuB;AAAA,EAG/C,WAAA,GAAc;AACpB,IAAA,KAAA,CAAMC,eAAA,EAAO,EAAE,IAAA,EAAM,QAAA,EAAU,UAAU,IAAIC,2CAAA,IAAuB,CAAA;AAHrE,IAAA,aAAA,CAAA,IAAA,EAAgB,QAAA,EAAS,IAAIC,yBAAA,EAAW,CAAA;AAAA,EAIxC;AACD,CAAA;AANuD,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAAhD,IAAM,UAAA,GAAN","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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/api/ApiRequest.ts"],"names":["IncomingMessage","RequestProxy","isNullishOrEmpty"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAA,cAAA,EAAA,qBAAA,EAAA,qBAAA;AAUO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmBA,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/api/ApiRequest.ts"],"names":["IncomingMessage","RequestProxy","isNullishOrEmpty"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAA,cAAA,EAAA,qBAAA,EAAA,qBAAA;AAUO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmBA,oBAAA,CAAgB;AAAA,EAAzC,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAAA,IAAA,YAAA,CAAA,IAAA,EAAA,qBAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,SAA2C,EAAC,CAAA;AAKnD;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,UAAiC,EAAC,CAAA;AASzC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,MAAA,CAAA;AAcP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,YAAA,CAAA;AAcP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA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A,EAAK;AAAA,EAC1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,kBAAwB,SAAA,EAA6C;AAC3E,IAAA,OAAO,IAAA,CAAK,QAAA,EAAS,CAAE,IAAA,CAAK,SAAS,CAAA;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,0BAAgC,SAAA,EAA8C;AACpF,IAAA,OAAO,IAAA,CAAK,gBAAA,EAAiB,CAAE,IAAA,CAAK,SAAS,CAAA;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,sBAA4B,SAAA,EAA6C;AAC/E,IAAA,OAAO,IAAA,CAAK,YAAA,EAAa,CAAE,IAAA,CAAK,SAAS,CAAA;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,sBAA4B,SAAA,EAA4C;AAC9E,IAAA,OAAO,IAAA,CAAK,YAAA,EAAa,CAAE,IAAA,CAAK,SAAS,CAAA;AAAA,EAC1C;AACD,CAAA;AA/HC,cAAA,GAAA,IAAA,OAAA,EAAA;AApDM,qBAAA,GAAA,IAAA,OAAA,EAAA;AAsDF,qBAAA,mBAAkB,MAAA,CAAA,WAAG;AACxB,EAAA,MAAM,cAAc,IAAA,CAAK,KAAA,EAAM,CAAE,OAAA,CAAQ,IAAI,cAAc,CAAA;AAG3D,EAAA,IAAIC,0BAAA,CAAiB,WAAW,CAAA,EAAG,OAAO,KAAA;AAG1C,EAAA,OAAO,YAAY,UAAA,CAAW,mCAAmC,CAAA,IAAK,WAAA,CAAY,WAAW,qBAAqB,CAAA;AACnH,CAAA,EARsB,oBAAA,CAAA;AAtDyB,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAAzC,IAAM,UAAA,GAAN","file":"ApiRequest.cjs","sourcesContent":["import { isNullishOrEmpty } from '@sapphire/utilities';\nimport type { Blob } from 'node:buffer';\nimport { IncomingMessage } from 'node:http';\nimport type { FormData, Request } from 'undici';\nimport type { MimeType } from '@sapphire/iana-mime-types';\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(): Promise<unknown> {\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(): Promise<ArrayBuffer> {\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(): Promise<Blob> {\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(): Promise<FormData> {\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(): Promise<unknown> {\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(): Promise<string> {\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>(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>(validator: ValidatorFunction<string, Type>) {\n\t\treturn this.readBodyText().then(validator);\n\t}\n}\n\nexport type ValidatorFunction<Data, Type> = (data: Data) => Type;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/api/ApiResponse.ts"],"names":["ServerResponse","STATUS_CODES","HttpCodes","Readable"],"mappings":";;;;;;;;;;;AAUO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAuEA,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/api/ApiResponse.ts"],"names":["ServerResponse","STATUS_CODES","HttpCodes","Readable"],"mappings":";;;;;;;;;;;AAUO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAuEA,mBAAA,CAAwB;AAAA,EAArG,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,SAAA,CAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAKA,EAAA,CAAG,IAAA,GAAgBC,iBAAA,CAAaC,uBAAA,CAAU,EAAE,CAAA,EAAS;AA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,CAAM,MAA4C,IAAA,EAAqD;AAC7G,IAAA,IAAI,gBAAgBE,eAAA,EAAU;AAC7B,MAAA,IAAA,CAAK,eAAe,IAAI,CAAA;AACxB,MAAA,IAAA,CAAK,KAAK,IAAI,CAAA;AAAA,IACf,CAAA,MAAO;AACN,MAAA,IAAA,CAAK,cAAA,CAAe,IAAI,CAAA,CAAE,GAAA,CAAI,IAAI,CAAA;AAAA,IACnC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKO,IAAA,CAAK,MAAc,IAAA,EAAoB;AAC7C,IAAA,IAAA,CAAK,eAAe,WAAW,CAAA,CAAE,OAAO,IAAI,CAAA,CAAE,IAAI,IAAI,CAAA;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA,EAKO,eAAe,WAAA,EAA6B;AAClD,IAAA,IAAA,CAAK,SAAA,CAAU,gBAAgB,WAAW,CAAA;AAC1C,IAAA,OAAO,IAAA;AAAA,EACR;AACD,CAAA;AA/I4G,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA;AAArG,IAAM,WAAA,GAAN","file":"ApiResponse.cjs","sourcesContent":["import { IncomingMessage, ServerResponse, STATUS_CODES } from 'node:http';\nimport { Readable } from 'node:stream';\nimport { ReadableStream } from 'node:stream/web';\nimport type { MimeType } from '@sapphire/iana-mime-types';\nimport { HttpCodes } from '../http/HttpCodes';\nimport type { CookieStore } from './CookieStore';\n\n/**\n * @since 1.0.0\n */\nexport class ApiResponse<Request extends IncomingMessage = IncomingMessage> extends ServerResponse<Request> {\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic cookies!: CookieStore;\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic ok(data: unknown = STATUS_CODES[HttpCodes.OK]): void {\n\t\tthis.status(HttpCodes.OK);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic created(data: unknown = STATUS_CODES[HttpCodes.Created]): void {\n\t\tthis.status(HttpCodes.Created);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic noContent(data: unknown = STATUS_CODES[HttpCodes.NoContent]): void {\n\t\tthis.status(HttpCodes.NoContent);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic badRequest(data?: unknown): void {\n\t\treturn this.error(HttpCodes.BadRequest, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic unauthorized(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Unauthorized, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic forbidden(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Forbidden, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic notFound(data?: unknown): void {\n\t\treturn this.error(HttpCodes.NotFound, data);\n\t}\n\n\t/**\n\t * @since 7.0.0\n\t */\n\tpublic methodNotAllowed(data?: unknown): void {\n\t\treturn this.error(HttpCodes.MethodNotAllowed, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic conflict(data?: unknown) {\n\t\treturn this.error(HttpCodes.Conflict, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic error(error: number | string, data?: unknown): void {\n\t\tif (typeof error === 'string') {\n\t\t\treturn this.status(HttpCodes.InternalServerError).json({ error });\n\t\t}\n\n\t\treturn this.status(error).json({ error: data ?? STATUS_CODES[error] });\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic respond(data: unknown): void {\n\t\treturn typeof data === 'string' ? this.text(data) : this.json(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic status(code: number): this {\n\t\tthis.statusCode = code;\n\t\treturn this;\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic json(data: any): void {\n\t\tthis.setContentType('application/json').end(JSON.stringify(data));\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic text(data: string): void {\n\t\tthis.setContentType('text/plain').end(data);\n\t}\n\n\t/**\n\t * @since 6.1.0\n\t *\n\t * Sets the image content type and sends the image data in the response.\n\t *\n\t * @param type - The MIME type of the image (e.g., 'image/png').\n\t * @param data - The image data as a `string`, {@link Buffer}, {@link Uint8Array}, or {@link ReadableStream}.\n\t */\n\tpublic image(type: Extract<MimeType, `image/${string}`>, data: string | Buffer | Uint8Array | Readable): void {\n\t\tif (data instanceof Readable) {\n\t\t\tthis.setContentType(type);\n\t\t\tdata.pipe(this);\n\t\t} else {\n\t\t\tthis.setContentType(type).end(data);\n\t\t}\n\t}\n\n\t/**\n\t * @since 5.1.0\n\t */\n\tpublic html(code: number, data: string): void {\n\t\tthis.setContentType('text/html').status(code).end(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic setContentType(contentType: MimeType): this {\n\t\tthis.setHeader('Content-Type', contentType);\n\t\treturn this;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/api/CookieStore.ts"],"names":["getDomain"],"mappings":";;;;;;;;AAOO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAoB,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/api/CookieStore.ts"],"names":["getDomain"],"mappings":";;;;;;;;AAOO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAoB,GAAA,CAAoB;AAAA,EAM7C,WAAA,CAAY,OAAA,EAAqB,QAAA,EAAuB,MAAA,EAAiB,eAAA,EAAiC;AAChH,IAAA,KAAA,EAAM;AANP,IAAA,aAAA,CAAA,IAAA,EAAU,SAAA,CAAA;AACV,IAAA,aAAA,CAAA,IAAA,EAAU,UAAA,CAAA;AACV,IAAA,aAAA,CAAA,IAAA,EAAQ,QAAA,CAAA;AACR,IAAA,aAAA,CAAA,IAAA,EAAQ,QAAA,CAAA;AAKP,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,IAAA,CAAK,QAAA,GAAW,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cjs","sourcesContent":["// Copyright (c) 2018 Stanislav Woodger. All rights reserved. MIT license.\n// Source: https://github.com/woodger/cookie-httponly\n\nimport { getDomain } from 'tldts';\nimport type { ApiRequest } from './ApiRequest';\nimport type { ApiResponse } from './ApiResponse';\n\nexport class CookieStore extends Map<string, string> {\n\tprotected request: ApiRequest;\n\tprotected response: ApiResponse;\n\tprivate domain: string;\n\tprivate secure: boolean;\n\n\tpublic constructor(request: ApiRequest, response: ApiResponse, secure: boolean, domainOverwrite?: string | null) {\n\t\tsuper();\n\n\t\tthis.request = request;\n\t\tthis.response = response;\n\n\t\t// Read cookies\n\t\tconst { cookie = '' } = request.headers;\n\t\tconst pairs = cookie.split(';');\n\n\t\tfor (const pair of pairs) {\n\t\t\tconst index = pair.indexOf('=');\n\t\t\tif (index === -1) continue;\n\n\t\t\tconst key = decodeURIComponent(pair.slice(0, index).trim());\n\t\t\tconst value = decodeURIComponent(pair.slice(index + 1).trim());\n\t\t\tthis.set(key, value);\n\t\t}\n\n\t\tconst [splitHost] = this.request.headers.host?.split(':') ?? [''];\n\n\t\tthis.domain = domainOverwrite ?? this.getHostDomain(splitHost);\n\n\t\tif (this.request.socket.remoteAddress === this.domain) {\n\t\t\tthrow new Error('The connection must be established from the domain name (i.e., not an IP address)');\n\t\t}\n\n\t\t// RFC 6265 4.1.2.5. The Secure Attribute\n\t\tthis.secure = secure;\n\t}\n\n\tpublic add(name: string, value: string, options?: SecureCookieStoreSetOptions) {\n\t\tthis.insert(name, this.prepare(name, value, options));\n\t}\n\n\tpublic remove(name: string) {\n\t\tthis.add(name, '', { expires: new Date(0) });\n\t}\n\n\tprotected insert(name: string, entry: string) {\n\t\tlet set = this.response.getHeader('Set-Cookie');\n\n\t\tif (set === undefined) {\n\t\t\tset = [];\n\t\t} else if (!Array.isArray(set)) {\n\t\t\tset = [set.toString()];\n\t\t}\n\n\t\tset = set.filter((i) => i.slice(0, i.indexOf('=')) !== name);\n\t\tset.push(entry);\n\n\t\tthis.response.setHeader('Set-Cookie', set);\n\t}\n\n\tprotected prepare(name: string, value: string, { expires, maxAge, domain, path, httpOnly }: SecureCookieStoreSetOptions = {}) {\n\t\tconst now = new Date();\n\n\t\tif (expires === undefined) {\n\t\t\texpires = now;\n\t\t}\n\n\t\t// RFC 6265 4.1.1. Syntax\n\t\tname = CookieStore.encodeCookieOctet(name);\n\t\tvalue = CookieStore.encodeCookieOctet(value);\n\n\t\tlet entry = `${name}=${value}`;\n\n\t\tif (expires !== now) {\n\t\t\tentry += `; Expires=${expires.toUTCString()}`;\n\t\t} else if (maxAge) {\n\t\t\tentry += `; Max-Age=${maxAge}`;\n\t\t}\n\n\t\t// RFC 6265 5.1.3 Domain Matching\n\t\tdomain = (domain ?? this.domain).toLowerCase();\n\n\t\tentry += `; Domain=${domain}`;\n\t\tentry += `; Path=${path ?? '/'}`;\n\n\t\tif (this.secure) {\n\t\t\tentry += `; Secure`;\n\t\t}\n\n\t\tif (httpOnly ?? true) {\n\t\t\tentry += `; HttpOnly`;\n\t\t}\n\n\t\treturn entry;\n\t}\n\n\t/**\n\t * Parses a host using the {@linkplain https://github.com/remusao/tldts tldts} library to extract the domain.\n\t * This is used for the domain of the cookie\n\t * @param host The hot to parse\n\t * @returns Either the host in all lower case or the parsed domain, ready for use on cookies\n\t */\n\tprivate getHostDomain(host: string): string {\n\t\t// Transform the host to lower case\n\t\tconst lowercaseHost = host.toLowerCase();\n\n\t\t// Try parsing the host with tldts\n\t\tconst tldParsedInfo = getDomain(lowercaseHost);\n\n\t\t// If the domain is not defined then return the host in lowercase\n\t\tif (!tldParsedInfo) return lowercaseHost;\n\n\t\t// If the domain was found from parsing then prefix it with a . for a cookie that works with subdomains and return it\n\t\treturn `.${tldParsedInfo}`;\n\t}\n\n\t// RFC 6265 4.1.1. Syntax\n\tprivate static readonly octetRegExp = /[^\\x21\\x23-\\x2B\\x2D-\\x3A\\x3C-\\x5B\\x5D-\\x7E]/g;\n\n\tprivate static encodeCookieOctet(value: string) {\n\t\tif (CookieStore.octetRegExp.test(value)) {\n\t\t\tthrow new Error(`Invalid character in value`);\n\t\t}\n\n\t\treturn encodeURIComponent(value);\n\t}\n}\n\nexport interface SecureCookieStoreSetOptions {\n\texpires?: Date;\n\tmaxAge?: number;\n\tdomain?: string;\n\tpath?: string;\n\thttpOnly?: boolean;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/http/Auth.ts"],"names":["OAuth2Scopes","randomBytes","createCipheriv","createDecipheriv","RouteBases","Routes","isThenable","fetch"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAA,OAAA;AAaO,IAAM,KAAA,GAAN,MAAM,KAAK,CAAA;AAAA,EAmCT,YAAY,OAA4B,EAAA;AA9BhD;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,IAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,cAAA,CAAA;AAEP,IAAA,aAAA,CAAA,IAAA,EAAO,iBAAiC,EAAA,IAAA,CAAA;AAExC,IAAA,YAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AAGC,IAAA,IAAA,CAAK,KAAK,OAAQ,CAAA,EAAA;AAClB,IAAK,IAAA,CAAA,MAAA,GAAS,QAAQ,MAAU,IAAA,eAAA;AAChC,IAAA,IAAA,CAAK,MAAS,GAAA,OAAA,CAAQ,MAAU,IAAA,CAACA,wBAAa,QAAQ,CAAA;AACtD,IAAA,IAAA,CAAK,WAAW,OAAQ,CAAA,QAAA;AACxB,IAAA,YAAA,CAAA,IAAA,EAAK,SAAU,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M,MAAA,MAAA,GAAS,MAAMC,YAAA,CAAM,GAAK,EAAA;AAAA,MAC/B,OAAS,EAAA;AAAA,QACR,aAAA,EAAe,UAAU,KAAK,CAAA;AAAA;AAC/B,KACA,CAAA;AAED,IAAA,OAAO,MAAO,CAAA,EAAA,GAAO,MAAM,MAAA,CAAO,MAAgB,GAAA,IAAA;AAAA;AACnD,EAEA,OAAc,OAAO,OAA0C,EAAA;AAC9D,IAAA,IAAI,CAAC,OAAS,EAAA,MAAA,IAAU,CAAC,OAAA,CAAQ,IAAW,OAAA,IAAA;AAC5C,IAAO,OAAA,IAAI,MAAK,OAAO,CAAA;AAAA;AAEzB,CAAA;AA7FC,OAAA,GAAA,IAAA,OAAA,EAAA;AAjCiB,MAAA,CAAA,KAAA,EAAA,MAAA,CAAA;AAAX,IAAM,IAAN,GAAA","file":"Auth.cjs","sourcesContent":["import { isThenable, type Awaitable } from '@sapphire/utilities';\nimport { createCipheriv, createDecipheriv, randomBytes } from 'crypto';\nimport {\n\tOAuth2Scopes,\n\tRouteBases,\n\tRoutes,\n\ttype RESTGetAPICurrentUserConnectionsResult,\n\ttype RESTGetAPICurrentUserGuildsResult,\n\ttype RESTGetAPICurrentUserResult,\n\ttype Snowflake\n} from 'discord.js';\nimport { fetch } from 'undici';\n\nexport class Auth {\n\t/**\n\t * The client's application id, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tpublic id: Snowflake;\n\n\t/**\n\t * The name for the cookie, this will be used to identify a Secure HttpOnly cookie.\n\t * @since 1.0.0\n\t */\n\tpublic cookie: string;\n\n\t/**\n\t * The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.\n\t * @since 1.0.0\n\t */\n\tpublic scopes: readonly OAuth2Scopes[];\n\n\t/**\n\t * The redirect uri.\n\t * @since 1.0.0\n\t */\n\tpublic redirect: string | undefined;\n\n\t/**\n\t * The transformers used for {@link Auth.fetchData}.\n\t * @since 1.4.0\n\t */\n\tpublic transformers: LoginDataTransformer[];\n\n\tpublic domainOverwrite: string | null = null;\n\n\t#secret: string;\n\n\tprivate constructor(options: ServerOptionsAuth) {\n\t\tthis.id = options.id;\n\t\tthis.cookie = options.cookie ?? 'SAPPHIRE_AUTH';\n\t\tthis.scopes = options.scopes ?? [OAuth2Scopes.Identify];\n\t\tthis.redirect = options.redirect;\n\t\tthis.#secret = options.secret;\n\t\tthis.transformers = options.transformers ?? [];\n\t\tthis.domainOverwrite = options.domainOverwrite ?? null;\n\t}\n\n\t/**\n\t * The client secret, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tpublic get secret() {\n\t\treturn this.#secret;\n\t}\n\n\t/**\n\t * Encrypts an object with aes-256-cbc to use as a token.\n\t * @since 1.0.0\n\t * @param data An object to encrypt\n\t */\n\tpublic encrypt(data: AuthData): string {\n\t\tconst iv = randomBytes(16);\n\t\tconst cipher = createCipheriv('aes-256-cbc', this.#secret, iv);\n\t\treturn `${cipher.update(JSON.stringify(data), 'utf8', 'base64') + cipher.final('base64')}.${iv.toString('base64')}`;\n\t}\n\n\t/**\n\t * Decrypts an object with aes-256-cbc to use as a token.\n\t * @since 1.0.0\n\t * @param token An data to decrypt\n\t */\n\tpublic decrypt(token: string): AuthData | null {\n\t\tconst [data, iv] = token.split('.');\n\t\tconst decipher = createDecipheriv('aes-256-cbc', this.#secret, Buffer.from(iv, 'base64'));\n\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(decipher.update(data, 'base64', 'utf8') + decipher.final('utf8')) as AuthData;\n\t\t\t// If the token expired, return null:\n\t\t\treturn parsed.expires >= Date.now() ? parsed : null;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves the data for a specific user.\n\t * @since 1.4.0\n\t * @param token The access token from the user.\n\t */\n\tpublic async fetchData(token: string): Promise<LoginData> {\n\t\t// Fetch the information:\n\t\tconst [user, guilds, connections] = await Promise.all([\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserResult>(OAuth2Scopes.Identify, token, `${RouteBases.api}${Routes.user()}`),\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserGuildsResult>(OAuth2Scopes.Guilds, token, `${RouteBases.api}${Routes.userGuilds()}`),\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserConnectionsResult>(\n\t\t\t\tOAuth2Scopes.Connections,\n\t\t\t\ttoken,\n\t\t\t\t`${RouteBases.api}${Routes.userConnections()}`\n\t\t\t)\n\t\t]);\n\n\t\t// Transform the information:\n\t\tlet data: LoginData = { user, guilds, connections };\n\t\tfor (const transformer of this.transformers) {\n\t\t\tconst result = transformer(data);\n\t\t\tif (isThenable(result)) data = await result;\n\t\t\telse data = result as LoginData;\n\t\t}\n\n\t\treturn data;\n\t}\n\n\tprivate async fetchInformation<T>(scope: OAuth2Scopes, token: string, url: string): Promise<T | null | undefined> {\n\t\tif (!this.scopes.includes(scope)) return undefined;\n\n\t\tconst result = await fetch(url, {\n\t\t\theaders: {\n\t\t\t\tauthorization: `Bearer ${token}`\n\t\t\t}\n\t\t});\n\n\t\treturn result.ok ? ((await result.json()) as T) : null;\n\t}\n\n\tpublic static create(options?: ServerOptionsAuth): Auth | null {\n\t\tif (!options?.secret || !options.id) return null;\n\t\treturn new Auth(options);\n\t}\n}\n\n/**\n * Defines the authentication data, this is to be encrypted and decrypted by the server.\n * @since 1.0.0\n */\nexport interface AuthData {\n\t/**\n\t * The user ID.\n\t * @since 1.0.0\n\t */\n\tid: string;\n\n\t/**\n\t * The timestamp at which the token expires.\n\t * @since 1.0.0\n\t */\n\texpires: number;\n\n\t/**\n\t * The refresh token.\n\t * @since 1.0.0\n\t */\n\trefresh: string;\n\n\t/**\n\t * The access token.\n\t * @since 1.0.0\n\t */\n\ttoken: string;\n}\n\n/**\n * Defines the authentication options.\n * @since 1.0.0\n */\nexport interface ServerOptionsAuth {\n\t/**\n\t * The client's application id, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tid: Snowflake;\n\n\t/**\n\t * The name for the cookie, this will be used to identify a Secure HttpOnly cookie.\n\t * @since 1.0.0\n\t * @default 'SAPPHIRE_AUTH'\n\t */\n\tcookie?: string;\n\n\t/**\n\t * The client secret, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tsecret: string;\n\n\t/**\n\t * The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.\n\t * @since 1.0.0\n\t * @default [OAuth2Scopes.Identify]\n\t */\n\tscopes?: OAuth2Scopes[];\n\n\t/**\n\t * The redirect uri. This will default to {@link OAuth2BodyData.redirectUri} if missing.\n\t * @since 1.0.0\n\t */\n\tredirect?: string;\n\n\t/**\n\t * The login data transformers used for {@link Auth.fetchData}.\n\t * @since 1.4.0\n\t * @default []\n\t */\n\ttransformers?: LoginDataTransformer[];\n\t/**\n\t * The domain that should be used for the cookie. This overwrites the automatic detection of the domain.\n\t * @remark if you want to support subdomains (`one.example.two` and `two.example.com`) then you need to use prefix your domain with a `.`, for example `.example.com`\n\t * @since 2.1.0\n\t * @default undefined\n\t */\n\tdomainOverwrite?: string;\n}\n\n/**\n * The login data sent when fetching data from a user.\n * @since 1.4.0\n */\nexport interface LoginData {\n\t/**\n\t * The user data, defined when the `'identify'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tuser?: RESTGetAPICurrentUserResult | null;\n\n\t/**\n\t * The guilds data, defined when the `'guilds'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tguilds?: RESTGetAPICurrentUserGuildsResult | null;\n\n\t/**\n\t * The connections data, defined when the `'connections'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tconnections?: RESTGetAPICurrentUserConnectionsResult | null;\n}\n\n/**\n * A login data transformer.\n * @since 1.4.0\n */\nexport interface LoginDataTransformer<T extends LoginData = LoginData> {\n\t/**\n\t * Transforms the object by mutating its properties or adding new ones.\n\t * @since 1.4.0\n\t */\n\t(data: LoginData): Awaitable<T>;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/http/Auth.ts"],"names":["OAuth2Scopes","randomBytes","createCipheriv","createDecipheriv","RouteBases","Routes","isThenable","fetch"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAA,OAAA;AAaO,IAAM,KAAA,GAAN,MAAM,KAAA,CAAK;AAAA,EAmCT,YAAY,OAAA,EAA4B;AA9BhD;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,IAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,QAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,QAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,UAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,cAAA,CAAA;AAEP,IAAA,aAAA,CAAA,IAAA,EAAO,iBAAA,EAAiC,IAAA,CAAA;AAExC,IAAA,YAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AAGC,IAAA,IAAA,CAAK,KAAK,OAAA,CAAQ,EAAA;AAClB,IAAA,IAAA,CAAK,MAAA,GAAS,QAAQ,MAAA,IAAU,eAAA;AAChC,IAAA,IAAA,CAAK,MAAA,GAAS,OAAA,CAAQ,MAAA,IAAU,CAACA,wBAAa,QAAQ,CAAA;AACtD,IAAA,IAAA,CAAK,WAAW,OAAA,CAAQ,QAAA;AACxB,IAAA,YAAA,CAAA,IAAA,EAAK,SAAU,OAAA,CAAQ,MAAA,CAAA;AACvB,IAAA,IAAA,CAAK,YAAA,GAAe,OAAA,CAAQ,YAAA,IAAgB,EAAC;AAC7C,IAAA,IAAA,CAAK,eAAA,GAAkB,QAAQ,eAAA,IAAmB,IAAA;AAAA,EACnD;AAAA;AAA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A,CAAA;AAED,IAAA,OAAO,MAAA,CAAO,EAAA,GAAO,MAAM,MAAA,CAAO,MAAK,GAAW,IAAA;AAAA,EACnD;AAAA,EAEA,OAAc,OAAO,OAAA,EAA0C;AAC9D,IAAA,IAAI,CAAC,OAAA,EAAS,MAAA,IAAU,CAAC,OAAA,CAAQ,IAAI,OAAO,IAAA;AAC5C,IAAA,OAAO,IAAI,MAAK,OAAO,CAAA;AAAA,EACxB;AACD,CAAA;AA7FC,OAAA,GAAA,IAAA,OAAA,EAAA;AAjCiB,MAAA,CAAA,KAAA,EAAA,MAAA,CAAA;AAAX,IAAM,IAAA,GAAN","file":"Auth.cjs","sourcesContent":["import { isThenable, type Awaitable } from '@sapphire/utilities';\nimport { createCipheriv, createDecipheriv, randomBytes } from 'crypto';\nimport {\n\tOAuth2Scopes,\n\tRouteBases,\n\tRoutes,\n\ttype RESTGetAPICurrentUserConnectionsResult,\n\ttype RESTGetAPICurrentUserGuildsResult,\n\ttype RESTGetAPICurrentUserResult,\n\ttype Snowflake\n} from 'discord.js';\nimport { fetch } from 'undici';\n\nexport class Auth {\n\t/**\n\t * The client's application id, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tpublic id: Snowflake;\n\n\t/**\n\t * The name for the cookie, this will be used to identify a Secure HttpOnly cookie.\n\t * @since 1.0.0\n\t */\n\tpublic cookie: string;\n\n\t/**\n\t * The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.\n\t * @since 1.0.0\n\t */\n\tpublic scopes: readonly OAuth2Scopes[];\n\n\t/**\n\t * The redirect uri.\n\t * @since 1.0.0\n\t */\n\tpublic redirect: string | undefined;\n\n\t/**\n\t * The transformers used for {@link Auth.fetchData}.\n\t * @since 1.4.0\n\t */\n\tpublic transformers: LoginDataTransformer[];\n\n\tpublic domainOverwrite: string | null = null;\n\n\t#secret: string;\n\n\tprivate constructor(options: ServerOptionsAuth) {\n\t\tthis.id = options.id;\n\t\tthis.cookie = options.cookie ?? 'SAPPHIRE_AUTH';\n\t\tthis.scopes = options.scopes ?? [OAuth2Scopes.Identify];\n\t\tthis.redirect = options.redirect;\n\t\tthis.#secret = options.secret;\n\t\tthis.transformers = options.transformers ?? [];\n\t\tthis.domainOverwrite = options.domainOverwrite ?? null;\n\t}\n\n\t/**\n\t * The client secret, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tpublic get secret() {\n\t\treturn this.#secret;\n\t}\n\n\t/**\n\t * Encrypts an object with aes-256-cbc to use as a token.\n\t * @since 1.0.0\n\t * @param data An object to encrypt\n\t */\n\tpublic encrypt(data: AuthData): string {\n\t\tconst iv = randomBytes(16);\n\t\tconst cipher = createCipheriv('aes-256-cbc', this.#secret, iv);\n\t\treturn `${cipher.update(JSON.stringify(data), 'utf8', 'base64') + cipher.final('base64')}.${iv.toString('base64')}`;\n\t}\n\n\t/**\n\t * Decrypts an object with aes-256-cbc to use as a token.\n\t * @since 1.0.0\n\t * @param token An data to decrypt\n\t */\n\tpublic decrypt(token: string): AuthData | null {\n\t\tconst [data, iv] = token.split('.');\n\t\tconst decipher = createDecipheriv('aes-256-cbc', this.#secret, Buffer.from(iv, 'base64'));\n\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(decipher.update(data, 'base64', 'utf8') + decipher.final('utf8')) as AuthData;\n\t\t\t// If the token expired, return null:\n\t\t\treturn parsed.expires >= Date.now() ? parsed : null;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves the data for a specific user.\n\t * @since 1.4.0\n\t * @param token The access token from the user.\n\t */\n\tpublic async fetchData(token: string): Promise<LoginData> {\n\t\t// Fetch the information:\n\t\tconst [user, guilds, connections] = await Promise.all([\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserResult>(OAuth2Scopes.Identify, token, `${RouteBases.api}${Routes.user()}`),\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserGuildsResult>(OAuth2Scopes.Guilds, token, `${RouteBases.api}${Routes.userGuilds()}`),\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserConnectionsResult>(\n\t\t\t\tOAuth2Scopes.Connections,\n\t\t\t\ttoken,\n\t\t\t\t`${RouteBases.api}${Routes.userConnections()}`\n\t\t\t)\n\t\t]);\n\n\t\t// Transform the information:\n\t\tlet data: LoginData = { user, guilds, connections };\n\t\tfor (const transformer of this.transformers) {\n\t\t\tconst result = transformer(data);\n\t\t\tif (isThenable(result)) data = await result;\n\t\t\telse data = result as LoginData;\n\t\t}\n\n\t\treturn data;\n\t}\n\n\tprivate async fetchInformation<T>(scope: OAuth2Scopes, token: string, url: string): Promise<T | null | undefined> {\n\t\tif (!this.scopes.includes(scope)) return undefined;\n\n\t\tconst result = await fetch(url, {\n\t\t\theaders: {\n\t\t\t\tauthorization: `Bearer ${token}`\n\t\t\t}\n\t\t});\n\n\t\treturn result.ok ? ((await result.json()) as T) : null;\n\t}\n\n\tpublic static create(options?: ServerOptionsAuth): Auth | null {\n\t\tif (!options?.secret || !options.id) return null;\n\t\treturn new Auth(options);\n\t}\n}\n\n/**\n * Defines the authentication data, this is to be encrypted and decrypted by the server.\n * @since 1.0.0\n */\nexport interface AuthData {\n\t/**\n\t * The user ID.\n\t * @since 1.0.0\n\t */\n\tid: string;\n\n\t/**\n\t * The timestamp at which the token expires.\n\t * @since 1.0.0\n\t */\n\texpires: number;\n\n\t/**\n\t * The refresh token.\n\t * @since 1.0.0\n\t */\n\trefresh: string;\n\n\t/**\n\t * The access token.\n\t * @since 1.0.0\n\t */\n\ttoken: string;\n}\n\n/**\n * Defines the authentication options.\n * @since 1.0.0\n */\nexport interface ServerOptionsAuth {\n\t/**\n\t * The client's application id, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tid: Snowflake;\n\n\t/**\n\t * The name for the cookie, this will be used to identify a Secure HttpOnly cookie.\n\t * @since 1.0.0\n\t * @default 'SAPPHIRE_AUTH'\n\t */\n\tcookie?: string;\n\n\t/**\n\t * The client secret, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tsecret: string;\n\n\t/**\n\t * The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.\n\t * @since 1.0.0\n\t * @default [OAuth2Scopes.Identify]\n\t */\n\tscopes?: OAuth2Scopes[];\n\n\t/**\n\t * The redirect uri. This will default to {@link OAuth2BodyData.redirectUri} if missing.\n\t * @since 1.0.0\n\t */\n\tredirect?: string;\n\n\t/**\n\t * The login data transformers used for {@link Auth.fetchData}.\n\t * @since 1.4.0\n\t * @default []\n\t */\n\ttransformers?: LoginDataTransformer[];\n\t/**\n\t * The domain that should be used for the cookie. This overwrites the automatic detection of the domain.\n\t * @remark if you want to support subdomains (`one.example.two` and `two.example.com`) then you need to use prefix your domain with a `.`, for example `.example.com`\n\t * @since 2.1.0\n\t * @default undefined\n\t */\n\tdomainOverwrite?: string;\n}\n\n/**\n * The login data sent when fetching data from a user.\n * @since 1.4.0\n */\nexport interface LoginData {\n\t/**\n\t * The user data, defined when the `'identify'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tuser?: RESTGetAPICurrentUserResult | null;\n\n\t/**\n\t * The guilds data, defined when the `'guilds'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tguilds?: RESTGetAPICurrentUserGuildsResult | null;\n\n\t/**\n\t * The connections data, defined when the `'connections'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tconnections?: RESTGetAPICurrentUserConnectionsResult | null;\n}\n\n/**\n * A login data transformer.\n * @since 1.4.0\n */\nexport interface LoginDataTransformer<T extends LoginData = LoginData> {\n\t/**\n\t * Transforms the object by mutating its properties or adding new ones.\n\t * @since 1.4.0\n\t */\n\t(data: LoginData): Awaitable<T>;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/http/HttpCodes.ts"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AAAA,UAAAA,CAAA,yBAAsB,GAAtB,CAAA,GAAA,qBAAA;AAOA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,oBAAiB,GAAjB,CAAA,GAAA,gBAAA;AAMA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,gBAAa,GAAb,CAAA,GAAA,YAAA;AAMA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,wBAAqB,GAArB,CAAA,GAAA,oBAAA;AAMA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,oBAAiB,GAAjB,CAAA,GAAA,gBAAA;AAKA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,6BAA0B,GAA1B,CAAA,GAAA,yBAAA;AAMA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,2BAAwB,GAAxB,CAAA,GAAA,uBAAA;AAMA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,yBAAsB,GAAtB,CAAA,GAAA,qBAAA;AAMA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,kBAAe,GAAf,CAAA,GAAA,cAAA;AAMA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,iBAAc,GAAd,CAAA,GAAA,aAAA;AAQA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,mCAAgC,GAAhC,CAAA,GAAA,+BAAA;AAjbW,EAAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA","file":"HttpCodes.cjs","sourcesContent":["export enum HttpCodes {\n\t/**\n\t * Standard response for successful HTTP requests. The actual response will\n\t * depend on the request method used. In a GET request, the response will\n\t * contain an entity corresponding to the requested resource. In a POST\n\t * request, the response will contain an entity describing or containing the\n\t * result of the action.\n\t */\n\tOK = 200,\n\n\t/**\n\t * The request has been fulfilled, resulting in the creation of a new\n\t * resource.\n\t */\n\tCreated = 201,\n\n\t/**\n\t * The request has been accepted for processing, but the processing has not\n\t * been completed. The request might or might not be eventually acted upon,\n\t * and may be disallowed when processing occurs.\n\t */\n\tAccepted = 202,\n\n\t/**\n\t * The server is a transforming proxy (e.g. a Web accelerator) that received\n\t * a 200 OK from its origin, but is returning a modified version of the\n\t * origin's response.\n\t */\n\tNonAuthoritativeInformation = 203,\n\n\t/**\n\t * The server successfully processed the request, and is not returning any\n\t * content.\n\t */\n\tNoContent = 204,\n\n\t/**\n\t * The server successfully processed the request, asks that the requester\n\t * reset its document view, and is not returning any content.\n\t */\n\tResetContent = 205,\n\n\t/**\n\t * (RFC 7233) The server is delivering only part of the resource (byte\n\t * serving) due to a range header sent by the client. The range header is\n\t * used by HTTP clients to enable resuming of interrupted downloads, or\n\t * split a download into multiple simultaneous streams.\n\t */\n\tPartialContent = 206,\n\n\t/**\n\t * (WebDAV; RFC 4918) The message body that follows is by default an XML\n\t * message and can contain a number of separate response codes, depending on\n\t * how many sub-requests were made.\n\t */\n\tMultiStatus = 207,\n\n\t/**\n\t * (WebDAV; RFC 5842) The members of a DAV binding have already been\n\t * enumerated in a preceding part of the (multistatus) response, and are not\n\t * being included again.\n\t */\n\tAlreadyReported = 208,\n\n\t/**\n\t * (RFC 3229) The server has fulfilled a request for the resource, and the\n\t * response is a representation of the result of one or more\n\t * instance-manipulations applied to the current instance.\n\t */\n\tIMUsed = 226,\n\n\t/**\n\t * Indicates multiple options for the resource from which the client may\n\t * choose (via agent-driven content negotiation). For example, this code\n\t * could be used to present multiple video format options, to list files\n\t * with different filename extensions, or to suggest word-sense\n\t * disambiguation.\n\t */\n\tMultipleChoices = 300,\n\n\t/**\n\t * This and all future requests should be directed to the given URI.\n\t */\n\tMovedPermanently = 301,\n\n\t/**\n\t * (Previously \"Moved temporarily\") Tells the client to look at (browse to)\n\t * another URL. 302 has been superseded by 303 and 307. This is an example\n\t * of industry practice contradicting the standard. The HTTP/1.0\n\t * specification (RFC 1945) required the client to perform a temporary\n\t * redirect (the original describing phrase was \"Moved Temporarily\"), but\n\t * popular browsers implemented 302 with the functionality of a 303 See\n\t * Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish\n\t * between the two behaviours. However, some Web applications and frameworks\n\t * use the 302 status code as if it were the 303.\n\t */\n\tFound = 302,\n\n\t/**\n\t * The response to the request can be found under another URI using the GET\n\t * method. When received in response to a POST (or PUT/DELETE), the client\n\t * should presume that the server has received the data and should issue a\n\t * new GET request to the given URI.\n\t */\n\tSeeOther = 303,\n\n\t/**\n\t * (RFC 7232) Indicates that the resource has not been modified since the\n\t * version specified by the request headers If-Modified-Since or\n\t * If-None-Match. In such case, there is no need to retransmit the resource\n\t * since the client still has a previously-downloaded copy.\n\t */\n\tNotModified = 304,\n\n\t/**\n\t * The requested resource is available only through a proxy, the address for\n\t * which is provided in the response. For security reasons, many HTTP\n\t * clients (such as Mozilla Firefox and Internet Explorer) do not obey this\n\t * status code.\n\t */\n\tUseProxy = 305,\n\t/**\n\t * No longer used. Originally meant \"Subsequent requests should use the\n\t * specified proxy.\".\n\t */\n\tSwitchProxy = 306,\n\n\t/**\n\t * In this case, the request should be repeated with another URI; however,\n\t * future requests should still use the original URI. In contrast to how 302\n\t * was historically implemented, the request method is not allowed to be\n\t * changed when reissuing the original request. For example, a POST request\n\t * should be repeated using another POST request.\n\t */\n\tTemporaryRedirect = 307,\n\n\t/**\n\t * (RFC 7538) The request and all future requests should be repeated using\n\t * another URI. 307 and 308 parallel the behaviors of 302 and 301, but do\n\t * not allow the HTTP method to change. So, for example, submitting a form\n\t * to a permanently redirected resource may continue smoothly.\n\t */\n\tPermanentRedirect = 308,\n\n\t/**\n\t * The server cannot or will not process the request due to an apparent\n\t * client error (e.g., malformed request syntax, size too large, invalid\n\t * request message framing, or deceptive request routing).\n\t */\n\tBadRequest = 400,\n\n\t/**\n\t * (RFC 7235) Similar to 403 Forbidden, but specifically for use when\n\t * authentication is required and has failed or has not yet been provided.\n\t * The response must include a WWW-Authenticate header field containing a\n\t * challenge applicable to the requested resource. See Basic access\n\t * authentication and Digest access authentication. 401 semantically means\n\t * \"unauthorised\", the user does not have valid authentication credentials\n\t * for the target resource.\n\t */\n\tUnauthorized = 401,\n\n\t/**\n\t * Reserved for future use. The original intention was that this code might\n\t * be used as part of some form of digital cash or micropayment scheme, as\n\t * proposed, for example, by GNU Taler, but that has not yet happened, and\n\t * this code is not widely used. Google Developers API uses this status if a\n\t * particular developer has exceeded the daily limit on requests. Sipgate\n\t * uses this code if an account does not have sufficient funds to start a\n\t * call. Shopify uses this code when the store has not paid their fees and\n\t * is temporarily disabled. Stripe uses this code for failed payments where\n\t * parameters were correct, for example blocked fraudulent payments.\n\t */\n\tPaymentRequired = 402,\n\n\t/**\n\t * The request contained valid data and was understood by the server, but\n\t * the server is refusing action. This may be due to the user not having the\n\t * necessary permissions for a resource or needing an account of some sort,\n\t * or attempting a prohibited action (e.g. creating a duplicate record\n\t * where only one is allowed). This code is also typically used if the\n\t * request provided authentication by answering the WWW-Authenticate header\n\t * field challenge, but the server did not accept that authentication. The\n\t * request should not be repeated.\n\t */\n\tForbidden = 403,\n\n\t/**\n\t * The requested resource could not be found but may be available in the\n\t * future. Subsequent requests by the client are permissible.\n\t */\n\tNotFound = 404,\n\n\t/**\n\t * A request method is not supported for the requested resource; for example,\n\t * a GET request on a form that requires data to be presented via POST, or a\n\t * PUT request on a read-only resource.\n\t */\n\tMethodNotAllowed = 405,\n\n\t/**\n\t * The requested resource is capable of generating only content not\n\t * acceptable according to the Accept headers sent in the request. See Content negotiation.\n\t */\n\tNotAcceptable = 406,\n\n\t/**\n\t * (RFC 7235) The client must first authenticate itself with the proxy.\n\t */\n\tProxyAuthenticationRequired = 407,\n\n\t/**\n\t * The server timed out waiting for the request. According to HTTP\n\t * specifications: \"The client did not produce a request within the time\n\t * that the server was prepared to wait. The client MAY repeat the request\n\t * without modifications at any later time.\"\n\t */\n\tRequestTimeout = 408,\n\n\t/**\n\t * Indicates that the request could not be processed because of conflict in\n\t * the current state of the resource, such as an edit conflict between\n\t * multiple simultaneous updates.\n\t */\n\tConflict = 409,\n\n\t/**\n\t * Indicates that the resource requested is no longer available and will not\n\t * be available again. This should be used when a resource has been\n\t * intentionally removed and the resource should be purged. Upon receiving a\n\t * 410 status code, the client should not request the resource in the future.\n\t * Clients such as search engines should remove the resource from their\n\t * indices. Most use cases do not require clients and search engines to\n\t * purge the resource, and a \"404 Not Found\" may be used instead.\n\t */\n\tGone = 410,\n\n\t/**\n\t * The request did not specify the length of its content, which is required\n\t * by the requested resource.\n\t */\n\tLengthRequired = 411,\n\n\t/**\n\t * (RFC 7232) The server does not meet one of the preconditions that the\n\t * requester put on the request header fields.\n\t */\n\tPreconditionFailed = 412,\n\n\t/**\n\t * (RFC 7231) The request is larger than the server is willing or able to\n\t * process. Previously called \"Request Entity Too Large\".\n\t */\n\tPayloadTooLarge = 413,\n\n\t/**\n\t * (RFC 7231) The URI provided was too long for the server to process. Often\n\t * the result of too much data being encoded as a query-string of a GET\n\t * request, in which case it should be converted to a POST request. Called\n\t * \"Request-URI Too Long\" previously.\n\t */\n\tURITooLong = 414,\n\n\t/**\n\t * (RFC 7231) The request entity has a media type which the server or\n\t * resource does not support. For example, the client uploads an image as\n\t * image/svg+xml, but the server requires that images use a different format.\n\t */\n\tUnsupportedMediaType = 415,\n\n\t/**\n\t * (RFC 7233) The client has asked for a portion of the file (byte serving),\n\t * but the server cannot supply that portion. For example, if the client\n\t * asked for a part of the file that lies beyond the end of the file. Called\n\t * \"Requested Range Not Satisfiable\" previously.\n\t */\n\tRangeNotSatisfiable = 416,\n\n\t/**\n\t * The server cannot meet the requirements of the Expect request-header\n\t * field.\n\t */\n\tExpectationFailed = 417,\n\n\t/**\n\t * (RFC 2324, RFC 7168) This code was defined in 1998 as one of the\n\t * traditional IETF April Fools' jokes, in RFC 2324, Hyper Text Coffee Pot\n\t * Control Protocol, and is not expected to be implemented by actual HTTP\n\t * servers. The RFC specifies this code should be returned by teapots\n\t * requested to brew coffee. This HTTP status is used as an Easter egg in\n\t * some websites, such as Google.com's I'm a teapot easter egg.\n\t */\n\tIAmATeapot = 418,\n\n\t/**\n\t * Returned by the Twitter Search and Trends API when the client is being rate limited.\n\t * The text is a quote from 'Demolition Man' and the '420' code is likely a reference\n\t * to this number's association with marijuana. Other services may wish to implement\n\t * the 429 Too Many Requests response code instead.\n\t */\n\tEnhanceYourCalm = 420,\n\n\t/**\n\t * (RFC 7540) The request was directed at a server that is not able to\n\t * produce a response (for example because of connection reuse).\n\t */\n\tMisdirectedRequest = 421,\n\n\t/**\n\t * (WebDAV; RFC 4918) The request was well-formed but was unable to be\n\t * followed due to semantic errors.\n\t */\n\tUnprocessableEntity = 422,\n\n\t/**\n\t * (WebDAV; RFC 4918) The resource that is being accessed is locked.\n\t */\n\tLocked = 423,\n\n\t/**\n\t * (WebDAV; RFC 4918) The request failed because it depended on another\n\t * request and that request failed (e.g., a PROPPATCH).\n\t */\n\tFailedDependency = 424,\n\n\t/**\n\t * (RFC 8470) Indicates that the server is unwilling to risk processing a\n\t * request that might be replayed.\n\t */\n\tTooEarly = 425,\n\n\t/**\n\t * The client should switch to a different protocol such as TLS/1.0, given\n\t * in the Upgrade header field.\n\t */\n\tUpgradeRequired = 426,\n\n\t/**\n\t * (RFC 6585) The origin server requires the request to be conditional.\n\t * Intended to prevent the 'lost update' problem, where a client GETs a\n\t * resource's state, modifies it, and PUTs it back to the server, when\n\t * meanwhile a third party has modified the state on the server, leading to\n\t * a conflict.\n\t */\n\tPreconditionRequired = 428,\n\n\t/**\n\t * (RFC 6585) The user has sent too many requests in a given amount of time.\n\t * Intended for use with rate-limiting schemes.\n\t */\n\tTooManyRequests = 429,\n\n\t/**\n\t * (RFC 6585) The server is unwilling to process the request because either\n\t * an individual header field, or all the header fields collectively, are\n\t * too large.\n\t */\n\tRequestHeaderFieldsTooLarge = 431,\n\n\t/**\n\t * (RFC 7725) A server operator has received a legal demand to deny access\n\t * to a resource or to a set of resources that includes the requested\n\t * resource. The code 451 was chosen as a reference to the novel Fahrenheit\n\t * 451 (see the Acknowledgements in the RFC).\n\t */\n\tUnavailableForLegalReasons = 451,\n\n\t/**\n\t * A generic error message, given when an unexpected condition was\n\t * encountered and no more specific message is suitable.\n\t */\n\tInternalServerError = 500,\n\n\t/**\n\t * The server either does not recognize the request method, or it lacks the\n\t * ability to fulfil the request. Usually this implies future availability\n\t * (e.g., a new feature of a web-service API).\n\t */\n\tNotImplemented = 501,\n\n\t/**\n\t * The server was acting as a gateway or proxy and received an invalid\n\t * response from the upstream server.\n\t */\n\tBadGateway = 502,\n\n\t/**\n\t * The server cannot handle the request (because it is overloaded or down\n\t * for maintenance). Generally, this is a temporary state.\n\t */\n\tServiceUnavailable = 503,\n\n\t/**\n\t * The server was acting as a gateway or proxy and did not receive a timely\n\t * response from the upstream server.\n\t */\n\tGatewayTimeout = 504,\n\n\t/**\n\t * The server does not support the HTTP protocol version used in the request.\n\t */\n\tHTTPVersionNotSupported = 505,\n\n\t/**\n\t * (RFC 2295) Transparent content negotiation for the request results in a\n\t * circular reference.\n\t */\n\tVariantAlsoNegotiates = 506,\n\n\t/**\n\t * (WebDAV; RFC 4918) The server is unable to store the representation\n\t * needed to complete the request.\n\t */\n\tInsufficientStorage = 507,\n\n\t/**\n\t * (WebDAV; RFC 5842) The server detected an infinite loop while processing\n\t * the request (sent instead of 208 Already Reported).\n\t */\n\tLoopDetected = 508,\n\n\t/**\n\t * (RFC 2774) Further extensions to the request are required for the server\n\t * to fulfil it.\n\t */\n\tNotExtended = 510,\n\n\t/**\n\t * (RFC 6585) The client needs to authenticate to gain network access.\n\t * Intended for use by intercepting proxies used to control access to the\n\t * network (e.g., \"captive portals\" used to require agreement to Terms of\n\t * Service before granting full Internet access via a Wi-Fi hotspot).\n\t */\n\tNetworkAuthenticationRequired = 511\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/http/HttpCodes.ts"],"names":["HttpCodes"],"mappings":";;;AAAO,IAAK,SAAA,qBAAAA,UAAAA,KAAL;AAQN,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,QAAK,GAAA,CAAA,GAAL,IAAA;AAMA,EAAAA,UAAAA,CAAAA,U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,CAAA,gBAAa,GAAA,CAAA,GAAb,YAAA;AAMA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,wBAAqB,GAAA,CAAA,GAArB,oBAAA;AAMA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,oBAAiB,GAAA,CAAA,GAAjB,gBAAA;AAKA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,6BAA0B,GAAA,CAAA,GAA1B,yBAAA;AAMA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,2BAAwB,GAAA,CAAA,GAAxB,uBAAA;AAMA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,yBAAsB,GAAA,CAAA,GAAtB,qBAAA;AAMA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,kBAAe,GAAA,CAAA,GAAf,cAAA;AAMA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,iBAAc,GAAA,CAAA,GAAd,aAAA;AAQA,EAAAA,UAAAA,CAAAA,UAAAA,CAAA,mCAAgC,GAAA,CAAA,GAAhC,+BAAA;AAjbW,EAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA","file":"HttpCodes.cjs","sourcesContent":["export enum HttpCodes {\n\t/**\n\t * Standard response for successful HTTP requests. The actual response will\n\t * depend on the request method used. In a GET request, the response will\n\t * contain an entity corresponding to the requested resource. In a POST\n\t * request, the response will contain an entity describing or containing the\n\t * result of the action.\n\t */\n\tOK = 200,\n\n\t/**\n\t * The request has been fulfilled, resulting in the creation of a new\n\t * resource.\n\t */\n\tCreated = 201,\n\n\t/**\n\t * The request has been accepted for processing, but the processing has not\n\t * been completed. The request might or might not be eventually acted upon,\n\t * and may be disallowed when processing occurs.\n\t */\n\tAccepted = 202,\n\n\t/**\n\t * The server is a transforming proxy (e.g. a Web accelerator) that received\n\t * a 200 OK from its origin, but is returning a modified version of the\n\t * origin's response.\n\t */\n\tNonAuthoritativeInformation = 203,\n\n\t/**\n\t * The server successfully processed the request, and is not returning any\n\t * content.\n\t */\n\tNoContent = 204,\n\n\t/**\n\t * The server successfully processed the request, asks that the requester\n\t * reset its document view, and is not returning any content.\n\t */\n\tResetContent = 205,\n\n\t/**\n\t * (RFC 7233) The server is delivering only part of the resource (byte\n\t * serving) due to a range header sent by the client. The range header is\n\t * used by HTTP clients to enable resuming of interrupted downloads, or\n\t * split a download into multiple simultaneous streams.\n\t */\n\tPartialContent = 206,\n\n\t/**\n\t * (WebDAV; RFC 4918) The message body that follows is by default an XML\n\t * message and can contain a number of separate response codes, depending on\n\t * how many sub-requests were made.\n\t */\n\tMultiStatus = 207,\n\n\t/**\n\t * (WebDAV; RFC 5842) The members of a DAV binding have already been\n\t * enumerated in a preceding part of the (multistatus) response, and are not\n\t * being included again.\n\t */\n\tAlreadyReported = 208,\n\n\t/**\n\t * (RFC 3229) The server has fulfilled a request for the resource, and the\n\t * response is a representation of the result of one or more\n\t * instance-manipulations applied to the current instance.\n\t */\n\tIMUsed = 226,\n\n\t/**\n\t * Indicates multiple options for the resource from which the client may\n\t * choose (via agent-driven content negotiation). For example, this code\n\t * could be used to present multiple video format options, to list files\n\t * with different filename extensions, or to suggest word-sense\n\t * disambiguation.\n\t */\n\tMultipleChoices = 300,\n\n\t/**\n\t * This and all future requests should be directed to the given URI.\n\t */\n\tMovedPermanently = 301,\n\n\t/**\n\t * (Previously \"Moved temporarily\") Tells the client to look at (browse to)\n\t * another URL. 302 has been superseded by 303 and 307. This is an example\n\t * of industry practice contradicting the standard. The HTTP/1.0\n\t * specification (RFC 1945) required the client to perform a temporary\n\t * redirect (the original describing phrase was \"Moved Temporarily\"), but\n\t * popular browsers implemented 302 with the functionality of a 303 See\n\t * Other. Therefore, HTTP/1.1 added status codes 303 and 307 to distinguish\n\t * between the two behaviours. However, some Web applications and frameworks\n\t * use the 302 status code as if it were the 303.\n\t */\n\tFound = 302,\n\n\t/**\n\t * The response to the request can be found under another URI using the GET\n\t * method. When received in response to a POST (or PUT/DELETE), the client\n\t * should presume that the server has received the data and should issue a\n\t * new GET request to the given URI.\n\t */\n\tSeeOther = 303,\n\n\t/**\n\t * (RFC 7232) Indicates that the resource has not been modified since the\n\t * version specified by the request headers If-Modified-Since or\n\t * If-None-Match. In such case, there is no need to retransmit the resource\n\t * since the client still has a previously-downloaded copy.\n\t */\n\tNotModified = 304,\n\n\t/**\n\t * The requested resource is available only through a proxy, the address for\n\t * which is provided in the response. For security reasons, many HTTP\n\t * clients (such as Mozilla Firefox and Internet Explorer) do not obey this\n\t * status code.\n\t */\n\tUseProxy = 305,\n\t/**\n\t * No longer used. Originally meant \"Subsequent requests should use the\n\t * specified proxy.\".\n\t */\n\tSwitchProxy = 306,\n\n\t/**\n\t * In this case, the request should be repeated with another URI; however,\n\t * future requests should still use the original URI. In contrast to how 302\n\t * was historically implemented, the request method is not allowed to be\n\t * changed when reissuing the original request. For example, a POST request\n\t * should be repeated using another POST request.\n\t */\n\tTemporaryRedirect = 307,\n\n\t/**\n\t * (RFC 7538) The request and all future requests should be repeated using\n\t * another URI. 307 and 308 parallel the behaviors of 302 and 301, but do\n\t * not allow the HTTP method to change. So, for example, submitting a form\n\t * to a permanently redirected resource may continue smoothly.\n\t */\n\tPermanentRedirect = 308,\n\n\t/**\n\t * The server cannot or will not process the request due to an apparent\n\t * client error (e.g., malformed request syntax, size too large, invalid\n\t * request message framing, or deceptive request routing).\n\t */\n\tBadRequest = 400,\n\n\t/**\n\t * (RFC 7235) Similar to 403 Forbidden, but specifically for use when\n\t * authentication is required and has failed or has not yet been provided.\n\t * The response must include a WWW-Authenticate header field containing a\n\t * challenge applicable to the requested resource. See Basic access\n\t * authentication and Digest access authentication. 401 semantically means\n\t * \"unauthorised\", the user does not have valid authentication credentials\n\t * for the target resource.\n\t */\n\tUnauthorized = 401,\n\n\t/**\n\t * Reserved for future use. The original intention was that this code might\n\t * be used as part of some form of digital cash or micropayment scheme, as\n\t * proposed, for example, by GNU Taler, but that has not yet happened, and\n\t * this code is not widely used. Google Developers API uses this status if a\n\t * particular developer has exceeded the daily limit on requests. Sipgate\n\t * uses this code if an account does not have sufficient funds to start a\n\t * call. Shopify uses this code when the store has not paid their fees and\n\t * is temporarily disabled. Stripe uses this code for failed payments where\n\t * parameters were correct, for example blocked fraudulent payments.\n\t */\n\tPaymentRequired = 402,\n\n\t/**\n\t * The request contained valid data and was understood by the server, but\n\t * the server is refusing action. This may be due to the user not having the\n\t * necessary permissions for a resource or needing an account of some sort,\n\t * or attempting a prohibited action (e.g. creating a duplicate record\n\t * where only one is allowed). This code is also typically used if the\n\t * request provided authentication by answering the WWW-Authenticate header\n\t * field challenge, but the server did not accept that authentication. The\n\t * request should not be repeated.\n\t */\n\tForbidden = 403,\n\n\t/**\n\t * The requested resource could not be found but may be available in the\n\t * future. Subsequent requests by the client are permissible.\n\t */\n\tNotFound = 404,\n\n\t/**\n\t * A request method is not supported for the requested resource; for example,\n\t * a GET request on a form that requires data to be presented via POST, or a\n\t * PUT request on a read-only resource.\n\t */\n\tMethodNotAllowed = 405,\n\n\t/**\n\t * The requested resource is capable of generating only content not\n\t * acceptable according to the Accept headers sent in the request. See Content negotiation.\n\t */\n\tNotAcceptable = 406,\n\n\t/**\n\t * (RFC 7235) The client must first authenticate itself with the proxy.\n\t */\n\tProxyAuthenticationRequired = 407,\n\n\t/**\n\t * The server timed out waiting for the request. According to HTTP\n\t * specifications: \"The client did not produce a request within the time\n\t * that the server was prepared to wait. The client MAY repeat the request\n\t * without modifications at any later time.\"\n\t */\n\tRequestTimeout = 408,\n\n\t/**\n\t * Indicates that the request could not be processed because of conflict in\n\t * the current state of the resource, such as an edit conflict between\n\t * multiple simultaneous updates.\n\t */\n\tConflict = 409,\n\n\t/**\n\t * Indicates that the resource requested is no longer available and will not\n\t * be available again. This should be used when a resource has been\n\t * intentionally removed and the resource should be purged. Upon receiving a\n\t * 410 status code, the client should not request the resource in the future.\n\t * Clients such as search engines should remove the resource from their\n\t * indices. Most use cases do not require clients and search engines to\n\t * purge the resource, and a \"404 Not Found\" may be used instead.\n\t */\n\tGone = 410,\n\n\t/**\n\t * The request did not specify the length of its content, which is required\n\t * by the requested resource.\n\t */\n\tLengthRequired = 411,\n\n\t/**\n\t * (RFC 7232) The server does not meet one of the preconditions that the\n\t * requester put on the request header fields.\n\t */\n\tPreconditionFailed = 412,\n\n\t/**\n\t * (RFC 7231) The request is larger than the server is willing or able to\n\t * process. Previously called \"Request Entity Too Large\".\n\t */\n\tPayloadTooLarge = 413,\n\n\t/**\n\t * (RFC 7231) The URI provided was too long for the server to process. Often\n\t * the result of too much data being encoded as a query-string of a GET\n\t * request, in which case it should be converted to a POST request. Called\n\t * \"Request-URI Too Long\" previously.\n\t */\n\tURITooLong = 414,\n\n\t/**\n\t * (RFC 7231) The request entity has a media type which the server or\n\t * resource does not support. For example, the client uploads an image as\n\t * image/svg+xml, but the server requires that images use a different format.\n\t */\n\tUnsupportedMediaType = 415,\n\n\t/**\n\t * (RFC 7233) The client has asked for a portion of the file (byte serving),\n\t * but the server cannot supply that portion. For example, if the client\n\t * asked for a part of the file that lies beyond the end of the file. Called\n\t * \"Requested Range Not Satisfiable\" previously.\n\t */\n\tRangeNotSatisfiable = 416,\n\n\t/**\n\t * The server cannot meet the requirements of the Expect request-header\n\t * field.\n\t */\n\tExpectationFailed = 417,\n\n\t/**\n\t * (RFC 2324, RFC 7168) This code was defined in 1998 as one of the\n\t * traditional IETF April Fools' jokes, in RFC 2324, Hyper Text Coffee Pot\n\t * Control Protocol, and is not expected to be implemented by actual HTTP\n\t * servers. The RFC specifies this code should be returned by teapots\n\t * requested to brew coffee. This HTTP status is used as an Easter egg in\n\t * some websites, such as Google.com's I'm a teapot easter egg.\n\t */\n\tIAmATeapot = 418,\n\n\t/**\n\t * Returned by the Twitter Search and Trends API when the client is being rate limited.\n\t * The text is a quote from 'Demolition Man' and the '420' code is likely a reference\n\t * to this number's association with marijuana. Other services may wish to implement\n\t * the 429 Too Many Requests response code instead.\n\t */\n\tEnhanceYourCalm = 420,\n\n\t/**\n\t * (RFC 7540) The request was directed at a server that is not able to\n\t * produce a response (for example because of connection reuse).\n\t */\n\tMisdirectedRequest = 421,\n\n\t/**\n\t * (WebDAV; RFC 4918) The request was well-formed but was unable to be\n\t * followed due to semantic errors.\n\t */\n\tUnprocessableEntity = 422,\n\n\t/**\n\t * (WebDAV; RFC 4918) The resource that is being accessed is locked.\n\t */\n\tLocked = 423,\n\n\t/**\n\t * (WebDAV; RFC 4918) The request failed because it depended on another\n\t * request and that request failed (e.g., a PROPPATCH).\n\t */\n\tFailedDependency = 424,\n\n\t/**\n\t * (RFC 8470) Indicates that the server is unwilling to risk processing a\n\t * request that might be replayed.\n\t */\n\tTooEarly = 425,\n\n\t/**\n\t * The client should switch to a different protocol such as TLS/1.0, given\n\t * in the Upgrade header field.\n\t */\n\tUpgradeRequired = 426,\n\n\t/**\n\t * (RFC 6585) The origin server requires the request to be conditional.\n\t * Intended to prevent the 'lost update' problem, where a client GETs a\n\t * resource's state, modifies it, and PUTs it back to the server, when\n\t * meanwhile a third party has modified the state on the server, leading to\n\t * a conflict.\n\t */\n\tPreconditionRequired = 428,\n\n\t/**\n\t * (RFC 6585) The user has sent too many requests in a given amount of time.\n\t * Intended for use with rate-limiting schemes.\n\t */\n\tTooManyRequests = 429,\n\n\t/**\n\t * (RFC 6585) The server is unwilling to process the request because either\n\t * an individual header field, or all the header fields collectively, are\n\t * too large.\n\t */\n\tRequestHeaderFieldsTooLarge = 431,\n\n\t/**\n\t * (RFC 7725) A server operator has received a legal demand to deny access\n\t * to a resource or to a set of resources that includes the requested\n\t * resource. The code 451 was chosen as a reference to the novel Fahrenheit\n\t * 451 (see the Acknowledgements in the RFC).\n\t */\n\tUnavailableForLegalReasons = 451,\n\n\t/**\n\t * A generic error message, given when an unexpected condition was\n\t * encountered and no more specific message is suitable.\n\t */\n\tInternalServerError = 500,\n\n\t/**\n\t * The server either does not recognize the request method, or it lacks the\n\t * ability to fulfil the request. Usually this implies future availability\n\t * (e.g., a new feature of a web-service API).\n\t */\n\tNotImplemented = 501,\n\n\t/**\n\t * The server was acting as a gateway or proxy and received an invalid\n\t * response from the upstream server.\n\t */\n\tBadGateway = 502,\n\n\t/**\n\t * The server cannot handle the request (because it is overloaded or down\n\t * for maintenance). Generally, this is a temporary state.\n\t */\n\tServiceUnavailable = 503,\n\n\t/**\n\t * The server was acting as a gateway or proxy and did not receive a timely\n\t * response from the upstream server.\n\t */\n\tGatewayTimeout = 504,\n\n\t/**\n\t * The server does not support the HTTP protocol version used in the request.\n\t */\n\tHTTPVersionNotSupported = 505,\n\n\t/**\n\t * (RFC 2295) Transparent content negotiation for the request results in a\n\t * circular reference.\n\t */\n\tVariantAlsoNegotiates = 506,\n\n\t/**\n\t * (WebDAV; RFC 4918) The server is unable to store the representation\n\t * needed to complete the request.\n\t */\n\tInsufficientStorage = 507,\n\n\t/**\n\t * (WebDAV; RFC 5842) The server detected an infinite loop while processing\n\t * the request (sent instead of 208 Already Reported).\n\t */\n\tLoopDetected = 508,\n\n\t/**\n\t * (RFC 2774) Further extensions to the request are required for the server\n\t * to fulfil it.\n\t */\n\tNotExtended = 510,\n\n\t/**\n\t * (RFC 6585) The client needs to authenticate to gain network access.\n\t * Intended for use by intercepting proxies used to control access to the\n\t * network (e.g., \"captive portals\" used to require agreement to Terms of\n\t * Service before granting full Internet access via a Wi-Fi hotspot).\n\t */\n\tNetworkAuthenticationRequired = 511\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/http/HttpMethods.ts"],"names":[],"mappings":";;;AAEO,IAAM,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/http/HttpMethods.ts"],"names":[],"mappings":";;;AAEO,IAAM,WAAA,GAAc;AAAA,EAC1B,KAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,QAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,WAAA;AAAA,EACA,OAAA;AAAA,EACA,KAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,WAAA;AAAA,EACA,OAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA;AACD","file":"HttpMethods.cjs","sourcesContent":["export type MethodName = (typeof MethodNames)[number];\n\nexport const MethodNames = [\n\t'ACL',\n\t'BIND',\n\t'CHECKOUT',\n\t'CONNECT',\n\t'COPY',\n\t'DELETE',\n\t'GET',\n\t'HEAD',\n\t'LINK',\n\t'LOCK',\n\t'M-SEARCH',\n\t'MERGE',\n\t'MKACTIVITY',\n\t'MKCALENDAR',\n\t'MKCOL',\n\t'MOVE',\n\t'NOTIFY',\n\t'OPTIONS',\n\t'PATCH',\n\t'POST',\n\t'PROPFIND',\n\t'PROPPATCH',\n\t'PURGE',\n\t'PUT',\n\t'QUERY',\n\t'REBIND',\n\t'REPORT',\n\t'SEARCH',\n\t'SOURCE',\n\t'SUBSCRIBE',\n\t'TRACE',\n\t'UNBIND',\n\t'UNLINK',\n\t'UNLOCK',\n\t'UNSUBSCRIBE'\n] as const;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/http/Server.ts"],"names":["ServerEvent","AsyncEventEmitter","container","httpCreateServer","ApiRequest","ApiResponse","RouteStore","MiddlewareStore","Auth","error"],"mappings":";;;;;;;;;;;;;;;AAYY,IAAA,WAAA,qBAAAA,YAAL,KAAA;AACN,EAAAA,aAAA,OAAQ,CAAA,GAAA,OAAA;AACR,EAAAA,aAAA,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QAAO,MAAA,CAAA,GAAA,CAAI,SAAS,KAAK,CAAA;AACzB,QAAO,MAAA,CAAA,GAAA,CAAI,SAAS,KAAK,CAAA;AAAA;AAHjB,MAAA,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA;AAMT,MAAO,MAAA,CAAA,EAAA,CAAG,aAAa,SAAS,CAAA;AAChC,MAAO,MAAA,CAAA,EAAA,CAAG,SAAS,KAAK,CAAA;AACxB,MAAO,MAAA,CAAA,EAAA,CAAG,SAAS,KAAK,CAAA;AAAA,KACxB,CAAA;AAAA;AACF,EAEO,UAAa,GAAA;AACnB,IAAA,OAAO,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAW,KAAA;AAC7C,MAAK,IAAA,CAAA,MAAA,CAAO,MAAM,CAAC,KAAA,KAAW,QAAQ,MAAO,CAAA,KAAK,CAAI,GAAA,OAAA,EAAU,CAAA;AAAA,KAChE,CAAA;AAAA;AAEH,CAAA;AA7F4D,MAAA,CAAA,OAAA,EAAA,QAAA,CAAA;AAArD,IAAM,MAAN,GAAA","file":"Server.cjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport { Server as HttpServer, createServer as httpCreateServer, type ServerOptions as HttpOptions } from 'node:http';\nimport type { ListenOptions } from 'node:net';\nimport { MiddlewareStore } from '../MiddlewareStore';\nimport type { Route } from '../Route';\nimport { RouteStore } from '../RouteStore';\nimport { ApiRequest } from '../api/ApiRequest';\nimport { ApiResponse } from '../api/ApiResponse';\nimport type { RouterBranch } from '../router/RouterBranch';\nimport { Auth, type ServerOptionsAuth } from './Auth';\n\nexport enum ServerEvent {\n\tError = 'error',\n\tRequest = 'request',\n\tRouterBranchNotFound = 'routerBranchNotFound',\n\tRouterBranchMethodNotAllowed = 'routerBranchMethodNotAllowed',\n\tRouterFound = 'routerFound',\n\tRouteError = 'routeError',\n\tMiddlewareFailure = 'middlewareFailure',\n\tMiddlewareError = 'middlewareError',\n\tMiddlewareSuccess = 'middlewareSuccess'\n}\n\nexport interface ServerEvents {\n\t[ServerEvent.Error]: [error: Error, request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.Request]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouterBranchNotFound]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouterBranchMethodNotAllowed]: [request: ApiRequest, response: ApiResponse, node: RouterBranch];\n\t[ServerEvent.RouterFound]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouteError]: [error: Error, request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.MiddlewareFailure]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.MiddlewareSuccess]: [request: Route.Request, response: Route.Response, route: Route];\n\t[ServerEvent.MiddlewareError]: [error: Error, request: ApiRequest, response: ApiResponse];\n}\n\n/**\n * @since 1.0.0\n */\nexport class Server extends AsyncEventEmitter<ServerEvents> {\n\t/**\n\t * The routes this server holds.\n\t * @since 1.0.0\n\t */\n\tpublic readonly routes: RouteStore;\n\n\t/**\n\t * The middlewares this server holds.\n\t * @since 1.0.0\n\t */\n\tpublic readonly middlewares: MiddlewareStore;\n\n\t/**\n\t * The authentication system.\n\t * @since 1.0.0\n\t */\n\tpublic readonly auth: Auth | null;\n\n\t/**\n\t * The http.Server instance that manages the recieved HTTP requests.\n\t * @since 1.0.0\n\t */\n\tpublic readonly server: HttpServer;\n\n\t/**\n\t * The options for this server.\n\t * @since 1.0.0\n\t */\n\tpublic readonly options: AuthLessServerOptions;\n\n\t/**\n\t * @since 1.0.0\n\t * @param options The options for this server\n\t */\n\tpublic constructor({ auth, ...options }: ServerOptions = {}) {\n\t\tsuper();\n\n\t\tcontainer.server = this;\n\n\t\tthis.options = options;\n\t\tthis.server = httpCreateServer({\n\t\t\tIncomingMessage: ApiRequest,\n\t\t\tServerResponse: ApiResponse,\n\t\t\t...(options.server ?? {})\n\t\t});\n\t\tthis.routes = new RouteStore();\n\t\tthis.middlewares = new MiddlewareStore();\n\t\tthis.auth = Auth.create(auth);\n\t\tthis.server.on('error', this.emit.bind(this, ServerEvent.Error));\n\t\tthis.server.on('request', this.emit.bind(this, ServerEvent.Request));\n\t}\n\n\tpublic connect() {\n\t\tconst { server } = this;\n\t\tserver.listen({\n\t\t\tport: 4000,\n\t\t\t...(this.options.listenOptions ?? {})\n\t\t});\n\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tfunction listening() {\n\t\t\t\tcleanup();\n\t\t\t\tresolve();\n\t\t\t}\n\n\t\t\tfunction error(error: Error) {\n\t\t\t\tcleanup();\n\t\t\t\treject(error);\n\t\t\t}\n\n\t\t\tfunction close() {\n\t\t\t\tcleanup();\n\t\t\t\treject(new Error('Closed unexpectedly.'));\n\t\t\t}\n\n\t\t\tfunction cleanup() {\n\t\t\t\tserver.off('listening', listening);\n\t\t\t\tserver.off('error', error);\n\t\t\t\tserver.off('close', close);\n\t\t\t}\n\n\t\t\tserver.on('listening', listening);\n\t\t\tserver.on('error', error);\n\t\t\tserver.on('close', close);\n\t\t});\n\t}\n\n\tpublic disconnect() {\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tthis.server.close((error) => (error ? reject(error) : resolve()));\n\t\t});\n\t}\n}\n\n/**\n * RFC 1341 4: Defines a Content-Type's type, which follows the following structure:\n *\n * - `type` = `text` | `multipart` | `message` | `image` | `audio` | `video` | `application` | x-token\n * - `x-token` = The two characters \"X-\" followed, with no intervening white space, by any token\n * @since 1.3.0\n */\nexport type ContentTypeType = 'text' | 'multipart' | 'message' | 'image' | 'audio' | 'video' | 'application' | `X-${string}`;\n\n/**\n * RFC 1341 4: Defines a Content-Type's parameter, which follows the following structure:\n *\n * - `parameter` = `attribute` \"=\" `value`\n * - `attribute` = `token`\n * - `value` = `token` / `quoted-string`\n * - `token` = `1*<any CHAR except \"SPACE\", \"CTLs\", or \"tspecials\">`\n * - `tspecials` = `(` | `)` | `<` | `>` | `@` | `,` | `;` | `:` | `\\` | `\"` | `/` | `[` | `]` | `?` | `.` | `=`\n *\n * @note `tspecials` must be in quoted-string, to use within parameter values.\n * @note The definition of `tspecials` is the same as the RFC 822 definition of `specials` with the addition of the\n * three characters `/`, `?`, and `=`.\n * @since 1.3.0\n */\nexport type ContentTypeParameter = `; ${string}=${string}`;\n\n/**\n * RFC 1341 4: Defines the syntax for a Content-Type field without parameters, which follows the following structure:\n * `type \"/\" subtype`.\n * @since 7.0.0\n */\nexport type GenericMimeType = `${ContentTypeType}/${string}`;\n\n/**\n * RFC 1341 4: Defines the syntax for a Content-Type field, which follows the following structure:\n * `type \"/\" subtype *[\";\" parameter]`.\n * @since 7.0.0\n */\nexport type GenericParametrizedMimeType = `${GenericMimeType}${'' | ContentTypeParameter}`;\n\n/**\n * The API options.\n * @since 1.0.0\n */\nexport interface ServerOptions {\n\t/**\n\t * The prefix for all routes, e.g. `v1/`.\n\t * @since 1.0.0\n\t * @default ''\n\t */\n\tprefix?: string;\n\n\t/**\n\t * The origin header to be set on every request at 'Access-Control-Allow-Origin'.\n\t * @since 1.0.0\n\t * @default '*'\n\t */\n\torigin?: 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 * @default 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The HTTP server options.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\tserver?: HttpOptions;\n\n\t/**\n\t * The HTTP listen options.\n\t * @since 1.0.0\n\t * @default { port: 4000 }\n\t */\n\tlistenOptions?: ListenOptions;\n\n\t/**\n\t * The auth options. If neither `auth` nor `auth.secret` are defined, auth-related routes and middlewares will be\n\t * automatically disabled.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\tauth?: ServerOptionsAuth;\n\n\t/**\n\t * Whether the server should connect upon being when the plugin is loaded.\n\t * @since 3.2.0\n\t * @default true\n\t */\n\tautomaticallyConnect?: boolean;\n}\n\n/**\n * The {@link ServerOptions} without {@link ServerOptions.auth}.\n * @since 1.0.0\n */\nexport type AuthLessServerOptions = Omit<ServerOptions, 'auth'>;\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/http/Server.ts"],"names":["ServerEvent","AsyncEventEmitter","container","httpCreateServer","ApiRequest","ApiResponse","RouteStore","MiddlewareStore","Auth","error"],"mappings":";;;;;;;;;;;;;;;AAYO,IAAK,WAAA,qBAAAA,YAAAA,KAAL;AACN,EAAAA,aAAA,OAAA,CAAA,GAAQ,OAAA;AACR,EAAAA,aAAA,SAAA,CAAA,GAAU,SAAA;AACV,EAAAA,aAAA,sBAAA,CAAA,GAAuB,sBAAA;AACvB,EAAAA,aAAA,8BAAA,CAAA,GAA+B,8BAAA;AAC/B,EAAAA,aAAA,aAAA,CAAA,GAAc,aAAA;AACd,EAAAA,aAAA,YAAA,CAAA,GAAa,YAAA;AACb,EAAAA,aAAA,mBAAA,CAAA,GAAoB,mBAAA;AACpB,EAAAA,aAAA,iBAAA,CAAA,GAAkB,iBAAA;AAClB,EAAAA,aAAA,mBAAA,CAAA,GAAoB,mBAAA;AATT,EAAA,OAAAA,YAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;AA2BL,IAAM,OAAA,GAAN,MAAM,OAAA,SAAeC,qCAAA,CAAgC;AAAA;AAAA;AAAA;AAAA;AAAA,EAmCpD,YAAY,EAAE,IAAA,EAAM,GAAG,OAAA,EAAQ,GAAmB,EAAC,EAAG;AAC5D,IAAA,KAAA,EAAM;AA/BP;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,QAAA,CAAA;AAMhB;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,aAAA,CAAA;AAMhB;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,MAAA,CAAA;AAMhB;AAAA;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,QAAA,CAAA;AAMhB;AAAA;AAAA;AAAA;AA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K,CAAA;AAAA,MACb;AAHS,MAAA,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA;AAKT,MAAA,SAAS,KAAA,GAAQ;AAChB,QAAA,OAAA,EAAQ;AACR,QAAA,MAAA,CAAO,IAAI,KAAA,CAAM,sBAAsB,CAAC,CAAA;AAAA,MACzC;AAHS,MAAA,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA;AAKT,MAAA,SAAS,OAAA,GAAU;AAClB,QAAA,MAAA,CAAO,GAAA,CAAI,aAAa,SAAS,CAAA;AACjC,QAAA,MAAA,CAAO,GAAA,CAAI,SAAS,KAAK,CAAA;AACzB,QAAA,MAAA,CAAO,GAAA,CAAI,SAAS,KAAK,CAAA;AAAA,MAC1B;AAJS,MAAA,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA;AAMT,MAAA,MAAA,CAAO,EAAA,CAAG,aAAa,SAAS,CAAA;AAChC,MAAA,MAAA,CAAO,EAAA,CAAG,SAAS,KAAK,CAAA;AACxB,MAAA,MAAA,CAAO,EAAA,CAAG,SAAS,KAAK,CAAA;AAAA,IACzB,CAAC,CAAA;AAAA,EACF;AAAA,EAEO,UAAA,GAAa;AACnB,IAAA,OAAO,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAA,KAAW;AAC7C,MAAA,IAAA,CAAK,MAAA,CAAO,MAAM,CAAC,KAAA,KAAW,QAAQ,MAAA,CAAO,KAAK,CAAA,GAAI,OAAA,EAAU,CAAA;AAAA,IACjE,CAAC,CAAA;AAAA,EACF;AACD,CAAA;AA7F4D,MAAA,CAAA,OAAA,EAAA,QAAA,CAAA;AAArD,IAAM,MAAA,GAAN","file":"Server.cjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport { Server as HttpServer, createServer as httpCreateServer, type ServerOptions as HttpOptions } from 'node:http';\nimport type { ListenOptions } from 'node:net';\nimport { MiddlewareStore } from '../MiddlewareStore';\nimport type { Route } from '../Route';\nimport { RouteStore } from '../RouteStore';\nimport { ApiRequest } from '../api/ApiRequest';\nimport { ApiResponse } from '../api/ApiResponse';\nimport type { RouterBranch } from '../router/RouterBranch';\nimport { Auth, type ServerOptionsAuth } from './Auth';\n\nexport enum ServerEvent {\n\tError = 'error',\n\tRequest = 'request',\n\tRouterBranchNotFound = 'routerBranchNotFound',\n\tRouterBranchMethodNotAllowed = 'routerBranchMethodNotAllowed',\n\tRouterFound = 'routerFound',\n\tRouteError = 'routeError',\n\tMiddlewareFailure = 'middlewareFailure',\n\tMiddlewareError = 'middlewareError',\n\tMiddlewareSuccess = 'middlewareSuccess'\n}\n\nexport interface ServerEvents {\n\t[ServerEvent.Error]: [error: Error, request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.Request]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouterBranchNotFound]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouterBranchMethodNotAllowed]: [request: ApiRequest, response: ApiResponse, node: RouterBranch];\n\t[ServerEvent.RouterFound]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouteError]: [error: Error, request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.MiddlewareFailure]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.MiddlewareSuccess]: [request: Route.Request, response: Route.Response, route: Route];\n\t[ServerEvent.MiddlewareError]: [error: Error, request: ApiRequest, response: ApiResponse];\n}\n\n/**\n * @since 1.0.0\n */\nexport class Server extends AsyncEventEmitter<ServerEvents> {\n\t/**\n\t * The routes this server holds.\n\t * @since 1.0.0\n\t */\n\tpublic readonly routes: RouteStore;\n\n\t/**\n\t * The middlewares this server holds.\n\t * @since 1.0.0\n\t */\n\tpublic readonly middlewares: MiddlewareStore;\n\n\t/**\n\t * The authentication system.\n\t * @since 1.0.0\n\t */\n\tpublic readonly auth: Auth | null;\n\n\t/**\n\t * The http.Server instance that manages the recieved HTTP requests.\n\t * @since 1.0.0\n\t */\n\tpublic readonly server: HttpServer;\n\n\t/**\n\t * The options for this server.\n\t * @since 1.0.0\n\t */\n\tpublic readonly options: AuthLessServerOptions;\n\n\t/**\n\t * @since 1.0.0\n\t * @param options The options for this server\n\t */\n\tpublic constructor({ auth, ...options }: ServerOptions = {}) {\n\t\tsuper();\n\n\t\tcontainer.server = this;\n\n\t\tthis.options = options;\n\t\tthis.server = httpCreateServer({\n\t\t\tIncomingMessage: ApiRequest,\n\t\t\tServerResponse: ApiResponse,\n\t\t\t...(options.server ?? {})\n\t\t});\n\t\tthis.routes = new RouteStore();\n\t\tthis.middlewares = new MiddlewareStore();\n\t\tthis.auth = Auth.create(auth);\n\t\tthis.server.on('error', this.emit.bind(this, ServerEvent.Error));\n\t\tthis.server.on('request', this.emit.bind(this, ServerEvent.Request));\n\t}\n\n\tpublic connect() {\n\t\tconst { server } = this;\n\t\tserver.listen({\n\t\t\tport: 4000,\n\t\t\t...(this.options.listenOptions ?? {})\n\t\t});\n\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tfunction listening() {\n\t\t\t\tcleanup();\n\t\t\t\tresolve();\n\t\t\t}\n\n\t\t\tfunction error(error: Error) {\n\t\t\t\tcleanup();\n\t\t\t\treject(error);\n\t\t\t}\n\n\t\t\tfunction close() {\n\t\t\t\tcleanup();\n\t\t\t\treject(new Error('Closed unexpectedly.'));\n\t\t\t}\n\n\t\t\tfunction cleanup() {\n\t\t\t\tserver.off('listening', listening);\n\t\t\t\tserver.off('error', error);\n\t\t\t\tserver.off('close', close);\n\t\t\t}\n\n\t\t\tserver.on('listening', listening);\n\t\t\tserver.on('error', error);\n\t\t\tserver.on('close', close);\n\t\t});\n\t}\n\n\tpublic disconnect() {\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tthis.server.close((error) => (error ? reject(error) : resolve()));\n\t\t});\n\t}\n}\n\n/**\n * RFC 1341 4: Defines a Content-Type's type, which follows the following structure:\n *\n * - `type` = `text` | `multipart` | `message` | `image` | `audio` | `video` | `application` | x-token\n * - `x-token` = The two characters \"X-\" followed, with no intervening white space, by any token\n * @since 1.3.0\n */\nexport type ContentTypeType = 'text' | 'multipart' | 'message' | 'image' | 'audio' | 'video' | 'application' | `X-${string}`;\n\n/**\n * RFC 1341 4: Defines a Content-Type's parameter, which follows the following structure:\n *\n * - `parameter` = `attribute` \"=\" `value`\n * - `attribute` = `token`\n * - `value` = `token` / `quoted-string`\n * - `token` = `1*<any CHAR except \"SPACE\", \"CTLs\", or \"tspecials\">`\n * - `tspecials` = `(` | `)` | `<` | `>` | `@` | `,` | `;` | `:` | `\\` | `\"` | `/` | `[` | `]` | `?` | `.` | `=`\n *\n * @note `tspecials` must be in quoted-string, to use within parameter values.\n * @note The definition of `tspecials` is the same as the RFC 822 definition of `specials` with the addition of the\n * three characters `/`, `?`, and `=`.\n * @since 1.3.0\n */\nexport type ContentTypeParameter = `; ${string}=${string}`;\n\n/**\n * RFC 1341 4: Defines the syntax for a Content-Type field without parameters, which follows the following structure:\n * `type \"/\" subtype`.\n * @since 7.0.0\n */\nexport type GenericMimeType = `${ContentTypeType}/${string}`;\n\n/**\n * RFC 1341 4: Defines the syntax for a Content-Type field, which follows the following structure:\n * `type \"/\" subtype *[\";\" parameter]`.\n * @since 7.0.0\n */\nexport type GenericParametrizedMimeType = `${GenericMimeType}${'' | ContentTypeParameter}`;\n\n/**\n * The API options.\n * @since 1.0.0\n */\nexport interface ServerOptions {\n\t/**\n\t * The prefix for all routes, e.g. `v1/`.\n\t * @since 1.0.0\n\t * @default ''\n\t */\n\tprefix?: string;\n\n\t/**\n\t * The origin header to be set on every request at 'Access-Control-Allow-Origin'.\n\t * @since 1.0.0\n\t * @default '*'\n\t */\n\torigin?: 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 * @default 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The HTTP server options.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\tserver?: HttpOptions;\n\n\t/**\n\t * The HTTP listen options.\n\t * @since 1.0.0\n\t * @default { port: 4000 }\n\t */\n\tlistenOptions?: ListenOptions;\n\n\t/**\n\t * The auth options. If neither `auth` nor `auth.secret` are defined, auth-related routes and middlewares will be\n\t * automatically disabled.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\tauth?: ServerOptionsAuth;\n\n\t/**\n\t * Whether the server should connect upon being when the plugin is loaded.\n\t * @since 3.2.0\n\t * @default true\n\t */\n\tautomaticallyConnect?: boolean;\n}\n\n/**\n * The {@link ServerOptions} without {@link ServerOptions.auth}.\n * @since 1.0.0\n */\nexport type AuthLessServerOptions = Omit<ServerOptions, 'auth'>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/router/RouterBranch.ts"],"names":["RouterNode","branch","isNullish"],"mappings":";;;;;;;;;AAIO,IAAM,aAAA,GAAN,MAAM,aAAa,CAAA;AAAA,EA6BlB,WAAA,CAAY,IAAc,EAAA,OAAA,EAAkB,MAA6B,EAAA;AAzBhF;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,EAAO,IAAIA,yBAAA,CAAW,IAAI,CAAA,CAAA;AAK1C;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,oBAAsC,EAAC,CAAA;AAE9C,IAAA,aAAA,CAAA,IAAA,EAAQ,mBAAkC,EAAC,CAAA;AAC3C,IAAA,aAAA,CAAA,IAAA,EAAQ,eAAqC,EAAA,IAAA,CAAA;AAG5C,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA;AACZ,IAAA,IAAA,CAAK,OAAU,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,QAAA,OAAA,CAAQ,IAAI,MAAM,CAAA;AAAA;AACnB;AAGD,IAAK,IAAA,CAAA,gBAAA,GAAmB,CAAC,GAAG,OAAO,CAAA;AAAA;AAErC,CAAA;AA7M0B,MAAA,CAAA,aAAA,EAAA,cAAA,CAAA;AAAnB,IAAM,YAAN,GAAA","file":"RouterBranch.cjs","sourcesContent":["import { isNullish } from '@sapphire/utilities';\nimport type { Route } from '../Route';\nimport { RouterNode } from './RouterNode';\n\nexport class RouterBranch {\n\t/**\n\t * The name of the branch.\n\t */\n\tpublic readonly name: string;\n\n\t/**\n\t * Whether or not the branch is dynamic.\n\t */\n\tpublic readonly dynamic: boolean;\n\n\t/**\n\t * The parent branch, if any.\n\t */\n\tpublic readonly parent: RouterBranch | null;\n\n\t/**\n\t * The node this branch is associated with.\n\t */\n\tpublic readonly node = new RouterNode(this);\n\n\t/**\n\t * The methods supported by the branch's node or any of its children.\n\t */\n\tpublic supportedMethods: readonly string[] = [];\n\n\tprivate _staticChildren: RouterBranch[] = [];\n\tprivate _dynamicChild: RouterBranch | null = null;\n\n\tpublic constructor(name: string, dynamic: boolean, parent: RouterBranch | null) {\n\t\tthis.name = name;\n\t\tthis.dynamic = dynamic;\n\t\tthis.parent = parent;\n\t}\n\n\t/**\n\t * The path representing this branch\n\t * @version 7.0.0\n\t */\n\tpublic get path(): string {\n\t\treturn this.parent ? `${this.parent}/${this}` : `${this}`;\n\t}\n\n\t/**\n\t * The branches the branch is associated with\n\t * @version 7.0.0\n\t */\n\tpublic get children(): RouterBranch[] {\n\t\treturn this._staticChildren.concat(this._dynamicChild ?? []);\n\t}\n\n\t/**\n\t * Whether or not the branch is empty\n\t * @version 7.0.0\n\t */\n\tpublic get empty(): boolean {\n\t\treturn this._staticChildren.length === 0 && this._dynamicChild === null;\n\t}\n\n\t/**\n\t * Tries to find a branch given a path\n\t * @version 7.0.0\n\t *\n\t * @param parts The parts of a path to find a node from\n\t * @returns The branch found, or null if not found\n\t */\n\tpublic find(parts: readonly string[]): RouterBranch | null {\n\t\treturn this._find(parts, 0);\n\t}\n\n\t/**\n\t * Checks if the given name matches the branch\n\t * @version 7.0.0\n\t *\n\t * @param name The name to match\n\t * @returns Whether or not the branch matches the name\n\t */\n\tpublic matches(name: string): boolean {\n\t\treturn this.dynamic || this.name === name;\n\t}\n\n\t/**\n\t * Returns the string representation of the branch\n\t * @version 7.0.0\n\t *\n\t * @returns The string representation of the branch\n\t */\n\tpublic toString(): string {\n\t\treturn this.dynamic ? `[${this.name}]` : this.name;\n\t}\n\n\tpublic *nodes(): IterableIterator<RouterNode> {\n\t\tyield this.node;\n\t\tfor (const child of this._staticChildren) {\n\t\t\tyield* child.nodes();\n\t\t}\n\n\t\tif (this._dynamicChild) {\n\t\t\tyield* this._dynamicChild.nodes();\n\t\t}\n\t}\n\n\tprotected _add(parts: readonly string[], index: number, route: Route): RouterNode {\n\t\tconst result = this._performAdd(parts, index, route);\n\t\tthis._updateSupportedChildrenMethods();\n\t\treturn result;\n\t}\n\n\tprotected _remove(parts: readonly string[], index: number, route: Route): boolean {\n\t\tconst result = this._performRemove(parts, index, route);\n\t\tif (result) this._updateSupportedChildrenMethods();\n\t\treturn result;\n\t}\n\n\tprotected _performAdd(parts: readonly string[], index: number, route: Route): RouterNode {\n\t\tif (index >= parts.length) {\n\t\t\tfor (const method of route.methods) {\n\t\t\t\tthis.node.set(method, route);\n\t\t\t}\n\n\t\t\treturn this.node;\n\t\t}\n\n\t\tconst part = parts[index];\n\t\tconst child = this._staticChildren.find((branch) => branch.matches(part));\n\t\tif (child) {\n\t\t\treturn child._add(parts, index + 1, route);\n\t\t}\n\n\t\tif (this._dynamicChild) {\n\t\t\treturn this._dynamicChild._add(parts, index + 1, route);\n\t\t}\n\n\t\tconst dynamic = part.startsWith('[') && part.endsWith(']');\n\t\tlet branch: RouterBranch;\n\t\tif (dynamic) {\n\t\t\tbranch = new RouterBranch(part.slice(1, -1), true, this);\n\t\t\tthis._dynamicChild = branch;\n\t\t} else {\n\t\t\tbranch = new RouterBranch(part, false, this);\n\t\t\tthis._staticChildren.push(branch);\n\t\t}\n\n\t\treturn branch._add(parts, index + 1, route);\n\t}\n\n\tprotected _performRemove(parts: readonly string[], index: number, route: Route): boolean {\n\t\tif (index >= parts.length) {\n\t\t\tlet success = false;\n\t\t\tfor (const method of route.methods) {\n\t\t\t\tif (this.node.delete(method, route)) {\n\t\t\t\t\tsuccess = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn success;\n\t\t}\n\n\t\tconst part = parts[index];\n\t\tconst staticChildIndex = this._staticChildren.findIndex((branch) => branch.matches(part));\n\t\tif (staticChildIndex === -1) {\n\t\t\tconst child = this._staticChildren[index];\n\t\t\tconst removed = child._remove(parts, index + 1, route);\n\t\t\tif (removed && child.empty) {\n\t\t\t\tthis._staticChildren = this._staticChildren.filter((branch) => branch !== child);\n\t\t\t}\n\n\t\t\treturn removed;\n\t\t}\n\n\t\tif (this._dynamicChild) {\n\t\t\tconst removed = this._dynamicChild._remove(parts, index + 1, route);\n\t\t\tif (removed && this._dynamicChild.empty) {\n\t\t\t\tthis._dynamicChild = null;\n\t\t\t}\n\n\t\t\treturn removed;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tprotected _find(parts: readonly string[], index: number): RouterBranch | null {\n\t\tif (index >= parts.length) return this;\n\n\t\tconst part = parts[index];\n\t\tconst child = this._staticChildren.find((branch) => branch.matches(part)) ?? this._dynamicChild;\n\n\t\t// If a child is not found, return null:\n\t\tif (isNullish(child)) return null;\n\n\t\t// Continue the search:\n\t\treturn child._find(parts, index + 1);\n\t}\n\n\tprotected _updateSupportedChildrenMethods(): void {\n\t\tconst methods = new Set(this.node.methods());\n\t\tfor (const child of this.children) {\n\t\t\tfor (const method of child.node.methods()) {\n\t\t\t\tmethods.add(method);\n\t\t\t}\n\t\t}\n\n\t\tthis.supportedMethods = [...methods];\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/router/RouterBranch.ts"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AI,OAAA,IAAW,IAAA,CAAK,aAAA,CAAc,KAAA,EAAO;AACxC,QAAA,IAAA,CAAK,aAAA,GAAgB,IAAA;AAAA,MACtB;AAEA,MAAA,OAAO,OAAA;AAAA,IACR;AAEA,IAAA,OAAO,KAAA;AAAA,EACR;AAAA,EAEU,KAAA,CAAM,OAA0B,KAAA,EAAoC;AAC7E,IAAA,IAAI,KAAA,IAAS,KAAA,CAAM,MAAA,EAAQ,OAAO,IAAA;AAElC,IAAA,MAAM,IAAA,GAAO,MAAM,KAAK,CAAA;AACxB,IAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,eAAA,CAAgB,IAAA,CAAK,CAAC,MAAA,KAAW,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAC,CAAA,IAAK,IAAA,CAAK,aAAA;AAGlF,IAAA,IAAIC,mBAAA,CAAU,KAAK,CAAA,EAAG,OAAO,IAAA;AAG7B,IAAA,OAAO,KAAA,CAAM,KAAA,CAAM,KAAA,EAAO,KAAA,GAAQ,CAAC,CAAA;AAAA,EACpC;AAAA,EAEU,+BAAA,GAAwC;AACjD,IAAA,MAAM,UAAU,IAAI,GAAA,CAAI,IAAA,CAAK,IAAA,CAAK,SAAS,CAAA;AAC3C,IAAA,KAAA,MAAW,KAAA,IAAS,KAAK,QAAA,EAAU;AAClC,MAAA,KAAA,MAAW,MAAA,IAAU,KAAA,CAAM,IAAA,CAAK,OAAA,EAAQ,EAAG;AAC1C,QAAA,OAAA,CAAQ,IAAI,MAAM,CAAA;AAAA,MACnB;AAAA,IACD;AAEA,IAAA,IAAA,CAAK,gBAAA,GAAmB,CAAC,GAAG,OAAO,CAAA;AAAA,EACpC;AACD,CAAA;AA7M0B,MAAA,CAAA,aAAA,EAAA,cAAA,CAAA;AAAnB,IAAM,YAAA,GAAN","file":"RouterBranch.cjs","sourcesContent":["import { isNullish } from '@sapphire/utilities';\nimport type { Route } from '../Route';\nimport { RouterNode } from './RouterNode';\n\nexport class RouterBranch {\n\t/**\n\t * The name of the branch.\n\t */\n\tpublic readonly name: string;\n\n\t/**\n\t * Whether or not the branch is dynamic.\n\t */\n\tpublic readonly dynamic: boolean;\n\n\t/**\n\t * The parent branch, if any.\n\t */\n\tpublic readonly parent: RouterBranch | null;\n\n\t/**\n\t * The node this branch is associated with.\n\t */\n\tpublic readonly node = new RouterNode(this);\n\n\t/**\n\t * The methods supported by the branch's node or any of its children.\n\t */\n\tpublic supportedMethods: readonly string[] = [];\n\n\tprivate _staticChildren: RouterBranch[] = [];\n\tprivate _dynamicChild: RouterBranch | null = null;\n\n\tpublic constructor(name: string, dynamic: boolean, parent: RouterBranch | null) {\n\t\tthis.name = name;\n\t\tthis.dynamic = dynamic;\n\t\tthis.parent = parent;\n\t}\n\n\t/**\n\t * The path representing this branch\n\t * @version 7.0.0\n\t */\n\tpublic get path(): string {\n\t\treturn this.parent ? `${this.parent}/${this}` : `${this}`;\n\t}\n\n\t/**\n\t * The branches the branch is associated with\n\t * @version 7.0.0\n\t */\n\tpublic get children(): RouterBranch[] {\n\t\treturn this._staticChildren.concat(this._dynamicChild ?? []);\n\t}\n\n\t/**\n\t * Whether or not the branch is empty\n\t * @version 7.0.0\n\t */\n\tpublic get empty(): boolean {\n\t\treturn this._staticChildren.length === 0 && this._dynamicChild === null;\n\t}\n\n\t/**\n\t * Tries to find a branch given a path\n\t * @version 7.0.0\n\t *\n\t * @param parts The parts of a path to find a node from\n\t * @returns The branch found, or null if not found\n\t */\n\tpublic find(parts: readonly string[]): RouterBranch | null {\n\t\treturn this._find(parts, 0);\n\t}\n\n\t/**\n\t * Checks if the given name matches the branch\n\t * @version 7.0.0\n\t *\n\t * @param name The name to match\n\t * @returns Whether or not the branch matches the name\n\t */\n\tpublic matches(name: string): boolean {\n\t\treturn this.dynamic || this.name === name;\n\t}\n\n\t/**\n\t * Returns the string representation of the branch\n\t * @version 7.0.0\n\t *\n\t * @returns The string representation of the branch\n\t */\n\tpublic toString(): string {\n\t\treturn this.dynamic ? `[${this.name}]` : this.name;\n\t}\n\n\tpublic *nodes(): IterableIterator<RouterNode> {\n\t\tyield this.node;\n\t\tfor (const child of this._staticChildren) {\n\t\t\tyield* child.nodes();\n\t\t}\n\n\t\tif (this._dynamicChild) {\n\t\t\tyield* this._dynamicChild.nodes();\n\t\t}\n\t}\n\n\tprotected _add(parts: readonly string[], index: number, route: Route): RouterNode {\n\t\tconst result = this._performAdd(parts, index, route);\n\t\tthis._updateSupportedChildrenMethods();\n\t\treturn result;\n\t}\n\n\tprotected _remove(parts: readonly string[], index: number, route: Route): boolean {\n\t\tconst result = this._performRemove(parts, index, route);\n\t\tif (result) this._updateSupportedChildrenMethods();\n\t\treturn result;\n\t}\n\n\tprotected _performAdd(parts: readonly string[], index: number, route: Route): RouterNode {\n\t\tif (index >= parts.length) {\n\t\t\tfor (const method of route.methods) {\n\t\t\t\tthis.node.set(method, route);\n\t\t\t}\n\n\t\t\treturn this.node;\n\t\t}\n\n\t\tconst part = parts[index];\n\t\tconst child = this._staticChildren.find((branch) => branch.matches(part));\n\t\tif (child) {\n\t\t\treturn child._add(parts, index + 1, route);\n\t\t}\n\n\t\tif (this._dynamicChild) {\n\t\t\treturn this._dynamicChild._add(parts, index + 1, route);\n\t\t}\n\n\t\tconst dynamic = part.startsWith('[') && part.endsWith(']');\n\t\tlet branch: RouterBranch;\n\t\tif (dynamic) {\n\t\t\tbranch = new RouterBranch(part.slice(1, -1), true, this);\n\t\t\tthis._dynamicChild = branch;\n\t\t} else {\n\t\t\tbranch = new RouterBranch(part, false, this);\n\t\t\tthis._staticChildren.push(branch);\n\t\t}\n\n\t\treturn branch._add(parts, index + 1, route);\n\t}\n\n\tprotected _performRemove(parts: readonly string[], index: number, route: Route): boolean {\n\t\tif (index >= parts.length) {\n\t\t\tlet success = false;\n\t\t\tfor (const method of route.methods) {\n\t\t\t\tif (this.node.delete(method, route)) {\n\t\t\t\t\tsuccess = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn success;\n\t\t}\n\n\t\tconst part = parts[index];\n\t\tconst staticChildIndex = this._staticChildren.findIndex((branch) => branch.matches(part));\n\t\tif (staticChildIndex === -1) {\n\t\t\tconst child = this._staticChildren[index];\n\t\t\tconst removed = child._remove(parts, index + 1, route);\n\t\t\tif (removed && child.empty) {\n\t\t\t\tthis._staticChildren = this._staticChildren.filter((branch) => branch !== child);\n\t\t\t}\n\n\t\t\treturn removed;\n\t\t}\n\n\t\tif (this._dynamicChild) {\n\t\t\tconst removed = this._dynamicChild._remove(parts, index + 1, route);\n\t\t\tif (removed && this._dynamicChild.empty) {\n\t\t\t\tthis._dynamicChild = null;\n\t\t\t}\n\n\t\t\treturn removed;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tprotected _find(parts: readonly string[], index: number): RouterBranch | null {\n\t\tif (index >= parts.length) return this;\n\n\t\tconst part = parts[index];\n\t\tconst child = this._staticChildren.find((branch) => branch.matches(part)) ?? this._dynamicChild;\n\n\t\t// If a child is not found, return null:\n\t\tif (isNullish(child)) return null;\n\n\t\t// Continue the search:\n\t\treturn child._find(parts, index + 1);\n\t}\n\n\tprotected _updateSupportedChildrenMethods(): void {\n\t\tconst methods = new Set(this.node.methods());\n\t\tfor (const child of this.children) {\n\t\t\tfor (const method of child.node.methods()) {\n\t\t\t\tmethods.add(method);\n\t\t\t}\n\t\t}\n\n\t\tthis.supportedMethods = [...methods];\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/router/RouterNode.ts"],"names":["Collection"],"mappings":";;;;;;;;;;;;;;AAAA,IAAA,QAAA;AAKO,IAAM,WAAA,GAAN,MAAM,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/router/RouterNode.ts"],"names":["Collection"],"mappings":";;;;;;;;;;;;;;AAAA,IAAA,QAAA;AAKO,IAAM,WAAA,GAAN,MAAM,WAAA,CAAW;AAAA,EAWhB,YAAY,MAAA,EAAsB;AAPzC;AAAA;AAAA;AAAA,IAAA,aAAA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AAC3B,MAAA,OAAO,IAAA;AAAA,IACR;AAEA,IAAA,OAAO,KAAA;AAAA,EACR;AAAA,EAEO,OAAA,GAAwC;AAC9C,IAAA,OAAO,YAAA,CAAA,IAAA,EAAK,UAAS,IAAA,EAAK;AAAA,EAC3B;AACD,CAAA;AA/CU,QAAA,GAAA,IAAA,OAAA,EAAA;AATc,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAAjB,IAAM,UAAA,GAAN","file":"RouterNode.cjs","sourcesContent":["import { Collection } from 'discord.js';\nimport type { Route } from '../Route';\nimport type { MethodName } from '../http/HttpMethods';\nimport type { RouterBranch } from './RouterBranch';\n\nexport class RouterNode {\n\t/**\n\t * The branch containing this node.\n\t */\n\tpublic readonly parent: RouterBranch;\n\n\t/**\n\t * The methods this node supports.\n\t */\n\treadonly #methods = new Collection<MethodName, Route>();\n\n\tpublic constructor(parent: RouterBranch) {\n\t\tthis.parent = parent;\n\t}\n\n\tpublic get path() {\n\t\treturn this.parent.path;\n\t}\n\n\tpublic extractParameters(parts: readonly string[]): Record<string, string> {\n\t\tconst parameters: Record<string, string> = {};\n\n\t\tlet branch: RouterBranch | null = this.parent;\n\t\tlet index = parts.length - 1;\n\t\tdo {\n\t\t\tif (branch.dynamic) parameters[branch.name] = parts[index];\n\n\t\t\tbranch = branch.parent;\n\t\t\t--index;\n\t\t} while (branch);\n\n\t\treturn parameters;\n\t}\n\n\tpublic get(method: MethodName): Route | null {\n\t\treturn this.#methods.get(method) ?? null;\n\t}\n\n\tpublic set(method: MethodName, route: Route): this {\n\t\tthis.#methods.set(method, route);\n\t\treturn this;\n\t}\n\n\tpublic delete(method: MethodName, route: Route): boolean {\n\t\tconst existing = this.#methods.get(method);\n\t\tif (existing === route) {\n\t\t\tthis.#methods.delete(method);\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tpublic methods(): IterableIterator<MethodName> {\n\t\treturn this.#methods.keys();\n\t}\n}\n"]}
|