@adonisjs/http-server 8.0.0-next.1 → 8.0.0-next.10

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 (67) hide show
  1. package/build/chunk-2QM3D5BN.js +87 -0
  2. package/build/chunk-5PWHBE2E.js +128 -0
  3. package/build/chunk-QDK57QGB.js +1176 -0
  4. package/build/{chunk-HMYAZG76.js → chunk-YBLFT4O6.js} +1146 -1663
  5. package/build/factories/http_context.d.ts +2 -1
  6. package/build/factories/http_server.d.ts +7 -0
  7. package/build/factories/main.js +33 -5
  8. package/build/factories/qs_parser_factory.d.ts +3 -2
  9. package/build/factories/request.d.ts +1 -0
  10. package/build/factories/response.d.ts +1 -0
  11. package/build/factories/router.d.ts +1 -0
  12. package/build/factories/server_factory.d.ts +1 -0
  13. package/build/factories/url_builder_factory.d.ts +3 -2
  14. package/build/index.d.ts +4 -1
  15. package/build/index.js +97 -42
  16. package/build/src/client/helpers.d.ts +37 -0
  17. package/build/src/client/types.d.ts +203 -0
  18. package/build/src/client/url_builder.d.ts +15 -0
  19. package/build/src/client/url_builder.js +12 -0
  20. package/build/src/cookies/client.d.ts +61 -3
  21. package/build/src/cookies/drivers/encrypted.d.ts +13 -0
  22. package/build/src/cookies/drivers/plain.d.ts +9 -0
  23. package/build/src/cookies/drivers/signed.d.ts +13 -0
  24. package/build/src/cookies/parser.d.ts +18 -0
  25. package/build/src/cookies/serializer.d.ts +21 -2
  26. package/build/src/debug.d.ts +13 -0
  27. package/build/src/define_config.d.ts +20 -4
  28. package/build/src/define_middleware.d.ts +20 -4
  29. package/build/src/errors.d.ts +60 -5
  30. package/build/src/exception_handler.d.ts +93 -39
  31. package/build/src/helpers.d.ts +57 -0
  32. package/build/src/helpers.js +9 -1
  33. package/build/src/http_context/local_storage.d.ts +17 -0
  34. package/build/src/http_context/main.d.ts +68 -10
  35. package/build/src/qs.d.ts +30 -2
  36. package/build/src/redirect.d.ts +84 -12
  37. package/build/src/request.d.ts +118 -12
  38. package/build/src/response.d.ts +416 -203
  39. package/build/src/response_status.d.ts +14 -0
  40. package/build/src/router/brisk.d.ts +15 -4
  41. package/build/src/router/executor.d.ts +4 -0
  42. package/build/src/router/factories/use_return_value.d.ts +5 -0
  43. package/build/src/router/group.d.ts +18 -1
  44. package/build/src/router/legacy/url_builder.d.ts +14 -14
  45. package/build/src/router/main.d.ts +79 -22
  46. package/build/src/router/matchers.d.ts +3 -0
  47. package/build/src/router/resource.d.ts +34 -1
  48. package/build/src/router/route.d.ts +28 -3
  49. package/build/src/router/signed_url_builder.d.ts +4 -8
  50. package/build/src/router/store.d.ts +9 -0
  51. package/build/src/server/factories/middleware_handler.d.ts +10 -1
  52. package/build/src/server/factories/route_finder.d.ts +13 -3
  53. package/build/src/server/factories/write_response.d.ts +9 -2
  54. package/build/src/server/main.d.ts +77 -23
  55. package/build/src/tracing_channels.d.ts +4 -4
  56. package/build/src/types/middleware.d.ts +34 -9
  57. package/build/src/types/qs.d.ts +5 -0
  58. package/build/src/types/request.d.ts +1 -1
  59. package/build/src/types/response.d.ts +14 -6
  60. package/build/src/types/route.d.ts +42 -42
  61. package/build/src/types/server.d.ts +26 -11
  62. package/build/src/types/tracing_channels.d.ts +21 -3
  63. package/build/src/types/url_builder.d.ts +10 -135
  64. package/build/src/utils.d.ts +71 -6
  65. package/package.json +26 -22
  66. package/build/chunk-ASX56VAK.js +0 -76
  67. package/build/src/router/url_builder.d.ts +0 -14
