@adonisjs/http-server 6.8.2-0 → 6.8.2-10

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 (103) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +3 -6
  3. package/build/factories/http_context.d.ts +10 -0
  4. package/build/factories/http_context.js +27 -0
  5. package/build/factories/http_server.d.ts +8 -0
  6. package/build/factories/http_server.js +26 -0
  7. package/build/factories/main.js +8 -0
  8. package/build/factories/qs_parser_factory.d.ts +10 -0
  9. package/build/factories/qs_parser_factory.js +18 -0
  10. package/build/factories/request.d.ts +10 -0
  11. package/build/factories/request.js +31 -0
  12. package/build/factories/response.d.ts +10 -0
  13. package/build/factories/response.js +34 -0
  14. package/build/factories/router.d.ts +10 -0
  15. package/build/factories/router.js +25 -0
  16. package/build/factories/server_factory.d.ts +10 -0
  17. package/build/factories/server_factory.js +34 -0
  18. package/build/index.js +8 -0
  19. package/build/src/cookies/client.d.ts +25 -0
  20. package/build/src/cookies/client.js +42 -0
  21. package/build/src/cookies/drivers/encrypted.d.ts +12 -0
  22. package/build/src/cookies/drivers/encrypted.js +20 -0
  23. package/build/src/cookies/drivers/plain.d.ts +12 -0
  24. package/build/src/cookies/drivers/plain.js +20 -0
  25. package/build/src/cookies/drivers/signed.d.ts +12 -0
  26. package/build/src/cookies/drivers/signed.js +20 -0
  27. package/build/src/cookies/parser.d.ts +28 -0
  28. package/build/src/cookies/parser.js +98 -0
  29. package/build/src/cookies/serializer.d.ts +22 -0
  30. package/build/src/cookies/serializer.js +40 -0
  31. package/build/src/debug.js +8 -0
  32. package/build/src/define_config.d.ts +3 -0
  33. package/build/src/define_config.js +11 -0
  34. package/build/src/define_middleware.d.ts +5 -0
  35. package/build/src/define_middleware.js +18 -0
  36. package/build/src/exception_handler.d.ts +93 -6
  37. package/build/src/exception_handler.js +203 -44
  38. package/build/src/exceptions.d.ts +6 -0
  39. package/build/src/exceptions.js +11 -0
  40. package/build/src/helpers.d.ts +14 -0
  41. package/build/src/helpers.js +43 -0
  42. package/build/src/http_context/local_storage.d.ts +3 -0
  43. package/build/src/http_context/local_storage.js +25 -0
  44. package/build/src/http_context/main.d.ts +36 -0
  45. package/build/src/http_context/main.js +54 -0
  46. package/build/src/qs.d.ts +4 -0
  47. package/build/src/qs.js +12 -0
  48. package/build/src/redirect.d.ts +24 -0
  49. package/build/src/redirect.js +60 -0
  50. package/build/src/request.d.ts +466 -0
  51. package/build/src/request.js +544 -2
  52. package/build/src/response.d.ts +425 -1
  53. package/build/src/response.js +611 -11
  54. package/build/src/router/brisk.d.ts +22 -0
  55. package/build/src/router/brisk.js +44 -2
  56. package/build/src/router/executor.d.ts +6 -1
  57. package/build/src/router/executor.js +14 -1
  58. package/build/src/router/factories/use_return_value.d.ts +4 -0
  59. package/build/src/router/factories/use_return_value.js +16 -3
  60. package/build/src/router/group.d.ts +47 -0
  61. package/build/src/router/group.js +88 -0
  62. package/build/src/router/lookup_store/main.d.ts +32 -0
  63. package/build/src/router/lookup_store/main.js +49 -0
  64. package/build/src/router/lookup_store/route_finder.d.ts +13 -0
  65. package/build/src/router/lookup_store/route_finder.js +21 -0
  66. package/build/src/router/lookup_store/url_builder.d.ts +36 -0
  67. package/build/src/router/lookup_store/url_builder.js +99 -2
  68. package/build/src/router/main.d.ts +92 -4
  69. package/build/src/router/main.js +146 -0
  70. package/build/src/router/matchers.d.ts +13 -0
  71. package/build/src/router/matchers.js +21 -0
  72. package/build/src/router/parser.d.ts +5 -0
  73. package/build/src/router/parser.js +17 -0
  74. package/build/src/router/resource.d.ts +30 -1
  75. package/build/src/router/resource.js +93 -1
  76. package/build/src/router/route.d.ts +65 -0
  77. package/build/src/router/route.js +151 -2
  78. package/build/src/router/store.d.ts +54 -0
  79. package/build/src/router/store.js +110 -2
  80. package/build/src/server/factories/final_handler.d.ts +7 -1
  81. package/build/src/server/factories/final_handler.js +15 -2
  82. package/build/src/server/factories/middleware_handler.d.ts +3 -0
  83. package/build/src/server/factories/middleware_handler.js +11 -0
  84. package/build/src/server/factories/write_response.d.ts +4 -0
  85. package/build/src/server/factories/write_response.js +12 -0
  86. package/build/src/server/main.d.ts +48 -0
  87. package/build/src/server/main.js +142 -5
  88. package/build/src/types/base.d.ts +12 -0
  89. package/build/src/types/base.js +8 -0
  90. package/build/src/types/main.js +8 -0
  91. package/build/src/types/middleware.d.ts +18 -0
  92. package/build/src/types/middleware.js +8 -0
  93. package/build/src/types/qs.d.ts +53 -0
  94. package/build/src/types/qs.js +8 -0
  95. package/build/src/types/request.d.ts +32 -0
  96. package/build/src/types/request.js +8 -0
  97. package/build/src/types/response.d.ts +27 -0
  98. package/build/src/types/response.js +8 -0
  99. package/build/src/types/route.d.ts +89 -1
  100. package/build/src/types/route.js +8 -0
  101. package/build/src/types/server.d.ts +36 -1
  102. package/build/src/types/server.js +8 -0
  103. package/package.json +53 -76
