@adonisjs/http-server 6.8.2-5 → 6.8.2-7

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 (208) hide show
  1. package/README.md +3 -6
  2. package/build/factories/http_context.d.ts +10 -1
  3. package/build/factories/http_context.js +27 -0
  4. package/build/factories/http_server.d.ts +8 -0
  5. package/build/factories/http_server.js +26 -0
  6. package/build/factories/main.d.ts +0 -1
  7. package/build/factories/main.js +8 -0
  8. package/build/factories/qs_parser_factory.d.ts +10 -1
  9. package/build/factories/qs_parser_factory.js +18 -0
  10. package/build/factories/request.d.ts +10 -1
  11. package/build/factories/request.js +31 -0
  12. package/build/factories/response.d.ts +10 -1
  13. package/build/factories/response.js +34 -0
  14. package/build/factories/router.d.ts +10 -1
  15. package/build/factories/router.js +25 -0
  16. package/build/factories/server_factory.d.ts +10 -1
  17. package/build/factories/server_factory.js +34 -0
  18. package/build/index.d.ts +0 -1
  19. package/build/index.js +8 -0
  20. package/build/src/cookies/client.d.ts +25 -1
  21. package/build/src/cookies/client.js +42 -0
  22. package/build/src/cookies/drivers/encrypted.d.ts +12 -1
  23. package/build/src/cookies/drivers/encrypted.js +20 -0
  24. package/build/src/cookies/drivers/plain.d.ts +12 -1
  25. package/build/src/cookies/drivers/plain.js +20 -0
  26. package/build/src/cookies/drivers/signed.d.ts +12 -1
  27. package/build/src/cookies/drivers/signed.js +20 -0
  28. package/build/src/cookies/parser.d.ts +28 -1
  29. package/build/src/cookies/parser.js +98 -0
  30. package/build/src/cookies/serializer.d.ts +22 -1
  31. package/build/src/cookies/serializer.js +40 -0
  32. package/build/src/debug.d.ts +0 -1
  33. package/build/src/debug.js +8 -0
  34. package/build/src/define_config.d.ts +3 -1
  35. package/build/src/define_config.js +11 -0
  36. package/build/src/define_middleware.d.ts +5 -1
  37. package/build/src/define_middleware.js +18 -0
  38. package/build/src/exception_handler.d.ts +65 -1
  39. package/build/src/exception_handler.js +95 -0
  40. package/build/src/exceptions.d.ts +6 -1
  41. package/build/src/exceptions.js +11 -0
  42. package/build/src/helpers.d.ts +14 -1
  43. package/build/src/helpers.js +22 -0
  44. package/build/src/http_context/local_storage.d.ts +3 -1
  45. package/build/src/http_context/local_storage.js +25 -0
  46. package/build/src/http_context/main.d.ts +36 -1
  47. package/build/src/http_context/main.js +54 -0
  48. package/build/src/qs.d.ts +4 -1
  49. package/build/src/qs.js +12 -0
  50. package/build/src/redirect.d.ts +24 -1
  51. package/build/src/redirect.js +60 -0
  52. package/build/src/request.d.ts +466 -1
  53. package/build/src/request.js +542 -0
  54. package/build/src/response.d.ts +425 -2
  55. package/build/src/response.js +608 -7
  56. package/build/src/router/brisk.d.ts +22 -1
  57. package/build/src/router/brisk.js +42 -0
  58. package/build/src/router/executor.d.ts +4 -1
  59. package/build/src/router/executor.js +12 -0
  60. package/build/src/router/factories/use_return_value.d.ts +4 -1
  61. package/build/src/router/factories/use_return_value.js +16 -3
  62. package/build/src/router/group.d.ts +47 -1
  63. package/build/src/router/group.js +88 -0
  64. package/build/src/router/lookup_store/main.d.ts +32 -1
  65. package/build/src/router/lookup_store/main.js +49 -0
  66. package/build/src/router/lookup_store/route_finder.d.ts +13 -1
  67. package/build/src/router/lookup_store/route_finder.js +21 -0
  68. package/build/src/router/lookup_store/url_builder.d.ts +36 -1
  69. package/build/src/router/lookup_store/url_builder.js +97 -0
  70. package/build/src/router/main.d.ts +87 -1
  71. package/build/src/router/main.js +142 -0
  72. package/build/src/router/matchers.d.ts +13 -1
  73. package/build/src/router/matchers.js +21 -0
  74. package/build/src/router/parser.d.ts +3 -1
  75. package/build/src/router/parser.js +12 -0
  76. package/build/src/router/resource.d.ts +28 -1
  77. package/build/src/router/resource.js +90 -0
  78. package/build/src/router/route.d.ts +65 -1
  79. package/build/src/router/route.js +142 -0
  80. package/build/src/router/store.d.ts +54 -1
  81. package/build/src/router/store.js +102 -0
  82. package/build/src/server/factories/final_handler.d.ts +5 -1
  83. package/build/src/server/factories/final_handler.js +13 -0
  84. package/build/src/server/factories/middleware_handler.d.ts +3 -1
  85. package/build/src/server/factories/middleware_handler.js +11 -0
  86. package/build/src/server/factories/write_response.d.ts +4 -1
  87. package/build/src/server/factories/write_response.js +12 -0
  88. package/build/src/server/main.d.ts +48 -1
  89. package/build/src/server/main.js +128 -0
  90. package/build/src/types/base.d.ts +12 -1
  91. package/build/src/types/base.js +8 -0
  92. package/build/src/types/main.d.ts +0 -1
  93. package/build/src/types/main.js +8 -0
  94. package/build/src/types/middleware.d.ts +18 -1
  95. package/build/src/types/middleware.js +8 -0
  96. package/build/src/types/qs.d.ts +53 -1
  97. package/build/src/types/qs.js +8 -0
  98. package/build/src/types/request.d.ts +32 -1
  99. package/build/src/types/request.js +8 -0
  100. package/build/src/types/response.d.ts +27 -1
  101. package/build/src/types/response.js +8 -0
  102. package/build/src/types/route.d.ts +87 -1
  103. package/build/src/types/route.js +8 -0
  104. package/build/src/types/server.d.ts +35 -1
  105. package/build/src/types/server.js +8 -0
  106. package/package.json +43 -70
  107. package/build/factories/http_context.d.ts.map +0 -1
  108. package/build/factories/main.d.ts.map +0 -1
  109. package/build/factories/qs_parser_factory.d.ts.map +0 -1
  110. package/build/factories/request.d.ts.map +0 -1
  111. package/build/factories/response.d.ts.map +0 -1
  112. package/build/factories/router.d.ts.map +0 -1
  113. package/build/factories/server_factory.d.ts.map +0 -1
  114. package/build/index.d.ts.map +0 -1
  115. package/build/src/cookies/client.d.ts.map +0 -1
  116. package/build/src/cookies/drivers/encrypted.d.ts.map +0 -1
  117. package/build/src/cookies/drivers/plain.d.ts.map +0 -1
  118. package/build/src/cookies/drivers/signed.d.ts.map +0 -1
  119. package/build/src/cookies/parser.d.ts.map +0 -1
  120. package/build/src/cookies/serializer.d.ts.map +0 -1
  121. package/build/src/debug.d.ts.map +0 -1
  122. package/build/src/define_config.d.ts.map +0 -1
  123. package/build/src/define_middleware.d.ts.map +0 -1
  124. package/build/src/exception_handler.d.ts.map +0 -1
  125. package/build/src/exceptions.d.ts.map +0 -1
  126. package/build/src/helpers.d.ts.map +0 -1
  127. package/build/src/http_context/local_storage.d.ts.map +0 -1
  128. package/build/src/http_context/main.d.ts.map +0 -1
  129. package/build/src/qs.d.ts.map +0 -1
  130. package/build/src/redirect.d.ts.map +0 -1
  131. package/build/src/request.d.ts.map +0 -1
  132. package/build/src/response.d.ts.map +0 -1
  133. package/build/src/router/brisk.d.ts.map +0 -1
  134. package/build/src/router/executor.d.ts.map +0 -1
  135. package/build/src/router/factories/use_return_value.d.ts.map +0 -1
  136. package/build/src/router/group.d.ts.map +0 -1
  137. package/build/src/router/lookup_store/main.d.ts.map +0 -1
  138. package/build/src/router/lookup_store/route_finder.d.ts.map +0 -1
  139. package/build/src/router/lookup_store/url_builder.d.ts.map +0 -1
  140. package/build/src/router/main.d.ts.map +0 -1
  141. package/build/src/router/matchers.d.ts.map +0 -1
  142. package/build/src/router/parser.d.ts.map +0 -1
  143. package/build/src/router/resource.d.ts.map +0 -1
  144. package/build/src/router/route.d.ts.map +0 -1
  145. package/build/src/router/store.d.ts.map +0 -1
  146. package/build/src/server/factories/final_handler.d.ts.map +0 -1
  147. package/build/src/server/factories/middleware_handler.d.ts.map +0 -1
  148. package/build/src/server/factories/write_response.d.ts.map +0 -1
  149. package/build/src/server/main.d.ts.map +0 -1
  150. package/build/src/types/base.d.ts.map +0 -1
  151. package/build/src/types/main.d.ts.map +0 -1
  152. package/build/src/types/middleware.d.ts.map +0 -1
  153. package/build/src/types/qs.d.ts.map +0 -1
  154. package/build/src/types/request.d.ts.map +0 -1
  155. package/build/src/types/response.d.ts.map +0 -1
  156. package/build/src/types/route.d.ts.map +0 -1
  157. package/build/src/types/server.d.ts.map +0 -1
  158. package/factories/http_context.ts +0 -73
  159. package/factories/main.ts +0 -15
  160. package/factories/qs_parser_factory.ts +0 -54
  161. package/factories/request.ts +0 -101
  162. package/factories/response.ts +0 -106
  163. package/factories/router.ts +0 -61
  164. package/factories/server_factory.ts +0 -94
  165. package/index.ts +0 -23
  166. package/src/cookies/client.ts +0 -98
  167. package/src/cookies/drivers/encrypted.ts +0 -42
  168. package/src/cookies/drivers/plain.ts +0 -37
  169. package/src/cookies/drivers/signed.ts +0 -42
  170. package/src/cookies/parser.ts +0 -196
  171. package/src/cookies/serializer.ts +0 -98
  172. package/src/debug.ts +0 -11
  173. package/src/define_config.ts +0 -56
  174. package/src/define_middleware.ts +0 -61
  175. package/src/exception_handler.ts +0 -290
  176. package/src/exceptions.ts +0 -55
  177. package/src/helpers.ts +0 -108
  178. package/src/http_context/local_storage.ts +0 -50
  179. package/src/http_context/main.ts +0 -126
  180. package/src/qs.ts +0 -31
  181. package/src/redirect.ts +0 -181
  182. package/src/request.ts +0 -982
  183. package/src/response.ts +0 -1421
  184. package/src/router/brisk.ts +0 -113
  185. package/src/router/executor.ts +0 -36
  186. package/src/router/factories/use_return_value.ts +0 -26
  187. package/src/router/group.ts +0 -243
  188. package/src/router/lookup_store/main.ts +0 -102
  189. package/src/router/lookup_store/route_finder.ts +0 -60
  190. package/src/router/lookup_store/url_builder.ts +0 -250
  191. package/src/router/main.ts +0 -431
  192. package/src/router/matchers.ts +0 -40
  193. package/src/router/parser.ts +0 -20
  194. package/src/router/resource.ts +0 -277
  195. package/src/router/route.ts +0 -363
  196. package/src/router/store.ts +0 -239
  197. package/src/server/factories/final_handler.ts +0 -38
  198. package/src/server/factories/middleware_handler.ts +0 -23
  199. package/src/server/factories/write_response.ts +0 -26
  200. package/src/server/main.ts +0 -356
  201. package/src/types/base.ts +0 -30
  202. package/src/types/main.ts +0 -16
  203. package/src/types/middleware.ts +0 -59
  204. package/src/types/qs.ts +0 -85
  205. package/src/types/request.ts +0 -52
  206. package/src/types/response.ts +0 -57
  207. package/src/types/route.ts +0 -217
  208. package/src/types/server.ts +0 -92
