clear-router 2.1.4 → 2.1.6

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.
@@ -30,11 +30,19 @@ var Route = class {
30
30
  path;
31
31
  handler;
32
32
  middlewares;
33
+ controllerName;
34
+ actionName;
35
+ handlerType;
36
+ middlewareCount;
33
37
  constructor(methods, path, handler, middlewares = []) {
34
38
  this.methods = methods;
35
39
  this.path = path;
36
40
  this.handler = handler;
37
41
  this.middlewares = middlewares;
42
+ this.handlerType = Array.isArray(handler) ? "controller" : "function";
43
+ this.middlewareCount = middlewares.length;
44
+ this.controllerName = Array.isArray(handler) ? handler[0]?.name : void 0;
45
+ this.actionName = Array.isArray(handler) ? handler[1] : typeof handler === "function" ? handler.constructor.name ?? handler.name : void 0;
38
46
  }
39
47
  };
40
48
 
@@ -31,11 +31,19 @@ var Route = class {
31
31
  path;
32
32
  handler;
33
33
  middlewares;
34
+ controllerName;
35
+ actionName;
36
+ handlerType;
37
+ middlewareCount;
34
38
  constructor(methods, path, handler, middlewares = []) {
35
39
  this.methods = methods;
36
40
  this.path = path;
37
41
  this.handler = handler;
38
42
  this.middlewares = middlewares;
43
+ this.handlerType = Array.isArray(handler) ? "controller" : "function";
44
+ this.middlewareCount = middlewares.length;
45
+ this.controllerName = Array.isArray(handler) ? handler[0]?.name : void 0;
46
+ this.actionName = Array.isArray(handler) ? handler[1] : typeof handler === "function" ? handler.constructor.name ?? handler.name : void 0;
39
47
  }
40
48
  };
41
49
 
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_Route = require('../Route-97p-tEbS.cjs');
2
+ const require_Route = require('../Route-DhC4kNPX.cjs');
3
3
 
4
4
  //#region src/express/router.ts
5
5
  /**
@@ -160,15 +160,18 @@ var Router = class Router {
160
160
  * @param callback - Function containing route definitions
161
161
  * @param middlewares - Middleware functions applied to all routes in group
162
162
  */
