@adonisjs/http-server 8.0.0-next.5 → 8.0.0-next.6

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 (56) hide show
  1. package/build/{chunk-BFGF3A5X.js → chunk-7ROFCP6L.js} +1095 -548
  2. package/build/{chunk-ASX56VAK.js → chunk-NQNHMINZ.js} +59 -0
  3. package/build/factories/http_context.d.ts +2 -1
  4. package/build/factories/http_server.d.ts +7 -0
  5. package/build/factories/main.js +31 -5
  6. package/build/factories/qs_parser_factory.d.ts +3 -2
  7. package/build/factories/request.d.ts +1 -0
  8. package/build/factories/response.d.ts +1 -0
  9. package/build/factories/router.d.ts +1 -0
  10. package/build/factories/server_factory.d.ts +1 -0
  11. package/build/factories/url_builder_factory.d.ts +1 -0
  12. package/build/index.d.ts +3 -1
  13. package/build/index.js +87 -37
  14. package/build/src/cookies/client.d.ts +35 -0
  15. package/build/src/cookies/drivers/encrypted.d.ts +13 -0
  16. package/build/src/cookies/drivers/plain.d.ts +9 -0
  17. package/build/src/cookies/drivers/signed.d.ts +13 -0
  18. package/build/src/cookies/parser.d.ts +18 -0
  19. package/build/src/cookies/serializer.d.ts +20 -0
  20. package/build/src/define_config.d.ts +1 -3
  21. package/build/src/define_middleware.d.ts +1 -1
  22. package/build/src/exception_handler.d.ts +72 -31
  23. package/build/src/helpers.d.ts +50 -0
  24. package/build/src/helpers.js +5 -1
  25. package/build/src/http_context/local_storage.d.ts +17 -0
  26. package/build/src/http_context/main.d.ts +8 -0
  27. package/build/src/qs.d.ts +14 -0
  28. package/build/src/redirect.d.ts +25 -9
  29. package/build/src/request.d.ts +109 -10
  30. package/build/src/response.d.ts +399 -203
  31. package/build/src/router/brisk.d.ts +13 -0
  32. package/build/src/router/executor.d.ts +4 -0
  33. package/build/src/router/factories/use_return_value.d.ts +5 -0
  34. package/build/src/router/group.d.ts +17 -0
  35. package/build/src/router/legacy/url_builder.d.ts +7 -0
  36. package/build/src/router/main.d.ts +72 -1
  37. package/build/src/router/matchers.d.ts +3 -0
  38. package/build/src/router/resource.d.ts +33 -0
  39. package/build/src/router/route.d.ts +8 -0
  40. package/build/src/router/signed_url_builder.d.ts +4 -8
  41. package/build/src/router/store.d.ts +9 -0
  42. package/build/src/router/url_builder.d.ts +4 -9
  43. package/build/src/server/factories/middleware_handler.d.ts +10 -1
  44. package/build/src/server/factories/route_finder.d.ts +13 -3
  45. package/build/src/server/factories/write_response.d.ts +9 -2
  46. package/build/src/server/main.d.ts +77 -23
  47. package/build/src/tracing_channels.d.ts +4 -4
  48. package/build/src/types/middleware.d.ts +33 -8
  49. package/build/src/types/qs.d.ts +5 -0
  50. package/build/src/types/request.d.ts +1 -1
  51. package/build/src/types/response.d.ts +14 -6
  52. package/build/src/types/route.d.ts +40 -17
  53. package/build/src/types/server.d.ts +26 -11
  54. package/build/src/types/tracing_channels.d.ts +21 -3
  55. package/build/src/types/url_builder.d.ts +24 -11
  56. package/package.json +15 -13
@@ -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 HTTP server implementation to handle incoming requests and respond using the
17
- * registered routes.
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
- * Check if the server has already been booted
36
+ * Indicates whether the server has completed its boot process
23
37
  */
24
38
  get booted(): boolean;
