@adonisjs/http-server 8.0.0-next.5 → 8.0.0-next.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.
- package/build/{chunk-BFGF3A5X.js → chunk-3XEJZ4S4.js} +1105 -566
- package/build/{chunk-ASX56VAK.js → chunk-NQNHMINZ.js} +59 -0
- package/build/factories/http_context.d.ts +2 -1
- package/build/factories/http_server.d.ts +7 -0
- package/build/factories/main.js +31 -5
- package/build/factories/qs_parser_factory.d.ts +3 -2
- package/build/factories/request.d.ts +1 -0
- package/build/factories/response.d.ts +1 -0
- package/build/factories/router.d.ts +1 -0
- package/build/factories/server_factory.d.ts +1 -0
- package/build/factories/url_builder_factory.d.ts +1 -0
- package/build/index.d.ts +3 -1
- package/build/index.js +87 -37
- package/build/src/cookies/client.d.ts +35 -0
- package/build/src/cookies/drivers/encrypted.d.ts +13 -0
- package/build/src/cookies/drivers/plain.d.ts +9 -0
- package/build/src/cookies/drivers/signed.d.ts +13 -0
- package/build/src/cookies/parser.d.ts +18 -0
- package/build/src/cookies/serializer.d.ts +21 -2
- package/build/src/define_config.d.ts +1 -3
- package/build/src/define_middleware.d.ts +1 -1
- package/build/src/exception_handler.d.ts +72 -31
- package/build/src/helpers.d.ts +50 -0
- package/build/src/helpers.js +5 -1
- package/build/src/http_context/local_storage.d.ts +17 -0
- package/build/src/http_context/main.d.ts +8 -0
- package/build/src/qs.d.ts +14 -0
- package/build/src/redirect.d.ts +62 -9
- package/build/src/request.d.ts +109 -10
- package/build/src/response.d.ts +416 -203
- package/build/src/router/brisk.d.ts +13 -0
- package/build/src/router/executor.d.ts +4 -0
- package/build/src/router/factories/use_return_value.d.ts +5 -0
- package/build/src/router/group.d.ts +18 -1
- package/build/src/router/legacy/url_builder.d.ts +14 -14
- package/build/src/router/main.d.ts +73 -4
- package/build/src/router/matchers.d.ts +3 -0
- package/build/src/router/resource.d.ts +34 -1
- package/build/src/router/route.d.ts +9 -1
- package/build/src/router/signed_url_builder.d.ts +4 -8
- package/build/src/router/store.d.ts +9 -0
- package/build/src/router/url_builder.d.ts +4 -9
- package/build/src/server/factories/middleware_handler.d.ts +10 -1
- package/build/src/server/factories/route_finder.d.ts +13 -3
- package/build/src/server/factories/write_response.d.ts +9 -2
- package/build/src/server/main.d.ts +77 -23
- package/build/src/tracing_channels.d.ts +4 -4
- package/build/src/types/middleware.d.ts +34 -9
- package/build/src/types/qs.d.ts +5 -0
- package/build/src/types/request.d.ts +1 -1
- package/build/src/types/response.d.ts +14 -6
- package/build/src/types/route.d.ts +40 -19
- package/build/src/types/server.d.ts +26 -11
- package/build/src/types/tracing_channels.d.ts +21 -3
- package/build/src/types/url_builder.d.ts +24 -11
- package/package.json +17 -15
|
@@ -13,74 +13,128 @@ import { Response } from '../response.ts';
|
|
|
13
13
|
import { Router } from '../router/main.ts';
|
|
14
14
|
import { HttpContext } from '../http_context/main.ts';
|
|
15
15
|
/**
|
|
16
|
-
* The
|
|
17
|
-
*
|
|
16
|
+
* The Server class provides the core HTTP server implementation for AdonisJS.
|
|
17
|
+
*
|
|
18
|
+
* It handles incoming HTTP requests by processing them through middleware pipelines,
|
|
19
|
+
* routing them to appropriate handlers, and managing response generation. The server
|
|
20
|
+
* supports custom error handling, middleware registration, and various Node.js HTTP
|
|
21
|
+
* server configurations.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const server = new Server(app, encryption, emitter, logger, config)
|
|
26
|
+
* server.use([AuthMiddleware, CorsMiddleware])
|
|
27
|
+
* server.errorHandler(() => import('./error_handler.ts'))
|
|
28
|
+
* await server.boot()
|
|
29
|
+
*
|
|
30
|
+
* http.createServer(server.handle.bind(server))
|
|
31
|
+
* ```
|
|
18
32
|
*/
|
|
19
33
|
export declare class Server {
|
|
20
34
|
#private;
|
|
21
35
|
/**
|
|
22
|
-
*
|
|
36
|
+
* Indicates whether the server has completed its boot process
|
|
23
37
|
*/
|
|
24
38
|
get booted(): boolean;
|
|
25
39
|
/**
|
|
26
|
-
*
|
|
40
|
+
* Indicates whether async local storage is enabled for request context
|
|
27
41
|
*/
|
|
28
42
|
get usingAsyncLocalStorage(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new Server instance
|
|
45
|
+
*
|
|
46
|
+
* @param app - AdonisJS application instance
|
|
47
|
+
* @param encryption - Encryption service for secure operations
|
|
48
|
+
* @param emitter - Event emitter for server lifecycle events
|
|
49
|
+
* @param logger - Logger instance for server operations
|
|
50
|
+
* @param config - Server configuration settings
|
|
51
|
+
*/
|
|
29
52
|
constructor(app: Application<any>, encryption: Encryption, emitter: EmitterLike<HttpServerEvents>, logger: Logger, config: ServerConfig);
|
|
30
53
|
/**
|
|
31
|
-
* Creates a pipeline
|
|
54
|
+
* Creates a testing middleware pipeline for unit/integration testing
|
|
55
|
+
*
|
|
56
|
+
* @param middleware - Array of middleware classes to include in pipeline
|
|
57
|
+
* @returns TestingMiddlewarePipeline instance for test execution
|
|
32
58
|
*/
|
|
33
59
|
pipeline(middleware: MiddlewareAsClass[]): TestingMiddlewarePipeline;
|
|
34
60
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* of middleware
|
|
61
|
+
* Registers global middleware to run on all incoming HTTP requests
|
|
62
|
+
*
|
|
63
|
+
* @param middleware - Array of lazy-imported middleware classes
|
|
64
|
+
* @returns The Server instance for method chaining
|
|
38
65
|
*/
|
|
39
66
|
use(middleware: LazyImport<MiddlewareAsClass>[]): this;
|
|
40
67
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
68
|
+
* Registers a custom error handler for HTTP request processing
|
|
69
|
+
*
|
|
70
|
+
* @param handler - Lazy import of the error handler class
|
|
71
|
+
* @returns The Server instance for method chaining
|
|
43
72
|
*/
|
|
44
73
|
errorHandler(handler: LazyImport<ErrorHandlerAsAClass>): this;
|
|
45
74
|
/**
|
|
46
|
-
*
|
|
75
|
+
* Initializes the server by compiling middleware, committing routes, and resolving handlers
|
|
47
76
|
*
|
|
48
|
-
*
|
|
49
|
-
* -
|
|
77
|
+
* Performs the following operations:
|
|
78
|
+
* - Compiles the middleware stack
|
|
79
|
+
* - Commits registered routes to the router
|
|
80
|
+
* - Resolves and instantiates the custom error handler
|
|
50
81
|
*/
|
|
51
82
|
boot(): Promise<void>;
|
|
52
83
|
/**
|
|
53
|
-
*
|
|
84
|
+
* Configures the underlying Node.js HTTP/HTTPS server with timeout settings
|
|
85
|
+
*
|
|
86
|
+
* @param server - Node.js HTTP or HTTPS server instance
|
|
54
87
|
*/
|
|
55
88
|
setNodeServer(server: HttpServer | HttpsServer): void;
|
|
56
89
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
90
|
+
* Gets the underlying Node.js HTTP/HTTPS server instance
|
|
91
|
+
*
|
|
92
|
+
* @returns The configured server instance or undefined if not set
|
|
59
93
|
*/
|
|
60
94
|
getNodeServer(): HttpServer<typeof IncomingMessage, typeof ServerResponse> | HttpsServer<typeof IncomingMessage, typeof ServerResponse> | undefined;
|
|
61
95
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
96
|
+
* Gets the router instance used for route registration and matching
|
|
97
|
+
*
|
|
98
|
+
* @returns The Router instance
|
|
64
99
|
*/
|
|
65
100
|
getRouter(): Router;
|
|
66
101
|
/**
|
|
67
|
-
* Creates
|
|
102
|
+
* Creates a Request instance from Node.js request/response objects
|
|
103
|
+
*
|
|
104
|
+
* @param req - Node.js IncomingMessage
|
|
105
|
+
* @param res - Node.js ServerResponse
|
|
106
|
+
* @returns New Request instance
|
|
68
107
|
*/
|
|
69
108
|
createRequest(req: IncomingMessage, res: ServerResponse): Request;
|
|
70
109
|
/**
|
|
71
|
-
* Creates
|
|
110
|
+
* Creates a Response instance from Node.js request/response objects
|
|
111
|
+
*
|
|
112
|
+
* @param req - Node.js IncomingMessage
|
|
113
|
+
* @param res - Node.js ServerResponse
|
|
114
|
+
* @returns New Response instance
|
|
72
115
|
*/
|
|
73
116
|
createResponse(req: IncomingMessage, res: ServerResponse): Response;
|
|
74
117
|
/**
|
|
75
|
-
* Creates an instance
|
|
118
|
+
* Creates an HttpContext instance with request-specific logger
|
|
119
|
+
*
|
|
120
|
+
* @param request - Request instance
|
|
121
|
+
* @param response - Response instance
|
|
122
|
+
* @param resolver - Container resolver for dependency injection
|
|
123
|
+
* @returns New HttpContext instance
|
|
76
124
|
*/
|
|
77
125
|
createHttpContext(request: Request, response: Response, resolver: ContainerResolver<any>): HttpContext;
|
|
78
126
|
/**
|
|
79
|
-
*
|
|
127
|
+
* Gets the list of registered global middleware
|
|
128
|
+
*
|
|
129
|
+
* @returns Array of parsed global middleware
|
|
80
130
|
*/
|
|
81
131
|
getMiddlewareList(): ParsedGlobalMiddleware[];
|
|
82
132
|
/**
|
|
83
|
-
*
|
|
133
|
+
* Handles an incoming HTTP request by creating context and processing through pipeline
|
|
134
|
+
*
|
|
135
|
+
* @param req - Node.js IncomingMessage
|
|
136
|
+
* @param res - Node.js ServerResponse
|
|
137
|
+
* @returns Promise that resolves when request processing is complete
|
|
84
138
|
*/
|
|
85
139
|
handle(req: IncomingMessage, res: ServerResponse): Promise<any>;
|
|
86
140
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import diagnostics_channel from 'node:diagnostics_channel';
|
|
2
|
-
import type { MiddlewareTracingData } from './types/tracing_channels.ts';
|
|
2
|
+
import type { MiddlewareTracingData, HTTPRequestTracingData, RouteHandlerTracingData } from './types/tracing_channels.ts';
|
|
3
3
|
/**
|
|
4
4
|
* Traces every HTTP request handled by the {@link Server} class.
|
|
5
5
|
*/
|
|
6
|
-
export declare const httpRequest: diagnostics_channel.TracingChannel<"adonisjs
|
|
6
|
+
export declare const httpRequest: diagnostics_channel.TracingChannel<"adonisjs.http.request", HTTPRequestTracingData>;
|
|
7
7
|
/**
|
|
8
8
|
* Traces middleware executed during the HTTP request
|
|
9
9
|
*/
|
|
10
|
-
export declare const httpMiddleware: diagnostics_channel.TracingChannel<"adonisjs
|
|
10
|
+
export declare const httpMiddleware: diagnostics_channel.TracingChannel<"adonisjs.http.middleware", MiddlewareTracingData>;
|
|
11
11
|
/**
|
|
12
12
|
* Traces the exception handler that converts errors into HTTP responses
|
|
13
13
|
*/
|
|
@@ -15,7 +15,7 @@ export declare const httpExceptionHandler: diagnostics_channel.TracingChannel<"a
|
|
|
15
15
|
/**
|
|
16
16
|
* Traces route handler executed during the HTTP request
|
|
17
17
|
*/
|
|
18
|
-
export declare const httpRouteHandler: diagnostics_channel.TracingChannel<"adonisjs
|
|
18
|
+
export declare const httpRouteHandler: diagnostics_channel.TracingChannel<"adonisjs.http.route.handler", RouteHandlerTracingData>;
|
|
19
19
|
/**
|
|
20
20
|
* Traces non-stream and non-file download responses written by the AdonisJS
|
|
21
21
|
* response class
|
|
@@ -2,69 +2,94 @@ import type { ContainerResolver } from '@adonisjs/fold';
|
|
|
2
2
|
import type { NextFn } from '@poppinss/middleware/types';
|
|
3
3
|
import type { Constructor, LazyImport } from '@poppinss/utils/types';
|
|
4
4
|
import type { HttpContext } from '../http_context/main.ts';
|
|
5
|
+
export { NextFn };
|
|
5
6
|
/**
|
|
6
|
-
* Middleware represented as a class
|
|
7
|
+
* Middleware represented as a class constructor that implements a handle method
|
|
7
8
|
*/
|
|
8
9
|
export type MiddlewareAsClass = Constructor<{
|
|
9
10
|
handle: (ctx: HttpContext, next: NextFn, args?: any) => any;
|
|
10
11
|
}>;
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
+
* Utility type to check if a union type includes undefined or null values
|
|
13
14
|
*/
|
|
14
15
|
type HasUndefined<T> = T extends NonNullable<T> ? true : false;
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
+
* Extracts and returns the argument types accepted by a middleware's handle method
|
|
18
|
+
* Returns an empty array if no args, otherwise returns the args type as a tuple
|
|
17
19
|
*/
|
|
18
20
|
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]?];
|
|
19
21
|
/**
|
|
20
|
-
*
|
|
22
|
+
* Middleware defined as a function that accepts HTTP context and next function
|
|
21
23
|
*/
|
|
22
24
|
export type MiddlewareFn = (ctx: HttpContext, next: NextFn) => any;
|
|
23
25
|
/**
|
|
24
|
-
*
|
|
26
|
+
* Representation of a parsed global middleware with its metadata and execution handler
|
|
25
27
|
*/
|
|
26
28
|
export type ParsedGlobalMiddleware = {
|
|
29
|
+
/** Optional name for the middleware */
|
|
27
30
|
name?: string;
|
|
31
|
+
/** Reference to the middleware class or lazy import */
|
|
28
32
|
reference: LazyImport<MiddlewareAsClass> | MiddlewareAsClass;
|
|
33
|
+
/** Handler function that executes the middleware */
|
|
29
34
|
handle: (resolver: ContainerResolver<any>, ...args: [ctx: HttpContext, next: NextFn, params?: any]) => any;
|
|
30
35
|
};
|
|
31
36
|
/**
|
|
32
|
-
*
|
|
37
|
+
* Representation of a parsed named middleware with its metadata, arguments and execution handler
|
|
33
38
|
*/
|
|
34
39
|
export type ParsedNamedMiddleware = {
|
|
40
|
+
/** Name identifier for the middleware */
|
|
35
41
|
name: string;
|
|
42
|
+
/** Reference to the middleware class or lazy import */
|
|
36
43
|
reference: LazyImport<MiddlewareAsClass> | MiddlewareAsClass;
|
|
44
|
+
/** Handler function that executes the middleware */
|
|
37
45
|
handle: ParsedGlobalMiddleware['handle'];
|
|
46
|
+
/** Arguments to pass to the middleware */
|
|
38
47
|
args: any;
|
|
39
48
|
};
|
|
40
49
|
/**
|
|
41
|
-
*
|
|
50
|
+
* Information node describing different types of middleware handlers and their metadata
|
|
42
51
|
*/
|
|
43
52
|
export type MiddlewareHandlerInfo = {
|
|
53
|
+
/** Type identifier for closure middleware */
|
|
44
54
|
type: 'closure';
|
|
55
|
+
/** Name of the closure middleware */
|
|
45
56
|
name: string;
|
|
46
57
|
} | {
|
|
58
|
+
/** Type identifier for named middleware */
|
|
47
59
|
type: 'named';
|
|
60
|
+
/** Name of the named middleware */
|
|
48
61
|
name: string;
|
|
62
|
+
/** Arguments to pass to the middleware */
|
|
49
63
|
args: any | undefined;
|
|
64
|
+
/** Method name on the middleware class */
|
|
50
65
|
method: string;
|
|
66
|
+
/** Module name or file path for the middleware */
|
|
51
67
|
moduleNameOrPath: string;
|
|
52
68
|
} | {
|
|
69
|
+
/** Type identifier for global middleware */
|
|
53
70
|
type: 'global';
|
|
71
|
+
/** Optional name for the global middleware */
|
|
54
72
|
name?: string | undefined;
|
|
73
|
+
/** Method name on the middleware class */
|
|
55
74
|
method: string;
|
|
75
|
+
/** Module name or file path for the middleware */
|
|
56
76
|
moduleNameOrPath: string;
|
|
57
77
|
};
|
|
58
78
|
/**
|
|
59
|
-
*
|
|
79
|
+
* Information node describing different types of route handlers and their metadata
|
|
60
80
|
*/
|
|
61
81
|
export type RouteHandlerInfo = {
|
|
82
|
+
/** Type identifier for closure route handler */
|
|
62
83
|
type: 'closure';
|
|
84
|
+
/** Name of the closure handler */
|
|
63
85
|
name: string;
|
|
86
|
+
/** Optional arguments for the closure */
|
|
64
87
|
args?: string;
|
|
65
88
|
} | {
|
|
89
|
+
/** Type identifier for controller route handler */
|
|
66
90
|
type: 'controller';
|
|
91
|
+
/** Method name on the controller class */
|
|
67
92
|
method: string;
|
|
93
|
+
/** Module name or file path for the controller */
|
|
68
94
|
moduleNameOrPath: string;
|
|
69
95
|
};
|
|
70
|
-
export {};
|
package/build/src/types/qs.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for query string parsing and stringification
|
|
3
|
+
*/
|
|
1
4
|
export type QSParserConfig = {
|
|
5
|
+
/** Configuration options for parsing query strings */
|
|
2
6
|
parse: {
|
|
3
7
|
/**
|
|
4
8
|
* Nesting depth till the parameters should be parsed.
|
|
@@ -33,6 +37,7 @@ export type QSParserConfig = {
|
|
|
33
37
|
*/
|
|
34
38
|
comma: boolean;
|
|
35
39
|
};
|
|
40
|
+
/** Configuration options for stringifying query objects */
|
|
36
41
|
stringify: {
|
|
37
42
|
/**
|
|
38
43
|
* URI encode the stringified query string
|
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
import { type Readable } from 'node:stream';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Configuration options for HTTP cookies that can be set on the response
|
|
4
4
|
*/
|
|
5
5
|
export type CookieOptions = {
|
|
6
|
+
/** Domain name for the cookie */
|
|
6
7
|
domain: string;
|
|
8
|
+
/** Expiration date for the cookie or function that returns the date */
|
|
7
9
|
expires: Date | (() => Date);
|
|
10
|
+
/** Whether the cookie should be accessible only through HTTP(S) */
|
|
8
11
|
httpOnly: boolean;
|
|
12
|
+
/** Maximum age of the cookie in seconds or as a string */
|
|
9
13
|
maxAge: number | string;
|
|
14
|
+
/** URL path for which the cookie is valid */
|
|
10
15
|
path: string;
|
|
16
|
+
/** SameSite attribute to control cross-site request behavior */
|
|
11
17
|
sameSite: boolean | 'lax' | 'none' | 'strict';
|
|
18
|
+
/** Whether the cookie should only be sent over HTTPS */
|
|
12
19
|
secure: boolean;
|
|
20
|
+
/** Whether the cookie should be partitioned (optional) */
|
|
13
21
|
partitioned?: boolean;
|
|
22
|
+
/** Priority level for the cookie (optional) */
|
|
14
23
|
priority?: 'low' | 'medium' | 'high';
|
|
15
24
|
};
|
|
16
25
|
/**
|
|
17
|
-
* Types
|
|
18
|
-
* string
|
|
26
|
+
* Types that can be cast to a string for HTTP response headers
|
|
19
27
|
*/
|
|
20
28
|
export type CastableHeader = string | number | boolean | string[] | number[] | boolean[];
|
|
21
29
|
/**
|
|
22
|
-
*
|
|
30
|
+
* Configuration options for HTTP response handling and processing
|
|
23
31
|
*/
|
|
24
32
|
export type ResponseConfig = {
|
|
25
33
|
/**
|
|
@@ -36,11 +44,11 @@ export type ResponseConfig = {
|
|
|
36
44
|
*/
|
|
37
45
|
jsonpCallbackName: string;
|
|
38
46
|
/**
|
|
39
|
-
*
|
|
47
|
+
* Default options to apply when setting cookies
|
|
40
48
|
*/
|
|
41
49
|
cookie: Partial<CookieOptions>;
|
|
42
50
|
};
|
|
43
51
|
/**
|
|
44
|
-
*
|
|
52
|
+
* A readable stream that can be piped to the response stream method
|
|
45
53
|
*/
|
|
46
54
|
export type ResponseStream = Readable;
|
|
@@ -5,81 +5,97 @@ import type { ServerErrorHandler } from './server.ts';
|
|
|
5
5
|
import type { HttpContext } from '../http_context/main.ts';
|
|
6
6
|
import type { MiddlewareFn, ParsedGlobalMiddleware } from './middleware.ts';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Configuration for matching and casting route parameters
|
|
9
9
|
*/
|
|
10
10
|
export type RouteMatcher = {
|
|
11
|
+
/** Regular expression to match parameter values */
|
|
11
12
|
match?: RegExp;
|
|
13
|
+
/** Function to cast string parameter values to specific types */
|
|
12
14
|
cast?: (value: string) => any;
|
|
13
15
|
};
|
|
14
16
|
/**
|
|
15
|
-
* Route token
|
|
17
|
+
* Route token structure used internally by the matchit routing library
|
|
16
18
|
*/
|
|
17
19
|
export type MatchItRouteToken = RouteMatcher & {
|
|
20
|
+
/** Original token string */
|
|
18
21
|
old: string;
|
|
22
|
+
/** Token type identifier (0=static, 1=param, 2=wildcard, 3=optional) */
|
|
19
23
|
type: 0 | 1 | 2 | 3;
|
|
24
|
+
/** Token value */
|
|
20
25
|
val: string;
|
|
26
|
+
/** Token end delimiter */
|
|
21
27
|
end: string;
|
|
22
28
|
};
|
|
23
29
|
/**
|
|
24
|
-
*
|
|
25
|
-
* the context as the first argument.
|
|
30
|
+
* Extracts method names from a controller class that accept HttpContext as first parameter
|
|
26
31
|
*/
|
|
27
32
|
export type GetControllerHandlers<Controller extends Constructor<any>> = {
|
|
28
33
|
[K in keyof InstanceType<Controller>]: InstanceType<Controller>[K] extends (ctx: HttpContext, ...args: any[]) => any ? K : never;
|
|
29
34
|
}[keyof InstanceType<Controller>];
|
|
30
35
|
/**
|
|
31
|
-
* Route handler
|
|
36
|
+
* Route handler implemented as a function that accepts HTTP context
|
|
32
37
|
*/
|
|
33
38
|
export type RouteFn = (ctx: HttpContext) => any;
|
|
34
39
|
/**
|
|
35
|
-
* Route handler
|
|
40
|
+
* Route handler representation stored in the route registry
|
|
36
41
|
*/
|
|
37
42
|
export type StoreRouteHandler = RouteFn | {
|
|
43
|
+
/** Optional name for the handler */
|
|
38
44
|
name?: string;
|
|
45
|
+
/** Method name on the controller */
|
|
39
46
|
method: string;
|
|
47
|
+
/** Dynamic import expression for lazy loading */
|
|
40
48
|
importExpression: string | null;
|
|
49
|
+
/** Reference to controller class or method */
|
|
41
50
|
reference: string | [LazyImport<Constructor<any>> | Constructor<any>, any?];
|
|
51
|
+
/** Handler execution function */
|
|
42
52
|
handle: (resolver: ContainerResolver<any>, ...args: [ctx: HttpContext, ...injections: any[]]) => any;
|
|
43
53
|
};
|
|
44
54
|
/**
|
|
45
|
-
*
|
|
55
|
+
* Middleware representation stored with route information
|
|
46
56
|
*/
|
|
47
57
|
export type StoreRouteMiddleware = MiddlewareFn | ({
|
|
48
58
|
name?: string;
|
|
49
59
|
args?: any[];
|
|
50
60
|
} & ParsedGlobalMiddleware);
|
|
51
61
|
/**
|
|
52
|
-
*
|
|
62
|
+
* Route storage structure for a specific HTTP method containing tokens and route mappings
|
|
53
63
|
*/
|
|
54
64
|
export type StoreMethodNode = {
|
|
65
|
+
/** Array of route tokens for pattern matching */
|
|
55
66
|
tokens: MatchItRouteToken[][];
|
|
67
|
+
/** Mapping from route patterns to unique route keys */
|
|
56
68
|
routeKeys: {
|
|
57
69
|
[pattern: string]: string;
|
|
58
70
|
};
|
|
71
|
+
/** Mapping from route patterns to route definitions */
|
|
59
72
|
routes: {
|
|
60
73
|
[pattern: string]: RouteJSON;
|
|
61
74
|
};
|
|
62
75
|
};
|
|
63
76
|
/**
|
|
64
|
-
*
|
|
65
|
-
* object has nested routes.
|
|
77
|
+
* Domain-specific route storage containing method-based route organization
|
|
66
78
|
*/
|
|
67
79
|
export type StoreDomainNode = {
|
|
80
|
+
/** HTTP method to method node mapping */
|
|
68
81
|
[method: string]: StoreMethodNode;
|
|
69
82
|
};
|
|
70
83
|
/**
|
|
71
|
-
*
|
|
84
|
+
* Complete route tree structure organizing routes by domains and methods
|
|
72
85
|
*/
|
|
73
86
|
export type StoreRoutesTree = {
|
|
87
|
+
/** Global route tokens for pattern matching */
|
|
74
88
|
tokens: MatchItRouteToken[][];
|
|
89
|
+
/** Domain-based route organization */
|
|
75
90
|
domains: {
|
|
76
91
|
[domain: string]: StoreDomainNode;
|
|
77
92
|
};
|
|
78
93
|
};
|
|
79
94
|
/**
|
|
80
|
-
*
|
|
95
|
+
* Result of successful route matching containing route details and extracted parameters
|
|
81
96
|
*/
|
|
82
97
|
export type MatchedRoute = {
|
|
98
|
+
/** The matched route definition */
|
|
83
99
|
route: RouteJSON;
|
|
84
100
|
/**
|
|
85
101
|
* A unique key for the looked up route
|
|
@@ -95,13 +111,14 @@ export type MatchedRoute = {
|
|
|
95
111
|
subdomains: Record<string, any>;
|
|
96
112
|
};
|
|
97
113
|
/**
|
|
98
|
-
*
|
|
114
|
+
* Collection of parameter matchers indexed by parameter name
|
|
99
115
|
*/
|
|
100
116
|
export type RouteMatchers = {
|
|
117
|
+
/** Parameter name to matcher mapping */
|
|
101
118
|
[param: string]: RouteMatcher;
|
|
102
119
|
};
|
|
103
120
|
/**
|
|
104
|
-
*
|
|
121
|
+
* Complete route definition with all metadata, handlers, and execution context
|
|
105
122
|
*/
|
|
106
123
|
export type RouteJSON = {
|
|
107
124
|
/**
|
|
@@ -147,24 +164,28 @@ export type RouteJSON = {
|
|
|
147
164
|
matchers: RouteMatchers;
|
|
148
165
|
};
|
|
149
166
|
/**
|
|
150
|
-
*
|
|
167
|
+
* Standard RESTful resource action names for CRUD operations
|
|
151
168
|
*/
|
|
152
169
|
export type ResourceActionNames = 'create' | 'index' | 'store' | 'show' | 'edit' | 'update' | 'destroy';
|
|
153
170
|
/**
|
|
154
|
-
* Options
|
|
155
|
-
* @deprecated
|
|
171
|
+
* @deprecated Options for URL generation (use URLBuilder instead)
|
|
156
172
|
*/
|
|
157
173
|
export type MakeUrlOptions = {
|
|
174
|
+
/** Query string parameters to append */
|
|
158
175
|
qs?: Record<string, any>;
|
|
176
|
+
/** Domain name to use for the URL */
|
|
159
177
|
domain?: string;
|
|
178
|
+
/** Prefix to prepend to the generated URL */
|
|
160
179
|
prefixUrl?: string;
|
|
180
|
+
/** Whether to disable route lookup optimization */
|
|
161
181
|
disableRouteLookup?: boolean;
|
|
162
182
|
};
|
|
163
183
|
/**
|
|
164
|
-
* Options
|
|
165
|
-
* @deprecated
|
|
184
|
+
* @deprecated Options for signed URL generation (use URLBuilder instead)
|
|
166
185
|
*/
|
|
167
186
|
export type MakeSignedUrlOptions = MakeUrlOptions & {
|
|
187
|
+
/** Expiration time for the signed URL */
|
|
168
188
|
expiresIn?: string | number;
|
|
189
|
+
/** Purpose identifier for the signed URL */
|
|
169
190
|
purpose?: string;
|
|
170
191
|
};
|
|
@@ -5,63 +5,78 @@ import type { RequestConfig } from './request.ts';
|
|
|
5
5
|
import type { ResponseConfig } from './response.ts';
|
|
6
6
|
import type { HttpContext } from '../http_context/main.ts';
|
|
7
7
|
/**
|
|
8
|
-
* Normalized HTTP error used by
|
|
9
|
-
* handler.
|
|
8
|
+
* Normalized HTTP error structure used by exception handlers
|
|
10
9
|
*/
|
|
11
10
|
export type HttpError = {
|
|
11
|
+
/** Error message describing the issue */
|
|
12
12
|
message: string;
|
|
13
|
+
/** HTTP status code */
|
|
13
14
|
status: number;
|
|
15
|
+
/** Optional error code identifier */
|
|
14
16
|
code?: string;
|
|
17
|
+
/** Optional stack trace */
|
|
15
18
|
stack?: string;
|
|
19
|
+
/** Optional underlying cause of the error */
|
|
16
20
|
cause?: any;
|
|
21
|
+
/** Optional additional error messages */
|
|
17
22
|
messages?: any;
|
|
23
|
+
/** Optional validation or field errors */
|
|
18
24
|
errors?: any;
|
|
25
|
+
/** Optional custom error handler method */
|
|
19
26
|
handle?: (...args: any[]) => any;
|
|
27
|
+
/** Optional error reporting method */
|
|
20
28
|
report?: (...args: any[]) => any;
|
|
21
29
|
};
|
|
22
30
|
/**
|
|
23
|
-
*
|
|
31
|
+
* Pipeline interface for executing middleware chains during testing
|
|
24
32
|
*/
|
|
25
33
|
export interface TestingMiddlewarePipeline {
|
|
34
|
+
/** Set the final handler for the pipeline */
|
|
26
35
|
finalHandler(handler: FinalHandler): this;
|
|
36
|
+
/** Set the error handler for the pipeline */
|
|
27
37
|
errorHandler(handler: ErrorHandler): this;
|
|
38
|
+
/** Execute the middleware pipeline with the given context */
|
|
28
39
|
run(ctx: HttpContext): Promise<any>;
|
|
29
40
|
}
|
|
30
41
|
/**
|
|
31
|
-
*
|
|
42
|
+
* Expression format for defining HTTP status code ranges for error pages
|
|
32
43
|
*/
|
|
33
44
|
export type StatusPageRange = `${number}..${number}` | `${number}` | number;
|
|
34
45
|
/**
|
|
35
|
-
*
|
|
36
|
-
* error.
|
|
46
|
+
* Callback function to render custom status pages for HTTP errors
|
|
37
47
|
*/
|
|
38
48
|
export type StatusPageRenderer = (error: HttpError, ctx: HttpContext) => any | Promise<any>;
|
|
39
49
|
/**
|
|
40
|
-
*
|
|
50
|
+
* Payload structure for the http:request_completed event
|
|
41
51
|
*/
|
|
42
52
|
export type HttpRequestFinishedPayload = {
|
|
53
|
+
/** HTTP context for the completed request */
|
|
43
54
|
ctx: HttpContext;
|
|
55
|
+
/** Request duration as a high-resolution time tuple */
|
|
44
56
|
duration: [number, number];
|
|
45
57
|
};
|
|
46
58
|
/**
|
|
47
|
-
*
|
|
59
|
+
* Event types and payloads emitted by the HTTP server
|
|
48
60
|
*/
|
|
49
61
|
export type HttpServerEvents = {
|
|
62
|
+
/** Event fired when an HTTP request is completed */
|
|
50
63
|
'http:request_completed': HttpRequestFinishedPayload;
|
|
51
64
|
};
|
|
52
65
|
/**
|
|
53
|
-
*
|
|
66
|
+
* Interface for handling and reporting HTTP errors in the server
|
|
54
67
|
*/
|
|
55
68
|
export type ServerErrorHandler = {
|
|
69
|
+
/** Method to report errors for logging or monitoring */
|
|
56
70
|
report: (error: any, ctx: HttpContext) => any;
|
|
71
|
+
/** Method to handle errors and send appropriate responses */
|
|
57
72
|
handle: (error: any, ctx: HttpContext) => any;
|
|
58
73
|
};
|
|
59
74
|
/**
|
|
60
|
-
*
|
|
75
|
+
* Constructor type for error handler classes that implement ServerErrorHandler
|
|
61
76
|
*/
|
|
62
77
|
export type ErrorHandlerAsAClass = Constructor<ServerErrorHandler>;
|
|
63
78
|
/**
|
|
64
|
-
*
|
|
79
|
+
* Complete configuration options for the HTTP server extending request and response configs
|
|
65
80
|
*/
|
|
66
81
|
export type ServerConfig = RequestConfig & ResponseConfig & {
|
|
67
82
|
/**
|
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import type { RouteJSON } from './route.ts';
|
|
2
2
|
import type { HttpContext } from '../http_context/main.ts';
|
|
3
3
|
import type { MiddlewareFn, ParsedGlobalMiddleware, ParsedNamedMiddleware } from './middleware.ts';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Tracing data structure for HTTP request events
|
|
6
|
+
*/
|
|
7
|
+
export type HTTPRequestTracingData = {
|
|
8
|
+
/** HTTP context for the traced request */
|
|
9
|
+
ctx: HttpContext;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Tracing data structure for middleware execution events
|
|
13
|
+
*/
|
|
14
|
+
export type MiddlewareTracingData = {
|
|
15
|
+
/** The middleware being traced */
|
|
16
|
+
middleware: ParsedGlobalMiddleware | ParsedNamedMiddleware | MiddlewareFn;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Tracing data structure for route handler execution events
|
|
20
|
+
*/
|
|
21
|
+
export type RouteHandlerTracingData = {
|
|
22
|
+
/** The route being traced */
|
|
23
|
+
route: RouteJSON;
|
|
24
|
+
};
|