163
- static group(prefix, callback, middlewares) {
163
+ static async group(prefix, callback, middlewares) {
164
164
  const previousPrefix = this.prefix;
165
165
  const previousMiddlewares = this.groupMiddlewares;
166
166
  const fullPrefix = [previousPrefix, prefix].filter(Boolean).join("/");
167
167
  this.prefix = this.normalizePath(fullPrefix);
168
168
  this.groupMiddlewares = [...previousMiddlewares, ...middlewares || []];
169
- callback();
170
- this.prefix = previousPrefix;
171
- this.groupMiddlewares = previousMiddlewares;
169
+ try {
170
+ await Promise.resolve(callback());
171
+ } finally {
172
+ this.prefix = previousPrefix;
173
+ this.groupMiddlewares = previousMiddlewares;
174
+ }
172
175
  }
173
176
  /**
174
177
  * Apply global middlewares for the duration of the callback
@@ -186,12 +189,7 @@ var Router = class Router {
186
189
  * @returns Array of route information objects
187
190
  */
188
191
  static allRoutes() {
189
- return this.routes.map((route) => ({
190
- methods: route.methods,
191
- path: route.path,
192
- middlewareCount: route.middlewares.length,
193
- handlerType: typeof route.handler === "function" ? "function" : "controller"
194
- }));
192
+ return this.routes;
195
193
  }
196
194
  static async apply(router) {
197
195
  for (const route of this.routes) {
@@ -1,4 +1,4 @@
1
- import { d as RouteInfo, i as Route, l as ControllerAction, n as HttpContext, r as Middleware, t as Handler, u as HttpMethod } from "../express-sjYra4oE.cjs";
1
+ import { i as Route, l as ControllerAction, n as HttpContext, r as Middleware, t as Handler, u as HttpMethod } from "../express-JHxK-EqQ.cjs";
2
2
  import { Router as Router$1 } from "express";
3
3
 
4
4
  //#region src/express/router.d.ts
@@ -106,7 +106,7 @@ declare class Router {
106
106
  * @param callback - Function containing route definitions
107
107
  * @param middlewares - Middleware functions applied to all routes in group
108
108
  */
109
- static group(prefix: string, callback: () => void, middlewares?: Middleware[]): void;
109
+ static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
110
110
  /**
111
111
  * Apply global middlewares for the duration of the callback
112
112
  * @param middlewares - Middleware functions
@@ -117,7 +117,7 @@ declare class Router {
117
117
  * Get all registered routes with their information
118
118
  * @returns Array of route information objects
119
119
  */
120
- static allRoutes(): RouteInfo[];
120
+ static allRoutes(): Route<HttpContext, Middleware>[];
121
121
  /**
122
122
  * Apply all registered routes to the provided Express Router instance
123
123
  * Handles controller-method binding and middleware application
@@ -1,4 +1,4 @@
1
- import { d as RouteInfo, i as Route, l as ControllerAction, n as HttpContext, r as Middleware, t as Handler, u as HttpMethod } from "../express-WiUTZlHA.mjs";
1
+ import { i as Route, l as ControllerAction, n as HttpContext, r as Middleware, t as Handler, u as HttpMethod } from "../express-D9GR9yTH.mjs";
2
2
  import { Router as Router$1 } from "express";
3
3
 
4
4
  //#region src/express/router.d.ts
@@ -106,7 +106,7 @@ declare class Router {
106
106
  * @param callback - Function containing route definitions
107
107
  * @param middlewares - Middleware functions applied to all routes in group
108
108
  */
109
- static group(prefix: string, callback: () => void, middlewares?: Middleware[]): void;
109
+ static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
110
110
  /**
111
111
  * Apply global middlewares for the duration of the callback
112
112
  * @param middlewares - Middleware functions
@@ -117,7 +117,7 @@ declare class Router {
117
117
  * Get all registered routes with their information
118
118
  * @returns Array of route information objects
119
119
  */
120
- static allRoutes(): RouteInfo[];
120
+ static allRoutes(): Route<HttpContext, Middleware>[];
121
121
  /**
122
122
  * Apply all registered routes to the provided Express Router instance
123
123
  * Handles controller-method binding and middleware application
@@ -1,4 +1,4 @@
1
- import { n as ClearRequest, t as Route } from "../Route-BtmoiYq5.mjs";
1
+ import { n as ClearRequest, t as Route } from "../Route-BbPXcDGX.mjs";
2
2
 
3
3
  //#region src/express/router.ts
4
4
  /**
@@ -159,15 +159,18 @@ var Router = class Router {
159
159
  * @param callback - Function containing route definitions
160
160
  * @param middlewares - Middleware functions applied to all routes in group
161
161
  */
162
- static group(prefix, callback, middlewares) {
162
+ static async group(prefix, callback, middlewares) {
163
163
  const previousPrefix = this.prefix;
164
164
  const previousMiddlewares = this.groupMiddlewares;
165
165
  const fullPrefix = [previousPrefix, prefix].filter(Boolean).join("/");
166
166
  this.prefix = this.normalizePath(fullPrefix);
167
167
  this.groupMiddlewares = [...previousMiddlewares, ...middlewares || []];
168
- callback();
169
- this.prefix = previousPrefix;
170
- this.groupMiddlewares = previousMiddlewares;
168
+ try {
169
+ await Promise.resolve(callback());
170
+ } finally {
171
+ this.prefix = previousPrefix;
172
+ this.groupMiddlewares = previousMiddlewares;
173
+ }
171
174
  }
172
175
  /**
173
176
  * Apply global middlewares for the duration of the callback
@@ -185,12 +188,7 @@ var Router = class Router {
185
188
  * @returns Array of route information objects
186
189
  */
187
190
  static allRoutes() {
188
- return this.routes.map((route) => ({
189
- methods: route.methods,
190
- path: route.path,
191
- middlewareCount: route.middlewares.length,
192
- handlerType: typeof route.handler === "function" ? "function" : "controller"
193
- }));
191
+ return this.routes;
194
192
  }
195
193
  static async apply(router) {
196
194
  for (const route of this.routes) {
@@ -10,15 +10,6 @@ type ControllerHandler = [any, string];
10
10
  * HTTP methods supported by the router
11
11
  */
12
12
  type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
13
- /**
14
- * Route information object
15
- */
16
- interface RouteInfo {
17
- methods: HttpMethod[];
18
- path: string;
19
- middlewareCount: number;
20
- handlerType: 'function' | 'controller';
21
- }
22
13
  /**
23
14
  * Common controller action names
24
15
  */
@@ -66,6 +57,10 @@ declare class Route<X = any, M = Middleware$1 | Middleware> {
66
57
  path: string;
67
58
  handler: Handler$1;
68
59
  middlewares: M[];
60
+ controllerName?: string;
61
+ actionName?: string;
62
+ handlerType: 'function' | 'controller';
63
+ middlewareCount: number;
69
64
  constructor(methods: HttpMethod[], path: string, handler: Handler$1, middlewares?: M[]);
70
65
  }
71
66
  //#endregion
@@ -120,4 +115,4 @@ type Handler = RouteHandler | ControllerHandler;
120
115
  */
121
116
  type Middleware = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
122
117
  //#endregion
123
- export { H3App as a, Middleware$1 as c, RouteInfo as d, Route as i, ControllerAction as l, HttpContext as n, Handler$1 as o, Middleware as r, HttpContext$1 as s, Handler as t, HttpMethod as u };
118
+ export { H3App as a, Middleware$1 as c, Route as i, ControllerAction as l, HttpContext as n, Handler$1 as o, Middleware as r, HttpContext$1 as s, Handler as t, HttpMethod as u };
@@ -10,15 +10,6 @@ type ControllerHandler = [any, string];
10
10
  * HTTP methods supported by the router
11
11
  */
12
12
  type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
13
- /**
14
- * Route information object
15
- */
16
- interface RouteInfo {
17
- methods: HttpMethod[];
18
- path: string;
19
- middlewareCount: number;
20
- handlerType: 'function' | 'controller';
21
- }
22
13
  /**
23
14
  * Common controller action names
24
15
  */
@@ -66,6 +57,10 @@ declare class Route<X = any, M = Middleware$1 | Middleware> {
66
57
  path: string;
67
58
  handler: Handler$1;
68
59
  middlewares: M[];
60
+ controllerName?: string;
61
+ actionName?: string;
62
+ handlerType: 'function' | 'controller';
63
+ middlewareCount: number;
69
64
  constructor(methods: HttpMethod[], path: string, handler: Handler$1, middlewares?: M[]);
70
65
  }
71
66
  //#endregion
@@ -120,4 +115,4 @@ type Handler = RouteHandler | ControllerHandler;
120
115
  */
121
116
  type Middleware = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
122
117
  //#endregion
123
- export { H3App as a, Middleware$1 as c, RouteInfo as d, Route as i, ControllerAction as l, HttpContext as n, Handler$1 as o, Middleware as r, HttpContext$1 as s, Handler as t, HttpMethod as u };
118
+ export { H3App as a, Middleware$1 as c, Route as i, ControllerAction as l, HttpContext as n, Handler$1 as o, Middleware as r, HttpContext$1 as s, Handler as t, HttpMethod as u };
package/dist/h3/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_Route = require('../Route-97p-tEbS.cjs');
2
+ const require_Route = require('../Route-DhC4kNPX.cjs');
3
3
  let h3 = require("h3");
4
4
 
5
5
  //#region src/h3/router.ts
@@ -160,15 +160,18 @@ var Router = class Router {
160
160
  * @param callback - Function containing route definitions
161
161
  * @param middlewares - Middleware functions applied to all routes in group
162
162
  */
163
- static group(prefix, callback, middlewares) {
163
+ static async group(prefix, callback, middlewares) {
164
164
  const previousPrefix = this.prefix;
165
165
  const previousMiddlewares = this.groupMiddlewares;
166
166
  const fullPrefix = [previousPrefix, prefix].filter(Boolean).join("/");
167
167
  this.prefix = this.normalizePath(fullPrefix);
168
168
  this.groupMiddlewares = [...previousMiddlewares, ...middlewares || []];
169
- callback();
170
- this.prefix = previousPrefix;
171
- this.groupMiddlewares = previousMiddlewares;
169
+ try {
170
+ await Promise.resolve(callback());
171
+ } finally {
172
+ this.prefix = previousPrefix;
173
+ this.groupMiddlewares = previousMiddlewares;
174
+ }
172
175
  }
173
176
  /**
174
177
  * Apply global middlewares for the duration of the callback
@@ -186,12 +189,7 @@ var Router = class Router {
186
189
  * @returns Array of route information objects
187
190
  */
188
191
  static allRoutes() {
189
- return this.routes.map((route) => ({
190
- methods: route.methods,
191
- path: route.path,
192
- middlewareCount: route.middlewares.length,
193
- handlerType: typeof route.handler === "function" ? "function" : "controller"
194
- }));
192
+ return this.routes;
195
193
  }
196
194
  /**
197
195
  * Apply all registered routes to the provided H3 Router instance
@@ -1,4 +1,5 @@
1
- import { a as H3App, c as Middleware, d as RouteInfo, i as Route, l as ControllerAction, o as Handler, s as HttpContext, u as HttpMethod } from "../express-sjYra4oE.cjs";
1
+ import { a as H3App, c as Middleware, i as Route, l as ControllerAction, o as Handler, s as HttpContext, u as HttpMethod } from "../express-JHxK-EqQ.cjs";
2
+ import * as h3 from "h3";
2
3
  import { H3 } from "h3";
3
4
 
4
5
  //#region src/h3/router.d.ts
@@ -105,7 +106,7 @@ declare class Router {
105
106
  * @param callback - Function containing route definitions
106
107
  * @param middlewares - Middleware functions applied to all routes in group
107
108
  */
108
- static group(prefix: string, callback: () => void, middlewares?: Middleware[]): void;
109
+ static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
109
110
  /**
110
111
  * Apply global middlewares for the duration of the callback
111
112
  * @param middlewares - Middleware functions
@@ -116,7 +117,7 @@ declare class Router {
116
117
  * Get all registered routes with their information
117
118
  * @returns Array of route information objects
118
119
  */
119
- static allRoutes(): RouteInfo[];
120
+ static allRoutes(): Route<h3.H3Event<h3.EventHandlerRequest>, Middleware>[];
120
121
  /**
121
122
  * Apply all registered routes to the provided H3 Router instance
122
123
  * Handles controller-method binding and middleware application
@@ -1,4 +1,5 @@
1
- import { a as H3App, c as Middleware, d as RouteInfo, i as Route, l as ControllerAction, o as Handler, s as HttpContext, u as HttpMethod } from "../express-WiUTZlHA.mjs";
1
+ import { a as H3App, c as Middleware, i as Route, l as ControllerAction, o as Handler, s as HttpContext, u as HttpMethod } from "../express-D9GR9yTH.mjs";
2
+ import * as h3 from "h3";
2
3
  import { H3 } from "h3";
3
4
 
4
5
  //#region src/h3/router.d.ts
@@ -105,7 +106,7 @@ declare class Router {
105
106
  * @param callback - Function containing route definitions
106
107
  * @param middlewares - Middleware functions applied to all routes in group
107
108
  */
108
- static group(prefix: string, callback: () => void, middlewares?: Middleware[]): void;
109
+ static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
109
110
  /**
110
111
  * Apply global middlewares for the duration of the callback
111
112
  * @param middlewares - Middleware functions
@@ -116,7 +117,7 @@ declare class Router {
116
117
  * Get all registered routes with their information
117
118
  * @returns Array of route information objects
118
119
  */
119
- static allRoutes(): RouteInfo[];
120
+ static allRoutes(): Route<h3.H3Event<h3.EventHandlerRequest>, Middleware>[];
120
121
  /**
121
122
  * Apply all registered routes to the provided H3 Router instance
122
123
  * Handles controller-method binding and middleware application
package/dist/h3/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as ClearRequest, t as Route } from "../Route-BtmoiYq5.mjs";
1
+ import { n as ClearRequest, t as Route } from "../Route-BbPXcDGX.mjs";
2
2
  import { getQuery, getRouterParams, readBody } from "h3";
3
3
 
4
4
  //#region src/h3/router.ts
@@ -159,15 +159,18 @@ var Router = class Router {
159
159
  * @param callback - Function containing route definitions
160
160
  * @param middlewares - Middleware functions applied to all routes in group
161
161
  */
162
- static group(prefix, callback, middlewares) {
162
+ static async group(prefix, callback, middlewares) {
163
163
  const previousPrefix = this.prefix;
164
164
  const previousMiddlewares = this.groupMiddlewares;
165
165
  const fullPrefix = [previousPrefix, prefix].filter(Boolean).join("/");
166
166
  this.prefix = this.normalizePath(fullPrefix);
167
167
  this.groupMiddlewares = [...previousMiddlewares, ...middlewares || []];
168
- callback();
169
- this.prefix = previousPrefix;
170
- this.groupMiddlewares = previousMiddlewares;
168
+ try {
169
+ await Promise.resolve(callback());
170
+ } finally {
171
+ this.prefix = previousPrefix;
172
+ this.groupMiddlewares = previousMiddlewares;
173
+ }
171
174
  }
172
175
  /**
173
176
  * Apply global middlewares for the duration of the callback
@@ -185,12 +188,7 @@ var Router = class Router {
185
188
  * @returns Array of route information objects
186
189
  */
187
190
  static allRoutes() {
188
- return this.routes.map((route) => ({
189
- methods: route.methods,
190
- path: route.path,
191
- middlewareCount: route.middlewares.length,
192
- handlerType: typeof route.handler === "function" ? "function" : "controller"
193
- }));
191
+ return this.routes;
194
192
  }
195
193
  /**
196
194
  * Apply all registered routes to the provided H3 Router instance
package/dist/index.cjs CHANGED
@@ -42,11 +42,19 @@ var Route = class {
42
42
  path;
43
43
  handler;
44
44
  middlewares;
45
+ controllerName;
46
+ actionName;
47
+ handlerType;
48
+ middlewareCount;
45
49
  constructor(methods, path, handler, middlewares = []) {
46
50
  this.methods = methods;
47
51
  this.path = path;
48
52
  this.handler = handler;
49
53
  this.middlewares = middlewares;
54
+ this.handlerType = Array.isArray(handler) ? "controller" : "function";
55
+ this.middlewareCount = middlewares.length;
56
+ this.controllerName = Array.isArray(handler) ? handler[0]?.name : void 0;
57
+ this.actionName = Array.isArray(handler) ? handler[1] : typeof handler === "function" ? handler.constructor.name ?? handler.name : void 0;
50
58
  }
51
59
  };
52
60
 
package/dist/index.d.cts CHANGED
@@ -56,6 +56,10 @@ declare class Route<X = any, M = Middleware | Middleware$1> {
56
56
  path: string;
57
57
  handler: Handler;
58
58
  middlewares: M[];
59
+ controllerName?: string;
60
+ actionName?: string;
61
+ handlerType: 'function' | 'controller';
62
+ middlewareCount: number;
59
63
  constructor(methods: HttpMethod[], path: string, handler: Handler, middlewares?: M[]);
60
64
  }
61
65
  //#endregion
package/dist/index.d.mts CHANGED
@@ -56,6 +56,10 @@ declare class Route<X = any, M = Middleware | Middleware$1> {
56
56
  path: string;
57
57
  handler: Handler;
58
58
  middlewares: M[];
59
+ controllerName?: string;
60
+ actionName?: string;
61
+ handlerType: 'function' | 'controller';
62
+ middlewareCount: number;
59
63
  constructor(methods: HttpMethod[], path: string, handler: Handler, middlewares?: M[]);
60
64
  }
61
65
  //#endregion
package/dist/index.mjs CHANGED
@@ -40,11 +40,19 @@ var Route = class {
40
40
  path;
41
41
  handler;
42
42
  middlewares;
43
+ controllerName;
44
+ actionName;
45
+ handlerType;
46
+ middlewareCount;
43
47
  constructor(methods, path, handler, middlewares = []) {
44
48
  this.methods = methods;
45
49
  this.path = path;
46
50
  this.handler = handler;
47
51
  this.middlewares = middlewares;
52
+ this.handlerType = Array.isArray(handler) ? "controller" : "function";
53
+ this.middlewareCount = middlewares.length;
54
+ this.controllerName = Array.isArray(handler) ? handler[0]?.name : void 0;
55
+ this.actionName = Array.isArray(handler) ? handler[1] : typeof handler === "function" ? handler.constructor.name ?? handler.name : void 0;
48
56
  }
49
57
  };
50
58
 
@@ -14,6 +14,10 @@ declare class Route<X = any, M = Middleware | Middleware$1> {
14
14
  path: string;
15
15
  handler: Handler;
16
16
  middlewares: M[];
17
+ controllerName?: string;
18
+ actionName?: string;
19
+ handlerType: 'function' | 'controller';
20
+ middlewareCount: number;
17
21
  constructor(methods: HttpMethod[], path: string, handler: Handler, middlewares?: M[]);
18
22
  }
19
23
  //#endregion
@@ -7,15 +7,6 @@ type ControllerHandler = [any, string];
7
7
  * HTTP methods supported by the router
8
8
  */
9
9
  type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
10
- /**
11
- * Route information object
12
- */
13
- interface RouteInfo {
14
- methods: HttpMethod[];
15
- path: string;
16
- middlewareCount: number;
17
- handlerType: 'function' | 'controller';
18
- }
19
10
  /**
20
11
  * Common controller action names
21
12
  */
@@ -25,4 +16,4 @@ type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
25
16
  */
26
17
  type RequestData = Record<string, any>;
27
18
  //#endregion
28
- export { ControllerAction, ControllerHandler, HttpMethod, RequestData, RouteInfo };
19
+ export { ControllerAction, ControllerHandler, HttpMethod, RequestData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-router",
3
- "version": "2.1.4",
3
+ "version": "2.1.6",
4
4
  "description": "Laravel-style routing system for Express.js and H3, with CommonJS, ESM, and TypeScript support",
5
5
  "keywords": [
6
6
  "h3",