@sapphire/plugin-api 7.0.0-next.03b2a90 → 7.0.0-next.301a15d

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 (119) hide show
  1. package/dist/cjs/index.cjs +22 -8
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index.d.cts +207 -114
  4. package/dist/cjs/lib/structures/Middleware.cjs.map +1 -1
  5. package/dist/cjs/lib/structures/MiddlewareStore.cjs +2 -2
  6. package/dist/cjs/lib/structures/MiddlewareStore.cjs.map +1 -1
  7. package/dist/cjs/lib/structures/Route.cjs +14 -11
  8. package/dist/cjs/lib/structures/Route.cjs.map +1 -1
  9. package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs +2 -10
  10. package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs.map +1 -1
  11. package/dist/cjs/lib/structures/RouteStore.cjs +2 -40
  12. package/dist/cjs/lib/structures/RouteStore.cjs.map +1 -1
  13. package/dist/cjs/lib/structures/api/ApiRequest.cjs +26 -0
  14. package/dist/cjs/lib/structures/api/ApiRequest.cjs.map +1 -1
  15. package/dist/cjs/lib/structures/api/ApiResponse.cjs +6 -0
  16. package/dist/cjs/lib/structures/api/ApiResponse.cjs.map +1 -1
  17. package/dist/cjs/lib/structures/http/Server.cjs +15 -14
  18. package/dist/cjs/lib/structures/http/Server.cjs.map +1 -1
  19. package/dist/cjs/lib/structures/router/RouterBranch.cjs +184 -0
  20. package/dist/cjs/lib/structures/router/RouterBranch.cjs.map +1 -0
  21. package/dist/cjs/lib/structures/router/RouterNode.cjs +67 -0
  22. package/dist/cjs/lib/structures/router/RouterNode.cjs.map +1 -0
  23. package/dist/cjs/lib/structures/router/RouterRoot.cjs +71 -0
  24. package/dist/cjs/lib/structures/router/RouterRoot.cjs.map +1 -0
  25. package/dist/cjs/listeners/PluginRouteError.cjs +2 -2
  26. package/dist/cjs/listeners/PluginRouteError.cjs.map +1 -1
  27. package/dist/cjs/listeners/PluginServerMiddlewareError.cjs +2 -2
  28. package/dist/cjs/listeners/PluginServerMiddlewareError.cjs.map +1 -1
  29. package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs +4 -4
  30. package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs.map +1 -1
  31. package/dist/cjs/listeners/PluginServerRequest.cjs +41 -7
  32. package/dist/cjs/listeners/PluginServerRequest.cjs.map +1 -1
  33. package/dist/cjs/listeners/{PluginServerMatch.cjs → PluginServerRouterBranchMethodNotAllowed.cjs} +4 -9
  34. package/dist/cjs/listeners/PluginServerRouterBranchMethodNotAllowed.cjs.map +1 -0
  35. package/dist/cjs/listeners/{PluginServerNoMatch.cjs → PluginServerRouterBranchNotFound.cjs} +2 -2
  36. package/dist/cjs/listeners/PluginServerRouterBranchNotFound.cjs.map +1 -0
  37. package/dist/cjs/listeners/PluginServerRouterFound.cjs +21 -0
  38. package/dist/cjs/listeners/PluginServerRouterFound.cjs.map +1 -0
  39. package/dist/cjs/listeners/_load.cjs +6 -4
  40. package/dist/cjs/listeners/_load.cjs.map +1 -1
  41. package/dist/cjs/middlewares/body.cjs +4 -3
  42. package/dist/cjs/middlewares/body.cjs.map +1 -1
  43. package/dist/cjs/middlewares/headers.cjs +9 -10
  44. package/dist/cjs/middlewares/headers.cjs.map +1 -1
  45. package/dist/esm/{chunk-JTFKMR4I.mjs → chunk-S573YWRP.mjs} +3 -2
  46. package/dist/esm/index.d.mts +207 -114
  47. package/dist/esm/index.mjs +5 -3
  48. package/dist/esm/index.mjs.map +1 -1
  49. package/dist/esm/lib/structures/MediaParser.mjs +1 -1
  50. package/dist/esm/lib/structures/MediaParserStore.mjs +1 -1
  51. package/dist/esm/lib/structures/Middleware.mjs +1 -1
  52. package/dist/esm/lib/structures/Middleware.mjs.map +1 -1
  53. package/dist/esm/lib/structures/MiddlewareStore.mjs +3 -3
  54. package/dist/esm/lib/structures/MiddlewareStore.mjs.map +1 -1
  55. package/dist/esm/lib/structures/Route.mjs +15 -12
  56. package/dist/esm/lib/structures/Route.mjs.map +1 -1
  57. package/dist/esm/lib/structures/RouteLoaderStrategy.mjs +3 -11
  58. package/dist/esm/lib/structures/RouteLoaderStrategy.mjs.map +1 -1
  59. package/dist/esm/lib/structures/RouteStore.mjs +3 -41
  60. package/dist/esm/lib/structures/RouteStore.mjs.map +1 -1
  61. package/dist/esm/lib/structures/api/ApiRequest.mjs +27 -1
  62. package/dist/esm/lib/structures/api/ApiRequest.mjs.map +1 -1
  63. package/dist/esm/lib/structures/api/ApiResponse.mjs +7 -1
  64. package/dist/esm/lib/structures/api/ApiResponse.mjs.map +1 -1
  65. package/dist/esm/lib/structures/api/CookieStore.mjs +1 -1
  66. package/dist/esm/lib/structures/http/Auth.mjs +1 -1
  67. package/dist/esm/lib/structures/http/HttpCodes.mjs +1 -1
  68. package/dist/esm/lib/structures/http/HttpMethods.mjs +1 -1
  69. package/dist/esm/lib/structures/http/Server.mjs +16 -15
  70. package/dist/esm/lib/structures/http/Server.mjs.map +1 -1
  71. package/dist/esm/lib/structures/router/RouterBranch.mjs +179 -0
  72. package/dist/esm/lib/structures/router/RouterBranch.mjs.map +1 -0
  73. package/dist/esm/lib/structures/router/RouterNode.mjs +56 -0
  74. package/dist/esm/lib/structures/router/RouterNode.mjs.map +1 -0
  75. package/dist/esm/lib/structures/router/RouterRoot.mjs +68 -0
  76. package/dist/esm/lib/structures/router/RouterRoot.mjs.map +1 -0
  77. package/dist/esm/lib/utils/MimeTypes.mjs +1 -1
  78. package/dist/esm/listeners/PluginRouteError.mjs +4 -4
  79. package/dist/esm/listeners/PluginRouteError.mjs.map +1 -1
  80. package/dist/esm/listeners/PluginServerMiddlewareError.mjs +4 -4
  81. package/dist/esm/listeners/PluginServerMiddlewareError.mjs.map +1 -1
  82. package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs +6 -6
  83. package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs.map +1 -1
  84. package/dist/esm/listeners/PluginServerRequest.mjs +37 -9
  85. package/dist/esm/listeners/PluginServerRequest.mjs.map +1 -1
  86. package/dist/esm/listeners/PluginServerRouterBranchMethodNotAllowed.mjs +18 -0
  87. package/dist/esm/listeners/PluginServerRouterBranchMethodNotAllowed.mjs.map +1 -0
  88. package/dist/esm/listeners/{PluginServerNoMatch.mjs → PluginServerRouterBranchNotFound.mjs} +4 -4
  89. package/dist/esm/listeners/PluginServerRouterBranchNotFound.mjs.map +1 -0
  90. package/dist/esm/listeners/PluginServerRouterFound.mjs +18 -0
  91. package/dist/esm/listeners/PluginServerRouterFound.mjs.map +1 -0
  92. package/dist/esm/listeners/_load.mjs +13 -11
  93. package/dist/esm/listeners/_load.mjs.map +1 -1
  94. package/dist/esm/mediaParsers/_load.mjs +1 -1
  95. package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs +1 -1
  96. package/dist/esm/mediaParsers/applicationJson.mjs +1 -1
  97. package/dist/esm/mediaParsers/textPlain.mjs +1 -1
  98. package/dist/esm/middlewares/_load.mjs +1 -1
  99. package/dist/esm/middlewares/auth.mjs +1 -1
  100. package/dist/esm/middlewares/body.mjs +5 -4
  101. package/dist/esm/middlewares/body.mjs.map +1 -1
  102. package/dist/esm/middlewares/cookies.mjs +1 -1
  103. package/dist/esm/middlewares/headers.mjs +10 -11
  104. package/dist/esm/middlewares/headers.mjs.map +1 -1
  105. package/dist/esm/register.mjs +1 -1
  106. package/dist/esm/routes/_load.mjs +1 -1
  107. package/dist/esm/routes/oauth/callback.post.mjs +1 -1
  108. package/dist/esm/routes/oauth/logout.post.mjs +1 -1
  109. package/package.json +4 -3
  110. package/dist/cjs/lib/utils/RouteData.cjs +0 -62
  111. package/dist/cjs/lib/utils/RouteData.cjs.map +0 -1
  112. package/dist/cjs/listeners/PluginServerMatch.cjs.map +0 -1
  113. package/dist/cjs/listeners/PluginServerNoMatch.cjs.map +0 -1
  114. package/dist/esm/lib/utils/RouteData.mjs +0 -56
  115. package/dist/esm/lib/utils/RouteData.mjs.map +0 -1
  116. package/dist/esm/listeners/PluginServerMatch.mjs +0 -23
  117. package/dist/esm/listeners/PluginServerMatch.mjs.map +0 -1
  118. package/dist/esm/listeners/PluginServerNoMatch.mjs.map +0 -1
  119. /package/dist/esm/{chunk-JTFKMR4I.mjs.map → chunk-S573YWRP.mjs.map} +0 -0
