@h3ravel/router 1.12.1 → 1.12.2

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.cjs CHANGED
@@ -22,26 +22,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
 
23
23
  //#endregion
24
24
  let __h3ravel_shared = require("@h3ravel/shared");
25
- __h3ravel_shared = __toESM(__h3ravel_shared);
26
25
  let __h3ravel_musket = require("@h3ravel/musket");
27
- __h3ravel_musket = __toESM(__h3ravel_musket);
28
26
  let node_fs_promises = require("node:fs/promises");
29
- node_fs_promises = __toESM(node_fs_promises);
30
27
  let __h3ravel_core = require("@h3ravel/core");
31
- __h3ravel_core = __toESM(__h3ravel_core);
32
28
  let __h3ravel_support = require("@h3ravel/support");
33
- __h3ravel_support = __toESM(__h3ravel_support);
34
29
  let node_path = require("node:path");
35
30
  node_path = __toESM(node_path);
36
31
  let h3 = require("h3");
37
- h3 = __toESM(h3);
38
32
  let node_fs = require("node:fs");
39
- node_fs = __toESM(node_fs);
40
33
  require("reflect-metadata");
41
34
  let __h3ravel_http = require("@h3ravel/http");
42
- __h3ravel_http = __toESM(__h3ravel_http);
43
35
  let __h3ravel_database = require("@h3ravel/database");
44
- __h3ravel_database = __toESM(__h3ravel_database);
45
36
 
46
37
  //#region src/Commands/RouteListCommand.ts
47
38
  var RouteListCommand = class extends __h3ravel_musket.Command {
@@ -259,7 +250,13 @@ var Router = class {
259
250
  event$1._h3ravelContext = ctx;
260
251
  return ctx;
261
252
  };
262
- return new __h3ravel_core.Kernel(this.app.context, middleware).handle(event, (ctx) => Promise.resolve(handler(ctx)));
253
+ return new __h3ravel_core.Kernel(this.app.context, middleware).handle(event, (ctx) => new Promise((resolve) => {
254
+ if (__h3ravel_shared.Resolver.isAsyncFunction(handler)) handler(ctx).then((response) => {
255
+ if (response instanceof __h3ravel_http.Response) resolve(response.prepare(ctx.request).send());
256
+ else resolve(response);
257
+ });
258
+ else resolve(handler(ctx));
259
+ }));
263
260
  };
264
261
  }
