@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.
- package/build/chunk-2QM3D5BN.js +87 -0
- package/build/chunk-5PWHBE2E.js +128 -0
- package/build/chunk-QDK57QGB.js +1176 -0
- package/build/{chunk-HMYAZG76.js → chunk-YBLFT4O6.js} +1146 -1663
- package/build/factories/http_context.d.ts +2 -1
- package/build/factories/http_server.d.ts +7 -0
- package/build/factories/main.js +33 -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 +3 -2
- package/build/index.d.ts +4 -1
- package/build/index.js +97 -42
- package/build/src/client/helpers.d.ts +37 -0
- package/build/src/client/types.d.ts +203 -0
- package/build/src/client/url_builder.d.ts +15 -0
- package/build/src/client/url_builder.js +12 -0
- package/build/src/cookies/client.d.ts +61 -3
- 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/debug.d.ts +13 -0
- package/build/src/define_config.d.ts +20 -4
- package/build/src/define_middleware.d.ts +20 -4
- package/build/src/errors.d.ts +60 -5
- package/build/src/exception_handler.d.ts +93 -39
- package/build/src/helpers.d.ts +57 -0
- package/build/src/helpers.js +9 -1
- package/build/src/http_context/local_storage.d.ts +17 -0
- package/build/src/http_context/main.d.ts +68 -10
- package/build/src/qs.d.ts +30 -2
- package/build/src/redirect.d.ts +84 -12
- package/build/src/request.d.ts +118 -12
- package/build/src/response.d.ts +416 -203
- package/build/src/response_status.d.ts +14 -0
- package/build/src/router/brisk.d.ts +15 -4
- 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 +79 -22
- 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 +28 -3
- package/build/src/router/signed_url_builder.d.ts +4 -8
- package/build/src/router/store.d.ts +9 -0
- 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 +42 -42
- 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 +10 -135
- package/build/src/utils.d.ts +71 -6
- package/package.json +26 -22
- package/build/chunk-ASX56VAK.js +0 -76
- package/build/src/router/url_builder.d.ts +0 -14
package/build/src/errors.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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,111 +3,165 @@ 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
|
|
7
|
-
* HTTP exceptions.
|
|
6
|
+
* The base HTTP exception handler that provides comprehensive error handling capabilities.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
8
|
+
* This class can be inherited to create custom exception handlers for your application.
|
|
9
|
+
* It provides built-in support for:
|
|
10
10
|
*
|
|
11
|
-
* -
|
|
12
|
-
* -
|
|
13
|
-
* -
|
|
14
|
-
* -
|
|
15
|
-
* -
|
|
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;
|
|
19
32
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
33
|
+
* Controls whether to include debug information in error responses
|
|
34
|
+
* When enabled, errors include complete stack traces and detailed debugging info
|
|
35
|
+
* Defaults to true in non-production environments
|
|
22
36
|
*/
|
|
23
37
|
protected debug: boolean;
|
|
24
38
|
/**
|
|
25
|
-
*
|
|
26
|
-
* errors with matching status codes
|
|
27
|
-
*
|
|
39
|
+
* Controls whether to render custom status pages for unhandled errors
|
|
40
|
+
* When enabled, errors with matching status codes use configured status page renderers
|
|
41
|
+
* Defaults to true in production environments
|
|
28
42
|
*/
|
|
29
43
|
protected renderStatusPages: boolean;
|
|
30
44
|
/**
|
|
31
|
-
*
|
|
45
|
+
* Mapping of HTTP status code ranges to their corresponding page renderers
|
|
46
|
+
* Supports ranges like '400-499' or individual codes like '404'
|
|
32
47
|
*/
|
|
33
48
|
protected statusPages: Record<StatusPageRange, StatusPageRenderer>;
|
|
34
49
|
/**
|
|
35
|
-
*
|
|
50
|
+
* Controls whether errors should be reported to logging systems
|
|
51
|
+
* When disabled, errors are handled but not logged or reported
|
|
36
52
|
*/
|
|
37
53
|
protected reportErrors: boolean;
|
|
38
54
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
55
|
+
* Array of exception class constructors to exclude from error reporting
|
|
56
|
+
* These exceptions are handled but not logged or reported to external systems
|
|
41
57
|
*/
|
|
42
58
|
protected ignoreExceptions: any[];
|
|
43
59
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
60
|
+
* Array of HTTP status codes to exclude from error reporting
|
|
61
|
+
* Errors with these status codes are handled but not logged
|
|
46
62
|
*/
|
|
47
63
|
protected ignoreStatuses: number[];
|
|
48
64
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
65
|
+
* Array of custom error codes to exclude from error reporting
|
|
66
|
+
* Errors with these codes are handled but not logged
|
|
51
67
|
*/
|
|
52
68
|
protected ignoreCodes: string[];
|
|
53
69
|
/**
|
|
54
|
-
*
|
|
70
|
+
* Provides additional context information for error reporting
|
|
71
|
+
* Includes request ID when available for correlation across logs
|
|
72
|
+
* @param ctx - HTTP context containing request information
|
|
73
|
+
* @returns Additional context data for error reporting
|
|
55
74
|
*/
|
|
56
75
|
protected context(ctx: HttpContext): any;
|
|
57
76
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
77
|
+
* Determines the appropriate log level based on HTTP status code
|
|
78
|
+
* 5xx errors are logged as 'error', 4xx as 'warn', others as 'info'
|
|
79
|
+
* @param error - HTTP error object with status code
|
|
80
|
+
* @returns {Level} Appropriate logging level for the error
|
|
60
81
|
*/
|
|
61
82
|
protected getErrorLogLevel(error: HttpError): Level;
|
|
62
83
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
84
|
+
* Determines whether debug information should be included in error responses
|
|
85
|
+
* Override this method to implement context-specific debug control
|
|
86
|
+
* @param _ - HTTP context (unused in base implementation)
|
|
87
|
+
* @returns {boolean} True if debugging should be enabled
|
|
65
88
|
*/
|
|
66
89
|
protected isDebuggingEnabled(_: HttpContext): boolean;
|
|
67
90
|
/**
|
|
68
|
-
*
|
|
91
|
+
* Determines whether an error should be reported to logging systems
|
|
92
|
+
* Checks against ignore lists for exceptions, status codes, and error codes
|
|
93
|
+
* @param error - HTTP error to evaluate for reporting
|
|
94
|
+
* @returns {boolean} True if the error should be reported
|
|
69
95
|
*/
|
|
70
96
|
protected shouldReport(error: HttpError): boolean;
|
|
71
97
|
/**
|
|
72
|
-
* Renders an error
|
|
98
|
+
* Renders an error as a JSON response
|
|
99
|
+
* In debug mode, includes full stack trace using Youch
|
|
100
|
+
* @param error - HTTP error to render
|
|
101
|
+
* @param ctx - HTTP context for the request
|
|
73
102
|
*/
|
|
74
103
|
renderErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
75
104
|
/**
|
|
76
|
-
* Renders an error
|
|
105
|
+
* Renders an error as a JSON API compliant response
|
|
106
|
+
* Follows JSON API specification for error objects
|
|
107
|
+
* @param error - HTTP error to render
|
|
108
|
+
* @param ctx - HTTP context for the request
|
|
77
109
|
*/
|
|
78
110
|
renderErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
79
111
|
/**
|
|
80
|
-
* Renders an error
|
|
112
|
+
* Renders an error as an HTML response
|
|
113
|
+
* Uses status pages if configured, otherwise shows debug info or simple message
|
|
114
|
+
* @param error - HTTP error to render
|
|
115
|
+
* @param ctx - HTTP context for the request
|
|
81
116
|
*/
|
|
82
117
|
renderErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<any>;
|
|
83
118
|
/**
|
|
84
|
-
* Renders
|
|
85
|
-
*
|
|
119
|
+
* Renders validation error messages as a JSON response
|
|
120
|
+
* Returns errors in a simple format with field-specific messages
|
|
121
|
+
* @param error - Validation error containing messages array
|
|
122
|
+
* @param ctx - HTTP context for the request
|
|
86
123
|
*/
|
|
87
124
|
renderValidationErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
88
125
|
/**
|
|
89
|
-
* Renders
|
|
90
|
-
*
|
|
126
|
+
* Renders validation error messages as JSON API compliant response
|
|
127
|
+
* Transforms validation messages to JSON API error object format
|
|
128
|
+
* @param error - Validation error containing messages array
|
|
129
|
+
* @param ctx - HTTP context for the request
|
|
91
130
|
*/
|
|
92
131
|
renderValidationErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
93
132
|
/**
|
|
94
|
-
* Renders
|
|
133
|
+
* Renders validation error messages as an HTML response
|
|
134
|
+
* Creates simple HTML list of field errors separated by line breaks
|
|
135
|
+
* @param error - Validation error containing messages array
|
|
136
|
+
* @param ctx - HTTP context for the request
|
|
95
137
|
*/
|
|
96
138
|
renderValidationErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
97
139
|
/**
|
|
98
|
-
* Renders
|
|
140
|
+
* Renders an error to the appropriate response format based on content negotiation
|
|
141
|
+
* Supports HTML, JSON API, and JSON formats based on Accept headers
|
|
142
|
+
* @param error - HTTP error to render
|
|
143
|
+
* @param ctx - HTTP context for the request
|
|
99
144
|
*/
|
|
100
145
|
renderError(error: HttpError, ctx: HttpContext): Promise<any>;
|
|
101
146
|
/**
|
|
102
|
-
* Renders
|
|
147
|
+
* Renders validation errors to the appropriate response format based on content negotiation
|
|
148
|
+
* Supports HTML, JSON API, and JSON formats for validation error messages
|
|
149
|
+
* @param error - Validation error to render
|
|
150
|
+
* @param ctx - HTTP context for the request
|
|
103
151
|
*/
|
|
104
152
|
renderValidationError(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
105
153
|
/**
|
|
106
|
-
* Reports an error
|
|
154
|
+
* Reports an error to logging systems if reporting is enabled
|
|
155
|
+
* Allows errors to self-report via their own report method if available
|
|
156
|
+
* @param error - Any error object to report
|
|
157
|
+
* @param ctx - HTTP context for additional reporting context
|
|
107
158
|
*/
|
|
108
159
|
report(error: unknown, ctx: HttpContext): Promise<void>;
|
|
109
160
|
/**
|
|
110
|
-
* Handles
|
|
161
|
+
* Handles errors during HTTP request processing
|
|
162
|
+
* Delegates to error's own handle method if available, otherwise renders response
|
|
163
|
+
* @param error - Any error object to handle
|
|
164
|
+
* @param ctx - HTTP context for error handling
|
|
111
165
|
*/
|
|
112
166
|
handle(error: unknown, ctx: HttpContext): Promise<any>;
|
|
113
167
|
}
|
package/build/src/helpers.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { type Encryption } from '@adonisjs/encryption';
|
|
2
|
+
import { type Qs } from './qs.ts';
|
|
3
|
+
import { createURL } from './client/helpers.ts';
|
|
1
4
|
import { type CookieOptions } from './types/response.ts';
|
|
5
|
+
import { type SignedURLOptions } from './types/url_builder.ts';
|
|
2
6
|
import type { RouteMatchers, RouteJSON, MatchItRouteToken } from './types/route.ts';
|
|
3
7
|
import { type MiddlewareFn, type RouteHandlerInfo, type MiddlewareHandlerInfo, type ParsedGlobalMiddleware, type ParsedNamedMiddleware } from './types/middleware.ts';
|
|
8
|
+
export { createURL };
|
|
4
9
|
/**
|
|
5
10
|
* This function is similar to the intrinsic function encodeURI. However, it will not encode:
|
|
6
11
|
* - The \, ^, or | characters
|
|
@@ -34,25 +39,77 @@ export { default as mime } from 'mime-types';
|
|
|
34
39
|
* Value (val) refers to the segment value
|
|
35
40
|
*
|
|
36
41
|
* end refers to be the suffix or the segment (if any)
|
|
42
|
+
*
|
|
43
|
+
* @param pattern - The route pattern to parse
|
|
44
|
+
* @param matchers - Optional route matchers
|
|
45
|
+
* @returns {MatchItRouteToken[]} Array of parsed route tokens
|
|
37
46
|
*/
|
|
38
47
|
export declare function parseRoute(pattern: string, matchers?: RouteMatchers): MatchItRouteToken[];
|
|
48
|
+
/**
|
|
49
|
+
* Makes signed URL for a given route pattern using its parsed tokens. The
|
|
50
|
+
* tokens could be generated using the "parseRoute" method.
|
|
51
|
+
*
|
|
52
|
+
* @param identifier - Route identifier
|
|
53
|
+
* @param tokens - Array of parsed route tokens
|
|
54
|
+
* @param searchParamsStringifier - Function to stringify query parameters
|
|
55
|
+
* @param encryption - Encryption instance for signing
|
|
56
|
+
* @param params - Route parameters as array or object
|
|
57
|
+
* @param options - Signed URL options
|
|
58
|
+
* @returns {string} The generated signed URL
|
|
59
|
+
*/
|
|
60
|
+
export declare function createSignedURL(identifier: string, tokens: MatchItRouteToken[], searchParamsStringifier: (qs: Record<string, any>) => string, encryption: Encryption, params?: any[] | {
|
|
61
|
+
[param: string]: any;
|
|
62
|
+
}, options?: SignedURLOptions): string;
|
|
39
63
|
/**
|
|
40
64
|
* Match a given URI with an array of patterns and extract the params
|
|
41
65
|
* from the URL. Null value is returned in case of no match
|
|
66
|
+
*
|
|
67
|
+
* @param url - The URL to match
|
|
68
|
+
* @param patterns - Array of route patterns to match against
|
|
69
|
+
* @returns {null | Record<string, string>} Extracted parameters or null if no match
|
|
42
70
|
*/
|
|
43
71
|
export declare function matchRoute(url: string, patterns: string[]): null | Record<string, string>;
|
|
44
72
|
/**
|
|
45
73
|
* Serialize the value of a cookie to a string you can send via
|
|
46
74
|
* set-cookie response header.
|
|
75
|
+
*
|
|
76
|
+
* @param key - Cookie name
|
|
77
|
+
* @param value - Cookie value
|
|
78
|
+
* @param options - Cookie options
|
|
79
|
+
* @returns {string} Serialized cookie string
|
|
47
80
|
*/
|
|
48
81
|
export declare function serializeCookie(key: string, value: string, options?: Partial<CookieOptions>): string;
|
|
49
82
|
/**
|
|
50
83
|
* Returns the info about a middleware handler. In case of lazy imports, the method
|
|
51
84
|
* will return the import path
|
|
85
|
+
*
|
|
86
|
+
* @param middleware - The middleware function or parsed middleware
|
|
87
|
+
* @returns {Promise<MiddlewareHandlerInfo>} Promise resolving to middleware handler information
|
|
52
88
|
*/
|
|
53
89
|
export declare function middlewareInfo(middleware: MiddlewareFn | ParsedGlobalMiddleware | ParsedNamedMiddleware): Promise<MiddlewareHandlerInfo>;
|
|
54
90
|
/**
|
|
55
91
|
* Returns the info about a route handler. In case of lazy imports, the method
|
|
56
92
|
* will return the import path.
|
|
93
|
+
*
|
|
94
|
+
* @param route - The route JSON object
|
|
95
|
+
* @returns {Promise<RouteHandlerInfo>} Promise resolving to route handler information
|
|
57
96
|
*/
|
|
58
97
|
export declare function routeInfo(route: RouteJSON): Promise<RouteHandlerInfo>;
|
|
98
|
+
/**
|
|
99
|
+
* Appends query string parameters to a URI. Existing query parameters
|
|
100
|
+
* in the URI are merged with the new ones.
|
|
101
|
+
*
|
|
102
|
+
* @param uri - The base URI to append query string to
|
|
103
|
+
* @param queryString - Object containing query parameters to append
|
|
104
|
+
* @param qsParser - Query string parser instance for stringify/parse operations
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const result = appendQueryString('/users', { page: 1, limit: 10 }, qsParser)
|
|
109
|
+
* // Returns: '/users?page=1&limit=10'
|
|
110
|
+
*
|
|
111
|
+
* const result2 = appendQueryString('/users?sort=name', { page: 1 }, qsParser)
|
|
112
|
+
* // Returns: '/users?sort=name&page=1'
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function appendQueryString(uri: string, queryString: Record<string, any>, qsParser: Qs): string;
|
package/build/src/helpers.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
+
appendQueryString,
|
|
3
|
+
createSignedURL,
|
|
2
4
|
default as default2,
|
|
3
5
|
default2 as default3,
|
|
4
6
|
matchRoute,
|
|
@@ -6,8 +8,14 @@ import {
|
|
|
6
8
|
parseRoute,
|
|
7
9
|
routeInfo,
|
|
8
10
|
serializeCookie
|
|
9
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-QDK57QGB.js";
|
|
12
|
+
import {
|
|
13
|
+
createURL
|
|
14
|
+
} from "../chunk-2QM3D5BN.js";
|
|
10
15
|
export {
|
|
16
|
+
appendQueryString,
|
|
17
|
+
createSignedURL,
|
|
18
|
+
createURL,
|
|
11
19
|
default2 as encodeUrl,
|
|
12
20
|
matchRoute,
|
|
13
21
|
middlewareInfo,
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
2
|
import type { HttpContext } from './main.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Async local storage for HTTP context
|
|
5
|
+
*/
|
|
3
6
|
/**
|
|
4
7
|
* Async local storage for HTTP context
|
|
5
8
|
*/
|
|
6
9
|
export declare const asyncLocalStorage: {
|
|
10
|
+
/**
|
|
11
|
+
* Check if the async local storage for the HTTP context is enabled or not
|
|
12
|
+
*/
|
|
7
13
|
isEnabled: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* HTTP context storage instance for the current scope
|
|
16
|
+
*/
|
|
8
17
|
storage: null | AsyncLocalStorage<HttpContext>;
|
|
18
|
+
/**
|
|
19
|
+
* Create the storage instance. This method must be called only once.
|
|
20
|
+
*
|
|
21
|
+
* @returns {AsyncLocalStorage<HttpContext>} The created storage instance
|
|
22
|
+
*/
|
|
9
23
|
create(): AsyncLocalStorage<HttpContext>;
|
|
24
|
+
/**
|
|
25
|
+
* Destroy the create storage instance
|
|
26
|
+
*/
|
|
10
27
|
destroy(): void;
|
|
11
28
|
};
|
|
@@ -5,8 +5,22 @@ import type { Request } from '../request.ts';
|
|
|
5
5
|
import type { Response } from '../response.ts';
|
|
6
6
|
import type { RouteJSON } from '../types/route.ts';
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* HTTP context encapsulates all properties and services for a given HTTP request.
|
|
9
|
+
*
|
|
10
|
+
* The HttpContext class serves as the central hub for request-specific data and services.
|
|
11
|
+
* It provides access to the request, response, route information, container resolver,
|
|
12
|
+
* and logger instances. The context can be extended using macros and getters for
|
|
13
|
+
* application-specific functionality.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* export default class UsersController {
|
|
18
|
+
* async show({ request, response, params }: HttpContext) {
|
|
19
|
+
* const user = await User.find(params.id)
|
|
20
|
+
* return response.json(user)
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
10
24
|
*/
|
|
11
25
|
export declare class HttpContext extends Macroable {
|
|
12
26
|
request: Request;
|
|
@@ -14,23 +28,59 @@ export declare class HttpContext extends Macroable {
|
|
|
14
28
|
logger: Logger;
|
|
15
29
|
containerResolver: ContainerResolver<any>;
|
|
16
30
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
31
|
+
* Indicates whether async local storage is enabled for HTTP requests.
|
|
32
|
+
*
|
|
33
|
+
* When enabled, the HTTP context is automatically available within the
|
|
34
|
+
* scope of request processing through static methods like get() and getOrFail().
|
|
19
35
|
*/
|
|
20
36
|
static get usingAsyncLocalStorage(): boolean;
|
|
21
37
|
/**
|
|
22
|
-
* Get access to the HTTP context
|
|
23
|
-
*
|
|
38
|
+
* Get access to the current HTTP context from async local storage.
|
|
39
|
+
*
|
|
40
|
+
* This method is only available when async local storage is enabled.
|
|
41
|
+
* Returns null if called outside of an HTTP request context.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const ctx = HttpContext.get()
|
|
46
|
+
* if (ctx) {
|
|
47
|
+
* console.log(ctx.request.url())
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
24
50
|
*/
|
|
25
51
|
static get(): HttpContext | null;
|
|
26
52
|
/**
|
|
27
|
-
* Get the HttpContext instance or raise an exception if not
|
|
28
|
-
*
|
|
53
|
+
* Get the HttpContext instance or raise an exception if not available.
|
|
54
|
+
*
|
|
55
|
+
* This method is useful when you need guaranteed access to the HTTP context
|
|
56
|
+
* and want to fail fast if it's not available.
|
|
57
|
+
*
|
|
58
|
+
* @throws RuntimeException when async local storage is disabled or context is unavailable
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* const ctx = HttpContext.getOrFail()
|
|
63
|
+
* const userId = ctx.request.input('user_id')
|
|
64
|
+
* ```
|
|
29
65
|
*/
|
|
30
66
|
static getOrFail(): HttpContext;
|
|
31
67
|
/**
|
|
32
|
-
* Run a method
|
|
33
|
-
*
|
|
68
|
+
* Run a method outside of the HTTP context scope.
|
|
69
|
+
*
|
|
70
|
+
* This method allows you to execute code that should not have access to
|
|
71
|
+
* the current HTTP context from async local storage. Useful for background
|
|
72
|
+
* tasks or operations that should be context-independent.
|
|
73
|
+
*
|
|
74
|
+
* @param callback - Function to execute outside the context
|
|
75
|
+
* @param args - Arguments to pass to the callback
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* HttpContext.runOutsideContext(() => {
|
|
80
|
+
* // This code cannot access HttpContext.get()
|
|
81
|
+
* performBackgroundTask()
|
|
82
|
+
* })
|
|
83
|
+
* ```
|
|
34
84
|
*/
|
|
35
85
|
static runOutsideContext<T>(callback: (...args: any[]) => T, ...args: any[]): T;
|
|
36
86
|
/**
|
|
@@ -50,6 +100,14 @@ export declare class HttpContext extends Macroable {
|
|
|
50
100
|
* Route subdomains
|
|
51
101
|
*/
|
|
52
102
|
subdomains: Record<string, any>;
|
|
103
|
+
/**
|
|
104
|
+
* Creates a new HttpContext instance
|
|
105
|
+
*
|
|
106
|
+
* @param {Request} request - The HTTP request instance
|
|
107
|
+
* @param {Response} response - The HTTP response instance
|
|
108
|
+
* @param {Logger} logger - The logger instance
|
|
109
|
+
* @param {ContainerResolver<any>} containerResolver - The IoC container resolver
|
|
110
|
+
*/
|
|
53
111
|
constructor(request: Request, response: Response, logger: Logger, containerResolver: ContainerResolver<any>);
|
|
54
112
|
/**
|
|
55
113
|
* A helper to see top level properties on the context object
|
package/build/src/qs.d.ts
CHANGED
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
import { type QSParserConfig } from './types/qs.ts';
|
|
2
2
|
/**
|
|
3
|
-
* Query string parser
|
|
4
|
-
*
|
|
3
|
+
* Query string parser that provides methods to parse and stringify query strings.
|
|
4
|
+
*
|
|
5
|
+
* This class wraps the popular 'qs' package with configurable options for parsing
|
|
6
|
+
* and stringifying query parameters. It allows customization of array handling,
|
|
7
|
+
* depth limits, and encoding behavior.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const qs = new Qs({
|
|
12
|
+
* parse: { depth: 5, arrayLimit: 20 },
|
|
13
|
+
* stringify: { encode: false, skipNulls: true }
|
|
14
|
+
* })
|
|
15
|
+
*
|
|
16
|
+
* const parsed = qs.parse('users[0][name]=john&users[0][age]=25')
|
|
17
|
+
* const stringified = qs.stringify({ users: [{ name: 'john', age: 25 }] })
|
|
18
|
+
* ```
|
|
5
19
|
*/
|
|
6
20
|
export declare class Qs {
|
|
7
21
|
#private;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new query string parser instance with the provided configuration
|
|
24
|
+
* @param config - Configuration object with parse and stringify options
|
|
25
|
+
*/
|
|
8
26
|
constructor(config: QSParserConfig);
|
|
27
|
+
/**
|
|
28
|
+
* Parses a query string into a JavaScript object using the configured options
|
|
29
|
+
* @param value - Query string to parse (e.g., "foo=bar&baz=qux")
|
|
30
|
+
* @returns Parsed object representation of the query string
|
|
31
|
+
*/
|
|
9
32
|
parse: (value: string) => import("qs").ParsedQs;
|
|
33
|
+
/**
|
|
34
|
+
* Converts a JavaScript object into a query string using the configured options
|
|
35
|
+
* @param value - Object to convert to query string
|
|
36
|
+
* @returns Stringified query string representation of the object
|
|
37
|
+
*/
|
|
10
38
|
stringify: (value: any) => string;
|
|
11
39
|
}
|