@adonisjs/http-server 5.12.0 → 6.0.1-0

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 (171) hide show
  1. package/README.md +15 -38
  2. package/build/index.d.ts +16 -0
  3. package/build/index.js +16 -0
  4. package/build/src/cookies/client.d.ts +12 -0
  5. package/build/src/cookies/client.js +42 -0
  6. package/build/src/cookies/drivers/encrypted.d.ts +4 -0
  7. package/build/src/cookies/drivers/encrypted.js +16 -0
  8. package/build/src/cookies/drivers/plain.d.ts +3 -0
  9. package/build/src/cookies/drivers/plain.js +13 -0
  10. package/build/src/cookies/drivers/signed.d.ts +4 -0
  11. package/build/src/cookies/drivers/signed.js +16 -0
  12. package/build/src/cookies/parser.d.ts +9 -0
  13. package/build/src/cookies/parser.js +69 -0
  14. package/build/src/cookies/serializer.d.ts +11 -0
  15. package/build/src/cookies/serializer.js +39 -0
  16. package/build/src/debug.d.ts +3 -0
  17. package/build/src/debug.js +2 -0
  18. package/build/src/define_config.d.ts +2 -0
  19. package/build/src/define_config.js +40 -0
  20. package/build/src/define_middleware.d.ts +4 -0
  21. package/build/src/define_middleware.js +6 -0
  22. package/build/src/exceptions/abort_exception.d.ts +5 -0
  23. package/build/src/exceptions/abort_exception.js +6 -0
  24. package/build/src/exceptions/cannot_lookup_route.d.ts +5 -0
  25. package/build/src/exceptions/cannot_lookup_route.js +5 -0
  26. package/build/src/exceptions/http_exception.d.ts +6 -0
  27. package/build/src/exceptions/http_exception.js +20 -0
  28. package/build/src/exceptions/route_not_found.d.ts +5 -0
  29. package/build/src/exceptions/route_not_found.js +5 -0
  30. package/build/src/helpers.d.ts +6 -67
  31. package/build/src/helpers.js +13 -168
  32. package/build/src/http_context/local_storage.d.ts +9 -0
  33. package/build/src/http_context/local_storage.js +14 -0
  34. package/build/src/http_context/main.d.ts +20 -0
  35. package/build/src/http_context/main.js +49 -0
  36. package/build/src/middleware/store.d.ts +11 -0
  37. package/build/src/middleware/store.js +33 -0
  38. package/build/src/qs.d.ts +7 -0
  39. package/build/src/qs.js +13 -0
  40. package/build/src/redirect.d.ts +18 -0
  41. package/build/src/redirect.js +80 -0
  42. package/build/src/request.d.ts +81 -0
  43. package/build/src/request.js +315 -0
  44. package/build/src/response.d.ts +108 -0
  45. package/build/src/response.js +587 -0
  46. package/build/src/router/brisk.d.ts +18 -0
  47. package/build/src/router/brisk.js +35 -0
  48. package/build/src/router/executor.d.ts +4 -0
  49. package/build/src/router/executor.js +16 -0
  50. package/build/src/router/group.d.ts +19 -0
  51. package/build/src/router/group.js +117 -0
  52. package/build/src/router/lookup_store/main.d.ts +17 -0
  53. package/build/src/router/lookup_store/main.js +37 -0
  54. package/build/src/router/lookup_store/route_finder.d.ts +8 -0
  55. package/build/src/router/lookup_store/route_finder.js +28 -0
  56. package/build/src/router/lookup_store/url_builder.d.ts +16 -0
  57. package/build/src/router/lookup_store/url_builder.js +111 -0
  58. package/build/src/router/main.d.ts +36 -0
  59. package/build/src/router/main.js +161 -0
  60. package/build/src/router/matchers.d.ts +14 -0
  61. package/build/src/router/matchers.js +15 -0
  62. package/build/src/router/resource.d.ts +27 -0
  63. package/build/src/router/resource.js +124 -0
  64. package/build/src/router/route.d.ts +28 -0
  65. package/build/src/router/route.js +135 -0
  66. package/build/src/router/store.d.ts +12 -0
  67. package/build/src/router/store.js +87 -0
  68. package/build/src/server/factories/final_handler.d.ts +4 -0
  69. package/build/src/server/factories/final_handler.js +17 -0
  70. package/build/src/server/factories/middleware_handler.d.ts +5 -0
  71. package/build/src/server/factories/middleware_handler.js +5 -0
  72. package/build/src/server/factories/use_return_value.d.ts +2 -0
  73. package/build/src/server/factories/use_return_value.js +9 -0
  74. package/build/src/server/factories/write_response.d.ts +2 -0
  75. package/build/src/server/factories/write_response.js +12 -0
  76. package/build/src/server/main.d.ts +23 -0
  77. package/build/src/server/main.js +124 -0
  78. package/build/src/types/base.d.ts +5 -0
  79. package/build/src/types/base.js +1 -0
  80. package/build/src/types/main.d.ts +7 -0
  81. package/build/src/types/main.js +7 -0
  82. package/build/src/types/middleware.d.ts +14 -0
  83. package/build/src/types/middleware.js +1 -0
  84. package/build/src/types/qs.d.ts +15 -0
  85. package/build/src/types/qs.js +1 -0
  86. package/build/src/types/request.d.ts +7 -0
  87. package/build/src/types/request.js +1 -0
  88. package/build/src/types/response.d.ts +18 -0
  89. package/build/src/types/response.js +1 -0
  90. package/build/src/types/route.d.ts +74 -0
  91. package/build/src/types/route.js +1 -0
  92. package/build/src/types/server.d.ts +13 -0
  93. package/build/src/types/server.js +1 -0
  94. package/package.json +88 -86
  95. package/build/adonis-typings/container.d.ts +0 -24
  96. package/build/adonis-typings/container.js +0 -8
  97. package/build/adonis-typings/context.d.ts +0 -73
  98. package/build/adonis-typings/context.js +0 -8
  99. package/build/adonis-typings/cookie-client.d.ts +0 -34
  100. package/build/adonis-typings/cookie-client.js +0 -8
  101. package/build/adonis-typings/http-server.d.ts +0 -98
  102. package/build/adonis-typings/http-server.js +0 -8
  103. package/build/adonis-typings/index.d.ts +0 -16
  104. package/build/adonis-typings/index.js +0 -16
  105. package/build/adonis-typings/middleware.d.ts +0 -95
  106. package/build/adonis-typings/middleware.js +0 -8
  107. package/build/adonis-typings/request.d.ts +0 -556
  108. package/build/adonis-typings/request.js +0 -8
  109. package/build/adonis-typings/response.d.ts +0 -440
  110. package/build/adonis-typings/response.js +0 -8
  111. package/build/adonis-typings/route.d.ts +0 -559
  112. package/build/adonis-typings/route.js +0 -8
  113. package/build/exceptions.json +0 -110
  114. package/build/providers/HttpServerProvider.d.ts +0 -46
  115. package/build/providers/HttpServerProvider.js +0 -100
  116. package/build/src/Cookie/Client/index.d.ts +0 -39
  117. package/build/src/Cookie/Client/index.js +0 -108
  118. package/build/src/Cookie/Drivers/Encrypted.d.ts +0 -24
  119. package/build/src/Cookie/Drivers/Encrypted.js +0 -42
  120. package/build/src/Cookie/Drivers/Plain.d.ts +0 -23
  121. package/build/src/Cookie/Drivers/Plain.js +0 -40
  122. package/build/src/Cookie/Drivers/Signed.d.ts +0 -24
  123. package/build/src/Cookie/Drivers/Signed.js +0 -42
  124. package/build/src/Cookie/Parser/index.d.ts +0 -61
  125. package/build/src/Cookie/Parser/index.js +0 -174
  126. package/build/src/Cookie/Serializer/index.d.ts +0 -46
  127. package/build/src/Cookie/Serializer/index.js +0 -88
  128. package/build/src/Exceptions/HttpException.d.ts +0 -20
  129. package/build/src/Exceptions/HttpException.js +0 -36
  130. package/build/src/Exceptions/RouterException.d.ts +0 -36
  131. package/build/src/Exceptions/RouterException.js +0 -76
  132. package/build/src/HttpContext/LocalStorage/index.d.ts +0 -24
  133. package/build/src/HttpContext/LocalStorage/index.js +0 -28
  134. package/build/src/HttpContext/index.d.ts +0 -90
  135. package/build/src/HttpContext/index.js +0 -181
  136. package/build/src/MiddlewareStore/index.d.ts +0 -92
  137. package/build/src/MiddlewareStore/index.js +0 -133
  138. package/build/src/Redirect/index.d.ts +0 -71
  139. package/build/src/Redirect/index.js +0 -139
  140. package/build/src/Request/index.d.ts +0 -619
  141. package/build/src/Request/index.js +0 -862
  142. package/build/src/Response/index.d.ts +0 -414
  143. package/build/src/Response/index.js +0 -1010
  144. package/build/src/Router/BriskRoute.d.ts +0 -53
  145. package/build/src/Router/BriskRoute.js +0 -74
  146. package/build/src/Router/Group.d.ts +0 -101
  147. package/build/src/Router/Group.js +0 -165
  148. package/build/src/Router/LookupStore.d.ts +0 -122
  149. package/build/src/Router/LookupStore.js +0 -264
  150. package/build/src/Router/Matchers.d.ts +0 -31
  151. package/build/src/Router/Matchers.js +0 -43
  152. package/build/src/Router/Resource.d.ts +0 -95
  153. package/build/src/Router/Resource.js +0 -182
  154. package/build/src/Router/Route.d.ts +0 -138
  155. package/build/src/Router/Route.js +0 -204
  156. package/build/src/Router/Store.d.ts +0 -93
  157. package/build/src/Router/Store.js +0 -211
  158. package/build/src/Router/index.d.ts +0 -142
  159. package/build/src/Router/index.js +0 -333
  160. package/build/src/Server/ExceptionManager/index.d.ts +0 -49
  161. package/build/src/Server/ExceptionManager/index.js +0 -96
  162. package/build/src/Server/Hooks/index.d.ts +0 -43
  163. package/build/src/Server/Hooks/index.js +0 -77
  164. package/build/src/Server/PreCompiler/index.d.ts +0 -60
  165. package/build/src/Server/PreCompiler/index.js +0 -143
  166. package/build/src/Server/RequestHandler/index.d.ts +0 -39
  167. package/build/src/Server/RequestHandler/index.js +0 -87
  168. package/build/src/Server/index.d.ts +0 -90
  169. package/build/src/Server/index.js +0 -175
  170. package/build/standalone.d.ts +0 -14
  171. package/build/standalone.js +0 -23
