@adonisjs/http-server 7.0.0-0 → 7.0.0-1

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 (107) hide show
  1. package/build/factories/http_context.d.ts +25 -0
  2. package/build/factories/http_context.js +51 -0
  3. package/build/factories/http_server.d.ts +8 -0
  4. package/build/factories/http_server.js +26 -0
  5. package/build/factories/main.d.ts +6 -149
  6. package/build/factories/main.js +14 -331
  7. package/build/factories/qs_parser_factory.d.ts +20 -0
  8. package/build/factories/qs_parser_factory.js +44 -0
  9. package/build/factories/request.d.ts +29 -0
  10. package/build/factories/request.js +73 -0
  11. package/build/factories/response.d.ts +29 -0
  12. package/build/factories/response.js +77 -0
  13. package/build/factories/router.d.ts +23 -0
  14. package/build/factories/router.js +45 -0
  15. package/build/factories/server_factory.d.ts +29 -0
  16. package/build/factories/server_factory.js +65 -0
  17. package/build/index.d.ts +14 -272
  18. package/build/index.js +22 -308
  19. package/build/src/cookies/client.d.ts +37 -0
  20. package/build/src/cookies/client.js +84 -0
  21. package/build/src/cookies/drivers/encrypted.d.ts +16 -0
  22. package/build/src/cookies/drivers/encrypted.js +36 -0
  23. package/build/src/cookies/drivers/plain.d.ts +15 -0
  24. package/build/src/cookies/drivers/plain.js +33 -0
  25. package/build/src/cookies/drivers/signed.d.ts +16 -0
  26. package/build/src/cookies/drivers/signed.js +36 -0
  27. package/build/src/cookies/parser.d.ts +37 -0
  28. package/build/src/cookies/parser.js +167 -0
  29. package/build/src/cookies/serializer.d.ts +33 -0
  30. package/build/src/cookies/serializer.js +79 -0
  31. package/build/src/debug.d.ts +3 -0
  32. package/build/src/debug.js +10 -0
  33. package/build/src/define_config.d.ts +9 -0
  34. package/build/src/define_config.js +68 -0
  35. package/build/src/define_middleware.d.ts +11 -0
  36. package/build/src/define_middleware.js +35 -0
  37. package/build/src/exception_handler.d.ts +113 -0
  38. package/build/src/exception_handler.js +306 -0
  39. package/build/src/exceptions.d.ts +84 -0
  40. package/build/src/exceptions.js +38 -0
  41. package/build/src/helpers.d.ts +23 -0
  42. package/build/src/helpers.js +105 -0
  43. package/build/src/http_context/local_storage.d.ts +12 -0
  44. package/build/src/http_context/local_storage.js +39 -0
  45. package/build/src/http_context/main.d.ts +58 -0
  46. package/build/src/http_context/main.js +105 -0
  47. package/build/src/qs.d.ts +11 -0
  48. package/build/src/qs.js +25 -0
  49. package/build/src/redirect.d.ts +42 -0
  50. package/build/src/redirect.js +140 -0
  51. package/build/src/request.d.ts +565 -0
  52. package/build/src/request.js +865 -0
  53. package/build/src/response.d.ts +620 -0
  54. package/build/src/response.js +1208 -0
  55. package/build/src/router/brisk.d.ts +42 -0
  56. package/build/src/router/brisk.js +85 -0
  57. package/build/src/router/executor.d.ts +9 -0
  58. package/build/src/router/executor.js +30 -0
  59. package/build/src/router/factories/use_return_value.d.ts +6 -0
  60. package/build/src/router/factories/use_return_value.js +22 -0
  61. package/build/src/router/group.d.ts +65 -0
  62. package/build/src/router/group.js +207 -0
  63. package/build/src/router/lookup_store/main.d.ts +49 -0
  64. package/build/src/router/lookup_store/main.js +86 -0
  65. package/build/src/router/lookup_store/route_finder.d.ts +21 -0
  66. package/build/src/router/lookup_store/route_finder.js +49 -0
  67. package/build/src/router/lookup_store/url_builder.d.ts +52 -0
  68. package/build/src/router/lookup_store/url_builder.js +209 -0
  69. package/build/src/router/main.d.ts +128 -0
  70. package/build/src/router/main.js +316 -0
  71. package/build/src/router/matchers.d.ts +27 -0
  72. package/build/src/router/matchers.js +36 -0
  73. package/build/src/router/parser.d.ts +5 -0
  74. package/build/src/router/parser.js +17 -0
  75. package/build/src/router/resource.d.ts +54 -0
  76. package/build/src/router/resource.js +216 -0
  77. package/build/src/router/route.d.ts +92 -0
  78. package/build/src/router/route.js +293 -0
  79. package/build/src/router/store.d.ts +66 -0
  80. package/build/src/router/store.js +195 -0
  81. package/build/src/server/factories/final_handler.d.ts +10 -0
  82. package/build/src/server/factories/final_handler.js +30 -0
  83. package/build/src/server/factories/middleware_handler.d.ts +8 -0
  84. package/build/src/server/factories/middleware_handler.js +16 -0
  85. package/build/src/server/factories/write_response.d.ts +6 -0
  86. package/build/src/server/factories/write_response.js +24 -0
  87. package/build/{main-29eaaee4.d.ts → src/server/main.d.ts} +18 -13
  88. package/build/src/server/main.js +292 -0
  89. package/build/src/types/base.d.ts +19 -0
  90. package/build/src/types/base.js +9 -0
  91. package/build/src/types/main.d.ts +7 -14
  92. package/build/src/types/main.js +15 -0
  93. package/build/src/types/middleware.d.ts +35 -0
  94. package/build/src/types/middleware.js +9 -0
  95. package/build/src/types/qs.d.ts +68 -0
  96. package/build/src/types/qs.js +9 -0
  97. package/build/src/types/request.d.ts +39 -0
  98. package/build/src/types/request.js +9 -0
  99. package/build/src/types/response.d.ts +45 -0
  100. package/build/src/types/response.js +9 -0
  101. package/build/src/types/route.d.ts +166 -0
  102. package/build/src/types/route.js +9 -0
  103. package/build/src/types/server.d.ts +72 -0
  104. package/build/src/types/server.js +9 -0
  105. package/package.json +6 -3
  106. package/build/chunk-XX72ATFY.js +0 -4388
  107. package/build/main-e5b46c83.d.ts +0 -2210
