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.
- 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 +91 -244
- package/dist/express/index.d.cts +68 -96
- package/dist/express/index.d.mts +68 -96
- package/dist/express/index.mjs +91 -244
- package/dist/h3/index.cjs +99 -244
- package/dist/h3/index.d.cts +72 -93
- package/dist/h3/index.d.mts +72 -93
- package/dist/h3/index.mjs +99 -244
- package/dist/index.cjs +342 -0
- package/dist/index.d.cts +184 -31
- package/dist/index.d.mts +184 -31
- 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/dist/types/express.d.mts +5 -2
- package/dist/types/h3.d.mts +7 -2
- package/package.json +10 -2
- package/dist/Route-BbPXcDGX.mjs +0 -50
- package/dist/Route-DhC4kNPX.cjs +0 -62
- package/dist/basic-DXbqD6cP.d.cts +0 -130
- package/dist/basic-vvrFwa_Y.d.mts +0 -130
package/dist/express/index.d.cts
CHANGED
|
@@ -1,69 +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;
|
|
12
|
+
declare class Router extends CoreRouter {
|
|
13
|
+
private static ensureRequestBodyAccessor;
|
|
15
14
|
/**
|
|
16
|
-
*
|
|
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
|
|
49
|
-
* @
|
|
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
|
-
*
|
|
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
|
|
65
|
-
* @param controller
|
|
66
|
-
* @param options
|
|
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
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* @param
|
|
77
|
-
* @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
|
|
78
42
|
*/
|
|
79
43
|
static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
80
44
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* @param
|
|
84
|
-
* @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
|
|
85
50
|
*/
|
|
86
51
|
static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
87
52
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* @param
|
|
91
|
-
* @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
|
|
92
58
|
*/
|
|
93
59
|
static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
94
60
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* @param
|
|
98
|
-
* @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
|
|
99
66
|
*/
|
|
100
67
|
static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
101
68
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* @param
|
|
105
|
-
* @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
|
|
106
74
|
*/
|
|
107
75
|
static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
108
76
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* @param
|
|
112
|
-
* @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
|
|
113
82
|
*/
|
|
114
83
|
static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
115
84
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* @param
|
|
119
|
-
* @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
|
|
120
90
|
*/
|
|
121
91
|
static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
122
92
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* @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
|
|
127
99
|
*/
|
|
128
100
|
static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
|
|
129
101
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* @param
|
|
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
|
-
*
|
|
137
|
-
*
|
|
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
|
-
*
|
|
144
|
-
*
|
|
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
|
|
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 };
|
package/dist/express/index.d.mts
CHANGED
|
@@ -1,69 +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;
|
|
12
|
+
declare class Router extends CoreRouter {
|
|
13
|
+
private static ensureRequestBodyAccessor;
|
|
15
14
|
/**
|
|
16
|
-
*
|
|
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
|
|
49
|
-
* @
|
|
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
|
-
*
|
|
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
|
|
65
|
-
* @param controller
|
|
66
|
-
* @param options
|
|
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
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* @param
|
|
77
|
-
* @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
|
|
78
42
|
*/
|
|
79
43
|
static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
80
44
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* @param
|
|
84
|
-
* @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
|
|
85
50
|
*/
|
|
86
51
|
static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
87
52
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* @param
|
|
91
|
-
* @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
|
|
92
58
|
*/
|
|
93
59
|
static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
94
60
|
/**
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* @param
|
|
98
|
-
* @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
|
|
99
66
|
*/
|
|
100
67
|
static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
101
68
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* @param
|
|
105
|
-
* @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
|
|
106
74
|
*/
|
|
107
75
|
static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
108
76
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* @param
|
|
112
|
-
* @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
|
|
113
82
|
*/
|
|
114
83
|
static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
115
84
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* @param
|
|
119
|
-
* @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
|
|
120
90
|
*/
|
|
121
91
|
static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
122
92
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* @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
|
|
127
99
|
*/
|
|
128
100
|
static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
|
|
129
101
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* @param
|
|
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
|
-
*
|
|
137
|
-
*
|
|
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
|
-
*
|
|
144
|
-
*
|
|
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
|
|
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 };
|