25
39
  /**
26
- * Know if async local storage is enabled or not.
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 of middleware.
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
- * Define an array of middleware to use on all the incoming HTTP request.
36
- * Calling this method multiple times pushes to the existing list
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
- * Register a custom error handler for HTTP requests.
42
- * All errors will be reported to this method
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
- * Boot the server. Calling this method performs the following actions.
75
+ * Initializes the server by compiling middleware, committing routes, and resolving handlers
47
76
  *
48
- * - Register routes with the store.
49
- * - Resolve and construct the error handler.
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
- * Set the HTTP server instance used to listen for requests.
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
- * Returns reference to the underlying HTTP server
58
- * in use
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
- * Returns reference to the router instance used
63
- * by the server.
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 an instance of the [[Request]] class
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 an instance of the [[Response]] class
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 of the [[HttpContext]] class
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
- * Returns a list of server middleware stack
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
- * Handle request
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:http.request", import("./http_context/main.ts").HttpContext>;
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:http.middleware", MiddlewareTracingData>;
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:http.route.handler", import("./types/route.ts").RouteJSON>;
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
@@ -3,68 +3,93 @@ 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
5
  /**
6
- * Middleware represented as a class
6
+ * Middleware represented as a class constructor that implements a handle method
7
7
  */
8
8
  export type MiddlewareAsClass = Constructor<{
9
9
  handle: (ctx: HttpContext, next: NextFn, args?: any) => any;
10
10
  }>;
11
11
  /**
12
- * Check if a union has undefined or null
12
+ * Utility type to check if a union type includes undefined or null values
13
13
  */
14
14
  type HasUndefined<T> = T extends NonNullable<T> ? true : false;
15
15
  /**
16
- * Returns the arguments accepted by the middleware's handle method
16
+ * Extracts and returns the argument types accepted by a middleware's handle method
17
+ * Returns an empty array if no args, otherwise returns the args type as a tuple
17
18
  */
18
19
  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
20
  /**
20
- * The middleware defined as a function on the router or the server
21
+ * Middleware defined as a function that accepts HTTP context and next function
21
22
  */
22
23
  export type MiddlewareFn = (ctx: HttpContext, next: NextFn) => any;
23
24
  /**
24
- * Parsed global middleware
25
+ * Representation of a parsed global middleware with its metadata and execution handler
25
26
  */
26
27
  export type ParsedGlobalMiddleware = {
28
+ /** Optional name for the middleware */
27
29
  name?: string;
30
+ /** Reference to the middleware class or lazy import */
28
31
  reference: LazyImport<MiddlewareAsClass> | MiddlewareAsClass;
32
+ /** Handler function that executes the middleware */
29
33
  handle: (resolver: ContainerResolver<any>, ...args: [ctx: HttpContext, next: NextFn, params?: any]) => any;
30
34
  };
31
35
  /**
32
- * Parsed named middleware
36
+ * Representation of a parsed named middleware with its metadata, arguments and execution handler
33
37
  */
34
38
  export type ParsedNamedMiddleware = {
39
+ /** Name identifier for the middleware */
35
40
  name: string;
41
+ /** Reference to the middleware class or lazy import */
36
42
  reference: LazyImport<MiddlewareAsClass> | MiddlewareAsClass;
43
+ /** Handler function that executes the middleware */
37
44
  handle: ParsedGlobalMiddleware['handle'];
45
+ /** Arguments to pass to the middleware */
38
46
  args: any;
39
47
  };
40
48
  /**
41
- * Info node representing a middleware handler
49
+ * Information node describing different types of middleware handlers and their metadata
42
50
  */
43
51
  export type MiddlewareHandlerInfo = {
52
+ /** Type identifier for closure middleware */
44
53
  type: 'closure';
54
+ /** Name of the closure middleware */
45
55
  name: string;
46
56
  } | {
57
+ /** Type identifier for named middleware */
47
58
  type: 'named';
59
+ /** Name of the named middleware */
48
60
  name: string;
61
+ /** Arguments to pass to the middleware */
49
62
  args: any | undefined;
63
+ /** Method name on the middleware class */
50
64
  method: string;
65
+ /** Module name or file path for the middleware */
51
66
  moduleNameOrPath: string;
52
67
  } | {
68
+ /** Type identifier for global middleware */
53
69
  type: 'global';
70
+ /** Optional name for the global middleware */
54
71
  name?: string | undefined;
72
+ /** Method name on the middleware class */
55
73
  method: string;
74
+ /** Module name or file path for the middleware */
56
75
  moduleNameOrPath: string;
57
76
  };