@@ -3,19 +3,40 @@ import type { Application } from '@adonisjs/application';
3
3
  import { Route } from './route.js';
4
4
  import type { ParsedGlobalMiddleware } from '../types/middleware.js';
5
5
  import type { MakeUrlOptions, RouteFn, RouteMatchers } from '../types/route.js';
6
+ /**
7
+ * Brisk routes exposes the API to configure the route handler by chaining
8
+ * one of the pre-defined methods.
9
+ *
10
+ * For example: Instead of defining the redirect logic as a callback, one can
11
+ * chain the `.redirect` method.
12
+ *
13
+ * Brisk routes are always registered under the `GET` HTTP method.
14
+ */
6
15
  export declare class BriskRoute extends Macroable {
7
16
  #private;
17
+ /**
18
+ * Reference to route instance. Set after `setHandler` is called
19
+ */
8
20
  route: null | Route;
9
21
  constructor(app: Application<any>, routerMiddleware: ParsedGlobalMiddleware[], options: {
10
22
  pattern: string;
11
23
  globalMatchers: RouteMatchers;
12
24
  });
25
+ /**
26
+ * Set handler for the brisk route
27
+ */
13
28
  setHandler(handler: RouteFn): Route;
29
+ /**
30
+ * Redirects to a given route. Params from the original request will
31
+ * be used when no custom params are defined.
32
+ */
14
33
  redirect(identifier: string, params?: any[] | Record<string, any>, options?: MakeUrlOptions & {
15
34
  status: number;
16
35
  }): Route;
36
+ /**
37
+ * Redirect request to a fixed URL
38
+ */
17
39
  redirectToPath(url: string, options?: {
18
40
  status: number;
19
41
  }): Route;
20
42
  }
