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.
- package/README.md +4 -4
- package/dist/core/index.cjs +4 -0
- package/dist/core/index.d.cts +2 -0
- package/dist/core/index.d.mts +2 -0
- package/dist/core/index.mjs +3 -0
- package/dist/express/index.cjs +86 -247
- package/dist/express/index.d.cts +68 -97
- package/dist/express/index.d.mts +68 -97
- package/dist/express/index.mjs +86 -247
- package/dist/h3/index.cjs +88 -242
- package/dist/h3/index.d.cts +72 -93
- package/dist/h3/index.d.mts +72 -93
- package/dist/h3/index.mjs +88 -242
- package/dist/index.cjs +342 -0
- package/dist/index.d.cts +184 -38
- package/dist/index.d.mts +184 -38
- package/dist/index.mjs +343 -1
- package/dist/router-BNVIrTi3.cjs +397 -0
- package/dist/router-BiCuy5TZ.mjs +392 -0
- package/dist/router-C1jVRytA.d.mts +311 -0
- package/dist/router-CZIh1ZPJ.d.cts +311 -0
- package/dist/types/Route.d.mts +4 -4
- package/package.json +6 -2
- package/dist/Route-BbPXcDGX.mjs +0 -50
- package/dist/Route-DhC4kNPX.cjs +0 -62
- package/dist/basic-C_1O6RVq.d.cts +0 -138
- package/dist/basic-cLeny2Zk.d.mts +0 -138
package/dist/express/index.d.cts
CHANGED
|
@@ -1,70 +1,32 @@
|
|
|
1
|
-
import { a as Handler, c as Route, i as
|
|
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
|
|
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
|
-
*
|
|
15
|
+
* Adds a new route to the router with the specified HTTP methods, path, handler, and optional middlewares.
|
|
47
16
|
*
|
|
48
|
-
* @param
|
|
49
|
-
* @
|
|
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
|
-
*
|
|
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
|
|
66
|
-
* @param controller
|
|
67
|
-
* @param options
|
|
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
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @param
|
|
78
|
-
* @param
|
|
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
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* @param
|
|
85
|
-
* @param
|
|
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
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* @param
|
|
92
|
-
* @param
|
|
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
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* @param
|
|
99
|
-
* @param
|
|
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
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* @param
|
|
106
|
-
* @param
|
|
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
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* @param
|
|
113
|
-
* @param
|
|
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
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* @param
|
|
120
|
-
* @param
|
|
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
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* @param
|
|
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
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* @param
|
|
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
|
-
*
|
|
138
|
-
*
|
|
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
|
-
*
|
|
145
|
-
*
|
|
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
|
|
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 };
|
package/dist/express/index.d.mts
CHANGED
|
@@ -1,70 +1,32 @@
|
|
|
1
|
-
import { a as Handler, c as Route, i as
|
|
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
|
|
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
|
-
*
|
|
15
|
+
* Adds a new route to the router with the specified HTTP methods, path, handler, and optional middlewares.
|
|
47
16
|
*
|
|
48
|
-
* @param
|
|
49
|
-
* @
|
|
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
|
-
*
|
|
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
|
|
66
|
-
* @param controller
|
|
67
|
-
* @param options
|
|
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
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* @param
|
|
78
|
-
* @param
|
|
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
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* @param
|
|
85
|
-
* @param
|
|
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
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* @param
|
|
92
|
-
* @param
|
|
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
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* @param
|
|
99
|
-
* @param
|
|
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
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* @param
|
|
106
|
-
* @param
|
|
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
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* @param
|
|
113
|
-
* @param
|
|
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
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* @param
|
|
120
|
-
* @param
|
|
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
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
* @param
|
|
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
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* @param
|
|
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
|
-
*
|
|
138
|
-
*
|
|
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
|
-
*
|
|
145
|
-
*
|
|
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
|
|
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 };
|