package/build/src/qs.js CHANGED
@@ -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 { parse, stringify } from 'qs';
10
+ /**
11
+ * Query string parser used to parse and stringify query
12
+ * strings.
13
+ */
2
14
  export class Qs {
3
15
  #config;
4
16
  constructor(config) {
@@ -4,15 +4,39 @@ import type { Qs } from './qs.js';
4
4
  import type { Response } from './response.js';
5
5
  import type { Router } from './router/main.js';
6
6
  import type { MakeUrlOptions } from './types/route.js';
7
+ /**
8
+ * Exposes the API to construct redirect routes
9
+ */
7
10
  export declare class Redirect {
8
11
  #private;
9
12
  constructor(request: IncomingMessage, response: Response, router: Router, qs: Qs);
13
+ /**
14
+ * Set a custom status code.
15
+ */
10
16
  status(statusCode: number): this;
17
+ /**
18
+ * Clearing query string values added using the
19
+ * "withQs" method
20
+ */
11
21
  clearQs(): this;
22
+ /**
23
+ * Define query string for the redirect. Not passing
24
+ * any value will forward the current request query
25
+ * string.
26
+ */
12
27
  withQs(): this;
13
28
  withQs(values: Record<string, any>): this;
14
29
  withQs(name: string, value: any): this;
30
+ /**
31
+ * Redirect to the previous path.
32
+ */
15
33
  back(): void;
34
+ /**
35
+ * Redirect the request using a route identifier.
36
+ */
16
37
  toRoute(routeIdentifier: string, params?: any[] | Record<string, any>, options?: MakeUrlOptions): void;
38
+ /**
39
+ * Redirect the request using a path.
40
+ */
17
41
  toPath(url: string): void;
18
42
  }
@@ -1,9 +1,29 @@
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 { parse } from 'node:url';
2
10
  import encodeUrl from 'encodeurl';
3
11
  import debug from './debug.js';
12
+ /**
13
+ * Exposes the API to construct redirect routes
14
+ */
4
15
  export class Redirect {
16
+ /**
17
+ * A boolean to forward the existing query string
18
+ */
5
19
  #forwardQueryString = false;
20
+ /**
21
+ * The status code for the redirect
22
+ */
6
23
  #statusCode = 302;
24
+ /**
25
+ * A custom query string to forward
26
+ */
7
27
  #queryString = {};
8
28
  #request;
9
29
  #response;
@@ -15,6 +35,9 @@ export class Redirect {
15
35
  this.#router = router;
16
36
  this.#qs = qs;
17
37
  }
38
+ /**
39
+ * Sends response by setting require headers
40
+ */
18
41
  #sendResponse(url, query) {
19
42
  const stringified = this.#qs.stringify(query);
20
43
  url = stringified ? `${url}?${stringified}` : url;
@@ -24,14 +47,24 @@ export class Redirect {
24
47
  this.#response.type('text/plain; charset=utf-8');
25
48
  this.#response.send(`Redirecting to ${url}`);
26
49
  }
50
+ /**
51
+ * Returns the referrer url
52
+ */
27
53
  #getReferrerUrl() {
28
54
  let url = this.#request.headers['referer'] || this.#request.headers['referrer'] || '/';
29
55
  return Array.isArray(url) ? url[0] : url;
30
56
  }
57
+ /**
58
+ * Set a custom status code.
59
+ */
31
60
  status(statusCode) {
32
61
  this.#statusCode = statusCode;
33
62
  return this;
34
63
  }
64
+ /**
65
+ * Clearing query string values added using the
66
+ * "withQs" method
67
+ */
35
68
  clearQs() {
36
69
  this.#forwardQueryString = false;
37
70
  this.#queryString = {};
@@ -49,18 +82,33 @@ export class Redirect {
49
82
  Object.assign(this.#queryString, name);
50
83
  return this;
51
84
  }
85
+ /**
86
+ * Redirect to the previous path.
87
+ */
52
88
  back() {
53
89
  let query = {};
54
90
  const referrerUrl = this.#getReferrerUrl();
55
91
  const url = parse(referrerUrl);
56
92
  debug('referrer url "%s"', referrerUrl);
57
93
  debug('referrer base url "%s"', url.pathname);
94
+ /**
95
+ * Parse query string from the referrer url
96
+ */
58
97
  if (this.#forwardQueryString) {
59
98
  query = this.#qs.parse(url.query || '');
60
99
  }
100
+ /**
101
+ * Append custom query string
102
+ */
61
103
  Object.assign(query, this.#queryString);
104
+ /**
105
+ * Redirect
106
+ */
62
107
  this.#sendResponse(url.pathname || '', query);
63
108
  }
109
+ /**
110
+ * Redirect the request using a route identifier.
111
+ */
64
112
  toRoute(routeIdentifier, params, options) {
65
113
  if (options && options.qs) {
66
114
  this.withQs(options.qs);
@@ -69,12 +117,24 @@ export class Redirect {
69
117
  const url = this.#router.makeUrl(routeIdentifier, params, options);
70
118
  return this.toPath(url);
71
119
  }
120
+ /**
121
+ * Redirect the request using a path.
122
+ */
72
123
  toPath(url) {
73
124
  let query = {};
125
+ /**
126
+ * Extract query string from the current URL
127
+ */
74
128
  if (this.#forwardQueryString) {
75
129
  query = this.#qs.parse(parse(this.#request.url).query || '');
76
130
  }
131
+ /**
132
+ * Assign custom query string
133
+ */
77
134
  Object.assign(query, this.#queryString);
135
+ /**
136
+ * Redirect
137
+ */
78
138
  this.#sendResponse(url, query);
79
139
  }
80
140
  }