clear-router 2.1.12 → 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,70 +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-C_1O6RVq.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;
15
- /**
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;
12
+ declare class Router extends CoreRouter {
13
+ private static ensureRequestBodyAccessor;
45
14
  /**
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 ensureRequestBodyAccessor;
53
- private static resolveMethodOverride;
54
- /**
55
- * Add a route with specified HTTP methods, path, handler, and middlewares
56
- * @param methods - HTTP method(s) for the route
57
- * @param path - Route path
58
- * @param handler - Route handler function or controller reference
59
- * @param middlewares - Array of middleware functions
60
- */
61
22
  static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
62
23
  /**
63
- * 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.
64
26
  *
65
- * @param basePath - Base path for the resource
66
- * @param controller - Controller object containing action methods
67
- * @param options - Optional filtering options for actions
27
+ * @param basePath
28
+ * @param controller
29
+ * @param options
68
30
  */
69
31
  static apiResource(basePath: string, controller: any, options?: {
70
32
  only?: ControllerAction[];
@@ -72,84 +34,93 @@ declare class Router {
72
34
  middlewares?: ApiResourceMiddleware<Middleware>;
73
35
  }): void;
74
36
  /**
75
- * Register a GET route
76
- * @param path - Route path
77
- * @param handler - Route handler
78
- * @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
79
42
  */
80
43
  static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
81
44
  /**
82
- * Register a POST route
83
- * @param path - Route path
84
- * @param handler - Route handler
85
- * @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
86
50
  */
87
51
  static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
88
52
  /**
89
- * Register a PUT route
90
- * @param path - Route path
91
- * @param handler - Route handler
92
- * @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
93
58
  */
94
59
  static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
95
60
  /**
96
- * Register a DELETE route
97
- * @param path - Route path
98
- * @param handler - Route handler
99
- * @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
100
66
  */
101
67
  static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
102
68
  /**
103
- * Register a PATCH route
104
- * @param path - Route path
105
- * @param handler - Route handler
106
- * @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
107
74
  */
108
75
  static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
109
76
  /**
110
- * Register an OPTIONS route
111
- * @param path - Route path
112
- * @param handler - Route handler
113
- * @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
114
82
  */
115
83
  static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
116
84
  /**
117
- * Register a HEAD route
118
- * @param path - Route path
119
- * @param handler - Route handler
120
- * @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
121
90
  */
122
91
  static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
123
92
  /**
124
- * Group routes with a common prefix and middlewares
125
- * @param prefix - URL prefix for grouped routes
126
- * @param callback - Function containing route definitions
127
- * @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
128
99
  */
129
100
  static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
130
101
  /**
131
- * Apply global middlewares for the duration of the callback
132
- * @param middlewares - Middleware functions
133
- * @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
134
106
  */
135
107
  static middleware(middlewares: Middleware[], callback: () => void): void;
136
108
  /**
137
- * Get all registered routes with their information
138
- * @returns Array of route information objects
109
+ * Retrieves all registered routes in the router, optionally organized by path or method.
110
+ *
111
+ * @param type
139
112
  */
140
- static allRoutes(): Array<Route<HttpContext, Middleware>>;
141
- static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware>>;
142
- 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>> };
143
116
  /**
144
- * Apply all registered routes to the provided Express Router instance
145
- * Handles controller-method binding and middleware application
146
- * 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.
147
119
  *
148
- * @param router - Express Router instance
120
+ * @param router
149
121
  */
150
122
  static apply(router: Router$1): void;
151
123
  static apply(router: Router$1): Promise<void>;
152
- private static bindRequestToInstance;
153
124
  }
154
125
  //#endregion
155
126
  export { Router };
@@ -1,70 +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-cLeny2Zk.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;
15
- /**
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;
12
+ declare class Router extends CoreRouter {
13
+ private static ensureRequestBodyAccessor;
45
14
  /**
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 ensureRequestBodyAccessor;
53
- private static resolveMethodOverride;
54
- /**
55
- * Add a route with specified HTTP methods, path, handler, and middlewares
56
- * @param methods - HTTP method(s) for the route
57
- * @param path - Route path
58
- * @param handler - Route handler function or controller reference
59
- * @param middlewares - Array of middleware functions
60
- */
61
22
  static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
62
23
  /**
63
- * 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.
64
26
  *
65
- * @param basePath - Base path for the resource
66
- * @param controller - Controller object containing action methods
67
- * @param options - Optional filtering options for actions
27
+ * @param basePath
28
+ * @param controller
29
+ * @param options
68
30
  */
69
31
  static apiResource(basePath: string, controller: any, options?: {
70
32
  only?: ControllerAction[];
@@ -72,84 +34,93 @@ declare class Router {
72
34
  middlewares?: ApiResourceMiddleware<Middleware>;
73
35
  }): void;
74
36
  /**
75
- * Register a GET route
76
- * @param path - Route path
77
- * @param handler - Route handler
78
- * @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
79
42
  */
80
43
  static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
81
44
  /**
82
- * Register a POST route
83
- * @param path - Route path
84
- * @param handler - Route handler
85
- * @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
86
50
  */
87
51
  static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
88
52
  /**
89
- * Register a PUT route
90
- * @param path - Route path
91
- * @param handler - Route handler
92
- * @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
93
58
  */
94
59
  static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
95
60
  /**
96
- * Register a DELETE route
97
- * @param path - Route path
98
- * @param handler - Route handler
99
- * @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
100
66
  */
101
67
  static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
102
68
  /**
103
- * Register a PATCH route
104
- * @param path - Route path
105
- * @param handler - Route handler
106
- * @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
107
74
  */
108
75
  static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
109
76
  /**
110
- * Register an OPTIONS route
111
- * @param path - Route path
112
- * @param handler - Route handler
113
- * @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
114
82
  */
115
83
  static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
116
84
  /**
117
- * Register a HEAD route
118
- * @param path - Route path
119
- * @param handler - Route handler
120
- * @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
121
90
  */
122
91
  static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
123
92
  /**
124
- * Group routes with a common prefix and middlewares
125
- * @param prefix - URL prefix for grouped routes
126
- * @param callback - Function containing route definitions
127
- * @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
128
99
  */
129
100
  static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
130
101
  /**
131
- * Apply global middlewares for the duration of the callback
132
- * @param middlewares - Middleware functions
133
- * @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
134
106
  */
135
107
  static middleware(middlewares: Middleware[], callback: () => void): void;
136
108
  /**
137
- * Get all registered routes with their information
138
- * @returns Array of route information objects
109
+ * Retrieves all registered routes in the router, optionally organized by path or method.
110
+ *
111
+ * @param type
139
112
  */
140
- static allRoutes(): Array<Route<HttpContext, Middleware>>;
141
- static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware>>;
142
- 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>> };
143
116
  /**
144
- * Apply all registered routes to the provided Express Router instance
145
- * Handles controller-method binding and middleware application
146
- * 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.
147
119
  *
148
- * @param router - Express Router instance
120
+ * @param router
149
121
  */
150
122
  static apply(router: Router$1): void;
151
123
  static apply(router: Router$1): Promise<void>;
152
- private static bindRequestToInstance;
153
124
  }
154
125
  //#endregion
155
126
  export { Router };