58
77
  /**
59
- * Info node representing route handler
78
+ * Information node describing different types of route handlers and their metadata
60
79
  */
61
80
  export type RouteHandlerInfo = {
81
+ /** Type identifier for closure route handler */
62
82
  type: 'closure';
83
+ /** Name of the closure handler */
63
84
  name: string;
85
+ /** Optional arguments for the closure */
64
86
  args?: string;
65
87
  } | {
88
+ /** Type identifier for controller route handler */
66
89
  type: 'controller';
90
+ /** Method name on the controller class */
67
91
  method: string;
92
+ /** Module name or file path for the controller */
68
93
  moduleNameOrPath: string;
69
94
  };
70
95
  export {};
@@ -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,5 +1,5 @@
1
1
  /**
2
- * Shape of the request config
2
+ * Configuration options for HTTP request handling and processing
3
3
  */
4
4
  export type RequestConfig = {
5
5
  /**
@@ -1,25 +1,33 @@
1
1
  import { type Readable } from 'node:stream';
2
2
  /**
3
- * Cookie options can that can be set on the response
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 from which response header can be casted to a
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
- * Config accepted by response the class
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
- * Options to set cookies
47
+ * Default options to apply when setting cookies
40
48
  */
41
49
  cookie: Partial<CookieOptions>;
42
50
  };
43
51
  /**
44
- * Stream that can be piped to the "response.stream" method
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
- * Shape of a route param matcher
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 stored by matchit library
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
- * Returns a union of methods from a controller that accepts
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 defined as a function
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 persisted with the route store
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
- * The middleware persisted with the route store
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
- * An object of routes for a given HTTP method
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
- * Each domain node container an object of methods. Each method
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
- * Routes tree stored within the routes store
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
- * Shape of the matched route for a pattern, method and domain.
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
- * A collection of route matchers
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
- * Representation of a route as JSON
121
+ * Complete route definition with all metadata, handlers, and execution context
105
122
  */
106
123
  export type RouteJSON = {
107
124
  /**
@@ -147,24 +164,30 @@ export type RouteJSON = {
147
164
  matchers: RouteMatchers;
148
165
  };
149
166
  /**
150
- * Resource action names
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 accepted by makeUrl method
171
+ * Options for URL generation (deprecated - use URLBuilder instead)
155
172
  * @deprecated
156
173
  */
157
174
  export type MakeUrlOptions = {
175
+ /** Query string parameters to append */
158
176
  qs?: Record<string, any>;
177
+ /** Domain name to use for the URL */
159
178
  domain?: string;
179
+ /** Prefix to prepend to the generated URL */
160
180
  prefixUrl?: string;
181
+ /** Whether to disable route lookup optimization */
161
182
  disableRouteLookup?: boolean;
162
183
  };
163
184
  /**
164
- * Options accepted by makeSignedUrl method
185
+ * Options for signed URL generation (deprecated - use URLBuilder instead)
165
186
  * @deprecated
166
187
  */
167
188
  export type MakeSignedUrlOptions = MakeUrlOptions & {
189
+ /** Expiration time for the signed URL */
168
190
  expiresIn?: string | number;
191
+ /** Purpose identifier for the signed URL */
169
192
  purpose?: string;
170
193
  };
@@ -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 the exception
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
- * The pipeline for executing middleware during tests
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
- * The expression to define a status page range
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
- * The callback function to render status page for a given
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
- * Data type for the "http:request_completed" event
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
- * Events emitted by the HttpServer
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
- * Error handler to handle HTTP errors
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
- * Error handler represented as a class
75
+ * Constructor type for error handler classes that implement ServerErrorHandler
61
76
  */
62
77
  export type ErrorHandlerAsAClass = Constructor<ServerErrorHandler>;
63
78
  /**
64
- * Config accepted by the HTTP server
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
- export type HTTPRequestTracingData = HttpContext;
5
- export type MiddlewareTracingData = ParsedGlobalMiddleware | ParsedNamedMiddleware | MiddlewareFn;
6
- export type RouteHandlerTracingData = RouteJSON;
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
+ };