@adonisjs/http-server 8.0.0-next.9 → 8.1.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.
- package/build/chunk-B2GA45YG.js +35 -0
- package/build/define_config-t7GL92UR.js +5470 -0
- package/build/factories/http_context.d.ts +10 -4
- package/build/factories/main.d.ts +2 -2
- package/build/factories/main.js +328 -345
- package/build/factories/request.d.ts +4 -4
- package/build/factories/response.d.ts +4 -4
- package/build/factories/router.d.ts +1 -1
- package/build/factories/server_factory.d.ts +1 -1
- package/build/factories/url_builder_factory.d.ts +3 -3
- package/build/helpers-XD4_pfkD.js +108 -0
- package/build/helpers-aa47NQc6.js +1426 -0
- package/build/index.d.ts +2 -2
- package/build/index.js +330 -373
- package/build/src/client/helpers.d.ts +37 -0
- package/build/src/client/types.d.ts +194 -0
- package/build/src/client/url_builder.d.ts +15 -0
- package/build/src/client/url_builder.js +131 -0
- package/build/src/cookies/client.d.ts +28 -5
- package/build/src/cookies/drivers/encrypted.d.ts +1 -1
- package/build/src/cookies/drivers/signed.d.ts +1 -1
- package/build/src/cookies/parser.d.ts +1 -1
- package/build/src/cookies/serializer.d.ts +2 -2
- package/build/src/debug.d.ts +14 -1
- package/build/src/define_config.d.ts +19 -1
- package/build/src/define_middleware.d.ts +19 -3
- package/build/src/errors.d.ts +60 -5
- package/build/src/exception_handler.d.ts +28 -8
- package/build/src/helpers.d.ts +5 -17
- package/build/src/helpers.js +4 -24
- package/build/src/http_context/main.d.ts +67 -17
- package/build/src/qs.d.ts +17 -3
- package/build/src/redirect.d.ts +22 -3
- package/build/src/request.d.ts +12 -5
- package/build/src/response.d.ts +5 -5
- package/build/src/response_status.d.ts +14 -0
- package/build/src/router/main.d.ts +6 -2
- package/build/src/router/route.d.ts +130 -32
- package/build/src/router/signed_url_builder.d.ts +1 -1
- package/build/src/server/main.d.ts +6 -6
- package/build/src/types/main.js +2 -0
- package/build/src/types/request.d.ts +2 -1
- package/build/src/types/response.d.ts +6 -1
- package/build/src/types/route.d.ts +3 -27
- package/build/src/types/url_builder.d.ts +2 -140
- package/build/src/utils.d.ts +71 -6
- package/package.json +57 -48
- package/build/chunk-CVZAIRWJ.js +0 -1222
- package/build/chunk-JD6QW4NQ.js +0 -4428
- package/build/src/router/url_builder.d.ts +0 -9
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ClientRouteMatchItTokens, type ClientRouteJSON, type URLOptions } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Finds a route by its identifier across domains.
|
|
4
|
+
*
|
|
5
|
+
* Searches for routes by name, pattern, or controller reference. When no domain
|
|
6
|
+
* is specified, searches across all domains. Supports legacy lookup strategies
|
|
7
|
+
* for backwards compatibility.
|
|
8
|
+
*
|
|
9
|
+
* @param domainsRoutes - Object mapping domain names to route arrays
|
|
10
|
+
* @param routeIdentifier - Route name, pattern, or controller reference to find
|
|
11
|
+
* @param domain - Optional domain to limit search scope
|
|
12
|
+
* @param method - Optional HTTP method to filter routes
|
|
13
|
+
* @param disableLegacyLookup - Whether to disable pattern and controller lookup
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const route = findRoute(routes, 'users.show', 'api', 'GET')
|
|
18
|
+
* const route2 = findRoute(routes, '/users/:id', undefined, 'GET')
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function findRoute<Route extends ClientRouteJSON>(domainsRoutes: {
|
|
22
|
+
[domain: string]: Route[];
|
|
23
|
+
}, routeIdentifier: string, domain?: string, method?: string, disableLegacyLookup?: boolean): null | Route;
|
|
24
|
+
/**
|
|
25
|
+
* Makes URL for a given route pattern using its parsed tokens. The
|
|
26
|
+
* tokens could be generated using the "parseRoute" method.
|
|
27
|
+
*
|
|
28
|
+
* @param pattern - The route pattern
|
|
29
|
+
* @param tokens - Array of parsed route tokens
|
|
30
|
+
* @param searchParamsStringifier - Function to stringify query parameters
|
|
31
|
+
* @param params - Route parameters as array or object
|
|
32
|
+
* @param options - URL options
|
|
33
|
+
* @returns {string} The generated URL
|
|
34
|
+
*/
|
|
35
|
+
export declare function createURL(pattern: string, tokens: Pick<ClientRouteMatchItTokens, 'val' | 'type' | 'end'>[], searchParamsStringifier: (qs: Record<string, any>) => string, params?: any[] | {
|
|
36
|
+
[param: string]: any;
|
|
37
|
+
}, options?: URLOptions): string;
|
|
@@ -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 URLOptions, 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, defaultOptions?: URLOptions): UrlFor<Routes>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import "../../chunk-B2GA45YG.js";
|
|
2
|
+
import { n as findRoute, t as createURL } from "../../helpers-XD4_pfkD.js";
|
|
3
|
+
//#region src/client/url_builder.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates the URLBuilder helper
|
|
6
|
+
* @param router - The router instance
|
|
7
|
+
* @param searchParamsStringifier - Function to stringify query string parameters
|
|
8
|
+
* @returns URL builder function for creating URLs
|
|
9
|
+
*/
|
|
10
|
+
function createUrlBuilder(routesLoader, searchParamsStringifier, defaultOptions) {
|
|
11
|
+
let domainsList;
|
|
12
|
+
let domainsRoutes;
|
|
13
|
+
function createUrlForRoute(identifier, params, options, method) {
|
|
14
|
+
if (!domainsRoutes) {
|
|
15
|
+
domainsRoutes = typeof routesLoader === "function" ? routesLoader() : routesLoader;
|
|
16
|
+
if (!domainsRoutes || typeof domainsRoutes !== "object") throw new Error(`Cannot construct routes. Expected the value to be an object, instead received ${typeof domainsRoutes}`);
|
|
17
|
+
if (!domainsList) domainsList = Object.keys(domainsRoutes).filter((domain) => domain !== "root");
|
|
18
|
+
}
|
|
19
|
+
const domain = domainsList.find((name) => identifier.startsWith(`${name}@`));
|
|
20
|
+
const routeIdentifier = domain ? identifier.replace(new RegExp(`^${domain}@`), "") : identifier;
|
|
21
|
+
const route = findRoute(domainsRoutes, routeIdentifier, domain, method, true);
|
|
22
|
+
if (!route) {
|
|
23
|
+
if (method) throw new Error(`Cannot lookup route "${routeIdentifier}" for method "${method}"`);
|
|
24
|
+
throw new Error(`Cannot lookup route "${routeIdentifier}"`);
|
|
25
|
+
}
|
|
26
|
+
const mergedOptions = defaultOptions || options ? {
|
|
27
|
+
...defaultOptions,
|
|
28
|
+
...options
|
|
29
|
+
} : void 0;
|
|
30
|
+
return createURL(route.name ?? route.pattern, route.tokens, searchParamsStringifier, params, mergedOptions);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The urlFor helper is used to make URLs for pre-existing known routes. You can
|
|
34
|
+
* make a URL using the route name or the route pattern.
|
|
35
|
+
*/
|
|
36
|
+
const urlFor = function route(...[identifier, params, options]) {
|
|
37
|
+
return createUrlForRoute(identifier, params, options);
|
|
38
|
+
};
|
|
39
|
+
urlFor.get = function urlForMethodGet(...[identifier, params, options]) {
|
|
40
|
+
const method = "GET";
|
|
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.post = function urlForMethodPost(...[identifier, params, options]) {
|
|
55
|
+
const method = "POST";
|
|
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.put = function urlForMethodPut(...[identifier, params, options]) {
|
|
70
|
+
const method = "PUT";
|
|
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.patch = function urlForMethodPatch(...[identifier, params, options]) {
|
|
85
|
+
const method = "PATCH";
|
|
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.delete = function urlForMethodDelete(...[identifier, params, options]) {
|
|
100
|
+
const method = "DELETE";
|
|
101
|
+
const url = createUrlForRoute(identifier, params, options, method);
|
|
102
|
+
return {
|
|
103
|
+
url,
|
|
104
|
+
method,
|
|
105
|
+
toString() {
|
|
106
|
+
return url;
|
|
107
|
+
},
|
|
108
|
+
form: {
|
|
109
|
+
action: url,
|
|
110
|
+
method
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
urlFor.method = function urlForCustomMethod(method, ...[identifier, params, options]) {
|
|
115
|
+
const url = createUrlForRoute(identifier, params, options, method);
|
|
116
|
+
return {
|
|
117
|
+
url,
|
|
118
|
+
method,
|
|
119
|
+
toString() {
|
|
120
|
+
return url;
|
|
121
|
+
},
|
|
122
|
+
form: {
|
|
123
|
+
action: url,
|
|
124
|
+
method
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
return urlFor;
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
export { createURL, createUrlBuilder, findRoute };
|
|
@@ -1,7 +1,20 @@
|
|
|
1
|
-
import type { Encryption } from '@
|
|
1
|
+
import type { Encryption } from '@boringnode/encryption';
|
|
2
2
|
/**
|
|
3
|
-
* Cookie client
|
|
4
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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 '@
|
|
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
|
-
* @
|
|
34
|
+
* @deprecated Instead use stringify option
|
|
35
35
|
*/
|
|
36
36
|
encode: boolean;
|
|
37
37
|
stringify: boolean;
|
package/build/src/debug.d.ts
CHANGED
|
@@ -1,2 +1,15 @@
|
|
|
1
|
-
|
|
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
|
|
5
|
-
*
|
|
6
|
-
* a
|
|
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;
|
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;
|