@h3ravel/router 1.8.3 → 1.9.1

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