@sapphire/plugin-api 7.0.0-next.d27dc1c → 7.0.0-next.e30dbc1

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 (188) hide show
  1. package/README.md +0 -1
  2. package/dist/cjs/index.cjs +17 -10
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/index.d.cts +264 -156
  5. package/dist/cjs/lib/structures/Augmentations.d.cjs +1 -1
  6. package/dist/cjs/lib/structures/Augmentations.d.cjs.map +1 -1
  7. package/dist/cjs/lib/structures/MediaParser.cjs +1 -1
  8. package/dist/cjs/lib/structures/MediaParser.cjs.map +1 -1
  9. package/dist/cjs/lib/structures/MediaParserStore.cjs +1 -1
  10. package/dist/cjs/lib/structures/MediaParserStore.cjs.map +1 -1
  11. package/dist/cjs/lib/structures/Middleware.cjs +2 -2
  12. package/dist/cjs/lib/structures/Middleware.cjs.map +1 -1
  13. package/dist/cjs/lib/structures/MiddlewareStore.cjs +4 -4
  14. package/dist/cjs/lib/structures/MiddlewareStore.cjs.map +1 -1
  15. package/dist/cjs/lib/structures/Route.cjs +18 -35
  16. package/dist/cjs/lib/structures/Route.cjs.map +1 -1
  17. package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs +20 -0
  18. package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs.map +1 -0
  19. package/dist/cjs/lib/structures/RouteStore.cjs +6 -44
  20. package/dist/cjs/lib/structures/RouteStore.cjs.map +1 -1
  21. package/dist/cjs/lib/structures/api/ApiRequest.cjs +27 -1
  22. package/dist/cjs/lib/structures/api/ApiRequest.cjs.map +1 -1
  23. package/dist/cjs/lib/structures/api/ApiResponse.cjs +12 -7
  24. package/dist/cjs/lib/structures/api/ApiResponse.cjs.map +1 -1
  25. package/dist/cjs/lib/structures/api/CookieStore.cjs +4 -4
  26. package/dist/cjs/lib/structures/api/CookieStore.cjs.map +1 -1
  27. package/dist/cjs/lib/structures/http/Auth.cjs +2 -2
  28. package/dist/cjs/lib/structures/http/Auth.cjs.map +1 -1
  29. package/dist/cjs/lib/structures/http/HttpCodes.cjs +1 -1
  30. package/dist/cjs/lib/structures/http/HttpCodes.cjs.map +1 -1
  31. package/dist/cjs/lib/structures/http/HttpMethods.cjs +38 -7
  32. package/dist/cjs/lib/structures/http/HttpMethods.cjs.map +1 -1
  33. package/dist/cjs/lib/structures/http/Server.cjs +16 -15
  34. package/dist/cjs/lib/structures/http/Server.cjs.map +1 -1
  35. package/dist/cjs/lib/structures/router/RouterBranch.cjs +184 -0
  36. package/dist/cjs/lib/structures/router/RouterBranch.cjs.map +1 -0
  37. package/dist/cjs/lib/structures/router/RouterNode.cjs +67 -0
  38. package/dist/cjs/lib/structures/router/RouterNode.cjs.map +1 -0
  39. package/dist/cjs/lib/structures/router/RouterRoot.cjs +71 -0
  40. package/dist/cjs/lib/structures/router/RouterRoot.cjs.map +1 -0
  41. package/dist/cjs/lib/utils/MimeType.cjs +4 -0
  42. package/dist/cjs/lib/utils/MimeType.cjs.map +1 -0
  43. package/dist/cjs/listeners/PluginRouteError.cjs +3 -3
  44. package/dist/cjs/listeners/PluginRouteError.cjs.map +1 -1
  45. package/dist/cjs/listeners/PluginServerMiddlewareError.cjs +3 -3
  46. package/dist/cjs/listeners/PluginServerMiddlewareError.cjs.map +1 -1
  47. package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs +5 -5
  48. package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs.map +1 -1
  49. package/dist/cjs/listeners/PluginServerRequest.cjs +42 -8
  50. package/dist/cjs/listeners/PluginServerRequest.cjs.map +1 -1
  51. package/dist/cjs/listeners/{PluginServerMatch.cjs → PluginServerRouterBranchMethodNotAllowed.cjs} +5 -10
  52. package/dist/cjs/listeners/PluginServerRouterBranchMethodNotAllowed.cjs.map +1 -0
  53. package/dist/cjs/listeners/{PluginServerNoMatch.cjs → PluginServerRouterBranchNotFound.cjs} +3 -3
  54. package/dist/cjs/listeners/PluginServerRouterBranchNotFound.cjs.map +1 -0
  55. package/dist/cjs/listeners/PluginServerRouterFound.cjs +22 -0
  56. package/dist/cjs/listeners/PluginServerRouterFound.cjs.map +1 -0
  57. package/dist/cjs/listeners/_load.cjs +7 -5
  58. package/dist/cjs/listeners/_load.cjs.map +1 -1
  59. package/dist/cjs/mediaParsers/_load.cjs +1 -1
  60. package/dist/cjs/mediaParsers/_load.cjs.map +1 -1
  61. package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs +2 -3
  62. package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs.map +1 -1
  63. package/dist/cjs/mediaParsers/applicationJson.cjs +2 -3
  64. package/dist/cjs/mediaParsers/applicationJson.cjs.map +1 -1
  65. package/dist/cjs/mediaParsers/textPlain.cjs +2 -3
  66. package/dist/cjs/mediaParsers/textPlain.cjs.map +1 -1
  67. package/dist/cjs/middlewares/_load.cjs +1 -1
  68. package/dist/cjs/middlewares/_load.cjs.map +1 -1
  69. package/dist/cjs/middlewares/auth.cjs +2 -2
  70. package/dist/cjs/middlewares/auth.cjs.map +1 -1
  71. package/dist/cjs/middlewares/body.cjs +6 -5
  72. package/dist/cjs/middlewares/body.cjs.map +1 -1
  73. package/dist/cjs/middlewares/cookies.cjs +1 -1
  74. package/dist/cjs/middlewares/cookies.cjs.map +1 -1
  75. package/dist/cjs/middlewares/headers.cjs +19 -9
  76. package/dist/cjs/middlewares/headers.cjs.map +1 -1
  77. package/dist/cjs/register.cjs +1 -1
  78. package/dist/cjs/register.cjs.map +1 -1
  79. package/dist/cjs/routes/_load.cjs +5 -5
  80. package/dist/cjs/routes/_load.cjs.map +1 -1
  81. package/dist/cjs/routes/oauth/{callback.cjs → callback.post.cjs} +5 -6
  82. package/dist/cjs/routes/oauth/callback.post.cjs.map +1 -0
  83. package/dist/cjs/routes/oauth/{logout.cjs → logout.post.cjs} +6 -8
  84. package/dist/cjs/routes/oauth/logout.post.cjs.map +1 -0
  85. package/dist/esm/{chunk-JTFKMR4I.mjs → chunk-S573YWRP.mjs} +4 -3
  86. package/dist/esm/chunk-S573YWRP.mjs.map +1 -0
  87. package/dist/esm/index.d.mts +264 -156
  88. package/dist/esm/index.mjs +6 -5
  89. package/dist/esm/index.mjs.map +1 -1
  90. package/dist/esm/lib/structures/Augmentations.d.mjs +1 -1
  91. package/dist/esm/lib/structures/Augmentations.d.mjs.map +1 -1
  92. package/dist/esm/lib/structures/MediaParser.mjs +2 -2
  93. package/dist/esm/lib/structures/MediaParser.mjs.map +1 -1
  94. package/dist/esm/lib/structures/MediaParserStore.mjs +2 -2
  95. package/dist/esm/lib/structures/MediaParserStore.mjs.map +1 -1
  96. package/dist/esm/lib/structures/Middleware.mjs +2 -2
  97. package/dist/esm/lib/structures/Middleware.mjs.map +1 -1
  98. package/dist/esm/lib/structures/MiddlewareStore.mjs +4 -4
  99. package/dist/esm/lib/structures/MiddlewareStore.mjs.map +1 -1
  100. package/dist/esm/lib/structures/Route.mjs +19 -36
  101. package/dist/esm/lib/structures/Route.mjs.map +1 -1
  102. package/dist/esm/lib/structures/RouteLoaderStrategy.mjs +17 -0
  103. package/dist/esm/lib/structures/RouteLoaderStrategy.mjs.map +1 -0
  104. package/dist/esm/lib/structures/RouteStore.mjs +6 -44
  105. package/dist/esm/lib/structures/RouteStore.mjs.map +1 -1
  106. package/dist/esm/lib/structures/api/ApiRequest.mjs +28 -2
  107. package/dist/esm/lib/structures/api/ApiRequest.mjs.map +1 -1
  108. package/dist/esm/lib/structures/api/ApiResponse.mjs +12 -7
  109. package/dist/esm/lib/structures/api/ApiResponse.mjs.map +1 -1
  110. package/dist/esm/lib/structures/api/CookieStore.mjs +5 -5
  111. package/dist/esm/lib/structures/api/CookieStore.mjs.map +1 -1
  112. package/dist/esm/lib/structures/http/Auth.mjs +2 -2
  113. package/dist/esm/lib/structures/http/Auth.mjs.map +1 -1
  114. package/dist/esm/lib/structures/http/HttpCodes.mjs +2 -2
  115. package/dist/esm/lib/structures/http/HttpCodes.mjs.map +1 -1
  116. package/dist/esm/lib/structures/http/HttpMethods.mjs +40 -6
  117. package/dist/esm/lib/structures/http/HttpMethods.mjs.map +1 -1
  118. package/dist/esm/lib/structures/http/Server.mjs +17 -16
  119. package/dist/esm/lib/structures/http/Server.mjs.map +1 -1
  120. package/dist/esm/lib/structures/router/RouterBranch.mjs +179 -0
  121. package/dist/esm/lib/structures/router/RouterBranch.mjs.map +1 -0
  122. package/dist/esm/lib/structures/router/RouterNode.mjs +56 -0
  123. package/dist/esm/lib/structures/router/RouterNode.mjs.map +1 -0
  124. package/dist/esm/lib/structures/router/RouterRoot.mjs +68 -0
  125. package/dist/esm/lib/structures/router/RouterRoot.mjs.map +1 -0
  126. package/dist/esm/lib/utils/MimeType.mjs +3 -0
  127. package/dist/esm/lib/utils/MimeType.mjs.map +1 -0
  128. package/dist/esm/listeners/PluginRouteError.mjs +5 -5
  129. package/dist/esm/listeners/PluginRouteError.mjs.map +1 -1
  130. package/dist/esm/listeners/PluginServerMiddlewareError.mjs +5 -5
  131. package/dist/esm/listeners/PluginServerMiddlewareError.mjs.map +1 -1
  132. package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs +7 -7
  133. package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs.map +1 -1
  134. package/dist/esm/listeners/PluginServerRequest.mjs +38 -10
  135. package/dist/esm/listeners/PluginServerRequest.mjs.map +1 -1
  136. package/dist/esm/listeners/PluginServerRouterBranchMethodNotAllowed.mjs +18 -0
  137. package/dist/esm/listeners/PluginServerRouterBranchMethodNotAllowed.mjs.map +1 -0
  138. package/dist/esm/listeners/{PluginServerNoMatch.mjs → PluginServerRouterBranchNotFound.mjs} +5 -5
  139. package/dist/esm/listeners/PluginServerRouterBranchNotFound.mjs.map +1 -0
  140. package/dist/esm/listeners/PluginServerRouterFound.mjs +19 -0
  141. package/dist/esm/listeners/PluginServerRouterFound.mjs.map +1 -0
  142. package/dist/esm/listeners/_load.mjs +14 -12
  143. package/dist/esm/listeners/_load.mjs.map +1 -1
  144. package/dist/esm/mediaParsers/_load.mjs +2 -2
  145. package/dist/esm/mediaParsers/_load.mjs.map +1 -1
  146. package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs +3 -4
  147. package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs.map +1 -1
  148. package/dist/esm/mediaParsers/applicationJson.mjs +3 -4
  149. package/dist/esm/mediaParsers/applicationJson.mjs.map +1 -1
  150. package/dist/esm/mediaParsers/textPlain.mjs +3 -4
  151. package/dist/esm/mediaParsers/textPlain.mjs.map +1 -1
  152. package/dist/esm/middlewares/_load.mjs +2 -2
  153. package/dist/esm/middlewares/_load.mjs.map +1 -1
  154. package/dist/esm/middlewares/auth.mjs +2 -2
  155. package/dist/esm/middlewares/auth.mjs.map +1 -1
  156. package/dist/esm/middlewares/body.mjs +6 -5
  157. package/dist/esm/middlewares/body.mjs.map +1 -1
  158. package/dist/esm/middlewares/cookies.mjs +2 -2
  159. package/dist/esm/middlewares/cookies.mjs.map +1 -1
  160. package/dist/esm/middlewares/headers.mjs +20 -10
  161. package/dist/esm/middlewares/headers.mjs.map +1 -1
  162. package/dist/esm/register.mjs +2 -2
  163. package/dist/esm/register.mjs.map +1 -1
  164. package/dist/esm/routes/_load.mjs +4 -4
  165. package/dist/esm/routes/_load.mjs.map +1 -1
  166. package/dist/esm/routes/oauth/{callback.mjs → callback.post.mjs} +5 -6
  167. package/dist/esm/routes/oauth/callback.post.mjs.map +1 -0
  168. package/dist/esm/routes/oauth/{logout.mjs → logout.post.mjs} +6 -8
  169. package/dist/esm/routes/oauth/logout.post.mjs.map +1 -0
  170. package/package.json +9 -7
  171. package/dist/cjs/lib/utils/MimeTypes.cjs +0 -26
  172. package/dist/cjs/lib/utils/MimeTypes.cjs.map +0 -1
  173. package/dist/cjs/lib/utils/RouteData.cjs +0 -62
  174. package/dist/cjs/lib/utils/RouteData.cjs.map +0 -1
  175. package/dist/cjs/listeners/PluginServerMatch.cjs.map +0 -1
  176. package/dist/cjs/listeners/PluginServerNoMatch.cjs.map +0 -1
  177. package/dist/cjs/routes/oauth/callback.cjs.map +0 -1
  178. package/dist/cjs/routes/oauth/logout.cjs.map +0 -1
  179. package/dist/esm/chunk-JTFKMR4I.mjs.map +0 -1
  180. package/dist/esm/lib/utils/MimeTypes.mjs +0 -26
  181. package/dist/esm/lib/utils/MimeTypes.mjs.map +0 -1
  182. package/dist/esm/lib/utils/RouteData.mjs +0 -56
  183. package/dist/esm/lib/utils/RouteData.mjs.map +0 -1
  184. package/dist/esm/listeners/PluginServerMatch.mjs +0 -23
  185. package/dist/esm/listeners/PluginServerMatch.mjs.map +0 -1
  186. package/dist/esm/listeners/PluginServerNoMatch.mjs.map +0 -1
  187. package/dist/esm/routes/oauth/callback.mjs.map +0 -1
  188. package/dist/esm/routes/oauth/logout.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import './chunk-JTFKMR4I.mjs';
