@h3ravel/router 1.8.3 → 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.ts CHANGED
@@ -1,17 +1,51 @@
1
- import { ServiceProvider, Application } from '@h3ravel/core';
2
- import { H3, Middleware, MiddlewareOptions } from 'h3';
3
- import { IRouter, RouteEventHandler, IMiddleware, RouterEnd, IController, EventHandler } from '@h3ravel/shared';
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
 
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>;
35
+ }
36
+ //#endregion
37
+ //#region src/Providers/AssetsServiceProvider.d.ts
5
38
  /**
6
39
  * Handles public assets loading
7
40
  *
8
41
  * Auto-Registered
9
42
  */
10
43
  declare class AssetsServiceProvider extends ServiceProvider {
11
- static priority: number;
12
- register(): void;
44
+ static priority: number;
45
+ register(): void;
13
46
  }
14
-
47
+ //#endregion
48
+ //#region src/Providers/RouteServiceProvider.d.ts
15
49
  /**
16
50
  * Handles routing registration
17
51
  *
@@ -22,149 +56,151 @@ declare class AssetsServiceProvider extends ServiceProvider {
22
56
  * Auto-Registered
23
57
  */
24
58
  declare class RouteServiceProvider extends ServiceProvider {
25
- static priority: number;
26
- register(): void;
27
- /**
28
- * Load routes from src/routes
29
- */
30
- boot(): Promise<void>;
59
+ static priority: number;
60
+ register(): void;
61
+ /**
62
+ * Load routes from src/routes
63
+ */
64
+ boot(): Promise<void>;
31
65
  }
32
-
66
+ //#endregion
67
+ //#region src/Route.d.ts
33
68
  declare class Router implements IRouter {
34
- protected h3App: H3;
35
- private app;
36
- private routes;
37
- private nameMap;
38
- private groupPrefix;
39
- private middlewareMap;
40
- private groupMiddleware;
41
- constructor(h3App: H3, app: Application);
42
- /**
43
- * Route Resolver
44
- *
45
- * @param handler
46
- * @param middleware
47
- * @returns
48
- */
49
- private resolveHandler;
50
- /**
51
- * Add a route to the stack
52
- *
53
- * @param method
54
- * @param path
55
- * @param handler
56
- * @param name
57
- * @param middleware
58
- */
59
- private addRoute;
60
- /**
61
- * Resolves a route handler definition into an executable EventHandler.
62
- *
63
- * A handler can be:
64
- * - A function matching the EventHandler signature
65
- * - A controller class (optionally decorated for IoC resolution)
66
- *
67
- * If it’s a controller class, this method will:
68
- * - Instantiate it (via IoC or manually)
69
- * - Call the specified method (defaults to `index`)
70
- *
71
- * @param handler Event handler function OR controller class
72
- * @param methodName Method to invoke on the controller (defaults to 'index')
73
- */
74
- private resolveControllerOrHandler;
75
- /**
76
- * Registers a route that responds to HTTP GET requests.
77
- *
78
- * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
79
- * @param definition Either:
80
- * - An EventHandler function
81
- * - A tuple: [ControllerClass, methodName]
82
- * @param name Optional route name (for URL generation or referencing).
83
- * @param middleware Optional array of middleware functions to execute before the handler.
84
- */
85
- get(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
86
- /**
87
- * Registers a route that responds to HTTP POST requests.
88
- *
89
- * @param path The URL pattern to match (can include parameters, e.g., '/users').
90
- * @param definition Either:
91
- * - An EventHandler function
92
- * - A tuple: [ControllerClass, methodName]
93
- * @param name Optional route name (for URL generation or referencing).
94
- * @param middleware Optional array of middleware functions to execute before the handler.
95
- */
96
- post(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
97
- /**
98
- * Registers a route that responds to HTTP PUT requests.
99
- *
100
- * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
101
- * @param definition Either:
102
- * - An EventHandler function
103
- * - A tuple: [ControllerClass, methodName]
104
- * @param name Optional route name (for URL generation or referencing).
105
- * @param middleware Optional array of middleware functions to execute before the handler.
106
- */
107
- put(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
108
- /**
109
- * Registers a route that responds to HTTP PATCH requests.
110
- *
111
- * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
112
- * @param definition Either:
113
- * - An EventHandler function
114
- * - A tuple: [ControllerClass, methodName]
115
- * @param name Optional route name (for URL generation or referencing).
116
- * @param middleware Optional array of middleware functions to execute before the handler.
117
- */
118
- patch(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
119
- /**
120
- * Registers a route that responds to HTTP DELETE requests.
121
- *
122
- * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
123
- * @param definition Either:
124
- * - An EventHandler function
125
- * - A tuple: [ControllerClass, methodName]
126
- * @param name Optional route name (for URL generation or referencing).
127
- * @param middleware Optional array of middleware functions to execute before the handler.
128
- */
129
- delete(path: string, definition: RouteEventHandler | [(new (...args: any[]) => Record<string, any>), methodName: string], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
130
- /**
131
- * API Resource support
132
- *
133
- * @param path
134
- * @param controller
135
- */
136
- apiResource(path: string, Controller: new (app: Application) => IController, middleware?: IMiddleware[]): Omit<this, RouterEnd | 'name'>;
137
- /**
138
- * Named route URL generator
139
- *
140
- * @param name
141
- * @param params
142
- * @returns
143
- */
144
- route(name: string, params?: Record<string, string>): string | undefined;
145
- /**
146
- * Grouping
147
- *
148
- * @param options
149
- * @param callback
150
- */
151
- group(options: {
152
- prefix?: string;
153
- middleware?: EventHandler[];
154
- }, callback: (_e: this) => void): this;
155
- /**
156
- * Set the name of the current route
157
- *
158
- * @param name
159
- */
160
- name(name: string): this;
161
- /**
162
- * Registers middleware for a specific path.
163
- * @param path - The path to apply the middleware.
164
- * @param handler - The middleware handler.
165
- * @param opts - Optional middleware options.
166
- */
167
- middleware(path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;
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;
168
203
  }
169
-
170
- export { AssetsServiceProvider, RouteServiceProvider, Router };
204
+ //#endregion
205
+ export { AssetsServiceProvider, Helpers, RouteServiceProvider, Router };
206
+ //# sourceMappingURL=index.d.ts.map