@@ -1,174 +0,0 @@
1
- "use strict";
2
- /**
3
- * @adonisjs/http-server
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- var __importDefault = (this && this.__importDefault) || function (mod) {
11
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.CookieParser = void 0;
15
- const cookie_1 = __importDefault(require("cookie"));
16
- const Client_1 = require("../Client");
17
- /**
18
- * Cookie parser parses the HTTP `cookie` header and collects all cookies
19
- * inside an object of `key-value` pair, but doesn't attempt to decrypt
20
- * or unsign or decode the individual values.
21
- *
22
- * The cookie values are lazily decrypted, or unsigned to avoid unncessary
23
- * processing, which infact can be used as a means to burden the server
24
- * by sending too many cookies which even doesn't belongs to the
25
- * server.
26
- */
27
- class CookieParser {
28
- constructor(cookieHeader, encryption) {
29
- this.cookieHeader = cookieHeader;
30
- this.encryption = encryption;
31
- this.client = new Client_1.CookieClient(this.encryption);
32
- /**
33
- * A copy of cached cookies, they are cached during a request after
34
- * initial decoding, unsigning or decrypting.
35
- */
36
- this.cachedCookies = {
37
- signedCookies: {},
38
- plainCookies: {},
39
- encryptedCookies: {},
40
- };
41
- /**
42
- * An object of key-value pair collected by parsing
43
- * the request cookie header.
44
- */
45
- this.cookies = this.parse();
46
- }
47
- /**
48
- * Parses the request `cookie` header
49
- */
50
- parse() {
51
- /*
52
- * Set to empty object when cookie header is empty string
53
- */
54
- if (!this.cookieHeader) {
55
- return {};
56
- }
57
- /*
58
- * Parse and store reference
59
- */
60
- return cookie_1.default.parse(this.cookieHeader);
61
- }
62
- /**
63
- * Attempts to decode a cookie by the name. When calling this method,
64
- * you are assuming that the cookie was just encoded at the first
65
- * place and not signed or encrypted.
66
- */
67
- decode(key, encoded = true) {
68
- /*
69
- * Ignore when initial value is not defined or null
70
- */
71
- const value = this.cookies[key];
72
- if (value === null || value === undefined) {
73
- return null;
74
- }
75
- /*
76
- * Reference to the cache object. Mainly done to avoid typos,
77
- * since this object is referenced a handful of times inside
78
- * this method.
79
- */
80
- const cacheObject = this.cachedCookies.plainCookies;
81
- /*
82
- * Return from cache, when already parsed
83
- */
84
- if (cacheObject[key] !== undefined) {
85
- return cacheObject[key];
86
- }
87
- /*
88
- * Attempt to unpack and cache it for future. The value is only
89
- * when value it is not null.
90
- */
91
- const parsed = encoded ? this.client.decode(key, value) : value;
92
- if (parsed !== null) {
93
- cacheObject[key] = parsed;
94
- }
95
- return parsed;
96
- }
97
- /**
98
- * Attempts to unsign a cookie by the name. When calling this method,
99
- * you are assuming that the cookie was signed at the first place.
100
- */
101
- unsign(key) {
102
- /*
103
- * Ignore when initial value is not defined or null
104
- */
105
- const value = this.cookies[key];
106
- if (value === null || value === undefined) {
107
- return null;
108
- }
109
- /*
110
- * Reference to the cache object. Mainly done to avoid typos,
111
- * since this object is referenced a handful of times inside
112
- * this method.
113
- */
114
- const cacheObject = this.cachedCookies.signedCookies;
115
- /*
116
- * Return from cache, when already parsed
117
- */
118
- if (cacheObject[key] !== undefined) {
119
- return cacheObject[key];
120
- }
121
- /*
122
- * Attempt to unpack and cache it for future. The value is only
123
- * when value it is not null.
124
- */
125
- const parsed = this.client.unsign(key, value);
126
- if (parsed !== null) {
127
- cacheObject[key] = parsed;
128
- }
129
- return parsed;
130
- }
131
- /**
132
- * Attempts to decrypt a cookie by the name. When calling this method,
133
- * you are assuming that the cookie was encrypted at the first place.
134
- */
135
- decrypt(key) {
136
- /*
137
- * Ignore when initial value is not defined or null
138
- */
139
- const value = this.cookies[key];
140
- if (value === null || value === undefined) {
141
- return null;
142
- }
143
- /*
144
- * Reference to the cache object. Mainly done to avoid typos,
145
- * since this object is referenced a handful of times inside
146
- * this method.
147
- */
148
- const cacheObject = this.cachedCookies.encryptedCookies;
149
- /*
150
- * Return from cache, when already parsed
151
- */
152
- if (cacheObject[key] !== undefined) {
153
- return cacheObject[key];
154
- }
155
- /*
156
- * Attempt to unpack and cache it for future. The value is only
157
- * when value it is not null.
158
- */
159
- const parsed = this.client.decrypt(key, value);
160
- if (parsed !== null) {
161
- cacheObject[key] = parsed;
162
- }
163
- return parsed;
164
- }
165
- /**
166
- * Returns an object of cookies key-value pair. Do note, the
167
- * cookies are not decoded, unsigned or decrypted inside this
168
- * list.
169
- */
170
- list() {
171
- return this.cookies;
172
- }
173
- }
174
- exports.CookieParser = CookieParser;
@@ -1,46 +0,0 @@
1
- /**
2
- * @adonisjs/http-server
3
- *
4
- * (c) Harminder Virk <virk@adonisjs.com>
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 { CookieOptions } from '@ioc:Adonis/Core/Response';
10
- import { EncryptionContract } from '@ioc:Adonis/Core/Encryption';
11
- /**
12
- * Cookies serializer is used to serialize a value to be set on the `Set-Cookie`
13
- * header. You can `encode`, `sign` on `encrypt` cookies using the serializer
14
- * and then set them individually using the `set-cookie` header.
15
- */
16
- export declare class CookieSerializer {
17
- private encryption;
18
- private client;
19
- constructor(encryption: EncryptionContract);
20
- /**
21
- * Serializes the key-value pair to a string, that can be set on the
22
- * `Set-Cookie` header.
23
- */
24
- private serializeAsCookie;
25
- /**
26
- * Encodes value as a plain cookie. Do note, the value is still JSON.stringified
27
- * and converted to base64 encoded string to avoid encoding issues.
28
- *
29
- * @example
30
- * ```ts
31
- * serializer.encode('name', 'virk')
32
- * ```
33
- */
34
- encode(key: string, value: any, options?: Partial<CookieOptions & {
35
- encode: boolean;
36
- }>): string | null;
37
- /**
38
- * Signs the value and returns it back as a url safe string. The signed value
39
- * has a verification hash attached to it to detect data tampering.
40
- */
41
- sign(key: string, value: any, options?: Partial<CookieOptions>): string | null;
42
- /**
43
- * Encrypts the value and returns it back as a url safe string.
44
- */
45
- encrypt(key: string, value: any, options?: Partial<CookieOptions>): string | null;
46
- }
@@ -1,88 +0,0 @@
1
- "use strict";
2
- /**
3
- * @adonisjs/http-server
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- var __importDefault = (this && this.__importDefault) || function (mod) {
11
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.CookieSerializer = void 0;
15
- const ms_1 = __importDefault(require("ms"));
16
- const cookie_1 = __importDefault(require("cookie"));
17
- const Client_1 = require("../Client");
18
- /**
19
- * Cookies serializer is used to serialize a value to be set on the `Set-Cookie`
20
- * header. You can `encode`, `sign` on `encrypt` cookies using the serializer
21
- * and then set them individually using the `set-cookie` header.
22
- */
23
- class CookieSerializer {
24
- constructor(encryption) {
25
- this.encryption = encryption;
26
- this.client = new Client_1.CookieClient(this.encryption);
27
- }
28
- /**
29
- * Serializes the key-value pair to a string, that can be set on the
30
- * `Set-Cookie` header.
31
- */
32
- serializeAsCookie(key, value, options) {
33
- /**
34
- * Invoked expires method to get the date
35
- */
36
- let expires = options?.expires;
37
- if (typeof expires === 'function') {
38
- expires = expires();
39
- }
40
- /**
41
- * Parse string based max age to number
42
- */
43
- let maxAge = options?.maxAge;
44
- if (typeof maxAge === 'string') {
45
- maxAge = (0, ms_1.default)(maxAge) / 1000;
46
- }
47
- const parsedOptions = Object.assign({}, options, { maxAge, expires });
48
- return cookie_1.default.serialize(key, value, parsedOptions);
49
- }
50
- /**
51
- * Encodes value as a plain cookie. Do note, the value is still JSON.stringified
52
- * and converted to base64 encoded string to avoid encoding issues.
53
- *
54
- * @example
55
- * ```ts
56
- * serializer.encode('name', 'virk')
57
- * ```
58
- */
59
- encode(key, value, options) {
60
- const packedValue = !(options?.encode ?? true) ? value : this.client.encode(key, value);
61
- if (packedValue === null) {
62
- return null;
63
- }
64
- return this.serializeAsCookie(key, packedValue, options);
65
- }
66
- /**
67
- * Signs the value and returns it back as a url safe string. The signed value
68
- * has a verification hash attached to it to detect data tampering.
69
- */
70
- sign(key, value, options) {
71
- const packedValue = this.client.sign(key, value);
72
- if (packedValue === null) {
73
- return null;
74
- }
75
- return this.serializeAsCookie(key, packedValue, options);
76
- }
77
- /**
78
- * Encrypts the value and returns it back as a url safe string.
79
- */
80
- encrypt(key, value, options) {
81
- const packedValue = this.client.encrypt(key, value);
82
- if (packedValue === null) {
83
- return null;
84
- }
85
- return this.serializeAsCookie(key, packedValue, options);
86
- }
87
- }
88
- exports.CookieSerializer = CookieSerializer;
@@ -1,20 +0,0 @@
1
- /**
2
- * @adonisjs/http-server
3
- *
4
- * (c) Harminder Virk <virk@adonisjs.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /// <reference path="../../adonis-typings/index.d.ts" />
10
- import { Exception } from '@poppinss/utils';
11
- /**
12
- * Custom exception to abort requests as one liners
13
- */
14
- export declare class HttpException extends Exception {
15
- body: any;
16
- /**
17
- * This method returns an instance of the exception class
18
- */
19
- static invoke(body: any, status: number, code?: string): HttpException;
20
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
- /**
3
- * @adonisjs/http-server
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.HttpException = void 0;
12
- /// <reference path="../../adonis-typings/index.ts" />
13
- const utils_1 = require("@poppinss/utils");
14
- const helpers_1 = require("@poppinss/utils/build/helpers");
15
- const exceptions_json_1 = require("../../exceptions.json");
16
- /**
17
- * Custom exception to abort requests as one liners
18
- */
19
- class HttpException extends utils_1.Exception {
20
- /**
21
- * This method returns an instance of the exception class
22
- */
23
- static invoke(body, status, code) {
24
- const message = exceptions_json_1.E_HTTP_EXCEPTION.message;
25
- code = code || exceptions_json_1.E_HTTP_EXCEPTION.code;
26
- if (body !== null && typeof body === 'object') {
27
- const error = new this(body.message || (0, helpers_1.interpolate)(message, { status }), status, code);
28
- error.body = body;
29
- return error;
30
- }
31
- const error = new this(body || (0, helpers_1.interpolate)(message, { status }), status, code);
32
- error.body = error.message;
33
- return error;
34
- }
35
- }
36
- exports.HttpException = HttpException;
@@ -1,36 +0,0 @@
1
- import { Exception } from '@poppinss/utils';
2
- /**
3
- * Exceptions related to the HTTP router
4
- */
5
- export declare class RouterException extends Exception {
6
- /**
7
- * Raised when one of the routes inside the group doesn't have a name
8
- * but an attempt is made to name the group
9
- */
10
- static cannotDefineGroupName(): void;
11
- /**
12
- * Raised when a duplicate route pattern is find for the same HTTP method
13
- */
14
- static duplicateRoute(method: string, pattern: string): void;
15
- /**
16
- * Raised when a route has duplicate params
17
- */
18
- static duplicateRouteParam(param: string, pattern: string): RouterException;
19
- /**
20
- * Raised when route name is not unique
21
- */
22
- static duplicateRouteName(name: string): void;
23
- /**
24
- * Raised when unable to make url for a given route, because one of the
25
- * params value is not defined
26
- */
27
- static cannotMakeRoute(param: string, pattern: string): void;
28
- /**
29
- * Raised when unable to lookup a route using its identifier
30
- */
31
- static cannotLookupRoute(identifier: string): void;
32
- /**
33
- * Raised when unable to lookup domain
34
- */
35
- static cannotLookupDomain(domain: string): void;
36
- }
@@ -1,76 +0,0 @@
1
- "use strict";
2
- /*
3
- * @adonisjs/http-server
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.RouterException = void 0;
12
- const utils_1 = require("@poppinss/utils");
13
- const helpers_1 = require("@poppinss/utils/build/helpers");
14
- const exceptions_json_1 = require("../../exceptions.json");
15
- /**
16
- * Exceptions related to the HTTP router
17
- */
18
- class RouterException extends utils_1.Exception {
19
- /**
20
- * Raised when one of the routes inside the group doesn't have a name
21
- * but an attempt is made to name the group
22
- */
23
- static cannotDefineGroupName() {
24
- const error = new this(exceptions_json_1.E_CANNOT_DEFINE_GROUP_NAME.message, exceptions_json_1.E_CANNOT_DEFINE_GROUP_NAME.status, exceptions_json_1.E_CANNOT_DEFINE_GROUP_NAME.code);
25
- error.help = exceptions_json_1.E_CANNOT_DEFINE_GROUP_NAME.help.join('\n');
26
- throw error;
27
- }
28
- /**
29
- * Raised when a duplicate route pattern is find for the same HTTP method
30
- */
31
- static duplicateRoute(method, pattern) {
32
- const error = new this((0, helpers_1.interpolate)(exceptions_json_1.E_DUPLICATE_ROUTE.message, { method, pattern }), exceptions_json_1.E_DUPLICATE_ROUTE.status, exceptions_json_1.E_DUPLICATE_ROUTE.code);
33
- error.help = exceptions_json_1.E_DUPLICATE_ROUTE.help.join('\n');
34
- throw error;
35
- }
36
- /**
37
- * Raised when a route has duplicate params
38
- */
39
- static duplicateRouteParam(param, pattern) {
40
- return new this((0, helpers_1.interpolate)(exceptions_json_1.E_DUPLICATE_ROUTE_PARAM.message, { param, pattern }), exceptions_json_1.E_DUPLICATE_ROUTE_PARAM.status, exceptions_json_1.E_DUPLICATE_ROUTE_PARAM.code);
41
- }
42
- /**
43
- * Raised when route name is not unique
44
- */
45
- static duplicateRouteName(name) {
46
- const error = new this((0, helpers_1.interpolate)(exceptions_json_1.E_DUPLICATE_ROUTE_NAME.message, { name }), exceptions_json_1.E_DUPLICATE_ROUTE_NAME.status, exceptions_json_1.E_DUPLICATE_ROUTE_NAME.code);
47
- error.help = exceptions_json_1.E_DUPLICATE_ROUTE_NAME.help.join('\n');
48
- throw error;
49
- }
50
- /**
51
- * Raised when unable to make url for a given route, because one of the
52
- * params value is not defined
53
- */
54
- static cannotMakeRoute(param, pattern) {
55
- const error = new this((0, helpers_1.interpolate)(exceptions_json_1.E_CANNOT_MAKE_ROUTE_URL.message, { pattern, param }), exceptions_json_1.E_CANNOT_MAKE_ROUTE_URL.status, exceptions_json_1.E_CANNOT_MAKE_ROUTE_URL.code);
56
- error.help = exceptions_json_1.E_CANNOT_MAKE_ROUTE_URL.help.join('\n');
57
- throw error;
58
- }
59
- /**
60
- * Raised when unable to lookup a route using its identifier
61
- */
62
- static cannotLookupRoute(identifier) {
63
- const error = new this((0, helpers_1.interpolate)(exceptions_json_1.E_CANNOT_LOOKUP_ROUTE.message, { identifier }), exceptions_json_1.E_CANNOT_LOOKUP_ROUTE.status, exceptions_json_1.E_CANNOT_LOOKUP_ROUTE.code);
64
- error.help = exceptions_json_1.E_CANNOT_LOOKUP_ROUTE.help.join('\n');
65
- throw error;
66
- }
67
- /**
68
- * Raised when unable to lookup domain
69
- */
70
- static cannotLookupDomain(domain) {
71
- const error = new this((0, helpers_1.interpolate)(exceptions_json_1.E_CANNOT_LOOKUP_DOMAIN.message, { domain }), exceptions_json_1.E_CANNOT_LOOKUP_DOMAIN.status, exceptions_json_1.E_CANNOT_LOOKUP_DOMAIN.code);
72
- error.help = exceptions_json_1.E_CANNOT_LOOKUP_DOMAIN.help.join('\n');
73
- throw error;
74
- }
75
- }
76
- exports.RouterException = RouterException;
@@ -1,24 +0,0 @@
1
- /**
2
- * @adonisjs/http-server
3
- *
4
- * (c) Harminder Virk <virk@adonisjs.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /// <reference path="../../../adonis-typings/index.d.ts" />
10
- /// <reference types="node" />
11
- import { AsyncLocalStorage } from 'async_hooks';
12
- import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
13
- /**
14
- * Find if the async localstorage is enabled or not
15
- */
16
- export declare let usingAsyncLocalStorage: boolean;
17
- /**
18
- * Toggle the async local storage
19
- */
20
- export declare function useAsyncLocalStorage(enabled: boolean): void;
21
- /**
22
- * Async local storage for the HTTP context
23
- */
24
- export declare const httpContextLocalStorage: AsyncLocalStorage<HttpContextContract>;
@@ -1,28 +0,0 @@
1
- "use strict";
2
- /**
3
- * @adonisjs/http-server
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.httpContextLocalStorage = exports.useAsyncLocalStorage = exports.usingAsyncLocalStorage = void 0;
12
- /// <reference path="../../../adonis-typings/index.ts" />
13
- const async_hooks_1 = require("async_hooks");
14
- /**
15
- * Find if the async localstorage is enabled or not
16
- */
17
- exports.usingAsyncLocalStorage = false;
18
- /**
19
- * Toggle the async local storage
20
- */
21
- function useAsyncLocalStorage(enabled) {
22
- exports.usingAsyncLocalStorage = enabled;
23
- }
24
- exports.useAsyncLocalStorage = useAsyncLocalStorage;
25
- /**
26
- * Async local storage for the HTTP context
27
- */
28
- exports.httpContextLocalStorage = new async_hooks_1.AsyncLocalStorage();
@@ -1,90 +0,0 @@
1
- /**
2
- * @adonisjs/http-server
3
- *
4
- * (c) Harminder Virk <virk@adonisjs.com>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /// <reference path="../../adonis-typings/index.d.ts" />
10
- /// <reference types="@adonisjs/logger/build/adonis-typings/logger" />
11
- /// <reference types="@adonisjs/profiler/build/adonis-typings/profiler" />
12
- /// <reference types="node" />
13
- import { Macroable } from 'macroable';
14
- import { RouteNode } from '@ioc:Adonis/Core/Route';
15
- import { IncomingMessage, ServerResponse } from 'http';
16
- import { LoggerContract } from '@ioc:Adonis/Core/Logger';
17
- import { RequestContract } from '@ioc:Adonis/Core/Request';
18
- import { ResponseContract } from '@ioc:Adonis/Core/Response';
19
- import { ProfilerRowContract } from '@ioc:Adonis/Core/Profiler';
20
- import { ApplicationContract } from '@ioc:Adonis/Core/Application';
21
- import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
22
- /**
23
- * Http context is passed to all route handlers, middleware,
24
- * error handler and server hooks.
25
- */
26
- export declare class HttpContext extends Macroable implements HttpContextContract {
27
- request: RequestContract;
28
- response: ResponseContract;
29
- logger: LoggerContract;
30
- profiler: ProfilerRowContract;
31
- /**
32
- * Set inside the provider
33
- */
34
- static app: ApplicationContract;
35
- /**
36
- * Find if async localstorage is enabled for HTTP requests
37
- * or not
38
- */
39
- static get usingAsyncLocalStorage(): boolean;
40
- /**
41
- * Get access to the HTTP context. Available only when
42
- * "usingAsyncLocalStorage" is true
43
- */
44
- static get(): HttpContextContract | null;
45
- /**
46
- * Get the HttpContext instance or raise an exception if not
47
- * available
48
- */
49
- static getOrFail(): HttpContextContract;
50
- /**
51
- * Run a method that doesn't have access to HTTP context from
52
- * the async local storage.
53
- */
54
- static runOutsideContext<T>(callback: (...args: any[]) => T, ...args: any[]): T;
55
- /**
56
- * A unique key for the current route
57
- */
58
- routeKey: string;
59
- /**
60
- * Route params
61
- */
62
- params: Record<string, any>;
63
- /**
64
- * Route subdomains
65
- */
66
- subdomains: Record<string, any>;
67
- /**
68
- * Reference to the current route. Not available inside
69
- * server hooks
70
- */
71
- route?: RouteNode & {
72
- params: string[];
73
- };
74
- /**
75
- * Required by macroable
76
- */
77
- protected static macros: {};
78
- protected static getters: {};
79
- constructor(request: RequestContract, response: ResponseContract, logger: LoggerContract, profiler: ProfilerRowContract);
80
- /**
81
- * A helper to see top level properties on the context object
82
- */
83
- inspect(): string;
84
- /**
85
- * Creates a new fake context instance for a given route. The method is
86
- * meant to be used inside an AdonisJS application since it relies
87
- * directly on the IoC container.
88
- */
89
- static create(routePattern: string, routeParams: Record<string, any>, req?: IncomingMessage, res?: ServerResponse): HttpContext;
90
- }