@adonisjs/http-server 8.0.0-next.5 → 8.0.0-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/{chunk-BFGF3A5X.js → chunk-3XEJZ4S4.js} +1105 -566
- package/build/{chunk-ASX56VAK.js → chunk-NQNHMINZ.js} +59 -0
- package/build/factories/http_context.d.ts +2 -1
- package/build/factories/http_server.d.ts +7 -0
- package/build/factories/main.js +31 -5
- package/build/factories/qs_parser_factory.d.ts +3 -2
- package/build/factories/request.d.ts +1 -0
- package/build/factories/response.d.ts +1 -0
- package/build/factories/router.d.ts +1 -0
- package/build/factories/server_factory.d.ts +1 -0
- package/build/factories/url_builder_factory.d.ts +1 -0
- package/build/index.d.ts +3 -1
- package/build/index.js +87 -37
- package/build/src/cookies/client.d.ts +35 -0
- package/build/src/cookies/drivers/encrypted.d.ts +13 -0
- package/build/src/cookies/drivers/plain.d.ts +9 -0
- package/build/src/cookies/drivers/signed.d.ts +13 -0
- package/build/src/cookies/parser.d.ts +18 -0
- package/build/src/cookies/serializer.d.ts +21 -2
- package/build/src/define_config.d.ts +1 -3
- package/build/src/define_middleware.d.ts +1 -1
- package/build/src/exception_handler.d.ts +72 -31
- package/build/src/helpers.d.ts +50 -0
- package/build/src/helpers.js +5 -1
- package/build/src/http_context/local_storage.d.ts +17 -0
- package/build/src/http_context/main.d.ts +8 -0
- package/build/src/qs.d.ts +14 -0
- package/build/src/redirect.d.ts +62 -9
- package/build/src/request.d.ts +109 -10
- package/build/src/response.d.ts +416 -203
- package/build/src/router/brisk.d.ts +13 -0
- package/build/src/router/executor.d.ts +4 -0
- package/build/src/router/factories/use_return_value.d.ts +5 -0
- package/build/src/router/group.d.ts +18 -1
- package/build/src/router/legacy/url_builder.d.ts +14 -14
- package/build/src/router/main.d.ts +73 -4
- package/build/src/router/matchers.d.ts +3 -0
- package/build/src/router/resource.d.ts +34 -1
- package/build/src/router/route.d.ts +9 -1
- package/build/src/router/signed_url_builder.d.ts +4 -8
- package/build/src/router/store.d.ts +9 -0
- package/build/src/router/url_builder.d.ts +4 -9
- package/build/src/server/factories/middleware_handler.d.ts +10 -1
- package/build/src/server/factories/route_finder.d.ts +13 -3
- package/build/src/server/factories/write_response.d.ts +9 -2
- package/build/src/server/main.d.ts +77 -23
- package/build/src/tracing_channels.d.ts +4 -4
- package/build/src/types/middleware.d.ts +34 -9
- package/build/src/types/qs.d.ts +5 -0
- package/build/src/types/request.d.ts +1 -1
- package/build/src/types/response.d.ts +14 -6
- package/build/src/types/route.d.ts +40 -19
- package/build/src/types/server.d.ts +26 -11
- package/build/src/types/tracing_channels.d.ts +21 -3
- package/build/src/types/url_builder.d.ts +24 -11
- package/package.json +17 -15
|
@@ -1,16 +1,29 @@
|
|
|
1
1
|
import type { Encryption } from '@adonisjs/encryption';
|
|
2
2
|
/**
|
|
3
3
|
* Encrypt a value to be set as cookie
|
|
4
|
+
*
|
|
5
|
+
* @param key - The cookie key used for encryption
|
|
6
|
+
* @param value - The value to encrypt
|
|
7
|
+
* @param encryption - The encryption instance
|
|
8
|
+
* @returns The encrypted cookie string or null if value is null/undefined
|
|
4
9
|
*/
|
|
5
10
|
export declare function pack(key: string, value: any, encryption: Encryption): null | string;
|
|
6
11
|
/**
|
|
7
12
|
* Returns a boolean, if the unpack method from this module can attempt
|
|
8
13
|
* to unpack encrypted value.
|
|
14
|
+
*
|
|
15
|
+
* @param encryptedValue - The encrypted value to check
|
|
16
|
+
* @returns True if the value can be unpacked by this module
|
|
9
17
|
*/
|
|
10
18
|
export declare function canUnpack(encryptedValue: string): boolean;
|
|
11
19
|
/**
|
|
12
20
|
* Attempts to unpack the encrypted cookie value. Returns null, when fails to do so.
|
|
13
21
|
* Only call this method, when `canUnpack` returns true, otherwise runtime
|
|
14
22
|
* exceptions can be raised.
|
|
23
|
+
*
|
|
24
|
+
* @param key - The cookie key used for decryption
|
|
25
|
+
* @param encryptedValue - The encrypted value to decrypt
|
|
26
|
+
* @param encryption - The encryption instance
|
|
27
|
+
* @returns The decrypted value or null if decryption fails
|
|
15
28
|
*/
|
|
16
29
|
export declare function unpack(key: string, encryptedValue: string, encryption: Encryption): null | any;
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Encodes a value into a base64 url encoded string to
|
|
3
3
|
* be set as cookie
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to encode
|
|
6
|
+
* @returns The encoded cookie string or null if value is null/undefined
|
|
4
7
|
*/
|
|
5
8
|
export declare function pack(value: any): null | string;
|
|
6
9
|
/**
|
|
7
10
|
* Returns true when this `unpack` method of this module can attempt
|
|
8
11
|
* to unpack the encode value.
|
|
12
|
+
*
|
|
13
|
+
* @param encodedValue - The encoded value to check
|
|
14
|
+
* @returns True if the value can be unpacked by this module
|
|
9
15
|
*/
|
|
10
16
|
export declare function canUnpack(encodedValue: string): boolean;
|
|
11
17
|
/**
|
|
12
18
|
* Attempts to unpack the value by decoding it. Make sure to call, `canUnpack`
|
|
13
19
|
* before calling this method
|
|
20
|
+
*
|
|
21
|
+
* @param encodedValue - The encoded value to decode
|
|
22
|
+
* @returns The decoded value or null if decoding fails
|
|
14
23
|
*/
|
|
15
24
|
export declare function unpack(encodedValue: string): null | any;
|
|
@@ -2,15 +2,28 @@ import type { Encryption } from '@adonisjs/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
|
|
5
|
+
*
|
|
6
|
+
* @param key - The cookie key used for signing
|
|
7
|
+
* @param value - The value to sign
|
|
8
|
+
* @param encryption - The encryption instance
|
|
9
|
+
* @returns The signed cookie string or null if value is null/undefined
|
|
5
10
|
*/
|
|
6
11
|
export declare function pack(key: string, value: any, encryption: Encryption): null | string;
|
|
7
12
|
/**
|
|
8
13
|
* Returns a boolean, if the unpack method from this module can attempt
|
|
9
14
|
* to unpack the signed value.
|
|
15
|
+
*
|
|
16
|
+
* @param signedValue - The signed value to check
|
|
17
|
+
* @returns True if the value can be unpacked by this module
|
|
10
18
|
*/
|
|
11
19
|
export declare function canUnpack(signedValue: string): boolean;
|
|
12
20
|
/**
|
|
13
21
|
* Attempts to unpack the signed value. Make sure to call `canUnpack` before
|
|
14
22
|
* calling this method.
|
|
23
|
+
*
|
|
24
|
+
* @param key - The cookie key used for verification
|
|
25
|
+
* @param signedValue - The signed value to verify and unpack
|
|
26
|
+
* @param encryption - The encryption instance
|
|
27
|
+
* @returns The original value or null if verification fails
|
|
15
28
|
*/
|
|
16
29
|
export declare function unpack(key: string, signedValue: string, encryption: Encryption): null | any;
|
|
@@ -11,27 +11,45 @@ import type { Encryption } from '@adonisjs/encryption';
|
|
|
11
11
|
*/
|
|
12
12
|
export declare class CookieParser {
|
|
13
13
|
#private;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new instance of CookieParser
|
|
16
|
+
*
|
|
17
|
+
* @param cookieHeader - The raw cookie header string from the request
|
|
18
|
+
* @param encryption - The encryption instance for cookie operations
|
|
19
|
+
*/
|
|
14
20
|
constructor(cookieHeader: string, encryption: Encryption);
|
|
15
21
|
/**
|
|
16
22
|
* Attempts to decode a cookie by the name. When calling this method,
|
|
17
23
|
* you are assuming that the cookie was just stringified in the first
|
|
18
24
|
* place and not signed or encrypted.
|
|
25
|
+
*
|
|
26
|
+
* @param key - The cookie key to decode
|
|
27
|
+
* @param stringified - Whether the cookie value was stringified
|
|
28
|
+
* @returns The decoded cookie value or null if decoding fails
|
|
19
29
|
*/
|
|
20
30
|
decode(key: string, stringified?: boolean): any | null;
|
|
21
31
|
/**
|
|
22
32
|
* Attempts to unsign a cookie by the name. When calling this method,
|
|
23
33
|
* you are assuming that the cookie was signed in the first place.
|
|
34
|
+
*
|
|
35
|
+
* @param key - The cookie key to unsign
|
|
36
|
+
* @returns The original cookie value or null if unsigning fails
|
|
24
37
|
*/
|
|
25
38
|
unsign(key: string): null | any;
|
|
26
39
|
/**
|
|
27
40
|
* Attempts to decrypt a cookie by the name. When calling this method,
|
|
28
41
|
* you are assuming that the cookie was encrypted in the first place.
|
|
42
|
+
*
|
|
43
|
+
* @param key - The cookie key to decrypt
|
|
44
|
+
* @returns The decrypted cookie value or null if decryption fails
|
|
29
45
|
*/
|
|
30
46
|
decrypt(key: string): null | any;
|
|
31
47
|
/**
|
|
32
48
|
* Returns an object of cookies key-value pair. Do note, the
|
|
33
49
|
* cookies are not decoded, unsigned or decrypted inside this
|
|
34
50
|
* list.
|
|
51
|
+
*
|
|
52
|
+
* @returns Raw cookies as key-value pairs
|
|
35
53
|
*/
|
|
36
54
|
list(): Record<string, any>;
|
|
37
55
|
}
|
|
@@ -7,6 +7,11 @@ import type { CookieOptions } from '../types/response.ts';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class CookieSerializer {
|
|
9
9
|
#private;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of CookieSerializer
|
|
12
|
+
*
|
|
13
|
+
* @param encryption - The encryption instance for cookie operations
|
|
14
|
+
*/
|
|
10
15
|
constructor(encryption: Encryption);
|
|
11
16
|
/**
|
|
12
17
|
* Encodes value as a plain cookie. By default, the plain value will be converted
|
|
@@ -18,11 +23,15 @@ export declare class CookieSerializer {
|
|
|
18
23
|
* serializer.encode('name', 'virk')
|
|
19
24
|
* serializer.encode('name', 'virk', { stringify: false })
|
|
20
25
|
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param key - The cookie key
|
|
28
|
+
* @param value - The value to encode
|
|
29
|
+
* @param options - Cookie encoding options
|
|
30
|
+
* @returns The serialized cookie string or null if encoding fails
|
|
21
31
|
*/
|
|
22
32
|
encode(key: string, value: any, options?: Partial<CookieOptions & {
|
|
23
33
|
/**
|
|
24
|
-
* @depreacted
|
|
25
|
-
* Instead use stringify option
|
|
34
|
+
* @depreacted Instead use stringify option
|
|
26
35
|
*/
|
|
27
36
|
encode: boolean;
|
|
28
37
|
stringify: boolean;
|
|
@@ -30,10 +39,20 @@ export declare class CookieSerializer {
|
|
|
30
39
|
/**
|
|
31
40
|
* Sign a key-value pair to a signed cookie. The signed value has a
|
|
32
41
|
* verification hash attached to it to detect data tampering.
|
|
42
|
+
*
|
|
43
|
+
* @param key - The cookie key
|
|
44
|
+
* @param value - The value to sign
|
|
45
|
+
* @param options - Cookie options
|
|
46
|
+
* @returns The serialized signed cookie string or null if signing fails
|
|
33
47
|
*/
|
|
34
48
|
sign(key: string, value: any, options?: Partial<CookieOptions>): string | null;
|
|
35
49
|
/**
|
|
36
50
|
* Encrypts a key-value pair to an encrypted cookie.
|
|
51
|
+
*
|
|
52
|
+
* @param key - The cookie key
|
|
53
|
+
* @param value - The value to encrypt
|
|
54
|
+
* @param options - Cookie options
|
|
55
|
+
* @returns The serialized encrypted cookie string or null if encryption fails
|
|
37
56
|
*/
|
|
38
57
|
encrypt(key: string, value: any, options?: Partial<CookieOptions>): string | null;
|
|
39
58
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
+
import { type DeepPartial } from '@poppinss/utils/types';
|
|
1
2
|
import type { ServerConfig } from './types/server.ts';
|
|
2
|
-
type DeepPartial<T> = {
|
|
3
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
4
|
-
};
|
|
5
3
|
type UserDefinedServerConfig = DeepPartial<Omit<ServerConfig, 'trustProxy'> & {
|
|
6
4
|
trustProxy: ((address: string, distance: number) => boolean) | boolean | string;
|
|
7
5
|
}>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LazyImport, UnWrapLazyImport } from '@poppinss/utils/types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { MiddlewareAsClass, GetMiddlewareArgs, ParsedGlobalMiddleware } from './types/middleware.ts';
|
|
3
3
|
/**
|
|
4
4
|
* Define an collection of named middleware. The collection gets converted
|
|
5
5
|
* into a collection of factory functions. Calling the function returns
|
|
@@ -17,97 +17,138 @@ import type { HttpError, StatusPageRange, StatusPageRenderer } from './types/ser
|
|
|
17
17
|
export declare class ExceptionHandler extends Macroable {
|
|
18
18
|
#private;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
20
|
+
* Controls whether to include debug information in error responses
|
|
21
|
+
* When enabled, errors include complete stack traces and detailed debugging info
|
|
22
|
+
* Defaults to true in non-production environments
|
|
22
23
|
*/
|
|
23
24
|
protected debug: boolean;
|
|
24
25
|
/**
|
|
25
|
-
*
|
|
26
|
-
* errors with matching status codes
|
|
27
|
-
*
|
|
26
|
+
* Controls whether to render custom status pages for unhandled errors
|
|
27
|
+
* When enabled, errors with matching status codes use configured status page renderers
|
|
28
|
+
* Defaults to true in production environments
|
|
28
29
|
*/
|
|
29
30
|
protected renderStatusPages: boolean;
|
|
30
31
|
/**
|
|
31
|
-
*
|
|
32
|
+
* Mapping of HTTP status code ranges to their corresponding page renderers
|
|
33
|
+
* Supports ranges like '400-499' or individual codes like '404'
|
|
32
34
|
*/
|
|
33
35
|
protected statusPages: Record<StatusPageRange, StatusPageRenderer>;
|
|
34
36
|
/**
|
|
35
|
-
*
|
|
37
|
+
* Controls whether errors should be reported to logging systems
|
|
38
|
+
* When disabled, errors are handled but not logged or reported
|
|
36
39
|
*/
|
|
37
40
|
protected reportErrors: boolean;
|
|
38
41
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
42
|
+
* Array of exception class constructors to exclude from error reporting
|
|
43
|
+
* These exceptions are handled but not logged or reported to external systems
|
|
41
44
|
*/
|
|
42
45
|
protected ignoreExceptions: any[];
|
|
43
46
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
47
|
+
* Array of HTTP status codes to exclude from error reporting
|
|
48
|
+
* Errors with these status codes are handled but not logged
|
|
46
49
|
*/
|
|
47
50
|
protected ignoreStatuses: number[];
|
|
48
51
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
52
|
+
* Array of custom error codes to exclude from error reporting
|
|
53
|
+
* Errors with these codes are handled but not logged
|
|
51
54
|
*/
|
|
52
55
|
protected ignoreCodes: string[];
|
|
53
56
|
/**
|
|
54
|
-
*
|
|
57
|
+
* Provides additional context information for error reporting
|
|
58
|
+
* Includes request ID when available for correlation across logs
|
|
59
|
+
* @param ctx - HTTP context containing request information
|
|
60
|
+
* @returns Additional context data for error reporting
|
|
55
61
|
*/
|
|
56
62
|
protected context(ctx: HttpContext): any;
|
|
57
63
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
64
|
+
* Determines the appropriate log level based on HTTP status code
|
|
65
|
+
* 5xx errors are logged as 'error', 4xx as 'warn', others as 'info'
|
|
66
|
+
* @param error - HTTP error object with status code
|
|
67
|
+
* @returns {Level} Appropriate logging level for the error
|
|
60
68
|
*/
|
|
61
69
|
protected getErrorLogLevel(error: HttpError): Level;
|
|
62
70
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
71
|
+
* Determines whether debug information should be included in error responses
|
|
72
|
+
* Override this method to implement context-specific debug control
|
|
73
|
+
* @param _ - HTTP context (unused in base implementation)
|
|
74
|
+
* @returns {boolean} True if debugging should be enabled
|
|
65
75
|
*/
|
|
66
76
|
protected isDebuggingEnabled(_: HttpContext): boolean;
|
|
67
77
|
/**
|
|
68
|
-
*
|
|
78
|
+
* Determines whether an error should be reported to logging systems
|
|
79
|
+
* Checks against ignore lists for exceptions, status codes, and error codes
|
|
80
|
+
* @param error - HTTP error to evaluate for reporting
|
|
81
|
+
* @returns {boolean} True if the error should be reported
|
|
69
82
|
*/
|
|
70
83
|
protected shouldReport(error: HttpError): boolean;
|
|
71
84
|
/**
|
|
72
|
-
* Renders an error
|
|
85
|
+
* Renders an error as a JSON response
|
|
86
|
+
* In debug mode, includes full stack trace using Youch
|
|
87
|
+
* @param error - HTTP error to render
|
|
88
|
+
* @param ctx - HTTP context for the request
|
|
73
89
|
*/
|
|
74
90
|
renderErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
75
91
|
/**
|
|
76
|
-
* Renders an error
|
|
92
|
+
* Renders an error as a JSON API compliant response
|
|
93
|
+
* Follows JSON API specification for error objects
|
|
94
|
+
* @param error - HTTP error to render
|
|
95
|
+
* @param ctx - HTTP context for the request
|
|
77
96
|
*/
|
|
78
97
|
renderErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
79
98
|
/**
|
|
80
|
-
* Renders an error
|
|
99
|
+
* Renders an error as an HTML response
|
|
100
|
+
* Uses status pages if configured, otherwise shows debug info or simple message
|
|
101
|
+
* @param error - HTTP error to render
|
|
102
|
+
* @param ctx - HTTP context for the request
|
|
81
103
|
*/
|
|
82
104
|
renderErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<any>;
|
|
83
105
|
/**
|
|
84
|
-
* Renders
|
|
85
|
-
*
|
|
106
|
+
* Renders validation error messages as a JSON response
|
|
107
|
+
* Returns errors in a simple format with field-specific messages
|
|
108
|
+
* @param error - Validation error containing messages array
|
|
109
|
+
* @param ctx - HTTP context for the request
|
|
86
110
|
*/
|
|
87
111
|
renderValidationErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
88
112
|
/**
|
|
89
|
-
* Renders
|
|
90
|
-
*
|
|
113
|
+
* Renders validation error messages as JSON API compliant response
|
|
114
|
+
* Transforms validation messages to JSON API error object format
|
|
115
|
+
* @param error - Validation error containing messages array
|
|
116
|
+
* @param ctx - HTTP context for the request
|
|
91
117
|
*/
|
|
92
118
|
renderValidationErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
93
119
|
/**
|
|
94
|
-
* Renders
|
|
120
|
+
* Renders validation error messages as an HTML response
|
|
121
|
+
* Creates simple HTML list of field errors separated by line breaks
|
|
122
|
+
* @param error - Validation error containing messages array
|
|
123
|
+
* @param ctx - HTTP context for the request
|
|
95
124
|
*/
|
|
96
125
|
renderValidationErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
97
126
|
/**
|
|
98
|
-
* Renders
|
|
127
|
+
* Renders an error to the appropriate response format based on content negotiation
|
|
128
|
+
* Supports HTML, JSON API, and JSON formats based on Accept headers
|
|
129
|
+
* @param error - HTTP error to render
|
|
130
|
+
* @param ctx - HTTP context for the request
|
|
99
131
|
*/
|
|
100
132
|
renderError(error: HttpError, ctx: HttpContext): Promise<any>;
|
|
101
133
|
/**
|
|
102
|
-
* Renders
|
|
134
|
+
* Renders validation errors to the appropriate response format based on content negotiation
|
|
135
|
+
* Supports HTML, JSON API, and JSON formats for validation error messages
|
|
136
|
+
* @param error - Validation error to render
|
|
137
|
+
* @param ctx - HTTP context for the request
|
|
103
138
|
*/
|
|
104
139
|
renderValidationError(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
105
140
|
/**
|
|
106
|
-
* Reports an error
|
|
141
|
+
* Reports an error to logging systems if reporting is enabled
|
|
142
|
+
* Allows errors to self-report via their own report method if available
|
|
143
|
+
* @param error - Any error object to report
|
|
144
|
+
* @param ctx - HTTP context for additional reporting context
|
|
107
145
|
*/
|
|
108
146
|
report(error: unknown, ctx: HttpContext): Promise<void>;
|
|
109
147
|
/**
|
|
110
|
-
* Handles
|
|
148
|
+
* Handles errors during HTTP request processing
|
|
149
|
+
* Delegates to error's own handle method if available, otherwise renders response
|
|
150
|
+
* @param error - Any error object to handle
|
|
151
|
+
* @param ctx - HTTP context for error handling
|
|
111
152
|
*/
|
|
112
153
|
handle(error: unknown, ctx: HttpContext): Promise<any>;
|
|
113
154
|
}
|
package/build/src/helpers.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { type Encryption } from '@adonisjs/encryption';
|
|
1
2
|
import { type CookieOptions } from './types/response.ts';
|
|
3
|
+
import { type SignedURLOptions, type URLOptions } from './types/url_builder.ts';
|
|
2
4
|
import type { RouteMatchers, RouteJSON, MatchItRouteToken } from './types/route.ts';
|
|
3
5
|
import { type MiddlewareFn, type RouteHandlerInfo, type MiddlewareHandlerInfo, type ParsedGlobalMiddleware, type ParsedNamedMiddleware } from './types/middleware.ts';
|
|
4
6
|
/**
|
|
@@ -34,25 +36,73 @@ export { default as mime } from 'mime-types';
|
|
|
34
36
|
* Value (val) refers to the segment value
|
|
35
37
|
*
|
|
36
38
|
* end refers to be the suffix or the segment (if any)
|
|
39
|
+
*
|
|
40
|
+
* @param pattern - The route pattern to parse
|
|
41
|
+
* @param matchers - Optional route matchers
|
|
42
|
+
* @returns {MatchItRouteToken[]} Array of parsed route tokens
|
|
37
43
|
*/
|
|
38
44
|
export declare function parseRoute(pattern: string, matchers?: RouteMatchers): MatchItRouteToken[];
|
|
45
|
+
/**
|
|
46
|
+
* Makes URL for a given route pattern using its parsed tokens. The
|
|
47
|
+
* tokens could be generated using the "parseRoute" method.
|
|
48
|
+
*
|
|
49
|
+
* @param pattern - The route pattern
|
|
50
|
+
* @param tokens - Array of parsed route tokens
|
|
51
|
+
* @param searchParamsStringifier - Function to stringify query parameters
|
|
52
|
+
* @param params - Route parameters as array or object
|
|
53
|
+
* @param options - URL options
|
|
54
|
+
* @returns {string} The generated URL
|
|
55
|
+
*/
|
|
56
|
+
export declare function createURL(pattern: string, tokens: Pick<MatchItRouteToken, 'val' | 'type' | 'end'>[], searchParamsStringifier: (qs: Record<string, any>) => string, params?: any[] | {
|
|
57
|
+
[param: string]: any;
|
|
58
|
+
}, options?: URLOptions): string;
|
|
59
|
+
/**
|
|
60
|
+
* Makes signed URL for a given route pattern using its parsed tokens. The
|
|
61
|
+
* tokens could be generated using the "parseRoute" method.
|
|
62
|
+
*
|
|
63
|
+
* @param identifier - Route identifier
|
|
64
|
+
* @param tokens - Array of parsed route tokens
|
|
65
|
+
* @param searchParamsStringifier - Function to stringify query parameters
|
|
66
|
+
* @param encryption - Encryption instance for signing
|
|
67
|
+
* @param params - Route parameters as array or object
|
|
68
|
+
* @param options - Signed URL options
|
|
69
|
+
* @returns {string} The generated signed URL
|
|
70
|
+
*/
|
|
71
|
+
export declare function createSignedURL(identifier: string, tokens: MatchItRouteToken[], searchParamsStringifier: (qs: Record<string, any>) => string, encryption: Encryption, params?: any[] | {
|
|
72
|
+
[param: string]: any;
|
|
73
|
+
}, options?: SignedURLOptions): string;
|
|
39
74
|
/**
|
|
40
75
|
* Match a given URI with an array of patterns and extract the params
|
|
41
76
|
* from the URL. Null value is returned in case of no match
|
|
77
|
+
*
|
|
78
|
+
* @param url - The URL to match
|
|
79
|
+
* @param patterns - Array of route patterns to match against
|
|
80
|
+
* @returns {null | Record<string, string>} Extracted parameters or null if no match
|
|
42
81
|
*/
|
|
43
82
|
export declare function matchRoute(url: string, patterns: string[]): null | Record<string, string>;
|
|
44
83
|
/**
|
|
45
84
|
* Serialize the value of a cookie to a string you can send via
|
|
46
85
|
* set-cookie response header.
|
|
86
|
+
*
|
|
87
|
+
* @param key - Cookie name
|
|
88
|
+
* @param value - Cookie value
|
|
89
|
+
* @param options - Cookie options
|
|
90
|
+
* @returns {string} Serialized cookie string
|
|
47
91
|
*/
|
|
48
92
|
export declare function serializeCookie(key: string, value: string, options?: Partial<CookieOptions>): string;
|
|
49
93
|
/**
|
|
50
94
|
* Returns the info about a middleware handler. In case of lazy imports, the method
|
|
51
95
|
* will return the import path
|
|
96
|
+
*
|
|
97
|
+
* @param middleware - The middleware function or parsed middleware
|
|
98
|
+
* @returns {Promise<MiddlewareHandlerInfo>} Promise resolving to middleware handler information
|
|
52
99
|
*/
|
|
53
100
|
export declare function middlewareInfo(middleware: MiddlewareFn | ParsedGlobalMiddleware | ParsedNamedMiddleware): Promise<MiddlewareHandlerInfo>;
|
|
54
101
|
/**
|
|
55
102
|
* Returns the info about a route handler. In case of lazy imports, the method
|
|
56
103
|
* will return the import path.
|
|
104
|
+
*
|
|
105
|
+
* @param route - The route JSON object
|
|
106
|
+
* @returns {Promise<RouteHandlerInfo>} Promise resolving to route handler information
|
|
57
107
|
*/
|
|
58
108
|
export declare function routeInfo(route: RouteJSON): Promise<RouteHandlerInfo>;
|
package/build/src/helpers.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
+
createSignedURL,
|
|
3
|
+
createURL,
|
|
2
4
|
default as default2,
|
|
3
5
|
default2 as default3,
|
|
4
6
|
matchRoute,
|
|
@@ -6,8 +8,10 @@ import {
|
|
|
6
8
|
parseRoute,
|
|
7
9
|
routeInfo,
|
|
8
10
|
serializeCookie
|
|
9
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-NQNHMINZ.js";
|
|
10
12
|
export {
|
|
13
|
+
createSignedURL,
|
|
14
|
+
createURL,
|
|
11
15
|
default2 as encodeUrl,
|
|
12
16
|
matchRoute,
|
|
13
17
|
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
|
};
|
|
@@ -50,6 +50,14 @@ export declare class HttpContext extends Macroable {
|
|
|
50
50
|
* Route subdomains
|
|
51
51
|
*/
|
|
52
52
|
subdomains: Record<string, any>;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a new HttpContext instance
|
|
55
|
+
*
|
|
56
|
+
* @param {Request} request - The HTTP request instance
|
|
57
|
+
* @param {Response} response - The HTTP response instance
|
|
58
|
+
* @param {Logger} logger - The logger instance
|
|
59
|
+
* @param {ContainerResolver<any>} containerResolver - The IoC container resolver
|
|
60
|
+
*/
|
|
53
61
|
constructor(request: Request, response: Response, logger: Logger, containerResolver: ContainerResolver<any>);
|
|
54
62
|
/**
|
|
55
63
|
* A helper to see top level properties on the context object
|
package/build/src/qs.d.ts
CHANGED
|
@@ -5,7 +5,21 @@ import { type QSParserConfig } from './types/qs.ts';
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class Qs {
|
|
7
7
|
#private;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new query string parser instance with the provided configuration
|
|
10
|
+
* @param config - Configuration object with parse and stringify options
|
|
11
|
+
*/
|
|
8
12
|
constructor(config: QSParserConfig);
|
|
13
|
+
/**
|
|
14
|
+
* Parses a query string into a JavaScript object using the configured options
|
|
15
|
+
* @param value - Query string to parse (e.g., "foo=bar&baz=qux")
|
|
16
|
+
* @returns Parsed object representation of the query string
|
|
17
|
+
*/
|
|
9
18
|
parse: (value: string) => import("qs").ParsedQs;
|
|
19
|
+
/**
|
|
20
|
+
* Converts a JavaScript object into a query string using the configured options
|
|
21
|
+
* @param value - Object to convert to query string
|
|
22
|
+
* @returns Stringified query string representation of the object
|
|
23
|
+
*/
|
|
10
24
|
stringify: (value: any) => string;
|
|
11
25
|
}
|
package/build/src/redirect.d.ts
CHANGED
|
@@ -8,34 +8,87 @@ import type { RoutesList, LookupList, URLOptions, GetRoutesForMethod, RouteBuild
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class Redirect {
|
|
10
10
|
#private;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new Redirect instance for handling HTTP redirects
|
|
13
|
+
* @param request - Node.js incoming HTTP request
|
|
14
|
+
* @param response - AdonisJS response instance
|
|
15
|
+
* @param router - AdonisJS router instance
|
|
16
|
+
* @param qs - Query string parser instance
|
|
17
|
+
*/
|
|
11
18
|
constructor(request: IncomingMessage, response: Response, router: Router, qs: Qs);
|
|
12
19
|
/**
|
|
13
|
-
*
|
|
20
|
+
* Sets a custom HTTP status code for the redirect response
|
|
21
|
+
* @param statusCode - HTTP status code to use (e.g., 301, 302, 307)
|
|
22
|
+
* @returns {this} The Redirect instance for method chaining
|
|
14
23
|
*/
|
|
15
24
|
status(statusCode: number): this;
|
|
16
25
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
26
|
+
* Clears any query string values previously added using the withQs method
|
|
27
|
+
* @returns {this} The Redirect instance for method chaining
|
|
19
28
|
*/
|
|
20
29
|
clearQs(): this;
|
|
21
30
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
31
|
+
* Forwards the current request's query string to the redirect URL
|
|
32
|
+
*
|
|
33
|
+
* Use this overload when you want to preserve all existing query parameters
|
|
34
|
+
* from the current request in the redirect URL.
|
|
35
|
+
*
|
|
36
|
+
* @returns The Redirect instance for method chaining
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* // If current URL is '/search?q=hello&page=2'
|
|
41
|
+
* response.redirect().withQs().toPath('/results')
|
|
42
|
+
* // Redirects to: '/results?q=hello&page=2'
|
|
43
|
+
* ```
|
|
25
44
|
*/
|
|
26
45
|
withQs(): this;
|
|
46
|
+
/**
|
|
47
|
+
* Adds multiple query string parameters to the redirect URL
|
|
48
|
+
*
|
|
49
|
+
* Use this overload when you want to add several query parameters at once
|
|
50
|
+
* using an object with key-value pairs.
|
|
51
|
+
*
|
|
52
|
+
* @param values - Object containing query parameter names and values
|
|
53
|
+
* @returns The Redirect instance for method chaining
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* response.redirect().withQs({ page: 1, sort: 'name' }).toPath('/users')
|
|
58
|
+
* // Redirects to: '/users?page=1&sort=name'
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
27
61
|
withQs(values: Record<string, any>): this;
|
|
62
|
+
/**
|
|
63
|
+
* Adds a single query string parameter to the redirect URL
|
|
64
|
+
*
|
|
65
|
+
* Use this overload when you want to add just one query parameter
|
|
66
|
+
* with a specific name and value.
|
|
67
|
+
*
|
|
68
|
+
* @param name - The query parameter name
|
|
69
|
+
* @param value - The query parameter value
|
|
70
|
+
* @returns The Redirect instance for method chaining
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* response.redirect().withQs('success', 'true').toPath('/dashboard')
|
|
75
|
+
* // Redirects to: '/dashboard?success=true'
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
28
78
|
withQs(name: string, value: any): this;
|
|
29
79
|
/**
|
|
30
|
-
*
|
|
80
|
+
* Redirects to the previous path using the Referer header
|
|
81
|
+
* Falls back to '/' if no referrer is found
|
|
31
82
|
*/
|
|
32
83
|
back(): void;
|
|
33
84
|
/**
|
|
34
|
-
*
|
|
85
|
+
* Redirects to a route using its identifier (name, pattern, or handler reference)
|
|
86
|
+
* @param args - Route identifier, parameters, and options for URL building
|
|
35
87
|
*/
|
|
36
88
|
toRoute<Identifier extends keyof GetRoutesForMethod<RoutesList, 'GET'> & string>(...args: RoutesList extends LookupList ? RouteBuilderArguments<Identifier, RoutesList['GET'][Identifier], URLOptions> : []): void;
|
|
37
89
|
/**
|
|
38
|
-
*
|
|
90
|
+
* Redirects to a specific URL path
|
|
91
|
+
* @param url - Target URL path for redirection
|
|
39
92
|
*/
|
|
40
93
|
toPath(url: string): void;
|
|
41
94
|
}
|