265
262
  /**
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  /// <reference path="./app.globals.d.ts" />
2
- import { EventHandler, ExtractControllerMethods, HttpContext, IMiddleware, IRouter, RouteEventHandler, RouterEnd } from "@h3ravel/shared";
3
2
  import { Command } from "@h3ravel/musket";
3
+ import { EventHandler, ExtractControllerMethods, HttpContext, IMiddleware, IRouter, RouteEventHandler, RouterEnd } from "@h3ravel/shared";
4
+ import { Model } from "@h3ravel/database";
4
5
  import { Application, ServiceProvider } from "@h3ravel/core";
5
6
  import { H3, Middleware, MiddlewareOptions } from "h3";
6
- import "reflect-metadata";
7
- import { Model } from "@h3ravel/database";
8
7
 
9
8
  //#region src/Commands/RouteListCommand.d.ts
10
9
  declare class RouteListCommand extends Command {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Logger } from "@h3ravel/shared";
1
+ import { Logger, Resolver } from "@h3ravel/shared";
2
2
  import { Command } from "@h3ravel/musket";
3
3
  import { readFile, readdir, stat } from "node:fs/promises";
4
4
  import { Container, Kernel, ServiceProvider } from "@h3ravel/core";
@@ -226,7 +226,13 @@ var Router = class {
226
226
  event$1._h3ravelContext = ctx;
227
227
  return ctx;
228
228
  };
229
- return new Kernel(this.app.context, middleware).handle(event, (ctx) => Promise.resolve(handler(ctx)));
229
+ return new Kernel(this.app.context, middleware).handle(event, (ctx) => new Promise((resolve) => {
230
+ if (Resolver.isAsyncFunction(handler)) handler(ctx).then((response) => {
231
+ if (response instanceof Response) resolve(response.prepare(ctx.request).send());
232
+ else resolve(response);
233
+ });
234
+ else resolve(handler(ctx));
235
+ }));
230
236
  };
231
237
  }
232
238
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/router",
3
- "version": "1.12.1",
3
+ "version": "1.12.2",
4
4
  "description": "Route facade, decorators and controller system for H3ravel.",
5
5
  "h3ravel": {
6
6
  "providers": [
@@ -9,15 +9,15 @@
9
9
  ]
10
10
  },
11
11
  "type": "module",
12
- "main": "./dist/index.js",
12
+ "main": "./dist/index.cjs",
13
13
  "types": "./dist/index.d.ts",
14
14
  "module": "./dist/index.js",
15
15
  "exports": {
16
16
  ".": {
17
- "types": "./dist/index.d.ts",
18
17
  "import": "./dist/index.js",
19
18
  "require": "./dist/index.cjs"
20
- }
19
+ },
20
+ "./*": "./*"
21
21
  },
22
22
  "files": [
23
23
  "dist"
@@ -45,11 +45,11 @@
45
45
  "@h3ravel/musket": "^0.3.1",
46
46
  "h3": "2.0.1-rc.5",
47
47
  "reflect-metadata": "^0.2.2",
48
- "@h3ravel/core": "^1.20.0",
49
- "@h3ravel/shared": "^0.26.0",
50
- "@h3ravel/http": "^11.6.0",
51
- "@h3ravel/support": "^0.14.4",
52
- "@h3ravel/database": "^11.4.4"
48
+ "@h3ravel/core": "^1.20.1",
49
+ "@h3ravel/http": "^11.6.1",
50
+ "@h3ravel/shared": "^0.26.1",
51
+ "@h3ravel/support": "^0.14.5",
52
+ "@h3ravel/database": "^11.4.5"
53
53
  },
54
54
  "scripts": {
55
55
  "barrel": "barrelsby --directory src --delete --singleQuotes",
package/dist/index.d.cts DELETED
@@ -1,244 +0,0 @@
1
- /// <reference path="./app.globals.d.ts" />
2
- import { Command } from "@h3ravel/musket";
3
- import { EventHandler, ExtractControllerMethods, HttpContext, IMiddleware, IRouter, RouteEventHandler, RouterEnd } from "@h3ravel/shared";
4
- import { Model } from "@h3ravel/database";
5
- import { Application, ServiceProvider } from "@h3ravel/core";
6
- import { H3, Middleware, MiddlewareOptions } from "h3";
7
-
8
- //#region src/Commands/RouteListCommand.d.ts
9
- declare class RouteListCommand extends Command {
10
- /**
11
- * The name and signature of the console command.
12
- *
13
- * @var string
14
- */
15
- protected signature: string;
16
- /**
17
- * The console command description.
18
- *
19
- * @var string
20
- */
21
- protected description: string;
22
- /**
23
- * Execute the console command.
24
- */
25
- handle(this: any): Promise<void>;
26
- /**
27
- * List all registered routes.
28
- */
29
- protected list(): Promise<void>;
30
- /**
31
- * Get the color
32
- *
33
- * @param method
34
- * @returns
35
- */
36
- private color;
37
- /**
38
- * Get the alternate method
39
- *
40
- * @param method
41
- * @returns
42
- */
43
- private pair;
44
- }
45
- //#endregion
46
- //#region src/Helpers.d.ts
47
- declare class Helpers {
48
- /**
49
- * Extracts parameter names from a route path string.
50
- *
51
- * - Looks for segments prefixed with ":" (e.g. "/users/:id")
52
- * - Captures only the param name (without the ":")
53
- * - Returns all matches in order of appearance
54
- *
55
- * @param path - The route path string (e.g. "/groups/:group/users/:user")
56
- * @returns An array of parameter names (e.g. ["group", "user"])
57
- */
58
- static extractParams(path: string): string[];
59
- /**
60
- * Resolves route model binding for a given path, HTTP context, and model.
61
- *
62
- * - Extracts all route parameters from the given path
63
- * - If a parameter matches the model name, it attempts to resolve the model binding
64
- * using the provided value and binding field (defaults to "id" unless specified).
65
- * - For non-matching parameters, it simply returns the key-value pair as is.
66
- * - If no parameters are found, returns an empty object.
67
- *
68
- * @param path - The route path (e.g. "/groups/:group/users/:user")
69
- * @param ctx - The HTTP context containing the request
70
- * @param model - The model instance to resolve bindings against
71
- * @returns A resolved model instance or an object containing param values
72
- */
73
- static resolveRouteModelBinding(path: string, ctx: HttpContext, model: Model): Promise<any>;
74
- }
75
- //#endregion
76
- //#region src/Providers/AssetsServiceProvider.d.ts
77
- /**
78
- * Handles public assets loading
79
- *
80
- * Auto-Registered
81
- */
82
- declare class AssetsServiceProvider extends ServiceProvider {
83
- static priority: number;
84
- register(): void;
85
- }
86
- //#endregion
87
- //#region src/Providers/RouteServiceProvider.d.ts
88
- /**
89
- * Handles routing registration
90
- *
91
- * Load route files (web.ts, api.ts).
92
- * Map controllers to routes.
93
- * Register route-related middleware.
94
- *
95
- * Auto-Registered
96
- */
97
- declare class RouteServiceProvider extends ServiceProvider {
98
- static priority: number;
99
- register(): void;
100
- /**
101
- * Load routes from src/routes
102
- */
103
- boot(): Promise<void>;
104
- }
105
- //#endregion
106
- //#region src/Route.d.ts
107
- declare class Router implements IRouter {
108
- protected h3App: H3;
109
- private app;
110
- private routes;
111
- private nameMap;
112
- private groupPrefix;
113
- private middlewareMap;
114
- private groupMiddleware;
115
- constructor(h3App: H3, app: Application);
116
- /**
117
- * Route Resolver
118
- *
119
- * @param handler
120
- * @param middleware
121
- * @returns
122
- */
123
- private resolveHandler;
124
- /**
125
- * Add a route to the stack
126
- *
127
- * @param method
128
- * @param path
129
- * @param handler
130
- * @param name
131
- * @param middleware
132
- */
133
- private addRoute;
134
- /**
135
- * Resolves a route handler definition into an executable EventHandler.
136
- *
137
- * A handler can be:
138
- * - A function matching the EventHandler signature
139
- * - A controller class (optionally decorated for IoC resolution)
140
- *
141
- * If it’s a controller class, this method will:
142
- * - Instantiate it (via IoC or manually)
143
- * - Call the specified method (defaults to `index`)
144
- *
145
- * @param handler Event handler function OR controller class
146
- * @param methodName Method to invoke on the controller (defaults to 'index')
147
- */
148
- private resolveControllerOrHandler;
149
- /**
150
- * Registers a route that responds to HTTP GET requests.
151
- *
152
- * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
153
- * @param definition Either:
154
- * - An EventHandler function
155
- * - A tuple: [ControllerClass, methodName]
156
- * @param name Optional route name (for URL generation or referencing).
157
- * @param middleware Optional array of middleware functions to execute before the handler.
158
- */
159
- get<C extends new (...args: any) => any>(path: string, definition: RouteEventHandler | [C, methodName: ExtractControllerMethods<InstanceType<C>>], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
160
- /**
161
- * Registers a route that responds to HTTP POST requests.
162
- *
163
- * @param path The URL pattern to match (can include parameters, e.g., '/users').
164
- * @param definition Either:
165
- * - An EventHandler function
166
- * - A tuple: [ControllerClass, methodName]
167
- * @param name Optional route name (for URL generation or referencing).
168
- * @param middleware Optional array of middleware functions to execute before the handler.
169
- */
170
- post<C extends new (...args: any) => any>(path: string, definition: RouteEventHandler | [C, methodName: ExtractControllerMethods<InstanceType<C>>], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
171
- /**
172
- * Registers a route that responds to HTTP PUT requests.
173
- *
174
- * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
175
- * @param definition Either:
176
- * - An EventHandler function
177
- * - A tuple: [ControllerClass, methodName]
178
- * @param name Optional route name (for URL generation or referencing).
179
- * @param middleware Optional array of middleware functions to execute before the handler.
180
- */
181
- put<C extends new (...args: any) => any>(path: string, definition: RouteEventHandler | [C, methodName: ExtractControllerMethods<InstanceType<C>>], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
182
- /**
183
- * Registers a route that responds to HTTP PATCH requests.
184
- *
185
- * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
186
- * @param definition Either:
187
- * - An EventHandler function
188
- * - A tuple: [ControllerClass, methodName]
189
- * @param name Optional route name (for URL generation or referencing).
190
- * @param middleware Optional array of middleware functions to execute before the handler.
191
- */
192
- patch<C extends new (...args: any) => any>(path: string, definition: RouteEventHandler | [C, methodName: ExtractControllerMethods<InstanceType<C>>], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
193
- /**
194
- * Registers a route that responds to HTTP DELETE requests.
195
- *
196
- * @param path The URL pattern to match (can include parameters, e.g., '/users/:id').
197
- * @param definition Either:
198
- * - An EventHandler function
199
- * - A tuple: [ControllerClass, methodName]
200
- * @param name Optional route name (for URL generation or referencing).
201
- * @param middleware Optional array of middleware functions to execute before the handler.
202
- */
203
- delete<C extends new (...args: any) => any>(path: string, definition: RouteEventHandler | [C, methodName: ExtractControllerMethods<InstanceType<C>>], name?: string, middleware?: IMiddleware[]): Omit<this, RouterEnd>;
204
- /**
205
- * API Resource support
206
- *
207
- * @param path
208
- * @param controller
209
- */
210
- apiResource<C extends new (...args: any) => any>(path: string, Controller: C, middleware?: IMiddleware[]): Omit<this, RouterEnd | 'name'>;
211
- /**
212
- * Named route URL generator
213
- *
214
- * @param name
215
- * @param params
216
- * @returns
217
- */
218
- route(name: string, params?: Record<string, string>): string | undefined;
219
- /**
220
- * Grouping
221
- *
222
- * @param options
223
- * @param callback
224
- */
225
- group(options: {
226
- prefix?: string;
227
- middleware?: EventHandler[];
228
- }, callback: (_e: this) => void): this;
229
- /**
230
- * Set the name of the current route
231
- *
232
- * @param name
233
- */
234
- name(name: string): this;
235
- /**
236
- * Registers middleware for a specific path.
237
- * @param path - The path to apply the middleware.
238
- * @param handler - The middleware handler.
239
- * @param opts - Optional middleware options.
240
- */
241
- middleware(path: string | IMiddleware[] | Middleware, handler: Middleware | MiddlewareOptions, opts?: MiddlewareOptions): this;
242
- }
243
- //#endregion
244
- export { AssetsServiceProvider, Helpers, RouteListCommand, RouteServiceProvider, Router };