1
+ import './chunk-S573YWRP.mjs';
2
2
  export * from './lib/structures/api/ApiRequest.mjs';
3
3
  export * from './lib/structures/api/ApiResponse.mjs';
4
4
  export * from './lib/structures/api/CookieStore.mjs';
@@ -11,16 +11,17 @@ export * from './lib/structures/MediaParserStore.mjs';
11
11
  export * from './lib/structures/Middleware.mjs';
12
12
  export * from './lib/structures/MiddlewareStore.mjs';
13
13
  export * from './lib/structures/Route.mjs';
14
+ export * from './lib/structures/router/RouterBranch.mjs';
15
+ export * from './lib/structures/router/RouterNode.mjs';
16
+ export * from './lib/structures/router/RouterRoot.mjs';
14
17
  export * from './lib/structures/RouteStore.mjs';
15
- export * from './lib/utils/MimeTypes.mjs';
16
- export * from './lib/utils/RouteData.mjs';
17
18
  export { loadListeners } from './listeners/_load.mjs';
18
19
  export { loadMediaParsers } from './mediaParsers/_load.mjs';
19
20
  export { loadMiddlewares } from './middlewares/_load.mjs';
20
21
  export { loadRoutes } from './routes/_load.mjs';
21
22
 
22
- var version = "7.0.0-next.d27dc1c";
23
+ var version = "7.0.0-next.e30dbc1";
23
24
 
