@adonisjs/http-server 6.8.2-8 → 7.0.0-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 (107) hide show
  1. package/build/chunk-XX72ATFY.js +4388 -0
  2. package/build/factories/main.d.ts +149 -6
  3. package/build/factories/main.js +331 -14
  4. package/build/index.d.ts +272 -14
  5. package/build/index.js +308 -22
  6. package/build/{src/server/main.d.ts → main-29eaaee4.d.ts} +12 -17
  7. package/build/main-e5b46c83.d.ts +2210 -0
  8. package/build/src/types/main.d.ts +14 -7
  9. package/build/src/types/main.js +0 -15
  10. package/package.json +65 -55
  11. package/build/factories/http_context.d.ts +0 -25
  12. package/build/factories/http_context.js +0 -51
  13. package/build/factories/http_server.d.ts +0 -8
  14. package/build/factories/http_server.js +0 -26
  15. package/build/factories/qs_parser_factory.d.ts +0 -20
  16. package/build/factories/qs_parser_factory.js +0 -44
  17. package/build/factories/request.d.ts +0 -29
  18. package/build/factories/request.js +0 -73
  19. package/build/factories/response.d.ts +0 -29
  20. package/build/factories/response.js +0 -77
  21. package/build/factories/router.d.ts +0 -23
  22. package/build/factories/router.js +0 -45
  23. package/build/factories/server_factory.d.ts +0 -29
  24. package/build/factories/server_factory.js +0 -65
  25. package/build/src/cookies/client.d.ts +0 -37
  26. package/build/src/cookies/client.js +0 -84
  27. package/build/src/cookies/drivers/encrypted.d.ts +0 -16
  28. package/build/src/cookies/drivers/encrypted.js +0 -36
  29. package/build/src/cookies/drivers/plain.d.ts +0 -15
  30. package/build/src/cookies/drivers/plain.js +0 -33
  31. package/build/src/cookies/drivers/signed.d.ts +0 -16
  32. package/build/src/cookies/drivers/signed.js +0 -36
  33. package/build/src/cookies/parser.d.ts +0 -37
  34. package/build/src/cookies/parser.js +0 -167
  35. package/build/src/cookies/serializer.d.ts +0 -33
  36. package/build/src/cookies/serializer.js +0 -79
  37. package/build/src/debug.d.ts +0 -3
  38. package/build/src/debug.js +0 -10
  39. package/build/src/define_config.d.ts +0 -5
  40. package/build/src/define_config.js +0 -51
  41. package/build/src/define_middleware.d.ts +0 -11
  42. package/build/src/define_middleware.js +0 -35
  43. package/build/src/exception_handler.d.ts +0 -90
  44. package/build/src/exception_handler.js +0 -239
  45. package/build/src/exceptions.d.ts +0 -84
  46. package/build/src/exceptions.js +0 -38
  47. package/build/src/helpers.d.ts +0 -23
  48. package/build/src/helpers.js +0 -84
  49. package/build/src/http_context/local_storage.d.ts +0 -12
  50. package/build/src/http_context/local_storage.js +0 -39
  51. package/build/src/http_context/main.d.ts +0 -58
  52. package/build/src/http_context/main.js +0 -105
  53. package/build/src/qs.d.ts +0 -11
  54. package/build/src/qs.js +0 -25
  55. package/build/src/redirect.d.ts +0 -42
  56. package/build/src/redirect.js +0 -140
  57. package/build/src/request.d.ts +0 -565
  58. package/build/src/request.js +0 -865
  59. package/build/src/response.d.ts +0 -540
  60. package/build/src/response.js +0 -1208
  61. package/build/src/router/brisk.d.ts +0 -42
  62. package/build/src/router/brisk.js +0 -85
  63. package/build/src/router/executor.d.ts +0 -8
  64. package/build/src/router/executor.js +0 -29
  65. package/build/src/router/factories/use_return_value.d.ts +0 -6
  66. package/build/src/router/factories/use_return_value.js +0 -22
  67. package/build/src/router/group.d.ts +0 -65
  68. package/build/src/router/group.js +0 -207
  69. package/build/src/router/lookup_store/main.d.ts +0 -49
  70. package/build/src/router/lookup_store/main.js +0 -86
  71. package/build/src/router/lookup_store/route_finder.d.ts +0 -21
  72. package/build/src/router/lookup_store/route_finder.js +0 -49
  73. package/build/src/router/lookup_store/url_builder.d.ts +0 -52
  74. package/build/src/router/lookup_store/url_builder.js +0 -209
  75. package/build/src/router/main.d.ts +0 -128
  76. package/build/src/router/main.js +0 -316
  77. package/build/src/router/matchers.d.ts +0 -27
  78. package/build/src/router/matchers.js +0 -36
  79. package/build/src/router/parser.d.ts +0 -5
  80. package/build/src/router/parser.js +0 -17
  81. package/build/src/router/resource.d.ts +0 -54
  82. package/build/src/router/resource.js +0 -216
  83. package/build/src/router/route.d.ts +0 -92
  84. package/build/src/router/route.js +0 -293
  85. package/build/src/router/store.d.ts +0 -66
  86. package/build/src/router/store.js +0 -195
  87. package/build/src/server/factories/final_handler.d.ts +0 -9
  88. package/build/src/server/factories/final_handler.js +0 -30
  89. package/build/src/server/factories/middleware_handler.d.ts +0 -8
  90. package/build/src/server/factories/middleware_handler.js +0 -16
  91. package/build/src/server/factories/write_response.d.ts +0 -6
  92. package/build/src/server/factories/write_response.js +0 -24
  93. package/build/src/server/main.js +0 -283
  94. package/build/src/types/base.d.ts +0 -19
  95. package/build/src/types/base.js +0 -9
  96. package/build/src/types/middleware.d.ts +0 -35
  97. package/build/src/types/middleware.js +0 -9
  98. package/build/src/types/qs.d.ts +0 -68
  99. package/build/src/types/qs.js +0 -9
  100. package/build/src/types/request.d.ts +0 -39
  101. package/build/src/types/request.js +0 -9
  102. package/build/src/types/response.d.ts +0 -45
  103. package/build/src/types/response.js +0 -9
  104. package/build/src/types/route.d.ts +0 -165
  105. package/build/src/types/route.js +0 -9
  106. package/build/src/types/server.d.ts +0 -72
  107. package/build/src/types/server.js +0 -9
