@sapphire/plugin-api 6.1.2-next.fc6b7cf.0 → 7.0.0-next.d27dc1c

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.
Files changed (99) hide show
  1. package/dist/cjs/index.cjs +1 -1
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.d.cts +7 -5
  4. package/dist/cjs/lib/structures/MediaParser.cjs +4 -8
  5. package/dist/cjs/lib/structures/MediaParser.cjs.map +1 -1
  6. package/dist/cjs/lib/structures/Middleware.cjs +1 -4
  7. package/dist/cjs/lib/structures/Middleware.cjs.map +1 -1
  8. package/dist/cjs/lib/structures/MiddlewareStore.cjs +6 -14
  9. package/dist/cjs/lib/structures/MiddlewareStore.cjs.map +1 -1
  10. package/dist/cjs/lib/structures/Route.cjs +5 -7
  11. package/dist/cjs/lib/structures/Route.cjs.map +1 -1
  12. package/dist/cjs/lib/structures/RouteStore.cjs +5 -12
  13. package/dist/cjs/lib/structures/RouteStore.cjs.map +1 -1
  14. package/dist/cjs/lib/structures/api/ApiRequest.cjs +1 -4
  15. package/dist/cjs/lib/structures/api/ApiRequest.cjs.map +1 -1
  16. package/dist/cjs/lib/structures/api/ApiResponse.cjs +1 -4
  17. package/dist/cjs/lib/structures/api/ApiResponse.cjs.map +1 -1
  18. package/dist/cjs/lib/structures/api/CookieStore.cjs +3 -8
  19. package/dist/cjs/lib/structures/api/CookieStore.cjs.map +1 -1
  20. package/dist/cjs/lib/structures/http/Auth.cjs +13 -31
  21. package/dist/cjs/lib/structures/http/Auth.cjs.map +1 -1
  22. package/dist/cjs/lib/structures/http/Server.cjs +1 -4
  23. package/dist/cjs/lib/structures/http/Server.cjs.map +1 -1
  24. package/dist/cjs/lib/utils/RouteData.cjs +10 -21
  25. package/dist/cjs/lib/utils/RouteData.cjs.map +1 -1
  26. package/dist/cjs/listeners/PluginRouteError.cjs +1 -2
  27. package/dist/cjs/listeners/PluginRouteError.cjs.map +1 -1
  28. package/dist/cjs/listeners/PluginServerMiddlewareError.cjs +1 -2
  29. package/dist/cjs/listeners/PluginServerMiddlewareError.cjs.map +1 -1
  30. package/dist/cjs/listeners/PluginServerNoMatch.cjs +1 -2
  31. package/dist/cjs/listeners/PluginServerNoMatch.cjs.map +1 -1
  32. package/dist/cjs/middlewares/auth.cjs +2 -6
  33. package/dist/cjs/middlewares/auth.cjs.map +1 -1
  34. package/dist/cjs/middlewares/body.cjs +3 -8
  35. package/dist/cjs/middlewares/body.cjs.map +1 -1
  36. package/dist/cjs/middlewares/cookies.cjs +1 -4
  37. package/dist/cjs/middlewares/cookies.cjs.map +1 -1
  38. package/dist/cjs/middlewares/headers.cjs +1 -4
  39. package/dist/cjs/middlewares/headers.cjs.map +1 -1
  40. package/dist/cjs/routes/oauth/callback.cjs +2 -6
  41. package/dist/cjs/routes/oauth/callback.cjs.map +1 -1
  42. package/dist/cjs/routes/oauth/logout.cjs +3 -6
  43. package/dist/cjs/routes/oauth/logout.cjs.map +1 -1
  44. package/dist/esm/chunk-JTFKMR4I.mjs +15 -0
  45. package/dist/esm/index.d.mts +7 -5
  46. package/dist/esm/index.mjs +2 -2
  47. package/dist/esm/index.mjs.map +1 -1
  48. package/dist/esm/lib/structures/MediaParser.mjs +5 -9
  49. package/dist/esm/lib/structures/MediaParser.mjs.map +1 -1
  50. package/dist/esm/lib/structures/MediaParserStore.mjs +1 -1
  51. package/dist/esm/lib/structures/Middleware.mjs +1 -1
  52. package/dist/esm/lib/structures/MiddlewareStore.mjs +6 -11
  53. package/dist/esm/lib/structures/MiddlewareStore.mjs.map +1 -1
  54. package/dist/esm/lib/structures/Route.mjs +5 -4
  55. package/dist/esm/lib/structures/Route.mjs.map +1 -1
  56. package/dist/esm/lib/structures/RouteStore.mjs +5 -9
  57. package/dist/esm/lib/structures/RouteStore.mjs.map +1 -1
  58. package/dist/esm/lib/structures/api/ApiRequest.mjs +1 -1
  59. package/dist/esm/lib/structures/api/ApiResponse.mjs +1 -1
  60. package/dist/esm/lib/structures/api/CookieStore.mjs +3 -5
  61. package/dist/esm/lib/structures/api/CookieStore.mjs.map +1 -1
  62. package/dist/esm/lib/structures/http/Auth.mjs +6 -10
  63. package/dist/esm/lib/structures/http/Auth.mjs.map +1 -1
  64. package/dist/esm/lib/structures/http/HttpCodes.mjs +1 -1
  65. package/dist/esm/lib/structures/http/HttpMethods.mjs +1 -1
  66. package/dist/esm/lib/structures/http/Server.mjs +1 -1
  67. package/dist/esm/lib/utils/MimeTypes.mjs +1 -1
  68. package/dist/esm/lib/utils/RouteData.mjs +10 -18
  69. package/dist/esm/lib/utils/RouteData.mjs.map +1 -1
  70. package/dist/esm/listeners/PluginRouteError.mjs +2 -3
  71. package/dist/esm/listeners/PluginRouteError.mjs.map +1 -1
  72. package/dist/esm/listeners/PluginServerMatch.mjs +1 -1
  73. package/dist/esm/listeners/PluginServerMiddlewareError.mjs +2 -3
  74. package/dist/esm/listeners/PluginServerMiddlewareError.mjs.map +1 -1
  75. package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs +1 -1
  76. package/dist/esm/listeners/PluginServerNoMatch.mjs +2 -3
  77. package/dist/esm/listeners/PluginServerNoMatch.mjs.map +1 -1
  78. package/dist/esm/listeners/PluginServerRequest.mjs +1 -1
  79. package/dist/esm/listeners/_load.mjs +1 -1
  80. package/dist/esm/mediaParsers/_load.mjs +1 -1
  81. package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs +1 -1
  82. package/dist/esm/mediaParsers/applicationJson.mjs +1 -1
  83. package/dist/esm/mediaParsers/textPlain.mjs +1 -1
  84. package/dist/esm/middlewares/_load.mjs +1 -1
  85. package/dist/esm/middlewares/auth.mjs +2 -3
  86. package/dist/esm/middlewares/auth.mjs.map +1 -1
  87. package/dist/esm/middlewares/body.mjs +3 -5
  88. package/dist/esm/middlewares/body.mjs.map +1 -1
  89. package/dist/esm/middlewares/cookies.mjs +1 -1
  90. package/dist/esm/middlewares/headers.mjs +1 -1
  91. package/dist/esm/register.mjs +1 -1
  92. package/dist/esm/routes/_load.mjs +1 -1
  93. package/dist/esm/routes/oauth/callback.mjs +2 -3
  94. package/dist/esm/routes/oauth/callback.mjs.map +1 -1
  95. package/dist/esm/routes/oauth/logout.mjs +4 -7
  96. package/dist/esm/routes/oauth/logout.mjs.map +1 -1
  97. package/package.json +7 -7
  98. package/dist/esm/chunk-PYETHG4R.mjs +0 -29
  99. /package/dist/esm/{chunk-PYETHG4R.mjs.map → chunk-JTFKMR4I.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/MediaParser.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,aAAa;AAEtB,SAAS,wBAAwB,cAAc,qBAAkC;AAS1E,IAAe,eAAf,MAAe,qBAA+E,MAA+B;AAAA,EAC5H,YAAY,SAAoC,UAAmB,CAAC,GAAc;AACxF,UAAM,SAAS,OAAO;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,QAAQ,OAAuB;AACrC,WAAO,MAAM,6BAA6B,QAAQ,MAAM,yBAAyB,SAAS,KAAK,IAAiC;AAAA,EACjI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,SAAsC;AAChE,UAAM,SAAS,KAAK,cAAc,OAAO;AACzC,QAAI,WAAW;AAAM,aAAO;AAE5B,QAAI,OAAO;AACX,qBAAiB,SAAS;AAAQ,cAAQ;AAE1C,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,SAAsC;AAChE,UAAM,SAAS,KAAK,cAAc,OAAO;AACzC,QAAI,WAAW;AAAM,aAAO,OAAO,MAAM,CAAC;AAE1C,UAAM,SAAmB,CAAC;AAC1B,qBAAiB,SAAS;AAAQ,aAAO,KAAK,KAAK;AAEnD,WAAO,OAAO,OAAO,MAAM;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,cAAc,SAAiD;AACxE,aAAS,QAAQ,QAAQ,kBAAkB,KAAK,YAAY,YAAY,GAAG;AAAA,MAK1E,KAAK,WAAW;AACf,cAAM,SAAS,cAAc;AAC7B,gBAAQ,KAAK,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,MAMA,KAAK;AAAA,MACL,KAAK,QAAQ;AACZ,cAAM,SAAS,aAAa;AAC5B,gBAAQ,KAAK,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,MAKA,KAAK,MAAM;AACV,cAAM,SAAS,uBAAuB;AACtC,gBAAQ,KAAK,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,MAIA,KAAK,YAAY;AAChB,eAAO;AAAA,MACR;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AACD;AAhGoI;AAA7H,IAAe,cAAf","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport { createBrotliDecompress, createGunzip, createInflate, type Gunzip } from 'zlib';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { MimeTypeWithoutParameters } from './http/Server';\nimport type { Route } from './Route';\n\n/**\n * A media parser\n * @since 1.3.0\n */\nexport abstract class MediaParser<Options extends MediaParser.Options = MediaParser.Options> extends Piece<Options, 'mediaParsers'> {\n\tpublic constructor(context: MediaParser.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t}\n\n\t/**\n\t * Parses the body data from an API request.\n\t * @since 1.3.0\n\t */\n\tpublic abstract run(request: ApiRequest): Awaitable<unknown>;\n\n\t/**\n\t * Checks if a route accepts the media type from this parser.\n\t * @since 1.3.0\n\t * @param route The route to be checked.\n\t */\n\tpublic accepts(route: Route): boolean {\n\t\treturn route.acceptedContentMimeTypes === null || route.acceptedContentMimeTypes.includes(this.name as MimeTypeWithoutParameters);\n\t}\n\n\t/**\n\t * Reads the content body as a string, this is useful for parsing/reading plain-text data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readString(request: ApiRequest): Promise<string> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return '';\n\n\t\tlet body = '';\n\t\tfor await (const chunk of stream) body += chunk;\n\n\t\treturn body;\n\t}\n\n\t/**\n\t * Reads the content body as a buffer, this is useful for parsing/reading binary data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readBuffer(request: ApiRequest): Promise<Buffer> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return Buffer.alloc(0);\n\n\t\tconst bodies: Buffer[] = [];\n\t\tfor await (const chunk of stream) bodies.push(chunk);\n\n\t\treturn Buffer.concat(bodies);\n\t}\n\n\t/**\n\t * Reads the content stream from a request, piping the data through a transformer stream.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected contentStream(request: ApiRequest): ApiRequest | Gunzip | null {\n\t\tswitch ((request.headers['content-encoding'] ?? 'identity').toLowerCase()) {\n\t\t\t// RFC 7230 4.2.2:\n\t\t\t//\n\t\t\t// The \"deflate\" coding is a \"zlib\" data format (RFC 1950) containing a \"deflate\" compressed data stream\n\t\t\t// (RFC 1951) that uses a combination of the Lempel-Ziv (LZ77) compression algorithm and Huffman coding.\n\t\t\tcase 'deflate': {\n\t\t\t\tconst stream = createInflate();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7230 4.2.3\n\t\t\t//\n\t\t\t// The \"gzip\" coding is an LZ77 coding with a 32-bit Cyclic Redundancy Check (CRC) that is commonly produced\n\t\t\t// by the gzip file compression program (RFC 1952).\n\t\t\tcase 'x-gzip':\n\t\t\tcase 'gzip': {\n\t\t\t\tconst stream = createGunzip();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7932\n\t\t\t//\n\t\t\t// A format using the Brotli algorithm.\n\t\t\tcase 'br': {\n\t\t\t\tconst stream = createBrotliDecompress();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// An \"identity\" token is used as a synonym for \"no encoding\" in order to communicate when no encoding is\n\t\t\t// preferred.\n\t\t\tcase 'identity': {\n\t\t\t\treturn request;\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n}\n\nexport namespace MediaParser {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'mediaParsers'>;\n\texport type Options = Piece.Options;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/MediaParser.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,aAAa;AAEtB,SAAS,wBAAwB,cAAc,qBAAkC;AAS1E,IAAe,eAAf,MAAe,qBAA+E,MAA+B;AAAA,EAC5H,YAAY,SAAoC,UAAmB,CAAC,GAAc;AACxF,UAAM,SAAS,OAAO;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,QAAQ,OAAuB;AACrC,WAAO,MAAM,6BAA6B,QAAQ,MAAM,yBAAyB,SAAS,KAAK,IAAiC;AAAA,EACjI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,SAAsC;AAChE,UAAM,SAAS,KAAK,cAAc,OAAO;AACzC,QAAI,WAAW,KAAM,QAAO;AAE5B,QAAI,OAAO;AACX,qBAAiB,SAAS,OAAQ,SAAQ;AAE1C,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,SAAsC;AAChE,UAAM,SAAS,KAAK,cAAc,OAAO;AACzC,QAAI,WAAW,KAAM,QAAO,OAAO,MAAM,CAAC;AAE1C,UAAM,SAAmB,CAAC;AAC1B,qBAAiB,SAAS,OAAQ,QAAO,KAAK,KAAK;AAEnD,WAAO,OAAO,OAAO,MAAM;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,cAAc,SAAiD;AACxE,aAAS,QAAQ,QAAQ,kBAAkB,KAAK,YAAY,YAAY,GAAG;AAAA,MAK1E,KAAK,WAAW;AACf,cAAM,SAAS,cAAc;AAC7B,gBAAQ,KAAK,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,MAMA,KAAK;AAAA,MACL,KAAK,QAAQ;AACZ,cAAM,SAAS,aAAa;AAC5B,gBAAQ,KAAK,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,MAKA,KAAK,MAAM;AACV,cAAM,SAAS,uBAAuB;AACtC,gBAAQ,KAAK,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,MAIA,KAAK,YAAY;AAChB,eAAO;AAAA,MACR;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AACD;AAhGoI;AAA7H,IAAe,cAAf","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport { createBrotliDecompress, createGunzip, createInflate, type Gunzip } from 'zlib';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { MimeTypeWithoutParameters } from './http/Server';\nimport type { Route } from './Route';\n\n/**\n * A media parser\n * @since 1.3.0\n */\nexport abstract class MediaParser<Options extends MediaParser.Options = MediaParser.Options> extends Piece<Options, 'mediaParsers'> {\n\tpublic constructor(context: MediaParser.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t}\n\n\t/**\n\t * Parses the body data from an API request.\n\t * @since 1.3.0\n\t */\n\tpublic abstract run(request: ApiRequest): Awaitable<unknown>;\n\n\t/**\n\t * Checks if a route accepts the media type from this parser.\n\t * @since 1.3.0\n\t * @param route The route to be checked.\n\t */\n\tpublic accepts(route: Route): boolean {\n\t\treturn route.acceptedContentMimeTypes === null || route.acceptedContentMimeTypes.includes(this.name as MimeTypeWithoutParameters);\n\t}\n\n\t/**\n\t * Reads the content body as a string, this is useful for parsing/reading plain-text data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readString(request: ApiRequest): Promise<string> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return '';\n\n\t\tlet body = '';\n\t\tfor await (const chunk of stream) body += chunk;\n\n\t\treturn body;\n\t}\n\n\t/**\n\t * Reads the content body as a buffer, this is useful for parsing/reading binary data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readBuffer(request: ApiRequest): Promise<Buffer> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return Buffer.alloc(0);\n\n\t\tconst bodies: Buffer[] = [];\n\t\tfor await (const chunk of stream) bodies.push(chunk);\n\n\t\treturn Buffer.concat(bodies);\n\t}\n\n\t/**\n\t * Reads the content stream from a request, piping the data through a transformer stream.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected contentStream(request: ApiRequest): ApiRequest | Gunzip | null {\n\t\tswitch ((request.headers['content-encoding'] ?? 'identity').toLowerCase()) {\n\t\t\t// RFC 7230 4.2.2:\n\t\t\t//\n\t\t\t// The \"deflate\" coding is a \"zlib\" data format (RFC 1950) containing a \"deflate\" compressed data stream\n\t\t\t// (RFC 1951) that uses a combination of the Lempel-Ziv (LZ77) compression algorithm and Huffman coding.\n\t\t\tcase 'deflate': {\n\t\t\t\tconst stream = createInflate();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7230 4.2.3\n\t\t\t//\n\t\t\t// The \"gzip\" coding is an LZ77 coding with a 32-bit Cyclic Redundancy Check (CRC) that is commonly produced\n\t\t\t// by the gzip file compression program (RFC 1952).\n\t\t\tcase 'x-gzip':\n\t\t\tcase 'gzip': {\n\t\t\t\tconst stream = createGunzip();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7932\n\t\t\t//\n\t\t\t// A format using the Brotli algorithm.\n\t\t\tcase 'br': {\n\t\t\t\tconst stream = createBrotliDecompress();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// An \"identity\" token is used as a synonym for \"no encoding\" in order to communicate when no encoding is\n\t\t\t// preferred.\n\t\t\tcase 'identity': {\n\t\t\t\treturn request;\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n}\n\nexport namespace MediaParser {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'mediaParsers'>;\n\texport type Options = Piece.Options;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { __name } from '../../chunk-PYETHG4R.mjs';
1
+ import { __name } from '../../chunk-JTFKMR4I.mjs';
2
2
  import { Store } from '@sapphire/pieces';
3
3
  import { MediaParser } from './MediaParser.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __name, __publicField } from '../../chunk-PYETHG4R.mjs';
1
+ import { __name, __publicField } from '../../chunk-JTFKMR4I.mjs';
2
2
  import { Piece } from '@sapphire/pieces';
3
3
 
4
4
  var _Middleware = class _Middleware extends Piece {
@@ -1,4 +1,4 @@
1
- import { __name, __publicField } from '../../chunk-PYETHG4R.mjs';
1
+ import { __name, __publicField } from '../../chunk-JTFKMR4I.mjs';
2
2
  import { Store } from '@sapphire/pieces';
3
3
  import { Middleware } from './Middleware.mjs';
4
4
 
@@ -12,24 +12,19 @@ var _MiddlewareStore = class _MiddlewareStore extends Store {
12
12
  }
13
13
  async run(request, response, route) {
14
14
  for (const middleware of this.sortedMiddlewares) {
15
- if (response.writableEnded)
16
- return;
17
- if (middleware.enabled)
18
- await middleware.run(request, response, route);
15
+ if (response.writableEnded) return;
16
+ if (middleware.enabled) await middleware.run(request, response, route);
19
17
  }
20
18
  }
21
19
  set(key, value) {
22
20
  const index = this.sortedMiddlewares.findIndex((middleware) => middleware.position >= value.position);
23
- if (index === -1)
24
- this.sortedMiddlewares.push(value);
25
- else
26
- this.sortedMiddlewares.splice(index, 0, value);
21
+ if (index === -1) this.sortedMiddlewares.push(value);
22
+ else this.sortedMiddlewares.splice(index, 0, value);
27
23
  return super.set(key, value);
28
24
  }
29
25
  delete(key) {
30
26
  const index = this.sortedMiddlewares.findIndex((middleware) => middleware.name === key);
31
- if (index !== -1)
32
- this.sortedMiddlewares.splice(index, 1);
27
+ if (index !== -1) this.sortedMiddlewares.splice(index, 1);
33
28
  return super.delete(key);
34
29
  }
35
30
  clear() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAQpB,IAAM,mBAAN,MAAM,yBAAwB,MAAiC;AAAA,EAM9D,cAAc;AACpB,UAAM,YAAY,EAAE,MAAM,cAAc,CAAC;AAH1C;AAAA;AAAA;AAAA,wBAAgB,qBAAkC,CAAC;AAAA,EAInD;AAAA,EAEA,MAAa,IAAI,SAAqB,UAAuB,OAAoC;AAChG,eAAW,cAAc,KAAK,mBAAmB;AAChD,UAAI,SAAS;AAAe;AAC5B,UAAI,WAAW;AAAS,cAAM,WAAW,IAAI,SAAS,UAAU,KAAK;AAAA,IACtE;AAAA,EACD;AAAA,EAEgB,IAAI,KAAa,OAAyB;AACzD,UAAM,QAAQ,KAAK,kBAAkB,UAAU,CAAC,eAAe,WAAW,YAAY,MAAM,QAAQ;AAGpG,QAAI,UAAU;AAAI,WAAK,kBAAkB,KAAK,KAAK;AAAA;AAC9C,WAAK,kBAAkB,OAAO,OAAO,GAAG,KAAK;AAElD,WAAO,MAAM,IAAI,KAAK,KAAK;AAAA,EAC5B;AAAA,EAEgB,OAAO,KAAsB;AAC5C,UAAM,QAAQ,KAAK,kBAAkB,UAAU,CAAC,eAAe,WAAW,SAAS,GAAG;AAGtF,QAAI,UAAU;AAAI,WAAK,kBAAkB,OAAO,OAAO,CAAC;AAExD,WAAO,MAAM,OAAO,GAAG;AAAA,EACxB;AAAA,EAEgB,QAAc;AAC7B,SAAK,kBAAkB,SAAS;AAChC,WAAO,MAAM,MAAM;AAAA,EACpB;AACD;AAxCsE;AAA/D,IAAM,kBAAN","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Middleware } from './Middleware';\nimport type { Route } from './Route';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\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: ApiRequest, response: ApiResponse, route: Route | null): 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, route);\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
+ {"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAQpB,IAAM,mBAAN,MAAM,yBAAwB,MAAiC;AAAA,EAM9D,cAAc;AACpB,UAAM,YAAY,EAAE,MAAM,cAAc,CAAC;AAH1C;AAAA;AAAA;AAAA,wBAAgB,qBAAkC,CAAC;AAAA,EAInD;AAAA,EAEA,MAAa,IAAI,SAAqB,UAAuB,OAAoC;AAChG,eAAW,cAAc,KAAK,mBAAmB;AAChD,UAAI,SAAS,cAAe;AAC5B,UAAI,WAAW,QAAS,OAAM,WAAW,IAAI,SAAS,UAAU,KAAK;AAAA,IACtE;AAAA,EACD;AAAA,EAEgB,IAAI,KAAa,OAAyB;AACzD,UAAM,QAAQ,KAAK,kBAAkB,UAAU,CAAC,eAAe,WAAW,YAAY,MAAM,QAAQ;AAGpG,QAAI,UAAU,GAAI,MAAK,kBAAkB,KAAK,KAAK;AAAA,QAC9C,MAAK,kBAAkB,OAAO,OAAO,GAAG,KAAK;AAElD,WAAO,MAAM,IAAI,KAAK,KAAK;AAAA,EAC5B;AAAA,EAEgB,OAAO,KAAsB;AAC5C,UAAM,QAAQ,KAAK,kBAAkB,UAAU,CAAC,eAAe,WAAW,SAAS,GAAG;AAGtF,QAAI,UAAU,GAAI,MAAK,kBAAkB,OAAO,OAAO,CAAC;AAExD,WAAO,MAAM,OAAO,GAAG;AAAA,EACxB;AAAA,EAEgB,QAAc;AAC7B,SAAK,kBAAkB,SAAS;AAChC,WAAO,MAAM,MAAM;AAAA,EACpB;AACD;AAxCsE;AAA/D,IAAM,kBAAN","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Middleware } from './Middleware';\nimport type { Route } from './Route';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\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: ApiRequest, response: ApiResponse, route: Route | null): 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, route);\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,4 +1,4 @@
1
- import { __name, __publicField } from '../../chunk-PYETHG4R.mjs';
1
+ import { __name, __publicField } from '../../chunk-JTFKMR4I.mjs';
2
2
  import { Piece } from '@sapphire/pieces';
3
3
  import { Collection } from 'discord.js';
4
4
  import { RouteData } from '../utils/RouteData.mjs';
@@ -24,11 +24,12 @@ var _Route = class _Route extends Piece {
24
24
  */
25
25
  __publicField(this, "methods", new Collection());
26
26
  const api = this.container.server.options;
27
- this.router = new RouteData(`${api.prefix ?? ""}${options.route ?? this.name ?? ""}`);
27
+ const prefix = api.prefix ? api.prefix.endsWith("/") ? api.prefix : `${api.prefix}/` : "";
28
+ const path = options.route ?? (this.location.virtual ? this.name : this.location.directories.concat(this.name).join("/"));
29
+ this.router = new RouteData(`${prefix}${path}`);
28
30
  for (const [method, symbol] of methodEntries) {
29
31
  const value = Reflect.get(this, symbol);
30
- if (typeof value === "function")
31
- this.methods.set(method, value);
32
+ if (typeof value === "function") this.methods.set(method, value);
32
33
  }
33
34
  this.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;
34
35
  this.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AAEtB,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAC1B,SAAS,qBAAmC;AAOrC,IAAe,SAAf,MAAe,eAA6D,MAAyB;AAAA,EAqBpG,YAAY,SAA8B,UAAmB,CAAC,GAAc;AAClF,UAAM,SAAS,OAAO;AAlBvB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB,WAAU,IAAI,WAAoC;AAKjE,UAAM,MAAM,KAAK,UAAU,OAAO;AAClC,SAAK,SAAS,IAAI,UAAU,GAAG,IAAI,UAAU,EAAE,GAAG,QAAQ,SAAS,KAAK,QAAQ,EAAE,EAAE;AAEpF,eAAW,CAAC,QAAQ,MAAM,KAAK,eAAe;AAC7C,YAAM,QAAQ,QAAQ,IAAI,MAAM,MAAM;AACtC,UAAI,OAAO,UAAU;AAAY,aAAK,QAAQ,IAAI,QAAQ,KAAK;AAAA,IAChE;AAEA,SAAK,oBAAoB,QAAQ,qBAAqB,IAAI,qBAAqB,OAAO,OAAO;AAC7F,SAAK,2BAA2B,QAAQ,4BAA4B,IAAI,4BAA4B;AAAA,EACrG;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,SAA6B;AAC5C,UAAM,QAAQ,KAAK;AAEnB,eAAW,CAAC,QAAQ,EAAE,KAAK,KAAK,SAAS;AACxC,YAAM,MAAM,IAAI,MAAM,EAAG,IAAI,MAAM,GAAG,KAAK,IAAI,CAAC;AAAA,IACjD;AAEA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,WAA+B;AAC9C,UAAM,QAAQ,KAAK;AAEnB,eAAW,CAAC,MAAM,KAAK,KAAK,SAAS;AACpC,YAAM,MAAM,IAAI,MAAM,EAAG,OAAO,IAAI;AAAA,IACrC;AAEA,WAAO;AAAA,EACR;AACD;AA/D4G;AAArG,IAAe,QAAf","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport { Collection } from 'discord.js';\nimport { RouteData } from '../utils/RouteData';\nimport { methodEntries, type Methods } from './http/HttpMethods';\nimport type { MimeTypeWithoutParameters } from './http/Server';\nimport type { MethodCallback, RouteStore } from './RouteStore';\n\n/**\n * @since 1.0.0\n */\nexport abstract class Route<Options extends Route.Options = Route.Options> extends Piece<Options, 'routes'> {\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t */\n\tpublic readonly maximumBodyLength: number;\n\n\t/**\n\t * The accepted content types.\n\t */\n\tpublic readonly acceptedContentMimeTypes: readonly MimeTypeWithoutParameters[] | null;\n\n\t/**\n\t * The route information.\n\t */\n\tpublic readonly router: RouteData;\n\n\t/**\n\t * The methods this route accepts.\n\t */\n\tpublic readonly methods = new Collection<Methods, MethodCallback>();\n\n\tpublic constructor(context: Route.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\n\t\tconst api = this.container.server.options;\n\t\tthis.router = new RouteData(`${api.prefix ?? ''}${options.route ?? this.name ?? ''}`);\n\n\t\tfor (const [method, symbol] of methodEntries) {\n\t\t\tconst value = Reflect.get(this, symbol) as MethodCallback;\n\t\t\tif (typeof value === 'function') this.methods.set(method, value);\n\t\t}\n\n\t\tthis.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;\n\t\tthis.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is loaded into the store.\n\t * Useful to set-up asynchronous initialization tasks.\n\t */\n\tpublic override onLoad(): Awaitable<unknown> {\n\t\tconst store = this.store as unknown as RouteStore;\n\n\t\tfor (const [method, cb] of this.methods) {\n\t\t\tstore.table.get(method)!.set(this, cb.bind(this));\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is unloaded from the store.\n\t * Useful to set-up clean-up tasks.\n\t */\n\tpublic override onUnload(): Awaitable<unknown> {\n\t\tconst store = this.store as unknown as RouteStore;\n\n\t\tfor (const [method] of this.methods) {\n\t\t\tstore.table.get(method)!.delete(this);\n\t\t}\n\n\t\treturn undefined;\n\t}\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 * @default ''\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 * @default this.context.server.options.maximumBodyLength ?? 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The accepted content types for this route. If set to null, the route will accept any data.\n\t * @since 1.3.0\n\t * @default this.context.server.options.acceptedContentMimeTypes ?? null\n\t */\n\tacceptedContentMimeTypes?: MimeTypeWithoutParameters[] | null;\n}\n\nexport namespace Route {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'routes'>;\n\texport type Options = RouteOptions;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AAEtB,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAI1B,SAAS,qBAAmC;AAMrC,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,EAAG,OAAO,IAAI;AAAA,IACrC;AAEA,WAAO;AAAA,EACR;AACD;AArE4G;AAArG,IAAe,QAAf","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport { Collection } from 'discord.js';\nimport { RouteData } from '../utils/RouteData';\nimport type { MethodCallback, RouteStore } from './RouteStore';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\nimport { methodEntries, type Methods } from './http/HttpMethods';\nimport type { MimeTypeWithoutParameters } from './http/Server';\n\n/**\n * @since 1.0.0\n */\nexport abstract class Route<Options extends Route.Options = Route.Options> extends Piece<Options, 'routes'> {\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t */\n\tpublic readonly maximumBodyLength: number;\n\n\t/**\n\t * The accepted content types.\n\t */\n\tpublic readonly acceptedContentMimeTypes: readonly MimeTypeWithoutParameters[] | null;\n\n\t/**\n\t * The route information.\n\t */\n\tpublic readonly router: RouteData;\n\n\t/**\n\t * The methods this route accepts.\n\t */\n\tpublic readonly methods = new Collection<Methods, MethodCallback>();\n\n\tpublic constructor(context: Route.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\n\t\tconst api = this.container.server.options;\n\t\t// Concat a `/` to the prefix if it does not end with it\n\t\tconst prefix = api.prefix ? (api.prefix.endsWith('/') ? api.prefix : `${api.prefix}/`) : '';\n\t\t// Use the defined route, otherwise:\n\t\t// - If the location is virtual, use the name.\n\t\t// - Otherwise, use the directories and the name.\n\t\tconst path = options.route ?? (this.location.virtual ? this.name : this.location.directories.concat(this.name).join('/'));\n\t\tthis.router = new RouteData(`${prefix}${path}`);\n\n\t\tfor (const [method, symbol] of methodEntries) {\n\t\t\tconst value = Reflect.get(this, symbol) as MethodCallback;\n\t\t\tif (typeof value === 'function') this.methods.set(method, value);\n\t\t}\n\n\t\tthis.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;\n\t\tthis.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is loaded into the store.\n\t * Useful to set-up asynchronous initialization tasks.\n\t */\n\tpublic override onLoad(): Awaitable<unknown> {\n\t\tconst store = this.store as unknown as RouteStore;\n\n\t\tfor (const [method, cb] of this.methods) {\n\t\t\tstore.table.get(method)!.set(this, cb.bind(this));\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is unloaded from the store.\n\t * Useful to set-up clean-up tasks.\n\t */\n\tpublic override onUnload(): Awaitable<unknown> {\n\t\tconst store = this.store as unknown as RouteStore;\n\n\t\tfor (const [method] of this.methods) {\n\t\t\tstore.table.get(method)!.delete(this);\n\t\t}\n\n\t\treturn undefined;\n\t}\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 * @default ''\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 * @default this.context.server.options.maximumBodyLength ?? 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The accepted content types for this route. If set to null, the route will accept any data.\n\t * @since 1.3.0\n\t * @default this.context.server.options.acceptedContentMimeTypes ?? null\n\t */\n\tacceptedContentMimeTypes?: MimeTypeWithoutParameters[] | null;\n}\n\nexport namespace Route {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'routes'>;\n\texport type Options = RouteOptions;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n\n\texport type Request = ApiRequest;\n\texport type Response = ApiResponse;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { __name, __publicField } from '../../chunk-PYETHG4R.mjs';
1
+ import { __name, __publicField } from '../../chunk-JTFKMR4I.mjs';
2
2
  import { Store } from '@sapphire/pieces';
3
3
  import { Collection } from 'discord.js';
4
4
  import { URLSearchParams } from 'url';
@@ -10,8 +10,7 @@ var _RouteStore = class _RouteStore extends Store {
10
10
  constructor() {
11
11
  super(Route, { name: "routes" });
12
12
  __publicField(this, "table", new Collection());
13
- for (const [method] of methodEntries)
14
- this.table.set(method, new Collection());
13
+ for (const [method] of methodEntries) this.table.set(method, new Collection());
15
14
  }
16
15
  match(request) {
17
16
  const { method } = request;
@@ -25,8 +24,7 @@ var _RouteStore = class _RouteStore extends Store {
25
24
  const { splits, querystring } = this.parseURL(request.url);
26
25
  for (const [route, cb] of methodTable.entries()) {
27
26
  const result = route.router.match(splits);
28
- if (result === null)
29
- continue;
27
+ if (result === null) continue;
30
28
  request.params = result;
31
29
  request.query = Object.fromEntries(new URLSearchParams(querystring).entries());
32
30
  return { route, cb };
@@ -44,10 +42,8 @@ var _RouteStore = class _RouteStore extends Store {
44
42
  pathname = url.substring(0, index);
45
43
  querystring = url.substring(index + 1);
46
44
  }
47
- if (pathname.charCodeAt(0) === slash)
48
- pathname = pathname.substring(1);
49
- if (pathname.length > 0 && pathname.charCodeAt(pathname.length - 1) === slash)
50
- pathname = pathname.substring(0, pathname.length - 1);
45
+ if (pathname.charCodeAt(0) === slash) pathname = pathname.substring(1);
46
+ if (pathname.length > 0 && pathname.charCodeAt(pathname.length - 1) === slash) pathname = pathname.substring(0, pathname.length - 1);
51
47
  const splits = pathname.split("/");
52
48
  return { splits, querystring };
53
49
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAGhC,SAA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AAM;AAAO,iBAAW,SAAS,UAAU,GAAG,SAAS,SAAS,CAAC;AAEnI,UAAM,SAAS,SAAS,MAAM,GAAG;AAEjC,WAAO,EAAE,QAAQ,YAAY;AAAA,EAC9B;AACD;AA9DuD;AAAhD,IAAM,aAAN","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Collection } from 'discord.js';\nimport { URLSearchParams } from 'url';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\nimport { methodEntries, type Methods } from './http/HttpMethods';\nimport { Route } from './Route';\n\nconst slash = '/'.charCodeAt(0);\n\nexport interface MethodCallback {\n\t(request: ApiRequest, response: ApiResponse): unknown;\n}\n\nexport interface RouteMatch {\n\troute: Route;\n\tcb: MethodCallback;\n}\n\n/**\n * @since 1.0.0\n */\nexport class RouteStore extends Store<Route, 'routes'> {\n\tpublic readonly table = new Collection<Methods, Collection<Route, MethodCallback>>();\n\n\tpublic constructor() {\n\t\tsuper(Route, { name: 'routes' });\n\n\t\tfor (const [method] of methodEntries) this.table.set(method, new Collection());\n\t}\n\n\tpublic match(request: ApiRequest): RouteMatch | null {\n\t\tconst { method } = request;\n\n\t\t// If there is no method, we can't match a route so return null\n\t\tif (typeof method === 'undefined') {\n\t\t\treturn null;\n\t\t}\n\n\t\t// We get all the methods that are tied to the provided method to have a smaller list to filter through\n\t\tconst methodTable = this.table.get(method as Methods);\n\n\t\t// If there are no methods of the provided type then we won't find any route so we return null\n\t\tif (typeof methodTable === 'undefined') {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst { splits, querystring } = this.parseURL(request.url);\n\n\t\tfor (const [route, cb] of methodTable.entries()) {\n\t\t\tconst result = route.router.match(splits);\n\t\t\tif (result === null) continue;\n\n\t\t\trequest.params = result;\n\t\t\trequest.query = Object.fromEntries(new URLSearchParams(querystring).entries());\n\n\t\t\treturn { route, cb };\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate parseURL(url = '') {\n\t\tconst index = url.indexOf('?');\n\n\t\t/* eslint-disable @typescript-eslint/init-declarations */\n\t\tlet pathname: string;\n\t\tlet querystring: string;\n\t\t/* eslint-enable @typescript-eslint/init-declarations */\n\t\tif (index === -1) {\n\t\t\tpathname = url;\n\t\t\tquerystring = '';\n\t\t} else {\n\t\t\tpathname = url.substring(0, index);\n\t\t\tquerystring = url.substring(index + 1);\n\t\t}\n\n\t\tif (pathname.charCodeAt(0) === slash) pathname = pathname.substring(1);\n\t\tif (pathname.length > 0 && pathname.charCodeAt(pathname.length - 1) === slash) pathname = pathname.substring(0, pathname.length - 1);\n\n\t\tconst splits = pathname.split('/');\n\n\t\treturn { splits, querystring };\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAGhC,SAAS,qBAAmC;AAC5C,SAAS,aAAa;AAEtB,IAAM,QAAQ,IAAI,WAAW,CAAC;AAcvB,IAAM,cAAN,MAAM,oBAAmB,MAAuB;AAAA,EAG/C,cAAc;AACpB,UAAM,OAAO,EAAE,MAAM,SAAS,CAAC;AAHhC,wBAAgB,SAAQ,IAAI,WAAuD;AAKlF,eAAW,CAAC,MAAM,KAAK,cAAe,MAAK,MAAM,IAAI,QAAQ,IAAI,WAAW,CAAC;AAAA,EAC9E;AAAA,EAEO,MAAM,SAAwC;AACpD,UAAM,EAAE,OAAO,IAAI;AAGnB,QAAI,OAAO,WAAW,aAAa;AAClC,aAAO;AAAA,IACR;AAGA,UAAM,cAAc,KAAK,MAAM,IAAI,MAAiB;AAGpD,QAAI,OAAO,gBAAgB,aAAa;AACvC,aAAO;AAAA,IACR;AAEA,UAAM,EAAE,QAAQ,YAAY,IAAI,KAAK,SAAS,QAAQ,GAAG;AAEzD,eAAW,CAAC,OAAO,EAAE,KAAK,YAAY,QAAQ,GAAG;AAChD,YAAM,SAAS,MAAM,OAAO,MAAM,MAAM;AACxC,UAAI,WAAW,KAAM;AAErB,cAAQ,SAAS;AACjB,cAAQ,QAAQ,OAAO,YAAY,IAAI,gBAAgB,WAAW,EAAE,QAAQ,CAAC;AAE7E,aAAO,EAAE,OAAO,GAAG;AAAA,IACpB;AAEA,WAAO;AAAA,EACR;AAAA,EAEQ,SAAS,MAAM,IAAI;AAC1B,UAAM,QAAQ,IAAI,QAAQ,GAAG;AAG7B,QAAI;AACJ,QAAI;AAEJ,QAAI,UAAU,IAAI;AACjB,iBAAW;AACX,oBAAc;AAAA,IACf,OAAO;AACN,iBAAW,IAAI,UAAU,GAAG,KAAK;AACjC,oBAAc,IAAI,UAAU,QAAQ,CAAC;AAAA,IACtC;AAEA,QAAI,SAAS,WAAW,CAAC,MAAM,MAAO,YAAW,SAAS,UAAU,CAAC;AACrE,QAAI,SAAS,SAAS,KAAK,SAAS,WAAW,SAAS,SAAS,CAAC,MAAM,MAAO,YAAW,SAAS,UAAU,GAAG,SAAS,SAAS,CAAC;AAEnI,UAAM,SAAS,SAAS,MAAM,GAAG;AAEjC,WAAO,EAAE,QAAQ,YAAY;AAAA,EAC9B;AACD;AA9DuD;AAAhD,IAAM,aAAN","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Collection } from 'discord.js';\nimport { URLSearchParams } from 'url';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\nimport { methodEntries, type Methods } from './http/HttpMethods';\nimport { Route } from './Route';\n\nconst slash = '/'.charCodeAt(0);\n\nexport interface MethodCallback {\n\t(request: ApiRequest, response: ApiResponse): unknown;\n}\n\nexport interface RouteMatch {\n\troute: Route;\n\tcb: MethodCallback;\n}\n\n/**\n * @since 1.0.0\n */\nexport class RouteStore extends Store<Route, 'routes'> {\n\tpublic readonly table = new Collection<Methods, Collection<Route, MethodCallback>>();\n\n\tpublic constructor() {\n\t\tsuper(Route, { name: 'routes' });\n\n\t\tfor (const [method] of methodEntries) this.table.set(method, new Collection());\n\t}\n\n\tpublic match(request: ApiRequest): RouteMatch | null {\n\t\tconst { method } = request;\n\n\t\t// If there is no method, we can't match a route so return null\n\t\tif (typeof method === 'undefined') {\n\t\t\treturn null;\n\t\t}\n\n\t\t// We get all the methods that are tied to the provided method to have a smaller list to filter through\n\t\tconst methodTable = this.table.get(method as Methods);\n\n\t\t// If there are no methods of the provided type then we won't find any route so we return null\n\t\tif (typeof methodTable === 'undefined') {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst { splits, querystring } = this.parseURL(request.url);\n\n\t\tfor (const [route, cb] of methodTable.entries()) {\n\t\t\tconst result = route.router.match(splits);\n\t\t\tif (result === null) continue;\n\n\t\t\trequest.params = result;\n\t\t\trequest.query = Object.fromEntries(new URLSearchParams(querystring).entries());\n\n\t\t\treturn { route, cb };\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate parseURL(url = '') {\n\t\tconst index = url.indexOf('?');\n\n\t\t/* eslint-disable @typescript-eslint/init-declarations */\n\t\tlet pathname: string;\n\t\tlet querystring: string;\n\t\t/* eslint-enable @typescript-eslint/init-declarations */\n\t\tif (index === -1) {\n\t\t\tpathname = url;\n\t\t\tquerystring = '';\n\t\t} else {\n\t\t\tpathname = url.substring(0, index);\n\t\t\tquerystring = url.substring(index + 1);\n\t\t}\n\n\t\tif (pathname.charCodeAt(0) === slash) pathname = pathname.substring(1);\n\t\tif (pathname.length > 0 && pathname.charCodeAt(pathname.length - 1) === slash) pathname = pathname.substring(0, pathname.length - 1);\n\n\t\tconst splits = pathname.split('/');\n\n\t\treturn { splits, querystring };\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { __name, __publicField } from '../../../chunk-PYETHG4R.mjs';
1
+ import { __name, __publicField } from '../../../chunk-JTFKMR4I.mjs';
2
2
  import { IncomingMessage } from 'node:http';
3
3
 
4
4
  var _ApiRequest = class _ApiRequest extends IncomingMessage {
@@ -1,4 +1,4 @@
1
- import { __name, __publicField } from '../../../chunk-PYETHG4R.mjs';
1
+ import { __name, __publicField } from '../../../chunk-JTFKMR4I.mjs';
2
2
  import { ServerResponse, STATUS_CODES } from 'node:http';
3
3
  import { Readable } from 'node:stream';
4
4
  import 'node:stream/web';
@@ -1,4 +1,4 @@
1
- import { __name, __publicField } from '../../../chunk-PYETHG4R.mjs';
1
+ import { __name, __publicField } from '../../../chunk-JTFKMR4I.mjs';
2
2
  import { getDomain } from 'tldts';
3
3
 
4
4
  var _CookieStore = class _CookieStore extends Map {
@@ -14,8 +14,7 @@ var _CookieStore = class _CookieStore extends Map {
14
14
  const pairs = cookie.split(";");
15
15
  for (const pair of pairs) {
16
16
  const index = pair.indexOf("=");
17
- if (index === -1)
18
- continue;
17
+ if (index === -1) continue;
19
18
  const key = decodeURIComponent(pair.substr(0, index).trim());
20
19
  const value = decodeURIComponent(pair.substr(index + 1).trim());
21
20
  this.set(key, value);
@@ -77,8 +76,7 @@ var _CookieStore = class _CookieStore extends Map {
77
76
  getHostDomain(host) {
78
77
  const lowercaseHost = host.toLowerCase();
79
78
  const tldParsedInfo = getDomain(lowercaseHost);
80
- if (!tldParsedInfo)
81
- return lowercaseHost;
79
+ if (!tldParsedInfo) return lowercaseHost;
82
80
  return `.${tldParsedInfo}`;
83
81
  }
84
82
  static encodeCookieOctet(value) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/lib/structures/api/CookieStore.ts"],"names":[],"mappings":";;;;;;AAGA,SAAS,iBAAiB;AAInB,IAAM,eAAN,MAAM,qBAAoB,IAAoB;AAAA,EAM7C,YAAY,SAAqB,UAAuB,QAAiB,iBAAiC;AAChH,UAAM;AANP,wBAAU;AACV,wBAAU;AACV,wBAAQ;AACR,wBAAQ;AAKP,SAAK,UAAU;AACf,SAAK,WAAW;AAGhB,UAAM,EAAE,SAAS,GAAG,IAAI,QAAQ;AAChC,UAAM,QAAQ,OAAO,MAAM,GAAG;AAE9B,eAAW,QAAQ,OAAO;AACzB,YAAM,QAAQ,KAAK,QAAQ,GAAG;AAC9B,UAAI,UAAU;AAAI;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aAAY,kBAAkB,IAAI;AACzC,YAAQ,aAAY,kBAAkB,KAAK;AAE3C,QAAI,QAAQ,GAAG,IAAI,IAAI,KAAK;AAE5B,QAAI,YAAY,KAAK;AACpB,eAAS,aAAa,QAAQ,YAAY,CAAC;AAAA,IAC5C,WAAW,QAAQ;AAClB,eAAS,aAAa,MAAM;AAAA,IAC7B;AAGA,cAAU,UAAU,KAAK,QAAQ,YAAY;AAE7C,aAAS,YAAY,MAAM;AAC3B,aAAS,UAAU,QAAQ,GAAG;AAE9B,QAAI,KAAK,QAAQ;AAChB,eAAS;AAAA,IACV;AAEA,QAAI,YAAY,MAAM;AACrB,eAAS;AAAA,IACV;AAEA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,cAAc,MAAsB;AAE3C,UAAM,gBAAgB,KAAK,YAAY;AAGvC,UAAM,gBAAgB,UAAU,aAAa;AAG7C,QAAI,CAAC;AAAe,aAAO;AAG3B,WAAO,IAAI,aAAa;AAAA,EACzB;AAAA,EAKA,OAAe,kBAAkB,OAAe;AAC/C,QAAI,aAAY,YAAY,KAAK,KAAK,GAAG;AACxC,YAAM,IAAI,MAAM,4BAA4B;AAAA,IAC7C;AAEA,WAAO,mBAAmB,KAAK;AAAA,EAChC;AACD;AA9HqD;AAAA;AAqHpD,cArHY,cAqHY,eAAc;AArHhC,IAAM,cAAN","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.substr(0, index).trim());\n\t\t\tconst value = decodeURIComponent(pair.substr(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.substr(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
+ {"version":3,"sources":["../../../../../src/lib/structures/api/CookieStore.ts"],"names":[],"mappings":";;;;;;AAGA,SAAS,iBAAiB;AAInB,IAAM,eAAN,MAAM,qBAAoB,IAAoB;AAAA,EAM7C,YAAY,SAAqB,UAAuB,QAAi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Domain } 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.substr(0, index).trim());\n\t\t\tconst value = decodeURIComponent(pair.substr(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.substr(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,4 +1,4 @@
1
- import { __name, __publicField, __privateAdd, __privateSet, __privateGet } from '../../../chunk-PYETHG4R.mjs';
1
+ import { __name, __publicField, __privateAdd, __privateSet, __privateGet } from '../../../chunk-JTFKMR4I.mjs';
2
2
  import { isThenable } from '@sapphire/utilities';
3
3
  import { randomBytes, createCipheriv, createDecipheriv } from 'crypto';
4
4
  import { OAuth2Scopes, RouteBases, Routes } from 'discord.js';
@@ -33,7 +33,7 @@ var _Auth = class _Auth {
33
33
  */
34
34
  __publicField(this, "transformers");
35
35
  __publicField(this, "domainOverwrite", null);
36
- __privateAdd(this, _secret, void 0);
36
+ __privateAdd(this, _secret);
37
37
  this.id = options.id;
38
38
  this.cookie = options.cookie ?? "SAPPHIRE_AUTH";
39
39
  this.scopes = options.scopes ?? [OAuth2Scopes.Identify];
@@ -92,16 +92,13 @@ var _Auth = class _Auth {
92
92
  let data = { user, guilds, connections };
93
93
  for (const transformer of this.transformers) {
94
94
  const result = transformer(data);
95
- if (isThenable(result))
96
- data = await result;
97
- else
98
- data = result;
95
+ if (isThenable(result)) data = await result;
96
+ else data = result;
99
97
  }
100
98
  return data;
101
99
  }
102
100
  async fetchInformation(scope, token, url) {
103
- if (!this.scopes.includes(scope))
104
- return void 0;
101
+ if (!this.scopes.includes(scope)) return void 0;
105
102
  const result = await fetch(url, {
106
103
  headers: {
107
104
  authorization: `Bearer ${token}`
@@ -110,8 +107,7 @@ var _Auth = class _Auth {
110
107
  return result.ok ? await result.json() : null;
111
108
  }
112
109
  static create(options) {
113
- if (!options?.secret || !options.id)
114
- return null;
110
+ if (!options?.secret || !options.id) return null;
115
111
  return new _Auth(options);
116
112
  }
117
113
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/lib/structures/http/Auth.ts"],"names":[],"mappings":";;;;;;;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;AA7FC;AAjCiB;AAAX,IAAM,OAAN","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 as Snowflake;\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: string;\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":[],"mappings":";;;;;;;;;AAAA,SAAS,kBAAkC;AAC3C,SAAS,gBAAgB,kBAAkB,mBAAmB;AAC9D;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAKM;AACP,SAAS,aAAa;AAXtB;AAaO,IAAM,QAAN,MAAM,MAAK;AAAA,EAmCT,YAAY,SAA4B;AA9BhD;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAA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,CAAC,EAAE;AAAA,MACpH,KAAK,iBAAoD,aAAa,QAAQ,OAAO,GAAG,WAAW,GAAG,GAAG,OAAO,WAAW,CAAC,EAAE;AAAA,MAC9H,KAAK;AAAA,QACJ,aAAa;AAAA,QACb;AAAA,QACA,GAAG,WAAW,GAAG,GAAG,OAAO,gBAAgB,CAAC;AAAA,MAC7C;AAAA,IACD,CAAC;AAGD,QAAI,OAAkB,EAAE,MAAM,QAAQ,YAAY;AAClD,eAAW,eAAe,KAAK,cAAc;AAC5C,YAAM,SAAS,YAAY,IAAI;AAC/B,UAAI,WAAW,MAAM,EAAG,QAAO,MAAM;AAAA,UAChC,QAAO;AAAA,IACb;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,MAAc,iBAAoB,OAAqB,OAAe,KAA4C;AACjH,QAAI,CAAC,KAAK,OAAO,SAAS,KAAK,EAAG,QAAO;AAEzC,UAAM,SAAS,MAAM,MAAM,KAAK;AAAA,MAC/B,SAAS;AAAA,QACR,eAAe,UAAU,KAAK;AAAA,MAC/B;AAAA,IACD,CAAC;AAED,WAAO,OAAO,KAAO,MAAM,OAAO,KAAK,IAAW;AAAA,EACnD;AAAA,EAEA,OAAc,OAAO,SAA0C;AAC9D,QAAI,CAAC,SAAS,UAAU,CAAC,QAAQ,GAAI,QAAO;AAC5C,WAAO,IAAI,MAAK,OAAO;AAAA,EACxB;AACD;AA7FC;AAjCiB;AAAX,IAAM,OAAN","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 as Snowflake;\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: string;\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,4 +1,4 @@
1
- import '../../../chunk-PYETHG4R.mjs';
1
+ import '../../../chunk-JTFKMR4I.mjs';
2
2
 
3
3
  // src/lib/structures/http/HttpCodes.ts
4
4
  var HttpCodes = /* @__PURE__ */ ((HttpCodes2) => {
@@ -1,4 +1,4 @@
1
- import '../../../chunk-PYETHG4R.mjs';
1
+ import '../../../chunk-JTFKMR4I.mjs';
2
2
  import { METHODS } from 'node:http';
3
3
 
4
4
  var methods = Object.fromEntries(METHODS.map((method) => [method, Symbol(`HTTP-${method}`)]));
@@ -1,4 +1,4 @@
1
- import { __name, __publicField } from '../../../chunk-PYETHG4R.mjs';
1
+ import { __name, __publicField } from '../../../chunk-JTFKMR4I.mjs';
2
2
  import { container } from '@sapphire/pieces';
3
3
  import { EventEmitter } from 'node:events';
4
4
  import { createServer } from 'node:http';
@@ -1,4 +1,4 @@
1
- import '../../chunk-PYETHG4R.mjs';
1
+ import '../../chunk-JTFKMR4I.mjs';
2
2
 
3
3
  // src/lib/utils/MimeTypes.ts
4
4
  var MimeTypes = /* @__PURE__ */ ((MimeTypes2) => {
@@ -1,7 +1,6 @@
1
- import { __name, __publicField } from '../../chunk-PYETHG4R.mjs';
1
+ import { __name, __publicField } from '../../chunk-JTFKMR4I.mjs';
2
2
 
3
3
  // src/lib/utils/RouteData.ts
4
- var [slash, colon] = [47, 58];
5
4
  var TypeState = /* @__PURE__ */ ((TypeState2) => {
6
5
  TypeState2[TypeState2["Static"] = 0] = "Static";
7
6
  TypeState2[TypeState2["Dynamic"] = 1] = "Dynamic";
@@ -13,21 +12,18 @@ var _RouteData = class _RouteData {
13
12
  __publicField(this, "static");
14
13
  __publicField(this, "parts");
15
14
  this.path = path;
16
- this.parts = _RouteData.split(path).map(_RouteData.parsePart.bind(null));
15
+ this.parts = _RouteData.split(path).map((value) => _RouteData.parsePart(value));
17
16
  this.static = this.parts.every((part) => part.type === 0 /* Static */);
18
17
  }
19
18
  match(split) {
20
- if (split.length !== this.parts.length)
21
- return null;
22
- if (this.static)
23
- return this.parts.every((part, index) => part.value === split[index]) ? {} : null;
19
+ if (split.length !== this.parts.length) return null;
20
+ if (this.static) return this.parts.every((part, index) => part.value === split[index]) ? {} : null;
24
21
  const parameters = [];
25
22
  for (let i = 0; i < this.parts.length; ++i) {
26
23
  const part = this.parts[i];
27
24
  const value = split[i];
28
25
  if (part.type === 0 /* Static */) {
29
- if (part.value === value)
30
- continue;
26
+ if (part.value === value) continue;
31
27
  return null;
32
28
  }
33
29
  parameters.push([part.value, value]);
@@ -38,21 +34,17 @@ var _RouteData = class _RouteData {
38
34
  * @since 1.0.0
39
35
  */
40
36
  static parsePart(value) {
41
- const type = value.charCodeAt(0) === colon ? 1 /* Dynamic */ : 0 /* Static */;
42
- if (type === 1 /* Dynamic */)
43
- value = value.substring(1);
37
+ const type = value.length > 2 && value.at(0) === "[" && value.at(-1) === "]" ? 1 /* Dynamic */ : 0 /* Static */;
38
+ if (type === 1 /* Dynamic */) value = value.slice(1, -1);
44
39
  return { value, type };
45
40
  }
46
41
  /**
47
42
  * @since 1.0.0
48
43
  */
49
44
  static split(url) {
50
- if (url.length === 1 && url.charCodeAt(0) === slash)
51
- return [""];
52
- if (url.charCodeAt(0) === slash)
53
- url = url.substring(1);
54
- if (url.length > 0 && url.charCodeAt(url.length - 1) === slash)
55
- url = url.substring(0, url.length - 1);
45
+ if (url.length === 1 && url.at(0) === "/") return [""];
46
+ if (url.at(0) === "/") url = url.slice(1);
47
+ if (url.length > 0 && url.at(-1) === "/") url = url.slice(0, -1);
56
48
  return url.split("/");
57
49
  }
58
50
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/utils/RouteData.ts"],"names":["TypeState"],"mappings":";;;;;;AAAA,IAAM,CAAC,OAAO,KAAK,IAAsB,CAAC,IAAI,EAAE;AAKzC,IAAK,YAAL,kBAAKA,eAAL;AAIN,EAAAA,sBAAA;AAKA,EAAAA,sBAAA;AATW,SAAAA;AAAA,GAAA;AAcL,IAAM,aAAN,MAAM,WAAU;AAAA,EAKf,YAAY,MAAc;AAJjC,wBAAgB;AAChB,wBAAiB;AACjB,wBAAiB;AAGhB,SAAK,OAAO;AACZ,SAAK,QAAQ,WAAU,MAAM,IAAI,EAAE,IAAI,WAAU,UAAU,KAAK,IAAI,CAAC;AACrE,SAAK,SAAS,KAAK,MAAM,MAAM,CAAC,SAAS,KAAK,SAAS,cAAgB;AAAA,EACxE;AAAA,EAEO,MAAM,OAAqC;AACjD,QAAI,MAAM,WAAW,KAAK,MAAM;AAAQ,aAAO;AAC/C,QAAI,KAAK;AAAQ,aAAO,KAAK,MAAM,MAAM,CAAC,MAAM,UAAU,KAAK,UAAU,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI;AAE9F,UAAM,aAAiC,CAAC;AACxC,aAAS,IAAI,GAAG,IAAI,KAAK,MAAM,QAAQ,EAAE,GAAG;AAC3C,YAAM,OAAO,KAAK,MAAM,CAAC;AACzB,YAAM,QAAQ,MAAM,CAAC;AAErB,UAAI,KAAK,SAAS,gBAAkB;AACnC,YAAI,KAAK,UAAU;AAAO;AAC1B,eAAO;AAAA,MACR;AAEA,iBAAW,KAAK,CAAC,KAAK,OAAO,KAAK,CAAC;AAAA,IACpC;AAEA,WAAO,OAAO,YAAY,UAAU;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA,EAKA,OAAe,UAAU,OAA2B;AACnD,UAAM,OAAO,MAAM,WAAW,CAAC,MAAM,QAAQ,kBAAoB;AACjE,QAAI,SAAS;AAAmB,cAAQ,MAAM,UAAU,CAAC;AACzD,WAAO,EAAE,OAAO,KAAK;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,OAAe,MAAM,KAAuB;AAC3C,QAAI,IAAI,WAAW,KAAK,IAAI,WAAW,CAAC,MAAM;AAAO,aAAO,CAAC,EAAE;AAC/D,QAAI,IAAI,WAAW,CAAC,MAAM;AAAO,YAAM,IAAI,UAAU,CAAC;AACtD,QAAI,IAAI,SAAS,KAAK,IAAI,WAAW,IAAI,SAAS,CAAC,MAAM;AAAO,YAAM,IAAI,UAAU,GAAG,IAAI,SAAS,CAAC;AACrG,WAAO,IAAI,MAAM,GAAG;AAAA,EACrB;AACD;AAjDuB;AAAhB,IAAM,YAAN","sourcesContent":["const [slash, colon]: [number, number] = [47, 58];\n\n/**\n * @since 1.0.0\n */\nexport enum TypeState {\n\t/**\n\t * @since 1.0.0\n\t */\n\tStatic,\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tDynamic\n}\n\nexport type MatchData = Record<string, string> | null;\n\nexport class RouteData {\n\tpublic readonly path: string;\n\tprivate readonly static: boolean;\n\tprivate readonly parts: readonly ParsedPart[];\n\n\tpublic constructor(path: string) {\n\t\tthis.path = path;\n\t\tthis.parts = RouteData.split(path).map(RouteData.parsePart.bind(null));\n\t\tthis.static = this.parts.every((part) => part.type === TypeState.Static);\n\t}\n\n\tpublic match(split: readonly string[]): MatchData {\n\t\tif (split.length !== this.parts.length) return null;\n\t\tif (this.static) return this.parts.every((part, index) => part.value === split[index]) ? {} : null;\n\n\t\tconst parameters: [string, string][] = [];\n\t\tfor (let i = 0; i < this.parts.length; ++i) {\n\t\t\tconst part = this.parts[i];\n\t\t\tconst value = split[i];\n\n\t\t\tif (part.type === TypeState.Static) {\n\t\t\t\tif (part.value === value) continue;\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tparameters.push([part.value, value]);\n\t\t}\n\n\t\treturn Object.fromEntries(parameters);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tprivate static parsePart(value: string): ParsedPart {\n\t\tconst type = value.charCodeAt(0) === colon ? TypeState.Dynamic : TypeState.Static;\n\t\tif (type === TypeState.Dynamic) value = value.substring(1);\n\t\treturn { value, type };\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tprivate static split(url: string): string[] {\n\t\tif (url.length === 1 && url.charCodeAt(0) === slash) return [''];\n\t\tif (url.charCodeAt(0) === slash) url = url.substring(1);\n\t\tif (url.length > 0 && url.charCodeAt(url.length - 1) === slash) url = url.substring(0, url.length - 1);\n\t\treturn url.split('/');\n\t}\n}\n\nexport interface ParsedPart {\n\tvalue: string;\n\ttype: TypeState;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/utils/RouteData.ts"],"names":["TypeState"],"mappings":";;;;;;AAGO,IAAK,YAAL,kBAAKA,eAAL;AAIN,EAAAA,sBAAA;AAKA,EAAAA,sBAAA;AATW,SAAAA;AAAA,GAAA;AAcL,IAAM,aAAN,MAAM,WAAU;AAAA,EAKf,YAAY,MAAc;AAJjC,wBAAgB;AAChB,wBAAiB;AACjB,wBAAiB;AAGhB,SAAK,OAAO;AACZ,SAAK,QAAQ,WAAU,MAAM,IAAI,EAAE,IAAI,CAAC,UAAU,WAAU,UAAU,KAAK,CAAC;AAC5E,SAAK,SAAS,KAAK,MAAM,MAAM,CAAC,SAAS,KAAK,SAAS,cAAgB;AAAA,EACxE;AAAA,EAEO,MAAM,OAAqC;AACjD,QAAI,MAAM,WAAW,KAAK,MAAM,OAAQ,QAAO;AAC/C,QAAI,KAAK,OAAQ,QAAO,KAAK,MAAM,MAAM,CAAC,MAAM,UAAU,KAAK,UAAU,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI;AAE9F,UAAM,aAAiC,CAAC;AACxC,aAAS,IAAI,GAAG,IAAI,KAAK,MAAM,QAAQ,EAAE,GAAG;AAC3C,YAAM,OAAO,KAAK,MAAM,CAAC;AACzB,YAAM,QAAQ,MAAM,CAAC;AAErB,UAAI,KAAK,SAAS,gBAAkB;AACnC,YAAI,KAAK,UAAU,MAAO;AAC1B,eAAO;AAAA,MACR;AAEA,iBAAW,KAAK,CAAC,KAAK,OAAO,KAAK,CAAC;AAAA,IACpC;AAEA,WAAO,OAAO,YAAY,UAAU;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA,EAKA,OAAe,UAAU,OAA2B;AACnD,UAAM,OAAO,MAAM,SAAS,KAAK,MAAM,GAAG,CAAC,MAAM,OAAO,MAAM,GAAG,EAAE,MAAM,MAAM,kBAAoB;AACnG,QAAI,SAAS,gBAAmB,SAAQ,MAAM,MAAM,GAAG,EAAE;AACzD,WAAO,EAAE,OAAO,KAAK;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKA,OAAe,MAAM,KAAuB;AAC3C,QAAI,IAAI,WAAW,KAAK,IAAI,GAAG,CAAC,MAAM,IAAK,QAAO,CAAC,EAAE;AACrD,QAAI,IAAI,GAAG,CAAC,MAAM,IAAK,OAAM,IAAI,MAAM,CAAC;AACxC,QAAI,IAAI,SAAS,KAAK,IAAI,GAAG,EAAE,MAAM,IAAK,OAAM,IAAI,MAAM,GAAG,EAAE;AAC/D,WAAO,IAAI,MAAM,GAAG;AAAA,EACrB;AACD;AAjDuB;AAAhB,IAAM,YAAN","sourcesContent":["/**\n * @since 1.0.0\n */\nexport enum TypeState {\n\t/**\n\t * @since 1.0.0\n\t */\n\tStatic,\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tDynamic\n}\n\nexport type MatchData = Record<string, string> | null;\n\nexport class RouteData {\n\tpublic readonly path: string;\n\tprivate readonly static: boolean;\n\tprivate readonly parts: readonly ParsedPart[];\n\n\tpublic constructor(path: string) {\n\t\tthis.path = path;\n\t\tthis.parts = RouteData.split(path).map((value) => RouteData.parsePart(value));\n\t\tthis.static = this.parts.every((part) => part.type === TypeState.Static);\n\t}\n\n\tpublic match(split: readonly string[]): MatchData {\n\t\tif (split.length !== this.parts.length) return null;\n\t\tif (this.static) return this.parts.every((part, index) => part.value === split[index]) ? {} : null;\n\n\t\tconst parameters: [string, string][] = [];\n\t\tfor (let i = 0; i < this.parts.length; ++i) {\n\t\t\tconst part = this.parts[i];\n\t\t\tconst value = split[i];\n\n\t\t\tif (part.type === TypeState.Static) {\n\t\t\t\tif (part.value === value) continue;\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tparameters.push([part.value, value]);\n\t\t}\n\n\t\treturn Object.fromEntries(parameters);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tprivate static parsePart(value: string): ParsedPart {\n\t\tconst type = value.length > 2 && value.at(0) === '[' && value.at(-1) === ']' ? TypeState.Dynamic : TypeState.Static;\n\t\tif (type === TypeState.Dynamic) value = value.slice(1, -1);\n\t\treturn { value, type };\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tprivate static split(url: string): string[] {\n\t\tif (url.length === 1 && url.at(0) === '/') return [''];\n\t\tif (url.at(0) === '/') url = url.slice(1);\n\t\tif (url.length > 0 && url.at(-1) === '/') url = url.slice(0, -1);\n\t\treturn url.split('/');\n\t}\n}\n\nexport interface ParsedPart {\n\tvalue: string;\n\ttype: TypeState;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { __name } from '../chunk-PYETHG4R.mjs';
1
+ import { __name } from '../chunk-JTFKMR4I.mjs';
2
2
  import { Listener } from '@sapphire/framework';
3
3
  import { HttpCodes } from '../lib/structures/http/HttpCodes.mjs';
4
4
  import { ServerEvents } from '../lib/structures/http/Server.mjs';
@@ -9,8 +9,7 @@ var _PluginListener = class _PluginListener extends Listener {
9
9
  }
10
10
  run(error, { response }) {
11
11
  this.container.logger.fatal(error);
12
- if (!response.writableEnded)
13
- response.status(HttpCodes.InternalServerError).json({ error: error.message ?? error });
12
+ if (!response.writableEnded) response.status(HttpCodes.InternalServerError).json({ error: error.message ?? error });
14
13
  }
15
14
  };
16
15
  __name(_PluginListener, "PluginListener");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/listeners/PluginRouteError.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,oBAAiD;AAEnD,IAAM,kBAAN,MAAM,wBAAuB,SAAS;AAAA,EACrC,YAAY,SAAiC;AACnD,UAAM,SAAS,EAAE,SAAS,UAAU,OAAO,aAAa,WAAW,CAAC;AAAA,EACrE;AAAA,EAEgB,IAAI,OAAc,EAAE,SAAS,GAA2B;AAEvE,SAAK,UAAU,OAAO,MAAM,KAAK;AAGjC,QAAI,CAAC,SAAS;AAAe,eAAS,OAAO,UAAU,mBAAmB,EAAE,KAAK,EAAE,OAAO,MAAM,WAAW,MAAM,CAAC;AAAA,EACnH;AACD;AAZ6C;AAAtC,IAAM,iBAAN","sourcesContent":["import { Listener } from '@sapphire/framework';\nimport { HttpCodes } from '../lib/structures/http/HttpCodes';\nimport { ServerEvents, type MiddlewareErrorContext } from '../lib/structures/http/Server';\n\nexport class PluginListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext) {\n\t\tsuper(context, { emitter: 'server', event: ServerEvents.RouteError });\n\t}\n\n\tpublic override run(error: Error, { response }: MiddlewareErrorContext) {\n\t\t// Log the error to console:\n\t\tthis.container.logger.fatal(error);\n\n\t\t// Send a response to the client if none was sent:\n\t\tif (!response.writableEnded) response.status(HttpCodes.InternalServerError).json({ error: error.message ?? error });\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/listeners/PluginRouteError.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,oBAAiD;AAEnD,IAAM,kBAAN,MAAM,wBAAuB,SAAS;AAAA,EACrC,YAAY,SAAiC;AACnD,UAAM,SAAS,EAAE,SAAS,UAAU,OAAO,aAAa,WAAW,CAAC;AAAA,EACrE;AAAA,EAEgB,IAAI,OAAc,EAAE,SAAS,GAA2B;AAEvE,SAAK,UAAU,OAAO,MAAM,KAAK;AAGjC,QAAI,CAAC,SAAS,cAAe,UAAS,OAAO,UAAU,mBAAmB,EAAE,KAAK,EAAE,OAAO,MAAM,WAAW,MAAM,CAAC;AAAA,EACnH;AACD;AAZ6C;AAAtC,IAAM,iBAAN","sourcesContent":["import { Listener } from '@sapphire/framework';\nimport { HttpCodes } from '../lib/structures/http/HttpCodes';\nimport { ServerEvents, type MiddlewareErrorContext } from '../lib/structures/http/Server';\n\nexport class PluginListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext) {\n\t\tsuper(context, { emitter: 'server', event: ServerEvents.RouteError });\n\t}\n\n\tpublic override run(error: Error, { response }: MiddlewareErrorContext) {\n\t\t// Log the error to console:\n\t\tthis.container.logger.fatal(error);\n\n\t\t// Send a response to the client if none was sent:\n\t\tif (!response.writableEnded) response.status(HttpCodes.InternalServerError).json({ error: error.message ?? error });\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { __name } from '../chunk-PYETHG4R.mjs';
1
+ import { __name } from '../chunk-JTFKMR4I.mjs';
2
2
  import { Listener } from '@sapphire/framework';
3
3
  import { ServerEvents } from '../lib/structures/http/Server.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __name } from '../chunk-PYETHG4R.mjs';
1
+ import { __name } from '../chunk-JTFKMR4I.mjs';
2
2
  import { Listener } from '@sapphire/framework';
3
3
  import { HttpCodes } from '../lib/structures/http/HttpCodes.mjs';
4
4
  import { ServerEvents } from '../lib/structures/http/Server.mjs';
@@ -9,8 +9,7 @@ var _PluginListener = class _PluginListener extends Listener {
9
9
  }
10
10
  run(error, { response }) {
11
11
  this.container.logger.fatal(error);
12
- if (!response.writableEnded)
13
- response.status(HttpCodes.InternalServerError).json({ error: error.message ?? error });
12
+ if (!response.writableEnded) response.status(HttpCodes.InternalServerError).json({ error: error.message ?? error });
14
13
  }
15
14
  };
16
15
  __name(_PluginListener, "PluginListener");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/listeners/PluginServerMiddlewareError.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,oBAAiD;AAEnD,IAAM,kBAAN,MAAM,wBAAuB,SAAS;AAAA,EACrC,YAAY,SAAiC;AACnD,UAAM,SAAS,EAAE,SAAS,UAAU,OAAO,aAAa,gBAAgB,CAAC;AAAA,EAC1E;AAAA,EAEgB,IAAI,OAAc,EAAE,SAAS,GAA2B;AAEvE,SAAK,UAAU,OAAO,MAAM,KAAK;AAGjC,QAAI,CAAC,SAAS;AAAe,eAAS,OAAO,UAAU,mBAAmB,EAAE,KAAK,EAAE,OAAO,MAAM,WAAW,MAAM,CAAC;AAAA,EACnH;AACD;AAZ6C;AAAtC,IAAM,iBAAN","sourcesContent":["import { Listener } from '@sapphire/framework';\nimport { HttpCodes } from '../lib/structures/http/HttpCodes';\nimport { ServerEvents, type MiddlewareErrorContext } from '../lib/structures/http/Server';\n\nexport class PluginListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext) {\n\t\tsuper(context, { emitter: 'server', event: ServerEvents.MiddlewareError });\n\t}\n\n\tpublic override run(error: Error, { response }: MiddlewareErrorContext) {\n\t\t// Log the error to console:\n\t\tthis.container.logger.fatal(error);\n\n\t\t// Send a response to the client if none was sent:\n\t\tif (!response.writableEnded) response.status(HttpCodes.InternalServerError).json({ error: error.message ?? error });\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/listeners/PluginServerMiddlewareError.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,oBAAiD;AAEnD,IAAM,kBAAN,MAAM,wBAAuB,SAAS;AAAA,EACrC,YAAY,SAAiC;AACnD,UAAM,SAAS,EAAE,SAAS,UAAU,OAAO,aAAa,gBAAgB,CAAC;AAAA,EAC1E;AAAA,EAEgB,IAAI,OAAc,EAAE,SAAS,GAA2B;AAEvE,SAAK,UAAU,OAAO,MAAM,KAAK;AAGjC,QAAI,CAAC,SAAS,cAAe,UAAS,OAAO,UAAU,mBAAmB,EAAE,KAAK,EAAE,OAAO,MAAM,WAAW,MAAM,CAAC;AAAA,EACnH;AACD;AAZ6C;AAAtC,IAAM,iBAAN","sourcesContent":["import { Listener } from '@sapphire/framework';\nimport { HttpCodes } from '../lib/structures/http/HttpCodes';\nimport { ServerEvents, type MiddlewareErrorContext } from '../lib/structures/http/Server';\n\nexport class PluginListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext) {\n\t\tsuper(context, { emitter: 'server', event: ServerEvents.MiddlewareError });\n\t}\n\n\tpublic override run(error: Error, { response }: MiddlewareErrorContext) {\n\t\t// Log the error to console:\n\t\tthis.container.logger.fatal(error);\n\n\t\t// Send a response to the client if none was sent:\n\t\tif (!response.writableEnded) response.status(HttpCodes.InternalServerError).json({ error: error.message ?? error });\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { __name } from '../chunk-PYETHG4R.mjs';
1
+ import { __name } from '../chunk-JTFKMR4I.mjs';
2
2
  import { Listener } from '@sapphire/framework';
3
3
  import { ServerEvents } from '../lib/structures/http/Server.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __name } from '../chunk-PYETHG4R.mjs';
1
+ import { __name } from '../chunk-JTFKMR4I.mjs';
2
2
  import { Listener } from '@sapphire/framework';
3
3
  import { ServerEvents } from '../lib/structures/http/Server.mjs';
4
4
 
@@ -7,8 +7,7 @@ var _PluginListener = class _PluginListener extends Listener {
7
7
  super(context, { emitter: "server", event: ServerEvents.NoMatch });
8
8
  }
9
9
  run(_, response) {
10
- if (!response.writableEnded)
11
- response.notFound();
10
+ if (!response.writableEnded) response.notFound();
12
11
  }
13
12
  };
14
13
  __name(_PluginListener, "PluginListener");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/listeners/PluginServerNoMatch.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,gBAAgB;AAGzB,SAAS,oBAAoB;AAEtB,IAAM,kBAAN,MAAM,wBAAuB,SAAS;AAAA,EACrC,YAAY,SAAiC;AACnD,UAAM,SAAS,EAAE,SAAS,UAAU,OAAO,aAAa,QAAQ,CAAC;AAAA,EAClE;AAAA,EAEgB,IAAI,GAAe,UAAuB;AACzD,QAAI,CAAC,SAAS;AAAe,eAAS,SAAS;AAAA,EAChD;AACD;AAR6C;AAAtC,IAAM,iBAAN","sourcesContent":["import { Listener } from '@sapphire/framework';\nimport type { ApiRequest } from '../lib/structures/api/ApiRequest';\nimport type { ApiResponse } from '../lib/structures/api/ApiResponse';\nimport { ServerEvents } from '../lib/structures/http/Server';\n\nexport class PluginListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext) {\n\t\tsuper(context, { emitter: 'server', event: ServerEvents.NoMatch });\n\t}\n\n\tpublic override run(_: ApiRequest, response: ApiResponse) {\n\t\tif (!response.writableEnded) response.notFound();\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/listeners/PluginServerNoMatch.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,gBAAgB;AAGzB,SAAS,oBAAoB;AAEtB,IAAM,kBAAN,MAAM,wBAAuB,SAAS;AAAA,EACrC,YAAY,SAAiC;AACnD,UAAM,SAAS,EAAE,SAAS,UAAU,OAAO,aAAa,QAAQ,CAAC;AAAA,EAClE;AAAA,EAEgB,IAAI,GAAe,UAAuB;AACzD,QAAI,CAAC,SAAS,cAAe,UAAS,SAAS;AAAA,EAChD;AACD;AAR6C;AAAtC,IAAM,iBAAN","sourcesContent":["import { Listener } from '@sapphire/framework';\nimport type { ApiRequest } from '../lib/structures/api/ApiRequest';\nimport type { ApiResponse } from '../lib/structures/api/ApiResponse';\nimport { ServerEvents } from '../lib/structures/http/Server';\n\nexport class PluginListener extends Listener {\n\tpublic constructor(context: Listener.LoaderContext) {\n\t\tsuper(context, { emitter: 'server', event: ServerEvents.NoMatch });\n\t}\n\n\tpublic override run(_: ApiRequest, response: ApiResponse) {\n\t\tif (!response.writableEnded) response.notFound();\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { __name } from '../chunk-PYETHG4R.mjs';
1
+ import { __name } from '../chunk-JTFKMR4I.mjs';
2
2
  import { Listener } from '@sapphire/framework';
3
3
  import { ServerEvents } from '../lib/structures/http/Server.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { __name } from '../chunk-PYETHG4R.mjs';
1
+ import { __name } from '../chunk-JTFKMR4I.mjs';
2
2
  import { container } from '@sapphire/pieces';
3
3
  import { PluginListener } from './PluginRouteError.mjs';
4
4
  import { PluginListener as PluginListener$1 } from './PluginServerMatch.mjs';