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