@adonisjs/http-server 8.0.0-next.8 → 8.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 (49) hide show
  1. package/build/define_config-D-kQXU0e.js +2438 -0
  2. package/build/factories/http_context.d.ts +10 -4
  3. package/build/factories/main.d.ts +2 -2
  4. package/build/factories/main.js +170 -345
  5. package/build/factories/request.d.ts +4 -4
  6. package/build/factories/response.d.ts +4 -4
  7. package/build/factories/router.d.ts +1 -1
  8. package/build/factories/server_factory.d.ts +1 -1
  9. package/build/factories/url_builder_factory.d.ts +3 -3
  10. package/build/helpers-C_2HouOe.js +52 -0
  11. package/build/index.d.ts +3 -2
  12. package/build/index.js +155 -370
  13. package/build/src/client/helpers.d.ts +37 -0
  14. package/build/src/client/types.d.ts +194 -0
  15. package/build/src/client/url_builder.d.ts +15 -0
  16. package/build/src/client/url_builder.js +115 -0
  17. package/build/src/cookies/client.d.ts +28 -5
  18. package/build/src/cookies/drivers/encrypted.d.ts +1 -1
  19. package/build/src/cookies/drivers/signed.d.ts +1 -1
  20. package/build/src/cookies/parser.d.ts +1 -1
  21. package/build/src/cookies/serializer.d.ts +2 -2
  22. package/build/src/debug.d.ts +14 -1
  23. package/build/src/define_config.d.ts +19 -1
  24. package/build/src/define_middleware.d.ts +19 -3
  25. package/build/src/errors.d.ts +60 -5
  26. package/build/src/exception_handler.d.ts +28 -8
  27. package/build/src/helpers.d.ts +23 -16
  28. package/build/src/helpers.js +76 -22
  29. package/build/src/http_context/main.d.ts +67 -17
  30. package/build/src/qs.d.ts +17 -3
  31. package/build/src/redirect.d.ts +22 -3
  32. package/build/src/request.d.ts +12 -5
  33. package/build/src/response.d.ts +5 -5
  34. package/build/src/response_status.d.ts +14 -0
  35. package/build/src/router/main.d.ts +6 -2
  36. package/build/src/router/route.d.ts +130 -32
  37. package/build/src/router/signed_url_builder.d.ts +1 -1
  38. package/build/src/server/main.d.ts +6 -6
  39. package/build/src/types/main.js +1 -0
  40. package/build/src/types/response.d.ts +6 -1
  41. package/build/src/types/route.d.ts +3 -27
  42. package/build/src/types/url_builder.d.ts +2 -140
  43. package/build/src/utils.d.ts +71 -6
  44. package/build/types-AUwURgIL.js +1 -0
  45. package/build/utils-BjSHKI3s.js +618 -0
  46. package/package.json +56 -47
  47. package/build/chunk-NQNHMINZ.js +0 -135
  48. package/build/chunk-W6WKITGF.js +0 -5486
  49. package/build/src/router/url_builder.d.ts +0 -9
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Types shared with the client. These should never import other types
3
+ */
4
+ export type ClientRouteMatchItTokens = {
5
+ /** Original token string */
6
+ old: string;
7
+ /** Token type identifier (0=static, 1=param, 2=wildcard, 3=optional) */
8
+ type: 0 | 1 | 2 | 3;
9
+ /** Token value */
10
+ val: string;
11
+ /** Token end delimiter */
12
+ end: string;
13
+ };
14
+ /**
15
+ * Complete route definition with all metadata, handlers, and execution context
16
+ */
17
+ export type ClientRouteJSON = {
18
+ /**
19
+ * A unique name for the route
20
+ */
21
+ name?: string;
22
+ /**
23
+ * Route URI pattern
24
+ */
25
+ pattern: string;
26
+ /**
27
+ * Route handler
28
+ */
29
+ handler?: unknown;
30
+ /**
31
+ * Tokens to be used to construct the route URL
32
+ */
33
+ tokens: ClientRouteMatchItTokens[];
34
+ /**
35
+ * HTTP methods, the route responds to.
36
+ */
37
+ methods: string[];
38
+ /**
39
+ * The domain for which the route is registered.
40
+ */
41
+ domain: string;
42
+ };
43
+ /**
44
+ * Configuration options for URL generation helpers
45
+ */
46
+ export type URLOptions = {
47
+ /** Query string parameters to append to the URL */
48
+ qs?: Record<string, any>;
49
+ /** URL prefix to prepend to the generated URL */
50
+ prefixUrl?: string;
51
+ };
52
+ /**
53
+ * LookupList type is used by the URLBuilder to provide
54
+ * type-safety when creating URLs.
55
+ *
56
+ * There is no runtime property that matches this type. Its
57
+ * purely for type-inference.
58
+ */
59
+ /**
60
+ * Route definition structure for type-safe URL building
61
+ */
62
+ export type LookupListRoute = {
63
+ /** Parameters as a tuple for positional arguments */
64
+ paramsTuple?: [...any[]];
65
+ /** Parameters as a named object */
66
+ params?: {
67
+ [name: string]: any;
68
+ };
69
+ };
70
+ /**
71
+ * Complete route lookup structure organized by HTTP methods and route identifiers
72
+ */
73
+ export type LookupList = {
74
+ /** HTTP method to route mapping */
75
+ [method: string]: {
76
+ /** Route identifier to route definition mapping */
77
+ [identifier: string]: LookupListRoute;
78
+ };
79
+ };
80
+ /**
81
+ * Utility type that constructs function arguments for route URL builders based on route parameters
82
+ */
83
+ export type RouteBuilderArguments<Identifier, Route, Options extends any = URLOptions> = Route extends LookupListRoute ? Route['params'] extends undefined ? [identifier: Identifier, params?: undefined, options?: Options] : [undefined] extends [Route['params']] ? [identifier: Identifier, params?: Route['params'] | Route['paramsTuple'], options?: Options] : [identifier: Identifier, params: Route['params'] | Route['paramsTuple'], options?: Options] : never;
84
+ /**
85
+ * The urlFor helper is used to make URLs for pre-existing known routes. You can
86
+ * make a URL using the route name, route pattern, or the route controller
87
+ * reference (depends upon enabled lookupStrategies)
88
+ *
89
+ * ```ts
90
+ * urlFor('users.show', [1]) // /users/1
91
+ *
92
+ * // Lookup inside a specific domain
93
+ * urlFor('blog.adonisjs.com@posts.show', [1]) // /posts/1
94
+ * ```
95
+ */
96
+ export type UrlFor<Routes extends LookupList, Options extends any = URLOptions> = (<Identifier extends keyof Routes['ALL'] & string>(...[identifier, params, options]: RouteBuilderArguments<Identifier, Routes['ALL'][Identifier], Options>) => string) & {
97
+ /**
98
+ * Make URL for a GET route. An error will be raised if the route doesn't
99
+ * exist.
100
+ *
101
+ * ```ts
102
+ * urlFor.get('users.show', [1]) // { method: 'get', url: '/users/1' }
103
+ * urlFor.get('users.store', [1]) // Error: Route not found GET@users/store
104
+ * ```
105
+ */
106
+ get<RouteIdentifier extends keyof Routes['GET'] & string>(...[identifier, params, options]: RouteBuilderArguments<RouteIdentifier, Routes['GET'][RouteIdentifier], Options>): {
107
+ method: 'GET';
108
+ url: string;
109
+ form: {
110
+ action: string;
111
+ method: 'GET';
112
+ };
113
+ };
114
+ /**
115
+ * Make URL for a POST route. An error will be raised if the route doesn't
116
+ * exist.
117
+ *
118
+ * ```ts
119
+ * urlFor.post('users.store') // { method: 'post', url: '/users' }
120
+ * urlFor.post('users.show', [1]) // Error: Route not found POST@users.show
121
+ * ```
122
+ */
123
+ post<RouteIdentifier extends keyof Routes['POST'] & string>(...[identifier, params, options]: RouteBuilderArguments<RouteIdentifier, Routes['POST'][RouteIdentifier], Options>): {
124
+ method: 'POST';
125
+ url: string;
126
+ form: {
127
+ action: string;
128
+ method: 'POST';
129
+ };
130
+ };
131
+ /**
132
+ * Make URL for a PUT route. An error will be raised if the route doesn't
133
+ * exist.
134
+ *
135
+ * ```ts
136
+ * urlFor.put('users.update', [1]) // { method: 'put', url: '/users/1' }
137
+ * urlFor.put('users.show', [1]) // Error: Route not found PUT@users.show
138
+ * ```
139
+ */
140
+ put<RouteIdentifier extends keyof Routes['PUT'] & string>(...[identifier, params, options]: RouteBuilderArguments<RouteIdentifier, Routes['PUT'][RouteIdentifier], Options>): {
141
+ method: 'PUT';
142
+ url: string;
143
+ form: {
144
+ action: string;
145
+ method: 'PUT';
146
+ };
147
+ };
148
+ /**
149
+ * Make URL for a PATCH route. An error will be raised if the route doesn't
150
+ * exist.
151
+ *
152
+ * ```ts
153
+ * urlFor.put('users.update', [1]) // { method: 'patch', url: '/users/1' }
154
+ * urlFor.put('users.show', [1]) // Error: Route not found PATCH@users.show
155
+ * ```
156
+ */
157
+ patch<RouteIdentifier extends keyof Routes['PATCH'] & string>(...[identifier, params, options]: RouteBuilderArguments<RouteIdentifier, Routes['PATCH'][RouteIdentifier], Options>): {
158
+ method: 'PATCH';
159
+ url: string;
160
+ form: {
161
+ action: string;
162
+ method: 'PATCH';
163
+ };
164
+ };
165
+ /**
166
+ * Make URL for a DELETE route. An error will be raised if the route doesn't
167
+ * exist.
168
+ *
169
+ * ```ts
170
+ * urlFor.delete('users.destroy', [1]) // { method: 'delete', url: '/users/1' }
171
+ * urlFor.delete('users.show', [1]) // Error: Route not found DELETE@users.show
172
+ * ```
173
+ */
174
+ delete<RouteIdentifier extends keyof Routes['DELETE'] & string>(...[identifier, params, options]: RouteBuilderArguments<RouteIdentifier, Routes['DELETE'][RouteIdentifier], Options>): {
175
+ method: 'DELETE';
176
+ url: string;
177
+ form: {
178
+ action: string;
179
+ method: 'DELETE';
180
+ };
181
+ };
182
+ /**
183
+ * Make URL for a custom route method. An error will be raised if the route doesn't
184
+ * exist for the same method.
185
+ */
186
+ method<Method extends keyof Routes & string, RouteIdentifier extends keyof Routes[Method] & string>(method: Method, ...[identifier, params, options]: RouteBuilderArguments<RouteIdentifier, Routes[Method][RouteIdentifier], Options>): {
187
+ method: Method;
188
+ url: string;
189
+ form: {
190
+ action: string;
191
+ method: Method;
192
+ };
193
+ };
194
+ };
@@ -0,0 +1,15 @@
1
+ import { createURL, findRoute } from './helpers.ts';
2
+ import { type UrlFor, type LookupList, type ClientRouteJSON } from './types.ts';
3
+ export * from './types.ts';
4
+ export { createURL, findRoute };
5
+ /**
6
+ * Creates the URLBuilder helper
7
+ * @param router - The router instance
8
+ * @param searchParamsStringifier - Function to stringify query string parameters
9
+ * @returns URL builder function for creating URLs
10
+ */
11
+ export declare function createUrlBuilder<Routes extends LookupList>(routesLoader: {
12
+ [domain: string]: ClientRouteJSON[];
13
+ } | (() => {
14
+ [domain: string]: ClientRouteJSON[];
15
+ }), searchParamsStringifier: (qs: Record<string, any>) => string): UrlFor<Routes>;
@@ -0,0 +1,115 @@
1
+ import { n as findRoute, t as createURL } from "../../helpers-C_2HouOe.js";
2
+ import "../../types-AUwURgIL.js";
3
+ function createUrlBuilder(routesLoader, searchParamsStringifier) {
4
+ let domainsList;
5
+ let domainsRoutes;
6
+ function createUrlForRoute(identifier, params, options, method) {
7
+ if (!domainsRoutes) {
8
+ domainsRoutes = typeof routesLoader === "function" ? routesLoader() : routesLoader;
9
+ if (!domainsRoutes || typeof domainsRoutes !== "object") throw new Error(`Cannot construct routes. Expected the value to be an object, instead received ${typeof domainsRoutes}`);
10
+ if (!domainsList) domainsList = Object.keys(domainsRoutes).filter((domain) => domain !== "root");
11
+ }
12
+ const domain = domainsList.find((name) => identifier.startsWith(`${name}@`));
13
+ const routeIdentifier = domain ? identifier.replace(new RegExp(`^${domain}@`), "") : identifier;
14
+ const route = findRoute(domainsRoutes, routeIdentifier, domain, method, true);
15
+ if (!route) {
16
+ if (method) throw new Error(`Cannot lookup route "${routeIdentifier}" for method "${method}"`);
17
+ throw new Error(`Cannot lookup route "${routeIdentifier}"`);
18
+ }
19
+ return createURL(route.name ?? route.pattern, route.tokens, searchParamsStringifier, params, options);
20
+ }
21
+ const urlFor = function route(...[identifier, params, options]) {
22
+ return createUrlForRoute(identifier, params, options);
23
+ };
24
+ urlFor.get = function urlForMethodGet(...[identifier, params, options]) {
25
+ const method = "GET";
26
+ const url = createUrlForRoute(identifier, params, options, method);
27
+ return {
28
+ url,
29
+ method,
30
+ toString() {
31
+ return url;
32
+ },
33
+ form: {
34
+ action: url,
35
+ method
36
+ }
37
+ };
38
+ };
39
+ urlFor.post = function urlForMethodPost(...[identifier, params, options]) {
40
+ const method = "POST";
41
+ const url = createUrlForRoute(identifier, params, options, method);
42
+ return {
43
+ url,
44
+ method,
45
+ toString() {
46
+ return url;
47
+ },
48
+ form: {
49
+ action: url,
50
+ method
51
+ }
52
+ };
53
+ };
54
+ urlFor.put = function urlForMethodPut(...[identifier, params, options]) {
55
+ const method = "PUT";
56
+ const url = createUrlForRoute(identifier, params, options, method);
57
+ return {
58
+ url,
59
+ method,
60
+ toString() {
61
+ return url;
62
+ },
63
+ form: {
64
+ action: url,
65
+ method
66
+ }
67
+ };
68
+ };
69
+ urlFor.patch = function urlForMethodPatch(...[identifier, params, options]) {
70
+ const method = "PATCH";
71
+ const url = createUrlForRoute(identifier, params, options, method);
72
+ return {
73
+ url,
74
+ method,
75
+ toString() {
76
+ return url;
77
+ },
78
+ form: {
79
+ action: url,
80
+ method
81
+ }
82
+ };
83
+ };
84
+ urlFor.delete = function urlForMethodDelete(...[identifier, params, options]) {
85
+ const method = "DELETE";
86
+ const url = createUrlForRoute(identifier, params, options, method);
87
+ return {
88
+ url,
89
+ method,
90
+ toString() {
91
+ return url;
92
+ },
93
+ form: {
94
+ action: url,
95
+ method
96
+ }
97
+ };
98
+ };
99
+ urlFor.method = function urlForCustomMethod(method, ...[identifier, params, options]) {
100
+ const url = createUrlForRoute(identifier, params, options, method);
101
+ return {
102
+ url,
103
+ method,
104
+ toString() {
105
+ return url;
106
+ },
107
+ form: {
108
+ action: url,
109
+ method
110
+ }
111
+ };
112
+ };
113
+ return urlFor;
114
+ }
115
+ export { createURL, createUrlBuilder, findRoute };
@@ -1,7 +1,20 @@
1
- import type { Encryption } from '@adonisjs/encryption';
1
+ import type { Encryption } from '@boringnode/encryption';
2
2
  /**
3
- * Cookie client exposes the API to parse/set AdonisJS cookies
4
- * as a client.
3
+ * Cookie client provides a unified API for parsing and setting AdonisJS cookies on the client side.
4
+ *
5
+ * This class handles different types of cookies including plain, signed, and encrypted cookies.
6
+ * It provides methods to encode/decode cookies for client-side operations and parse server responses.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const client = new CookieClient(encryption)
11
+ *
12
+ * // Encrypt a cookie value
13
+ * const encrypted = client.encrypt('sessionId', 'abc123')
14
+ *
15
+ * // Parse a cookie from server response
16
+ * const value = client.parse('sessionId', cookieValue)
17
+ * ```
5
18
  */