@@ -44,6 +44,8 @@ export declare class RoutesStore {
44
44
  * }
45
45
  * })
46
46
  * ```
47
+ * @param route - The route to add to the store
48
+ * @returns Current RoutesStore instance for method chaining
47
49
  */
48
50
  add(route: RouteJSON): this;
49
51
  /**
@@ -54,6 +56,11 @@ export declare class RoutesStore {
54
56
  * The domain parameter has to be a registered pattern and not the fully
55
57
  * qualified runtime domain. You must call `matchDomain` first to fetch
56
58
  * the pattern for qualified domain
59
+ * @param url - The URL to match
60
+ * @param method - HTTP method
61
+ * @param shouldDecodeParam - Whether to decode parameters
62
+ * @param domain - Optional domain tokens and hostname
63
+ * @returns Matched route or null if no match found
57
64
  */
58
65
  match(url: string, method: string, shouldDecodeParam: boolean, domain?: {
59
66
  tokens: MatchItRouteToken[];
@@ -61,6 +68,8 @@ export declare class RoutesStore {
61
68
  }): null | MatchedRoute;
62
69
  /**
63
70
  * Match hostname against registered domains.
71
+ * @param hostname - The hostname to match
72
+ * @returns Array of matched domain tokens
64
73
  */
65
74
  matchDomain(hostname?: string | null): MatchItRouteToken[];
66
75
  }
@@ -3,6 +3,15 @@ import type { NextFn } from '@poppinss/middleware/types';
3
3
  import type { HttpContext } from '../../http_context/main.ts';
4
4
  import { type ParsedGlobalMiddleware } from '../../types/middleware.ts';
5
5
  /**
6
- * The middleware handler invokes the middleware functions.
6
+ * Creates a middleware execution handler that invokes middleware functions with tracing support
7
+ *
8
+ * This factory function returns a middleware execution handler that:
9
+ * - Executes middleware with debug logging
10
+ * - Provides distributed tracing through tracing channels
11
+ * - Passes the container resolver, HTTP context, and next function to middleware
12
+ *
13
+ * @param resolver - Container resolver for dependency injection
14
+ * @param ctx - HTTP context containing request/response data
15
+ * @returns Middleware execution function
7
16
  */
8
17
  export declare function middlewareHandler(resolver: ContainerResolver<any>, ctx: HttpContext): (fn: ParsedGlobalMiddleware, next: NextFn) => Promise<any>;
@@ -3,8 +3,18 @@ import type { Router } from '../../router/main.ts';
3
3
  import type { HttpContext } from '../../http_context/main.ts';
4
4
  import type { ServerErrorHandler } from '../../types/server.ts';
5
5
  /**
6
- * The route finder is executed after the server middleware stack.
7
- * It looks for a matching route and executes the route middleware
8
- * stack.
6
+ * Creates a route finder function that matches HTTP requests to registered routes
7
+ *
8
+ * This factory function returns a route handler that:
9
+ * - Matches incoming requests against registered routes
10
+ * - Extracts route parameters and subdomains
11
+ * - Executes the matched route's handler and middleware
12
+ * - Throws E_ROUTE_NOT_FOUND error for unmatched requests
13
+ *
14
+ * @param router - Router instance containing registered routes
15
+ * @param resolver - Container resolver for dependency injection
16
+ * @param ctx - HTTP context containing request/response data
17
+ * @param errorResponder - Error handler for route execution errors
18
+ * @returns Route execution function
9
19
  */
10
20
  export declare function routeFinder(router: Router, resolver: ContainerResolver<any>, ctx: HttpContext, errorResponder: ServerErrorHandler['handle']): () => any;
@@ -1,6 +1,13 @@
1
1
  import type { HttpContext } from '../../http_context/main.ts';
2
2
  /**
3
- * Writes the response to the socket. The "finish" method can
4
- * raise error when unable to serialize the response.
3
+ * Creates a response writer function that finalizes HTTP responses with error handling
4
+ *
5
+ * This factory function returns a response finalizer that:
6
+ * - Calls the response.finish() method to send the response
7
+ * - Catches serialization errors and sends a 500 error response
8
+ * - Logs fatal errors for debugging and monitoring
9
+ *
10
+ * @param ctx - HTTP context containing the response to finalize
11
+ * @returns Response finalization function
5
12
  */
6
13
  export declare function writeResponse(ctx: HttpContext): () => void;
@@ -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
@@ -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
- * Check if a union has undefined or null
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
- * Returns the arguments accepted by the middleware's handle method
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
- * The middleware defined as a function on the router or the server
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
- * Parsed global middleware
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
- * Parsed named middleware
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
- * Info node representing a middleware handler
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
- * Info node representing route handler
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 {};
@@ -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;
@@ -4,79 +4,90 @@ import type { Constructor, LazyImport } from '@poppinss/utils/types';
4
4
  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
+ import { type ClientRouteJSON, type ClientRouteMatchItTokens } from '../client/types.ts';
7
8
  /**
8
- * Shape of a route param matcher
9
+ * Configuration for matching and casting route parameters
9
10
  */
10
11
  export type RouteMatcher = {
12
+ /** Regular expression to match parameter values */
11
13
  match?: RegExp;
14
+ /** Function to cast string parameter values to specific types */
12
15
  cast?: (value: string) => any;
13
16
  };
14
17
  /**
15
- * Route token stored by matchit library
18
+ * Route token structure used internally by the matchit routing library
16
19
  */
17
- export type MatchItRouteToken = RouteMatcher & {
18
- old: string;
19
- type: 0 | 1 | 2 | 3;
20
- val: string;
21
- end: string;
22
- };
20
+ export type MatchItRouteToken = RouteMatcher & ClientRouteMatchItTokens;
23
21
  /**
24
- * Returns a union of methods from a controller that accepts
25
- * the context as the first argument.
22
+ * Extracts method names from a controller class that accept HttpContext as first parameter
26
23
  */
27
24
  export type GetControllerHandlers<Controller extends Constructor<any>> = {
28
25
  [K in keyof InstanceType<Controller>]: InstanceType<Controller>[K] extends (ctx: HttpContext, ...args: any[]) => any ? K : never;
29
26
  }[keyof InstanceType<Controller>];
30
27
  /**
31
- * Route handler defined as a function
28
+ * Route handler implemented as a function that accepts HTTP context
32
29
  */
33
30
  export type RouteFn = (ctx: HttpContext) => any;
34
31
  /**
35
- * Route handler persisted with the route store
32
+ * Route handler representation stored in the route registry
36
33
  */
37
34
  export type StoreRouteHandler = RouteFn | {
35
+ /** Optional name for the handler */
36
+ name?: string;
37
+ /** Method name on the controller */
38
+ method: string;
39
+ /** Dynamic import expression for lazy loading */
40
+ importExpression: string | null;
41
+ /** Reference to controller class or method */
38
42
  reference: string | [LazyImport<Constructor<any>> | Constructor<any>, any?];
43
+ /** Handler execution function */
39
44
  handle: (resolver: ContainerResolver<any>, ...args: [ctx: HttpContext, ...injections: any[]]) => any;
40
45
  };
41
46
  /**
42
- * The middleware persisted with the route store
47
+ * Middleware representation stored with route information
43
48
  */
44
49
  export type StoreRouteMiddleware = MiddlewareFn | ({
45
50
  name?: string;
46
51
  args?: any[];
47
52
  } & ParsedGlobalMiddleware);
48
53
  /**
49
- * An object of routes for a given HTTP method
54
+ * Route storage structure for a specific HTTP method containing tokens and route mappings
50
55
  */
51
56
  export type StoreMethodNode = {
57
+ /** Array of route tokens for pattern matching */
52
58
  tokens: MatchItRouteToken[][];
59
+ /** Mapping from route patterns to unique route keys */
53
60
  routeKeys: {
54
61
  [pattern: string]: string;
55
62
  };
63
+ /** Mapping from route patterns to route definitions */
56
64
  routes: {
57
65
  [pattern: string]: RouteJSON;
58
66
  };
59
67
  };
60
68
  /**
61
- * Each domain node container an object of methods. Each method
62
- * object has nested routes.
69
+ * Domain-specific route storage containing method-based route organization
63
70
  */
64
71
  export type StoreDomainNode = {
72
+ /** HTTP method to method node mapping */
65
73
  [method: string]: StoreMethodNode;
66
74
  };
67
75
  /**
68
- * Routes tree stored within the routes store
76
+ * Complete route tree structure organizing routes by domains and methods
69
77
  */
70
78
  export type StoreRoutesTree = {
79
+ /** Global route tokens for pattern matching */
71
80
  tokens: MatchItRouteToken[][];
81
+ /** Domain-based route organization */
72
82
  domains: {
73
83
  [domain: string]: StoreDomainNode;
74
84
  };
75
85
  };
76
86
  /**
77
- * Shape of the matched route for a pattern, method and domain.
87
+ * Result of successful route matching containing route details and extracted parameters
78
88
  */
79
89
  export type MatchedRoute = {
90
+ /** The matched route definition */
80
91
  route: RouteJSON;
81
92
  /**
82
93
  * A unique key for the looked up route
@@ -92,28 +103,21 @@ export type MatchedRoute = {
92
103
  subdomains: Record<string, any>;
93
104
  };
94
105
  /**
95
- * A collection of route matchers
106
+ * Collection of parameter matchers indexed by parameter name
96
107
  */
97
108
  export type RouteMatchers = {
109
+ /** Parameter name to matcher mapping */
98
110
  [param: string]: RouteMatcher;
99
111
  };
100
112
  /**
101
- * Representation of a route as JSON
113
+ * Complete route definition with all metadata, handlers, and execution context
102
114
  */
103
- export type RouteJSON = {
115
+ export type RouteJSON = Pick<ClientRouteJSON, 'name' | 'methods' | 'domain' | 'pattern'> & {
104
116
  /**
105
117
  * The execute function to execute the route middleware
106
118
  * and the handler
107
119
  */
108
120
  execute: (route: RouteJSON, resolver: ContainerResolver<any>, ctx: HttpContext, errorResponder: ServerErrorHandler['handle']) => any;
109
- /**
110
- * A unique name for the route
111
- */
112
- name?: string;
113
- /**
114
- * Route URI pattern
115
- */
116
- pattern: string;
117
121
  /**
118
122
  * Route handler
119
123
  */
@@ -130,38 +134,34 @@ export type RouteJSON = {
130
134
  * Tokens to be used to construct the route URL
131
135
  */
132
136
  tokens: MatchItRouteToken[];
133
- /**
134
- * HTTP methods, the route responds to.
135
- */
136
- methods: string[];
137
- /**
138
- * The domain for which the route is registered.
139
- */
140
- domain: string;
141
137
  /**
142
138
  * Matchers for route params.
143
139
  */
144
140
  matchers: RouteMatchers;
145
141
  };
146
142
  /**
147
- * Resource action names
143
+ * Standard RESTful resource action names for CRUD operations
148
144
  */
149
145
  export type ResourceActionNames = 'create' | 'index' | 'store' | 'show' | 'edit' | 'update' | 'destroy';
150
146
  /**
151
- * Options accepted by makeUrl method
152
- * @deprecated
147
+ * @deprecated Options for URL generation (use URLBuilder instead)
153
148
  */
154
149
  export type MakeUrlOptions = {
150
+ /** Query string parameters to append */
155
151
  qs?: Record<string, any>;
152
+ /** Domain name to use for the URL */
156
153
  domain?: string;
154
+ /** Prefix to prepend to the generated URL */
157
155
  prefixUrl?: string;
156
+ /** Whether to disable route lookup optimization */
158
157
  disableRouteLookup?: boolean;
159
158
  };
160
159
  /**
161
- * Options accepted by makeSignedUrl method
162
- * @deprecated
160
+ * @deprecated Options for signed URL generation (use URLBuilder instead)
163
161
  */
164
162
  export type MakeSignedUrlOptions = MakeUrlOptions & {
163
+ /** Expiration time for the signed URL */
165
164
  expiresIn?: string | number;
165
+ /** Purpose identifier for the signed URL */
166
166
  purpose?: string;
167
167
  };