@@ -0,0 +1,105 @@
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
+ import { inspect } from 'node:util';
10
+ import Macroable from '@poppinss/macroable';
11
+ import { RuntimeException } from '@poppinss/utils';
12
+ import { asyncLocalStorage } from './local_storage.js';
13
+ /**
14
+ * Http context encapsulates properties for a given HTTP request. The
15
+ * context class can be extended using macros and getters.
16
+ */
17
+ export class HttpContext extends Macroable {
18
+ request;
19
+ response;
20
+ logger;
21
+ containerResolver;
22
+ /**
23
+ * Find if async localstorage is enabled for HTTP requests
24
+ * or not
25
+ */
26
+ static get usingAsyncLocalStorage() {
27
+ return asyncLocalStorage.isEnabled;
28
+ }
29
+ /**
30
+ * Get access to the HTTP context. Available only when
31
+ * "usingAsyncLocalStorage" is true
32
+ */
33
+ static get() {
34
+ if (!this.usingAsyncLocalStorage || !asyncLocalStorage.storage) {
35
+ return null;
36
+ }
37
+ return asyncLocalStorage.storage.getStore() || null;
38
+ }
39
+ /**
40
+ * Get the HttpContext instance or raise an exception if not
41
+ * available
42
+ */
43
+ static getOrFail() {
44
+ /**
45
+ * Localstorage is not enabled
46
+ */
47
+ if (!this.usingAsyncLocalStorage || !asyncLocalStorage.storage) {
48
+ throw new RuntimeException('HTTP context is not available. Enable "useAsyncLocalStorage" inside "config/app.ts" file');
49
+ }
50
+ const store = this.get();
51
+ if (!store) {
52
+ throw new RuntimeException('Http context is not available outside of an HTTP request');
53
+ }
54
+ return store;
55
+ }
56
+ /**
57
+ * Run a method that doesn't have access to HTTP context from
58
+ * the async local storage.
59
+ */
60
+ static runOutsideContext(callback, ...args) {
61
+ if (!asyncLocalStorage.storage) {
62
+ return callback(...args);
63
+ }
64
+ return asyncLocalStorage.storage.exit(callback, ...args);
65
+ }
66
+ /**
67
+ * Reference to the current route. Not available inside
68
+ * server middleware
69
+ */
70
+ route;
71
+ /**
72
+ * A unique key for the current route
73
+ */
74
+ routeKey;
75
+ /**
76
+ * Route params
77
+ */
78
+ params = {};
79
+ /**
80
+ * Route subdomains
81
+ */
82
+ subdomains = {};
83
+ constructor(request, response, logger, containerResolver) {
84
+ super();
85
+ this.request = request;
86
+ this.response = response;
87
+ this.logger = logger;
88
+ this.containerResolver = containerResolver;
89
+ /*
90
+ * Creating the circular reference. We do this, since request and response
91
+ * are meant to be extended and at times people would want to access
92
+ * other ctx properties like `logger`, `profiler` inside those
93
+ * extended methods.
94
+ */
95
+ this.request.ctx = this;
96
+ this.response.ctx = this;
97
+ }
98
+ /**
99
+ * A helper to see top level properties on the context object
100
+ */
101
+ /* c8 ignore next 3 */
102
+ inspect() {
103
+ return inspect(this, false, 1, true);
104
+ }
105
+ }
@@ -0,0 +1,11 @@
1
+ import { QSParserConfig } from './types/qs.js';
2
+ /**
3
+ * Query string parser used to parse and stringify query
4
+ * strings.
5
+ */
6
+ export declare class Qs {
7
+ #private;
8
+ constructor(config: QSParserConfig);
9
+ parse(value: string): import("qs").ParsedQs;
10
+ stringify(value: any): string;
11
+ }
@@ -0,0 +1,25 @@
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
+ import { parse, stringify } from 'qs';
10
+ /**
11
+ * Query string parser used to parse and stringify query
12
+ * strings.
13
+ */
14
+ export class Qs {
15
+ #config;
16
+ constructor(config) {
17
+ this.#config = config;
18
+ }
19
+ parse(value) {
20
+ return parse(value, this.#config.parse);
21
+ }
22
+ stringify(value) {
23
+ return stringify(value, this.#config.stringify);
24
+ }
25
+ }
@@ -0,0 +1,42 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { IncomingMessage } from 'node:http';
3
+ import type { Qs } from './qs.js';
4
+ import type { Response } from './response.js';
5
+ import type { Router } from './router/main.js';
6
+ import type { MakeUrlOptions } from './types/route.js';
7
+ /**
8
+ * Exposes the API to construct redirect routes
9
+ */
10
+ export declare class Redirect {
11
+ #private;
12
+ constructor(request: IncomingMessage, response: Response, router: Router, qs: Qs);
13
+ /**
14
+ * Set a custom status code.
15
+ */
16
+ status(statusCode: number): this;
17
+ /**
18
+ * Clearing query string values added using the
19
+ * "withQs" method
20
+ */
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
+ */
27
+ withQs(): this;
28
+ withQs(values: Record<string, any>): this;
29
+ withQs(name: string, value: any): this;
30
+ /**
31
+ * Redirect to the previous path.
32
+ */
33
+ back(): void;
34
+ /**
35
+ * Redirect the request using a route identifier.
36
+ */
37
+ toRoute(routeIdentifier: string, params?: any[] | Record<string, any>, options?: MakeUrlOptions): void;
38
+ /**
39
+ * Redirect the request using a path.
40
+ */
41
+ toPath(url: string): void;
42
+ }
@@ -0,0 +1,140 @@
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
+ import { parse } from 'node:url';
10
+ import encodeUrl from 'encodeurl';
11
+ import debug from './debug.js';
12
+ /**
13
+ * Exposes the API to construct redirect routes
14
+ */
15
+ export class Redirect {
16
+ /**
17
+ * A boolean to forward the existing query string
18
+ */
19
+ #forwardQueryString = false;
20
+ /**
21
+ * The status code for the redirect
22
+ */
23
+ #statusCode = 302;
24
+ /**
25
+ * A custom query string to forward
26
+ */
27
+ #queryString = {};
28
+ #request;
29
+ #response;
30
+ #router;
31
+ #qs;
32
+ constructor(request, response, router, qs) {
33
+ this.#request = request;
34
+ this.#response = response;
35
+ this.#router = router;
36
+ this.#qs = qs;
37
+ }
38
+ /**
39
+ * Sends response by setting require headers
40
+ */
41
+ #sendResponse(url, query) {
42
+ const stringified = this.#qs.stringify(query);
43
+ url = stringified ? `${url}?${stringified}` : url;
44
+ debug('redirecting to url "%s"', url);
45
+ this.#response.location(encodeUrl(url));
46
+ this.#response.safeStatus(this.#statusCode);
47
+ this.#response.type('text/plain; charset=utf-8');
48
+ this.#response.send(`Redirecting to ${url}`);
49
+ }
50
+ /**
51
+ * Returns the referrer url
52
+ */
53
+ #getReferrerUrl() {
54
+ let url = this.#request.headers['referer'] || this.#request.headers['referrer'] || '/';
55
+ return Array.isArray(url) ? url[0] : url;
56
+ }
57
+ /**
58
+ * Set a custom status code.
59
+ */
60
+ status(statusCode) {
61
+ this.#statusCode = statusCode;
62
+ return this;
63
+ }
64
+ /**
65
+ * Clearing query string values added using the
66
+ * "withQs" method
67
+ */
68
+ clearQs() {
69
+ this.#forwardQueryString = false;
70
+ this.#queryString = {};
71
+ return this;
72
+ }
73
+ withQs(name, value) {
74
+ if (typeof name === 'undefined') {
75
+ this.#forwardQueryString = true;
76
+ return this;
77
+ }
78
+ if (typeof name === 'string') {
79
+ this.#queryString[name] = value;
80
+ return this;
81
+ }
82
+ Object.assign(this.#queryString, name);
83
+ return this;
84
+ }
85
+ /**
86
+ * Redirect to the previous path.
87
+ */
88
+ back() {
89
+ let query = {};
90
+ const referrerUrl = this.#getReferrerUrl();
91
+ const url = parse(referrerUrl);
92
+ debug('referrer url "%s"', referrerUrl);
93
+ debug('referrer base url "%s"', url.pathname);
94
+ /**
95
+ * Parse query string from the referrer url
96
+ */
97
+ if (this.#forwardQueryString) {
98
+ query = this.#qs.parse(url.query || '');
99
+ }
100
+ /**
101
+ * Append custom query string
102
+ */
103
+ Object.assign(query, this.#queryString);
104
+ /**
105
+ * Redirect
106
+ */
107
+ this.#sendResponse(url.pathname || '', query);
108
+ }
109
+ /**
110
+ * Redirect the request using a route identifier.
111
+ */
112
+ toRoute(routeIdentifier, params, options) {
113
+ if (options && options.qs) {
114
+ this.withQs(options.qs);
115
+ options.qs = undefined;
116
+ }
117
+ const url = this.#router.makeUrl(routeIdentifier, params, options);
118
+ return this.toPath(url);
119
+ }
120
+ /**
121
+ * Redirect the request using a path.
122
+ */
123
+ toPath(url) {
124
+ let query = {};
125
+ /**
126
+ * Extract query string from the current URL
127
+ */
128
+ if (this.#forwardQueryString) {
129
+ query = this.#qs.parse(parse(this.#request.url).query || '');
130
+ }
131
+ /**
132
+ * Assign custom query string
133
+ */
134
+ Object.assign(query, this.#queryString);
135
+ /**
136
+ * Redirect
137
+ */
138
+ this.#sendResponse(url, query);
139
+ }
140
+ }