6
19
  export declare class CookieClient {
7
20
  #private;
@@ -62,11 +75,21 @@ export declare class CookieClient {
62
75
  */
63
76
  decode(_: string, value: string, stringified?: boolean): any;
64
77
  /**
65
- * Parse response cookie
78
+ * Parse a cookie value by attempting to decrypt, unsign, or decode it.
79
+ *
80
+ * This method tries different unpacking strategies in order:
81
+ * 1. Unsign if it's a signed cookie
82
+ * 2. Decrypt if it's an encrypted cookie
83
+ * 3. Decode if it's a plain encoded cookie
66
84
  *
67
85
  * @param key - The cookie key
68
86
  * @param value - The cookie value to parse
69
- * @returns The parsed value or undefined if parsing fails
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const parsed = client.parse('session', 'e30.abc123def')
91
+ * // Returns the original value if successfully parsed
92
+ * ```
70
93
  */
71
94
  parse(key: string, value: any): any;
72
95
  }
@@ -1,4 +1,4 @@
1
- import type { Encryption } from '@adonisjs/encryption';
1
+ import type { Encryption } from '@boringnode/encryption';
2
2
  /**
3
3
  * Encrypt a value to be set as cookie
4
4
  *
@@ -1,4 +1,4 @@
1
- import type { Encryption } from '@adonisjs/encryption';
1
+ import type { Encryption } from '@boringnode/encryption';
2
2
  /**
3
3
  * Signs a value to be shared as a cookie. The signed output has a
4
4
  * hash to verify tampering with the original value
@@ -1,4 +1,4 @@
1
- import type { Encryption } from '@adonisjs/encryption';
1
+ import type { Encryption } from '@boringnode/encryption';
2
2
  /**
3
3
  * Cookie parser parses the HTTP `cookie` header and collects all cookies
4
4
  * inside an object of `key-value` pair, but doesn't attempt to decrypt
@@ -1,4 +1,4 @@
1
- import type { Encryption } from '@adonisjs/encryption';
1
+ import type { Encryption } from '@boringnode/encryption';
2
2
  import type { CookieOptions } from '../types/response.ts';
3
3
  /**
4
4
  * Cookies serializer is used to serialize a value to be set on the `Set-Cookie`
@@ -31,7 +31,7 @@ export declare class CookieSerializer {
31
31
  */
32
32
  encode(key: string, value: any, options?: Partial<CookieOptions & {
33
33
  /**
34
- * @depreacted Instead use stringify option
34
+ * @deprecated Instead use stringify option
35
35
  */
36
36
  encode: boolean;
37
37
  stringify: boolean;
@@ -1,2 +1,15 @@
1
- declare const _default: import("util").DebugLogger;
1
+ /**
2
+ * Debug logger instance for the AdonisJS HTTP server package.
3
+ *
4
+ * This debug logger can be enabled by setting the NODE_DEBUG environment variable
5
+ * to include 'adonisjs:http'. When enabled, it will output detailed debugging
6
+ * information about HTTP server operations including route matching, middleware
7
+ * execution, and response generation.
8
+ *
9
+ * @example
10
+ * ```bash
11
+ * NODE_DEBUG=adonisjs:http node ace serve
12
+ * ```
13
+ */
14
+ declare const _default: import("node:util").DebugLogger;
2
15
  export default _default;
@@ -4,7 +4,25 @@ type UserDefinedServerConfig = DeepPartial<Omit<ServerConfig, 'trustProxy'> & {
4
4
  trustProxy: ((address: string, distance: number) => boolean) | boolean | string;
5
5
  }>;
6
6
  /**
7
- * Define configuration for the HTTP server
7
+ * Define configuration for the HTTP server with sensible defaults.
8
+ *
9
+ * This function merges user-provided configuration with default values,
10
+ * normalizes certain properties (like cookie maxAge and trustProxy settings),
11
+ * and returns a complete ServerConfig object.
12
+ *
13
+ * @param config - User-defined server configuration options
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const config = defineConfig({
18
+ * trustProxy: true,
19
+ * cookie: {
20
+ * maxAge: '7d',
21
+ * secure: false
22
+ * },
23
+ * etag: true
24
+ * })
25
+ * ```
8
26
  */
9
27
  export declare function defineConfig(config: UserDefinedServerConfig): ServerConfig;
10
28
  export {};
@@ -1,9 +1,25 @@
1
1
  import type { LazyImport, UnWrapLazyImport } from '@poppinss/utils/types';
2
2
  import type { MiddlewareAsClass, GetMiddlewareArgs, ParsedGlobalMiddleware } from './types/middleware.ts';
3
3
  /**
4
- * Define an collection of named middleware. The collection gets converted
5
- * into a collection of factory functions. Calling the function returns
6
- * a reference to the executable middleware.
4
+ * Define a collection of named middleware that can be referenced by name in routes and route groups.
5
+ *
6
+ * This function converts a collection of middleware classes into factory functions that can be
7
+ * called with arguments to create middleware references. Each middleware in the collection
8
+ * becomes available as a typed function that preserves the middleware's argument signature.
9
+ *
10
+ * @param collection - Object mapping middleware names to their lazy import references
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const namedMiddleware = defineNamedMiddleware({
15
+ * auth: () => import('./middleware/auth.ts'),
16
+ * throttle: () => import('./middleware/throttle.ts')
17
+ * })
18
+ *
19
+ * // Usage in routes
20
+ * router.get('/dashboard', [namedMiddleware.auth(), handler])
21
+ * router.get('/api/data', [namedMiddleware.throttle({ max: 100 }), handler])
22
+ * ```
7
23
  */
8
24
  export declare function defineNamedMiddleware<NamedMiddleware extends Record<string, LazyImport<MiddlewareAsClass>>>(collection: NamedMiddleware): { [K in keyof NamedMiddleware]: <Args extends GetMiddlewareArgs<UnWrapLazyImport<NamedMiddleware[K]>>>(...args: Args) => {
9
25
  name: K;
@@ -1,15 +1,41 @@
1
1
  import { Exception } from '@poppinss/utils/exception';
2
2
  import type { HttpContext } from './http_context/main.ts';
3
3
  /**
4
- * Thrown when unable to find a matching route for the given request
4
+ * Thrown when unable to find a matching route for the given request.
5
+ *
6
+ * This error is raised when the router cannot match the incoming HTTP method
7
+ * and URL pattern to any registered route in the application.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * throw new E_ROUTE_NOT_FOUND(['GET', '/nonexistent'])
12
+ * ```
5
13
  */
6
14
  export declare const E_ROUTE_NOT_FOUND: new (args: [method: string, url: string], options?: ErrorOptions) => Exception;
7
15
  /**
8
16
  * Thrown when unable to lookup a route by its identifier.
17
+ *
18
+ * This error occurs when trying to generate URLs or find routes using
19
+ * a route name, pattern, or controller reference that doesn't exist.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * throw new E_CANNOT_LOOKUP_ROUTE(['nonexistent.route'])
24
+ * ```
9
25
  */
10
26
  export declare const E_CANNOT_LOOKUP_ROUTE: new (args: [routeIdentifier: string], options?: ErrorOptions) => Exception;
11
27
  /**
12
- * A generic HTTP exception to convert errors to HTTP response
28
+ * A generic HTTP exception for converting errors to HTTP responses.
29
+ *
30
+ * This class provides a standardized way to create HTTP exceptions with
31
+ * specific status codes and response bodies. It handles various input types
32
+ * including strings, objects, and null/undefined values.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * throw E_HTTP_EXCEPTION.invoke('Not found', 404)
37
+ * throw E_HTTP_EXCEPTION.invoke({ error: 'Invalid data' }, 422)
38
+ * ```
13
39
  */
14
40
  export declare const E_HTTP_EXCEPTION: {
15
41
  new (message?: string, options?: ErrorOptions & {
@@ -29,7 +55,17 @@ export declare const E_HTTP_EXCEPTION: {
29
55
  };
30
56
  code: string;
31
57
  /**
32
- * This method returns an instance of the exception class
58
+ * Creates and returns an instance of the HttpException class.
59
+ *
60
+ * @param body - The response body (string, object, or null/undefined)
61
+ * @param status - HTTP status code for the response
62
+ * @param code - Optional error code (defaults to 'E_HTTP_EXCEPTION')
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const error = HttpException.invoke('Resource not found', 404)
67
+ * const error2 = HttpException.invoke({ message: 'Validation failed' }, 422)
68
+ * ```
33
69
  */
34
70
  invoke(body: any, status: number, code?: string): {
35
71
  body: any;
@@ -52,7 +88,16 @@ export declare const E_HTTP_EXCEPTION: {
52
88
  stackTraceLimit: number;
53
89
  };
54
90
  /**
55
- * Thrown when the "response.abort" method is called
91
+ * Thrown when the "response.abort" method is called.
92
+ *
93
+ * This exception is used to immediately terminate request processing
94
+ * and send a response. It includes a built-in handler that automatically
95
+ * sends the appropriate status and body to the client.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * throw new E_HTTP_REQUEST_ABORTED()
100
+ * ```
56
101
  */
57
102
  export declare const E_HTTP_REQUEST_ABORTED: {
58
103
  new (message?: string, options?: ErrorOptions & {
@@ -73,7 +118,17 @@ export declare const E_HTTP_REQUEST_ABORTED: {
73
118
  };
74
119
  code: string;
75
120
  /**
76
- * This method returns an instance of the exception class
121
+ * Creates and returns an instance of the HttpException class.
122
+ *
123
+ * @param body - The response body (string, object, or null/undefined)
124
+ * @param status - HTTP status code for the response
125
+ * @param code - Optional error code (defaults to 'E_HTTP_EXCEPTION')
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * const error = HttpException.invoke('Resource not found', 404)
130
+ * const error2 = HttpException.invoke({ message: 'Validation failed' }, 422)
131
+ * ```
77
132
  */
78
133
  invoke(body: any, status: number, code?: string): {
79
134
  body: any;
@@ -3,16 +3,29 @@ import type { Level } from '@adonisjs/logger/types';
3
3
  import type { HttpContext } from './http_context/main.ts';
4
4
  import type { HttpError, StatusPageRange, StatusPageRenderer } from './types/server.ts';
5
5
  /**
6
- * The base HTTP exception handler one can inherit from to handle
7
- * HTTP exceptions.
6
+ * The base HTTP exception handler that provides comprehensive error handling capabilities.
8
7
  *
9
- * The HTTP exception handler has support for
8
+ * This class can be inherited to create custom exception handlers for your application.
9
+ * It provides built-in support for:
10
10
  *
11
- * - Ability to render exceptions by calling the render method on the exception.
12
- * - Rendering status pages
13
- * - Pretty printing errors during development
14
- * - Transforming errors to JSON or HTML using content negotiation
15
- * - Reporting errors
11
+ * - Self-handling exceptions via their own render/handle methods
12
+ * - Custom status page rendering for different HTTP error codes
13
+ * - Debug-friendly error display during development
14
+ * - Content negotiation for JSON, JSON API, and HTML error responses
15
+ * - Configurable error reporting and logging
16
+ * - Validation error handling with field-specific messages
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * export default class HttpExceptionHandler extends ExceptionHandler {
21
+ * protected debug = app.inDev
22
+ * protected renderStatusPages = app.inProduction
23
+ *
24
+ * protected statusPages = {
25
+ * '404': (error, ctx) => ctx.view.render('errors/404')
26
+ * }
27
+ * }
28
+ * ```
16
29
  */
17
30
  export declare class ExceptionHandler extends Macroable {
18
31
  #private;
@@ -53,6 +66,13 @@ export declare class ExceptionHandler extends Macroable {
53
66
  * Errors with these codes are handled but not logged
54
67
  */
55
68
  protected ignoreCodes: string[];
69
+ /**
70
+ * Normalizes any thrown value into a standardized HttpError object
71
+ * Ensures the error has required properties like message and status
72
+ * @param error - Any thrown value (Error, string, object, etc.)
73
+ * @returns {HttpError} Normalized error object with status and message
74
+ */
75
+ protected toHttpError(error: unknown): HttpError;
56
76
  /**
57
77
  * Provides additional context information for error reporting
58
78
  * Includes request ID when available for correlation across logs