clear-router 2.1.7 → 2.1.8
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/dist/{express-D9GR9yTH.d.mts → basic-Chn8OGPD.d.cts} +21 -20
- package/dist/{express-JHxK-EqQ.d.cts → basic-DJmmZq1h.d.mts} +21 -20
- package/dist/express/index.cjs +3 -1
- package/dist/express/index.d.cts +10 -9
- package/dist/express/index.d.mts +10 -9
- package/dist/express/index.mjs +3 -1
- package/dist/h3/index.cjs +3 -1
- package/dist/h3/index.d.cts +10 -9
- package/dist/h3/index.d.mts +10 -9
- package/dist/h3/index.mjs +3 -1
- package/dist/index.d.cts +23 -25
- package/dist/index.d.mts +23 -25
- package/dist/types/ClearRequest.d.mts +1 -1
- package/dist/types/Route.d.mts +1 -1
- package/dist/types/basic.d.mts +5 -1
- package/dist/types/express.d.mts +1 -1
- package/dist/types/h3.d.mts +1 -1
- package/package.json +1 -1
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
import { H3, H3Event, Middleware as Middleware$1, TypedServerRequest } from "h3";
|
|
2
1
|
import { NextFunction, Request, Response as Response$1 } from "express";
|
|
2
|
+
import { H3, H3Event, Middleware as Middleware$1, TypedServerRequest } from "h3";
|
|
3
3
|
|
|
4
|
-
//#region types/basic.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Controller method reference
|
|
7
|
-
*/
|
|
8
|
-
type ControllerHandler = [any, string];
|
|
9
|
-
/**
|
|
10
|
-
* HTTP methods supported by the router
|
|
11
|
-
*/
|
|
12
|
-
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
13
|
-
/**
|
|
14
|
-
* Common controller action names
|
|
15
|
-
*/
|
|
16
|
-
type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
17
|
-
/**
|
|
18
|
-
* Generic Object type for request data
|
|
19
|
-
*/
|
|
20
|
-
type RequestData = Record<string, any>;
|
|
21
|
-
//#endregion
|
|
22
4
|
//#region types/h3.d.ts
|
|
23
5
|
type H3App = Omit<H3['fetch'], 'fetch'> & {
|
|
24
6
|
fetch: (request: TypedServerRequest) => Promise<Response>;
|
|
@@ -115,4 +97,23 @@ type Handler = RouteHandler | ControllerHandler;
|
|
|
115
97
|
*/
|
|
116
98
|
type Middleware = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
|
|
117
99
|
//#endregion
|
|
118
|
-
|
|
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
|
+
//#endregion
|
|
119
|
+
export { HttpContext as a, H3App as c, Middleware$1 as d, Handler as i, Handler$1 as l, ControllerAction as n, Middleware as o, HttpMethod as r, Route as s, ApiResourceMiddleware as t, HttpContext$1 as u };
|
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
import { NextFunction, Request, Response as Response$1 } from "express";
|
|
2
1
|
import { H3, H3Event, Middleware as Middleware$1, TypedServerRequest } from "h3";
|
|
2
|
+
import { NextFunction, Request, Response as Response$1 } from "express";
|
|
3
3
|
|
|
4
|
-
//#region types/basic.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Controller method reference
|
|
7
|
-
*/
|
|
8
|
-
type ControllerHandler = [any, string];
|
|
9
|
-
/**
|
|
10
|
-
* HTTP methods supported by the router
|
|
11
|
-
*/
|
|
12
|
-
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
13
|
-
/**
|
|
14
|
-
* Common controller action names
|
|
15
|
-
*/
|
|
16
|
-
type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
17
|
-
/**
|
|
18
|
-
* Generic Object type for request data
|
|
19
|
-
*/
|
|
20
|
-
type RequestData = Record<string, any>;
|
|
21
|
-
//#endregion
|
|
22
4
|
//#region types/h3.d.ts
|
|
23
5
|
type H3App = Omit<H3['fetch'], 'fetch'> & {
|
|
24
6
|
fetch: (request: TypedServerRequest) => Promise<Response>;
|
|
@@ -115,4 +97,23 @@ type Handler = RouteHandler | ControllerHandler;
|
|
|
115
97
|
*/
|
|
116
98
|
type Middleware = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
|
|
117
99
|
//#endregion
|
|
118
|
-
|
|
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
|
+
//#endregion
|
|
119
|
+
export { HttpContext as a, H3App as c, Middleware$1 as d, Handler as i, Handler$1 as l, ControllerAction as n, Middleware as o, HttpMethod as r, Route as s, ApiResourceMiddleware as t, HttpContext$1 as u };
|
package/dist/express/index.cjs
CHANGED
|
@@ -51,6 +51,7 @@ var Router = class Router {
|
|
|
51
51
|
*/
|
|
52
52
|
static add(methods, path, handler, middlewares) {
|
|
53
53
|
methods = Array.isArray(methods) ? methods : [methods];
|
|
54
|
+
middlewares = middlewares ? Array.isArray(middlewares) ? middlewares : [middlewares] : void 0;
|
|
54
55
|
const fullPath = this.normalizePath(`${this.prefix}/${path}`);
|
|
55
56
|
const route = new require_Route.Route(methods.includes("options") ? methods : methods.concat("options"), fullPath, handler, [
|
|
56
57
|
...this.globalMiddlewares,
|
|
@@ -105,7 +106,8 @@ var Router = class Router {
|
|
|
105
106
|
if (except.includes(action)) continue;
|
|
106
107
|
if (typeof preController[action] === "function") {
|
|
107
108
|
const { method, path } = actions[action];
|
|
108
|
-
|
|
109
|
+
const actionMiddlewares = typeof options?.middlewares === "object" && !Array.isArray(options.middlewares) ? options.middlewares[action] : options?.middlewares;
|
|
110
|
+
this.add(method, `${basePath}${path}`, [controller, action], Array.isArray(actionMiddlewares) ? actionMiddlewares : actionMiddlewares ? [actionMiddlewares] : void 0);
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
}
|
package/dist/express/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as
|
|
1
|
+
import { a as HttpContext, i as Handler, n as ControllerAction, o as Middleware, r as HttpMethod, s as Route, t as ApiResourceMiddleware } from "../basic-Chn8OGPD.cjs";
|
|
2
2
|
import { Router as Router$1 } from "express";
|
|
3
3
|
|
|
4
4
|
//#region src/express/router.d.ts
|
|
@@ -47,7 +47,7 @@ declare class Router {
|
|
|
47
47
|
* @param handler - Route handler function or controller reference
|
|
48
48
|
* @param middlewares - Array of middleware functions
|
|
49
49
|
*/
|
|
50
|
-
static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
50
|
+
static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
51
51
|
/**
|
|
52
52
|
* Register RESTful API resource routes for a controller with optional action filtering
|
|
53
53
|
*
|
|
@@ -58,6 +58,7 @@ declare class Router {
|
|
|
58
58
|
static apiResource(basePath: string, controller: any, options?: {
|
|
59
59
|
only?: ControllerAction[];
|
|
60
60
|
except?: ControllerAction[];
|
|
61
|
+
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
61
62
|
}): void;
|
|
62
63
|
/**
|
|
63
64
|
* Register a GET route
|
|
@@ -65,49 +66,49 @@ declare class Router {
|
|
|
65
66
|
* @param handler - Route handler
|
|
66
67
|
* @param middlewares - Middleware functions
|
|
67
68
|
*/
|
|
68
|
-
static get(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
69
|
+
static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
69
70
|
/**
|
|
70
71
|
* Register a POST route
|
|
71
72
|
* @param path - Route path
|
|
72
73
|
* @param handler - Route handler
|
|
73
74
|
* @param middlewares - Middleware functions
|
|
74
75
|
*/
|
|
75
|
-
static post(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
76
|
+
static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
76
77
|
/**
|
|
77
78
|
* Register a PUT route
|
|
78
79
|
* @param path - Route path
|
|
79
80
|
* @param handler - Route handler
|
|
80
81
|
* @param middlewares - Middleware functions
|
|
81
82
|
*/
|
|
82
|
-
static put(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
83
|
+
static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
83
84
|
/**
|
|
84
85
|
* Register a DELETE route
|
|
85
86
|
* @param path - Route path
|
|
86
87
|
* @param handler - Route handler
|
|
87
88
|
* @param middlewares - Middleware functions
|
|
88
89
|
*/
|
|
89
|
-
static delete(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
90
|
+
static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
90
91
|
/**
|
|
91
92
|
* Register a PATCH route
|
|
92
93
|
* @param path - Route path
|
|
93
94
|
* @param handler - Route handler
|
|
94
95
|
* @param middlewares - Middleware functions
|
|
95
96
|
*/
|
|
96
|
-
static patch(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
97
|
+
static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
97
98
|
/**
|
|
98
99
|
* Register an OPTIONS route
|
|
99
100
|
* @param path - Route path
|
|
100
101
|
* @param handler - Route handler
|
|
101
102
|
* @param middlewares - Middleware functions
|
|
102
103
|
*/
|
|
103
|
-
static options(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
104
|
+
static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
104
105
|
/**
|
|
105
106
|
* Register a HEAD route
|
|
106
107
|
* @param path - Route path
|
|
107
108
|
* @param handler - Route handler
|
|
108
109
|
* @param middlewares - Middleware functions
|
|
109
110
|
*/
|
|
110
|
-
static head(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
111
|
+
static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
111
112
|
/**
|
|
112
113
|
* Group routes with a common prefix and middlewares
|
|
113
114
|
* @param prefix - URL prefix for grouped routes
|
package/dist/express/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as
|
|
1
|
+
import { a as HttpContext, i as Handler, n as ControllerAction, o as Middleware, r as HttpMethod, s as Route, t as ApiResourceMiddleware } from "../basic-DJmmZq1h.mjs";
|
|
2
2
|
import { Router as Router$1 } from "express";
|
|
3
3
|
|
|
4
4
|
//#region src/express/router.d.ts
|
|
@@ -47,7 +47,7 @@ declare class Router {
|
|
|
47
47
|
* @param handler - Route handler function or controller reference
|
|
48
48
|
* @param middlewares - Array of middleware functions
|
|
49
49
|
*/
|
|
50
|
-
static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
50
|
+
static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
51
51
|
/**
|
|
52
52
|
* Register RESTful API resource routes for a controller with optional action filtering
|
|
53
53
|
*
|
|
@@ -58,6 +58,7 @@ declare class Router {
|
|
|
58
58
|
static apiResource(basePath: string, controller: any, options?: {
|
|
59
59
|
only?: ControllerAction[];
|
|
60
60
|
except?: ControllerAction[];
|
|
61
|
+
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
61
62
|
}): void;
|
|
62
63
|
/**
|
|
63
64
|
* Register a GET route
|
|
@@ -65,49 +66,49 @@ declare class Router {
|
|
|
65
66
|
* @param handler - Route handler
|
|
66
67
|
* @param middlewares - Middleware functions
|
|
67
68
|
*/
|
|
68
|
-
static get(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
69
|
+
static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
69
70
|
/**
|
|
70
71
|
* Register a POST route
|
|
71
72
|
* @param path - Route path
|
|
72
73
|
* @param handler - Route handler
|
|
73
74
|
* @param middlewares - Middleware functions
|
|
74
75
|
*/
|
|
75
|
-
static post(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
76
|
+
static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
76
77
|
/**
|
|
77
78
|
* Register a PUT route
|
|
78
79
|
* @param path - Route path
|
|
79
80
|
* @param handler - Route handler
|
|
80
81
|
* @param middlewares - Middleware functions
|
|
81
82
|
*/
|
|
82
|
-
static put(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
83
|
+
static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
83
84
|
/**
|
|
84
85
|
* Register a DELETE route
|
|
85
86
|
* @param path - Route path
|
|
86
87
|
* @param handler - Route handler
|
|
87
88
|
* @param middlewares - Middleware functions
|
|
88
89
|
*/
|
|
89
|
-
static delete(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
90
|
+
static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
90
91
|
/**
|
|
91
92
|
* Register a PATCH route
|
|
92
93
|
* @param path - Route path
|
|
93
94
|
* @param handler - Route handler
|
|
94
95
|
* @param middlewares - Middleware functions
|
|
95
96
|
*/
|
|
96
|
-
static patch(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
97
|
+
static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
97
98
|
/**
|
|
98
99
|
* Register an OPTIONS route
|
|
99
100
|
* @param path - Route path
|
|
100
101
|
* @param handler - Route handler
|
|
101
102
|
* @param middlewares - Middleware functions
|
|
102
103
|
*/
|
|
103
|
-
static options(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
104
|
+
static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
104
105
|
/**
|
|
105
106
|
* Register a HEAD route
|
|
106
107
|
* @param path - Route path
|
|
107
108
|
* @param handler - Route handler
|
|
108
109
|
* @param middlewares - Middleware functions
|
|
109
110
|
*/
|
|
110
|
-
static head(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
111
|
+
static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
111
112
|
/**
|
|
112
113
|
* Group routes with a common prefix and middlewares
|
|
113
114
|
* @param prefix - URL prefix for grouped routes
|
package/dist/express/index.mjs
CHANGED
|
@@ -50,6 +50,7 @@ var Router = class Router {
|
|
|
50
50
|
*/
|
|
51
51
|
static add(methods, path, handler, middlewares) {
|
|
52
52
|
methods = Array.isArray(methods) ? methods : [methods];
|
|
53
|
+
middlewares = middlewares ? Array.isArray(middlewares) ? middlewares : [middlewares] : void 0;
|
|
53
54
|
const fullPath = this.normalizePath(`${this.prefix}/${path}`);
|
|
54
55
|
const route = new Route(methods.includes("options") ? methods : methods.concat("options"), fullPath, handler, [
|
|
55
56
|
...this.globalMiddlewares,
|
|
@@ -104,7 +105,8 @@ var Router = class Router {
|
|
|
104
105
|
if (except.includes(action)) continue;
|
|
105
106
|
if (typeof preController[action] === "function") {
|
|
106
107
|
const { method, path } = actions[action];
|
|
107
|
-
|
|
108
|
+
const actionMiddlewares = typeof options?.middlewares === "object" && !Array.isArray(options.middlewares) ? options.middlewares[action] : options?.middlewares;
|
|
109
|
+
this.add(method, `${basePath}${path}`, [controller, action], Array.isArray(actionMiddlewares) ? actionMiddlewares : actionMiddlewares ? [actionMiddlewares] : void 0);
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
112
|
}
|
package/dist/h3/index.cjs
CHANGED
|
@@ -51,6 +51,7 @@ var Router = class Router {
|
|
|
51
51
|
*/
|
|
52
52
|
static add(methods, path, handler, middlewares) {
|
|
53
53
|
methods = Array.isArray(methods) ? methods : [methods];
|
|
54
|
+
middlewares = middlewares ? Array.isArray(middlewares) ? middlewares : [middlewares] : void 0;
|
|
54
55
|
const fullPath = this.normalizePath(`${this.prefix}/${path}`);
|
|
55
56
|
const route = new require_Route.Route(methods.includes("options") ? methods : methods.concat("options"), fullPath, handler, [
|
|
56
57
|
...this.globalMiddlewares,
|
|
@@ -105,7 +106,8 @@ var Router = class Router {
|
|
|
105
106
|
if (except.includes(action)) continue;
|
|
106
107
|
if (typeof preController[action] === "function") {
|
|
107
108
|
const { method, path } = actions[action];
|
|
108
|
-
|
|
109
|
+
const actionMiddlewares = typeof options?.middlewares === "object" && !Array.isArray(options.middlewares) ? options.middlewares[action] : options?.middlewares;
|
|
110
|
+
this.add(method, `${basePath}${path}`, [controller, action], Array.isArray(actionMiddlewares) ? actionMiddlewares : actionMiddlewares ? [actionMiddlewares] : void 0);
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
}
|
package/dist/h3/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as H3App, d as Middleware, l as Handler, n as ControllerAction, r as HttpMethod, s as Route, t as ApiResourceMiddleware, u as HttpContext } from "../basic-Chn8OGPD.cjs";
|
|
2
2
|
import { H3 } from "h3";
|
|
3
3
|
|
|
4
4
|
//#region src/h3/router.d.ts
|
|
@@ -46,7 +46,7 @@ declare class Router {
|
|
|
46
46
|
* @param handler - Route handler function or controller reference
|
|
47
47
|
* @param middlewares - Array of middleware functions
|
|
48
48
|
*/
|
|
49
|
-
static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
49
|
+
static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
50
50
|
/**
|
|
51
51
|
* Register RESTful API resource routes for a controller with optional action filtering
|
|
52
52
|
*
|
|
@@ -57,6 +57,7 @@ declare class Router {
|
|
|
57
57
|
static apiResource(basePath: string, controller: any, options?: {
|
|
58
58
|
only?: ControllerAction[];
|
|
59
59
|
except?: ControllerAction[];
|
|
60
|
+
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
60
61
|
}): void;
|
|
61
62
|
/**
|
|
62
63
|
* Register a GET route
|
|
@@ -64,49 +65,49 @@ declare class Router {
|
|
|
64
65
|
* @param handler - Route handler
|
|
65
66
|
* @param middlewares - Middleware functions
|
|
66
67
|
*/
|
|
67
|
-
static get(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
68
|
+
static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
68
69
|
/**
|
|
69
70
|
* Register a POST route
|
|
70
71
|
* @param path - Route path
|
|
71
72
|
* @param handler - Route handler
|
|
72
73
|
* @param middlewares - Middleware functions
|
|
73
74
|
*/
|
|
74
|
-
static post(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
75
|
+
static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
75
76
|
/**
|
|
76
77
|
* Register a PUT route
|
|
77
78
|
* @param path - Route path
|
|
78
79
|
* @param handler - Route handler
|
|
79
80
|
* @param middlewares - Middleware functions
|
|
80
81
|
*/
|
|
81
|
-
static put(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
82
|
+
static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
82
83
|
/**
|
|
83
84
|
* Register a DELETE route
|
|
84
85
|
* @param path - Route path
|
|
85
86
|
* @param handler - Route handler
|
|
86
87
|
* @param middlewares - Middleware functions
|
|
87
88
|
*/
|
|
88
|
-
static delete(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
89
|
+
static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
89
90
|
/**
|
|
90
91
|
* Register a PATCH route
|
|
91
92
|
* @param path - Route path
|
|
92
93
|
* @param handler - Route handler
|
|
93
94
|
* @param middlewares - Middleware functions
|
|
94
95
|
*/
|
|
95
|
-
static patch(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
96
|
+
static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
96
97
|
/**
|
|
97
98
|
* Register an OPTIONS route
|
|
98
99
|
* @param path - Route path
|
|
99
100
|
* @param handler - Route handler
|
|
100
101
|
* @param middlewares - Middleware functions
|
|
101
102
|
*/
|
|
102
|
-
static options(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
103
|
+
static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
103
104
|
/**
|
|
104
105
|
* Register a HEAD route
|
|
105
106
|
* @param path - Route path
|
|
106
107
|
* @param handler - Route handler
|
|
107
108
|
* @param middlewares - Middleware functions
|
|
108
109
|
*/
|
|
109
|
-
static head(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
110
|
+
static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
110
111
|
/**
|
|
111
112
|
* Group routes with a common prefix and middlewares
|
|
112
113
|
* @param prefix - URL prefix for grouped routes
|
package/dist/h3/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as H3App, d as Middleware, l as Handler, n as ControllerAction, r as HttpMethod, s as Route, t as ApiResourceMiddleware, u as HttpContext } from "../basic-DJmmZq1h.mjs";
|
|
2
2
|
import { H3 } from "h3";
|
|
3
3
|
|
|
4
4
|
//#region src/h3/router.d.ts
|
|
@@ -46,7 +46,7 @@ declare class Router {
|
|
|
46
46
|
* @param handler - Route handler function or controller reference
|
|
47
47
|
* @param middlewares - Array of middleware functions
|
|
48
48
|
*/
|
|
49
|
-
static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
49
|
+
static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
50
50
|
/**
|
|
51
51
|
* Register RESTful API resource routes for a controller with optional action filtering
|
|
52
52
|
*
|
|
@@ -57,6 +57,7 @@ declare class Router {
|
|
|
57
57
|
static apiResource(basePath: string, controller: any, options?: {
|
|
58
58
|
only?: ControllerAction[];
|
|
59
59
|
except?: ControllerAction[];
|
|
60
|
+
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
60
61
|
}): void;
|
|
61
62
|
/**
|
|
62
63
|
* Register a GET route
|
|
@@ -64,49 +65,49 @@ declare class Router {
|
|
|
64
65
|
* @param handler - Route handler
|
|
65
66
|
* @param middlewares - Middleware functions
|
|
66
67
|
*/
|
|
67
|
-
static get(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
68
|
+
static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
68
69
|
/**
|
|
69
70
|
* Register a POST route
|
|
70
71
|
* @param path - Route path
|
|
71
72
|
* @param handler - Route handler
|
|
72
73
|
* @param middlewares - Middleware functions
|
|
73
74
|
*/
|
|
74
|
-
static post(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
75
|
+
static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
75
76
|
/**
|
|
76
77
|
* Register a PUT route
|
|
77
78
|
* @param path - Route path
|
|
78
79
|
* @param handler - Route handler
|
|
79
80
|
* @param middlewares - Middleware functions
|
|
80
81
|
*/
|
|
81
|
-
static put(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
82
|
+
static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
82
83
|
/**
|
|
83
84
|
* Register a DELETE route
|
|
84
85
|
* @param path - Route path
|
|
85
86
|
* @param handler - Route handler
|
|
86
87
|
* @param middlewares - Middleware functions
|
|
87
88
|
*/
|
|
88
|
-
static delete(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
89
|
+
static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
89
90
|
/**
|
|
90
91
|
* Register a PATCH route
|
|
91
92
|
* @param path - Route path
|
|
92
93
|
* @param handler - Route handler
|
|
93
94
|
* @param middlewares - Middleware functions
|
|
94
95
|
*/
|
|
95
|
-
static patch(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
96
|
+
static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
96
97
|
/**
|
|
97
98
|
* Register an OPTIONS route
|
|
98
99
|
* @param path - Route path
|
|
99
100
|
* @param handler - Route handler
|
|
100
101
|
* @param middlewares - Middleware functions
|
|
101
102
|
*/
|
|
102
|
-
static options(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
103
|
+
static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
103
104
|
/**
|
|
104
105
|
* Register a HEAD route
|
|
105
106
|
* @param path - Route path
|
|
106
107
|
* @param handler - Route handler
|
|
107
108
|
* @param middlewares - Middleware functions
|
|
108
109
|
*/
|
|
109
|
-
static head(path: string, handler: Handler, middlewares?: Middleware[]): void;
|
|
110
|
+
static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
|
|
110
111
|
/**
|
|
111
112
|
* Group routes with a common prefix and middlewares
|
|
112
113
|
* @param prefix - URL prefix for grouped routes
|
package/dist/h3/index.mjs
CHANGED
|
@@ -50,6 +50,7 @@ var Router = class Router {
|
|
|
50
50
|
*/
|
|
51
51
|
static add(methods, path, handler, middlewares) {
|
|
52
52
|
methods = Array.isArray(methods) ? methods : [methods];
|
|
53
|
+
middlewares = middlewares ? Array.isArray(middlewares) ? middlewares : [middlewares] : void 0;
|
|
53
54
|
const fullPath = this.normalizePath(`${this.prefix}/${path}`);
|
|
54
55
|
const route = new Route(methods.includes("options") ? methods : methods.concat("options"), fullPath, handler, [
|
|
55
56
|
...this.globalMiddlewares,
|
|
@@ -104,7 +105,8 @@ var Router = class Router {
|
|
|
104
105
|
if (except.includes(action)) continue;
|
|
105
106
|
if (typeof preController[action] === "function") {
|
|
106
107
|
const { method, path } = actions[action];
|
|
107
|
-
|
|
108
|
+
const actionMiddlewares = typeof options?.middlewares === "object" && !Array.isArray(options.middlewares) ? options.middlewares[action] : options?.middlewares;
|
|
109
|
+
this.add(method, `${basePath}${path}`, [controller, action], Array.isArray(actionMiddlewares) ? actionMiddlewares : actionMiddlewares ? [actionMiddlewares] : void 0);
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
112
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
import { NextFunction, Request, Response as Response$1 } from "express";
|
|
2
|
-
import { H3Event, Middleware } from "h3";
|
|
2
|
+
import { H3Event, Middleware as Middleware$1 } from "h3";
|
|
3
3
|
|
|
4
|
-
//#region types/basic.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Controller method reference
|
|
7
|
-
*/
|
|
8
|
-
type ControllerHandler = [any, string];
|
|
9
|
-
/**
|
|
10
|
-
* HTTP methods supported by the router
|
|
11
|
-
*/
|
|
12
|
-
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
13
|
-
/**
|
|
14
|
-
* Generic Object type for request data
|
|
15
|
-
*/
|
|
16
|
-
type RequestData = Record<string, any>;
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region types/express.d.ts
|
|
19
|
-
/**
|
|
20
|
-
* Middleware function type
|
|
21
|
-
*/
|
|
22
|
-
type Middleware$1 = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
|
|
23
|
-
//#endregion
|
|
24
4
|
//#region types/h3.d.ts
|
|
25
5
|
/**
|
|
26
6
|
* HTTP context passed to route handlers
|
|
@@ -33,20 +13,38 @@ type RouteHandler = (
|
|
|
33
13
|
/**
|
|
34
14
|
* H3 event context
|
|
35
15
|
*/
|
|
36
|
-
|
|
37
16
|
ctx: HttpContext,
|
|
38
17
|
/**
|
|
39
18
|
* ClearRequest instance
|
|
40
19
|
*/
|
|
41
|
-
|
|
42
20
|
req: ClearRequest) => any | Promise<any>;
|
|
43
21
|
/**
|
|
44
22
|
* Handler can be either a function or controller reference
|
|
45
23
|
*/
|
|
46
24
|
type Handler = RouteHandler | ControllerHandler;
|
|
47
25
|
//#endregion
|
|
26
|
+
//#region types/basic.d.ts
|
|
27
|
+
/**
|
|
28
|
+
* Controller method reference
|
|
29
|
+
*/
|
|
30
|
+
type ControllerHandler = [any, string];
|
|
31
|
+
/**
|
|
32
|
+
* HTTP methods supported by the router
|
|
33
|
+
*/
|
|
34
|
+
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
35
|
+
/**
|
|
36
|
+
* Generic Object type for request data
|
|
37
|
+
*/
|
|
38
|
+
type RequestData = Record<string, any>;
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region types/express.d.ts
|
|
41
|
+
/**
|
|
42
|
+
* Middleware function type
|
|
43
|
+
*/
|
|
44
|
+
type Middleware = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
|
|
45
|
+
//#endregion
|
|
48
46
|
//#region src/Route.d.ts
|
|
49
|
-
declare class Route<X = any, M = Middleware | Middleware
|
|
47
|
+
declare class Route<X = any, M = Middleware$1 | Middleware> {
|
|
50
48
|
ctx: X;
|
|
51
49
|
body: RequestData;
|
|
52
50
|
query: RequestData;
|
|
@@ -64,7 +62,7 @@ declare class Route<X = any, M = Middleware | Middleware$1> {
|
|
|
64
62
|
}
|
|
65
63
|
//#endregion
|
|
66
64
|
//#region src/ClearRequest.d.ts
|
|
67
|
-
declare class ClearRequest<X = any, M = Middleware | Middleware
|
|
65
|
+
declare class ClearRequest<X = any, M = Middleware$1 | Middleware> {
|
|
68
66
|
[key: string]: any;
|
|
69
67
|
/**
|
|
70
68
|
* @param body - Parsed request body
|
package/dist/index.d.mts
CHANGED
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
import { NextFunction, Request, Response as Response$1 } from "express";
|
|
2
|
-
import { H3Event, Middleware } from "h3";
|
|
2
|
+
import { H3Event, Middleware as Middleware$1 } from "h3";
|
|
3
3
|
|
|
4
|
-
//#region types/basic.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Controller method reference
|
|
7
|
-
*/
|
|
8
|
-
type ControllerHandler = [any, string];
|
|
9
|
-
/**
|
|
10
|
-
* HTTP methods supported by the router
|
|
11
|
-
*/
|
|
12
|
-
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
13
|
-
/**
|
|
14
|
-
* Generic Object type for request data
|
|
15
|
-
*/
|
|
16
|
-
type RequestData = Record<string, any>;
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region types/express.d.ts
|
|
19
|
-
/**
|
|
20
|
-
* Middleware function type
|
|
21
|
-
*/
|
|
22
|
-
type Middleware$1 = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
|
|
23
|
-
//#endregion
|
|
24
4
|
//#region types/h3.d.ts
|
|
25
5
|
/**
|
|
26
6
|
* HTTP context passed to route handlers
|
|
@@ -33,20 +13,38 @@ type RouteHandler = (
|
|
|
33
13
|
/**
|
|
34
14
|
* H3 event context
|
|
35
15
|
*/
|
|
36
|
-
|
|
37
16
|
ctx: HttpContext,
|
|
38
17
|
/**
|
|
39
18
|
* ClearRequest instance
|
|
40
19
|
*/
|
|
41
|
-
|
|
42
20
|
req: ClearRequest) => any | Promise<any>;
|
|
43
21
|
/**
|
|
44
22
|
* Handler can be either a function or controller reference
|
|
45
23
|
*/
|
|
46
24
|
type Handler = RouteHandler | ControllerHandler;
|
|
47
25
|
//#endregion
|
|
26
|
+
//#region types/basic.d.ts
|
|
27
|
+
/**
|
|
28
|
+
* Controller method reference
|
|
29
|
+
*/
|
|
30
|
+
type ControllerHandler = [any, string];
|
|
31
|
+
/**
|
|
32
|
+
* HTTP methods supported by the router
|
|
33
|
+
*/
|
|
34
|
+
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
35
|
+
/**
|
|
36
|
+
* Generic Object type for request data
|
|
37
|
+
*/
|
|
38
|
+
type RequestData = Record<string, any>;
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region types/express.d.ts
|
|
41
|
+
/**
|
|
42
|
+
* Middleware function type
|
|
43
|
+
*/
|
|
44
|
+
type Middleware = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
|
|
45
|
+
//#endregion
|
|
48
46
|
//#region src/Route.d.ts
|
|
49
|
-
declare class Route<X = any, M = Middleware | Middleware
|
|
47
|
+
declare class Route<X = any, M = Middleware$1 | Middleware> {
|
|
50
48
|
ctx: X;
|
|
51
49
|
body: RequestData;
|
|
52
50
|
query: RequestData;
|
|
@@ -64,7 +62,7 @@ declare class Route<X = any, M = Middleware | Middleware$1> {
|
|
|
64
62
|
}
|
|
65
63
|
//#endregion
|
|
66
64
|
//#region src/ClearRequest.d.ts
|
|
67
|
-
declare class ClearRequest<X = any, M = Middleware | Middleware
|
|
65
|
+
declare class ClearRequest<X = any, M = Middleware$1 | Middleware> {
|
|
68
66
|
[key: string]: any;
|
|
69
67
|
/**
|
|
70
68
|
* @param body - Parsed request body
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { RequestData } from "../types/basic.mjs";
|
|
2
1
|
import { Middleware } from "../types/h3.mjs";
|
|
3
2
|
import { Route } from "./Route.mjs";
|
|
4
3
|
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";
|
|
2
1
|
import { Handler, Middleware } from "../types/h3.mjs";
|
|
3
2
|
import { ClearRequest } from "./ClearRequest.mjs";
|
|
4
3
|
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> {
|
package/dist/types/basic.d.mts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Middleware } from "./h3.mjs";
|
|
2
|
+
import { Middleware as Middleware$1 } from "./express.mjs";
|
|
3
|
+
|
|
1
4
|
//#region types/basic.d.ts
|
|
2
5
|
/**
|
|
3
6
|
* Controller method reference
|
|
@@ -15,5 +18,6 @@ type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
|
15
18
|
* Generic Object type for request data
|
|
16
19
|
*/
|
|
17
20
|
type RequestData = Record<string, any>;
|
|
21
|
+
type ApiResourceMiddleware<M extends Middleware$1 | Middleware> = M | M[] | { [K in ControllerAction]?: M | M[] };
|
|
18
22
|
//#endregion
|
|
19
|
-
export { ControllerAction, ControllerHandler, HttpMethod, RequestData };
|
|
23
|
+
export { ApiResourceMiddleware, ControllerAction, ControllerHandler, HttpMethod, RequestData };
|
package/dist/types/express.d.mts
CHANGED
package/dist/types/h3.d.mts
CHANGED