24
25
  export { version };
25
- //# sourceMappingURL=out.js.map
26
+ //# sourceMappingURL=index.mjs.map
26
27
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;AAKA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AA+BpB,IAAM,UAAkB","sourcesContent":["import type { Server, ServerOptions } from './lib/structures/http/Server';\nimport type { MediaParserStore } from './lib/structures/MediaParserStore';\nimport type { MiddlewareStore } from './lib/structures/MiddlewareStore';\nimport type { RouteStore } from './lib/structures/RouteStore';\n\nexport * from './lib/structures/api/ApiRequest';\nexport * from './lib/structures/api/ApiResponse';\nexport * from './lib/structures/api/CookieStore';\nexport * from './lib/structures/http/Auth';\nexport * from './lib/structures/http/HttpCodes';\nexport * from './lib/structures/http/HttpMethods';\nexport * from './lib/structures/http/Server';\nexport * from './lib/structures/MediaParser';\nexport * from './lib/structures/MediaParserStore';\nexport * from './lib/structures/Middleware';\nexport * from './lib/structures/MiddlewareStore';\nexport * from './lib/structures/Route';\nexport * from './lib/structures/RouteStore';\nexport * from './lib/utils/MimeTypes';\nexport * from './lib/utils/RouteData';\n\nexport { loadListeners } from './listeners/_load';\nexport { loadMediaParsers } from './mediaParsers/_load';\nexport { loadMiddlewares } from './middlewares/_load';\nexport { loadRoutes } from './routes/_load';\n\ndeclare module 'discord.js' {\n\tinterface Client {\n\t\tserver: Server;\n\t}\n\n\tinterface ClientOptions {\n\t\tapi?: ServerOptions;\n\t}\n}\n\ndeclare module '@sapphire/pieces' {\n\tinterface StoreRegistryEntries {\n\t\troutes: RouteStore;\n\t\tmediaParsers: MediaParserStore;\n\t\tmiddlewares: MiddlewareStore;\n\t}\n\n\tinterface Container {\n\t\tserver: Server;\n\t}\n}\n\n/**\n * The [@sapphire/plugin-api](https://github.com/sapphiredev/plugins/blob/main/packages/api) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '7.0.0-next.d27dc1c';\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyDO,IAAM,OAAkB,GAAA","file":"index.mjs","sourcesContent":["import type { Server, ServerOptions } from './lib/structures/http/Server';\nimport type { MediaParserStore } from './lib/structures/MediaParserStore';\nimport type { MiddlewareStore } from './lib/structures/MiddlewareStore';\nimport type { RouteStore } from './lib/structures/RouteStore';\n\nexport * from './lib/structures/api/ApiRequest';\nexport * from './lib/structures/api/ApiResponse';\nexport * from './lib/structures/api/CookieStore';\nexport * from './lib/structures/http/Auth';\nexport * from './lib/structures/http/HttpCodes';\nexport * from './lib/structures/http/HttpMethods';\nexport * from './lib/structures/http/Server';\nexport * from './lib/structures/MediaParser';\nexport * from './lib/structures/MediaParserStore';\nexport * from './lib/structures/Middleware';\nexport * from './lib/structures/MiddlewareStore';\nexport * from './lib/structures/Route';\nexport * from './lib/structures/router/RouterBranch';\nexport * from './lib/structures/router/RouterNode';\nexport * from './lib/structures/router/RouterRoot';\nexport * from './lib/structures/RouteStore';\nexport type * from './lib/utils/MimeType';\n\nexport { loadListeners } from './listeners/_load';\nexport { loadMediaParsers } from './mediaParsers/_load';\nexport { loadMiddlewares } from './middlewares/_load';\nexport { loadRoutes } from './routes/_load';\n\ndeclare module 'discord.js' {\n\tinterface Client {\n\t\tserver: Server;\n\t}\n\n\tinterface ClientOptions {\n\t\tapi?: ServerOptions;\n\t}\n}\n\ndeclare module '@sapphire/pieces' {\n\tinterface StoreRegistryEntries {\n\t\troutes: RouteStore;\n\t\tmediaParsers: MediaParserStore;\n\t\tmiddlewares: MiddlewareStore;\n\t}\n\n\tinterface Container {\n\t\tserver: Server;\n\t}\n}\n\n/**\n * The [@sapphire/plugin-api](https://github.com/sapphiredev/plugins/blob/main/packages/api) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '7.0.0-next.e30dbc1';\n"]}
@@ -1,3 +1,3 @@
1
1
 
2
- //# sourceMappingURL=out.js.map
2
+ //# sourceMappingURL=Augmentations.d.mjs.map
3
3
  //# sourceMappingURL=Augmentations.d.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"Augmentations.d.mjs"}
@@ -1,4 +1,4 @@
1
- import { __name } from '../../chunk-JTFKMR4I.mjs';
1
+ import { __name } from '../../chunk-S573YWRP.mjs';
2
2
  import { Piece } from '@sapphire/pieces';
3
3
  import { createBrotliDecompress, createGunzip, createInflate } from 'zlib';
4
4
 
@@ -72,5 +72,5 @@ __name(_MediaParser, "MediaParser");
72
72
  var MediaParser = _MediaParser;
73
73
 
74
74
  export { MediaParser };
75
- //# sourceMappingURL=out.js.map
75
+ //# sourceMappingURL=MediaParser.mjs.map
76
76
  //# sourceMappingURL=MediaParser.mjs.map
@@ -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,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
+ {"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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AMA,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"]}
@@ -1,4 +1,4 @@
1
- import { __name } from '../../chunk-JTFKMR4I.mjs';
1
+ import { __name } from '../../chunk-S573YWRP.mjs';
2
2
  import { Store } from '@sapphire/pieces';
3
3
  import { MediaParser } from './MediaParser.mjs';
4
4
 
@@ -20,5 +20,5 @@ __name(_MediaParserStore, "MediaParserStore");
20
20
  var MediaParserStore = _MediaParserStore;
21
21
 
22
22
  export { MediaParserStore };
23
- //# sourceMappingURL=out.js.map
23
+ //# sourceMappingURL=MediaParserStore.mjs.map
24
24
  //# sourceMappingURL=MediaParserStore.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/MediaParserStore.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAKrB,IAAM,oBAAN,MAAM,0BAAyB,MAAmC;AAAA,EACjE,cAAc;AACpB,UAAM,aAAa,EAAE,MAAM,eAAe,CAAC;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,iBAAiB,aAA6B;AACpD,UAAM,QAAQ,YAAY,QAAQ,GAAG;AACrC,WAAO,UAAU,KAAK,cAAc,YAAY,MAAM,GAAG,KAAK;AAAA,EAC/D;AACD;AAdyE;AAAlE,IAAM,mBAAN","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { MediaParser } from './MediaParser';\n\n/**\n * @since 1.3.0\n */\nexport class MediaParserStore extends Store<MediaParser, 'mediaParsers'> {\n\tpublic constructor() {\n\t\tsuper(MediaParser, { name: 'mediaParsers' });\n\t}\n\n\t/**\n\t * Parses a content type by getting the relevant information inside.\n\t * @since 1.3.0\n\t * @param contentType The content type to parse.\n\t */\n\tpublic parseContentType(contentType: string): string {\n\t\tconst index = contentType.indexOf(';');\n\t\treturn index === -1 ? contentType : contentType.slice(0, index);\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/MediaParserStore.ts"],"names":[],"mappings":";;;;AAMO,IAAM,iBAAA,GAAN,MAAM,iBAAA,SAAyB,KAAmC,CAAA;AAAA,EACjE,WAAc,GAAA;AACpB,IAAA,KAAA,CAAM,WAAa,EAAA,EAAE,IAAM,EAAA,cAAA,EAAgB,CAAA,CAAA;AAAA,GAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,iBAAiB,WAA6B,EAAA;AACpD,IAAM,MAAA,KAAA,GAAQ,WAAY,CAAA,OAAA,CAAQ,GAAG,CAAA,CAAA;AACrC,IAAA,OAAO,UAAU,CAAK,CAAA,GAAA,WAAA,GAAc,WAAY,CAAA,KAAA,CAAM,GAAG,KAAK,CAAA,CAAA;AAAA,GAC/D;AACD,CAAA,CAAA;AAdyE,MAAA,CAAA,iBAAA,EAAA,kBAAA,CAAA,CAAA;AAAlE,IAAM,gBAAN,GAAA","file":"MediaParserStore.mjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { MediaParser } from './MediaParser';\n\n/**\n * @since 1.3.0\n */\nexport class MediaParserStore extends Store<MediaParser, 'mediaParsers'> {\n\tpublic constructor() {\n\t\tsuper(MediaParser, { name: 'mediaParsers' });\n\t}\n\n\t/**\n\t * Parses a content type by getting the relevant information inside.\n\t * @since 1.3.0\n\t * @param contentType The content type to parse.\n\t */\n\tpublic parseContentType(contentType: string): string {\n\t\tconst index = contentType.indexOf(';');\n\t\treturn index === -1 ? contentType : contentType.slice(0, index);\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { __name, __publicField } from '../../chunk-JTFKMR4I.mjs';
1
+ import { __name, __publicField } from '../../chunk-S573YWRP.mjs';
2
2
  import { Piece } from '@sapphire/pieces';
3
3
 
4
4
  var _Middleware = class _Middleware extends Piece {
@@ -22,5 +22,5 @@ __name(_Middleware, "Middleware");
22
22
  var Middleware = _Middleware;
23
23
 
24
24
  export { Middleware };
25
- //# sourceMappingURL=out.js.map
25
+ //# sourceMappingURL=Middleware.mjs.map
26
26
  //# sourceMappingURL=Middleware.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/Middleware.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AASf,IAAe,cAAf,MAAe,oBAA4E,MAA8B;AAAA,EAaxH,YAAY,SAAmC,UAAmB,CAAC,GAAc;AACvF,UAAM,SAAS,OAAO;AAHvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAIf,SAAK,WAAW,QAAQ,YAAY;AAAA,EACrC;AASD;AAzBgI;AAAzH,IAAe,aAAf","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport type { Route } from './Route';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\n\n/**\n * @since 1.0.0\n */\nexport abstract class Middleware<Options extends Middleware.Options = Middleware.Options> extends Piece<Options, 'middlewares'> {\n\t/**\n\t * The position the middleware has. The {@link MiddlewareStore} will run all middlewares with lower position than\n\t * this one.\n\t *\n\t * The built-in middlewares follow the following positions:\n\t * - headers: 10\n\t * - body: 20\n\t * - cookies: 30\n\t * - auth: 40\n\t */\n\tpublic readonly position: number;\n\n\tpublic constructor(context: Middleware.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t\tthis.position = options.position ?? 1000;\n\t}\n\n\t/**\n\t * The method to be overridden by other middlewares.\n\t * @param request The client's request.\n\t * @param response The server's response.\n\t * @param route The route that matched this request, will be `null` if none matched.\n\t */\n\tpublic abstract run(request: ApiRequest, response: ApiResponse, route: Route | null): Awaitable<unknown>;\n}\n\n/**\n * The options for all middlewares.\n */\nexport interface MiddlewareOptions extends Piece.Options {\n\t/**\n\t * The position to insert the middleware at.\n\t * @see Middleware#position\n\t * @default 1000\n\t */\n\tposition?: number;\n}\n\nexport namespace Middleware {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'middlewares'>;\n\texport type Options = MiddlewareOptions;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/Middleware.ts"],"names":[],"mappings":";;;AAQO,IAAe,WAAA,GAAf,MAAe,WAAA,SAA4E,KAA8B,CAAA;AAAA,EAaxH,WAAY,CAAA,OAAA,EAAmC,OAAmB,GAAA,EAAe,EAAA;AACvF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAHvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA;AAIf,IAAK,IAAA,CAAA,QAAA,GAAW,QAAQ,QAAY,IAAA,GAAA,CAAA;AAAA,GACrC;AASD,CAAA,CAAA;AAzBgI,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA,CAAA;AAAzH,IAAe,UAAf,GAAA","file":"Middleware.mjs","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\n\n/**\n * @since 1.0.0\n */\nexport abstract class Middleware<Options extends Middleware.Options = Middleware.Options> extends Piece<Options, 'middlewares'> {\n\t/**\n\t * The position the middleware has. The {@link MiddlewareStore} will run all middlewares with lower position than\n\t * this one.\n\t *\n\t * The built-in middlewares follow the following positions:\n\t * - headers: 10\n\t * - body: 20\n\t * - cookies: 30\n\t * - auth: 40\n\t */\n\tpublic readonly position: number;\n\n\tpublic constructor(context: Middleware.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t\tthis.position = options.position ?? 1000;\n\t}\n\n\t/**\n\t * The method to be overridden by other middlewares.\n\t * @param request The client's request.\n\t * @param response The server's response.\n\t * @param route The route that matched this request, will be `null` if none matched.\n\t */\n\tpublic abstract run(request: Middleware.Request, response: Middleware.Response): Awaitable<unknown>;\n}\n\n/**\n * The options for all middlewares.\n */\nexport interface MiddlewareOptions extends Piece.Options {\n\t/**\n\t * The position to insert the middleware at.\n\t * @see Middleware#position\n\t * @default 1000\n\t */\n\tposition?: number;\n}\n\nexport namespace Middleware {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'middlewares'>;\n\texport type Options = MiddlewareOptions;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n\n\texport type Request = ApiRequest;\n\texport type Response = ApiResponse;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { __name, __publicField } from '../../chunk-JTFKMR4I.mjs';
1
+ import { __name, __publicField } from '../../chunk-S573YWRP.mjs';
2
2
  import { Store } from '@sapphire/pieces';
3
3
  import { Middleware } from './Middleware.mjs';
4
4
 
@@ -10,10 +10,10 @@ var _MiddlewareStore = class _MiddlewareStore extends Store {
10
10
  */
11
11
  __publicField(this, "sortedMiddlewares", []);
12
12
  }
13
- async run(request, response, route) {
13
+ async run(request, response) {
14
14
  for (const middleware of this.sortedMiddlewares) {
15
15
  if (response.writableEnded) return;
16
- if (middleware.enabled) await middleware.run(request, response, route);
16
+ if (middleware.enabled) await middleware.run(request, response);
17
17
  }
18
18
  }
19
19
  set(key, value) {
@@ -36,5 +36,5 @@ __name(_MiddlewareStore, "MiddlewareStore");
36
36
  var MiddlewareStore = _MiddlewareStore;
37
37
 
38
38
  export { MiddlewareStore };
39
- //# sourceMappingURL=out.js.map
39
+ //# sourceMappingURL=MiddlewareStore.mjs.map
40
40
  //# sourceMappingURL=MiddlewareStore.mjs.map
@@ -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,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
+ {"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":[],"mappings":";;;;AAMO,IAAM,gBAAA,GAAN,MAAM,gBAAA,SAAwB,KAAiC,CAAA;AAAA,EAM9D,WAAc,GAAA;AACpB,IAAA,KAAA,CAAM,UAAY,EAAA,EAAE,IAAM,EAAA,aAAA,EAAe,CAAA,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A;AAChC,IAAA,OAAO,MAAM,KAAM,EAAA,CAAA;AAAA,GACpB;AACD,CAAA,CAAA;AAxCsE,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA,CAAA;AAA/D,IAAM,eAAN,GAAA","file":"MiddlewareStore.mjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Middleware } from './Middleware';\n\n/**\n * @since 1.0.0\n */\nexport class MiddlewareStore extends Store<Middleware, 'middlewares'> {\n\t/**\n\t * The sorted middlewares, in ascending order of see {@link Middleware.position}.\n\t */\n\tpublic readonly sortedMiddlewares: Middleware[] = [];\n\n\tpublic constructor() {\n\t\tsuper(Middleware, { name: 'middlewares' });\n\t}\n\n\tpublic async run(request: Middleware.Request, response: Middleware.Response): Promise<void> {\n\t\tfor (const middleware of this.sortedMiddlewares) {\n\t\t\tif (response.writableEnded) return;\n\t\t\tif (middleware.enabled) await middleware.run(request, response);\n\t\t}\n\t}\n\n\tpublic override set(key: string, value: Middleware): this {\n\t\tconst index = this.sortedMiddlewares.findIndex((middleware) => middleware.position >= value.position);\n\n\t\t// If a middleware with lower priority wasn't found, push to the end of the array\n\t\tif (index === -1) this.sortedMiddlewares.push(value);\n\t\telse this.sortedMiddlewares.splice(index, 0, value);\n\n\t\treturn super.set(key, value);\n\t}\n\n\tpublic override delete(key: string): boolean {\n\t\tconst index = this.sortedMiddlewares.findIndex((middleware) => middleware.name === key);\n\n\t\t// If the middleware was found, remove it\n\t\tif (index !== -1) this.sortedMiddlewares.splice(index, 1);\n\n\t\treturn super.delete(key);\n\t}\n\n\tpublic override clear(): void {\n\t\tthis.sortedMiddlewares.length = 0;\n\t\treturn super.clear();\n\t}\n}\n"]}
@@ -1,8 +1,7 @@
1
- import { __name, __publicField } from '../../chunk-JTFKMR4I.mjs';
1
+ import { __name, __publicField } from '../../chunk-S573YWRP.mjs';
2
2
  import { Piece } from '@sapphire/pieces';
3
- import { Collection } from 'discord.js';
4
- import { RouteData } from '../utils/RouteData.mjs';
5
- import { methodEntries } from './http/HttpMethods.mjs';
3
+ import { isNullish } from '@sapphire/utilities';
4
+ import { RouterRoot } from './router/RouterRoot.mjs';
6
5
 
7
6
  var _Route = class _Route extends Piece {
8
7
  constructor(context, options = {}) {
@@ -16,50 +15,34 @@ var _Route = class _Route extends Piece {
16
15
  */
17
16
  __publicField(this, "acceptedContentMimeTypes");
18
17
  /**
19
- * The route information.
18
+ * The path this route represents.
20
19
  */
21
- __publicField(this, "router");
20
+ __publicField(this, "path");
22
21
  /**
23
22
  * The methods this route accepts.
24
23
  */
25
- __publicField(this, "methods", new Collection());
24
+ __publicField(this, "methods");
26
25
  const api = this.container.server.options;
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}`);
30
- for (const [method, symbol] of methodEntries) {
31
- const value = Reflect.get(this, symbol);
32
- if (typeof value === "function") this.methods.set(method, value);
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
+ );
30
+ const methods = new Set(options.methods);
31
+ const implied = RouterRoot.extractMethod(path);
32
+ if (!isNullish(implied)) {
33
+ const lastIndex = path.length - 1;
34
+ path[lastIndex] = path[lastIndex].slice(0, path[lastIndex].length - implied.length - 1);
35
+ methods.add(implied);
33
36
  }
37
+ this.path = path;
38
+ this.methods = methods;
34
39
  this.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;
35
40
  this.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;
36
41
  }
37
- /**
38
- * Per-piece listener that is called when the piece is loaded into the store.
39
- * Useful to set-up asynchronous initialization tasks.
40
- */
41
- onLoad() {
42
- const store = this.store;
43
- for (const [method, cb] of this.methods) {
44
- store.table.get(method).set(this, cb.bind(this));
45
- }
46
- return void 0;
47
- }
48
- /**
49
- * Per-piece listener that is called when the piece is unloaded from the store.
50
- * Useful to set-up clean-up tasks.
51
- */
52
- onUnload() {
53
- const store = this.store;
54
- for (const [method] of this.methods) {
55
- store.table.get(method).delete(this);
56
- }
57
- return void 0;
58
- }
59
42
  };
60
43
  __name(_Route, "Route");
61
44
  var Route = _Route;
62
45
 
63
46
  export { Route };
64
- //# sourceMappingURL=out.js.map
47
+ //# sourceMappingURL=Route.mjs.map
65
48
  //# sourceMappingURL=Route.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AAEtB,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAI1B,SAAS,qBAAmC;AAMrC,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;AAElC,UAAM,SAAS,IAAI,SAAU,IAAI,OAAO,SAAS,GAAG,IAAI,IAAI,SAAS,GAAG,IAAI,MAAM,MAAO;AAIzF,UAAM,OAAO,QAAQ,UAAU,KAAK,SAAS,UAAU,KAAK,OAAO,KAAK,SAAS,YAAY,OAAO,KAAK,IAAI,EAAE,KAAK,GAAG;AACvH,SAAK,SAAS,IAAI,UAAU,GAAG,MAAM,GAAG,IAAI,EAAE;AAE9C,eAAW,CAAC,QAAQ,MAAM,KAAK,eAAe;AAC7C,YAAM,QAAQ,QAAQ,IAAI,MAAM,MAAM;AACtC,UAAI,OAAO,UAAU,WAAY,MAAK,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;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
+ {"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,UAA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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 = ([] 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 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"]}
@@ -0,0 +1,17 @@
1
+ import { __name } from '../../chunk-S573YWRP.mjs';
2
+ import { LoaderStrategy } from '@sapphire/pieces';
3
+
4
+ var _RouteLoaderStrategy = class _RouteLoaderStrategy extends LoaderStrategy {
5
+ onLoad(store, piece) {
6
+ store.router.add(piece);
7
+ }
8
+ onUnload(store, piece) {
9
+ store.router.remove(piece);
10
+ }
11
+ };
12
+ __name(_RouteLoaderStrategy, "RouteLoaderStrategy");
13
+ var RouteLoaderStrategy = _RouteLoaderStrategy;
14
+
15
+ export { RouteLoaderStrategy };
16
+ //# sourceMappingURL=RouteLoaderStrategy.mjs.map
17
+ //# sourceMappingURL=RouteLoaderStrategy.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/lib/structures/RouteLoaderStrategy.ts"],"names":[],"mappings":";;;AAIO,IAAM,oBAAA,GAAN,MAAM,oBAAA,SAA4B,cAAsB,CAAA;AAAA,EAC9C,MAAA,CAAO,OAAmB,KAAoB,EAAA;AAC7D,IAAM,KAAA,CAAA,MAAA,CAAO,IAAI,KAAK,CAAA,CAAA;AAAA,GACvB;AAAA,EAEgB,QAAA,CAAS,OAAmB,KAAoB,EAAA;AAC/D,IAAM,KAAA,CAAA,MAAA,CAAO,OAAO,KAAK,CAAA,CAAA;AAAA,GAC1B;AACD,CAAA,CAAA;AAR+D,MAAA,CAAA,oBAAA,EAAA,qBAAA,CAAA,CAAA;AAAxD,IAAM,mBAAN,GAAA","file":"RouteLoaderStrategy.mjs","sourcesContent":["import { LoaderStrategy } from '@sapphire/pieces';\nimport type { Route } from './Route';\nimport type { RouteStore } from './RouteStore';\n\nexport class RouteLoaderStrategy extends LoaderStrategy<Route> {\n\tpublic override onLoad(store: RouteStore, piece: Route): void {\n\t\tstore.router.add(piece);\n\t}\n\n\tpublic override onUnload(store: RouteStore, piece: Route): void {\n\t\tstore.router.remove(piece);\n\t}\n}\n"]}
@@ -1,56 +1,18 @@
1
- import { __name, __publicField } from '../../chunk-JTFKMR4I.mjs';
1
+ import { __name, __publicField } from '../../chunk-S573YWRP.mjs';
2
2
  import { Store } from '@sapphire/pieces';
3
- import { Collection } from 'discord.js';
4
- import { URLSearchParams } from 'url';
5
- import { methodEntries } from './http/HttpMethods.mjs';
6
3
  import { Route } from './Route.mjs';
4
+ import { RouteLoaderStrategy } from './RouteLoaderStrategy.mjs';
5
+ import { RouterRoot } from './router/RouterRoot.mjs';
7
6
 
8
- var slash = "/".charCodeAt(0);
9
7
  var _RouteStore = class _RouteStore extends Store {
10
8
  constructor() {
11
- super(Route, { name: "routes" });
12
- __publicField(this, "table", new Collection());
13
- for (const [method] of methodEntries) this.table.set(method, new Collection());
14
- }
15
- match(request) {
16
- const { method } = request;
17
- if (typeof method === "undefined") {
18
- return null;
19
- }
20
- const methodTable = this.table.get(method);
21
- if (typeof methodTable === "undefined") {
22
- return null;
23
- }
24
- const { splits, querystring } = this.parseURL(request.url);
25
- for (const [route, cb] of methodTable.entries()) {
26
- const result = route.router.match(splits);
27
- if (result === null) continue;
28
- request.params = result;
29
- request.query = Object.fromEntries(new URLSearchParams(querystring).entries());
30
- return { route, cb };
31
- }
32
- return null;
33
- }
34
- parseURL(url = "") {
35
- const index = url.indexOf("?");
36
- let pathname;
37
- let querystring;
38
- if (index === -1) {
39
- pathname = url;
40
- querystring = "";
41
- } else {
42
- pathname = url.substring(0, index);
43
- querystring = url.substring(index + 1);
44
- }
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);
47
- const splits = pathname.split("/");
48
- return { splits, querystring };
9
+ super(Route, { name: "routes", strategy: new RouteLoaderStrategy() });
10
+ __publicField(this, "router", new RouterRoot());
49
11
  }
50
12
  };
51
13
  __name(_RouteStore, "RouteStore");
52
14
  var RouteStore = _RouteStore;
53
15
 
54
16
  export { RouteStore };
55
- //# sourceMappingURL=out.js.map
17
+ //# sourceMappingURL=RouteStore.mjs.map
56
18
  //# sourceMappingURL=RouteStore.mjs.map
@@ -1 +1 @@
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
+ {"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":[],"mappings":";;;;;;AAQO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmB,KAAuB,CAAA;AAAA,EAG/C,WAAc,GAAA;AACpB,IAAM,KAAA,CAAA,KAAA,EAAO,EAAE,IAAM,EAAA,QAAA,EAAU,UAAU,IAAI,mBAAA,IAAuB,CAAA,CAAA;AAHrE,IAAgB,aAAA,CAAA,IAAA,EAAA,QAAA,EAAS,IAAI,UAAW,EAAA,CAAA,CAAA;AAAA,GAIxC;AACD,CAAA,CAAA;AANuD,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA,CAAA;AAAhD,IAAM,UAAN,GAAA","file":"RouteStore.mjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Route } from './Route';\nimport { RouteLoaderStrategy } from './RouteLoaderStrategy';\nimport { RouterRoot } from './router/RouterRoot';\n\n/**\n * @since 1.0.0\n */\nexport class RouteStore extends Store<Route, 'routes'> {\n\tpublic readonly router = new RouterRoot();\n\n\tpublic constructor() {\n\t\tsuper(Route, { name: 'routes', strategy: new RouteLoaderStrategy() });\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { __name, __publicField } from '../../../chunk-JTFKMR4I.mjs';
1
+ import { __name, __publicField } from '../../../chunk-S573YWRP.mjs';
2
2
  import { IncomingMessage } from 'node:http';
3
3
 
4
4
  var _ApiRequest = class _ApiRequest extends IncomingMessage {
@@ -24,11 +24,37 @@ var _ApiRequest = class _ApiRequest extends IncomingMessage {
24
24
  * - `AuthData`: The user is authorized.
25
25
  */
26
26
  __publicField(this, "auth");
27
+ /**
28
+ * The router node that matched the request. The field indicates three
29
+ * possible values:
30
+ *
31
+ * - `undefined`: The router handler has not been executed yet.
32
+ * - `null`: The router handler has been executed, but no node matched the
33
+ * request.
34
+ * - `RouterNode`: The router handler has been executed and a node matched
35
+ * the request.
36
+ *
37
+ * @since 7.0.0
38
+ */
39
+ __publicField(this, "routerNode");
40
+ /**
41
+ * The route that matched the request. The field indicates three possible
42
+ * values:
43
+ *
44
+ * - `undefined`: The router handler has not been executed yet.
45
+ * - `null`: The router handler has been executed, but no route matched the
46
+ * request.
47
+ * - `Route`: The router handler has been executed and a route matched the
48
+ * request.
49
+ *
50
+ * @since 7.0.0
51
+ */
52
+ __publicField(this, "route");
27
53
  }
28
54
  };
29
55
  __name(_ApiRequest, "ApiRequest");
30
56
  var ApiRequest = _ApiRequest;
31
57
 
32
58
  export { ApiRequest };
33
- //# sourceMappingURL=out.js.map
59
+ //# sourceMappingURL=ApiRequest.mjs.map
34
60
  //# sourceMappingURL=ApiRequest.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/lib/structures/api/ApiRequest.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,uBAAuB;AAGzB,IAAM,cAAN,MAAM,oBAAmB,gBAAgB;AAAA,EAAzC;AAAA;AAIN;AAAA;AAAA;AAAA,wBAAO,SAA2C,CAAC;AAKnD;AAAA;AAAA;AAAA,wBAAO,UAAiC,CAAC;AAKzC;AAAA;AAAA;AAAA,wBAAO;AASP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAO;AAAA;AACR;AAxBgD;AAAzC,IAAM,aAAN","sourcesContent":["import { IncomingMessage } from 'node:http';\nimport type { AuthData } from '../http/Auth';\n\nexport class ApiRequest extends IncomingMessage {\n\t/**\n\t * The query parameters.\n\t */\n\tpublic query: Record<string, string | string[]> = {};\n\n\t/**\n\t * The URI parameters.\n\t */\n\tpublic params: Record<string, string> = {};\n\n\t/**\n\t * The body that was sent by the user.\n\t */\n\tpublic body?: unknown;\n\n\t/**\n\t * The authorization information. This field indicates three possible values:\n\t *\n\t * - `undefined`: The authorization middleware has not been executed yet.\n\t * - `null`: The user is not authorized.\n\t * - `AuthData`: The user is authorized.\n\t */\n\tpublic auth?: AuthData | null;\n}\n"]}
1
+ {"version":3,"sources":["../../../../../src/lib/structures/api/ApiRequest.ts"],"names":[],"mappings":";;;AAKO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmB,eAAgB,CAAA;AAAA,EAAzC,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,SAA2C,EAAC,CAAA,CAAA;AAKnD;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,UAAiC,EAAC,CAAA,CAAA;AAKzC;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA,CAAA;AASP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA,CAAA;AAcP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,YAAA,CAAA,CAAA;AAcP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA,CAAA;AAAA,GAAA;AACR,CAAA,CAAA;AApDgD,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA,CAAA;AAAzC,IAAM,UAAN,GAAA","file":"ApiRequest.mjs","sourcesContent":["import { IncomingMessage } from 'node:http';\nimport type { Route } from '../Route';\nimport type { AuthData } from '../http/Auth';\nimport type { RouterNode } from '../router/RouterNode';\n\nexport class ApiRequest extends IncomingMessage {\n\t/**\n\t * The query parameters.\n\t */\n\tpublic query: Record<string, string | string[]> = {};\n\n\t/**\n\t * The URI parameters.\n\t */\n\tpublic params: Record<string, string> = {};\n\n\t/**\n\t * The body that was sent by the user.\n\t */\n\tpublic body?: unknown;\n\n\t/**\n\t * The authorization information. This field indicates three possible values:\n\t *\n\t * - `undefined`: The authorization middleware has not been executed yet.\n\t * - `null`: The user is not authorized.\n\t * - `AuthData`: The user is authorized.\n\t */\n\tpublic auth?: AuthData | null;\n\n\t/**\n\t * The router node that matched the request. The field indicates three\n\t * possible values:\n\t *\n\t * - `undefined`: The router handler has not been executed yet.\n\t * - `null`: The router handler has been executed, but no node matched the\n\t * request.\n\t * - `RouterNode`: The router handler has been executed and a node matched\n\t * the request.\n\t *\n\t * @since 7.0.0\n\t */\n\tpublic routerNode?: RouterNode | null;\n\n\t/**\n\t * The route that matched the request. The field indicates three possible\n\t * values:\n\t *\n\t * - `undefined`: The router handler has not been executed yet.\n\t * - `null`: The router handler has been executed, but no route matched the\n\t * request.\n\t * - `Route`: The router handler has been executed and a route matched the\n\t * request.\n\t *\n\t * @since 7.0.0\n\t */\n\tpublic route?: Route | null;\n}\n"]}
@@ -1,8 +1,7 @@
1
- import { __name, __publicField } from '../../../chunk-JTFKMR4I.mjs';
1
+ 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 {
@@ -58,6 +57,12 @@ var _ApiResponse = class _ApiResponse extends ServerResponse {
58
57
  notFound(data) {
59
58
  return this.error(HttpCodes.NotFound, data);
60
59
  }
60
+ /**
61
+ * @since 7.0.0
62
+ */
63
+ methodNotAllowed(data) {
64
+ return this.error(HttpCodes.MethodNotAllowed, data);
65
+ }
61
66
  /**
62
67
  * @since 1.0.0
63
68
  */
@@ -90,20 +95,20 @@ var _ApiResponse = class _ApiResponse extends ServerResponse {
90
95
  * @since 1.0.0
91
96
  */
92
97
  json(data) {
93
- this.setContentType(MimeTypes.ApplicationJson).end(JSON.stringify(data));
98
+ this.setContentType("application/json").end(JSON.stringify(data));
94
99
  }
95
100
  /**
96
101
  * @since 1.0.0
97
102
  */
98
103
  text(data) {
99
- this.setContentType(MimeTypes.TextPlain).end(data);
104
+ this.setContentType("text/plain").end(data);
100
105
  }
101
106
  /**
102
107
  * @since 6.1.0
103
108
  *
104
109
  * Sets the image content type and sends the image data in the response.
105
110
  *
106
- * @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').
107
112
  * @param data - The image data as a `string`, {@link Buffer}, {@link Uint8Array}, or {@link ReadableStream}.
108
113
  */
109
114
  image(type, data) {
@@ -118,7 +123,7 @@ var _ApiResponse = class _ApiResponse extends ServerResponse {
118
123
  * @since 5.1.0
119
124
  */
120
125
  html(code, data) {
121
- this.setContentType(MimeTypes.TextHtml).status(code).end(data);
126
+ this.setContentType("text/html").status(code).end(data);
122
127
  }
123
128
  /**
124
129
  * @since 1.0.0
@@ -132,5 +137,5 @@ __name(_ApiResponse, "ApiResponse");
132
137
  var ApiResponse = _ApiResponse;
133
138
 
134
139
  export { ApiResponse };
135
- //# sourceMappingURL=out.js.map
140
+ //# sourceMappingURL=ApiResponse.mjs.map
136
141
  //# sourceMappingURL=ApiResponse.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/lib/structures/api/ApiResponse.ts"],"names":[],"mappings":";;;;;;AAAA,SAA0B,gBAAgB,oBAAoB;AAC9D,SAAS,gBAAgB;AACzB,OAA+B;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAMnB,IAAM,eAAN,MAAM,qBAAuE,eAAwB;AAAA,EAArG;AAAA;AAIN;AAAA;AAAA;AAAA,wBAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,GAAG,OAAgB,aAAa,UAAU,EAAE,GAAS;AAC3D,SAAK,OAAO,UAAU,EAAE;AACxB,WAAO,KAAK,QAAQ,IAAI;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKO,QAAQ,OAAgB,aAAa,UAAU,OAAO,GAAS;AACrE,SAAK,OAAO,UAAU,OAAO;AAC7B,WAAO,KAAK,QAAQ,IAAI;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKO,UAAU,OAAgB,aAAa,UAAU,SAAS,GAAS;AACzE,SAAK,OAAO,UAAU,SAAS;AAC/B,WAAO,KAAK,QAAQ,IAAI;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKO,WAAW,MAAsB;AACvC,WAAO,KAAK,MAAM,UAAU,YAAY,IAAI;AAAA,EAC7C;AAAA;AAAA;AAAA;AAAA,EAKO,aAAa,MAAsB;AACzC,WAAO,KAAK,MAAM,UAAU,cAAc,IAAI;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA,EAKO,UAAU,MAAsB;AACtC,WAAO,KAAK,MAAM,UAAU,WAAW,IAAI;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKO,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AAA;AAAA;AAAA;AAAA,EAKO,eAAe,aAA8B;AACnD,SAAK,UAAU,gBAAgB,WAAW;AAC1C,WAAO;AAAA,EACR;AACD;AA3I4G;AAArG,IAAM,cAAN","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 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\t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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;\n\t}\n}\n"]}