@sapphire/plugin-api 7.0.0-next.7829696 → 7.0.0-next.7ba75bc

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 (44) hide show
  1. package/README.md +0 -1
  2. package/dist/cjs/index.cjs +1 -8
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/index.d.cts +17 -32
  5. package/dist/cjs/lib/structures/MediaParser.cjs.map +1 -1
  6. package/dist/cjs/lib/structures/Route.cjs +4 -4
  7. package/dist/cjs/lib/structures/Route.cjs.map +1 -1
  8. package/dist/cjs/lib/structures/api/ApiResponse.cjs +4 -5
  9. package/dist/cjs/lib/structures/api/ApiResponse.cjs.map +1 -1
  10. package/dist/cjs/lib/structures/http/Server.cjs.map +1 -1
  11. package/dist/cjs/lib/structures/router/RouterRoot.cjs +11 -0
  12. package/dist/cjs/lib/structures/router/RouterRoot.cjs.map +1 -1
  13. package/dist/cjs/lib/utils/MimeType.cjs +4 -0
  14. package/dist/cjs/lib/utils/MimeType.cjs.map +1 -0
  15. package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs +1 -2
  16. package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs.map +1 -1
  17. package/dist/cjs/mediaParsers/applicationJson.cjs +1 -2
  18. package/dist/cjs/mediaParsers/applicationJson.cjs.map +1 -1
  19. package/dist/cjs/mediaParsers/textPlain.cjs +1 -2
  20. package/dist/cjs/mediaParsers/textPlain.cjs.map +1 -1
  21. package/dist/esm/index.d.mts +17 -32
  22. package/dist/esm/index.mjs +1 -2
  23. package/dist/esm/index.mjs.map +1 -1
  24. package/dist/esm/lib/structures/MediaParser.mjs.map +1 -1
  25. package/dist/esm/lib/structures/Route.mjs +4 -4
  26. package/dist/esm/lib/structures/Route.mjs.map +1 -1
  27. package/dist/esm/lib/structures/api/ApiResponse.mjs +4 -5
  28. package/dist/esm/lib/structures/api/ApiResponse.mjs.map +1 -1
  29. package/dist/esm/lib/structures/http/Server.mjs.map +1 -1
  30. package/dist/esm/lib/structures/router/RouterRoot.mjs +11 -0
  31. package/dist/esm/lib/structures/router/RouterRoot.mjs.map +1 -1
  32. package/dist/esm/lib/utils/MimeType.mjs +3 -0
  33. package/dist/esm/lib/utils/MimeType.mjs.map +1 -0
  34. package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs +1 -2
  35. package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs.map +1 -1
  36. package/dist/esm/mediaParsers/applicationJson.mjs +1 -2
  37. package/dist/esm/mediaParsers/applicationJson.mjs.map +1 -1
  38. package/dist/esm/mediaParsers/textPlain.mjs +1 -2
  39. package/dist/esm/mediaParsers/textPlain.mjs.map +1 -1
  40. package/package.json +9 -8
  41. package/dist/cjs/lib/utils/MimeTypes.cjs +0 -26
  42. package/dist/cjs/lib/utils/MimeTypes.cjs.map +0 -1
  43. package/dist/esm/lib/utils/MimeTypes.mjs +0 -26
  44. package/dist/esm/lib/utils/MimeTypes.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/MediaParser.ts"],"names":[],"mappings":";;;;AAWO,IAAe,YAAA,GAAf,MAAe,YAAA,SAA+E,KAA+B,CAAA;AAAA,EAC5H,WAAY,CAAA,OAAA,EAAoC,OAAmB,GAAA,EAAe,EAAA;AACxF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAAA,GACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,QAAQ,KAAuB,EAAA;AACrC,IAAA,OAAO,MAAM,wBAA6B,KAAA,IAAA,IAAQ,MAAM,wBAAyB,CAAA,QAAA,CAAS,KAAK,IAAiC,CAAA,CAAA;AAAA,GACjI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,OAA+C,EAAA;AACzE,IAAM,MAAA,MAAA,GAAS,IAAK,CAAA,aAAA,CAAc,OAAO,CAAA,CAAA;AACzC,IAAI,IAAA,MAAA,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;AACnB,QAAO,OAAA,MAAA,CAAA;AAAA,OACR;AAAA,MAIA,KAAK,UAAY,EAAA;AAChB,QAAO,OAAA,OAAA,CAAA;AAAA,OACR;AAAA,KACD;AAEA,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AACD,CAAA,CAAA;AAhGoI,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAA7H,IAAe,WAAf,GAAA","file":"MediaParser.mjs","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport { createBrotliDecompress, createGunzip, createInflate, type Gunzip } from 'zlib';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { MimeTypeWithoutParameters } from './http/Server';\nimport type { Route } from './Route';\n\n/**\n * A media parser\n * @since 1.3.0\n */\nexport abstract class MediaParser<Options extends MediaParser.Options = MediaParser.Options> extends Piece<Options, 'mediaParsers'> {\n\tpublic constructor(context: MediaParser.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t}\n\n\t/**\n\t * Parses the body data from an API request.\n\t * @since 1.3.0\n\t */\n\tpublic abstract run(request: MediaParser.Request): Awaitable<unknown>;\n\n\t/**\n\t * Checks if a route accepts the media type from this parser.\n\t * @since 1.3.0\n\t * @param route The route to be checked.\n\t */\n\tpublic accepts(route: Route): boolean {\n\t\treturn route.acceptedContentMimeTypes === null || route.acceptedContentMimeTypes.includes(this.name as MimeTypeWithoutParameters);\n\t}\n\n\t/**\n\t * Reads the content body as a string, this is useful for parsing/reading plain-text data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readString(request: MediaParser.Request): Promise<string> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return '';\n\n\t\tlet body = '';\n\t\tfor await (const chunk of stream) body += chunk;\n\n\t\treturn body;\n\t}\n\n\t/**\n\t * Reads the content body as a buffer, this is useful for parsing/reading binary data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readBuffer(request: MediaParser.Request): Promise<Buffer> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return Buffer.alloc(0);\n\n\t\tconst bodies: Buffer[] = [];\n\t\tfor await (const chunk of stream) bodies.push(chunk);\n\n\t\treturn Buffer.concat(bodies);\n\t}\n\n\t/**\n\t * Reads the content stream from a request, piping the data through a transformer stream.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected contentStream(request: MediaParser.Request): MediaParser.Request | Gunzip | null {\n\t\tswitch ((request.headers['content-encoding'] ?? 'identity').toLowerCase()) {\n\t\t\t// RFC 7230 4.2.2:\n\t\t\t//\n\t\t\t// The \"deflate\" coding is a \"zlib\" data format (RFC 1950) containing a \"deflate\" compressed data stream\n\t\t\t// (RFC 1951) that uses a combination of the Lempel-Ziv (LZ77) compression algorithm and Huffman coding.\n\t\t\tcase 'deflate': {\n\t\t\t\tconst stream = createInflate();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7230 4.2.3\n\t\t\t//\n\t\t\t// The \"gzip\" coding is an LZ77 coding with a 32-bit Cyclic Redundancy Check (CRC) that is commonly produced\n\t\t\t// by the gzip file compression program (RFC 1952).\n\t\t\tcase 'x-gzip':\n\t\t\tcase 'gzip': {\n\t\t\t\tconst stream = createGunzip();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7932\n\t\t\t//\n\t\t\t// A format using the Brotli algorithm.\n\t\t\tcase 'br': {\n\t\t\t\tconst stream = createBrotliDecompress();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// An \"identity\" token is used as a synonym for \"no encoding\" in order to communicate when no encoding is\n\t\t\t// preferred.\n\t\t\tcase 'identity': {\n\t\t\t\treturn request;\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n}\n\nexport namespace MediaParser {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'mediaParsers'>;\n\texport type Options = Piece.Options;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n\n\texport type Request = ApiRequest;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/MediaParser.ts"],"names":[],"mappings":";;;;AAWO,IAAe,YAAA,GAAf,MAAe,YAAA,SAA+E,KAA+B,CAAA;AAAA,EAC5H,WAAY,CAAA,OAAA,EAAoC,OAAmB,GAAA,EAAe,EAAA;AACxF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAAA,GACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,QAAQ,KAAuB,EAAA;AACrC,IAAA,OAAO,MAAM,wBAA6B,KAAA,IAAA,IAAQ,MAAM,wBAAyB,CAAA,QAAA,CAAS,KAAK,IAAgB,CAAA,CAAA;AAAA,GAChH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,OAA+C,EAAA;AACzE,IAAM,MAAA,MAAA,GAAS,IAAK,CAAA,aAAA,CAAc,OAAO,CAAA,CAAA;AACzC,IAAI,IAAA,MAAA,KAAW,MAAa,OAAA,EAAA,CAAA;AAE5B,IAAA,IAAI,IAAO,GAAA,EAAA,CAAA;AACX,IAAiB,WAAA,MAAA,KAAA,IAAS,QAAgB,IAAA,IAAA,KAAA,CAAA;AAE1C,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,OAA+C,EAAA;AACzE,IAAM,MAAA,MAAA,GAAS,IAAK,CAAA,aAAA,CAAc,OAAO,CAAA,CAAA;AACzC,IAAA,IAAI,MAAW,KAAA,IAAA,EAAa,OAAA,MAAA,CAAO,MAAM,CAAC,CAAA,CAAA;AAE1C,IAAA,MAAM,SAAmB,EAAC,CAAA;AAC1B,IAAA,WAAA,MAAiB,KAAS,IAAA,MAAA,EAAe,MAAA,CAAA,IAAA,CAAK,KAAK,CAAA,CAAA;AAEnD,IAAO,OAAA,MAAA,CAAO,OAAO,MAAM,CAAA,CAAA;AAAA,GAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,cAAc,OAAmE,EAAA;AAC1F,IAAA,QAAA,CAAS,QAAQ,OAAQ,CAAA,kBAAkB,CAAK,IAAA,UAAA,EAAY,aAAe;AAAA,MAK1E,KAAK,SAAW,EAAA;AACf,QAAA,MAAM,SAAS,aAAc,EAAA,CAAA;AAC7B,QAAA,OAAA,CAAQ,KAAK,MAAM,CAAA,CAAA;AACnB,QAAO,OAAA,MAAA,CAAA;AAAA,OACR;AAAA,MAMA,KAAK,QAAA,CAAA;AAAA,MACL,KAAK,MAAQ,EAAA;AACZ,QAAA,MAAM,SAAS,YAAa,EAAA,CAAA;AAC5B,QAAA,OAAA,CAAQ,KAAK,MAAM,CAAA,CAAA;AACnB,QAAO,OAAA,MAAA,CAAA;AAAA,OACR;AAAA,MAKA,KAAK,IAAM,EAAA;AACV,QAAA,MAAM,SAAS,sBAAuB,EAAA,CAAA;AACtC,QAAA,OAAA,CAAQ,KAAK,MAAM,CAAA,CAAA;AACnB,QAAO,OAAA,MAAA,CAAA;AAAA,OACR;AAAA,MAIA,KAAK,UAAY,EAAA;AAChB,QAAO,OAAA,OAAA,CAAA;AAAA,OACR;AAAA,KACD;AAEA,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AACD,CAAA,CAAA;AAhGoI,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAA7H,IAAe,WAAf,GAAA","file":"MediaParser.mjs","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport { createBrotliDecompress, createGunzip, createInflate, type Gunzip } from 'zlib';\nimport type { MimeType } from '../utils/MimeType';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { Route } from './Route';\n\n/**\n * A media parser\n * @since 1.3.0\n */\nexport abstract class MediaParser<Options extends MediaParser.Options = MediaParser.Options> extends Piece<Options, 'mediaParsers'> {\n\tpublic constructor(context: MediaParser.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t}\n\n\t/**\n\t * Parses the body data from an API request.\n\t * @since 1.3.0\n\t */\n\tpublic abstract run(request: MediaParser.Request): Awaitable<unknown>;\n\n\t/**\n\t * Checks if a route accepts the media type from this parser.\n\t * @since 1.3.0\n\t * @param route The route to be checked.\n\t */\n\tpublic accepts(route: Route): boolean {\n\t\treturn route.acceptedContentMimeTypes === null || route.acceptedContentMimeTypes.includes(this.name as MimeType);\n\t}\n\n\t/**\n\t * Reads the content body as a string, this is useful for parsing/reading plain-text data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readString(request: MediaParser.Request): Promise<string> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return '';\n\n\t\tlet body = '';\n\t\tfor await (const chunk of stream) body += chunk;\n\n\t\treturn body;\n\t}\n\n\t/**\n\t * Reads the content body as a buffer, this is useful for parsing/reading binary data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readBuffer(request: MediaParser.Request): Promise<Buffer> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return Buffer.alloc(0);\n\n\t\tconst bodies: Buffer[] = [];\n\t\tfor await (const chunk of stream) bodies.push(chunk);\n\n\t\treturn Buffer.concat(bodies);\n\t}\n\n\t/**\n\t * Reads the content stream from a request, piping the data through a transformer stream.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected contentStream(request: MediaParser.Request): MediaParser.Request | Gunzip | null {\n\t\tswitch ((request.headers['content-encoding'] ?? 'identity').toLowerCase()) {\n\t\t\t// RFC 7230 4.2.2:\n\t\t\t//\n\t\t\t// The \"deflate\" coding is a \"zlib\" data format (RFC 1950) containing a \"deflate\" compressed data stream\n\t\t\t// (RFC 1951) that uses a combination of the Lempel-Ziv (LZ77) compression algorithm and Huffman coding.\n\t\t\tcase 'deflate': {\n\t\t\t\tconst stream = createInflate();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7230 4.2.3\n\t\t\t//\n\t\t\t// The \"gzip\" coding is an LZ77 coding with a 32-bit Cyclic Redundancy Check (CRC) that is commonly produced\n\t\t\t// by the gzip file compression program (RFC 1952).\n\t\t\tcase 'x-gzip':\n\t\t\tcase 'gzip': {\n\t\t\t\tconst stream = createGunzip();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7932\n\t\t\t//\n\t\t\t// A format using the Brotli algorithm.\n\t\t\tcase 'br': {\n\t\t\t\tconst stream = createBrotliDecompress();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// An \"identity\" token is used as a synonym for \"no encoding\" in order to communicate when no encoding is\n\t\t\t// preferred.\n\t\t\tcase 'identity': {\n\t\t\t\treturn request;\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n}\n\nexport namespace MediaParser {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'mediaParsers'>;\n\texport type Options = Piece.Options;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n\n\texport type Request = ApiRequest;\n}\n"]}
@@ -23,10 +23,10 @@ var _Route = class _Route extends Piece {
23
23
  */
24
24
  __publicField(this, "methods");
25
25
  const api = this.container.server.options;
26
- const path = [].concat(
27
- RouterRoot.normalize(api.prefix),
28
- RouterRoot.normalize(options.route ?? (this.location.virtual ? this.name : this.location.directories.concat(this.name).join("/")))
29
- );
26
+ const path = [
27
+ ...RouterRoot.normalize(api.prefix),
28
+ ...RouterRoot.normalize(options.route ?? RouterRoot.makeRoutePathForPiece(this.location.directories, this.name))
29
+ ];
30
30
  const methods = new Set(options.methods);
31
31
  const implied = RouterRoot.extractMethod(path);
32
32
  if (!isNullish(implied)) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":";;;;;AA6CO,IAAe,MAAA,GAAf,MAAe,MAAA,SAA6D,KAAyB,CAAA;AAAA,EAqBpG,WAAY,CAAA,OAAA,EAA8B,OAAmB,GAAA,EAAe,EAAA;AAClF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAlBvB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,mBAAA,CAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,0BAAA,CAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA,CAAA;AAKhB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;AAKf,IAAM,MAAA,GAAA,GAAM,IAAK,CAAA,SAAA,CAAU,MAAO,CAAA,OAAA,CAAA;AAClC,IAAM,MAAA,IAAA,GAAQ,EAAgB,CAAA,MAAA;AAAA,MAC7B,UAAA,CAAW,SAAU,CAAA,GAAA,CAAI,MAAM,CAAA;AAAA,MAC/B,WAAW,SAAU,CAAA,OAAA,CAAQ,UAAU,IAAK,CAAA,QAAA,CAAS,UAAU,IAAK,CAAA,IAAA,GAAO,IAAK,CAAA,QAAA,CAAS,YAAY,MAAO,CAAA,IAAA,CAAK,IAAI,CAAE,CAAA,IAAA,CAAK,GAAG,CAAE,CAAA,CAAA;AAAA,KAClI,CAAA;AAEA,IAAA,MAAM,OAAU,GAAA,IAAI,GAAI,CAAA,OAAA,CAAQ,OAAO,CAAA,CAAA;AACvC,IAAM,MAAA,OAAA,GAAU,UAAW,CAAA,aAAA,CAAc,IAAI,CAAA,CAAA;AAC7C,IAAI,IAAA,CAAC,SAAU,CAAA,OAAO,CAAG,EAAA;AACxB,MAAM,MAAA,SAAA,GAAY,KAAK,MAAS,GAAA,CAAA,CAAA;AAChC,MAAA,IAAA,CAAK,SAAS,CAAA,GAAI,IAAK,CAAA,SAAS,CAAE,CAAA,KAAA,CAAM,CAAG,EAAA,IAAA,CAAK,SAAS,CAAA,CAAE,MAAS,GAAA,OAAA,CAAQ,SAAS,CAAC,CAAA,CAAA;AACtF,MAAA,OAAA,CAAQ,IAAI,OAAqB,CAAA,CAAA;AAAA,KAClC;AAEA,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AACZ,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA,CAAA;AACf,IAAA,IAAA,CAAK,oBAAoB,OAAQ,CAAA,iBAAA,IAAqB,GAAI,CAAA,iBAAA,IAAqB,OAAO,IAAO,GAAA,EAAA,CAAA;AAC7F,IAAA,IAAA,CAAK,wBAA2B,GAAA,OAAA,CAAQ,wBAA4B,IAAA,GAAA,CAAI,wBAA4B,IAAA,IAAA,CAAA;AAAA,GACrG;AAGD,CAAA,CAAA;AA7C4G,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;AAArG,IAAe,KAAf,GAAA","file":"Route.mjs","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport { isNullish, type Awaitable } from '@sapphire/utilities';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\nimport type { MethodName } from './http/HttpMethods';\nimport type { MimeTypeWithoutParameters } from './http/Server';\nimport { RouterRoot } from './router/RouterRoot';\n\n/**\n * @since 1.0.0\n *\n * @example A simple GET route that returns a JSON response:\n * ```typescript\n * // hello.get.ts\n * import { Route } from '@sapphire/plugin-api';\n *\n * export class MyRoute extends Route {\n * public run(request: Route.Request, response: Route.Response) {\n * return response.json({ message: 'Hello, World!' });\n * }\n * }\n * ```\n *\n * ```bash\n * $ curl http://localhost:4000/hello\n * {\"message\":\"Hello, World!\"}\n * ```\n *\n * @example A simple POST route that reads the body and returns it:\n * ```typescript\n * // echo.post.ts\n * import { Route } from '@sapphire/plugin-api';\n *\n * export class MyRoute extends Route {\n * public run(request: Route.Request, response: Route.Response) {\n * return response.json(request.params);\n * }\n * }\n * ```\n *\n * ```bash\n * $ curl -X POST -H \"Content-Type: application/json\" -d '{\"hello\":\"world\"}' http://localhost:4000/echo\n * {\"hello\":\"world\"}\n * ```\n */\nexport abstract class Route<Options extends Route.Options = Route.Options> extends Piece<Options, 'routes'> {\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t */\n\tpublic readonly maximumBodyLength: number;\n\n\t/**\n\t * The accepted content types.\n\t */\n\tpublic readonly acceptedContentMimeTypes: readonly MimeTypeWithoutParameters[] | null;\n\n\t/**\n\t * The path this route represents.\n\t */\n\tpublic readonly path: readonly string[];\n\n\t/**\n\t * The methods this route accepts.\n\t */\n\tpublic readonly methods: ReadonlySet<MethodName>;\n\n\tpublic constructor(context: Route.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\n\t\tconst api = this.container.server.options;\n\t\tconst path = ([] as string[]).concat(\n\t\t\tRouterRoot.normalize(api.prefix),\n\t\t\tRouterRoot.normalize(options.route ?? (this.location.virtual ? this.name : this.location.directories.concat(this.name).join('/')))\n\t\t);\n\n\t\tconst methods = new Set(options.methods);\n\t\tconst implied = RouterRoot.extractMethod(path);\n\t\tif (!isNullish(implied)) {\n\t\t\tconst lastIndex = path.length - 1;\n\t\t\tpath[lastIndex] = path[lastIndex].slice(0, path[lastIndex].length - implied.length - 1);\n\t\t\tmethods.add(implied as MethodName);\n\t\t}\n\n\t\tthis.path = path;\n\t\tthis.methods = methods;\n\t\tthis.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;\n\t\tthis.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;\n\t}\n\n\tpublic abstract run(request: Route.Request, response: Route.Response): Awaitable<unknown>;\n}\n\nexport interface RouteOptions extends Piece.Options {\n\t/**\n\t * The route the piece should represent.\n\t * @since 1.0.0\n\t *\n\t * @defaultValue The filesystem-based path, or the name if the location is virtual.\n\t *\n\t * @example\n\t * ```typescript\n\t * '/users'\n\t * // request.params -> {}\n\t * ```\n\t * @example\n\t * ```typescript\n\t * '/guilds/[guild]/members/[member]'\n\t * // request.params -> { guild: '...', member: '...' }\n\t * ```\n\t */\n\troute?: string;\n\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t * @since 1.0.0\n\t *\n\t * @defaultValue this.context.server.options.maximumBodyLength ?? 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The accepted content types for this route. If set to null, the route will accept any data.\n\t * @since 1.3.0\n\t *\n\t * @defaultValue this.context.server.options.acceptedContentMimeTypes ?? null\n\t */\n\tacceptedContentMimeTypes?: readonly MimeTypeWithoutParameters[] | null;\n\n\t/**\n\t * The methods this route accepts.\n\t * @since 7.0.0\n\t *\n\t * @defaultValue The method defined in the piece name, or none if not set.\n\t */\n\tmethods?: readonly MethodName[];\n}\n\nexport namespace Route {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'routes'>;\n\texport type Options = RouteOptions;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n\n\texport type Request = ApiRequest;\n\texport type Response = ApiResponse;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":";;;;;AA6CO,IAAe,MAAA,GAAf,MAAe,MAAA,SAA6D,KAAyB,CAAA;AAAA,EAqBpG,WAAY,CAAA,OAAA,EAA8B,OAAmB,GAAA,EAAe,EAAA;AAClF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAlBvB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,mBAAA,CAAA,CAAA;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AAqB,GAAI,CAAA,iBAAA,IAAqB,OAAO,IAAO,GAAA,EAAA,CAAA;AAC7F,IAAA,IAAA,CAAK,wBAA2B,GAAA,OAAA,CAAQ,wBAA4B,IAAA,GAAA,CAAI,wBAA4B,IAAA,IAAA,CAAA;AAAA,GACrG;AAGD,CAAA,CAAA;AA7C4G,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;AAArG,IAAe,KAAf,GAAA","file":"Route.mjs","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport { isNullish, type Awaitable } from '@sapphire/utilities';\nimport type { MimeType } from '../utils/MimeType';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\nimport type { MethodName } from './http/HttpMethods';\nimport { RouterRoot } from './router/RouterRoot';\n\n/**\n * @since 1.0.0\n *\n * @example A simple GET route that returns a JSON response:\n * ```typescript\n * // hello.get.ts\n * import { Route } from '@sapphire/plugin-api';\n *\n * export class MyRoute extends Route {\n * public run(request: Route.Request, response: Route.Response) {\n * return response.json({ message: 'Hello, World!' });\n * }\n * }\n * ```\n *\n * ```bash\n * $ curl http://localhost:4000/hello\n * {\"message\":\"Hello, World!\"}\n * ```\n *\n * @example A simple POST route that reads the body and returns it:\n * ```typescript\n * // echo.post.ts\n * import { Route } from '@sapphire/plugin-api';\n *\n * export class MyRoute extends Route {\n * public run(request: Route.Request, response: Route.Response) {\n * return response.json(request.params);\n * }\n * }\n * ```\n *\n * ```bash\n * $ curl -X POST -H \"Content-Type: application/json\" -d '{\"hello\":\"world\"}' http://localhost:4000/echo\n * {\"hello\":\"world\"}\n * ```\n */\nexport abstract class Route<Options extends Route.Options = Route.Options> extends Piece<Options, 'routes'> {\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t */\n\tpublic readonly maximumBodyLength: number;\n\n\t/**\n\t * The accepted content types.\n\t */\n\tpublic readonly acceptedContentMimeTypes: readonly MimeType[] | null;\n\n\t/**\n\t * The path this route represents.\n\t */\n\tpublic readonly path: readonly string[];\n\n\t/**\n\t * The methods this route accepts.\n\t */\n\tpublic readonly methods: ReadonlySet<MethodName>;\n\n\tpublic constructor(context: Route.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\n\t\tconst api = this.container.server.options;\n\t\tconst path = [\n\t\t\t...RouterRoot.normalize(api.prefix),\n\t\t\t...RouterRoot.normalize(options.route ?? RouterRoot.makeRoutePathForPiece(this.location.directories, this.name))\n\t\t];\n\n\t\tconst methods = new Set(options.methods);\n\t\tconst implied = RouterRoot.extractMethod(path);\n\t\tif (!isNullish(implied)) {\n\t\t\tconst lastIndex = path.length - 1;\n\t\t\tpath[lastIndex] = path[lastIndex].slice(0, path[lastIndex].length - implied.length - 1);\n\t\t\tmethods.add(implied as MethodName);\n\t\t}\n\n\t\tthis.path = path;\n\t\tthis.methods = methods;\n\t\tthis.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;\n\t\tthis.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;\n\t}\n\n\tpublic abstract run(request: Route.Request, response: Route.Response): Awaitable<unknown>;\n}\n\nexport interface RouteOptions extends Piece.Options {\n\t/**\n\t * The route the piece should represent.\n\t * @since 1.0.0\n\t *\n\t * @defaultValue The filesystem-based path, or the name if the location is virtual.\n\t *\n\t * @example\n\t * ```typescript\n\t * '/users'\n\t * // request.params -> {}\n\t * ```\n\t * @example\n\t * ```typescript\n\t * '/guilds/[guild]/members/[member]'\n\t * // request.params -> { guild: '...', member: '...' }\n\t * ```\n\t */\n\troute?: string;\n\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t * @since 1.0.0\n\t *\n\t * @defaultValue this.context.server.options.maximumBodyLength ?? 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The accepted content types for this route. If set to null, the route will accept any data.\n\t * @since 1.3.0\n\t *\n\t * @defaultValue this.context.server.options.acceptedContentMimeTypes ?? null\n\t */\n\tacceptedContentMimeTypes?: readonly MimeType[] | null;\n\n\t/**\n\t * The methods this route accepts.\n\t * @since 7.0.0\n\t *\n\t * @defaultValue The method defined in the piece name, or none if not set.\n\t */\n\tmethods?: readonly MethodName[];\n}\n\nexport namespace Route {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'routes'>;\n\texport type Options = RouteOptions;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n\n\texport type Request = ApiRequest;\n\texport type Response = ApiResponse;\n}\n"]}
@@ -2,7 +2,6 @@ import { __name, __publicField } from '../../../chunk-S573YWRP.mjs';
2
2
  import { ServerResponse, STATUS_CODES } from 'node:http';
3
3
  import { Readable } from 'node:stream';
4
4
  import 'node:stream/web';
5
- import { MimeTypes } from '../../utils/MimeTypes.mjs';
6
5
  import { HttpCodes } from '../http/HttpCodes.mjs';
7
6
 
8
7
  var _ApiResponse = class _ApiResponse extends ServerResponse {
@@ -96,20 +95,20 @@ var _ApiResponse = class _ApiResponse extends ServerResponse {
96
95
  * @since 1.0.0
97
96
  */
98
97
  json(data) {
99
- this.setContentType(MimeTypes.ApplicationJson).end(JSON.stringify(data));
98
+ this.setContentType("application/json").end(JSON.stringify(data));
100
99
  }
101
100
  /**
102
101
  * @since 1.0.0
103
102
  */
104
103
  text(data) {
105
- this.setContentType(MimeTypes.TextPlain).end(data);
104
+ this.setContentType("text/plain").end(data);
106
105
  }
107
106
  /**
108
107
  * @since 6.1.0
109
108
  *
110
109
  * Sets the image content type and sends the image data in the response.
111
110
  *
112
- * @param type - The MIME type of the image (e.g., {@link MimeTypes.ImagePng}).
111
+ * @param type - The MIME type of the image (e.g., 'image/png').
113
112
  * @param data - The image data as a `string`, {@link Buffer}, {@link Uint8Array}, or {@link ReadableStream}.
114
113
  */
115
114
  image(type, data) {
@@ -124,7 +123,7 @@ var _ApiResponse = class _ApiResponse extends ServerResponse {
124
123
  * @since 5.1.0
125
124
  */
126
125
  html(code, data) {
127
- this.setContentType(MimeTypes.TextHtml).status(code).end(data);
126
+ this.setContentType("text/html").status(code).end(data);
128
127
  }
129
128
  /**
130
129
  * @since 1.0.0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/lib/structures/api/ApiResponse.ts"],"names":[],"mappings":";;;;;;;AAUO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAuE,cAAwB,CAAA;AAAA,EAArG,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;AAAA,GAAA;AAAA;AAAA;AAAA;AAAA,EAKA,EAAG,CAAA,IAAA,GAAgB,YAAa,CAAA,SAAA,CAAU,EAAE,CAAS,EAAA;AAC3D,IAAK,IAAA,CAAA,MAAA,CAAO,UAAU,EAAE,CAAA,CAAA;AACxB,IAAO,OAAA,IAAA,CAAK,QAAQ,IAAI,CAAA,CAAA;AAAA,GACzB;AAAA;AAAA;AAAA;AAAA,EAKO,OAAQ,CAAA,IAAA,GAAgB,YAAa,CAAA,SAAA,CAAU,OAAO,CAAS,EAAA;AACrE,IAAK,IAAA,CAAA,MAAA,CAAO,UAAU,OAAO,CAAA,CAAA;AAC7B,IAAO,OAAA,IAAA,CAAK,QAAQ,IAAI,CAAA,CAAA;AAAA,GACzB;AAAA;AAAA;AAAA;AAAA,EAKO,SAAU,CAAA,IAAA,GAAgB,YAAa,CAAA,SAAA,CAAU,SAAS,CAAS,EAAA;AACzE,IAAK,IAAA,CAAA,MAAA,CAAO,UAAU,SAAS,CAAA,CAAA;AAC/B,IAAO,OAAA,IAAA,CAAK,QAAQ,IAAI,CAAA,CAAA;AAAA,GACzB;AAAA;AAAA;AAAA;AAAA,EAKO,WAAW,IAAsB,EAAA;AACvC,IAAA,OAAO,IAAK,CAAA,KAAA,CAAM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AAC1C,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AACD,CAAA,CAAA;AAlJ4G,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAArG,IAAM,WAAN,GAAA","file":"ApiResponse.mjs","sourcesContent":["import { IncomingMessage, ServerResponse, STATUS_CODES } from 'node:http';\nimport { Readable } from 'node:stream';\nimport { ReadableStream } from 'node:stream/web';\nimport { MimeTypes } from '../../utils/MimeTypes';\nimport { HttpCodes } from '../http/HttpCodes';\nimport type { CookieStore } from './CookieStore';\n\n/**\n * @since 1.0.0\n */\nexport class ApiResponse<Request extends IncomingMessage = IncomingMessage> extends ServerResponse<Request> {\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic cookies!: CookieStore;\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic ok(data: unknown = STATUS_CODES[HttpCodes.OK]): void {\n\t\tthis.status(HttpCodes.OK);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic created(data: unknown = STATUS_CODES[HttpCodes.Created]): void {\n\t\tthis.status(HttpCodes.Created);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic noContent(data: unknown = STATUS_CODES[HttpCodes.NoContent]): void {\n\t\tthis.status(HttpCodes.NoContent);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic badRequest(data?: unknown): void {\n\t\treturn this.error(HttpCodes.BadRequest, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic unauthorized(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Unauthorized, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic forbidden(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Forbidden, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic notFound(data?: unknown): void {\n\t\treturn this.error(HttpCodes.NotFound, data);\n\t}\n\n\t/**\n\t * @since 7.0.0\n\t */\n\tpublic methodNotAllowed(data?: unknown): void {\n\t\treturn this.error(HttpCodes.MethodNotAllowed, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic conflict(data?: unknown) {\n\t\treturn this.error(HttpCodes.Conflict, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic error(error: number | string, data?: unknown): void {\n\t\tif (typeof error === 'string') {\n\t\t\treturn this.status(HttpCodes.InternalServerError).json({ error });\n\t\t}\n\n\t\treturn this.status(error).json({ error: data ?? STATUS_CODES[error] });\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic respond(data: unknown): void {\n\t\treturn typeof data === 'string' ? this.text(data) : this.json(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic status(code: number): this {\n\t\tthis.statusCode = code;\n\t\treturn this;\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic json(data: any): void {\n\t\tthis.setContentType(MimeTypes.ApplicationJson).end(JSON.stringify(data));\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic text(data: string): void {\n\t\tthis.setContentType(MimeTypes.TextPlain).end(data);\n\t}\n\n\t/**\n\t * @since 6.1.0\n\t *\n\t * Sets the image content type and sends the image data in the response.\n\t *\n\t * @param type - The MIME type of the image (e.g., {@link MimeTypes.ImagePng}).\n\t * @param data - The image data as a `string`, {@link Buffer}, {@link Uint8Array}, or {@link ReadableStream}.\n\t */\n\tpublic image(\n\t\ttype: MimeTypes.ImageGif | MimeTypes.ImageJpg | MimeTypes.ImagePng | MimeTypes.ImageWebp | MimeTypes.ImageXIcon,\n\t\tdata: string | Buffer | Uint8Array | Readable\n\t): void {\n\t\tif (data instanceof Readable) {\n\t\t\tthis.setContentType(type);\n\t\t\tdata.pipe(this);\n\t\t} else {\n\t\t\tthis.setContentType(type).end(data);\n\t\t}\n\t}\n\n\t/**\n\t * @since 5.1.0\n\t */\n\tpublic html(code: number, data: string): void {\n\t\tthis.setContentType(MimeTypes.TextHtml).status(code).end(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic setContentType(contentType: MimeTypes): this {\n\t\tthis.setHeader('Content-Type', contentType);\n\t\treturn this;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../../src/lib/structures/api/ApiResponse.ts"],"names":[],"mappings":";;;;;;AAUO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAuE,cAAwB,CAAA;AAAA,EAArG,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;AAAA,GAAA;AAAA;AAAA;AAAA;AAAA,EAKA,EAAG,CAAA,IAAA,GAAgB,YAAa,CAAA,SAAA,CAAU,EAAE,CAAS,EAAA;AAC3D,IAAK,IAAA,CAAA,MAAA,CAAO,UAAU,EAAE,CAAA,CAAA;AACxB,IAAO,OAAA,IAAA,CAAK,QAAQ,IAAI,CAAA,CAAA;AAAA,GACzB;AAAA;AAAA;AAAA;AAAA,EAKO,OAAQ,CAAA,IAAA,GAAgB,YAAa,CAAA,SAAA,CAAU,OAAO,CAAS,EAAA;AACrE,IAAK,IAAA,CAAA,MAAA,CAAO,UAAU,OAAO,CAAA,CAAA;AAC7B,IAAO,OAAA,IAAA,CAAK,QAAQ,IAAI,CAAA,CAAA;AAAA,GACzB;AAAA;AAAA;AAAA;AAAA,EAKO,SAAU,CAAA,IAAA,GAAgB,YAAa,CAAA,SAAA,CAAU,SAAS,CAAS,EAAA;AACzE,IAAK,IAAA,CAAA,MAAA,CAAO,UAAU,SAAS,CAAA,CAAA;AAC/B,IAAO,OAAA,IAAA,CAAK,QAAQ,IAAI,CAAA,CAAA;AAAA,GACzB;AAAA;AAAA;AAAA;AAAA,EAKO,WAAW,IAAsB,EAAA;AACvC,IAAA,OAAO,IAAK,CAAA,KAAA,CAAM,SA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,CAAA;AAAA,GACR;AACD,CAAA,CAAA;AA/I4G,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAArG,IAAM,WAAN,GAAA","file":"ApiResponse.mjs","sourcesContent":["import { IncomingMessage, ServerResponse, STATUS_CODES } from 'node:http';\nimport { Readable } from 'node:stream';\nimport { ReadableStream } from 'node:stream/web';\nimport type { MimeType } from '../../utils/MimeType';\nimport { HttpCodes } from '../http/HttpCodes';\nimport type { CookieStore } from './CookieStore';\n\n/**\n * @since 1.0.0\n */\nexport class ApiResponse<Request extends IncomingMessage = IncomingMessage> extends ServerResponse<Request> {\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic cookies!: CookieStore;\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic ok(data: unknown = STATUS_CODES[HttpCodes.OK]): void {\n\t\tthis.status(HttpCodes.OK);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic created(data: unknown = STATUS_CODES[HttpCodes.Created]): void {\n\t\tthis.status(HttpCodes.Created);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic noContent(data: unknown = STATUS_CODES[HttpCodes.NoContent]): void {\n\t\tthis.status(HttpCodes.NoContent);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic badRequest(data?: unknown): void {\n\t\treturn this.error(HttpCodes.BadRequest, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic unauthorized(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Unauthorized, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic forbidden(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Forbidden, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic notFound(data?: unknown): void {\n\t\treturn this.error(HttpCodes.NotFound, data);\n\t}\n\n\t/**\n\t * @since 7.0.0\n\t */\n\tpublic methodNotAllowed(data?: unknown): void {\n\t\treturn this.error(HttpCodes.MethodNotAllowed, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic conflict(data?: unknown) {\n\t\treturn this.error(HttpCodes.Conflict, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic error(error: number | string, data?: unknown): void {\n\t\tif (typeof error === 'string') {\n\t\t\treturn this.status(HttpCodes.InternalServerError).json({ error });\n\t\t}\n\n\t\treturn this.status(error).json({ error: data ?? STATUS_CODES[error] });\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic respond(data: unknown): void {\n\t\treturn typeof data === 'string' ? this.text(data) : this.json(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic status(code: number): this {\n\t\tthis.statusCode = code;\n\t\treturn this;\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic json(data: any): void {\n\t\tthis.setContentType('application/json').end(JSON.stringify(data));\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic text(data: string): void {\n\t\tthis.setContentType('text/plain').end(data);\n\t}\n\n\t/**\n\t * @since 6.1.0\n\t *\n\t * Sets the image content type and sends the image data in the response.\n\t *\n\t * @param type - The MIME type of the image (e.g., 'image/png').\n\t * @param data - The image data as a `string`, {@link Buffer}, {@link Uint8Array}, or {@link ReadableStream}.\n\t */\n\tpublic image(type: Extract<MimeType, `image/${string}`>, data: string | Buffer | Uint8Array | Readable): void {\n\t\tif (data instanceof Readable) {\n\t\t\tthis.setContentType(type);\n\t\t\tdata.pipe(this);\n\t\t} else {\n\t\t\tthis.setContentType(type).end(data);\n\t\t}\n\t}\n\n\t/**\n\t * @since 5.1.0\n\t */\n\tpublic html(code: number, data: string): void {\n\t\tthis.setContentType('text/html').status(code).end(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic setContentType(contentType: MimeType): this {\n\t\tthis.setHeader('Content-Type', contentType);\n\t\treturn this;\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AA;AAAA,GACF;AACD,CAAA,CAAA;AApG4D,MAAA,CAAA,OAAA,EAAA,QAAA,CAAA,CAAA;AAArD,IAAM,MAAN,GAAA","file":"Server.mjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport { Server as HttpServer, createServer as httpCreateServer, type ServerOptions as HttpOptions } from 'node:http';\nimport type { ListenOptions } from 'node:net';\nimport { MediaParserStore } from '../MediaParserStore';\nimport { MiddlewareStore } from '../MiddlewareStore';\nimport type { Route } from '../Route';\nimport { RouteStore } from '../RouteStore';\nimport { ApiRequest } from '../api/ApiRequest';\nimport { ApiResponse } from '../api/ApiResponse';\nimport type { RouterBranch } from '../router/RouterBranch';\nimport { Auth, type ServerOptionsAuth } from './Auth';\n\nexport enum ServerEvent {\n\tError = 'error',\n\tRequest = 'request',\n\tRouterBranchNotFound = 'routerBranchNotFound',\n\tRouterBranchMethodNotAllowed = 'routerBranchMethodNotAllowed',\n\tRouterFound = 'routerFound',\n\tRouteError = 'routeError',\n\tMiddlewareFailure = 'middlewareFailure',\n\tMiddlewareError = 'middlewareError',\n\tMiddlewareSuccess = 'middlewareSuccess'\n}\n\nexport interface ServerEvents {\n\t[ServerEvent.Error]: [error: Error, request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.Request]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouterBranchNotFound]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouterBranchMethodNotAllowed]: [request: ApiRequest, response: ApiResponse, node: RouterBranch];\n\t[ServerEvent.RouterFound]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouteError]: [error: Error, request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.MiddlewareFailure]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.MiddlewareSuccess]: [request: Route.Request, response: Route.Response, route: Route];\n\t[ServerEvent.MiddlewareError]: [error: Error, request: ApiRequest, response: ApiResponse];\n}\n\n/**\n * @since 1.0.0\n */\nexport class Server extends AsyncEventEmitter<ServerEvents> {\n\t/**\n\t * The routes this server holds.\n\t * @since 1.0.0\n\t */\n\tpublic readonly routes: RouteStore;\n\n\t/**\n\t * The middlewares this server holds.\n\t * @since 1.0.0\n\t */\n\tpublic readonly middlewares: MiddlewareStore;\n\n\t/**\n\t * The media parsers this server holds.\n\t * @since 1.3.0\n\t */\n\tpublic readonly mediaParsers: MediaParserStore;\n\n\t/**\n\t * The authentication system.\n\t * @since 1.0.0\n\t */\n\tpublic readonly auth: Auth | null;\n\n\t/**\n\t * The http.Server instance that manages the recieved HTTP requests.\n\t * @since 1.0.0\n\t */\n\tpublic readonly server: HttpServer;\n\n\t/**\n\t * The options for this server.\n\t * @since 1.0.0\n\t */\n\tpublic readonly options: AuthLessServerOptions;\n\n\t/**\n\t * @since 1.0.0\n\t * @param options The options for this server\n\t */\n\tpublic constructor({ auth, ...options }: ServerOptions = {}) {\n\t\tsuper();\n\n\t\tcontainer.server = this;\n\n\t\tthis.options = options;\n\t\tthis.server = httpCreateServer({\n\t\t\tIncomingMessage: ApiRequest,\n\t\t\tServerResponse: ApiResponse,\n\t\t\t...(options.server ?? {})\n\t\t});\n\t\tthis.routes = new RouteStore();\n\t\tthis.middlewares = new MiddlewareStore();\n\t\tthis.mediaParsers = new MediaParserStore();\n\t\tthis.auth = Auth.create(auth);\n\t\tthis.server.on('error', this.emit.bind(this, ServerEvent.Error));\n\t\tthis.server.on('request', this.emit.bind(this, ServerEvent.Request));\n\t}\n\n\tpublic connect() {\n\t\tconst { server } = this;\n\t\tserver.listen({\n\t\t\tport: 4000,\n\t\t\t...(this.options.listenOptions ?? {})\n\t\t});\n\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tfunction listening() {\n\t\t\t\tcleanup();\n\t\t\t\tresolve();\n\t\t\t}\n\n\t\t\tfunction error(error: Error) {\n\t\t\t\tcleanup();\n\t\t\t\treject(error);\n\t\t\t}\n\n\t\t\tfunction close() {\n\t\t\t\tcleanup();\n\t\t\t\treject(new Error('Closed unexpectedly.'));\n\t\t\t}\n\n\t\t\tfunction cleanup() {\n\t\t\t\tserver.off('listening', listening);\n\t\t\t\tserver.off('error', error);\n\t\t\t\tserver.off('close', close);\n\t\t\t}\n\n\t\t\tserver.on('listening', listening);\n\t\t\tserver.on('error', error);\n\t\t\tserver.on('close', close);\n\t\t});\n\t}\n\n\tpublic disconnect() {\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tthis.server.close((error) => (error ? resolve() : reject(error)));\n\t\t});\n\t}\n}\n\n/**\n * RFC 1341 4: Defines a Content-Type's type, which follows the following structure:\n *\n * - `type` = `text` | `multipart` | `message` | `image` | `audio` | `video` | `application` | x-token\n * - `x-token` = The two characters \"X-\" followed, with no intervening white space, by any token\n * @since 1.3.0\n */\nexport type ContentTypeType = 'text' | 'multipart' | 'message' | 'image' | 'audio' | 'video' | 'application' | `X-${string}`;\n\n/**\n * RFC 1341 4: Defines a Content-Type's parameter, which follows the following structure:\n *\n * - `parameter` = `attribute` \"=\" `value`\n * - `attribute` = `token`\n * - `value` = `token` / `quoted-string`\n * - `token` = `1*<any CHAR except \"SPACE\", \"CTLs\", or \"tspecials\">`\n * - `tspecials` = `(` | `)` | `<` | `>` | `@` | `,` | `;` | `:` | `\\` | `\"` | `/` | `[` | `]` | `?` | `.` | `=`\n *\n * @note `tspecials` must be in quoted-string, to use within parameter values.\n * @note The definition of `tspecials` is the same as the RFC 822 definition of `specials` with the addition of the\n * three characters `/`, `?`, and `=`.\n * @since 1.3.0\n */\nexport type ContentTypeParameter = `; ${string}=${string}`;\n\n/**\n * RFC 1341 4: Defines the syntax for a Content-Type field without parameters, which follows the following structure:\n * `type \"/\" subtype`.\n */\nexport type MimeTypeWithoutParameters = `${ContentTypeType}/${string}`;\n\n/**\n * RFC 1341 4: Defines the syntax for a Content-Type field, which follows the following structure:\n * `type \"/\" subtype *[\";\" parameter]`.\n * @since 1.3.0\n */\nexport type MimeType = `${MimeTypeWithoutParameters}${'' | ContentTypeParameter}`;\n\n/**\n * The API options.\n * @since 1.0.0\n */\nexport interface ServerOptions {\n\t/**\n\t * The prefix for all routes, e.g. `v1/`.\n\t * @since 1.0.0\n\t * @default ''\n\t */\n\tprefix?: string;\n\n\t/**\n\t * The origin header to be set on every request at 'Access-Control-Allow-Origin'.\n\t * @since 1.0.0\n\t * @default '*'\n\t */\n\torigin?: string;\n\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t * @since 1.0.0\n\t * @default 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The 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 null\n\t */\n\tacceptedContentMimeTypes?: MimeTypeWithoutParameters[] | null;\n\n\t/**\n\t * The HTTP server options.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\tserver?: HttpOptions;\n\n\t/**\n\t * The HTTP listen options.\n\t * @since 1.0.0\n\t * @default { port: 4000 }\n\t */\n\tlistenOptions?: ListenOptions;\n\n\t/**\n\t * The auth options. If neither `auth` nor `auth.secret` are defined, auth-related routes and middlewares will be\n\t * automatically disabled.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\tauth?: ServerOptionsAuth;\n\n\t/**\n\t * Whether the server should connect upon being when the plugin is loaded.\n\t * @since 3.2.0\n\t * @default true\n\t */\n\tautomaticallyConnect?: boolean;\n}\n\n/**\n * The {@link ServerOptions} without {@link ServerOptions.auth}.\n * @since 1.0.0\n */\nexport type AuthLessServerOptions = Omit<ServerOptions, 'auth'>;\n"]}
1
+ {"version":3,"sources":["../../../../../src/lib/structures/http/Server.ts"],"names":["ServerEvent","httpCreateServer","error"],"mappings":";;;;;;;;;;;AAcY,IAAA,WAAA,qBAAAA,YAAL,KAAA;AACN,EAAAA,aAAA,OAAQ,CAAA,GAAA,OAAA,CAAA;AACR,EAAAA,aAAA,SAAU,CAAA,GAAA,SAAA,CAAA;AACV,EAAAA,aAAA,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AAA,KAAA,EAAA,OAAA,CAAA,CAAA;AAKT,MAAA,SAAS,KAAQ,GAAA;AAChB,QAAQ,OAAA,EAAA,CAAA;AACR,QAAO,MAAA,CAAA,IAAI,KAAM,CAAA,sBAAsB,CAAC,CAAA,CAAA;AAAA,OACzC;AAHS,MAAA,MAAA,CAAA,KAAA,EAAA,OAAA,CAAA,CAAA;AAKT,MAAA,SAAS,OAAU,GAAA;AAClB,QAAO,MAAA,CAAA,GAAA,CAAI,aAAa,SAAS,CAAA,CAAA;AACjC,QAAO,MAAA,CAAA,GAAA,CAAI,SAAS,KAAK,CAAA,CAAA;AACzB,QAAO,MAAA,CAAA,GAAA,CAAI,SAAS,KAAK,CAAA,CAAA;AAAA,OAC1B;AAJS,MAAA,MAAA,CAAA,OAAA,EAAA,SAAA,CAAA,CAAA;AAMT,MAAO,MAAA,CAAA,EAAA,CAAG,aAAa,SAAS,CAAA,CAAA;AAChC,MAAO,MAAA,CAAA,EAAA,CAAG,SAAS,KAAK,CAAA,CAAA;AACxB,MAAO,MAAA,CAAA,EAAA,CAAG,SAAS,KAAK,CAAA,CAAA;AAAA,KACxB,CAAA,CAAA;AAAA,GACF;AAAA,EAEO,UAAa,GAAA;AACnB,IAAA,OAAO,IAAI,OAAA,CAAc,CAAC,OAAA,EAAS,MAAW,KAAA;AAC7C,MAAK,IAAA,CAAA,MAAA,CAAO,MAAM,CAAC,KAAA,KAAW,QAAQ,OAAQ,EAAA,GAAI,MAAO,CAAA,KAAK,CAAE,CAAA,CAAA;AAAA,KAChE,CAAA,CAAA;AAAA,GACF;AACD,CAAA,CAAA;AApG4D,MAAA,CAAA,OAAA,EAAA,QAAA,CAAA,CAAA;AAArD,IAAM,MAAN,GAAA","file":"Server.mjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';\nimport { Server as HttpServer, createServer as httpCreateServer, type ServerOptions as HttpOptions } from 'node:http';\nimport type { ListenOptions } from 'node:net';\nimport type { MimeType } from '../../utils/MimeType';\nimport { MediaParserStore } from '../MediaParserStore';\nimport { MiddlewareStore } from '../MiddlewareStore';\nimport type { Route } from '../Route';\nimport { RouteStore } from '../RouteStore';\nimport { ApiRequest } from '../api/ApiRequest';\nimport { ApiResponse } from '../api/ApiResponse';\nimport type { RouterBranch } from '../router/RouterBranch';\nimport { Auth, type ServerOptionsAuth } from './Auth';\n\nexport enum ServerEvent {\n\tError = 'error',\n\tRequest = 'request',\n\tRouterBranchNotFound = 'routerBranchNotFound',\n\tRouterBranchMethodNotAllowed = 'routerBranchMethodNotAllowed',\n\tRouterFound = 'routerFound',\n\tRouteError = 'routeError',\n\tMiddlewareFailure = 'middlewareFailure',\n\tMiddlewareError = 'middlewareError',\n\tMiddlewareSuccess = 'middlewareSuccess'\n}\n\nexport interface ServerEvents {\n\t[ServerEvent.Error]: [error: Error, request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.Request]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouterBranchNotFound]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouterBranchMethodNotAllowed]: [request: ApiRequest, response: ApiResponse, node: RouterBranch];\n\t[ServerEvent.RouterFound]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.RouteError]: [error: Error, request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.MiddlewareFailure]: [request: ApiRequest, response: ApiResponse];\n\t[ServerEvent.MiddlewareSuccess]: [request: Route.Request, response: Route.Response, route: Route];\n\t[ServerEvent.MiddlewareError]: [error: Error, request: ApiRequest, response: ApiResponse];\n}\n\n/**\n * @since 1.0.0\n */\nexport class Server extends AsyncEventEmitter<ServerEvents> {\n\t/**\n\t * The routes this server holds.\n\t * @since 1.0.0\n\t */\n\tpublic readonly routes: RouteStore;\n\n\t/**\n\t * The middlewares this server holds.\n\t * @since 1.0.0\n\t */\n\tpublic readonly middlewares: MiddlewareStore;\n\n\t/**\n\t * The media parsers this server holds.\n\t * @since 1.3.0\n\t */\n\tpublic readonly mediaParsers: MediaParserStore;\n\n\t/**\n\t * The authentication system.\n\t * @since 1.0.0\n\t */\n\tpublic readonly auth: Auth | null;\n\n\t/**\n\t * The http.Server instance that manages the recieved HTTP requests.\n\t * @since 1.0.0\n\t */\n\tpublic readonly server: HttpServer;\n\n\t/**\n\t * The options for this server.\n\t * @since 1.0.0\n\t */\n\tpublic readonly options: AuthLessServerOptions;\n\n\t/**\n\t * @since 1.0.0\n\t * @param options The options for this server\n\t */\n\tpublic constructor({ auth, ...options }: ServerOptions = {}) {\n\t\tsuper();\n\n\t\tcontainer.server = this;\n\n\t\tthis.options = options;\n\t\tthis.server = httpCreateServer({\n\t\t\tIncomingMessage: ApiRequest,\n\t\t\tServerResponse: ApiResponse,\n\t\t\t...(options.server ?? {})\n\t\t});\n\t\tthis.routes = new RouteStore();\n\t\tthis.middlewares = new MiddlewareStore();\n\t\tthis.mediaParsers = new MediaParserStore();\n\t\tthis.auth = Auth.create(auth);\n\t\tthis.server.on('error', this.emit.bind(this, ServerEvent.Error));\n\t\tthis.server.on('request', this.emit.bind(this, ServerEvent.Request));\n\t}\n\n\tpublic connect() {\n\t\tconst { server } = this;\n\t\tserver.listen({\n\t\t\tport: 4000,\n\t\t\t...(this.options.listenOptions ?? {})\n\t\t});\n\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tfunction listening() {\n\t\t\t\tcleanup();\n\t\t\t\tresolve();\n\t\t\t}\n\n\t\t\tfunction error(error: Error) {\n\t\t\t\tcleanup();\n\t\t\t\treject(error);\n\t\t\t}\n\n\t\t\tfunction close() {\n\t\t\t\tcleanup();\n\t\t\t\treject(new Error('Closed unexpectedly.'));\n\t\t\t}\n\n\t\t\tfunction cleanup() {\n\t\t\t\tserver.off('listening', listening);\n\t\t\t\tserver.off('error', error);\n\t\t\t\tserver.off('close', close);\n\t\t\t}\n\n\t\t\tserver.on('listening', listening);\n\t\t\tserver.on('error', error);\n\t\t\tserver.on('close', close);\n\t\t});\n\t}\n\n\tpublic disconnect() {\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tthis.server.close((error) => (error ? resolve() : reject(error)));\n\t\t});\n\t}\n}\n\n/**\n * RFC 1341 4: Defines a Content-Type's type, which follows the following structure:\n *\n * - `type` = `text` | `multipart` | `message` | `image` | `audio` | `video` | `application` | x-token\n * - `x-token` = The two characters \"X-\" followed, with no intervening white space, by any token\n * @since 1.3.0\n */\nexport type ContentTypeType = 'text' | 'multipart' | 'message' | 'image' | 'audio' | 'video' | 'application' | `X-${string}`;\n\n/**\n * RFC 1341 4: Defines a Content-Type's parameter, which follows the following structure:\n *\n * - `parameter` = `attribute` \"=\" `value`\n * - `attribute` = `token`\n * - `value` = `token` / `quoted-string`\n * - `token` = `1*<any CHAR except \"SPACE\", \"CTLs\", or \"tspecials\">`\n * - `tspecials` = `(` | `)` | `<` | `>` | `@` | `,` | `;` | `:` | `\\` | `\"` | `/` | `[` | `]` | `?` | `.` | `=`\n *\n * @note `tspecials` must be in quoted-string, to use within parameter values.\n * @note The definition of `tspecials` is the same as the RFC 822 definition of `specials` with the addition of the\n * three characters `/`, `?`, and `=`.\n * @since 1.3.0\n */\nexport type ContentTypeParameter = `; ${string}=${string}`;\n\n/**\n * RFC 1341 4: Defines the syntax for a Content-Type field without parameters, which follows the following structure:\n * `type \"/\" subtype`.\n * @since 7.0.0\n */\nexport type GenericMimeType = `${ContentTypeType}/${string}`;\n\n/**\n * RFC 1341 4: Defines the syntax for a Content-Type field, which follows the following structure:\n * `type \"/\" subtype *[\";\" parameter]`.\n * @since 7.0.0\n */\nexport type GenericParametrizedMimeType = `${GenericMimeType}${'' | ContentTypeParameter}`;\n\n/**\n * The API options.\n * @since 1.0.0\n */\nexport interface ServerOptions {\n\t/**\n\t * The prefix for all routes, e.g. `v1/`.\n\t * @since 1.0.0\n\t * @default ''\n\t */\n\tprefix?: string;\n\n\t/**\n\t * The origin header to be set on every request at 'Access-Control-Allow-Origin'.\n\t * @since 1.0.0\n\t * @default '*'\n\t */\n\torigin?: string;\n\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t * @since 1.0.0\n\t * @default 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The 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 null\n\t */\n\tacceptedContentMimeTypes?: MimeType[] | null;\n\n\t/**\n\t * The HTTP server options.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\tserver?: HttpOptions;\n\n\t/**\n\t * The HTTP listen options.\n\t * @since 1.0.0\n\t * @default { port: 4000 }\n\t */\n\tlistenOptions?: ListenOptions;\n\n\t/**\n\t * The auth options. If neither `auth` nor `auth.secret` are defined, auth-related routes and middlewares will be\n\t * automatically disabled.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\tauth?: ServerOptionsAuth;\n\n\t/**\n\t * Whether the server should connect upon being when the plugin is loaded.\n\t * @since 3.2.0\n\t * @default true\n\t */\n\tautomaticallyConnect?: boolean;\n}\n\n/**\n * The {@link ServerOptions} without {@link ServerOptions.auth}.\n * @since 1.0.0\n */\nexport type AuthLessServerOptions = Omit<ServerOptions, 'auth'>;\n"]}
@@ -31,6 +31,17 @@ var _RouterRoot = class _RouterRoot extends RouterBranch {
31
31
  toString() {
32
32
  return "";
33
33
  }
34
+ static makeRoutePathForPiece(directories, name) {
35
+ const parts = [];
36
+ for (const directory of directories) {
37
+ const trimmed = directory.trim();
38
+ if (isNullishOrEmpty(trimmed)) continue;
39
+ if (trimmed.startsWith("(") && trimmed.endsWith(")")) continue;
40
+ parts.push(trimmed);
41
+ }
42
+ parts.push(name.trim());
43
+ return parts.join("/");
44
+ }
34
45
  static normalize(path) {
35
46
  const parts = [];
36
47
  if (isNullishOrEmpty(path)) return parts;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/lib/structures/router/RouterRoot.ts"],"names":[],"mappings":";;;;AAMO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmB,Y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ACR;AAAA,EAEA,OAAc,cAAc,IAA4C,EAAA;AACvE,IAAI,IAAA,IAAA,CAAK,MAAW,KAAA,CAAA,EAAU,OAAA,IAAA,CAAA;AAE9B,IAAM,MAAA,SAAA,GAAY,KAAK,MAAS,GAAA,CAAA,CAAA;AAChC,IAAM,MAAA,IAAA,GAAO,KAAK,SAAS,CAAA,CAAA;AAC3B,IAAM,MAAA,WAAA,GAAc,IAAK,CAAA,WAAA,CAAY,GAAG,CAAA,CAAA;AACxC,IAAA,IAAI,gBAAgB,CAAM,CAAA,IAAA,WAAA,KAAgB,IAAK,CAAA,MAAA,GAAS,GAAU,OAAA,IAAA,CAAA;AAElE,IAAA,OAAO,IAAK,CAAA,KAAA,CAAM,WAAc,GAAA,CAAC,EAAE,WAAY,EAAA,CAAA;AAAA,GAChD;AACD,CAAA,CAAA;AApE6C,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA,CAAA;AAAtC,IAAM,UAAN,GAAA","file":"RouterRoot.mjs","sourcesContent":["import { isNullishOrEmpty } from '@sapphire/utilities';\nimport type { Route } from '../Route';\nimport type { MethodName } from '../http/HttpMethods';\nimport { RouterBranch } from './RouterBranch';\nimport type { RouterNode } from './RouterNode';\n\nexport class RouterRoot extends RouterBranch {\n\tpublic constructor() {\n\t\tsuper('::ROOT::', false, null);\n\t}\n\n\t/**\n\t * Adds a route to the branch\n\t *\n\t * @param route The route to add\n\t * @returns The node the route was added to\n\t */\n\tpublic add(route: Route): RouterNode {\n\t\treturn this._add(route.path, 0, route);\n\t}\n\n\t/**\n\t * Removes a route from the branch\n\t *\n\t * @param route The route to remove\n\t * @returns Whether or not the route was removed\n\t */\n\tpublic remove(route: Route): boolean {\n\t\treturn this._remove(route.path, 0, route);\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/class-literal-property-style\n\tpublic override get path(): string {\n\t\treturn '';\n\t}\n\n\tpublic override toString(): string {\n\t\treturn '';\n\t}\n\n\tpublic static normalize(path: string | null | undefined): string[] {\n\t\tconst parts = [] as string[];\n\t\tif (isNullishOrEmpty(path)) return parts;\n\n\t\tlet part = '';\n\t\tfor (const char of path) {\n\t\t\tif (char === '/') {\n\t\t\t\tif (part.length) {\n\t\t\t\t\tparts.push(part);\n\t\t\t\t\tpart = '';\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tpart += char;\n\t\t\t}\n\t\t}\n\n\t\tif (part.length) {\n\t\t\tparts.push(part);\n\t\t\tpart = '';\n\t\t}\n\n\t\treturn parts;\n\t}\n\n\tpublic static extractMethod(path: readonly string[]): MethodName | null {\n\t\tif (path.length === 0) return null;\n\n\t\tconst lastIndex = path.length - 1;\n\t\tconst last = path[lastIndex];\n\t\tconst methodIndex = last.lastIndexOf('.');\n\t\tif (methodIndex === -1 || methodIndex === last.length - 1) return null;\n\n\t\treturn last.slice(methodIndex + 1).toUpperCase() as MethodName;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../../src/lib/structures/router/RouterRoot.ts"],"names":[],"mappings":";;;;AAMO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmB,YAAa,CAAA;AAAA,EACrC,WAAc,GAAA;AACpB,IAAM,KAAA,CAAA,UAAA,EAAY,OAAO,IAAI,CAAA,CAAA;AAAA,GAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,IAAI,KAA0B,EAAA;AACpC,IAAA,OAAO,IAAK,CAAA,IAAA,CAAK,KAAM,CAAA,IAAA,EAAM,GAAG,KAAK,CAAA,CAAA;AAAA,GACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,OAAO,KAAuB,EAAA;AACpC,IAAA,OAAO,IAAK,CAAA,OAAA,CAAQ,KAAM,CAAA,IAAA,EAAM,GAAG,KAAK,CAAA,CAAA;AAAA,GACzC;AAAA;AAAA,EAGA,IAAoB,IAAe,GAAA;AAClC,IAAO,OAAA,EAAA,CAAA;AAAA,GACR;AAAA,EAEgB,QAAmB,GAAA;AAClC,IAAO,OAAA,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cAAc,IAA4C,EAAA;AACvE,IAAI,IAAA,IAAA,CAAK,MAAW,KAAA,CAAA,EAAU,OAAA,IAAA,CAAA;AAE9B,IAAM,MAAA,SAAA,GAAY,KAAK,MAAS,GAAA,CAAA,CAAA;AAChC,IAAM,MAAA,IAAA,GAAO,KAAK,SAAS,CAAA,CAAA;AAC3B,IAAM,MAAA,WAAA,GAAc,IAAK,CAAA,WAAA,CAAY,GAAG,CAAA,CAAA;AACxC,IAAA,IAAI,gBAAgB,CAAM,CAAA,IAAA,WAAA,KAAgB,IAAK,CAAA,MAAA,GAAS,GAAU,OAAA,IAAA,CAAA;AAElE,IAAA,OAAO,IAAK,CAAA,KAAA,CAAM,WAAc,GAAA,CAAC,EAAE,WAAY,EAAA,CAAA;AAAA,GAChD;AACD,CAAA,CAAA;AArF6C,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA,CAAA;AAAtC,IAAM,UAAN,GAAA","file":"RouterRoot.mjs","sourcesContent":["import { isNullishOrEmpty } from '@sapphire/utilities';\nimport type { Route } from '../Route';\nimport type { MethodName } from '../http/HttpMethods';\nimport { RouterBranch } from './RouterBranch';\nimport type { RouterNode } from './RouterNode';\n\nexport class RouterRoot extends RouterBranch {\n\tpublic constructor() {\n\t\tsuper('::ROOT::', false, null);\n\t}\n\n\t/**\n\t * Adds a route to the branch\n\t *\n\t * @param route The route to add\n\t * @returns The node the route was added to\n\t */\n\tpublic add(route: Route): RouterNode {\n\t\treturn this._add(route.path, 0, route);\n\t}\n\n\t/**\n\t * Removes a route from the branch\n\t *\n\t * @param route The route to remove\n\t * @returns Whether or not the route was removed\n\t */\n\tpublic remove(route: Route): boolean {\n\t\treturn this._remove(route.path, 0, route);\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/class-literal-property-style\n\tpublic override get path(): string {\n\t\treturn '';\n\t}\n\n\tpublic override toString(): string {\n\t\treturn '';\n\t}\n\n\tpublic static makeRoutePathForPiece(directories: readonly string[], name: string): string {\n\t\tconst parts: string[] = [];\n\t\tfor (const directory of directories) {\n\t\t\tconst trimmed = directory.trim();\n\n\t\t\t// If empty, skip:\n\t\t\tif (isNullishOrEmpty(trimmed)) continue;\n\t\t\t// If it's a group, skip:\n\t\t\tif (trimmed.startsWith('(') && trimmed.endsWith(')')) continue;\n\n\t\t\tparts.push(trimmed);\n\t\t}\n\n\t\tparts.push(name.trim());\n\t\treturn parts.join('/');\n\t}\n\n\tpublic static normalize(path: string | null | undefined): string[] {\n\t\tconst parts = [] as string[];\n\t\tif (isNullishOrEmpty(path)) return parts;\n\n\t\tlet part = '';\n\t\tfor (const char of path) {\n\t\t\tif (char === '/') {\n\t\t\t\tif (part.length) {\n\t\t\t\t\tparts.push(part);\n\t\t\t\t\tpart = '';\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tpart += char;\n\t\t\t}\n\t\t}\n\n\t\tif (part.length) {\n\t\t\tparts.push(part);\n\t\t\tpart = '';\n\t\t}\n\n\t\treturn parts;\n\t}\n\n\tpublic static extractMethod(path: readonly string[]): MethodName | null {\n\t\tif (path.length === 0) return null;\n\n\t\tconst lastIndex = path.length - 1;\n\t\tconst last = path[lastIndex];\n\t\tconst methodIndex = last.lastIndexOf('.');\n\t\tif (methodIndex === -1 || methodIndex === last.length - 1) return null;\n\n\t\treturn last.slice(methodIndex + 1).toUpperCase() as MethodName;\n\t}\n}\n"]}
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=MimeType.mjs.map
3
+ //# sourceMappingURL=MimeType.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"MimeType.mjs"}
@@ -1,11 +1,10 @@
1
1
  import { __name } from '../chunk-S573YWRP.mjs';
2
2
  import { URLSearchParams } from 'url';
3
3
  import { MediaParser } from '../lib/structures/MediaParser.mjs';
4
- import { MimeTypes } from '../lib/utils/MimeTypes.mjs';
5
4
 
6
5
  var _PluginMediaParser = class _PluginMediaParser extends MediaParser {
7
6
  constructor(context) {
8
- super(context, { name: MimeTypes.ApplicationFormUrlEncoded });
7
+ super(context, { name: "application/x-www-form-urlencoded" });
9
8
  }
10
9
  async run(request) {
11
10
  const body = await this.readString(request);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/mediaParsers/applicationFormUrlEncoded.ts"],"names":[],"mappings":";;;;;AAKO,IAAM,kBAAA,GAAN,MAAM,kBAAA,SAA0B,WAAY,CAAA;AAAA,EAC3C,YAAY,OAAoC,EAAA;AACtD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,IAAM,EAAA,SAAA,CAAU,2BAA2B,CAAA,CAAA;AAAA,GAC7D;AAAA,EAEA,MAAsB,IAAI,OAAuC,EAAA;AAChE,IAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,UAAA,CAAW,OAAO,CAAA,CAAA;AAC1C,IAAO,OAAA,IAAA,CAAK,MAAW,KAAA,CAAA,GAAI,IAAO,GAAA,MAAA,CAAO,WAAY,CAAA,IAAI,eAAgB,CAAA,IAAI,CAAE,CAAA,OAAA,EAAS,CAAA,CAAA;AAAA,GACzF;AACD,CAAA,CAAA;AATmD,MAAA,CAAA,kBAAA,EAAA,mBAAA,CAAA,CAAA;AAA5C,IAAM,iBAAN,GAAA","file":"applicationFormUrlEncoded.mjs","sourcesContent":["import { URLSearchParams } from 'url';\nimport { MediaParser } from '../lib/structures/MediaParser';\nimport type { ApiRequest } from '../lib/structures/api/ApiRequest';\nimport { MimeTypes } from '../lib/utils/MimeTypes';\n\nexport class PluginMediaParser extends MediaParser {\n\tpublic constructor(context: MediaParser.LoaderContext) {\n\t\tsuper(context, { name: MimeTypes.ApplicationFormUrlEncoded });\n\t}\n\n\tpublic override async run(request: ApiRequest): Promise<unknown> {\n\t\tconst body = await this.readString(request);\n\t\treturn body.length === 0 ? null : Object.fromEntries(new URLSearchParams(body).entries());\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/mediaParsers/applicationFormUrlEncoded.ts"],"names":[],"mappings":";;;;AAIO,IAAM,kBAAA,GAAN,MAAM,kBAAA,SAA0B,WAAY,CAAA;AAAA,EAC3C,YAAY,OAAoC,EAAA;AACtD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,IAAM,EAAA,mCAAA,EAAwD,CAAA,CAAA;AAAA,GAChF;AAAA,EAEA,MAAsB,IAAI,OAAgD,EAAA;AACzE,IAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,UAAA,CAAW,OAAO,CAAA,CAAA;AAC1C,IAAO,OAAA,IAAA,CAAK,MAAW,KAAA,CAAA,GAAI,IAAO,GAAA,MAAA,CAAO,WAAY,CAAA,IAAI,eAAgB,CAAA,IAAI,CAAE,CAAA,OAAA,EAAS,CAAA,CAAA;AAAA,GACzF;AACD,CAAA,CAAA;AATmD,MAAA,CAAA,kBAAA,EAAA,mBAAA,CAAA,CAAA;AAA5C,IAAM,iBAAN,GAAA","file":"applicationFormUrlEncoded.mjs","sourcesContent":["import { URLSearchParams } from 'url';\nimport { MediaParser } from '../lib/structures/MediaParser';\nimport type { MimeType } from '../lib/utils/MimeType';\n\nexport class PluginMediaParser extends MediaParser {\n\tpublic constructor(context: MediaParser.LoaderContext) {\n\t\tsuper(context, { name: 'application/x-www-form-urlencoded' satisfies MimeType });\n\t}\n\n\tpublic override async run(request: MediaParser.Request): Promise<unknown> {\n\t\tconst body = await this.readString(request);\n\t\treturn body.length === 0 ? null : Object.fromEntries(new URLSearchParams(body).entries());\n\t}\n}\n"]}
@@ -1,10 +1,9 @@
1
1
  import { __name } from '../chunk-S573YWRP.mjs';
2
2
  import { MediaParser } from '../lib/structures/MediaParser.mjs';
3
- import { MimeTypes } from '../lib/utils/MimeTypes.mjs';
4
3
 
5
4
  var _PluginMediaParser = class _PluginMediaParser extends MediaParser {
6
5
  constructor(context) {
7
- super(context, { name: MimeTypes.ApplicationJson });
6
+ super(context, { name: "application/json" });
8
7
  }
9
8
  async run(request) {
10
9
  const body = await this.readString(request);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/mediaParsers/applicationJson.ts"],"names":[],"mappings":";;;;AAGO,IAAM,kBAAA,GAAN,MAAM,kBAAA,SAA0B,WAAY,CAAA;AAAA,EAC3C,YAAY,OAAoC,EAAA;AACtD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,IAAM,EAAA,SAAA,CAAU,iBAAiB,CAAA,CAAA;AAAA,GACnD;AAAA,EAEA,MAAsB,IAAI,OAAgD,EAAA;AACzE,IAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,UAAA,CAAW,OAAO,CAAA,CAAA;AAC1C,IAAA,OAAO,KAAK,MAAW,KAAA,CAAA,GAAI,IAAO,GAAA,IAAA,CAAK,MAAM,IAAI,CAAA,CAAA;AAAA,GAClD;AACD,CAAA,CAAA;AATmD,MAAA,CAAA,kBAAA,EAAA,mBAAA,CAAA,CAAA;AAA5C,IAAM,iBAAN,GAAA","file":"applicationJson.mjs","sourcesContent":["import { MediaParser } from '../lib/structures/MediaParser';\nimport { MimeTypes } from '../lib/utils/MimeTypes';\n\nexport class PluginMediaParser extends MediaParser {\n\tpublic constructor(context: MediaParser.LoaderContext) {\n\t\tsuper(context, { name: MimeTypes.ApplicationJson });\n\t}\n\n\tpublic override async run(request: MediaParser.Request): Promise<unknown> {\n\t\tconst body = await this.readString(request);\n\t\treturn body.length === 0 ? null : JSON.parse(body);\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/mediaParsers/applicationJson.ts"],"names":[],"mappings":";;;AAGO,IAAM,kBAAA,GAAN,MAAM,kBAAA,SAA0B,WAAY,CAAA;AAAA,EAC3C,YAAY,OAAoC,EAAA;AACtD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,IAAM,EAAA,kBAAA,EAAuC,CAAA,CAAA;AAAA,GAC/D;AAAA,EAEA,MAAsB,IAAI,OAAgD,EAAA;AACzE,IAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,UAAA,CAAW,OAAO,CAAA,CAAA;AAC1C,IAAA,OAAO,KAAK,MAAW,KAAA,CAAA,GAAI,IAAO,GAAA,IAAA,CAAK,MAAM,IAAI,CAAA,CAAA;AAAA,GAClD;AACD,CAAA,CAAA;AATmD,MAAA,CAAA,kBAAA,EAAA,mBAAA,CAAA,CAAA;AAA5C,IAAM,iBAAN,GAAA","file":"applicationJson.mjs","sourcesContent":["import { MediaParser } from '../lib/structures/MediaParser';\nimport type { MimeType } from '../lib/utils/MimeType';\n\nexport class PluginMediaParser extends MediaParser {\n\tpublic constructor(context: MediaParser.LoaderContext) {\n\t\tsuper(context, { name: 'application/json' satisfies MimeType });\n\t}\n\n\tpublic override async run(request: MediaParser.Request): Promise<unknown> {\n\t\tconst body = await this.readString(request);\n\t\treturn body.length === 0 ? null : JSON.parse(body);\n\t}\n}\n"]}
@@ -1,10 +1,9 @@
1
1
  import { __name } from '../chunk-S573YWRP.mjs';
2
2
  import { MediaParser } from '../lib/structures/MediaParser.mjs';
3
- import { MimeTypes } from '../lib/utils/MimeTypes.mjs';
4
3
 
5
4
  var _PluginMediaParser = class _PluginMediaParser extends MediaParser {
6
5
  constructor(context) {
7
- super(context, { name: MimeTypes.TextPlain });
6
+ super(context, { name: "text/plain" });
8
7
  }
9
8
  async run(request) {
10
9
  const body = await this.readString(request);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/mediaParsers/textPlain.ts"],"names":[],"mappings":";;;;AAGO,IAAM,kBAAA,GAAN,MAAM,kBAAA,SAA0B,WAAY,CAAA;AAAA,EAC3C,YAAY,OAAoC,EAAA;AACtD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,IAAM,EAAA,SAAA,CAAU,WAAW,CAAA,CAAA;AAAA,GAC7C;AAAA,EAEA,MAAsB,IAAI,OAAgD,EAAA;AACzE,IAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,UAAA,CAAW,OAAO,CAAA,CAAA;AAC1C,IAAO,OAAA,IAAA,CAAK,MAAW,KAAA,CAAA,GAAI,IAAO,GAAA,IAAA,CAAA;AAAA,GACnC;AACD,CAAA,CAAA;AATmD,MAAA,CAAA,kBAAA,EAAA,mBAAA,CAAA,CAAA;AAA5C,IAAM,iBAAN,GAAA","file":"textPlain.mjs","sourcesContent":["import { MediaParser } from '../lib/structures/MediaParser';\nimport { MimeTypes } from '../lib/utils/MimeTypes';\n\nexport class PluginMediaParser extends MediaParser {\n\tpublic constructor(context: MediaParser.LoaderContext) {\n\t\tsuper(context, { name: MimeTypes.TextPlain });\n\t}\n\n\tpublic override async run(request: MediaParser.Request): Promise<unknown> {\n\t\tconst body = await this.readString(request);\n\t\treturn body.length === 0 ? null : body;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/mediaParsers/textPlain.ts"],"names":[],"mappings":";;;AAGO,IAAM,kBAAA,GAAN,MAAM,kBAAA,SAA0B,WAAY,CAAA;AAAA,EAC3C,YAAY,OAAoC,EAAA;AACtD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,IAAM,EAAA,YAAA,EAAiC,CAAA,CAAA;AAAA,GACzD;AAAA,EAEA,MAAsB,IAAI,OAAgD,EAAA;AACzE,IAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,UAAA,CAAW,OAAO,CAAA,CAAA;AAC1C,IAAO,OAAA,IAAA,CAAK,MAAW,KAAA,CAAA,GAAI,IAAO,GAAA,IAAA,CAAA;AAAA,GACnC;AACD,CAAA,CAAA;AATmD,MAAA,CAAA,kBAAA,EAAA,mBAAA,CAAA,CAAA;AAA5C,IAAM,iBAAN,GAAA","file":"textPlain.mjs","sourcesContent":["import { MediaParser } from '../lib/structures/MediaParser';\nimport type { MimeType } from '../lib/utils/MimeType';\n\nexport class PluginMediaParser extends MediaParser {\n\tpublic constructor(context: MediaParser.LoaderContext) {\n\t\tsuper(context, { name: 'text/plain' satisfies MimeType });\n\t}\n\n\tpublic override async run(request: MediaParser.Request): Promise<unknown> {\n\t\tconst body = await this.readString(request);\n\t\treturn body.length === 0 ? null : body;\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire/plugin-api",
3
- "version": "7.0.0-next.7829696",
3
+ "version": "7.0.0-next.7ba75bc",
4
4
  "description": "Plugin for @sapphire/framework to expose a REST API",
5
5
  "author": "@sapphire",
6
6
  "license": "MIT",
@@ -43,6 +43,7 @@
43
43
  "build:types:esm": "rollup-type-bundler -d dist/esm -t .mts",
44
44
  "build:types:cleanup": "tsx ../../scripts/clean-register-imports.mts",
45
45
  "build:rename-cjs-register": "tsx ../../scripts/rename-cjs-register.mts",
46
+ "sync-mime-types": "tsx scripts/sync-mime-types.mts",
46
47
  "typecheck": "tsc -b src",
47
48
  "docs": "typedoc-json-parser",
48
49
  "prepack": "yarn build",
@@ -50,10 +51,10 @@
50
51
  "check-update": "cliff-jumper --dry-run"
51
52
  },
52
53
  "dependencies": {
53
- "@types/ws": "^8.5.11",
54
- "@vladfrangu/async_event_emitter": "2.4.4",
55
- "tldts": "^6.1.35",
56
- "undici": "^6.19.4"
54
+ "@types/ws": "^8.5.12",
55
+ "@vladfrangu/async_event_emitter": "2.4.6",
56
+ "tldts": "^6.1.41",
57
+ "undici": "^6.19.8"
57
58
  },
58
59
  "repository": {
59
60
  "type": "git",
@@ -84,11 +85,11 @@
84
85
  "access": "public"
85
86
  },
86
87
  "devDependencies": {
87
- "@favware/cliff-jumper": "^4.0.3",
88
+ "@favware/cliff-jumper": "^4.1.0",
88
89
  "@favware/rollup-type-bundler": "^3.3.0",
89
90
  "concurrently": "^8.2.2",
90
- "tsup": "^8.2.3",
91
- "tsx": "^4.16.2",
91
+ "tsup": "^8.2.4",
92
+ "tsx": "^4.18.0",
92
93
  "typedoc": "^0.25.13",
93
94
  "typedoc-json-parser": "^10.0.0",
94
95
  "typescript": "~5.4.5"
@@ -1,26 +0,0 @@
1
- 'use strict';
2
-
3
- // src/lib/utils/MimeTypes.ts
4
- var MimeTypes = /* @__PURE__ */ ((MimeTypes2) => {
5
- MimeTypes2["ApplicationFormUrlEncoded"] = "application/x-www-form-urlencoded";
6
- MimeTypes2["ApplicationJson"] = "application/json";
7
- MimeTypes2["AudioOgg"] = "audio/ogg";
8
- MimeTypes2["AudioOpus"] = "audio/opus";
9
- MimeTypes2["AudioWebm"] = "audio/webm";
10
- MimeTypes2["ImageGif"] = "image/gif";
11
- MimeTypes2["ImageJpg"] = "image/jpeg";
12
- MimeTypes2["ImagePng"] = "image/png";
13
- MimeTypes2["ImageWebp"] = "image/webp";
14
- MimeTypes2["ImageXIcon"] = "image/x-icon";
15
- MimeTypes2["TextPlain"] = "text/plain";
16
- MimeTypes2["TextHtml"] = "text/html";
17
- MimeTypes2["VideoMp4"] = "video/mp4";
18
- MimeTypes2["VideoMpeg"] = "video/mpeg";
19
- MimeTypes2["VideoOgg"] = "video/ogg";
20
- MimeTypes2["VideoWebm"] = "video/webm";
21
- return MimeTypes2;
22
- })(MimeTypes || {});
23
-
24
- exports.MimeTypes = MimeTypes;
25
- //# sourceMappingURL=MimeTypes.cjs.map
26
- //# sourceMappingURL=MimeTypes.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/lib/utils/MimeTypes.ts"],"names":["MimeTypes"],"mappings":";;;AAAY,IAAA,SAAA,qBAAAA,UAAL,KAAA;AACN,EAAAA,WAAA,2BAA4B,CAAA,GAAA,mCAAA,CAAA;AAC5B,EAAAA,WAAA,iBAAkB,CAAA,GAAA,kBAAA,CAAA;AAClB,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,UAAW,CAAA,GAAA,YAAA,CAAA;AACX,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,YAAa,CAAA,GAAA,cAAA,CAAA;AACb,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AAhBD,EAAAA,OAAAA,UAAAA,CAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA","file":"MimeTypes.cjs","sourcesContent":["export enum MimeTypes {\n\tApplicationFormUrlEncoded = 'application/x-www-form-urlencoded',\n\tApplicationJson = 'application/json',\n\tAudioOgg = 'audio/ogg',\n\tAudioOpus = 'audio/opus',\n\tAudioWebm = 'audio/webm',\n\tImageGif = 'image/gif',\n\tImageJpg = 'image/jpeg',\n\tImagePng = 'image/png',\n\tImageWebp = 'image/webp',\n\tImageXIcon = 'image/x-icon',\n\tTextPlain = 'text/plain',\n\tTextHtml = 'text/html',\n\tVideoMp4 = 'video/mp4',\n\tVideoMpeg = 'video/mpeg',\n\tVideoOgg = 'video/ogg',\n\tVideoWebm = 'video/webm'\n}\n"]}
@@ -1,26 +0,0 @@
1
- import '../../chunk-S573YWRP.mjs';
2
-
3
- // src/lib/utils/MimeTypes.ts
4
- var MimeTypes = /* @__PURE__ */ ((MimeTypes2) => {
5
- MimeTypes2["ApplicationFormUrlEncoded"] = "application/x-www-form-urlencoded";
6
- MimeTypes2["ApplicationJson"] = "application/json";
7
- MimeTypes2["AudioOgg"] = "audio/ogg";
8
- MimeTypes2["AudioOpus"] = "audio/opus";
9
- MimeTypes2["AudioWebm"] = "audio/webm";
10
- MimeTypes2["ImageGif"] = "image/gif";
11
- MimeTypes2["ImageJpg"] = "image/jpeg";
12
- MimeTypes2["ImagePng"] = "image/png";
13
- MimeTypes2["ImageWebp"] = "image/webp";
14
- MimeTypes2["ImageXIcon"] = "image/x-icon";
15
- MimeTypes2["TextPlain"] = "text/plain";
16
- MimeTypes2["TextHtml"] = "text/html";
17
- MimeTypes2["VideoMp4"] = "video/mp4";
18
- MimeTypes2["VideoMpeg"] = "video/mpeg";
19
- MimeTypes2["VideoOgg"] = "video/ogg";
20
- MimeTypes2["VideoWebm"] = "video/webm";
21
- return MimeTypes2;
22
- })(MimeTypes || {});
23
-
24
- export { MimeTypes };
25
- //# sourceMappingURL=MimeTypes.mjs.map
26
- //# sourceMappingURL=MimeTypes.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/lib/utils/MimeTypes.ts"],"names":["MimeTypes"],"mappings":";;;AAAY,IAAA,SAAA,qBAAAA,UAAL,KAAA;AACN,EAAAA,WAAA,2BAA4B,CAAA,GAAA,mCAAA,CAAA;AAC5B,EAAAA,WAAA,iBAAkB,CAAA,GAAA,kBAAA,CAAA;AAClB,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,UAAW,CAAA,GAAA,YAAA,CAAA;AACX,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,YAAa,CAAA,GAAA,cAAA,CAAA;AACb,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AACZ,EAAAA,WAAA,UAAW,CAAA,GAAA,WAAA,CAAA;AACX,EAAAA,WAAA,WAAY,CAAA,GAAA,YAAA,CAAA;AAhBD,EAAAA,OAAAA,UAAAA,CAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA","file":"MimeTypes.mjs","sourcesContent":["export enum MimeTypes {\n\tApplicationFormUrlEncoded = 'application/x-www-form-urlencoded',\n\tApplicationJson = 'application/json',\n\tAudioOgg = 'audio/ogg',\n\tAudioOpus = 'audio/opus',\n\tAudioWebm = 'audio/webm',\n\tImageGif = 'image/gif',\n\tImageJpg = 'image/jpeg',\n\tImagePng = 'image/png',\n\tImageWebp = 'image/webp',\n\tImageXIcon = 'image/x-icon',\n\tTextPlain = 'text/plain',\n\tTextHtml = 'text/html',\n\tVideoMp4 = 'video/mp4',\n\tVideoMpeg = 'video/mpeg',\n\tVideoOgg = 'video/ogg',\n\tVideoWebm = 'video/webm'\n}\n"]}