@@ -1,283 +0,0 @@
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 onFinished from 'on-finished';
10
- import Middleware from '@poppinss/middleware';
11
- import { moduleCaller, moduleImporter } from '@adonisjs/fold';
12
- import { Qs } from '../qs.js';
13
- import debug from '../debug.js';
14
- import { Request } from '../request.js';
15
- import { Response } from '../response.js';
16
- import { Router } from '../router/main.js';
17
- import { HttpContext } from '../http_context/main.js';
18
- import { finalHandler } from './factories/final_handler.js';
19
- import { writeResponse } from './factories/write_response.js';
20
- import { asyncLocalStorage } from '../http_context/local_storage.js';
21
- import { middlewareHandler } from './factories/middleware_handler.js';
22
- /**
23
- * The HTTP server implementation to handle incoming requests and respond using the
24
- * registered routes.
25
- */
26
- export class Server {
27
- /**
28
- * The default error handler to use
29
- */
30
- #defaultErrorHandler = {
31
- report() { },
32
- handle(error, ctx) {
33
- ctx.response.status(error.status || 500).send(error.message || 'Internal server error');
34
- },
35
- };
36
- /**
37
- * Logger instance, a child logger is added
38
- * to the context to have request specific
39
- * logging capabilities.
40
- */
41
- #logger;
42
- /**
43
- * Registered error handler (if any)
44
- */
45
- #errorHandler;
46
- /**
47
- * Resolved error handler is an instance of the lazily imported error
48
- * handler class.
49
- */
50
- #resolvedErrorHandler = this.#defaultErrorHandler;
51
- /**
52
- * Emitter is required to notify when a request finishes
53
- */
54
- #emitter;
55
- /**
56
- * The application instance to be shared with the router
57
- */
58
- #app;
59
- /**
60
- * The encryption instance to be shared with the router
61
- */
62
- #encryption;
63
- /**
64
- * Server config
65
- */
66
- #config;
67
- /**
68
- * Query string parser used by the server
69
- */
70
- #qsParser;
71
- /**
72
- * Server middleware stack runs on every incoming HTTP request
73
- */
74
- #serverMiddlewareStack;
75
- /**
76
- * Reference to the router used by the server
77
- */
78
- #router;
79
- /**
80
- * Reference to the underlying Node HTTP server in use
81
- */
82
- #nodeHttpServer;
83
- /**
84
- * Middleware store to be shared with the routes
85
- */
86
- #middleware = [];
87
- /**
88
- * Know if async local storage is enabled or not.
89
- */
90
- get usingAsyncLocalStorage() {
91
- return asyncLocalStorage.isEnabled;
92
- }
93
- constructor(app, encryption, emitter, logger, config) {
94
- this.#app = app;
95
- this.#emitter = emitter;
96
- this.#config = config;
97
- this.#logger = logger;
98
- this.#encryption = encryption;
99
- this.#qsParser = new Qs(this.#config.qs);
100
- this.#router = new Router(this.#app, this.#encryption, this.#qsParser);
101
- this.#createAsyncLocalStore();
102
- debug('server config: %O', this.#config);
103
- }
104
- /**
105
- * Create async local storage store when enabled
106
- */
107
- #createAsyncLocalStore() {
108
- if (this.#config.useAsyncLocalStorage) {
109
- debug('creating ALS store for HTTP context');
110
- asyncLocalStorage.create();
111
- }
112
- else {
113
- asyncLocalStorage.destroy();
114
- }
115
- }
116
- /**
117
- * Creates an instance of the server middleware stack
118
- */
119
- #createServerMiddlewareStack() {
120
- this.#serverMiddlewareStack = new Middleware();
121
- this.#middleware.forEach((middleware) => this.#serverMiddlewareStack.add(middleware));
122
- this.#serverMiddlewareStack.freeze();
123
- this.#middleware = [];
124
- }
125
- /**
126
- * Handles the HTTP request
127
- */
128
- #handleRequest(ctx, resolver) {
129
- return this.#serverMiddlewareStack.runner()
130
- .errorHandler((error) => {
131
- this.#resolvedErrorHandler.report(error, ctx);
132
- return this.#resolvedErrorHandler.handle(error, ctx);
133
- })
134
- .finalHandler(finalHandler(this.#router, resolver, ctx))
135
- .run(middlewareHandler(resolver, ctx))
136
- .catch((error) => {
137
- ctx.logger.fatal({ err: error }, 'Exception raised by error handler');
138
- return this.#defaultErrorHandler.handle(error, ctx);
139
- })
140
- .finally(writeResponse(ctx));
141
- }
142
- /**
143
- * Creates a pipeline of middleware.
144
- */
145
- pipeline(middleware) {
146
- const middlewareStack = new Middleware();
147
- middleware.forEach((one) => {
148
- middlewareStack.add(moduleCaller(one, 'handle').toHandleMethod());
149
- });
150
- middlewareStack.freeze();
151
- const stackRunner = middlewareStack.runner();
152
- return {
153
- finalHandler(handler) {
154
- stackRunner.finalHandler(handler);
155
- return this;
156
- },
157
- errorHandler(handler) {
158
- stackRunner.errorHandler(handler);
159
- return this;
160
- },
161
- run(ctx) {
162
- return stackRunner.run((handler, next) => {
163
- return handler.handle(ctx.containerResolver, ctx, next);
164
- });
165
- },
166
- };
167
- }
168
- /**
169
- * Define an array of middleware to use on all the incoming HTTP request.
170
- * Calling this method multiple times pushes to the existing list
171
- * of middleware
172
- */
173
- use(middleware) {
174
- middleware.forEach((one) => this.#middleware.push(moduleImporter(one, 'handle').toHandleMethod()));
175
- return this;
176
- }
177
- /**
178
- * Register a custom error handler for HTTP requests.
179
- * All errors will be reported to this method
180
- */
181
- errorHandler(handler) {
182
- this.#errorHandler = handler;
183
- return this;
184
- }
185
- /**
186
- * Boot the server. Calling this method performs the following actions.
187
- *
188
- * - Register routes with the store.
189
- * - Resolve and construct the error handler.
190
- */
191
- async boot() {
192
- debug('booting HTTP server');
193
- /**
194
- * Creates the middleware stack for the server
195
- */
196
- this.#createServerMiddlewareStack();
197
- /**
198
- * Commit routes
199
- */
200
- this.#router.commit();
201
- /**
202
- * Register custom error handler
203
- */
204
- if (this.#errorHandler) {
205
- if (debug.enabled) {
206
- debug('using custom error handler "%s"', this.#errorHandler);
207
- }
208
- const moduleExports = await this.#errorHandler();
209
- this.#resolvedErrorHandler = await this.#app.container.make(moduleExports.default);
210
- }
211
- }
212
- /**
213
- * Set the HTTP server instance used to listen for requests.
214
- */
215
- setNodeServer(server) {
216
- this.#nodeHttpServer = server;
217
- }
218
- /**
219
- * Returns reference to the underlying HTTP server
220
- * in use
221
- */
222
- getNodeServer() {
223
- return this.#nodeHttpServer;
224
- }
225
- /**
226
- * Returns reference to the router instance used
227
- * by the server.
228
- */
229
- getRouter() {
230
- return this.#router;
231
- }
232
- /**
233
- * Creates an instance of the [[Request]] class
234
- */
235
- createRequest(req, res) {
236
- return new Request(req, res, this.#encryption, this.#config, this.#qsParser);
237
- }
238
- /**
239
- * Creates an instance of the [[Response]] class
240
- */
241
- createResponse(req, res) {
242
- return new Response(req, res, this.#encryption, this.#config, this.#router, this.#qsParser);
243
- }
244
- /**
245
- * Creates an instance of the [[HttpContext]] class
246
- */
247
- createHttpContext(request, response, resolver) {
248
- return new HttpContext(request, response, this.#logger.child({ request_id: request.id() }), resolver);
249
- }
250
- /**
251
- * Handle request
252
- */
253
- handle(req, res) {
254
- /**
255
- * Setup for the "http:request_finished" event
256
- */
257
- const hasRequestListener = this.#emitter.hasListeners('http:request_finished');
258
- const startTime = hasRequestListener ? process.hrtime() : null;
259
- /**
260
- * Creating essential instances
261
- */
262
- const resolver = this.#app.container.createResolver();
263
- const ctx = this.createHttpContext(this.createRequest(req, res), this.createResponse(req, res), resolver);
264
- /**
265
- * Emit event when listening for the request_finished event
266
- */
267
- if (startTime) {
268
- onFinished(res, () => {
269
- this.#emitter.emit('http:request_finished', {
270
- ctx: ctx,
271
- duration: process.hrtime(startTime),
272
- });
273
- });
274
- }
275
- /**
276
- * Handle request
277
- */
278
- if (this.usingAsyncLocalStorage) {
279
- return asyncLocalStorage.storage.run(ctx, () => this.#handleRequest(ctx, resolver));
280
- }
281
- return this.#handleRequest(ctx, resolver);
282
- }
283
- }
@@ -1,19 +0,0 @@
1
- export type { NextFn } from '@poppinss/middleware/types';
2
- /**
3
- * Accept one or more of the mentioned type
4
- */
5
- export type OneOrMore<T> = T | T[];
6
- /**
7
- * Class constructor type
8
- */
9
- export type Constructor<T> = new (...args: any[]) => T;
10
- /**
11
- * A function that lazily imports a middleware
12
- */
13
- export type LazyImport<DefaultExport> = () => Promise<{
14
- default: DefaultExport;
15
- }>;
16
- /**
17
- * Unwraps default export from a lazy import function
18
- */
19
- export type UnWrapLazyImport<Fn extends LazyImport<any>> = Awaited<ReturnType<Fn>>['default'];
@@ -1,9 +0,0 @@
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
- export {};
@@ -1,35 +0,0 @@
1
- import type { ContainerResolver } from '@adonisjs/fold';
2
- import type { Constructor, NextFn } from './base.js';
3
- import type { HttpContext } from '../http_context/main.js';
4
- /**
5
- * Middleware represented as a class
6
- */
7
- export type MiddlewareAsClass = Constructor<{
8
- handle: (ctx: HttpContext, next: NextFn, args?: any) => any;
9
- }>;
10
- /**
11
- * Check if a union has undefined or null
12
- */
13
- type HasUndefined<T> = T extends NonNullable<T> ? true : false;
14
- /**
15
- * Returns the arguments accepted by the middleware's handle method
16
- */
17
- export type GetMiddlewareArgs<Middleware extends MiddlewareAsClass> = Parameters<InstanceType<Middleware>['handle']>[2] extends undefined ? [] : HasUndefined<Parameters<InstanceType<Middleware>['handle']>[2]> extends true ? [Parameters<InstanceType<Middleware>['handle']>[2]] : [Parameters<InstanceType<Middleware>['handle']>[2]?];
18
- /**
19
- * The middleware defined as a function on the router or the server
20
- */
21
- export type MiddlewareFn = (ctx: HttpContext, next: NextFn) => any;
22
- /**
23
- * Parsed global middleware
24
- */
25
- export type ParsedGlobalMiddleware = {
26
- handle: (resolver: ContainerResolver<any>, ...args: [ctx: HttpContext, next: NextFn, params?: any]) => any;
27
- };
28
- /**
29
- * Parsed named middleware
30
- */
31
- export type ParsedNamedMiddleware = ParsedGlobalMiddleware & {
32
- name: string;
33
- args: any;
34
- };
35
- export {};
@@ -1,9 +0,0 @@
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
- export {};
@@ -1,68 +0,0 @@
1
- export type QSParserConfig = {
2
- parse: {
3
- /**
4
- * Nesting depth till the parameters should be parsed.
5
- *
6
- * Defaults to 5
7
- */
8
- depth: number;
9
- /**
10
- * Number of parameters to parse.
11
- *
12
- * Defaults to 1000
13
- */
14
- parameterLimit: number;
15
- /**
16
- * Allow sparse elements in an array.
17
- *
18
- * Defaults to false
19
- */
20
- allowSparse: boolean;
21
- /**
22
- * The max limimit for the array indices. After the given limit
23
- * the array indices will be converted to an object, where the
24
- * index is the key.
25
- *
26
- * Defaults to 20
27
- */
28
- arrayLimit: number;
29
- /**
30
- * Join comma seperated query string values to an array
31
- *
32
- * Defaults to false
33
- */
34
- comma: boolean;
35
- };
36
- stringify: {
37
- /**
38
- * URI encode the stringified query string
39
- *
40
- * Defaults to true
41
- */
42
- encode: boolean;
43
- /**
44
- * URI encode but only the values and not the keys
45
- *
46
- * Defaults to false
47
- */
48
- encodeValuesOnly: boolean;
49
- /**
50
- * Define the format in which arrays should be serialized.
51
- *
52
- * - indices: a[0]=b&a[1]=c
53
- * - brackets: a[]=b&a[]=c
54
- * - repeat: a=b&a=c
55
- * - comma: a=b,c
56
- *
57
- * Defaults to "indices"
58
- */
59
- arrayFormat: 'indices' | 'brackets' | 'repeat' | 'comma';
60
- /**
61
- * Whether or not to skip null values when serializing. When set to
62
- * false, the null values will be treated as an empty string.
63
- *
64
- * Defaults to: false
65
- */
66
- skipNulls: boolean;
67
- };
68
- };
@@ -1,9 +0,0 @@
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
- export {};
@@ -1,39 +0,0 @@
1
- /**
2
- * Shape of the request config
3
- */
4
- export type RequestConfig = {
5
- /**
6
- * URL segments to ignore when extracting subdomains from a URL.
7
- * Defaults to 2
8
- */
9
- subdomainOffset: number;
10
- /**
11
- * Enabling the flag will generated a unique request id from every
12
- * HTTP request.
13
- *
14
- * The request id can be accessed using the "request.id()" method. Also,
15
- * the value of `x-request-id` header is used as the id (if it exists).
16
- *
17
- * Defaults to false
18
- */
19
- generateRequestId: boolean;
20
- /**
21
- * Method spoofing allows changing the request method using the query string.
22
- * For example: Making a POST request on URL /users/1?_method=PATCH will
23
- * be handled by the patch route.
24
- *
25
- * Defaults to false
26
- */
27
- allowMethodSpoofing: boolean;
28
- /**
29
- * A custom implementation to get the request ip address
30
- */
31
- getIp?: (request: any) => string;
32
- /**
33
- * A callback function to trust proxy ip addresses. You must use
34
- * the `proxy-addr` package to compute this value.
35
- *
36
- * Defaults to: "proxyAddr.compile('loopback')"
37
- */
38
- trustProxy: (address: string, distance: number) => boolean;
39
- };
@@ -1,9 +0,0 @@
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
- export {};
@@ -1,45 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- /**
4
- * Cookie options can that can be set on the response
5
- */
6
- export type CookieOptions = {
7
- domain: string;
8
- expires: Date | (() => Date);
9
- httpOnly: boolean;
10
- maxAge: number | string;
11
- path: string;
12
- sameSite: boolean | 'lax' | 'none' | 'strict';
13
- secure: boolean;
14
- };
15
- /**
16
- * Types from which response header can be casted to a
17
- * string
18
- */
19
- export type CastableHeader = string | number | boolean | string[] | number[] | boolean[];
20
- /**
21
- * Config accepted by response the class
22
- */
23
- export type ResponseConfig = {
24
- /**
25
- * Whether or not to generate etags for responses. Etags can be
26
- * enabled/disabled when sending response as well.
27
- *
28
- * Defaults to false
29
- */
30
- etag: boolean;
31
- /**
32
- * The callback name for the JSONP response.
33
- *
34
- * Defaults to 'callback'
35
- */
36
- jsonpCallbackName: string;
37
- /**
38
- * Options to set cookies
39
- */
40
- cookie: Partial<CookieOptions>;
41
- };
42
- /**
43
- * Stream that can be piped to the "response.stream" method
44
- */
45
- export type ResponseStream = NodeJS.ReadStream | NodeJS.ReadWriteStream | NodeJS.ReadableStream;
@@ -1,9 +0,0 @@
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
- export {};