clear-router 2.2.0 → 2.3.1
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 +15 -5
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.d.cts +1 -1
- package/dist/core/index.d.mts +1 -1
- package/dist/core/index.mjs +1 -1
- package/dist/express/index.cjs +1 -1
- package/dist/express/index.d.cts +1 -1
- package/dist/express/index.d.mts +1 -1
- package/dist/express/index.mjs +1 -1
- package/dist/fastify/index.cjs +213 -0
- package/dist/fastify/index.d.cts +137 -0
- package/dist/fastify/index.d.mts +137 -0
- package/dist/fastify/index.mjs +212 -0
- package/dist/h3/index.cjs +1 -1
- package/dist/h3/index.d.cts +1 -1
- package/dist/h3/index.d.mts +1 -1
- package/dist/h3/index.mjs +1 -1
- package/dist/hono/index.cjs +227 -0
- package/dist/hono/index.d.cts +141 -0
- package/dist/hono/index.d.mts +141 -0
- package/dist/hono/index.mjs +226 -0
- package/dist/index.cjs +26 -11
- package/dist/index.d.cts +14 -5
- package/dist/index.d.mts +14 -5
- package/dist/index.mjs +26 -11
- package/dist/{router-BNVIrTi3.cjs → router-Ba2MVNn-.cjs} +26 -11
- package/dist/{router-BiCuy5TZ.mjs → router-Bug2IE_u.mjs} +26 -11
- package/dist/{router-C1jVRytA.d.mts → router-DLmimm_U.d.cts} +82 -73
- package/dist/{router-CZIh1ZPJ.d.cts → router-cWYmcfTX.d.mts} +83 -74
- package/dist/types/ClearRequest.d.mts +1 -1
- package/dist/types/Route.d.mts +1 -1
- package/dist/types/basic.d.mts +1 -4
- package/dist/types/express.d.mts +1 -1
- package/dist/types/fastify.d.mts +19 -0
- package/dist/types/fastify.mjs +1 -0
- package/dist/types/h3.d.mts +1 -1
- package/dist/types/hono.d.mts +18 -0
- package/dist/types/hono.mjs +1 -0
- package/package.json +23 -3
|
@@ -1,7 +1,72 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import { H3, H3Event, Middleware as Middleware$1, TypedServerRequest } from "h3";
|
|
3
2
|
import { NextFunction, Request, Response as Response$1 } from "express";
|
|
3
|
+
import { H3, H3Event, Middleware, TypedServerRequest } from "h3";
|
|
4
4
|
|
|
5
|
+
//#region types/basic.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Controller method reference
|
|
8
|
+
*/
|
|
9
|
+
type ControllerHandler = [any, string];
|
|
10
|
+
/**
|
|
11
|
+
* HTTP methods supported by the router
|
|
12
|
+
*/
|
|
13
|
+
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
14
|
+
/**
|
|
15
|
+
* Common controller action names
|
|
16
|
+
*/
|
|
17
|
+
type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
18
|
+
/**
|
|
19
|
+
* Generic Object type for request data
|
|
20
|
+
*/
|
|
21
|
+
type RequestData = Record<string, any>;
|
|
22
|
+
type ApiResourceMiddleware<M = any> = M | M[] | { [K in ControllerAction]?: M | M[] };
|
|
23
|
+
interface RouterConfig {
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for method override functionality, allowing clients to use a
|
|
26
|
+
* specific header or body parameter to override the HTTP method.
|
|
27
|
+
*/
|
|
28
|
+
methodOverride?: {
|
|
29
|
+
/** Whether method override is enabled */enabled?: boolean; /** Keys in the request body to check for method override */
|
|
30
|
+
bodyKeys?: string[] | string; /** Keys in the request headers to check for method override */
|
|
31
|
+
headerKeys?: string[] | string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region types/express.d.ts
|
|
36
|
+
interface RequestWithGetBody extends Request {
|
|
37
|
+
getBody: () => Record<string, any>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* HTTP context passed to route handlers
|
|
41
|
+
*/
|
|
42
|
+
interface HttpContext$1 {
|
|
43
|
+
req: RequestWithGetBody;
|
|
44
|
+
res: Response$1;
|
|
45
|
+
next: NextFunction;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Route handler function type
|
|
49
|
+
*/
|
|
50
|
+
type RouteHandler$1 = (
|
|
51
|
+
/**
|
|
52
|
+
* Express context object containing req, res, and next
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
ctx: HttpContext$1,
|
|
56
|
+
/**
|
|
57
|
+
* ClearRequest instance
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
req: ClearRequest) => any | Promise<any>;
|
|
61
|
+
/**
|
|
62
|
+
* Handler can be either a function or controller reference
|
|
63
|
+
*/
|
|
64
|
+
type Handler$1 = RouteHandler$1 | ControllerHandler;
|
|
65
|
+
/**
|
|
66
|
+
* Middleware function type
|
|
67
|
+
*/
|
|
68
|
+
type Middleware$1 = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
|
|
69
|
+
//#endregion
|
|
5
70
|
//#region types/h3.d.ts
|
|
6
71
|
type H3App = Omit<H3['fetch'], 'fetch'> & {
|
|
7
72
|
fetch: (request: TypedServerRequest) => Promise<Response>;
|
|
@@ -12,18 +77,18 @@ type HttpRequest = H3Event['req'] & {
|
|
|
12
77
|
/**
|
|
13
78
|
* HTTP context passed to route handlers
|
|
14
79
|
*/
|
|
15
|
-
type HttpContext
|
|
80
|
+
type HttpContext = Omit<H3Event, 'req'> & {
|
|
16
81
|
req: HttpRequest;
|
|
17
82
|
};
|
|
18
83
|
/**
|
|
19
84
|
* Route handler function type
|
|
20
85
|
*/
|
|
21
|
-
type RouteHandler
|
|
86
|
+
type RouteHandler = (
|
|
22
87
|
/**
|
|
23
88
|
* H3 event context
|
|
24
89
|
*/
|
|
25
90
|
|
|
26
|
-
ctx: HttpContext
|
|
91
|
+
ctx: HttpContext,
|
|
27
92
|
/**
|
|
28
93
|
* ClearRequest instance
|
|
29
94
|
*/
|
|
@@ -32,10 +97,10 @@ req: ClearRequest) => any | Promise<any>;
|
|
|
32
97
|
/**
|
|
33
98
|
* Handler can be either a function or controller reference
|
|
34
99
|
*/
|
|
35
|
-
type Handler
|
|
100
|
+
type Handler = RouteHandler | ControllerHandler;
|
|
36
101
|
//#endregion
|
|
37
102
|
//#region src/Route.d.ts
|
|
38
|
-
declare class Route<X = any, M = Middleware
|
|
103
|
+
declare class Route<X = any, M = Middleware | Middleware$1, H = any> {
|
|
39
104
|
ctx: X;
|
|
40
105
|
body: RequestData;
|
|
41
106
|
query: RequestData;
|
|
@@ -53,7 +118,7 @@ declare class Route<X = any, M = Middleware$1 | Middleware, H = any> {
|
|
|
53
118
|
}
|
|
54
119
|
//#endregion
|
|
55
120
|
//#region src/ClearRequest.d.ts
|
|
56
|
-
declare class ClearRequest<X = any, M = Middleware
|
|
121
|
+
declare class ClearRequest<X = any, M = Middleware | Middleware$1> {
|
|
57
122
|
[key: string]: any;
|
|
58
123
|
/**
|
|
59
124
|
* @param body - Parsed request body
|
|
@@ -71,71 +136,6 @@ declare class ClearRequest<X = any, M = Middleware$1 | Middleware> {
|
|
|
71
136
|
constructor(init?: Partial<ClearRequest>);
|
|
72
137
|
}
|
|
73
138
|
//#endregion
|
|
74
|
-
//#region types/express.d.ts
|
|
75
|
-
interface RequestWithGetBody extends Request {
|
|
76
|
-
getBody: () => Record<string, any>;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* HTTP context passed to route handlers
|
|
80
|
-
*/
|
|
81
|
-
interface HttpContext {
|
|
82
|
-
req: RequestWithGetBody;
|
|
83
|
-
res: Response$1;
|
|
84
|
-
next: NextFunction;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Route handler function type
|
|
88
|
-
*/
|
|
89
|
-
type RouteHandler = (
|
|
90
|
-
/**
|
|
91
|
-
* Express context object containing req, res, and next
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
ctx: HttpContext,
|
|
95
|
-
/**
|
|
96
|
-
* ClearRequest instance
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
req: ClearRequest) => any | Promise<any>;
|
|
100
|
-
/**
|
|
101
|
-
* Handler can be either a function or controller reference
|
|
102
|
-
*/
|
|
103
|
-
type Handler = RouteHandler | ControllerHandler;
|
|
104
|
-
/**
|
|
105
|
-
* Middleware function type
|
|
106
|
-
*/
|
|
107
|
-
type Middleware = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region types/basic.d.ts
|
|
110
|
-
/**
|
|
111
|
-
* Controller method reference
|
|
112
|
-
*/
|
|
113
|
-
type ControllerHandler = [any, string];
|
|
114
|
-
/**
|
|
115
|
-
* HTTP methods supported by the router
|
|
116
|
-
*/
|
|
117
|
-
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
118
|
-
/**
|
|
119
|
-
* Common controller action names
|
|
120
|
-
*/
|
|
121
|
-
type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
122
|
-
/**
|
|
123
|
-
* Generic Object type for request data
|
|
124
|
-
*/
|
|
125
|
-
type RequestData = Record<string, any>;
|
|
126
|
-
type ApiResourceMiddleware<M extends Middleware | Middleware$1> = M | M[] | { [K in ControllerAction]?: M | M[] };
|
|
127
|
-
interface RouterConfig {
|
|
128
|
-
/**
|
|
129
|
-
* Configuration for method override functionality, allowing clients to use a
|
|
130
|
-
* specific header or body parameter to override the HTTP method.
|
|
131
|
-
*/
|
|
132
|
-
methodOverride?: {
|
|
133
|
-
/** Whether method override is enabled */enabled?: boolean; /** Keys in the request body to check for method override */
|
|
134
|
-
bodyKeys?: string[] | string; /** Keys in the request headers to check for method override */
|
|
135
|
-
headerKeys?: string[] | string;
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
//#endregion
|
|
139
139
|
//#region src/Controller.d.ts
|
|
140
140
|
declare abstract class Controller<X = any> {
|
|
141
141
|
[x: string]: any;
|
|
@@ -154,6 +154,7 @@ declare abstract class Controller<X = any> {
|
|
|
154
154
|
* @repository https://github.com/toneflix/clear-router
|
|
155
155
|
*/
|
|
156
156
|
declare abstract class CoreRouter {
|
|
157
|
+
protected static createDefaultOptionsHandler(): any;
|
|
157
158
|
static config: RouterConfig;
|
|
158
159
|
protected static groupContext: AsyncLocalStorage<{
|
|
159
160
|
prefix: string;
|
|
@@ -295,7 +296,15 @@ declare abstract class CoreRouter {
|
|
|
295
296
|
* @param this
|
|
296
297
|
*/
|
|
297
298
|
static allRoutes(this: any): Array<Route<any, any, any>>;
|
|
299
|
+
/**
|
|
300
|
+
* @param this
|
|
301
|
+
* @param type - 'path' to get routes organized by path
|
|
302
|
+
*/
|
|
298
303
|
static allRoutes(this: any, type: 'path'): Record<string, Route<any, any, any>>;
|
|
304
|
+
/**
|
|
305
|
+
* @param this
|
|
306
|
+
* @param type - 'method' to get routes organized by method
|
|
307
|
+
*/
|
|
299
308
|
static allRoutes(this: any, type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
|
|
300
309
|
protected static resolveHandler(route: Route<any, any, any>): {
|
|
301
310
|
handlerFunction: ((ctx: any, req: ClearRequest) => any | Promise<any>) | null;
|
|
@@ -308,4 +317,4 @@ declare abstract class CoreRouter {
|
|
|
308
317
|
}): void;
|
|
309
318
|
}
|
|
310
319
|
//#endregion
|
|
311
|
-
export { Handler as a,
|
|
320
|
+
export { Handler as a, Handler$1 as c, ApiResourceMiddleware as d, ControllerAction as f, H3App as i, HttpContext$1 as l, HttpMethod as m, ClearRequest as n, HttpContext as o, ControllerHandler as p, Route as r, Middleware as s, CoreRouter as t, Middleware$1 as u };
|
|
@@ -1,7 +1,72 @@
|
|
|
1
|
-
import { NextFunction, Request, Response as Response$1 } from "express";
|
|
2
|
-
import { H3, H3Event, Middleware as Middleware$1, TypedServerRequest } from "h3";
|
|
3
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { H3, H3Event, Middleware, TypedServerRequest } from "h3";
|
|
3
|
+
import { NextFunction, Request, Response as Response$1 } from "express";
|
|
4
4
|
|
|
5
|
+
//#region types/basic.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Controller method reference
|
|
8
|
+
*/
|
|
9
|
+
type ControllerHandler = [any, string];
|
|
10
|
+
/**
|
|
11
|
+
* HTTP methods supported by the router
|
|
12
|
+
*/
|
|
13
|
+
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
14
|
+
/**
|
|
15
|
+
* Common controller action names
|
|
16
|
+
*/
|
|
17
|
+
type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
18
|
+
/**
|
|
19
|
+
* Generic Object type for request data
|
|
20
|
+
*/
|
|
21
|
+
type RequestData = Record<string, any>;
|
|
22
|
+
type ApiResourceMiddleware<M = any> = M | M[] | { [K in ControllerAction]?: M | M[] };
|
|
23
|
+
interface RouterConfig {
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for method override functionality, allowing clients to use a
|
|
26
|
+
* specific header or body parameter to override the HTTP method.
|
|
27
|
+
*/
|
|
28
|
+
methodOverride?: {
|
|
29
|
+
/** Whether method override is enabled */enabled?: boolean; /** Keys in the request body to check for method override */
|
|
30
|
+
bodyKeys?: string[] | string; /** Keys in the request headers to check for method override */
|
|
31
|
+
headerKeys?: string[] | string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region types/express.d.ts
|
|
36
|
+
interface RequestWithGetBody extends Request {
|
|
37
|
+
getBody: () => Record<string, any>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* HTTP context passed to route handlers
|
|
41
|
+
*/
|
|
42
|
+
interface HttpContext$1 {
|
|
43
|
+
req: RequestWithGetBody;
|
|
44
|
+
res: Response$1;
|
|
45
|
+
next: NextFunction;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Route handler function type
|
|
49
|
+
*/
|
|
50
|
+
type RouteHandler$1 = (
|
|
51
|
+
/**
|
|
52
|
+
* Express context object containing req, res, and next
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
ctx: HttpContext$1,
|
|
56
|
+
/**
|
|
57
|
+
* ClearRequest instance
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
req: ClearRequest) => any | Promise<any>;
|
|
61
|
+
/**
|
|
62
|
+
* Handler can be either a function or controller reference
|
|
63
|
+
*/
|
|
64
|
+
type Handler$1 = RouteHandler$1 | ControllerHandler;
|
|
65
|
+
/**
|
|
66
|
+
* Middleware function type
|
|
67
|
+
*/
|
|
68
|
+
type Middleware$1 = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
|
|
69
|
+
//#endregion
|
|
5
70
|
//#region types/h3.d.ts
|
|
6
71
|
type H3App = Omit<H3['fetch'], 'fetch'> & {
|
|
7
72
|
fetch: (request: TypedServerRequest) => Promise<Response>;
|
|
@@ -12,18 +77,18 @@ type HttpRequest = H3Event['req'] & {
|
|
|
12
77
|
/**
|
|
13
78
|
* HTTP context passed to route handlers
|
|
14
79
|
*/
|
|
15
|
-
type HttpContext
|
|
80
|
+
type HttpContext = Omit<H3Event, 'req'> & {
|
|
16
81
|
req: HttpRequest;
|
|
17
82
|
};
|
|
18
83
|
/**
|
|
19
84
|
* Route handler function type
|
|
20
85
|
*/
|
|
21
|
-
type RouteHandler
|
|
86
|
+
type RouteHandler = (
|
|
22
87
|
/**
|
|
23
88
|
* H3 event context
|
|
24
89
|
*/
|
|
25
90
|
|
|
26
|
-
ctx: HttpContext
|
|
91
|
+
ctx: HttpContext,
|
|
27
92
|
/**
|
|
28
93
|
* ClearRequest instance
|
|
29
94
|
*/
|
|
@@ -32,10 +97,10 @@ req: ClearRequest) => any | Promise<any>;
|
|
|
32
97
|
/**
|
|
33
98
|
* Handler can be either a function or controller reference
|
|
34
99
|
*/
|
|
35
|
-
type Handler
|
|
100
|
+
type Handler = RouteHandler | ControllerHandler;
|
|
36
101
|
//#endregion
|
|
37
102
|
//#region src/Route.d.ts
|
|
38
|
-
declare class Route<X = any, M = Middleware
|
|
103
|
+
declare class Route<X = any, M = Middleware | Middleware$1, H = any> {
|
|
39
104
|
ctx: X;
|
|
40
105
|
body: RequestData;
|
|
41
106
|
query: RequestData;
|
|
@@ -53,7 +118,7 @@ declare class Route<X = any, M = Middleware$1 | Middleware, H = any> {
|
|
|
53
118
|
}
|
|
54
119
|
//#endregion
|
|
55
120
|
//#region src/ClearRequest.d.ts
|
|
56
|
-
declare class ClearRequest<X = any, M = Middleware
|
|
121
|
+
declare class ClearRequest<X = any, M = Middleware | Middleware$1> {
|
|
57
122
|
[key: string]: any;
|
|
58
123
|
/**
|
|
59
124
|
* @param body - Parsed request body
|
|
@@ -71,71 +136,6 @@ declare class ClearRequest<X = any, M = Middleware$1 | Middleware> {
|
|
|
71
136
|
constructor(init?: Partial<ClearRequest>);
|
|
72
137
|
}
|
|
73
138
|
//#endregion
|
|
74
|
-
//#region types/express.d.ts
|
|
75
|
-
interface RequestWithGetBody extends Request {
|
|
76
|
-
getBody: () => Record<string, any>;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* HTTP context passed to route handlers
|
|
80
|
-
*/
|
|
81
|
-
interface HttpContext {
|
|
82
|
-
req: RequestWithGetBody;
|
|
83
|
-
res: Response$1;
|
|
84
|
-
next: NextFunction;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Route handler function type
|
|
88
|
-
*/
|
|
89
|
-
type RouteHandler = (
|
|
90
|
-
/**
|
|
91
|
-
* Express context object containing req, res, and next
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
ctx: HttpContext,
|
|
95
|
-
/**
|
|
96
|
-
* ClearRequest instance
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
req: ClearRequest) => any | Promise<any>;
|
|
100
|
-
/**
|
|
101
|
-
* Handler can be either a function or controller reference
|
|
102
|
-
*/
|
|
103
|
-
type Handler = RouteHandler | ControllerHandler;
|
|
104
|
-
/**
|
|
105
|
-
* Middleware function type
|
|
106
|
-
*/
|
|
107
|
-
type Middleware = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
|
|
108
|
-
//#endregion
|
|
109
|
-
//#region types/basic.d.ts
|
|
110
|
-
/**
|
|
111
|
-
* Controller method reference
|
|
112
|
-
*/
|
|
113
|
-
type ControllerHandler = [any, string];
|
|
114
|
-
/**
|
|
115
|
-
* HTTP methods supported by the router
|
|
116
|
-
*/
|
|
117
|
-
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
118
|
-
/**
|
|
119
|
-
* Common controller action names
|
|
120
|
-
*/
|
|
121
|
-
type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
122
|
-
/**
|
|
123
|
-
* Generic Object type for request data
|
|
124
|
-
*/
|
|
125
|
-
type RequestData = Record<string, any>;
|
|
126
|
-
type ApiResourceMiddleware<M extends Middleware | Middleware$1> = M | M[] | { [K in ControllerAction]?: M | M[] };
|
|
127
|
-
interface RouterConfig {
|
|
128
|
-
/**
|
|
129
|
-
* Configuration for method override functionality, allowing clients to use a
|
|
130
|
-
* specific header or body parameter to override the HTTP method.
|
|
131
|
-
*/
|
|
132
|
-
methodOverride?: {
|
|
133
|
-
/** Whether method override is enabled */enabled?: boolean; /** Keys in the request body to check for method override */
|
|
134
|
-
bodyKeys?: string[] | string; /** Keys in the request headers to check for method override */
|
|
135
|
-
headerKeys?: string[] | string;
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
//#endregion
|
|
139
139
|
//#region src/Controller.d.ts
|
|
140
140
|
declare abstract class Controller<X = any> {
|
|
141
141
|
[x: string]: any;
|
|
@@ -154,6 +154,7 @@ declare abstract class Controller<X = any> {
|
|
|
154
154
|
* @repository https://github.com/toneflix/clear-router
|
|
155
155
|
*/
|
|
156
156
|
declare abstract class CoreRouter {
|
|
157
|
+
protected static createDefaultOptionsHandler(): any;
|
|
157
158
|
static config: RouterConfig;
|
|
158
159
|
protected static groupContext: AsyncLocalStorage<{
|
|
159
160
|
prefix: string;
|
|
@@ -295,7 +296,15 @@ declare abstract class CoreRouter {
|
|
|
295
296
|
* @param this
|
|
296
297
|
*/
|
|
297
298
|
static allRoutes(this: any): Array<Route<any, any, any>>;
|
|
299
|
+
/**
|
|
300
|
+
* @param this
|
|
301
|
+
* @param type - 'path' to get routes organized by path
|
|
302
|
+
*/
|
|
298
303
|
static allRoutes(this: any, type: 'path'): Record<string, Route<any, any, any>>;
|
|
304
|
+
/**
|
|
305
|
+
* @param this
|
|
306
|
+
* @param type - 'method' to get routes organized by method
|
|
307
|
+
*/
|
|
299
308
|
static allRoutes(this: any, type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
|
|
300
309
|
protected static resolveHandler(route: Route<any, any, any>): {
|
|
301
310
|
handlerFunction: ((ctx: any, req: ClearRequest) => any | Promise<any>) | null;
|
|
@@ -308,4 +317,4 @@ declare abstract class CoreRouter {
|
|
|
308
317
|
}): void;
|
|
309
318
|
}
|
|
310
319
|
//#endregion
|
|
311
|
-
export { Handler as a,
|
|
320
|
+
export { Handler as a, Handler$1 as c, ApiResourceMiddleware as d, ControllerAction as f, H3App as i, HttpContext$1 as l, HttpMethod as m, ClearRequest as n, HttpContext as o, ControllerHandler as p, Route as r, Middleware as s, CoreRouter as t, Middleware$1 as u };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { RequestData } from "../types/basic.mjs";
|
|
1
2
|
import { Middleware } from "../types/h3.mjs";
|
|
2
3
|
import { Route } from "./Route.mjs";
|
|
3
4
|
import { Middleware as Middleware$1 } from "../types/express.mjs";
|
|
4
|
-
import { RequestData } from "../types/basic.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/ClearRequest.d.ts
|
|
7
7
|
declare class ClearRequest<X = any, M = Middleware | Middleware$1> {
|
package/dist/types/Route.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { HttpMethod, RequestData } from "../types/basic.mjs";
|
|
1
2
|
import { Middleware } from "../types/h3.mjs";
|
|
2
3
|
import { ClearRequest } from "./ClearRequest.mjs";
|
|
3
4
|
import { Middleware as Middleware$1 } from "../types/express.mjs";
|
|
4
|
-
import { HttpMethod, RequestData } from "../types/basic.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/Route.d.ts
|
|
7
7
|
declare class Route<X = any, M = Middleware | Middleware$1, H = any> {
|
package/dist/types/basic.d.mts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { Middleware } from "./h3.mjs";
|
|
2
|
-
import { Middleware as Middleware$1 } from "./express.mjs";
|
|
3
|
-
|
|
4
1
|
//#region types/basic.d.ts
|
|
5
2
|
/**
|
|
6
3
|
* Controller method reference
|
|
@@ -18,7 +15,7 @@ type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
|
18
15
|
* Generic Object type for request data
|
|
19
16
|
*/
|
|
20
17
|
type RequestData = Record<string, any>;
|
|
21
|
-
type ApiResourceMiddleware<M
|
|
18
|
+
type ApiResourceMiddleware<M = any> = M | M[] | { [K in ControllerAction]?: M | M[] };
|
|
22
19
|
interface RouterConfig {
|
|
23
20
|
/**
|
|
24
21
|
* Configuration for method override functionality, allowing clients to use a
|
package/dist/types/express.d.mts
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ControllerHandler } from "./basic.mjs";
|
|
2
|
+
import { ClearRequest } from "./ClearRequest.mjs";
|
|
3
|
+
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
4
|
+
|
|
5
|
+
//#region types/fastify.d.ts
|
|
6
|
+
interface RequestWithGetBody extends FastifyRequest {
|
|
7
|
+
getBody: () => Record<string, any>;
|
|
8
|
+
}
|
|
9
|
+
interface HttpContext {
|
|
10
|
+
req: RequestWithGetBody;
|
|
11
|
+
reply: FastifyReply;
|
|
12
|
+
}
|
|
13
|
+
type RouteHandler = (ctx: HttpContext, req: ClearRequest) => any | Promise<any>;
|
|
14
|
+
type Handler = RouteHandler | ControllerHandler;
|
|
15
|
+
type NextFunction = (err?: Error) => void;
|
|
16
|
+
type Middleware = (req: RequestWithGetBody, reply: FastifyReply, next: NextFunction) => any | Promise<any>;
|
|
17
|
+
type FastifyApp = FastifyInstance;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { FastifyApp, Handler, HttpContext, Middleware, NextFunction, RequestWithGetBody, RouteHandler };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/types/h3.d.mts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ControllerHandler } from "./basic.mjs";
|
|
2
|
+
import { ClearRequest } from "./ClearRequest.mjs";
|
|
3
|
+
import { Context, HonoRequest, MiddlewareHandler } from "hono";
|
|
4
|
+
|
|
5
|
+
//#region types/hono.d.ts
|
|
6
|
+
type RequestWithGetBody = HonoRequest & {
|
|
7
|
+
getBody: () => Record<string, any>;
|
|
8
|
+
};
|
|
9
|
+
type HttpContext = Context & {
|
|
10
|
+
req: RequestWithGetBody;
|
|
11
|
+
};
|
|
12
|
+
type RouteHandler = (ctx: HttpContext, req: ClearRequest) => any | Promise<any>;
|
|
13
|
+
type Handler = RouteHandler | ControllerHandler;
|
|
14
|
+
type NextFunction = () => Promise<void>;
|
|
15
|
+
type Middleware = MiddlewareHandler;
|
|
16
|
+
type HonoApp = { [K in 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head']: (path: string, ...handlers: Middleware[]) => any };
|
|
17
|
+
//#endregion
|
|
18
|
+
export { Handler, HonoApp, HttpContext, Middleware, NextFunction, RequestWithGetBody, RouteHandler };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clear-router",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Laravel-style routing
|
|
3
|
+
"version": "2.3.1",
|
|
4
|
+
"description": "Laravel-style routing for Node.js with support for Express, H3, Fastify, and Hono, including CommonJS, ESM, and TypeScript support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"h3",
|
|
7
7
|
"srvx",
|
|
@@ -44,13 +44,23 @@
|
|
|
44
44
|
"import": "./dist/express/index.mjs",
|
|
45
45
|
"require": "./dist/express/index.cjs"
|
|
46
46
|
},
|
|
47
|
+
"./fastify": {
|
|
48
|
+
"import": "./dist/fastify/index.mjs",
|
|
49
|
+
"require": "./dist/fastify/index.cjs"
|
|
50
|
+
},
|
|
47
51
|
"./h3": {
|
|
48
52
|
"import": "./dist/h3/index.mjs",
|
|
49
53
|
"require": "./dist/h3/index.cjs"
|
|
50
54
|
},
|
|
55
|
+
"./hono": {
|
|
56
|
+
"import": "./dist/hono/index.mjs",
|
|
57
|
+
"require": "./dist/hono/index.cjs"
|
|
58
|
+
},
|
|
51
59
|
"./types/basic": "./dist/types/basic.mjs",
|
|
52
60
|
"./types/express": "./dist/types/express.mjs",
|
|
61
|
+
"./types/fastify": "./dist/types/fastify.mjs",
|
|
53
62
|
"./types/h3": "./dist/types/h3.mjs",
|
|
63
|
+
"./types/hono": "./dist/types/hono.mjs",
|
|
54
64
|
"./package.json": "./package.json"
|
|
55
65
|
},
|
|
56
66
|
"files": [
|
|
@@ -60,14 +70,22 @@
|
|
|
60
70
|
],
|
|
61
71
|
"peerDependencies": {
|
|
62
72
|
"express": "^5.1.0",
|
|
63
|
-
"
|
|
73
|
+
"fastify": "^5.0.0",
|
|
74
|
+
"h3": "^2.0.1-rc.16",
|
|
75
|
+
"hono": "^4.0.0"
|
|
64
76
|
},
|
|
65
77
|
"peerDependenciesMeta": {
|
|
66
78
|
"express": {
|
|
67
79
|
"optional": true
|
|
68
80
|
},
|
|
81
|
+
"fastify": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
69
84
|
"h3": {
|
|
70
85
|
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"hono": {
|
|
88
|
+
"optional": true
|
|
71
89
|
}
|
|
72
90
|
},
|
|
73
91
|
"devDependencies": {
|
|
@@ -78,6 +96,8 @@
|
|
|
78
96
|
"@types/supertest": "^6.0.3",
|
|
79
97
|
"@vitest/coverage-v8": "4.0.18",
|
|
80
98
|
"eslint": "^10.0.2",
|
|
99
|
+
"fastify": "^5.8.2",
|
|
100
|
+
"hono": "^4.12.8",
|
|
81
101
|
"supertest": "^7.1.1",
|
|
82
102
|
"tsdown": "^0.20.3",
|
|
83
103
|
"tsx": "^4.21.0",
|