21
- //# sourceMappingURL=brisk.d.ts.map
@@ -1,10 +1,42 @@
1
+ /*
2
+ * @adonisjs/http-server
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  import Macroable from '@poppinss/macroable';
2
10
  import { Route } from './route.js';
11
+ /**
12
+ * Brisk routes exposes the API to configure the route handler by chaining
13
+ * one of the pre-defined methods.
14
+ *
15
+ * For example: Instead of defining the redirect logic as a callback, one can
16
+ * chain the `.redirect` method.
17
+ *
18
+ * Brisk routes are always registered under the `GET` HTTP method.
19
+ */
3
20
  export class BriskRoute extends Macroable {
21
+ /**
22
+ * Route pattern
23
+ */
4
24
  #pattern;
25
+ /**
26
+ * Matchers inherited from the router
27
+ */
5
28
  #globalMatchers;
29
+ /**
30
+ * Reference to the AdonisJS application
31
+ */
6
32
  #app;
33
+ /**
34
+ * Middleware registered on the router
35
+ */
7
36
  #routerMiddleware;
37
+ /**
38
+ * Reference to route instance. Set after `setHandler` is called
39
+ */
8
40
  route = null;
9
41
  constructor(app, routerMiddleware, options) {
10
42
  super();
@@ -13,6 +45,9 @@ export class BriskRoute extends Macroable {
13
45
  this.#pattern = options.pattern;
14
46
  this.#globalMatchers = options.globalMatchers;
15
47
  }
48
+ /**
49
+ * Set handler for the brisk route
50
+ */
16
51
  setHandler(handler) {
17
52
  this.route = new Route(this.#app, this.#routerMiddleware, {
18
53
  pattern: this.#pattern,
@@ -22,6 +57,10 @@ export class BriskRoute extends Macroable {
22
57
  });
23
58
  return this.route;
24
59
  }
60
+ /**
61
+ * Redirects to a given route. Params from the original request will
62
+ * be used when no custom params are defined.
63
+ */
25
64
  redirect(identifier, params, options) {
26
65
  return this.setHandler(async function redirectsToRoute(ctx) {
27
66
  const redirector = ctx.response.redirect();
@@ -31,6 +70,9 @@ export class BriskRoute extends Macroable {
31
70
  return redirector.toRoute(identifier, params || ctx.params, options);
32
71
  });
33
72
  }
73
+ /**
74
+ * Redirect request to a fixed URL
75
+ */
34
76
  redirectToPath(url, options) {
35
77
  return this.setHandler(async function redirectsToPath(ctx) {
36
78
  const redirector = ctx.response.redirect();
@@ -1,5 +1,8 @@
1
1
  import type { ContainerResolver } from '@adonisjs/fold';
2
2
  import type { StoreRouteNode } from '../types/route.js';
3
3
  import type { HttpContext } from '../http_context/main.js';
4
+ /**
5
+ * Executor to execute the route middleware pipeline the route
6
+ * handler
7
+ */
4
8
  export declare function execute(route: StoreRouteNode, resolver: ContainerResolver<any>, ctx: HttpContext): Promise<void>;
5
- //# sourceMappingURL=executor.d.ts.map
@@ -1,4 +1,16 @@
1
+ /*
2
+ * @adonisjs/http-server
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  import { useReturnValue } from './factories/use_return_value.js';
10
+ /**
11
+ * Executor to execute the route middleware pipeline the route
12
+ * handler
13
+ */
2
14
  export function execute(route, resolver, ctx) {
3
15
  return route.middleware
4
16
  .runner()
@@ -1,3 +1,6 @@
1
1
  import type { HttpContext } from '../../http_context/main.js';
2
+ /**
3
+ * A factory function that uses the return value of the request
4
+ * pipeline as the response
5
+ */
2
6
  export declare function useReturnValue(ctx: HttpContext): (value: any) => void;
3
- //# sourceMappingURL=use_return_value.d.ts.map
@@ -1,8 +1,21 @@
1
+ /*
2
+ * @adonisjs/http-server
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ /**
10
+ * A factory function that uses the return value of the request
11
+ * pipeline as the response
12
+ */
1
13
  export function useReturnValue(ctx) {
2
14
  return function (value) {
3
- if (value !== undefined &&
4
- !ctx.response.hasLazyBody &&
5
- value !== ctx.response) {
15
+ if (value !== undefined && // Return value is explicitly defined
16
+ !ctx.response.hasLazyBody && // Lazy body is not set
17
+ value !== ctx.response // Return value is not the instance of response object
18
+ ) {
6
19
  ctx.response.send(value);
7
20
  }
8
21
  };
@@ -5,15 +5,61 @@ import { Route } from './route.js';
5
5
  import { BriskRoute } from './brisk.js';
6
6
  import { RouteResource } from './resource.js';
7
7
  import { OneOrMore } from '../types/base.js';
8
+ /**
9
+ * Group class exposes the API to take action on a group of routes.
10
+ * The group routes must be pre-defined using the constructor.
11
+ */
8
12
  export declare class RouteGroup extends Macroable {
9
13
  #private;
10
14
  routes: (Route | RouteGroup | RouteResource | BriskRoute)[];
11
15
  constructor(routes: (Route | RouteGroup | RouteResource | BriskRoute)[]);
16
+ /**
17
+ * Define route param matcher
18
+ *
19
+ * ```ts
20
+ * Route.group(() => {
21
+ * }).where('id', /^[0-9]+/)
22
+ * ```
23
+ */
12
24
  where(param: string, matcher: RouteMatcher | string | RegExp): this;
25
+ /**
26
+ * Define prefix all the routes in the group.
27
+ *
28
+ * ```ts
29
+ * Route.group(() => {
30
+ * }).prefix('v1')
31
+ * ```
32
+ */
13
33
  prefix(prefix: string): this;
34
+ /**
35
+ * Define domain for all the routes.
36
+ *
37
+ * ```ts
38
+ * Route.group(() => {
39
+ * }).domain(':name.adonisjs.com')
40
+ * ```
41
+ */
14
42
  domain(domain: string): this;
43
+ /**
44
+ * Prepend name to the routes name.
45
+ *
46
+ * ```ts
47
+ * Route.group(() => {
48
+ * }).as('version1')
49
+ * ```
50
+ */
15
51
  as(name: string): this;
52
+ /**
53
+ * Prepend an array of middleware to all routes middleware.
54
+ *
55
+ * ```ts
56
+ * Route.group(() => {
57
+ * }).use(middleware.auth())
58
+ * ```
59
+ */
16
60
  use(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
61
+ /**
62
+ * @alias use
63
+ */
17
64
  middleware(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
18
65
  }
19
- //# sourceMappingURL=group.d.ts.map
@@ -1,13 +1,33 @@
1
+ /*
2
+ * @adonisjs/http-server
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  import Macroable from '@poppinss/macroable';
2
10
  import { BriskRoute } from './brisk.js';
3
11
  import { RouteResource } from './resource.js';
12
+ /**
13
+ * Group class exposes the API to take action on a group of routes.
14
+ * The group routes must be pre-defined using the constructor.
15
+ */
4
16
  export class RouteGroup extends Macroable {
5
17
  routes;
18
+ /**
19
+ * Array of middleware registered on the group.
20
+ */
6
21
  #middleware = [];
7
22
  constructor(routes) {
8
23
  super();
9
24
  this.routes = routes;
10
25
  }
26
+ /**
27
+ * Shares midldeware stack with the routes. The method is invoked recursively
28
+ * to only register middleware with the route class and not with the
29
+ * resource or the child group
30
+ */
11
31
  #shareMiddlewareStackWithRoutes(route) {
12
32
  if (route instanceof RouteGroup) {
13
33
  route.routes.forEach((child) => this.#shareMiddlewareStackWithRoutes(child));
@@ -23,6 +43,11 @@ export class RouteGroup extends Macroable {
23
43
  }
24
44
  route.getMiddleware().unshift(this.#middleware);
25
45
  }
46
+ /**
47
+ * Updates the route name. The method is invoked recursively to only update
48
+ * the name with the route class and not with the resource or the child
49
+ * group.
50
+ */
26
51
  #updateRouteName(route, name) {
27
52
  if (route instanceof RouteGroup) {
28
53
  route.routes.forEach((child) => this.#updateRouteName(child, name));
@@ -38,6 +63,11 @@ export class RouteGroup extends Macroable {
38
63
  }
39
64
  route.as(name, true);
40
65
  }
66
+ /**
67
+ * Sets prefix on the route. The method is invoked recursively to only set
68
+ * the prefix with the route class and not with the resource or the
69
+ * child group.
70
+ */
41
71
  #setRoutePrefix(route, prefix) {
42
72
  if (route instanceof RouteGroup) {
43
73
  route.routes.forEach((child) => this.#setRoutePrefix(child, prefix));
@@ -53,6 +83,11 @@ export class RouteGroup extends Macroable {
53
83
  }
54
84
  route.prefix(prefix);
55
85
  }
86
+ /**
87
+ * Updates domain on the route. The method is invoked recursively to only update
88
+ * the domain with the route class and not with the resource or the child
89
+ * group.
90
+ */
56
91
  #updateRouteDomain(route, domain) {
57
92
  if (route instanceof RouteGroup) {
58
93
  route.routes.forEach((child) => this.#updateRouteDomain(child, domain));
@@ -68,6 +103,11 @@ export class RouteGroup extends Macroable {
68
103
  }
69
104
  route.domain(domain, false);
70
105
  }
106
+ /**
107
+ * Updates matchers on the route. The method is invoked recursively to only update
108
+ * the matchers with the route class and not with the resource or the child
109
+ * group.
110
+ */
71
111
  #updateRouteMatchers(route, param, matcher) {
72
112
  if (route instanceof RouteGroup) {
73
113
  route.routes.forEach((child) => this.#updateRouteMatchers(child, param, matcher));
@@ -83,23 +123,68 @@ export class RouteGroup extends Macroable {
83
123
  }
84
124
  route.where(param, matcher);
85
125
  }
126
+ /**
127
+ * Define route param matcher
128
+ *
129
+ * ```ts
130
+ * Route.group(() => {
131
+ * }).where('id', /^[0-9]+/)
132
+ * ```
133
+ */
86
134
  where(param, matcher) {
87
135
  this.routes.forEach((route) => this.#updateRouteMatchers(route, param, matcher));
88
136
  return this;
89
137
  }
138
+ /**
139
+ * Define prefix all the routes in the group.
140
+ *
141
+ * ```ts
142
+ * Route.group(() => {
143
+ * }).prefix('v1')
144
+ * ```
145
+ */
90
146
  prefix(prefix) {
91
147
  this.routes.forEach((route) => this.#setRoutePrefix(route, prefix));
92
148
  return this;
93
149
  }
150
+ /**
151
+ * Define domain for all the routes.
152
+ *
153
+ * ```ts
154
+ * Route.group(() => {
155
+ * }).domain(':name.adonisjs.com')
156
+ * ```
157
+ */
94
158
  domain(domain) {
95
159
  this.routes.forEach((route) => this.#updateRouteDomain(route, domain));
96
160
  return this;
97
161
  }
162
+ /**
163
+ * Prepend name to the routes name.
164
+ *
165
+ * ```ts
166
+ * Route.group(() => {
167
+ * }).as('version1')
168
+ * ```
169
+ */
98
170
  as(name) {
99
171
  this.routes.forEach((route) => this.#updateRouteName(route, name));
100
172
  return this;
101
173
  }
174
+ /**
175
+ * Prepend an array of middleware to all routes middleware.
176
+ *
177
+ * ```ts
178
+ * Route.group(() => {
179
+ * }).use(middleware.auth())
180
+ * ```
181
+ */
102
182
  use(middleware) {
183
+ /**
184
+ * Register middleware with children. We share the group middleware
185
+ * array by reference, therefore have to register it only for the
186
+ * first time.
187
+ */
103
188
  if (!this.#middleware.length) {
104
189
  this.routes.forEach((route) => this.#shareMiddlewareStackWithRoutes(route));
105
190
  }
@@ -113,6 +198,9 @@ export class RouteGroup extends Macroable {
113
198
  }
114
199
  return this;
115
200
  }
201
+ /**
202
+ * @alias use
203
+ */
116
204
  middleware(middleware) {
117
205
  return this.use(middleware);
118
206
  }
@@ -2,17 +2,48 @@ import type { Encryption } from '@adonisjs/encryption';
2
2
  import type { Qs } from '../../qs.js';
3
3
  import { UrlBuilder } from './url_builder.js';
4
4
  import type { RouteJSON } from '../../types/route.js';
5
+ /**
6
+ * Lookup store exposes the API to lookup routes and
7
+ * make URLs for registered routes.
8
+ */
5
9
  export declare class LookupStore {
6
10
  #private;
7
11
  constructor(encryption: Encryption, qsParser: Qs);
12
+ /**
13
+ * Register route JSON payload
14
+ */
8
15
  register(route: RouteJSON): void;
16
+ /**
17
+ * Returns an instance of the URL builder for making
18
+ * route URIs
19
+ */
9
20
  builder(): UrlBuilder;
21
+ /**
22
+ * Returns an instance of the URL builder for a specific
23
+ * domain.
24
+ */
10
25
  builderForDomain(domain: string): UrlBuilder;
26
+ /**
27
+ * Finds a route by its identifier. The identifier can be the
28
+ * route name, controller.method name or the route pattern
29
+ * itself.
30
+ */
11
31
  find(routeIdentifier: string, domain?: string): RouteJSON | null;
32
+ /**
33
+ * Finds a route by its identifier. The identifier can be the
34
+ * route name, controller.method name or the route pattern
35
+ * itself.
36
+ *
37
+ * An error is raised when unable to find the route.
38
+ */
12
39
  findOrFail(routeIdentifier: string, domain?: string): RouteJSON;
40
+ /**
41
+ * Check if a route exists. The identifier can be the
42
+ * route name, controller.method name or the route pattern
43
+ * itself.
44
+ */
13
45
  has(routeIdentifier: string, domain?: string): boolean;
14
46
  toJSON(): {
15
47
  [domain: string]: RouteJSON[];
16
48
  };
17
49
  }
18
- //# sourceMappingURL=main.d.ts.map
@@ -1,32 +1,81 @@
1
+ /*
2
+ * @adonisjs/http-server
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  import { UrlBuilder } from './url_builder.js';
2
10
  import { RouteFinder } from './route_finder.js';
11
+ /**
12
+ * Lookup store exposes the API to lookup routes and
13
+ * make URLs for registered routes.
14
+ */
3
15
  export class LookupStore {
16
+ /**
17
+ * List of routes grouped by domain
18
+ */
4
19
  #routes = {};
20
+ /**
21
+ * Encryption for making URLs
22
+ */
5
23
  #encryption;
24
+ /**
25
+ * Query string parser for making URLs
26
+ */
6
27
  #qsParser;
7
28
  constructor(encryption, qsParser) {
8
29
  this.#encryption = encryption;
9
30
  this.#qsParser = qsParser;
10
31
  }
32
+ /**
33
+ * Register route JSON payload
34
+ */
11
35
  register(route) {
12
36
  this.#routes[route.domain] = this.#routes[route.domain] || [];
13
37
  this.#routes[route.domain].push(route);
14
38
  }
39
+ /**
40
+ * Returns an instance of the URL builder for making
41
+ * route URIs
42
+ */
15
43
  builder() {
16
44
  return this.builderForDomain('root');
17
45
  }
46
+ /**
47
+ * Returns an instance of the URL builder for a specific
48
+ * domain.
49
+ */
18
50
  builderForDomain(domain) {
19
51
  const routes = this.#routes[domain];
20
52
  return new UrlBuilder(this.#encryption, new RouteFinder(routes || []), this.#qsParser);
21
53
  }
54
+ /**
55
+ * Finds a route by its identifier. The identifier can be the
56
+ * route name, controller.method name or the route pattern
57
+ * itself.
58
+ */
22
59
  find(routeIdentifier, domain) {
23
60
  const routes = this.#routes[domain || 'root'] || [];
24
61
  return new RouteFinder(routes).find(routeIdentifier);
25
62
  }
63
+ /**
64
+ * Finds a route by its identifier. The identifier can be the
65
+ * route name, controller.method name or the route pattern
66
+ * itself.
67
+ *
68
+ * An error is raised when unable to find the route.
69
+ */
26
70
  findOrFail(routeIdentifier, domain) {
27
71
  const routes = this.#routes[domain || 'root'] || [];
28
72
  return new RouteFinder(routes).findOrFail(routeIdentifier);
29
73
  }
74
+ /**
75
+ * Check if a route exists. The identifier can be the
76
+ * route name, controller.method name or the route pattern
77
+ * itself.
78
+ */
30
79
  has(routeIdentifier, domain) {
31
80
  const routes = this.#routes[domain || 'root'] || [];
32
81
  return new RouteFinder(routes).has(routeIdentifier);
@@ -1,9 +1,21 @@
1
1
  import type { RouteJSON } from '../../types/route.js';
2
+ /**
3
+ * Route finder is used to find a route by its name, route pattern
4
+ * or the controller.method name.
5
+ */
2
6
  export declare class RouteFinder {
3
7
  #private;
4
8
  constructor(routes: RouteJSON[]);
9
+ /**
10
+ * Find a route by indentifier
11
+ */
5
12
  find(routeIdentifier: string): RouteJSON | null;
13
+ /**
14
+ * Find a route by indentifier or fail
15
+ */
6
16
  findOrFail(routeIdentifier: string): RouteJSON;
17
+ /**
18
+ * Find if a route exists
19
+ */
7
20
  has(routeIdentifier: string): boolean;
8
21
  }
9
- //# sourceMappingURL=route_finder.d.ts.map
@@ -1,9 +1,24 @@
1
+ /*
2
+ * @adonisjs/http-server
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  import * as errors from '../../exceptions.js';
10
+ /**
11
+ * Route finder is used to find a route by its name, route pattern
12
+ * or the controller.method name.
13
+ */
2
14
  export class RouteFinder {
3
15
  #routes;
4
16
  constructor(routes) {
5
17
  this.#routes = routes;
6
18
  }
19
+ /**
20
+ * Find a route by indentifier
21
+ */
7
22
  find(routeIdentifier) {
8
23
  return (this.#routes.find(({ name, pattern, handler }) => {
9
24
  if (name === routeIdentifier || pattern === routeIdentifier) {
@@ -15,6 +30,9 @@ export class RouteFinder {
15
30
  return handler.reference === routeIdentifier;
16
31
  }) || null);
17
32
  }
33
+ /**
34
+ * Find a route by indentifier or fail
35
+ */
18
36
  findOrFail(routeIdentifier) {
19
37
  const route = this.find(routeIdentifier);
20
38
  if (!route) {
@@ -22,6 +40,9 @@ export class RouteFinder {
22
40
  }
23
41
  return route;
24
42
  }
43
+ /**
44
+ * Find if a route exists
45
+ */
25
46
  has(routeIdentifier) {
26
47
  return !!this.find(routeIdentifier);
27
48
  }
@@ -1,17 +1,52 @@
1
1
  import type { Encryption } from '@adonisjs/encryption';
2
2
  import type { Qs } from '../../qs.js';
3
3
  import type { RouteFinder } from './route_finder.js';
4
+ /**
5
+ * URL builder class is used to create URIs for pre-registered
6
+ * routes.
7
+ *
8
+ * ```ts
9
+ * const builder = new UrlBuilder(encryption, routeFinder)
10
+ *
11
+ * builder
12
+ * .qs({ sort: 'id' })
13
+ * .params([category.id])
14
+ * .make('categories.posts.index')
15
+ * ```
16
+ */
4
17
  export declare class UrlBuilder {
5
18
  #private;
6
19
  constructor(encryption: Encryption, routeFinder: RouteFinder, qsParser: Qs);
20
+ /**
21
+ * Prefix a custom base URL to the final URI
22
+ */
7
23
  prefixUrl(url: string): this;
24
+ /**
25
+ * Disable route lookup. Calling this method considers
26
+ * the "identifier" as the route pattern
27
+ */
8
28
  disableRouteLookup(): this;
29
+ /**
30
+ * Append query string to the final URI
31
+ */
9
32
  qs(queryString?: Record<string, any>): this;
33
+ /**
34
+ * Specify params to apply to the route pattern
35
+ */
10
36
  params(params?: any[] | Record<string, any>): this;
37
+ /**
38
+ * Generate URL for the given route identifier. The identifier can be the
39
+ * route name, controller.method name or the route pattern
40
+ * itself.
41
+ */
11
42
  make(identifier: string): string;
43
+ /**
44
+ * Generate a signed URL for the given route identifier. The identifier can be the
45
+ * route name, controller.method name or the route pattern
46
+ * itself.
47
+ */
12
48
  makeSigned(identifier: string, options?: {
13
49
  expiresIn?: string | number;
14
50
  purpose?: string;
15
51
  }): string;
16
52
  }
17
- //# sourceMappingURL=url_builder.d.ts.map