clear-router 2.1.11 → 2.2.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.
@@ -1,69 +1,32 @@
1
- import { a as Handler, c as Route, i as RouterConfig, n as ControllerAction, o as HttpContext, r as HttpMethod, s as Middleware, t as ApiResourceMiddleware } from "../basic-DXbqD6cP.cjs";
1
+ import { a as Handler, c as Route, i as HttpMethod, n as ApiResourceMiddleware, o as HttpContext, r as ControllerAction, s as Middleware, t as CoreRouter } from "../router-CZIh1ZPJ.cjs";
2
2
  import { Router as Router$1 } from "express";
3
3
 
4
4
  //#region src/express/router.d.ts
5
5
  /**
6
- * @class clear-router
6
+ * @class clear-router Express Router
7
7
  * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
8
8
  * @author Refkinscallv
9
9
  * @author 3m1n3nc3
10
10
  * @repository https://github.com/toneflix/clear-router
11
11
  */
12
- declare class Router {
13
- static config: RouterConfig;
14
- private static readonly groupContext;
12
+ declare class Router extends CoreRouter {
13
+ private static ensureRequestBodyAccessor;
15
14
  /**
16
- * All registered routes
17
- */
18
- static routes: Array<Route<HttpContext, Middleware>>;
19
- /**
20
- * Mapping of routes by path and method for quick lookup.
21
- */
22
- static routesByPathMethod: Record<string, Route<HttpContext, Middleware>>;
23
- /**
24
- * Mapping of routes by method for quick lookup.
25
- */
26
- static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware>> };
27
- /**
28
- * Current route prefix
29
- */
30
- static prefix: string;
31
- /**
32
- * Group-level middlewares
33
- */
34
- static groupMiddlewares: Middleware[];
35
- /**
36
- * Global-level middlewares
37
- */
38
- static globalMiddlewares: Middleware[];
39
- /**
40
- * Normalize path by removing duplicate slashes and ensuring leading slash
41
- * @param path - Path to normalize
42
- * @returns Normalized path
43
- */
44
- static normalizePath(path: string): string;
45
- /**
46
- * Configure router settings to modify behavior.
15
+ * Adds a new route to the router with the specified HTTP methods, path, handler, and optional middlewares.
47
16
  *
48
- * @param options - Configuration options for the router
49
- * @returns
17
+ * @param methods
18
+ * @param path
19
+ * @param handler
20
+ * @param middlewares
50
21
  */
51
- static configure(options?: RouterConfig): void;
52
- private static resolveMethodOverride;
53
- /**
54
- * Add a route with specified HTTP methods, path, handler, and middlewares
55
- * @param methods - HTTP method(s) for the route
56
- * @param path - Route path
57
- * @param handler - Route handler function or controller reference
58
- * @param middlewares - Array of middleware functions
59
- */
60
22
  static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
61
23
  /**
62
- * Register RESTful API resource routes for a controller with optional action filtering
24
+ * Adds a new API resource route to the router for the specified base path and controller, with
25
+ * optional configuration for included/excluded actions and middlewares.
63
26
  *
64
- * @param basePath - Base path for the resource
65
- * @param controller - Controller object containing action methods
66
- * @param options - Optional filtering options for actions
27
+ * @param basePath
28
+ * @param controller
29
+ * @param options
67
30
  */
68
31
  static apiResource(basePath: string, controller: any, options?: {
69
32
  only?: ControllerAction[];
@@ -71,84 +34,93 @@ declare class Router {
71
34
  middlewares?: ApiResourceMiddleware<Middleware>;
72
35
  }): void;
73
36
  /**
74
- * Register a GET route
75
- * @param path - Route path
76
- * @param handler - Route handler
77
- * @param middlewares - Middleware functions
37
+ * Adds a new GET route to the router with the specified path, handler, and optional middlewares.
38
+ *
39
+ * @param path
40
+ * @param handler
41
+ * @param middlewares
78
42
  */
79
43
  static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
80
44
  /**
81
- * Register a POST route
82
- * @param path - Route path
83
- * @param handler - Route handler
84
- * @param middlewares - Middleware functions
45
+ * Adds a new POST route to the router with the specified path, handler, and optional middlewares.
46
+ *
47
+ * @param path
48
+ * @param handler
49
+ * @param middlewares
85
50
  */
86
51
  static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
87
52
  /**
88
- * Register a PUT route
89
- * @param path - Route path
90
- * @param handler - Route handler
91
- * @param middlewares - Middleware functions
53
+ * Adds a new PUT route to the router with the specified path, handler, and optional middlewares.
54
+ *
55
+ * @param path
56
+ * @param handler
57
+ * @param middlewares
92
58
  */
93
59
  static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
94
60
  /**
95
- * Register a DELETE route
96
- * @param path - Route path
97
- * @param handler - Route handler
98
- * @param middlewares - Middleware functions
61
+ * Adds a new DELETE route to the router with the specified path, handler, and optional middlewares.
62
+ *
63
+ * @param path
64
+ * @param handler
65
+ * @param middlewares
99
66
  */
100
67
  static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
101
68
  /**
102
- * Register a PATCH route
103
- * @param path - Route path
104
- * @param handler - Route handler
105
- * @param middlewares - Middleware functions
69
+ * Adds a new PATCH route to the router with the specified path, handler, and optional middlewares.
70
+ *
71
+ * @param path
72
+ * @param handler
73
+ * @param middlewares
106
74
  */
107
75
  static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
108
76
  /**
109
- * Register an OPTIONS route
110
- * @param path - Route path
111
- * @param handler - Route handler
112
- * @param middlewares - Middleware functions
77
+ * Adds a new OPTIONS route to the router with the specified path, handler, and optional middlewares.
78
+ *
79
+ * @param path
80
+ * @param handler
81
+ * @param middlewares
113
82
  */
114
83
  static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
115
84
  /**
116
- * Register a HEAD route
117
- * @param path - Route path
118
- * @param handler - Route handler
119
- * @param middlewares - Middleware functions
85
+ * Adds a new HEAD route to the router with the specified path, handler, and optional middlewares.
86
+ *
87
+ * @param path
88
+ * @param handler
89
+ * @param middlewares
120
90
  */
121
91
  static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
122
92
  /**
123
- * Group routes with a common prefix and middlewares
124
- * @param prefix - URL prefix for grouped routes
125
- * @param callback - Function containing route definitions
126
- * @param middlewares - Middleware functions applied to all routes in group
93
+ * Defines a group of routes with a common prefix and optional middlewares, allowing for better
94
+ * organization and reuse of route configurations.
95
+ *
96
+ * @param prefix
97
+ * @param callback
98
+ * @param middlewares
127
99
  */
128
100
  static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
129
101
  /**
130
- * Apply global middlewares for the duration of the callback
131
- * @param middlewares - Middleware functions
132
- * @param callback - Function containing route definitions
102
+ * Adds global middlewares to the router, which will be applied to all routes.
103
+ *
104
+ * @param middlewares
105
+ * @param callback
133
106
  */
134
107
  static middleware(middlewares: Middleware[], callback: () => void): void;
135
108
  /**
136
- * Get all registered routes with their information
137
- * @returns Array of route information objects
109
+ * Retrieves all registered routes in the router, optionally organized by path or method.
110
+ *
111
+ * @param type
138
112
  */
139
- static allRoutes(): Array<Route<HttpContext, Middleware>>;
140
- static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware>>;
141
- static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware>> };
113
+ static allRoutes(): Array<Route<HttpContext, Middleware, Handler>>;
114
+ static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler>>;
115
+ static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler>> };
142
116
  /**
143
- * Apply all registered routes to the provided Express Router instance
144
- * Handles controller-method binding and middleware application
145
- * All errors are thrown to Express error handling middleware
117
+ * Applies the registered routes to the given Express router instance, setting up the necessary
118
+ * handlers and middlewares for each route.
146
119
  *
147
- * @param router - Express Router instance
120
+ * @param router
148
121
  */
