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
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { NextFunction, Request, Response as Response$1 } from "express";
|
|
2
|
+
import { H3, H3Event, Middleware as Middleware$1, TypedServerRequest } from "h3";
|
|
3
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
|
+
|
|
5
|
+
//#region types/h3.d.ts
|
|
6
|
+
type H3App = Omit<H3['fetch'], 'fetch'> & {
|
|
7
|
+
fetch: (request: TypedServerRequest) => Promise<Response>;
|
|
8
|
+
};
|
|
9
|
+
type HttpRequest = H3Event['req'] & {
|
|
10
|
+
getBody: () => Record<string, any>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* HTTP context passed to route handlers
|
|
14
|
+
*/
|
|
15
|
+
type HttpContext$1 = Omit<H3Event, 'req'> & {
|
|
16
|
+
req: HttpRequest;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Route handler function type
|
|
20
|
+
*/
|
|
21
|
+
type RouteHandler$1 = (
|
|
22
|
+
/**
|
|
23
|
+
* H3 event context
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
ctx: HttpContext$1,
|
|
27
|
+
/**
|
|
28
|
+
* ClearRequest instance
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
req: ClearRequest) => any | Promise<any>;
|
|
32
|
+
/**
|
|
33
|
+
* Handler can be either a function or controller reference
|
|
34
|
+
*/
|
|
35
|
+
type Handler$1 = RouteHandler$1 | ControllerHandler;
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/Route.d.ts
|
|
38
|
+
declare class Route<X = any, M = Middleware$1 | Middleware, H = any> {
|
|
39
|
+
ctx: X;
|
|
40
|
+
body: RequestData;
|
|
41
|
+
query: RequestData;
|
|
42
|
+
params: RequestData;
|
|
43
|
+
clearRequest: ClearRequest;
|
|
44
|
+
methods: HttpMethod[];
|
|
45
|
+
path: string;
|
|
46
|
+
handler: H;
|
|
47
|
+
middlewares: M[];
|
|
48
|
+
controllerName?: string;
|
|
49
|
+
actionName?: string;
|
|
50
|
+
handlerType: 'function' | 'controller';
|
|
51
|
+
middlewareCount: number;
|
|
52
|
+
constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[]);
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/ClearRequest.d.ts
|
|
56
|
+
declare class ClearRequest<X = any, M = Middleware$1 | Middleware> {
|
|
57
|
+
[key: string]: any;
|
|
58
|
+
/**
|
|
59
|
+
* @param body - Parsed request body
|
|
60
|
+
*/
|
|
61
|
+
body: RequestData;
|
|
62
|
+
/**
|
|
63
|
+
* @param query - Parsed query parameters
|
|
64
|
+
*/
|
|
65
|
+
query: RequestData;
|
|
66
|
+
/**
|
|
67
|
+
* @param params - Parsed route parameters
|
|
68
|
+
*/
|
|
69
|
+
params: RequestData;
|
|
70
|
+
route: Route<X, M>;
|
|
71
|
+
constructor(init?: Partial<ClearRequest>);
|
|
72
|
+
}
|
|
73
|
+
//#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
|
+
//#region src/Controller.d.ts
|
|
140
|
+
declare abstract class Controller<X = any> {
|
|
141
|
+
[x: string]: any;
|
|
142
|
+
ctx: X;
|
|
143
|
+
body: RequestData;
|
|
144
|
+
query: RequestData;
|
|
145
|
+
params: RequestData;
|
|
146
|
+
clearRequest: ClearRequest;
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/core/router.d.ts
|
|
150
|
+
/**
|
|
151
|
+
* @class clear-router CoreRouter
|
|
152
|
+
* @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
|
|
153
|
+
* @author 3m1n3nc3
|
|
154
|
+
* @repository https://github.com/toneflix/clear-router
|
|
155
|
+
*/
|
|
156
|
+
declare abstract class CoreRouter {
|
|
157
|
+
static config: RouterConfig;
|
|
158
|
+
protected static groupContext: AsyncLocalStorage<{
|
|
159
|
+
prefix: string;
|
|
160
|
+
groupMiddlewares: any[];
|
|
161
|
+
}>;
|
|
162
|
+
static routes: Array<Route<any, any, any>>;
|
|
163
|
+
static routesByPathMethod: Record<string, Route<any, any, any>>;
|
|
164
|
+
static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
|
|
165
|
+
static prefix: string;
|
|
166
|
+
static groupMiddlewares: any[];
|
|
167
|
+
static globalMiddlewares: any[];
|
|
168
|
+
protected static ensureState(this: any): void;
|
|
169
|
+
/**
|
|
170
|
+
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
171
|
+
* slashes, while preserving dynamic segments and parameters.
|
|
172
|
+
*
|
|
173
|
+
* @param path The path to normalize.
|
|
174
|
+
* @returns The normalized path.
|
|
175
|
+
*/
|
|
176
|
+
static normalizePath(path: string): string;
|
|
177
|
+
/**
|
|
178
|
+
* Configures the router with the given options, such as method override settings.
|
|
179
|
+
*
|
|
180
|
+
* @param this
|
|
181
|
+
* @param options
|
|
182
|
+
* @returns
|
|
183
|
+
*/
|
|
184
|
+
static configure(this: any, options?: RouterConfig): void;
|
|
185
|
+
protected static resolveMethodOverride(this: any, method: string, headers: Headers | Record<string, any>, body: unknown): HttpMethod | null;
|
|
186
|
+
/**
|
|
187
|
+
* Adds a new route to the router with the specified methods, path, handler, and middlewares.
|
|
188
|
+
*
|
|
189
|
+
* @param this
|
|
190
|
+
* @param methods
|
|
191
|
+
* @param path
|
|
192
|
+
* @param handler
|
|
193
|
+
* @param middlewares
|
|
194
|
+
*/
|
|
195
|
+
static add(this: any, methods: HttpMethod | HttpMethod[], path: string, handler: any, middlewares?: any[] | any): void;
|
|
196
|
+
/**
|
|
197
|
+
* Adds a new API resource route to the router for the specified base path and controller, with
|
|
198
|
+
* options to include/exclude specific actions and apply middlewares.
|
|
199
|
+
*
|
|
200
|
+
* @param this
|
|
201
|
+
* @param basePath
|
|
202
|
+
* @param controller
|
|
203
|
+
* @param options
|
|
204
|
+
*/
|
|
205
|
+
static apiResource(this: any, basePath: string, controller: any, options?: {
|
|
206
|
+
only?: ControllerAction[];
|
|
207
|
+
except?: ControllerAction[];
|
|
208
|
+
middlewares?: ApiResourceMiddleware<any>;
|
|
209
|
+
}): void;
|
|
210
|
+
/**
|
|
211
|
+
* Adds a new GET route to the router with the specified path, handler, and optional middlewares.
|
|
212
|
+
*
|
|
213
|
+
* @param this The router instance.
|
|
214
|
+
* @param path The path for the GET route.
|
|
215
|
+
* @param handler The handler function for the GET route.
|
|
216
|
+
* @param middlewares Optional middlewares to apply to the GET route.
|
|
217
|
+
*/
|
|
218
|
+
static get(this: any, path: string, handler: any, middlewares?: any[] | any): void;
|
|
219
|
+
/**
|
|
220
|
+
* Adds a new POST route to the router with the specified path, handler, and optional middlewares.
|
|
221
|
+
*
|
|
222
|
+
* @param this
|
|
223
|
+
* @param path
|
|
224
|
+
* @param handler
|
|
225
|
+
* @param middlewares
|
|
226
|
+
*/
|
|
227
|
+
static post(this: any, path: string, handler: any, middlewares?: any[] | any): void;
|
|
228
|
+
/**
|
|
229
|
+
* Adds a new PUT route to the router with the specified path, handler, and optional middlewares.
|
|
230
|
+
*
|
|
231
|
+
* @param this
|
|
232
|
+
* @param path
|
|
233
|
+
* @param handler
|
|
234
|
+
* @param middlewares
|
|
235
|
+
*/
|
|
236
|
+
static put(this: any, path: string, handler: any, middlewares?: any[] | any): void;
|
|
237
|
+
/**
|
|
238
|
+
* Adds a new DELETE route to the router with the specified path, handler, and optional middlewares.
|
|
239
|
+
*
|
|
240
|
+
* @param this
|
|
241
|
+
* @param path
|
|
242
|
+
* @param handler
|
|
243
|
+
* @param middlewares
|
|
244
|
+
*/
|
|
245
|
+
static delete(this: any, path: string, handler: any, middlewares?: any[] | any): void;
|
|
246
|
+
/**
|
|
247
|
+
* Adds a new PATCH route to the router with the specified path, handler, and optional middlewares.
|
|
248
|
+
*
|
|
249
|
+
* @param this
|
|
250
|
+
* @param path
|
|
251
|
+
* @param handler
|
|
252
|
+
* @param middlewares
|
|
253
|
+
*/
|
|
254
|
+
static patch(this: any, path: string, handler: any, middlewares?: any[] | any): void;
|
|
255
|
+
/**
|
|
256
|
+
* Adds a new OPTIONS route to the router with the specified path, handler, and optional middlewares.
|
|
257
|
+
*
|
|
258
|
+
* @param this
|
|
259
|
+
* @param path
|
|
260
|
+
* @param handler
|
|
261
|
+
* @param middlewares
|
|
262
|
+
*/
|
|
263
|
+
static options(this: any, path: string, handler: any, middlewares?: any[] | any): void;
|
|
264
|
+
/**
|
|
265
|
+
* Adds a new HEAD route to the router with the specified path, handler, and optional middlewares.
|
|
266
|
+
*
|
|
267
|
+
* @param this
|
|
268
|
+
* @param path
|
|
269
|
+
* @param handler
|
|
270
|
+
* @param middlewares
|
|
271
|
+
*/
|
|
272
|
+
static head(this: any, path: string, handler: any, middlewares?: any[] | any): void;
|
|
273
|
+
/**
|
|
274
|
+
* Defines a group of routes with a common prefix and optional middlewares, allowing for better
|
|
275
|
+
* organization and reuse of route configurations.
|
|
276
|
+
*
|
|
277
|
+
* @param this
|
|
278
|
+
* @param prefix
|
|
279
|
+
* @param callback
|
|
280
|
+
* @param middlewares
|
|
281
|
+
*/
|
|
282
|
+
static group(this: any, prefix: string, callback: () => void | Promise<void>, middlewares?: any[]): Promise<void>;
|
|
283
|
+
/**
|
|
284
|
+
* Adds global middlewares to the router, which will be applied to all routes.
|
|
285
|
+
*
|
|
286
|
+
* @param this
|
|
287
|
+
* @param middlewares
|
|
288
|
+
* @param callback
|
|
289
|
+
*/
|
|
290
|
+
static middleware(this: any, middlewares: any[], callback: () => void): void;
|
|
291
|
+
/**
|
|
292
|
+
* Retrieves all registered routes in the router, optionally organized by path or method
|
|
293
|
+
* for easier access and management.
|
|
294
|
+
*
|
|
295
|
+
* @param this
|
|
296
|
+
*/
|
|
297
|
+
static allRoutes(this: any): Array<Route<any, any, any>>;
|
|
298
|
+
static allRoutes(this: any, type: 'path'): Record<string, Route<any, any, any>>;
|
|
299
|
+
static allRoutes(this: any, type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
|
|
300
|
+
protected static resolveHandler(route: Route<any, any, any>): {
|
|
301
|
+
handlerFunction: ((ctx: any, req: ClearRequest) => any | Promise<any>) | null;
|
|
302
|
+
instance: Controller<any> | null;
|
|
303
|
+
};
|
|
304
|
+
protected static bindRequestToInstance(ctx: any, instance: Controller<any> | Route<any, any, any> | null, route: Route<any, any, any>, payload: {
|
|
305
|
+
body: Record<string, any>;
|
|
306
|
+
query: Record<string, any>;
|
|
307
|
+
params: Record<string, any>;
|
|
308
|
+
}): void;
|
|
309
|
+
}
|
|
310
|
+
//#endregion
|
|
311
|
+
export { Handler as a, Route as c, HttpContext$1 as d, Middleware$1 as f, HttpMethod as i, H3App as l, ApiResourceMiddleware as n, HttpContext as o, ControllerAction as r, Middleware as s, CoreRouter as t, Handler$1 as u };
|
package/dist/types/Route.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Middleware } from "../types/h3.mjs";
|
|
2
2
|
import { ClearRequest } from "./ClearRequest.mjs";
|
|
3
3
|
import { Middleware as Middleware$1 } from "../types/express.mjs";
|
|
4
4
|
import { HttpMethod, RequestData } from "../types/basic.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/Route.d.ts
|
|
7
|
-
declare class Route<X = any, M = Middleware | Middleware$1> {
|
|
7
|
+
declare class Route<X = any, M = Middleware | Middleware$1, H = any> {
|
|
8
8
|
ctx: X;
|
|
9
9
|
body: RequestData;
|
|
10
10
|
query: RequestData;
|
|
@@ -12,13 +12,13 @@ declare class Route<X = any, M = Middleware | Middleware$1> {
|
|
|
12
12
|
clearRequest: ClearRequest;
|
|
13
13
|
methods: HttpMethod[];
|
|
14
14
|
path: string;
|
|
15
|
-
handler:
|
|
15
|
+
handler: H;
|
|
16
16
|
middlewares: M[];
|
|
17
17
|
controllerName?: string;
|
|
18
18
|
actionName?: string;
|
|
19
19
|
handlerType: 'function' | 'controller';
|
|
20
20
|
middlewareCount: number;
|
|
21
|
-
constructor(methods: HttpMethod[], path: string, handler:
|
|
21
|
+
constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[]);
|
|
22
22
|
}
|
|
23
23
|
//#endregion
|
|
24
24
|
export { Route };
|
package/dist/types/express.d.mts
CHANGED
|
@@ -3,11 +3,14 @@ import { ControllerHandler } from "./basic.mjs";
|
|
|
3
3
|
import { NextFunction, Request, Response } from "express";
|
|
4
4
|
|
|
5
5
|
//#region types/express.d.ts
|
|
6
|
+
interface RequestWithGetBody extends Request {
|
|
7
|
+
getBody: () => Record<string, any>;
|
|
8
|
+
}
|
|
6
9
|
/**
|
|
7
10
|
* HTTP context passed to route handlers
|
|
8
11
|
*/
|
|
9
12
|
interface HttpContext {
|
|
10
|
-
req:
|
|
13
|
+
req: RequestWithGetBody;
|
|
11
14
|
res: Response;
|
|
12
15
|
next: NextFunction;
|
|
13
16
|
}
|
|
@@ -34,4 +37,4 @@ type Handler = RouteHandler | ControllerHandler;
|
|
|
34
37
|
*/
|
|
35
38
|
type Middleware = (req: Request, res: Response, next: NextFunction) => any | Promise<any>;
|
|
36
39
|
//#endregion
|
|
37
|
-
export { Handler, HttpContext, Middleware, RouteHandler };
|
|
40
|
+
export { Handler, HttpContext, Middleware, RequestWithGetBody, RouteHandler };
|
package/dist/types/h3.d.mts
CHANGED
|
@@ -7,10 +7,15 @@ type H3App = Omit<H3['fetch'], 'fetch'> & {
|
|
|
7
7
|
fetch: (request: TypedServerRequest) => Promise<Response>;
|
|
8
8
|
};
|
|
9
9
|
type MaybePromise<T = unknown> = T | Promise<T>;
|
|
10
|
+
type HttpRequest = H3Event['req'] & {
|
|
11
|
+
getBody: () => Record<string, any>;
|
|
12
|
+
};
|
|
10
13
|
/**
|
|
11
14
|
* HTTP context passed to route handlers
|
|
12
15
|
*/
|
|
13
|
-
type HttpContext = H3Event & {
|
|
16
|
+
type HttpContext = Omit<H3Event, 'req'> & {
|
|
17
|
+
req: HttpRequest;
|
|
18
|
+
};
|
|
14
19
|
/**
|
|
15
20
|
* Route handler function type
|
|
16
21
|
*/
|
|
@@ -31,4 +36,4 @@ req: ClearRequest) => any | Promise<any>;
|
|
|
31
36
|
type Handler = RouteHandler | ControllerHandler;
|
|
32
37
|
type NextFunction = () => MaybePromise<unknown | undefined>;
|
|
33
38
|
//#endregion
|
|
34
|
-
export { H3App, Handler, HttpContext, MaybePromise, type Middleware, NextFunction, RouteHandler };
|
|
39
|
+
export { H3App, Handler, HttpContext, HttpRequest, MaybePromise, type Middleware, NextFunction, RouteHandler };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clear-router",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Laravel-style routing system for Express.js and H3, with CommonJS, ESM, and TypeScript support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"h3",
|
|
@@ -36,6 +36,10 @@
|
|
|
36
36
|
"import": "./dist/index.mjs",
|
|
37
37
|
"require": "./dist/index.cjs"
|
|
38
38
|
},
|
|
39
|
+
"./core": {
|
|
40
|
+
"import": "./dist/core/index.mjs",
|
|
41
|
+
"require": "./dist/core/index.cjs"
|
|
42
|
+
},
|
|
39
43
|
"./express": {
|
|
40
44
|
"import": "./dist/express/index.mjs",
|
|
41
45
|
"require": "./dist/express/index.cjs"
|
|
@@ -56,7 +60,7 @@
|
|
|
56
60
|
],
|
|
57
61
|
"peerDependencies": {
|
|
58
62
|
"express": "^5.1.0",
|
|
59
|
-
"h3": "2.0.1-rc.
|
|
63
|
+
"h3": "^2.0.1-rc.16"
|
|
60
64
|
},
|
|
61
65
|
"peerDependenciesMeta": {
|
|
62
66
|
"express": {
|
|
@@ -80,6 +84,7 @@
|
|
|
80
84
|
"typescript": "^5.3.3",
|
|
81
85
|
"typescript-eslint": "^8.56.1",
|
|
82
86
|
"vite-tsconfig-paths": "^6.1.1",
|
|
87
|
+
"vitepress": "^1.6.4",
|
|
83
88
|
"vitest": "^4.0.18"
|
|
84
89
|
},
|
|
85
90
|
"engines": {
|
|
@@ -88,6 +93,9 @@
|
|
|
88
93
|
"scripts": {
|
|
89
94
|
"test": "vitest",
|
|
90
95
|
"lint": "eslint",
|
|
96
|
+
"docs:dev": "vitepress dev docs",
|
|
97
|
+
"docs:build": "vitepress build docs",
|
|
98
|
+
"docs:preview": "vitepress preview docs",
|
|
91
99
|
"test:esm": "vitest tests/esm.test.ts",
|
|
92
100
|
"test:ts": "vitest tests/typescript.test.ts",
|
|
93
101
|
"test:coverage": "vitest run --coverage",
|
package/dist/Route-BbPXcDGX.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
//#region src/ClearRequest.ts
|
|
2
|
-
var ClearRequest = class {
|
|
3
|
-
/**
|
|
4
|
-
* @param body - Parsed request body
|
|
5
|
-
*/
|
|
6
|
-
body;
|
|
7
|
-
/**
|
|
8
|
-
* @param query - Parsed query parameters
|
|
9
|
-
*/
|
|
10
|
-
query;
|
|
11
|
-
/**
|
|
12
|
-
* @param params - Parsed route parameters
|
|
13
|
-
*/
|
|
14
|
-
params;
|
|
15
|
-
route;
|
|
16
|
-
constructor(init) {
|
|
17
|
-
Object.assign(this, init);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/Route.ts
|
|
23
|
-
var Route = class {
|
|
24
|
-
ctx;
|
|
25
|
-
body = {};
|
|
26
|
-
query = {};
|
|
27
|
-
params = {};
|
|
28
|
-
clearRequest;
|
|
29
|
-
methods;
|
|
30
|
-
path;
|
|
31
|
-
handler;
|
|
32
|
-
middlewares;
|
|
33
|
-
controllerName;
|
|
34
|
-
actionName;
|
|
35
|
-
handlerType;
|
|
36
|
-
middlewareCount;
|
|
37
|
-
constructor(methods, path, handler, middlewares = []) {
|
|
38
|
-
this.methods = methods;
|
|
39
|
-
this.path = path;
|
|
40
|
-
this.handler = handler;
|
|
41
|
-
this.middlewares = middlewares;
|
|
42
|
-
this.handlerType = Array.isArray(handler) ? "controller" : "function";
|
|
43
|
-
this.middlewareCount = middlewares.length;
|
|
44
|
-
this.controllerName = Array.isArray(handler) ? handler[0]?.name : void 0;
|
|
45
|
-
this.actionName = Array.isArray(handler) ? handler[1] : typeof handler === "function" ? handler.constructor.name ?? handler.name : void 0;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
//#endregion
|
|
50
|
-
export { ClearRequest as n, Route as t };
|
package/dist/Route-DhC4kNPX.cjs
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/ClearRequest.ts
|
|
3
|
-
var ClearRequest = class {
|
|
4
|
-
/**
|
|
5
|
-
* @param body - Parsed request body
|
|
6
|
-
*/
|
|
7
|
-
body;
|
|
8
|
-
/**
|
|
9
|
-
* @param query - Parsed query parameters
|
|
10
|
-
*/
|
|
11
|
-
query;
|
|
12
|
-
/**
|
|
13
|
-
* @param params - Parsed route parameters
|
|
14
|
-
*/
|
|
15
|
-
params;
|
|
16
|
-
route;
|
|
17
|
-
constructor(init) {
|
|
18
|
-
Object.assign(this, init);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/Route.ts
|
|
24
|
-
var Route = class {
|
|
25
|
-
ctx;
|
|
26
|
-
body = {};
|
|
27
|
-
query = {};
|
|
28
|
-
params = {};
|
|
29
|
-
clearRequest;
|
|
30
|
-
methods;
|
|
31
|
-
path;
|
|
32
|
-
handler;
|
|
33
|
-
middlewares;
|
|
34
|
-
controllerName;
|
|
35
|
-
actionName;
|
|
36
|
-
handlerType;
|
|
37
|
-
middlewareCount;
|
|
38
|
-
constructor(methods, path, handler, middlewares = []) {
|
|
39
|
-
this.methods = methods;
|
|
40
|
-
this.path = path;
|
|
41
|
-
this.handler = handler;
|
|
42
|
-
this.middlewares = middlewares;
|
|
43
|
-
this.handlerType = Array.isArray(handler) ? "controller" : "function";
|
|
44
|
-
this.middlewareCount = middlewares.length;
|
|
45
|
-
this.controllerName = Array.isArray(handler) ? handler[0]?.name : void 0;
|
|
46
|
-
this.actionName = Array.isArray(handler) ? handler[1] : typeof handler === "function" ? handler.constructor.name ?? handler.name : void 0;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
//#endregion
|
|
51
|
-
Object.defineProperty(exports, 'ClearRequest', {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function () {
|
|
54
|
-
return ClearRequest;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
Object.defineProperty(exports, 'Route', {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
get: function () {
|
|
60
|
-
return Route;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { NextFunction, Request, Response as Response$1 } from "express";
|
|
2
|
-
import { H3, H3Event, Middleware as Middleware$1, TypedServerRequest } from "h3";
|
|
3
|
-
|
|
4
|
-
//#region types/h3.d.ts
|
|
5
|
-
type H3App = Omit<H3['fetch'], 'fetch'> & {
|
|
6
|
-
fetch: (request: TypedServerRequest) => Promise<Response>;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* HTTP context passed to route handlers
|
|
10
|
-
*/
|
|
11
|
-
type HttpContext$1 = H3Event & {};
|
|
12
|
-
/**
|
|
13
|
-
* Route handler function type
|
|
14
|
-
*/
|
|
15
|
-
type RouteHandler$1 = (
|
|
16
|
-
/**
|
|
17
|
-
* H3 event context
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
ctx: HttpContext$1,
|
|
21
|
-
/**
|
|
22
|
-
* ClearRequest instance
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
req: ClearRequest) => any | Promise<any>;
|
|
26
|
-
/**
|
|
27
|
-
* Handler can be either a function or controller reference
|
|
28
|
-
*/
|
|
29
|
-
type Handler$1 = RouteHandler$1 | ControllerHandler;
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/Route.d.ts
|
|
32
|
-
declare class Route<X = any, M = Middleware$1 | Middleware> {
|
|
33
|
-
ctx: X;
|
|
34
|
-
body: RequestData;
|
|
35
|
-
query: RequestData;
|
|
36
|
-
params: RequestData;
|
|
37
|
-
clearRequest: ClearRequest;
|
|
38
|
-
methods: HttpMethod[];
|
|
39
|
-
path: string;
|
|
40
|
-
handler: Handler$1;
|
|
41
|
-
middlewares: M[];
|
|
42
|
-
controllerName?: string;
|
|
43
|
-
actionName?: string;
|
|
44
|
-
handlerType: 'function' | 'controller';
|
|
45
|
-
middlewareCount: number;
|
|
46
|
-
constructor(methods: HttpMethod[], path: string, handler: Handler$1, middlewares?: M[]);
|
|
47
|
-
}
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/ClearRequest.d.ts
|
|
50
|
-
declare class ClearRequest<X = any, M = Middleware$1 | Middleware> {
|
|
51
|
-
[key: string]: any;
|
|
52
|
-
/**
|
|
53
|
-
* @param body - Parsed request body
|
|
54
|
-
*/
|
|
55
|
-
body: RequestData;
|
|
56
|
-
/**
|
|
57
|
-
* @param query - Parsed query parameters
|
|
58
|
-
*/
|
|
59
|
-
query: RequestData;
|
|
60
|
-
/**
|
|
61
|
-
* @param params - Parsed route parameters
|
|
62
|
-
*/
|
|
63
|
-
params: RequestData;
|
|
64
|
-
route: Route<X, M>;
|
|
65
|
-
constructor(init?: Partial<ClearRequest>);
|
|
66
|
-
}
|
|
67
|
-
//#endregion
|
|
68
|
-
//#region types/express.d.ts
|
|
69
|
-
/**
|
|
70
|
-
* HTTP context passed to route handlers
|
|
71
|
-
*/
|
|
72
|
-
interface HttpContext {
|
|
73
|
-
req: Request;
|
|
74
|
-
res: Response$1;
|
|
75
|
-
next: NextFunction;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Route handler function type
|
|
79
|
-
*/
|
|
80
|
-
type RouteHandler = (
|
|
81
|
-
/**
|
|
82
|
-
* Express context object containing req, res, and next
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
ctx: HttpContext,
|
|
86
|
-
/**
|
|
87
|
-
* ClearRequest instance
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
req: ClearRequest) => any | Promise<any>;
|
|
91
|
-
/**
|
|
92
|
-
* Handler can be either a function or controller reference
|
|
93
|
-
*/
|
|
94
|
-
type Handler = RouteHandler | ControllerHandler;
|
|
95
|
-
/**
|
|
96
|
-
* Middleware function type
|
|
97
|
-
*/
|
|
98
|
-
type Middleware = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
|
|
99
|
-
//#endregion
|
|
100
|
-
//#region types/basic.d.ts
|
|
101
|
-
/**
|
|
102
|
-
* Controller method reference
|
|
103
|
-
*/
|
|
104
|
-
type ControllerHandler = [any, string];
|
|
105
|
-
/**
|
|
106
|
-
* HTTP methods supported by the router
|
|
107
|
-
*/
|
|
108
|
-
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
109
|
-
/**
|
|
110
|
-
* Common controller action names
|
|
111
|
-
*/
|
|
112
|
-
type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
113
|
-
/**
|
|
114
|
-
* Generic Object type for request data
|
|
115
|
-
*/
|
|
116
|
-
type RequestData = Record<string, any>;
|
|
117
|
-
type ApiResourceMiddleware<M extends Middleware | Middleware$1> = M | M[] | { [K in ControllerAction]?: M | M[] };
|
|
118
|
-
interface RouterConfig {
|
|
119
|
-
/**
|
|
120
|
-
* Configuration for method override functionality, allowing clients to use a
|
|
121
|
-
* specific header or body parameter to override the HTTP method.
|
|
122
|
-
*/
|
|
123
|
-
methodOverride?: {
|
|
124
|
-
/** Whether method override is enabled */enabled?: boolean; /** Keys in the request body to check for method override */
|
|
125
|
-
bodyKeys?: string[] | string; /** Keys in the request headers to check for method override */
|
|
126
|
-
headerKeys?: string[] | string;
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
//#endregion
|
|
130
|
-
export { Handler as a, Route as c, HttpContext$1 as d, Middleware$1 as f, RouterConfig as i, H3App as l, ControllerAction as n, HttpContext as o, HttpMethod as r, Middleware as s, ApiResourceMiddleware as t, Handler$1 as u };
|