@h3ravel/router 1.8.2 → 1.9.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/README.md +13 -1
- package/dist/index.cjs +445 -1614
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +185 -150
- package/dist/index.d.ts +186 -150
- package/dist/index.js +417 -1605
- package/dist/index.js.map +1 -1
- package/package.json +11 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,154 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { Application, ServiceProvider } from "@h3ravel/core";
|
|
2
|
+
import { H3, Middleware, MiddlewareOptions } from "h3";
|
|
3
|
+
import "reflect-metadata";
|
|
4
|
+
import { EventHandler, HttpContext, IController, IMiddleware, IRouter, RouteEventHandler, RouterEnd } from "@h3ravel/shared";
|
|
5
|
+
import { Model } from "@h3ravel/database";
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* Resolves a route handler definition into an executable EventHandler.
|
|
34
|
-
*
|
|
35
|
-
* A handler can be:
|
|
36
|
-
* - A function matching the EventHandler signature
|
|
37
|
-
* - A controller class (optionally decorated for IoC resolution)
|
|
38
|
-
*
|
|
39
|
-
* If it’s a controller class, this method will:
|
|
40
|
-
* - Instantiate it (via IoC or manually)
|
|
41
|
-
* - Call the specified method (defaults to `index`)
|
|
42
|
-
*
|
|
43
|
-
* @param handler Event handler function OR controller class
|
|
44
|
-
* @param methodName Method to invoke on the controller (defaults to 'index')
|
|
45
|
-
*/
|
|
46
|
-
private resolveControllerOrHandler;
|
|
47
|
-
/**
|
|
48
|
-
* Registers a route that responds to HTTP GET requests.
|
|
49
|
-
*
|
|
50
|
-
* @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
|
|
51
|
-
* @param definition Either:
|
|
52
|
-
* - An EventHandler function
|
|
53
|
-
* - A tuple: [ControllerClass, methodName]
|
|
54
|
-
* @param name Optional route name (for URL generation or referencing).
|
|
55
|
-
* @param middleware Optional array of middleware functions to execute before the handler.
|
|
56
|
-
*/
|
|
57
|
-
get(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
|
|
58
|
-
/**
|
|
59
|
-
* Registers a route that responds to HTTP POST requests.
|
|
60
|
-
*
|
|
61
|
-
* @param path The URL pattern to match (can include parameters, e.g., '/users').
|
|
62
|
-
* @param definition Either:
|
|
63
|
-
* - An EventHandler function
|
|
64
|
-
* - A tuple: [ControllerClass, methodName]
|
|
65
|
-
* @param name Optional route name (for URL generation or referencing).
|
|
66
|
-
* @param middleware Optional array of middleware functions to execute before the handler.
|
|
67
|
-
*/
|
|
68
|
-
post(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
|
|
69
|
-
/**
|
|
70
|
-
* Registers a route that responds to HTTP PUT requests.
|
|
71
|
-
*
|
|
72
|
-
* @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
|
|
73
|
-
* @param definition Either:
|
|
74
|
-
* - An EventHandler function
|
|
75
|
-
* - A tuple: [ControllerClass, methodName]
|
|
76
|
-
* @param name Optional route name (for URL generation or referencing).
|
|
77
|
-
* @param middleware Optional array of middleware functions to execute before the handler.
|
|
78
|
-
*/
|
|
79
|
-
put(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
|
|
80
|
-
/**
|
|
81
|
-
* Registers a route that responds to HTTP PATCH requests.
|
|
82
|
-
*
|
|
83
|
-
* @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
|
|
84
|
-
* @param definition Either:
|
|
85
|
-
* - An EventHandler function
|
|
86
|
-
* - A tuple: [ControllerClass, methodName]
|
|
87
|
-
* @param name Optional route name (for URL generation or referencing).
|
|
88
|
-
* @param middleware Optional array of middleware functions to execute before the handler.
|
|
89
|
-
*/
|
|
90
|
-
patch(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
|
|
91
|
-
/**
|
|
92
|
-
* Registers a route that responds to HTTP DELETE requests.
|
|
93
|
-
*
|
|
94
|
-
* @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
|
|
95
|
-
* @param definition Either:
|
|
96
|
-
* - An EventHandler function
|
|
97
|
-
* - A tuple: [ControllerClass, methodName]
|
|
98
|
-
* @param name Optional route name (for URL generation or referencing).
|
|
99
|
-
* @param middleware Optional array of middleware functions to execute before the handler.
|
|
100
|
-
*/
|
|
101
|
-
delete(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
|
|
102
|
-
/**
|
|
103
|
-
* API Resource support
|
|
104
|
-
*
|
|
105
|
-
* @param path
|
|
106
|
-
* @param controller
|
|
107
|
-
*/
|
|
108
|
-
apiResource(path: string, Controller: new (app: Application) => IController, middleware?: IMiddleware[]): Omit<this, RouterEnd | 'name'>;
|
|
109
|
-
/**
|
|
110
|
-
* Named route URL generator
|
|
111
|
-
*
|
|
112
|
-
* @param name
|
|
113
|
-
* @param params
|
|
114
|
-
* @returns
|
|
115
|
-
*/
|
|
116
|
-
route(name: string, params?: Record<string, string>): string | undefined;
|
|
117
|
-
/**
|
|
118
|
-
* Grouping
|
|
119
|
-
*
|
|
120
|
-
* @param options
|
|
121
|
-
* @param callback
|
|
122
|
-
*/
|
|
123
|
-
group(options: {
|
|
124
|
-
prefix?: string;
|
|
125
|
-
middleware?: EventHandler[];
|
|
126
|
-
}, callback: (_e: this) => void): this;
|
|
127
|
-
/**
|
|
128
|
-
* Set the name of the current route
|
|
129
|
-
*
|
|
130
|
-
* @param name
|
|
131
|
-
*/
|
|
132
|
-
name(name: string): this;
|
|
133
|
-
/**
|
|
134
|
-
* Registers middleware for a specific path.
|
|
135
|
-
* @param path - The path to apply the middleware.
|
|
136
|
-
* @param handler - The middleware handler.
|
|
137
|
-
* @param opts - Optional middleware options.
|
|
138
|
-
*/
|
|
139
|
-
middleware(path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;
|
|
7
|
+
//#region src/Helpers.d.ts
|
|
8
|
+
declare class Helpers {
|
|
9
|
+
/**
|
|
10
|
+
* Extracts parameter names from a route path string.
|
|
11
|
+
*
|
|
12
|
+
* - Looks for segments prefixed with ":" (e.g. "/users/:id")
|
|
13
|
+
* - Captures only the param name (without the ":")
|
|
14
|
+
* - Returns all matches in order of appearance
|
|
15
|
+
*
|
|
16
|
+
* @param path - The route path string (e.g. "/groups/:group/users/:user")
|
|
17
|
+
* @returns An array of parameter names (e.g. ["group", "user"])
|
|
18
|
+
*/
|
|
19
|
+
static extractParams(path: string): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Resolves route model binding for a given path, HTTP context, and model.
|
|
22
|
+
*
|
|
23
|
+
* - Extracts all route parameters from the given path
|
|
24
|
+
* - If a parameter matches the model name, it attempts to resolve the model binding
|
|
25
|
+
* using the provided value and binding field (defaults to "id" unless specified).
|
|
26
|
+
* - For non-matching parameters, it simply returns the key-value pair as is.
|
|
27
|
+
* - If no parameters are found, returns an empty object.
|
|
28
|
+
*
|
|
29
|
+
* @param path - The route path (e.g. "/groups/:group/users/:user")
|
|
30
|
+
* @param ctx - The HTTP context containing the request
|
|
31
|
+
* @param model - The model instance to resolve bindings against
|
|
32
|
+
* @returns A resolved model instance or an object containing param values
|
|
33
|
+
*/
|
|
34
|
+
static resolveRouteModelBinding(path: string, ctx: HttpContext, model: Model): Promise<any>;
|
|
140
35
|
}
|
|
141
|
-
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/Providers/AssetsServiceProvider.d.ts
|
|
142
38
|
/**
|
|
143
39
|
* Handles public assets loading
|
|
144
40
|
*
|
|
145
41
|
* Auto-Registered
|
|
146
42
|
*/
|
|
147
43
|
declare class AssetsServiceProvider extends ServiceProvider {
|
|
148
|
-
|
|
149
|
-
|
|
44
|
+
static priority: number;
|
|
45
|
+
register(): void;
|
|
150
46
|
}
|
|
151
|
-
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/Providers/RouteServiceProvider.d.ts
|
|
152
49
|
/**
|
|
153
50
|
* Handles routing registration
|
|
154
51
|
*
|
|
@@ -159,12 +56,151 @@ declare class AssetsServiceProvider extends ServiceProvider {
|
|
|
159
56
|
* Auto-Registered
|
|
160
57
|
*/
|
|
161
58
|
declare class RouteServiceProvider extends ServiceProvider {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
59
|
+
static priority: number;
|
|
60
|
+
register(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Load routes from src/routes
|
|
63
|
+
*/
|
|
64
|
+
boot(): Promise<void>;
|
|
168
65
|
}
|
|
169
|
-
|
|
170
|
-
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/Route.d.ts
|
|
68
|
+
declare class Router implements IRouter {
|
|
69
|
+
protected h3App: H3;
|
|
70
|
+
private app;
|
|
71
|
+
private routes;
|
|
72
|
+
private nameMap;
|
|
73
|
+
private groupPrefix;
|
|
74
|
+
private middlewareMap;
|
|
75
|
+
private groupMiddleware;
|
|
76
|
+
constructor(h3App: H3, app: Application);
|
|
77
|
+
/**
|
|
78
|
+
* Route Resolver
|
|
79
|
+
*
|
|
80
|
+
* @param handler
|
|
81
|
+
* @param middleware
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
private resolveHandler;
|
|
85
|
+
/**
|
|
86
|
+
* Add a route to the stack
|
|
87
|
+
*
|
|
88
|
+
* @param method
|
|
89
|
+
* @param path
|
|
90
|
+
* @param handler
|
|
91
|
+
* @param name
|
|
92
|
+
* @param middleware
|
|
93
|
+
*/
|
|
94
|
+
private addRoute;
|
|
95
|
+
/**
|
|
96
|
+
* Resolves a route handler definition into an executable EventHandler.
|
|
97
|
+
*
|
|
98
|
+
* A handler can be:
|
|
99
|
+
* - A function matching the EventHandler signature
|
|
100
|
+
* - A controller class (optionally decorated for IoC resolution)
|
|
101
|
+
*
|
|
102
|
+
* If it’s a controller class, this method will:
|
|
103
|
+
* - Instantiate it (via IoC or manually)
|
|
104
|
+
* - Call the specified method (defaults to `index`)
|
|
105
|
+
*
|
|
106
|
+
* @param handler Event handler function OR controller class
|
|
107
|
+
* @param methodName Method to invoke on the controller (defaults to 'index')
|
|
108
|
+
*/
|
|
109
|
+
private resolveControllerOrHandler;
|
|
110
|
+
/**
|
|
111
|
+
* Registers a route that responds to HTTP GET requests.
|
|
112
|
+
*
|
|
113
|
+
* @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
|
|
114
|
+
* @param definition Either:
|
|
115
|
+
* - An EventHandler function
|
|
116
|
+
* - A tuple: [ControllerClass, methodName]
|
|
117
|
+
* @param name Optional route name (for URL generation or referencing).
|
|
118
|
+
* @param middleware Optional array of middleware functions to execute before the handler.
|
|
119
|
+
*/
|
|
120
|
+
get(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
|
|
121
|
+
/**
|
|
122
|
+
* Registers a route that responds to HTTP POST requests.
|
|
123
|
+
*
|
|
124
|
+
* @param path The URL pattern to match (can include parameters, e.g., '/users').
|
|
125
|
+
* @param definition Either:
|
|
126
|
+
* - An EventHandler function
|
|
127
|
+
* - A tuple: [ControllerClass, methodName]
|
|
128
|
+
* @param name Optional route name (for URL generation or referencing).
|
|
129
|
+
* @param middleware Optional array of middleware functions to execute before the handler.
|
|
130
|
+
*/
|
|
131
|
+
post(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
|
|
132
|
+
/**
|
|
133
|
+
* Registers a route that responds to HTTP PUT requests.
|
|
134
|
+
*
|
|
135
|
+
* @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
|
|
136
|
+
* @param definition Either:
|
|
137
|
+
* - An EventHandler function
|
|
138
|
+
* - A tuple: [ControllerClass, methodName]
|
|
139
|
+
* @param name Optional route name (for URL generation or referencing).
|
|
140
|
+
* @param middleware Optional array of middleware functions to execute before the handler.
|
|
141
|
+
*/
|
|
142
|
+
put(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
|
|
143
|
+
/**
|
|
144
|
+
* Registers a route that responds to HTTP PATCH requests.
|
|
145
|
+
*
|
|
146
|
+
* @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
|
|
147
|
+
* @param definition Either:
|
|
148
|
+
* - An EventHandler function
|
|
149
|
+
* - A tuple: [ControllerClass, methodName]
|
|
150
|
+
* @param name Optional route name (for URL generation or referencing).
|
|
151
|
+
* @param middleware Optional array of middleware functions to execute before the handler.
|
|
152
|
+
*/
|
|
153
|
+
patch(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
|
|
154
|
+
/**
|
|
155
|
+
* Registers a route that responds to HTTP DELETE requests.
|
|
156
|
+
*
|
|
157
|
+
* @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
|
|
158
|
+
* @param definition Either:
|
|
159
|
+
* - An EventHandler function
|
|
160
|
+
* - A tuple: [ControllerClass, methodName]
|
|
161
|
+
* @param name Optional route name (for URL generation or referencing).
|
|
162
|
+
* @param middleware Optional array of middleware functions to execute before the handler.
|
|
163
|
+
*/
|
|
164
|
+
delete(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
|
|
165
|
+
/**
|
|
166
|
+
* API Resource support
|
|
167
|
+
*
|
|
168
|
+
* @param path
|
|
169
|
+
* @param controller
|
|
170
|
+
*/
|
|
171
|
+
apiResource(path: string, Controller: new (app: Application) => IController, middleware?: IMiddleware[]): Omit<this, RouterEnd | 'name'>;
|
|
172
|
+
/**
|
|
173
|
+
* Named route URL generator
|
|
174
|
+
*
|
|
175
|
+
* @param name
|
|
176
|
+
* @param params
|
|
177
|
+
* @returns
|
|
178
|
+
*/
|
|
179
|
+
route(name: string, params?: Record<string, string>): string | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* Grouping
|
|
182
|
+
*
|
|
183
|
+
* @param options
|
|
184
|
+
* @param callback
|
|
185
|
+
*/
|
|
186
|
+
group(options: {
|
|
187
|
+
prefix?: string;
|
|
188
|
+
middleware?: EventHandler[];
|
|
189
|
+
}, callback: (_e: this) => void): this;
|
|
190
|
+
/**
|
|
191
|
+
* Set the name of the current route
|
|
192
|
+
*
|
|
193
|
+
* @param name
|
|
194
|
+
*/
|
|
195
|
+
name(name: string): this;
|
|
196
|
+
/**
|
|
197
|
+
* Registers middleware for a specific path.
|
|
198
|
+
* @param path - The path to apply the middleware.
|
|
199
|
+
* @param handler - The middleware handler.
|
|
200
|
+
* @param opts - Optional middleware options.
|
|
201
|
+
*/
|
|
202
|
+
middleware(path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;
|
|
203
|
+
}
|
|
204
|
+
//#endregion
|
|
205
|
+
export { AssetsServiceProvider, Helpers, RouteServiceProvider, Router };
|
|
206
|
+
//# sourceMappingURL=index.d.ts.map
|