@adonisjs/http-server 8.0.0-next.8 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/define_config-D-kQXU0e.js +2438 -0
- package/build/factories/http_context.d.ts +10 -4
- package/build/factories/main.d.ts +2 -2
- package/build/factories/main.js +170 -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-C_2HouOe.js +52 -0
- package/build/index.d.ts +3 -2
- package/build/index.js +155 -370
- 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 +115 -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 +23 -16
- package/build/src/helpers.js +76 -22
- 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 +1 -0
- 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/build/types-AUwURgIL.js +1 -0
- package/build/utils-BjSHKI3s.js +618 -0
- package/package.json +56 -47
- package/build/chunk-NQNHMINZ.js +0 -135
- package/build/chunk-W6WKITGF.js +0 -5486
- package/build/src/router/url_builder.d.ts +0 -9
|
@@ -2,10 +2,27 @@ import Macroable from '@poppinss/macroable';
|
|
|
2
2
|
import type { Application } from '@adonisjs/application';
|
|
3
3
|
import type { Constructor, LazyImport, OneOrMore } from '@poppinss/utils/types';
|
|
4
4
|
import type { MiddlewareFn, ParsedNamedMiddleware, ParsedGlobalMiddleware } from '../types/middleware.ts';
|
|
5
|
-
import type { RouteFn, RouteJSON, RouteMatcher, RouteMatchers, StoreRouteMiddleware, GetControllerHandlers } from '../types/route.ts';
|
|
5
|
+
import type { RouteFn, RouteJSON, RouteMatcher, RouteMatchers, StoreRouteHandler, StoreRouteMiddleware, GetControllerHandlers } from '../types/route.ts';
|
|
6
6
|
/**
|
|
7
|
-
* The
|
|
8
|
-
*
|
|
7
|
+
* The Route class provides a fluent API for constructing and configuring HTTP routes.
|
|
8
|
+
*
|
|
9
|
+
* Routes define how HTTP requests are handled by mapping URL patterns and HTTP methods
|
|
10
|
+
* to controller actions or inline handlers. This class supports middleware application,
|
|
11
|
+
* parameter validation, naming, and various other route-specific configurations.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const route = new Route(app, middleware, {
|
|
16
|
+
* pattern: '/users/:id',
|
|
17
|
+
* methods: ['GET'],
|
|
18
|
+
* handler: 'UsersController.show'
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* route
|
|
22
|
+
* .where('id', /^[0-9]+$/)
|
|
23
|
+
* .middleware(['auth'])
|
|
24
|
+
* .as('users.show')
|
|
25
|
+
* ```
|
|
9
26
|
*/
|
|
10
27
|
export declare class Route<Controller extends Constructor<any> = any> extends Macroable {
|
|
11
28
|
#private;
|
|
@@ -22,79 +39,160 @@ export declare class Route<Controller extends Constructor<any> = any> extends Ma
|
|
|
22
39
|
globalMatchers: RouteMatchers;
|
|
23
40
|
});
|
|
24
41
|
/**
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
42
|
+
* Returns the route's handler configuration object.
|
|
43
|
+
*/
|
|
44
|
+
getHandler(): StoreRouteHandler;
|
|
45
|
+
/**
|
|
46
|
+
* Defines a validation matcher for a route parameter. Route-level matchers
|
|
47
|
+
* take precedence over group-level matchers to ensure routes can override
|
|
48
|
+
* group constraints.
|
|
49
|
+
*
|
|
50
|
+
* @param param - The name of the route parameter to validate
|
|
51
|
+
* @param matcher - The validation pattern as a string, RegExp, or RouteMatcher object
|
|
29
52
|
*
|
|
53
|
+
* @example
|
|
30
54
|
* ```ts
|
|
55
|
+
* // Validate that 'id' is numeric
|
|
56
|
+
* route.where('id', /^[0-9]+$/)
|
|
57
|
+
*
|
|
58
|
+
* // Using a string pattern
|
|
59
|
+
* route.where('slug', '[a-z0-9-]+')
|
|
60
|
+
*
|
|
61
|
+
* // Route matcher takes precedence over group matcher
|
|
31
62
|
* Route.group(() => {
|
|
32
63
|
* Route.get('/:id', 'handler').where('id', /^[0-9]$/)
|
|
33
64
|
* }).where('id', /[^a-z$]/)
|
|
65
|
+
* // The route's /^[0-9]$/ wins over the group's matcher
|
|
34
66
|
* ```
|
|
35
|
-
*
|
|
36
|
-
* The `/^[0-9]$/` will win over the matcher defined by the group
|
|
37
67
|
*/
|
|
38
68
|
where(param: string, matcher: RouteMatcher | string | RegExp): this;
|
|
39
69
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* @
|
|
70
|
+
* Adds a URL prefix to the route pattern. Multiple calls stack prefixes
|
|
71
|
+
* which are applied in reverse order during pattern computation.
|
|
72
|
+
*
|
|
73
|
+
* @param prefix - The URL prefix to prepend to the route pattern
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* route.prefix('/api').prefix('/v1')
|
|
78
|
+
* // Results in pattern: /v1/api/users (for original pattern /users)
|
|
79
|
+
* ```
|
|
44
80
|
*/
|
|
45
81
|
prefix(prefix: string): this;
|
|
46
82
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
83
|
+
* Assigns a custom domain to the route. By default, routes belong to the
|
|
84
|
+
* 'root' domain. Once set, the domain is not overwritten unless the
|
|
85
|
+
* overwrite flag is true.
|
|
86
|
+
*
|
|
87
|
+
* @param domain - The domain identifier for this route
|
|
88
|
+
* @param overwrite - Whether to overwrite an existing non-root domain
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* route.domain('api.example.com')
|
|
93
|
+
*
|
|
94
|
+
* // Overwrite existing domain
|
|
95
|
+
* route.domain('new.example.com', true)
|
|
96
|
+
* ```
|
|
49
97
|
*/
|
|
50
98
|
domain(domain: string, overwrite?: boolean): this;
|
|
51
99
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
100
|
+
* Registers one or more middleware to execute before the route handler.
|
|
101
|
+
* Middleware can be inline functions or named middleware references registered
|
|
102
|
+
* with the router's middleware store.
|
|
103
|
+
*
|
|
104
|
+
* @param middleware - Single middleware or array of middleware to apply
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* // Single middleware
|
|
109
|
+
* route.use(async (ctx, next) => {
|
|
110
|
+
* console.log('Before handler')
|
|
111
|
+
* await next()
|
|
112
|
+
* })
|
|
54
113
|
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
114
|
+
* // Multiple middleware
|
|
115
|
+
* route.use(['auth', 'admin'])
|
|
116
|
+
* ```
|
|
57
117
|
*/
|
|
58
118
|
use(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
|
|
59
119
|
/**
|
|
60
|
-
* Alias for {@link Route.use}
|
|
120
|
+
* Alias for the {@link Route.use} method.
|
|
121
|
+
*
|
|
122
|
+
* @param middleware - Single middleware or array of middleware to apply
|
|
61
123
|
*/
|
|
62
124
|
middleware(middleware: OneOrMore<MiddlewareFn | ParsedNamedMiddleware>): this;
|
|
63
125
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
126
|
+
* Assigns a unique name to the route for use in URL generation and route
|
|
127
|
+
* referencing. Assigning a new name replaces any existing name unless
|
|
128
|
+
* prepend is true.
|
|
66
129
|
*
|
|
67
|
-
*
|
|
130
|
+
* @param name - The route name to assign
|
|
131
|
+
* @param prepend - If true, prepends the name to the existing name with a dot separator
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* // Set route name
|
|
136
|
+
* route.as('users.show')
|
|
137
|
+
*
|
|
138
|
+
* // Prepend to existing name (typically used by route groups)
|
|
139
|
+
* route.as('admin', true) // Results in 'admin.users.show'
|
|
140
|
+
* ```
|
|
68
141
|
*/
|
|
69
142
|
as(name: string, prepend?: boolean): this;
|
|
70
143
|
/**
|
|
71
|
-
*
|
|
144
|
+
* Checks whether the route has been marked for deletion. Deleted routes
|
|
145
|
+
* are excluded from the route store during registration.
|
|
72
146
|
*/
|
|
73
147
|
isDeleted(): boolean;
|
|
74
148
|
/**
|
|
75
|
-
*
|
|
76
|
-
* with the route store
|
|
149
|
+
* Marks the route for deletion. Deleted routes will not be registered
|
|
150
|
+
* with the route store when Router.commit() is called.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* const route = Route.get('/admin', 'handler')
|
|
155
|
+
* route.markAsDeleted()
|
|
156
|
+
* // This route will not be registered
|
|
157
|
+
* ```
|
|
77
158
|
*/
|
|
78
159
|
markAsDeleted(): void;
|
|
79
160
|
/**
|
|
80
|
-
*
|
|
161
|
+
* Returns the unique name assigned to the route, if any.
|
|
81
162
|
*/
|
|
82
163
|
getName(): string | undefined;
|
|
83
164
|
/**
|
|
84
|
-
*
|
|
165
|
+
* Returns the route's URL pattern with dynamic parameters.
|
|
85
166
|
*/
|
|
86
167
|
getPattern(): string;
|
|
87
168
|
/**
|
|
88
|
-
*
|
|
169
|
+
* Updates the route's URL pattern.
|
|
170
|
+
*
|
|
171
|
+
* @param pattern - The new URL pattern to assign to the route
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* route.setPattern('/users/:id/posts/:postId')
|
|
176
|
+
* ```
|
|
89
177
|
*/
|
|
90
178
|
setPattern(pattern: string): this;
|
|
91
179
|
/**
|
|
92
|
-
* Returns the
|
|
93
|
-
* The value is shared by reference.
|
|
180
|
+
* Returns the multi-dimensional middleware stack registered on this route.
|
|
181
|
+
* The returned value is shared by reference, not a copy.
|
|
94
182
|
*/
|
|
95
183
|
getMiddleware(): StoreRouteMiddleware[][];
|
|
96
184
|
/**
|
|
97
|
-
*
|
|
185
|
+
* Serializes the route into a JSON representation suitable for storage and
|
|
186
|
+
* execution. This includes the computed pattern with prefixes, merged matchers,
|
|
187
|
+
* parsed route tokens, and frozen middleware stack.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* const json = route.toJSON()
|
|
192
|
+
* console.log(json.pattern) // '/api/users/:id'
|
|
193
|
+
* console.log(json.methods) // ['GET']
|
|
194
|
+
* console.log(json.name) // 'users.show'
|
|
195
|
+
* ```
|
|
98
196
|
*/
|
|
99
197
|
toJSON(): RouteJSON;
|
|
100
198
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from '@adonisjs/logger';
|
|
2
2
|
import type { LazyImport } from '@poppinss/utils/types';
|
|
3
|
-
import type { Encryption } from '@
|
|
3
|
+
import type { Encryption } from '@boringnode/encryption';
|
|
4
4
|
import type { Server as HttpsServer } from 'node:https';
|
|
5
5
|
import type { Application } from '@adonisjs/application';
|
|
6
6
|
import type { EmitterLike } from '@adonisjs/events/types';
|
|
@@ -8,9 +8,9 @@ import { type ContainerResolver } from '@adonisjs/fold';
|
|
|
8
8
|
import type { ServerResponse, IncomingMessage, Server as HttpServer } from 'node:http';
|
|
9
9
|
import type { MiddlewareAsClass, ParsedGlobalMiddleware } from '../types/middleware.ts';
|
|
10
10
|
import type { ServerConfig, HttpServerEvents, ErrorHandlerAsAClass, TestingMiddlewarePipeline } from '../types/server.ts';
|
|
11
|
-
import {
|
|
12
|
-
import { Response } from '../response.ts';
|
|
11
|
+
import { HttpRequest } from '../request.ts';
|
|
13
12
|
import { Router } from '../router/main.ts';
|
|
13
|
+
import { HttpResponse } from '../response.ts';
|
|
14
14
|
import { HttpContext } from '../http_context/main.ts';
|
|
15
15
|
/**
|
|
16
16
|
* The Server class provides the core HTTP server implementation for AdonisJS.
|
|
@@ -105,7 +105,7 @@ export declare class Server {
|
|
|
105
105
|
* @param res - Node.js ServerResponse
|
|
106
106
|
* @returns New Request instance
|
|
107
107
|
*/
|
|
108
|
-
createRequest(req: IncomingMessage, res: ServerResponse):
|
|
108
|
+
createRequest(req: IncomingMessage, res: ServerResponse): HttpRequest;
|
|
109
109
|
/**
|
|
110
110
|
* Creates a Response instance from Node.js request/response objects
|
|
111
111
|
*
|
|
@@ -113,7 +113,7 @@ export declare class Server {
|
|
|
113
113
|
* @param res - Node.js ServerResponse
|
|
114
114
|
* @returns New Response instance
|
|
115
115
|
*/
|
|
116
|
-
createResponse(req: IncomingMessage, res: ServerResponse):
|
|
116
|
+
createResponse(req: IncomingMessage, res: ServerResponse): HttpResponse;
|
|
117
117
|
/**
|
|
118
118
|
* Creates an HttpContext instance with request-specific logger
|
|
119
119
|
*
|
|
@@ -122,7 +122,7 @@ export declare class Server {
|
|
|
122
122
|
* @param resolver - Container resolver for dependency injection
|
|
123
123
|
* @returns New HttpContext instance
|
|
124
124
|
*/
|
|
125
|
-
createHttpContext(request:
|
|
125
|
+
createHttpContext(request: HttpRequest, response: HttpResponse, resolver: ContainerResolver<any>): HttpContext;
|
|
126
126
|
/**
|
|
127
127
|
* Gets the list of registered global middleware
|
|
128
128
|
*
|
package/build/src/types/main.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -30,6 +30,11 @@ export type CastableHeader = string | number | boolean | string[] | number[] | b
|
|
|
30
30
|
* Configuration options for HTTP response handling and processing
|
|
31
31
|
*/
|
|
32
32
|
export type ResponseConfig = {
|
|
33
|
+
/**
|
|
34
|
+
* Define a custom serializer to serialize the response body
|
|
35
|
+
* to a JSON string
|
|
36
|
+
*/
|
|
37
|
+
serializeJSON(payload: unknown): string | undefined;
|
|
33
38
|
/**
|
|
34
39
|
* Whether or not to generate etags for responses. Etags can be
|
|
35
40
|
* enabled/disabled when sending response as well.
|
|
@@ -51,4 +56,4 @@ export type ResponseConfig = {
|
|
|
51
56
|
/**
|
|
52
57
|
* A readable stream that can be piped to the response stream method
|
|
53
58
|
*/
|
|
54
|
-
export type ResponseStream = Readable
|
|
59
|
+
export type ResponseStream = Readable | ReadableStream<any>;
|
|
@@ -4,6 +4,7 @@ import type { Constructor, LazyImport } from '@poppinss/utils/types';
|
|
|
4
4
|
import type { ServerErrorHandler } from './server.ts';
|
|
5
5
|
import type { HttpContext } from '../http_context/main.ts';
|
|
6
6
|
import type { MiddlewareFn, ParsedGlobalMiddleware } from './middleware.ts';
|
|
7
|
+
import { type ClientRouteJSON, type ClientRouteMatchItTokens } from '../client/types.ts';
|
|
7
8
|
/**
|
|
8
9
|
* Configuration for matching and casting route parameters
|
|
9
10
|
*/
|
|
@@ -16,16 +17,7 @@ export type RouteMatcher = {
|
|
|
16
17
|
/**
|
|
17
18
|
* Route token structure used internally by the matchit routing library
|
|
18
19
|
*/
|
|
19
|
-
export type MatchItRouteToken = RouteMatcher &
|
|
20
|
-
/** Original token string */
|
|
21
|
-
old: string;
|
|
22
|
-
/** Token type identifier (0=static, 1=param, 2=wildcard, 3=optional) */
|
|
23
|
-
type: 0 | 1 | 2 | 3;
|
|
24
|
-
/** Token value */
|
|
25
|
-
val: string;
|
|
26
|
-
/** Token end delimiter */
|
|
27
|
-
end: string;
|
|
28
|
-
};
|
|
20
|
+
export type MatchItRouteToken = RouteMatcher & ClientRouteMatchItTokens;
|
|
29
21
|
/**
|
|
30
22
|
* Extracts method names from a controller class that accept HttpContext as first parameter
|
|
31
23
|
*/
|
|
@@ -120,20 +112,12 @@ export type RouteMatchers = {
|
|
|
120
112
|
/**
|
|
121
113
|
* Complete route definition with all metadata, handlers, and execution context
|
|
122
114
|
*/
|
|
123
|
-
export type RouteJSON = {
|
|
115
|
+
export type RouteJSON = Pick<ClientRouteJSON, 'name' | 'methods' | 'domain' | 'pattern'> & {
|
|
124
116
|
/**
|
|
125
117
|
* The execute function to execute the route middleware
|
|
126
118
|
* and the handler
|
|
127
119
|
*/
|
|
128
120
|
execute: (route: RouteJSON, resolver: ContainerResolver<any>, ctx: HttpContext, errorResponder: ServerErrorHandler['handle']) => any;
|
|
129
|
-
/**
|
|
130
|
-
* A unique name for the route
|
|
131
|
-
*/
|
|
132
|
-
name?: string;
|
|
133
|
-
/**
|
|
134
|
-
* Route URI pattern
|
|
135
|
-
*/
|
|
136
|
-
pattern: string;
|
|
137
121
|
/**
|
|
138
122
|
* Route handler
|
|
139
123
|
*/
|
|
@@ -150,14 +134,6 @@ export type RouteJSON = {
|
|
|
150
134
|
* Tokens to be used to construct the route URL
|
|
151
135
|
*/
|
|
152
136
|
tokens: MatchItRouteToken[];
|
|
153
|
-
/**
|
|
154
|
-
* HTTP methods, the route responds to.
|
|
155
|
-
*/
|
|
156
|
-
methods: string[];
|
|
157
|
-
/**
|
|
158
|
-
* The domain for which the route is registered.
|
|
159
|
-
*/
|
|
160
|
-
domain: string;
|
|
161
137
|
/**
|
|
162
138
|
* Matchers for route params.
|
|
163
139
|
*/
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import { type Prettify } from '@poppinss/utils/types';
|
|
5
|
-
/**
|
|
6
|
-
* Configuration options for URL generation helpers
|
|
7
|
-
*/
|
|
8
|
-
export type URLOptions = {
|
|
9
|
-
/** Query string parameters to append to the URL */
|
|
10
|
-
qs?: Record<string, any>;
|
|
11
|
-
/** URL prefix to prepend to the generated URL */
|
|
12
|
-
prefixUrl?: string;
|
|
13
|
-
};
|
|
1
|
+
import { type UrlFor, type LookupList, type URLOptions, type LookupListRoute, type RouteBuilderArguments } from '../client/types.ts';
|
|
2
|
+
export { URLOptions, LookupListRoute, RouteBuilderArguments, LookupList, UrlFor };
|
|
14
3
|
/**
|
|
15
4
|
* Configuration options for signed URL generation helpers
|
|
16
5
|
*/
|
|
@@ -20,133 +9,6 @@ export type SignedURLOptions = URLOptions & {
|
|
|
20
9
|
/** Purpose identifier for the signed URL */
|
|
21
10
|
purpose?: string;
|
|
22
11
|
};
|
|
23
|
-
/**
|
|
24
|
-
* Utility type that constructs function arguments for route URL builders based on route parameters
|
|
25
|
-
*/
|
|
26
|
-
export type RouteBuilderArguments<Identifier, Route, Options extends any = URLOptions> = Route extends LookupListRoute ? Prettify<Route['params'] extends undefined ? [identifier: Identifier, params?: undefined, options?: Options] : [undefined] extends [Route['params']] ? [
|
|
27
|
-
identifier: Identifier,
|
|
28
|
-
params?: Route['params'] | Route['paramsTuple'],
|
|
29
|
-
options?: Options
|
|
30
|
-
] : [
|
|
31
|
-
identifier: Identifier,
|
|
32
|
-
params: Route['params'] | Route['paramsTuple'],
|
|
33
|
-
options?: Options
|
|
34
|
-
]> : never;
|
|
35
|
-
/**
|
|
36
|
-
* LookupList type is used by the URLBuilder to provide
|
|
37
|
-
* type-safety when creating URLs.
|
|
38
|
-
*
|
|
39
|
-
* There is no runtime property that matches this type. Its
|
|
40
|
-
* purely for type-inference.
|
|
41
|
-
*/
|
|
42
|
-
/**
|
|
43
|
-
* Route definition structure for type-safe URL building
|
|
44
|
-
*/
|
|
45
|
-
export type LookupListRoute = {
|
|
46
|
-
/** Parameters as a tuple for positional arguments */
|
|
47
|
-
paramsTuple?: [...any[]];
|
|
48
|
-
/** Parameters as a named object */
|
|
49
|
-
params?: {
|
|
50
|
-
[name: string]: any;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Complete route lookup structure organized by HTTP methods and route identifiers
|
|
55
|
-
*/
|
|
56
|
-
export type LookupList = {
|
|
57
|
-
/** HTTP method to route mapping */
|
|
58
|
-
[method: string]: {
|
|
59
|
-
/** Route identifier to route definition mapping */
|
|
60
|
-
[identifier: string]: LookupListRoute;
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* The urlFor helper is used to make URLs for pre-existing known routes. You can
|
|
65
|
-
* make a URL using the route name, route pattern, or the route controller
|
|
66
|
-
* reference (depends upon enabled lookupStrategies)
|
|
67
|
-
*
|
|
68
|
-
* ```ts
|
|
69
|
-
* urlFor('users.show', [1]) // /users/1
|
|
70
|
-
*
|
|
71
|
-
* // Lookup inside a specific domain
|
|
72
|
-
* urlFor('blog.adonisjs.com@posts.show', [1]) // /posts/1
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
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) & {
|
|
76
|
-
/**
|
|
77
|
-
* Make URL for a GET route. An error will be raised if the route doesn't
|
|
78
|
-
* exist.
|
|
79
|
-
*
|
|
80
|
-
* ```ts
|
|
81
|
-
* urlFor.get('users.show', [1]) // { method: 'get', url: '/users/1' }
|
|
82
|
-
* urlFor.get('users.store', [1]) // Error: Route not found GET@users/store
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
get<RouteIdentifier extends keyof Routes['GET'] & string>(...[identifier, params, options]: RouteBuilderArguments<RouteIdentifier, Routes['GET'][RouteIdentifier], Options>): {
|
|
86
|
-
method: 'get';
|
|
87
|
-
url: string;
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Make URL for a POST route. An error will be raised if the route doesn't
|
|
91
|
-
* exist.
|
|
92
|
-
*
|
|
93
|
-
* ```ts
|
|
94
|
-
* urlFor.post('users.store') // { method: 'post', url: '/users' }
|
|
95
|
-
* urlFor.post('users.show', [1]) // Error: Route not found POST@users.show
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
post<RouteIdentifier extends keyof Routes['POST'] & string>(...[identifier, params, options]: RouteBuilderArguments<RouteIdentifier, Routes['POST'][RouteIdentifier], Options>): {
|
|
99
|
-
method: 'post';
|
|
100
|
-
url: string;
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Make URL for a PUT route. An error will be raised if the route doesn't
|
|
104
|
-
* exist.
|
|
105
|
-
*
|
|
106
|
-
* ```ts
|
|
107
|
-
* urlFor.put('users.update', [1]) // { method: 'put', url: '/users/1' }
|
|
108
|
-
* urlFor.put('users.show', [1]) // Error: Route not found PUT@users.show
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
put<RouteIdentifier extends keyof Routes['PUT'] & string>(...[identifier, params, options]: RouteBuilderArguments<RouteIdentifier, Routes['PUT'][RouteIdentifier], Options>): {
|
|
112
|
-
method: 'put';
|
|
113
|
-
url: string;
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* Make URL for a PATCH route. An error will be raised if the route doesn't
|
|
117
|
-
* exist.
|
|
118
|
-
*
|
|
119
|
-
* ```ts
|
|
120
|
-
* urlFor.put('users.update', [1]) // { method: 'patch', url: '/users/1' }
|
|
121
|
-
* urlFor.put('users.show', [1]) // Error: Route not found PATCH@users.show
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
124
|
-
patch<RouteIdentifier extends keyof Routes['PATCH'] & string>(...[identifier, params, options]: RouteBuilderArguments<RouteIdentifier, Routes['PATCH'][RouteIdentifier], Options>): {
|
|
125
|
-
method: 'patch';
|
|
126
|
-
url: string;
|
|
127
|
-
};
|
|
128
|
-
/**
|
|
129
|
-
* Make URL for a DELETE route. An error will be raised if the route doesn't
|
|
130
|
-
* exist.
|
|
131
|
-
*
|
|
132
|
-
* ```ts
|
|
133
|
-
* urlFor.delete('users.destroy', [1]) // { method: 'delete', url: '/users/1' }
|
|
134
|
-
* urlFor.delete('users.show', [1]) // Error: Route not found DELETE@users.show
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
delete<RouteIdentifier extends keyof Routes['DELETE'] & string>(...[identifier, params, options]: RouteBuilderArguments<RouteIdentifier, Routes['DELETE'][RouteIdentifier], Options>): {
|
|
138
|
-
method: 'delete';
|
|
139
|
-
url: string;
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* Make URL for a custom route method. An error will be raised if the route doesn't
|
|
143
|
-
* exist for the same method.
|
|
144
|
-
*/
|
|
145
|
-
method<Method extends keyof Routes & string, RouteIdentifier extends keyof Routes[Method] & string>(method: Method, ...[identifier, params, options]: RouteBuilderArguments<RouteIdentifier, Routes[Method][RouteIdentifier], Options>): {
|
|
146
|
-
method: Method;
|
|
147
|
-
url: string;
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
12
|
/**
|
|
151
13
|
* Utility type to extract routes for a specific HTTP method from the routes collection
|
|
152
14
|
*/
|
package/build/src/utils.d.ts
CHANGED
|
@@ -4,23 +4,88 @@ import { BriskRoute } from './router/brisk.ts';
|
|
|
4
4
|
import type { RouteJSON } from './types/route.ts';
|
|
5
5
|
import { RouteResource } from './router/resource.ts';
|
|
6
6
|
/**
|
|
7
|
-
* Makes input string consistent by having only the starting
|
|
8
|
-
*
|
|
7
|
+
* Makes input string consistent by having only the starting slash.
|
|
8
|
+
*
|
|
9
|
+
* Removes trailing slashes and ensures the path starts with a forward slash,
|
|
10
|
+
* except for the root path '/' which remains unchanged.
|
|
11
|
+
*
|
|
12
|
+
* @param input - The input path string to normalize
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* dropSlash('/users/') // '/users'
|
|
17
|
+
* dropSlash('users') // '/users'
|
|
18
|
+
* dropSlash('/') // '/'
|
|
19
|
+
* ```
|
|
9
20
|
*/
|
|
10
21
|
export declare function dropSlash(input: string): string;
|
|
11
22
|
/**
|
|
12
|
-
* Returns a flat list of routes from
|
|
23
|
+
* Returns a flat list of routes from route groups, resources, and brisk routes.
|
|
24
|
+
*
|
|
25
|
+
* This function recursively processes route collections, extracting individual routes
|
|
26
|
+
* from groups and resources while filtering out any deleted routes.
|
|
27
|
+
*
|
|
28
|
+
* @param routes - Array containing route groups, individual routes, resources, and brisk routes
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const flatRoutes = toRoutesJSON([
|
|
33
|
+
* routeGroup,
|
|
34
|
+
* singleRoute,
|
|
35
|
+
* resourceRoutes
|
|
36
|
+
* ])
|
|
37
|
+
* ```
|
|
13
38
|
*/
|
|
14
39
|
export declare function toRoutesJSON(routes: (RouteGroup | Route | RouteResource | BriskRoute)[]): RouteJSON[];
|
|
15
40
|
/**
|
|
16
|
-
* Helper to
|
|
17
|
-
*
|
|
41
|
+
* Helper to determine if a remote address should be trusted.
|
|
42
|
+
*
|
|
43
|
+
* Uses caching to avoid repeated expensive proxy function calls for the same
|
|
44
|
+
* remote address. The cache improves performance when the same addresses are
|
|
45
|
+
* checked multiple times.
|
|
46
|
+
*
|
|
47
|
+
* @param remoteAddress - The remote IP address to check
|
|
48
|
+
* @param proxyFn - Function that determines if an address should be trusted
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const isTrusted = trustProxy('192.168.1.1', proxyAddr.compile('loopback'))
|
|
53
|
+
* ```
|
|
18
54
|
*/
|
|
19
55
|
export declare function trustProxy(remoteAddress: string, proxyFn: (addr: string, distance: number) => boolean): boolean;
|
|
20
56
|
/**
|
|
21
|
-
* Parses a range expression
|
|
57
|
+
* Parses a range expression (e.g., '200..299') into an object with numeric keys.
|
|
58
|
+
*
|
|
59
|
+
* Supports both single values and ranges. For ranges, all numbers between
|
|
60
|
+
* the start and end (inclusive) are mapped to the provided value.
|
|
61
|
+
*
|
|
62
|
+
* @param range - Range expression as a string (e.g., '200', '200..299')
|
|
63
|
+
* @param value - Value to assign to each number in the range
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* parseRange('200', 'success') // { 200: 'success' }
|
|
68
|
+
* parseRange('200..202', 'success') // { 200: 'success', 201: 'success', 202: 'success' }
|
|
69
|
+
* ```
|
|
22
70
|
*/
|
|
23
71
|
export declare function parseRange<T>(range: string, value: T): Record<number, T>;
|
|
72
|
+
/**
|
|
73
|
+
* Safely decodes a URI path while handling special characters and query strings.
|
|
74
|
+
*
|
|
75
|
+
* This function carefully parses and decodes URI components, handling edge cases
|
|
76
|
+
* like double-encoded characters and non-standard query string delimiters.
|
|
77
|
+
* It separates the pathname from query parameters and determines whether
|
|
78
|
+
* route parameters should be decoded.
|
|
79
|
+
*
|
|
80
|
+
* @param path - The URI path to decode
|
|
81
|
+
* @param useSemicolonDelimiter - Whether to treat semicolons as query string delimiters
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const result = safeDecodeURI('/users/123?name=john', false)
|
|
86
|
+
* // Returns: { pathname: '/users/123', query: 'name=john', shouldDecodeParam: false }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
24
89
|
export declare function safeDecodeURI(path: string, useSemicolonDelimiter: boolean): {
|
|
25
90
|
pathname: string;
|
|
26
91
|
query: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|