@@ -1,51 +1,13 @@
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 { isNullish } from '@sapphire/utilities';
4
- import { Collection } from 'discord.js';
5
- import { URLSearchParams } from 'url';
6
3
  import { Route } from './Route.mjs';
7
4
  import { RouteLoaderStrategy } from './RouteLoaderStrategy.mjs';
5
+ import { RouterRoot } from './router/RouterRoot.mjs';
8
6
 
9
- var slash = "/".charCodeAt(0);
10
7
  var _RouteStore = class _RouteStore extends Store {
11
8
  constructor() {
12
9
  super(Route, { name: "routes", strategy: new RouteLoaderStrategy() });
13
- __publicField(this, "methods", new Collection());
14
- }
15
- match(request) {
16
- const { method } = request;
17
- if (typeof method === "undefined") {
18
- return null;
19
- }
20
- const methodTable = this.methods.get(method);
21
- if (isNullish(methodTable)) {
22
- return null;
23
- }
24
- const { splits, querystring } = this.parseURL(request.url);
25
- for (const [route, router] of methodTable.entries()) {
26
- const result = router.match(splits);
27
- if (result === null) continue;
28
- request.params = result;
29
- request.query = Object.fromEntries(new URLSearchParams(querystring).entries());
30
- return route;
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 };
10
+ __publicField(this, "router", new RouterRoot());
49
11
  }
50
12
  };