149
122
  static apply(router: Router$1): void;
150
123
  static apply(router: Router$1): Promise<void>;
151
- private static bindRequestToInstance;
152
124
  }
153
125
  //#endregion
154
126
  export { Router };
@@ -1,69 +1,32 @@
1
- import { a as Handler, c as Route, i as RouterConfig, n as ControllerAction, o as HttpContext, r as HttpMethod, s as Middleware, t as ApiResourceMiddleware } from "../basic-vvrFwa_Y.mjs";
1
+ import { a as Handler, c as Route, i as HttpMethod, n as ApiResourceMiddleware, o as HttpContext, r as ControllerAction, s as Middleware, t as CoreRouter } from "../router-C1jVRytA.mjs";
2
2
  import { Router as Router$1 } from "express";
3
3
 
4
4
  //#region src/express/router.d.ts
5
5
  /**
6
- * @class clear-router
6
+ * @class clear-router Express Router
7
7
  * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
8
8
  * @author Refkinscallv
9
9
  * @author 3m1n3nc3
10
10
  * @repository https://github.com/toneflix/clear-router
11
11
  */
12
- declare class Router {
13
- static config: RouterConfig;
14
- private static readonly groupContext;
12
+ declare class Router extends CoreRouter {
13
+ private static ensureRequestBodyAccessor;
15
14
  /**
16
- * All registered routes
17
- */
18
- static routes: Array<Route<HttpContext, Middleware>>;
19
- /**
20
- * Mapping of routes by path and method for quick lookup.
21
- */
22
- static routesByPathMethod: Record<string, Route<HttpContext, Middleware>>;
23
- /**
24
- * Mapping of routes by method for quick lookup.
25
- */
26
- static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware>> };
27
- /**
28
- * Current route prefix
29
- */
30
- static prefix: string;
31
- /**
32
- * Group-level middlewares
33
- */
34
- static groupMiddlewares: Middleware[];
35
- /**
36
- * Global-level middlewares
37
- */
38
- static globalMiddlewares: Middleware[];
39
- /**
40
- * Normalize path by removing duplicate slashes and ensuring leading slash
41
- * @param path - Path to normalize
42
- * @returns Normalized path
43
- */
44
- static normalizePath(path: string): string;
45
- /**
46
- * Configure router settings to modify behavior.
15
+ * Adds a new route to the router with the specified HTTP methods, path, handler, and optional middlewares.
47
16
  *
48
- * @param options - Configuration options for the router
49
- * @returns
17
+ * @param methods
18
+ * @param path
19
+ * @param handler
20
+ * @param middlewares
50
21
  */
51
- static configure(options?: RouterConfig): void;
52
- private static resolveMethodOverride;
53
- /**
54
- * Add a route with specified HTTP methods, path, handler, and middlewares
55
- * @param methods - HTTP method(s) for the route
56
- * @param path - Route path
57
- * @param handler - Route handler function or controller reference
58
- * @param middlewares - Array of middleware functions
59
- */
60
22
  static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
61
23
  /**
62
- * Register RESTful API resource routes for a controller with optional action filtering
24
+ * Adds a new API resource route to the router for the specified base path and controller, with
25
+ * optional configuration for included/excluded actions and middlewares.
63
26
  *
64
- * @param basePath - Base path for the resource
65
- * @param controller - Controller object containing action methods
66
- * @param options - Optional filtering options for actions
27
+ * @param basePath
28
+ * @param controller
29
+ * @param options
67
30
  */
68
31
  static apiResource(basePath: string, controller: any, options?: {
69
32
  only?: ControllerAction[];
@@ -71,84 +34,93 @@ declare class Router {
71
34
  middlewares?: ApiResourceMiddleware<Middleware>;
72
35
  }): void;
73
36
  /**
74
- * Register a GET route
75
- * @param path - Route path
76
- * @param handler - Route handler
77
- * @param middlewares - Middleware functions
37
+ * Adds a new GET route to the router with the specified path, handler, and optional middlewares.
38
+ *
39
+ * @param path
40
+ * @param handler
41
+ * @param middlewares
78
42
  */
79
43
  static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
80
44
  /**
81
- * Register a POST route
82
- * @param path - Route path
83
- * @param handler - Route handler
84
- * @param middlewares - Middleware functions
45
+ * Adds a new POST route to the router with the specified path, handler, and optional middlewares.
46
+ *
47
+ * @param path
48
+ * @param handler
49
+ * @param middlewares
85
50
  */
86
51
  static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
87
52
  /**
88
- * Register a PUT route
89
- * @param path - Route path
90
- * @param handler - Route handler
91
- * @param middlewares - Middleware functions
53
+ * Adds a new PUT route to the router with the specified path, handler, and optional middlewares.
54
+ *
55
+ * @param path
56
+ * @param handler
57
+ * @param middlewares
92
58
  */
93
59
  static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
94
60
  /**
95
- * Register a DELETE route
96
- * @param path - Route path
97
- * @param handler - Route handler
98
- * @param middlewares - Middleware functions
61
+ * Adds a new DELETE route to the router with the specified path, handler, and optional middlewares.
62
+ *
63
+ * @param path
64
+ * @param handler
65
+ * @param middlewares
99
66
  */
100
67
  static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
101
68
  /**
102
- * Register a PATCH route
103
- * @param path - Route path
104
- * @param handler - Route handler
105
- * @param middlewares - Middleware functions
69
+ * Adds a new PATCH route to the router with the specified path, handler, and optional middlewares.
70
+ *
71
+ * @param path
72
+ * @param handler
73
+ * @param middlewares
106
74
  */
107
75
  static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
108
76
  /**
109
- * Register an OPTIONS route
110
- * @param path - Route path
111
- * @param handler - Route handler
112
- * @param middlewares - Middleware functions
77
+ * Adds a new OPTIONS route to the router with the specified path, handler, and optional middlewares.
78
+ *
79
+ * @param path
80
+ * @param handler
81
+ * @param middlewares
113
82
  */
114
83
  static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
115
84
  /**
116
- * Register a HEAD route
117
- * @param path - Route path
118
- * @param handler - Route handler
119
- * @param middlewares - Middleware functions
85
+ * Adds a new HEAD route to the router with the specified path, handler, and optional middlewares.
86
+ *
87
+ * @param path
88
+ * @param handler
89
+ * @param middlewares
120
90
  */
121
91
  static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
122
92
  /**
123
- * Group routes with a common prefix and middlewares
124
- * @param prefix - URL prefix for grouped routes
125
- * @param callback - Function containing route definitions
126
- * @param middlewares - Middleware functions applied to all routes in group
93
+ * Defines a group of routes with a common prefix and optional middlewares, allowing for better
94
+ * organization and reuse of route configurations.
95
+ *
96
+ * @param prefix
97
+ * @param callback
98
+ * @param middlewares
127
99
  */
128
100
  static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
129
101
  /**
130
- * Apply global middlewares for the duration of the callback
131
- * @param middlewares - Middleware functions
132
- * @param callback - Function containing route definitions
102
+ * Adds global middlewares to the router, which will be applied to all routes.
103
+ *
104
+ * @param middlewares
105
+ * @param callback
133
106
  */
134
107
  static middleware(middlewares: Middleware[], callback: () => void): void;
135
108
  /**
136
- * Get all registered routes with their information
137
- * @returns Array of route information objects
109
+ * Retrieves all registered routes in the router, optionally organized by path or method.
110
+ *
111
+ * @param type
138
112
  */
139
- static allRoutes(): Array<Route<HttpContext, Middleware>>;
140
- static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware>>;
141
- static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware>> };
113
+ static allRoutes(): Array<Route<HttpContext, Middleware, Handler>>;
114
+ static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler>>;
115
+ static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler>> };
142
116
  /**
143
- * Apply all registered routes to the provided Express Router instance
144
- * Handles controller-method binding and middleware application
145
- * All errors are thrown to Express error handling middleware
117
+ * Applies the registered routes to the given Express router instance, setting up the necessary
118
+ * handlers and middlewares for each route.
146
119
  *
147
- * @param router - Express Router instance
120
+ * @param router
148
121
  */
149
122
  static apply(router: Router$1): void;
150
123
  static apply(router: Router$1): Promise<void>;
151
- private static bindRequestToInstance;
152
124
  }
153
125
  //#endregion
154
126
  export { Router };