51
13
  __name(_RouteStore, "RouteStore");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAEhC,SAAS,aAAa;AACtB,SAAS,2BAA2B;AAGpC,IAAM,QAAQ,IAAI,WAAW,CAAC;AAKvB,IAAM,cAAN,MAAM,oBAAmB,MAAuB;AAAA,EAG/C,cAAc;AACpB,UAAM,OAAO,EAAE,MAAM,UAAU,UAAU,IAAI,oBAAoB,EAAE,CAAC;AAHrE,wBAAgB,WAAU,IAAI,WAAqD;AAAA,EAInF;AAAA,EAEO,MAAM,SAAsC;AAClD,UAAM,EAAE,OAAO,IAAI;AAGnB,QAAI,OAAO,WAAW,aAAa;AAClC,aAAO;AAAA,IACR;AAGA,UAAM,cAAc,KAAK,QAAQ,IAAI,MAAoB;AAGzD,QAAI,UAAU,WAAW,GAAG;AAC3B,aAAO;AAAA,IACR;AAEA,UAAM,EAAE,QAAQ,YAAY,IAAI,KAAK,SAAS,QAAQ,GAAG;AAEzD,eAAW,CAAC,OAAO,MAAM,KAAK,YAAY,QAAQ,GAAG;AACpD,YAAM,SAAS,OAAO,MAAM,MAAM;AAClC,UAAI,WAAW,KAAM;AAErB,cAAQ,SAAS;AACjB,cAAQ,QAAQ,OAAO,YAAY,IAAI,gBAAgB,WAAW,EAAE,QAAQ,CAAC;AAE7E,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR;AAAA,EAEQ,SAAS,MAAM,IAAI;AAC1B,UAAM,QAAQ,IAAI,QAAQ,GAAG;AAE7B,QAAI;AACJ,QAAI;AACJ,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;AA1DuD;AAAhD,IAAM,aAAN","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { isNullish } from '@sapphire/utilities';\nimport { Collection } from 'discord.js';\nimport { URLSearchParams } from 'url';\nimport type { RouteData } from '../utils/RouteData';\nimport { Route } from './Route';\nimport { RouteLoaderStrategy } from './RouteLoaderStrategy';\nimport type { MethodName } from './http/HttpMethods';\n\nconst slash = '/'.charCodeAt(0);\n\n/**\n * @since 1.0.0\n */\nexport class RouteStore extends Store<Route, 'routes'> {\n\tpublic readonly methods = new Collection<MethodName, Collection<Route, RouteData>>();\n\n\tpublic constructor() {\n\t\tsuper(Route, { name: 'routes', strategy: new RouteLoaderStrategy() });\n\t}\n\n\tpublic match(request: Route.Request): Route | 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 routes that are tied to the provided method to have a smaller list to filter through\n\t\tconst methodTable = this.methods.get(method as MethodName);\n\n\t\t// If there are no routes of the provided type then we won't find any route so we return null\n\t\tif (isNullish(methodTable)) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst { splits, querystring } = this.parseURL(request.url);\n\n\t\tfor (const [route, router] of methodTable.entries()) {\n\t\t\tconst result = 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;\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate parseURL(url = '') {\n\t\tconst index = url.indexOf('?');\n\n\t\tlet pathname: string;\n\t\tlet querystring: string;\n\t\tif (index === -1) {\n\t\t\tpathname = url;\n\t\t\tquerystring = '';\n\t\t} else {\n\t\t\tpathname = url.substring(0, index);\n\t\t\tquerystring = url.substring(index + 1);\n\t\t}\n\n\t\tif (pathname.charCodeAt(0) === slash) pathname = pathname.substring(1);\n\t\tif (pathname.length > 0 && pathname.charCodeAt(pathname.length - 1) === slash) pathname = pathname.substring(0, pathname.length - 1);\n\n\t\tconst splits = pathname.split('/');\n\n\t\treturn { splits, querystring };\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,aAAa;AACtB,SAAS,2BAA2B;AACpC,SAAS,kBAAkB;AAKpB,IAAM,cAAN,MAAM,oBAAmB,MAAuB;AAAA,EAG/C,cAAc;AACpB,UAAM,OAAO,EAAE,MAAM,UAAU,UAAU,IAAI,oBAAoB,EAAE,CAAC;AAHrE,wBAAgB,UAAS,IAAI,WAAW;AAAA,EAIxC;AACD;AANuD;AAAhD,IAAM,aAAN","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,6 +24,32 @@ 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");
@@ -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":";;;;;;AAAA,SAAS,uBAAuB;AAKzB,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;AAcP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAO;AAcP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAO;AAAA;AACR;AApDgD;AAAzC,IAAM,aAAN","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,4 +1,4 @@
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';
@@ -58,6 +58,12 @@ var _ApiResponse = class _ApiResponse extends ServerResponse {
58
58
  notFound(data) {
59
59
  return this.error(HttpCodes.NotFound, data);
60
60
  }
61
+ /**
62
+ * @since 7.0.0
63
+ */
64
+ methodNotAllowed(data) {
65
+ return this.error(HttpCodes.MethodNotAllowed, data);
66
+ }
61
67
  /**
62
68
  * @since 1.0.0
63
69
  */
@@ -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,QAA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AAI,CAAC;AAAA,EACxE;AAAA;AAAA;AAAA;AAAA,EAKO,KAAK,MAAoB;AAC/B,SAAK,eAAe,UAAU,SAAS,EAAE,IAAI,IAAI;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUO,MACN,MACA,MACO;AACP,QAAI,gBAAgB,UAAU;AAC7B,WAAK,eAAe,IAAI;AACxB,WAAK,KAAK,IAAI;AAAA,IACf,OAAO;AACN,WAAK,eAAe,IAAI,EAAE,IAAI,IAAI;AAAA,IACnC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKO,KAAK,MAAc,MAAoB;AAC7C,SAAK,eAAe,UAAU,QAAQ,EAAE,OAAO,IAAI,EAAE,IAAI,IAAI;AAAA,EAC9D;AAAA;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\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":";;;;;;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;AAA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,KAAK,MAAoB;AAC/B,SAAK,eAAe,UAAU,SAAS,EAAE,IAAI,IAAI;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUO,MACN,MACA,MACO;AACP,QAAI,gBAAgB,UAAU;AAC7B,WAAK,eAAe,IAAI;AACxB,WAAK,KAAK,IAAI;AAAA,IACf,OAAO;AACN,WAAK,eAAe,IAAI,EAAE,IAAI,IAAI;AAAA,IACnC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKO,KAAK,MAAc,MAAoB;AAC7C,SAAK,eAAe,UAAU,QAAQ,EAAE,OAAO,IAAI,EAAE,IAAI,IAAI;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA,EAKO,eAAe,aAA8B;AACnD,SAAK,UAAU,gBAAgB,WAAW;AAC1C,WAAO;AAAA,EACR;AACD;AAlJ4G;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 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,4 +1,4 @@
1
- import { __name, __publicField } from '../../../chunk-JTFKMR4I.mjs';
1
+ import { __name, __publicField } from '../../../chunk-S573YWRP.mjs';
2
2
  import { getDomain } from 'tldts';
3
3
 
4
4
  var _CookieStore = class _CookieStore extends Map {
@@ -1,4 +1,4 @@
1
- import { __name, __publicField, __privateAdd, __privateSet, __privateGet } from '../../../chunk-JTFKMR4I.mjs';
1
+ import { __name, __publicField, __privateAdd, __privateSet, __privateGet } from '../../../chunk-S573YWRP.mjs';
2
2
  import { isThenable } from '@sapphire/utilities';
3
3
  import { randomBytes, createCipheriv, createDecipheriv } from 'crypto';
4
4
  import { OAuth2Scopes, RouteBases, Routes } from 'discord.js';
@@ -1,4 +1,4 @@
1
- import '../../../chunk-JTFKMR4I.mjs';
1
+ import '../../../chunk-S573YWRP.mjs';
2
2
 
3
3
  // src/lib/structures/http/HttpCodes.ts
4
4
  var HttpCodes = /* @__PURE__ */ ((HttpCodes2) => {
@@ -1,4 +1,4 @@
1
- import '../../../chunk-JTFKMR4I.mjs';
1
+ import '../../../chunk-S573YWRP.mjs';
2
2
 
3
3
  // src/lib/structures/http/HttpMethods.ts
4
4
  var MethodNames = [
@@ -1,6 +1,6 @@
1
- import { __name, __publicField } from '../../../chunk-JTFKMR4I.mjs';
1
+ import { __name, __publicField } from '../../../chunk-S573YWRP.mjs';
2
2
  import { container } from '@sapphire/pieces';
3
- import { EventEmitter } from 'node:events';
3
+ import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
4
4
  import { createServer } from 'node:http';
5
5
  import { MediaParserStore } from '../MediaParserStore.mjs';
6
6
  import { MiddlewareStore } from '../MiddlewareStore.mjs';
@@ -9,18 +9,19 @@ import { ApiRequest } from '../api/ApiRequest.mjs';
9
9
  import { ApiResponse } from '../api/ApiResponse.mjs';
10
10
  import { Auth } from './Auth.mjs';
11
11
 
12
- var ServerEvents = /* @__PURE__ */ ((ServerEvents2) => {
13
- ServerEvents2["Error"] = "error";
14
- ServerEvents2["Request"] = "request";
15
- ServerEvents2["Match"] = "match";
16
- ServerEvents2["NoMatch"] = "noMatch";
17
- ServerEvents2["RouteError"] = "routeError";
18
- ServerEvents2["MiddlewareFailure"] = "middlewareFailure";
19
- ServerEvents2["MiddlewareError"] = "middlewareError";
20
- ServerEvents2["MiddlewareSuccess"] = "middlewareSuccess";
21
- return ServerEvents2;
22
- })(ServerEvents || {});
23
- var _Server = class _Server extends EventEmitter {
12
+ var ServerEvent = /* @__PURE__ */ ((ServerEvent2) => {
13
+ ServerEvent2["Error"] = "error";
14
+ ServerEvent2["Request"] = "request";
15
+ ServerEvent2["RouterBranchNotFound"] = "routerBranchNotFound";
16
+ ServerEvent2["RouterBranchMethodNotAllowed"] = "routerBranchMethodNotAllowed";
17
+ ServerEvent2["RouterFound"] = "routerFound";
18
+ ServerEvent2["RouteError"] = "routeError";
19
+ ServerEvent2["MiddlewareFailure"] = "middlewareFailure";
20
+ ServerEvent2["MiddlewareError"] = "middlewareError";
21
+ ServerEvent2["MiddlewareSuccess"] = "middlewareSuccess";
22
+ return ServerEvent2;
23
+ })(ServerEvent || {});
24
+ var _Server = class _Server extends AsyncEventEmitter {
24
25
  /**
25
26
  * @since 1.0.0
26
27
  * @param options The options for this server
@@ -113,6 +114,6 @@ var _Server = class _Server extends EventEmitter {
113
114
  __name(_Server, "Server");
114
115
  var Server = _Server;
115
116
 
116
- export { Server, ServerEvents };
117
+ export { Server, ServerEvent };
117
118
  //# sourceMappingURL=out.js.map
118
119
  //# sourceMappingURL=Server.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/lib/structures/http/Server.ts"],"names":["ServerEvents","error"],"mappings":";;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AAC7B,SAA+B,gBAAgB,wBAA2D;AAE1G,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAEhC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,mBAAmB;AAC5B,SAAS,YAAoC;AAEtC,IAAK,eAAL,kBAAKA,kBAAL;AACN,EAAAA,cAAA,WAAQ;AACR,EAAAA,cAAA,aAAU;AACV,EAAAA,cAAA,WAAQ;AACR,EAAAA,cAAA,aAAU;AACV,EAAAA,cAAA,gBAAa;AACb,EAAAA,cAAA,uBAAoB;AACpB,EAAAA,cAAA,qBAAkB;AAClB,EAAAA,cAAA,uBAAoB;AART,SAAAA;AAAA,GAAA;AAcL,IAAM,UAAN,MAAM,gBAAe,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA,EAyCjC,YAAY,EAAE,MAAM,GAAG,QAAQ,IAAmB,CAAC,GAAG;AAC5D,UAAM;AArCP;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAMhB;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAMhB;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAMhB;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAMhB;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAMhB;AAAA;AAAA;AAAA;AAAA,w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,KAAK,CAAE;AAAA,IACjE,CAAC;AAAA,EACF;AACD;AApGyC;AAAlC,IAAM,SAAN","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { EventEmitter } from 'node:events';\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 { Auth, type ServerOptionsAuth } from './Auth';\n\nexport enum ServerEvents {\n\tError = 'error',\n\tRequest = 'request',\n\tMatch = 'match',\n\tNoMatch = 'noMatch',\n\tRouteError = 'routeError',\n\tMiddlewareFailure = 'middlewareFailure',\n\tMiddlewareError = 'middlewareError',\n\tMiddlewareSuccess = 'middlewareSuccess'\n}\n\n/**\n * @since 1.0.0\n */\nexport class Server extends EventEmitter {\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, ServerEvents.Error));\n\t\tthis.server.on('request', this.emit.bind(this, ServerEvents.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\n/**\n * The context sent in the error events.\n * @since 1.2.0\n */\nexport interface MiddlewareErrorContext {\n\t/**\n\t * The erroneous request.\n\t * @since 1.2.0\n\t */\n\trequest: ApiRequest;\n\n\t/**\n\t * The server's response.\n\t * @since 1.2.0\n\t */\n\tresponse: ApiResponse;\n\n\t/**\n\t * The route match.\n\t * @since 1.2.0\n\t */\n\troute: Route;\n}\n"]}
1
+ {"version":3,"sources":["../../../../../src/lib/structures/http/Server.ts"],"names":["ServerEvent","error"],"mappings":";;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAClC,SAA+B,gBAAgB,wBAA2D;AAE1G,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAEhC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,mBAAmB;AAE5B,SAAS,YAAoC;AAEtC,IAAK,cAAL,kBAAKA,iBAAL;AACN,EAAAA,aAAA,WAAQ;AACR,EAAAA,aAAA,aAAU;AACV,EAAAA,aAAA,0BAAuB;AACvB,EAAAA,aAAA,kCAA+B;AAC/B,EAAAA,aAAA,iBAAc;AACd,EAAAA,aAAA,gBAAa;AACb,EAAAA,aAAA,uBAAoB;AACpB,EAAAA,aAAA,qBAAkB;AAClB,EAAAA,aAAA,uBAAoB;AATT,SAAAA;AAAA,GAAA;AA2BL,IAAM,UAAN,MAAM,gBAAe,kBAAgC;AAAA;AAAA;AAAA;AAAA;AAAA,EAyCpD,YAAY,EAAE,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AO,IAAI,SAAS,KAAK;AAAA,MAC1B;AAJS;AAMT,aAAO,GAAG,aAAa,SAAS;AAChC,aAAO,GAAG,SAAS,KAAK;AACxB,aAAO,GAAG,SAAS,KAAK;AAAA,IACzB,CAAC;AAAA,EACF;AAAA,EAEO,aAAa;AACnB,WAAO,IAAI,QAAc,CAAC,SAAS,WAAW;AAC7C,WAAK,OAAO,MAAM,CAAC,UAAW,QAAQ,QAAQ,IAAI,OAAO,KAAK,CAAE;AAAA,IACjE,CAAC;AAAA,EACF;AACD;AApG4D;AAArD,IAAM,SAAN","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]: [error: Error, 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"]}
@@ -0,0 +1,179 @@
1
+ import { __name, __publicField } from '../../../chunk-S573YWRP.mjs';
2
+ import { isNullish } from '@sapphire/utilities';
3
+ import { RouterNode } from './RouterNode.mjs';
4
+
5
+ var _RouterBranch = class _RouterBranch {
6
+ constructor(name, dynamic, parent) {
7
+ /**
8
+ * The name of the branch.
9
+ */
10
+ __publicField(this, "name");
11
+ /**
12
+ * Whether or not the branch is dynamic.
13
+ */
14
+ __publicField(this, "dynamic");
15
+ /**
16
+ * The parent branch, if any.
17
+ */
18
+ __publicField(this, "parent");
19
+ /**
20
+ * The node this branch is associated with.
21
+ */
22
+ __publicField(this, "node", new RouterNode(this));
23
+ /**
24
+ * The methods supported by the branch's node or any of its children.
25
+ */
26
+ __publicField(this, "supportedMethods", []);
27
+ __publicField(this, "_staticChildren", []);
28
+ __publicField(this, "_dynamicChild", null);
29
+ this.name = name;
30
+ this.dynamic = dynamic;
31
+ this.parent = parent;
32
+ }
33
+ /**
34
+ * The path representing this branch
35
+ * @version 7.0.0
36
+ */
37
+ get path() {
38
+ return this.parent ? `${this.parent}/${this}` : `${this}`;
39
+ }
40
+ /**
41
+ * The branches the branch is associated with
42
+ * @version 7.0.0
43
+ */
44
+ get children() {
45
+ return this._staticChildren.concat(this._dynamicChild ?? []);
46
+ }
47
+ /**
48
+ * Whether or not the branch is empty
49
+ * @version 7.0.0
50
+ */
51
+ get empty() {
52
+ return this._staticChildren.length === 0 && this._dynamicChild === null;
53
+ }
54
+ /**
55
+ * Tries to find a branch given a path
56
+ * @version 7.0.0
57
+ *
58
+ * @param parts The parts of a path to find a node from
59
+ * @returns The branch found, or null if not found
60
+ */
61
+ find(parts) {
62
+ return this._find(parts, 0);
63
+ }
64
+ /**
65
+ * Checks if the given name matches the branch
66
+ * @version 7.0.0
67
+ *
68
+ * @param name The name to match
69
+ * @returns Whether or not the branch matches the name
70
+ */
71
+ matches(name) {
72
+ return this.dynamic || this.name === name;
73
+ }
74
+ /**
75
+ * Returns the string representation of the branch
76
+ * @version 7.0.0
77
+ *
78
+ * @returns The string representation of the branch
79
+ */
80
+ toString() {
81
+ return this.dynamic ? `[${this.name}]` : this.name;
82
+ }
83
+ *nodes() {
84
+ yield this.node;
85
+ for (const child of this._staticChildren) {
86
+ yield* child.nodes();
87
+ }
88
+ if (this._dynamicChild) {
89
+ yield* this._dynamicChild.nodes();
90
+ }
91
+ }
92
+ _add(parts, index, route) {
93
+ const result = this._performAdd(parts, index, route);
94
+ this._updateSupportedChildrenMethods();
95
+ return result;
96
+ }
97
+ _remove(parts, index, route) {
98
+ const result = this._performRemove(parts, index, route);
99
+ if (result) this._updateSupportedChildrenMethods();
100
+ return result;
101
+ }
102
+ _performAdd(parts, index, route) {
103
+ if (index >= parts.length) {
104
+ for (const method of route.methods) {
105
+ this.node.set(method, route);
106
+ }
107
+ return this.node;
108
+ }
109
+ const part = parts[index];
110
+ const child = this._staticChildren.find((branch2) => branch2.matches(part));
111
+ if (child) {
112
+ return child._add(parts, index + 1, route);
113
+ }
114
+ if (this._dynamicChild) {
115
+ return this._dynamicChild._add(parts, index + 1, route);
116
+ }
117
+ const dynamic = part.startsWith("[") && part.endsWith("]");
118
+ let branch;
119
+ if (dynamic) {
120
+ branch = new _RouterBranch(part.slice(1, -1), true, this);
121
+ this._dynamicChild = branch;
122
+ } else {
123
+ branch = new _RouterBranch(part, false, this);
124
+ this._staticChildren.push(branch);
125
+ }
126
+ return branch._add(parts, index + 1, route);
127
+ }
128
+ _performRemove(parts, index, route) {
129
+ if (index >= parts.length) {
130
+ let success = false;
131
+ for (const method of route.methods) {
132
+ if (this.node.delete(method, route)) {
133
+ success = true;
134
+ }
135
+ }
136
+ return success;
137
+ }
138
+ const part = parts[index];
139
+ const staticChildIndex = this._staticChildren.findIndex((branch) => branch.matches(part));
140
+ if (staticChildIndex === -1) {
141
+ const child = this._staticChildren[index];
142
+ const removed = child._remove(parts, index + 1, route);
143
+ if (removed && child.empty) {
144
+ this._staticChildren = this._staticChildren.filter((branch) => branch !== child);
145
+ }
146
+ return removed;
147
+ }
148
+ if (this._dynamicChild) {
149
+ const removed = this._dynamicChild._remove(parts, index + 1, route);
150
+ if (removed && this._dynamicChild.empty) {
151
+ this._dynamicChild = null;
152
+ }
153
+ return removed;
154
+ }
155
+ return false;
156
+ }
157
+ _find(parts, index) {
158
+ if (index >= parts.length) return this;
159
+ const part = parts[index];
160
+ const child = this._staticChildren.find((branch) => branch.matches(part)) ?? this._dynamicChild;
161
+ if (isNullish(child)) return null;
162
+ return child._find(parts, index + 1);
163
+ }
164
+ _updateSupportedChildrenMethods() {
165
+ const methods = new Set(this.node.methods());
166
+ for (const child of this.children) {
167
+ for (const method of child.node.methods()) {
168
+ methods.add(method);
169
+ }
170
+ }
171
+ this.supportedMethods = [...methods];
172
+ }
173
+ };
174
+ __name(_RouterBranch, "RouterBranch");
175
+ var RouterBranch = _RouterBranch;
176
+
177
+ export { RouterBranch };
178
+ //# sourceMappingURL=out.js.map
179
+ //# sourceMappingURL=RouterBranch.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/lib/structures/router/RouterBranch.ts"],"names":["branch"],"mappings":";;;;;;AAAA,SAAS,iBAAiB;AAE1B,SAAS,kBAAkB;AAEpB,IAAM,gBAAN,MAAM,cAAa;AAAA,EA6BlB,YAAY,MAAc,SAAkB,QAA6B;AAzBhF;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB,QAAO,IAAI,WAAW,IAAI;AAK1C;AAAA;AAAA;AAAA,wBAAO,oBAAsC,CAAC;AAE9C,wBAAQ,mBAAkC,CAAC;AAC3C,wBAAQ,iBAAqC;AAG5C,SAAK,OAAO;AACZ,SAAK,UAAU;AACf,SAAK,SAAS;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAW,OAAe;AACzB,WAAO,KAAK,SAAS,GAAG,KAAK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;AAAA,MAChF;AAEA,aAAO;AAAA,IACR;AAEA,QAAI,KAAK,eAAe;AACvB,YAAM,UAAU,KAAK,cAAc,QAAQ,OAAO,QAAQ,GAAG,KAAK;AAClE,UAAI,WAAW,KAAK,cAAc,OAAO;AACxC,aAAK,gBAAgB;AAAA,MACtB;AAEA,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR;AAAA,EAEU,MAAM,OAA0B,OAAoC;AAC7E,QAAI,SAAS,MAAM,OAAQ,QAAO;AAElC,UAAM,OAAO,MAAM,KAAK;AACxB,UAAM,QAAQ,KAAK,gBAAgB,KAAK,CAAC,WAAW,OAAO,QAAQ,IAAI,CAAC,KAAK,KAAK;AAGlF,QAAI,UAAU,KAAK,EAAG,QAAO;AAG7B,WAAO,MAAM,MAAM,OAAO,QAAQ,CAAC;AAAA,EACpC;AAAA,EAEU,kCAAwC;AACjD,UAAM,UAAU,IAAI,IAAI,KAAK,KAAK,QAAQ,CAAC;AAC3C,eAAW,SAAS,KAAK,UAAU;AAClC,iBAAW,UAAU,MAAM,KAAK,QAAQ,GAAG;AAC1C,gBAAQ,IAAI,MAAM;AAAA,MACnB;AAAA,IACD;AAEA,SAAK,mBAAmB,CAAC,GAAG,OAAO;AAAA,EACpC;AACD;AA7M0B;AAAnB,IAAM,eAAN","sourcesContent":["import { isNullish } from '@sapphire/utilities';\nimport type { Route } from '../Route';\nimport { RouterNode } from './RouterNode';\n\nexport class RouterBranch {\n\t/**\n\t * The name of the branch.\n\t */\n\tpublic readonly name: string;\n\n\t/**\n\t * Whether or not the branch is dynamic.\n\t */\n\tpublic readonly dynamic: boolean;\n\n\t/**\n\t * The parent branch, if any.\n\t */\n\tpublic readonly parent: RouterBranch | null;\n\n\t/**\n\t * The node this branch is associated with.\n\t */\n\tpublic readonly node = new RouterNode(this);\n\n\t/**\n\t * The methods supported by the branch's node or any of its children.\n\t */\n\tpublic supportedMethods: readonly string[] = [];\n\n\tprivate _staticChildren: RouterBranch[] = [];\n\tprivate _dynamicChild: RouterBranch | null = null;\n\n\tpublic constructor(name: string, dynamic: boolean, parent: RouterBranch | null) {\n\t\tthis.name = name;\n\t\tthis.dynamic = dynamic;\n\t\tthis.parent = parent;\n\t}\n\n\t/**\n\t * The path representing this branch\n\t * @version 7.0.0\n\t */\n\tpublic get path(): string {\n\t\treturn this.parent ? `${this.parent}/${this}` : `${this}`;\n\t}\n\n\t/**\n\t * The branches the branch is associated with\n\t * @version 7.0.0\n\t */\n\tpublic get children(): RouterBranch[] {\n\t\treturn this._staticChildren.concat(this._dynamicChild ?? []);\n\t}\n\n\t/**\n\t * Whether or not the branch is empty\n\t * @version 7.0.0\n\t */\n\tpublic get empty(): boolean {\n\t\treturn this._staticChildren.length === 0 && this._dynamicChild === null;\n\t}\n\n\t/**\n\t * Tries to find a branch given a path\n\t * @version 7.0.0\n\t *\n\t * @param parts The parts of a path to find a node from\n\t * @returns The branch found, or null if not found\n\t */\n\tpublic find(parts: readonly string[]): RouterBranch | null {\n\t\treturn this._find(parts, 0);\n\t}\n\n\t/**\n\t * Checks if the given name matches the branch\n\t * @version 7.0.0\n\t *\n\t * @param name The name to match\n\t * @returns Whether or not the branch matches the name\n\t */\n\tpublic matches(name: string): boolean {\n\t\treturn this.dynamic || this.name === name;\n\t}\n\n\t/**\n\t * Returns the string representation of the branch\n\t * @version 7.0.0\n\t *\n\t * @returns The string representation of the branch\n\t */\n\tpublic toString(): string {\n\t\treturn this.dynamic ? `[${this.name}]` : this.name;\n\t}\n\n\tpublic *nodes(): IterableIterator<RouterNode> {\n\t\tyield this.node;\n\t\tfor (const child of this._staticChildren) {\n\t\t\tyield* child.nodes();\n\t\t}\n\n\t\tif (this._dynamicChild) {\n\t\t\tyield* this._dynamicChild.nodes();\n\t\t}\n\t}\n\n\tprotected _add(parts: readonly string[], index: number, route: Route): RouterNode {\n\t\tconst result = this._performAdd(parts, index, route);\n\t\tthis._updateSupportedChildrenMethods();\n\t\treturn result;\n\t}\n\n\tprotected _remove(parts: readonly string[], index: number, route: Route): boolean {\n\t\tconst result = this._performRemove(parts, index, route);\n\t\tif (result) this._updateSupportedChildrenMethods();\n\t\treturn result;\n\t}\n\n\tprotected _performAdd(parts: readonly string[], index: number, route: Route): RouterNode {\n\t\tif (index >= parts.length) {\n\t\t\tfor (const method of route.methods) {\n\t\t\t\tthis.node.set(method, route);\n\t\t\t}\n\n\t\t\treturn this.node;\n\t\t}\n\n\t\tconst part = parts[index];\n\t\tconst child = this._staticChildren.find((branch) => branch.matches(part));\n\t\tif (child) {\n\t\t\treturn child._add(parts, index + 1, route);\n\t\t}\n\n\t\tif (this._dynamicChild) {\n\t\t\treturn this._dynamicChild._add(parts, index + 1, route);\n\t\t}\n\n\t\tconst dynamic = part.startsWith('[') && part.endsWith(']');\n\t\tlet branch: RouterBranch;\n\t\tif (dynamic) {\n\t\t\tbranch = new RouterBranch(part.slice(1, -1), true, this);\n\t\t\tthis._dynamicChild = branch;\n\t\t} else {\n\t\t\tbranch = new RouterBranch(part, false, this);\n\t\t\tthis._staticChildren.push(branch);\n\t\t}\n\n\t\treturn branch._add(parts, index + 1, route);\n\t}\n\n\tprotected _performRemove(parts: readonly string[], index: number, route: Route): boolean {\n\t\tif (index >= parts.length) {\n\t\t\tlet success = false;\n\t\t\tfor (const method of route.methods) {\n\t\t\t\tif (this.node.delete(method, route)) {\n\t\t\t\t\tsuccess = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn success;\n\t\t}\n\n\t\tconst part = parts[index];\n\t\tconst staticChildIndex = this._staticChildren.findIndex((branch) => branch.matches(part));\n\t\tif (staticChildIndex === -1) {\n\t\t\tconst child = this._staticChildren[index];\n\t\t\tconst removed = child._remove(parts, index + 1, route);\n\t\t\tif (removed && child.empty) {\n\t\t\t\tthis._staticChildren = this._staticChildren.filter((branch) => branch !== child);\n\t\t\t}\n\n\t\t\treturn removed;\n\t\t}\n\n\t\tif (this._dynamicChild) {\n\t\t\tconst removed = this._dynamicChild._remove(parts, index + 1, route);\n\t\t\tif (removed && this._dynamicChild.empty) {\n\t\t\t\tthis._dynamicChild = null;\n\t\t\t}\n\n\t\t\treturn removed;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tprotected _find(parts: readonly string[], index: number): RouterBranch | null {\n\t\tif (index >= parts.length) return this;\n\n\t\tconst part = parts[index];\n\t\tconst child = this._staticChildren.find((branch) => branch.matches(part)) ?? this._dynamicChild;\n\n\t\t// If a child is not found, return null:\n\t\tif (isNullish(child)) return null;\n\n\t\t// Continue the search:\n\t\treturn child._find(parts, index + 1);\n\t}\n\n\tprotected _updateSupportedChildrenMethods(): void {\n\t\tconst methods = new Set(this.node.methods());\n\t\tfor (const child of this.children) {\n\t\t\tfor (const method of child.node.methods()) {\n\t\t\t\tmethods.add(method);\n\t\t\t}\n\t\t}\n\n\t\tthis.supportedMethods = [...methods];\n\t}\n}\n"]}
@@ -0,0 +1,56 @@
1
+ import { __name, __publicField, __privateAdd, __privateGet } from '../../../chunk-S573YWRP.mjs';
2
+ import { Collection } from 'discord.js';
3
+
4
+ var _methods;
5
+ var _RouterNode = class _RouterNode {
6
+ constructor(parent) {
7
+ /**
8
+ * The branch containing this node.
9
+ */
10
+ __publicField(this, "parent");
11
+ /**
12
+ * The methods this node supports.
13
+ */
14
+ __privateAdd(this, _methods, new Collection());
15
+ this.parent = parent;
16
+ }
17
+ get path() {
18
+ return this.parent.path;
19
+ }
20
+ extractParameters(parts) {
21
+ const parameters = {};
22
+ let branch = this.parent;
23
+ let index = parts.length - 1;
24
+ do {
25
+ if (branch.dynamic) parameters[branch.name] = parts[index];
26
+ branch = branch.parent;
27
+ --index;
28
+ } while (branch);
29
+ return parameters;
30
+ }
31
+ get(method) {
32
+ return __privateGet(this, _methods).get(method) ?? null;
33
+ }
34
+ set(method, route) {
35
+ __privateGet(this, _methods).set(method, route);
36
+ return this;
37
+ }
38
+ delete(method, route) {
39
+ const existing = __privateGet(this, _methods).get(method);
40
+ if (existing === route) {
41
+ __privateGet(this, _methods).delete(method);
42
+ return true;
43
+ }
44
+ return false;
45
+ }
46
+ methods() {
47
+ return __privateGet(this, _methods).keys();
48
+ }
49
+ };
50
+ _methods = new WeakMap();
51
+ __name(_RouterNode, "RouterNode");
52
+ var RouterNode = _RouterNode;
53
+
54
+ export { RouterNode };
55
+ //# sourceMappingURL=out.js.map
56
+ //# sourceMappingURL=RouterNode.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/lib/structures/router/RouterNode.ts"],"names":[],"mappings":";;;;;;;;AAAA,SAAS,kBAAkB;AAA3B;AAKO,IAAM,cAAN,MAAM,YAAW;AAAA,EAWhB,YAAY,QAAsB;AAPzC;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,iCAAW,IAAI,WAA8B;AAG5C,SAAK,SAAS;AAAA,EACf;AAAA,EAEA,IAAW,OAAO;AACjB,WAAO,KAAK,OAAO;AAAA,EACpB;AAAA,EAEO,kBAAkB,OAAkD;AAC1E,UAAM,aAAqC,CAAC;AAE5C,QAAI,SAA8B,KAAK;AACvC,QAAI,QAAQ,MAAM,SAAS;AAC3B,OAAG;AACF,UAAI,OAAO,QAAS,YAAW,OAAO,IAAI,IAAI,MAAM,KAAK;AAEzD,eAAS,OAAO;AAChB,QAAE;AAAA,IACH,SAAS;AAET,WAAO;AAAA,EACR;AAAA,EAEO,IAAI,QAAkC;AAC5C,WAAO,mBAAK,UAAS,IAAI,MAAM,KAAK;AAAA,EACrC;AAAA,EAEO,IAAI,QAAoB,OAAoB;AAClD,uBAAK,UAAS,IAAI,QAAQ,KAAK;AAC/B,WAAO;AAAA,EACR;AAAA,EAEO,OAAO,QAAoB,OAAuB;AACxD,UAAM,WAAW,mBAAK,UAAS,IAAI,MAAM;AACzC,QAAI,aAAa,OAAO;AACvB,yBAAK,UAAS,OAAO,MAAM;AAC3B,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR;AAAA,EAEO,UAAwC;AAC9C,WAAO,mBAAK,UAAS,KAAK;AAAA,EAC3B;AACD;AA/CC;AATuB;AAAjB,IAAM,aAAN","sourcesContent":["import { Collection } from 'discord.js';\nimport type { Route } from '../Route';\nimport type { MethodName } from '../http/HttpMethods';\nimport type { RouterBranch } from './RouterBranch';\n\nexport class RouterNode {\n\t/**\n\t * The branch containing this node.\n\t */\n\tpublic readonly parent: RouterBranch;\n\n\t/**\n\t * The methods this node supports.\n\t */\n\t#methods = new Collection<MethodName, Route>();\n\n\tpublic constructor(parent: RouterBranch) {\n\t\tthis.parent = parent;\n\t}\n\n\tpublic get path() {\n\t\treturn this.parent.path;\n\t}\n\n\tpublic extractParameters(parts: readonly string[]): Record<string, string> {\n\t\tconst parameters: Record<string, string> = {};\n\n\t\tlet branch: RouterBranch | null = this.parent;\n\t\tlet index = parts.length - 1;\n\t\tdo {\n\t\t\tif (branch.dynamic) parameters[branch.name] = parts[index];\n\n\t\t\tbranch = branch.parent;\n\t\t\t--index;\n\t\t} while (branch);\n\n\t\treturn parameters;\n\t}\n\n\tpublic get(method: MethodName): Route | null {\n\t\treturn this.#methods.get(method) ?? null;\n\t}\n\n\tpublic set(method: MethodName, route: Route): this {\n\t\tthis.#methods.set(method, route);\n\t\treturn this;\n\t}\n\n\tpublic delete(method: MethodName, route: Route): boolean {\n\t\tconst existing = this.#methods.get(method);\n\t\tif (existing === route) {\n\t\t\tthis.#methods.delete(method);\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tpublic methods(): IterableIterator<MethodName> {\n\t\treturn this.#methods.keys();\n\t}\n}\n"]}
@@ -0,0 +1,68 @@
1
+ import { __name } from '../../../chunk-S573YWRP.mjs';
2
+ import { isNullishOrEmpty } from '@sapphire/utilities';
3
+ import { RouterBranch } from './RouterBranch.mjs';
4
+
5
+ var _RouterRoot = class _RouterRoot extends RouterBranch {
6
+ constructor() {
7
+ super("::ROOT::", false, null);
8
+ }
9
+ /**
10
+ * Adds a route to the branch
11
+ *
12
+ * @param route The route to add
13
+ * @returns The node the route was added to
14
+ */
15
+ add(route) {
16
+ return this._add(route.path, 0, route);
17
+ }
18
+ /**
19
+ * Removes a route from the branch
20
+ *
21
+ * @param route The route to remove
22
+ * @returns Whether or not the route was removed
23
+ */
24
+ remove(route) {
25
+ return this._remove(route.path, 0, route);
26
+ }
27
+ // eslint-disable-next-line @typescript-eslint/class-literal-property-style
28
+ get path() {
29
+ return "";
30
+ }
31
+ toString() {
32
+ return "";
33
+ }
34
+ static normalize(path) {
35
+ const parts = [];
36
+ if (isNullishOrEmpty(path)) return parts;
37
+ let part = "";
38
+ for (const char of path) {
39
+ if (char === "/") {
40
+ if (part.length) {
41
+ parts.push(part);
42
+ part = "";
43
+ }
44
+ } else {
45
+ part += char;
46
+ }
47
+ }
48
+ if (part.length) {
49
+ parts.push(part);
50
+ part = "";
51
+ }
52
+ return parts;
53
+ }
54
+ static extractMethod(path) {
55
+ if (path.length === 0) return null;
56
+ const lastIndex = path.length - 1;
57
+ const last = path[lastIndex];
58
+ const methodIndex = last.lastIndexOf(".");
59
+ if (methodIndex === -1 || methodIndex === last.length - 1) return null;
60
+ return last.slice(methodIndex + 1).toUpperCase();
61
+ }
62
+ };
63
+ __name(_RouterRoot, "RouterRoot");
64
+ var RouterRoot = _RouterRoot;
65
+
66
+ export { RouterRoot };
67
+ //# sourceMappingURL=out.js.map
68
+ //# sourceMappingURL=RouterRoot.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/lib/structures/router/RouterRoot.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,wBAAwB;AAGjC,SAAS,oBAAoB;AAGtB,IAAM,cAAN,MAAM,oBAAmB,aAAa;AAAA,EACrC,cAAc;AACpB,UAAM,YAAY,OAAO,IAAI;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,IAAI,OAA0B;AACpC,WAAO,KAAK,KAAK,MAAM,MAAM,GAAG,KAAK;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,OAAO,OAAuB;AACpC,WAAO,KAAK,QAAQ,MAAM,MAAM,GAAG,KAAK;AAAA,EACzC;AAAA;AAAA,EAGA,IAAoB,OAAe;AAClC,WAAO;AAAA,EACR;AAAA,EAEgB,WAAmB;AAClC,WAAO;AAAA,EACR;AAAA,EAEA,OAAc,UAAU,MAA2C;AAClE,UAAM,QAAQ,CAAC;AACf,QAAI,iBAAiB,IAAI,EAAG,QAAO;AAEnC,QAAI,OAAO;AACX,eAAW,QAAQ,MAAM;AACxB,UAAI,SAAS,KAAK;AACjB,YAAI,KAAK,QAAQ;AAChB,gBAAM,KAAK,IAAI;AACf,iBAAO;AAAA,QACR;AAAA,MACD,OAAO;AACN,gBAAQ;AAAA,MACT;AAAA,IACD;AAEA,QAAI,KAAK,QAAQ;AAChB,YAAM,KAAK,IAAI;AACf,aAAO;AAAA,IACR;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,OAAc,cAAc,MAA4C;AACvE,QAAI,KAAK,WAAW,EAAG,QAAO;AAE9B,UAAM,YAAY,KAAK,SAAS;AAChC,UAAM,OAAO,KAAK,SAAS;AAC3B,UAAM,cAAc,KAAK,YAAY,GAAG;AACxC,QAAI,gBAAgB,MAAM,gBAAgB,KAAK,SAAS,EAAG,QAAO;AAElE,WAAO,KAAK,MAAM,cAAc,CAAC,EAAE,YAAY;AAAA,EAChD;AACD;AApE6C;AAAtC,IAAM,aAAN","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"]}