clear-router 2.7.7 → 2.8.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/dist/{Request-BhTJDR_5.d.mts → Request-Ci0UQ-Vl.d.mts} +27 -0
- package/dist/ResourceRouteSelection.cjs +26 -0
- package/dist/ResourceRouteSelection.d.cts +20 -0
- package/dist/ResourceRouteSelection.d.mts +20 -0
- package/dist/ResourceRouteSelection.mjs +25 -0
- package/dist/ResourceRoutes.cjs +150 -0
- package/dist/ResourceRoutes.d.cts +96 -0
- package/dist/ResourceRoutes.d.mts +96 -0
- package/dist/ResourceRoutes.mjs +150 -0
- package/dist/Route.cjs +32 -0
- package/dist/Route.d.cts +27 -0
- package/dist/Route.d.mts +27 -0
- package/dist/Route.mjs +32 -0
- package/dist/core/helpers.cjs +9 -0
- package/dist/core/helpers.d.cts +4 -0
- package/dist/core/helpers.d.mts +4 -0
- package/dist/core/helpers.mjs +8 -0
- package/dist/core/index.cjs +8 -0
- package/dist/core/index.d.cts +2 -1
- package/dist/core/index.d.mts +2 -1
- package/dist/core/index.mjs +2 -1
- package/dist/core/router.cjs +66 -37
- package/dist/core/router.d.cts +17 -4
- package/dist/core/router.d.mts +17 -4
- package/dist/core/router.mjs +66 -37
- package/dist/decorators/setup.d.mts +0 -1
- package/dist/express/router.cjs +2 -2
- package/dist/express/router.d.cts +5 -4
- package/dist/express/router.d.mts +5 -4
- package/dist/express/router.mjs +2 -2
- package/dist/fastify/router.cjs +2 -2
- package/dist/fastify/router.d.cts +5 -4
- package/dist/fastify/router.d.mts +5 -4
- package/dist/fastify/router.mjs +2 -2
- package/dist/h3/router.cjs +2 -2
- package/dist/h3/router.d.cts +22 -21
- package/dist/h3/router.d.mts +22 -21
- package/dist/h3/router.mjs +2 -2
- package/dist/hono/router.cjs +2 -2
- package/dist/hono/router.d.cts +5 -4
- package/dist/hono/router.d.mts +5 -4
- package/dist/hono/router.mjs +2 -2
- package/dist/index.cjs +3 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/koa/router.cjs +2 -2
- package/dist/koa/router.d.cts +5 -4
- package/dist/koa/router.d.mts +5 -4
- package/dist/koa/router.mjs +2 -2
- package/dist/types/basic.d.cts +13 -4
- package/dist/types/basic.d.mts +13 -4
- package/dist/types/express.d.cts +6 -2
- package/dist/types/express.d.mts +6 -2
- package/dist/types/fastify.d.cts +3 -2
- package/dist/types/fastify.d.mts +3 -2
- package/dist/types/h3.d.cts +7 -2
- package/dist/types/h3.d.mts +7 -2
- package/dist/types/hono.d.cts +4 -3
- package/dist/types/hono.d.mts +4 -3
- package/dist/types/koa.d.cts +3 -2
- package/dist/types/koa.d.mts +3 -2
- package/package.json +1 -1
package/dist/express/router.mjs
CHANGED
|
@@ -62,7 +62,7 @@ var Router = class Router extends CoreRouter {
|
|
|
62
62
|
* @param options
|
|
63
63
|
*/
|
|
64
64
|
static apiResource(basePath, controller, options) {
|
|
65
|
-
super.apiResource(basePath, controller, options);
|
|
65
|
+
return super.apiResource(basePath, controller, options);
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Adds a new GET route to the router.
|
|
@@ -160,7 +160,7 @@ var Router = class Router extends CoreRouter {
|
|
|
160
160
|
return super.route(name);
|
|
161
161
|
}
|
|
162
162
|
static async apply(router) {
|
|
163
|
-
for (const route of
|
|
163
|
+
for (const route of this.orderedRoutes()) {
|
|
164
164
|
let handlerFunction = null;
|
|
165
165
|
let instance = null;
|
|
166
166
|
let bindingTarget;
|
package/dist/fastify/router.cjs
CHANGED
|
@@ -55,7 +55,7 @@ var Router = class Router extends require_router.CoreRouter {
|
|
|
55
55
|
* @param options Optional configuration for the resource
|
|
56
56
|
*/
|
|
57
57
|
static apiResource(basePath, controller, options) {
|
|
58
|
-
super.apiResource(basePath, controller, options);
|
|
58
|
+
return super.apiResource(basePath, controller, options);
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Define a GET route
|
|
@@ -159,7 +159,7 @@ var Router = class Router extends require_router.CoreRouter {
|
|
|
159
159
|
* @returns The Fastify application instance with the applied routes
|
|
160
160
|
*/
|
|
161
161
|
static apply(app) {
|
|
162
|
-
for (const route of
|
|
162
|
+
for (const route of this.orderedRoutes()) {
|
|
163
163
|
let handlerFunction = null;
|
|
164
164
|
let instance = null;
|
|
165
165
|
let bindingTarget;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction } from "../types/basic.cjs";
|
|
2
2
|
import { FastifyApp, Handler, HttpContext, Middleware } from "../types/fastify.cjs";
|
|
3
3
|
import { Route } from "../Route.cjs";
|
|
4
|
+
import { ResourceRoutes } from "../ResourceRoutes.cjs";
|
|
4
5
|
import { CoreRouter } from "../core/router.cjs";
|
|
5
6
|
|
|
6
7
|
//#region src/fastify/router.d.ts
|
|
@@ -31,10 +32,10 @@ declare class Router extends CoreRouter {
|
|
|
31
32
|
* @param options Optional configuration for the resource
|
|
32
33
|
*/
|
|
33
34
|
static apiResource(basePath: string, controller: any, options?: {
|
|
34
|
-
only?:
|
|
35
|
-
except?:
|
|
35
|
+
only?: ResourceAction[];
|
|
36
|
+
except?: ResourceAction[];
|
|
36
37
|
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
37
|
-
}):
|
|
38
|
+
}): ResourceRoutes<HttpContext, Middleware, Handler>;
|
|
38
39
|
/**
|
|
39
40
|
* Define a GET route
|
|
40
41
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction } from "../types/basic.mjs";
|
|
2
2
|
import { FastifyApp, Handler, HttpContext, Middleware } from "../types/fastify.mjs";
|
|
3
3
|
import { Route } from "../Route.mjs";
|
|
4
|
+
import { ResourceRoutes } from "../ResourceRoutes.mjs";
|
|
4
5
|
import { CoreRouter } from "../core/router.mjs";
|
|
5
6
|
|
|
6
7
|
//#region src/fastify/router.d.ts
|
|
@@ -31,10 +32,10 @@ declare class Router extends CoreRouter {
|
|
|
31
32
|
* @param options Optional configuration for the resource
|
|
32
33
|
*/
|
|
33
34
|
static apiResource(basePath: string, controller: any, options?: {
|
|
34
|
-
only?:
|
|
35
|
-
except?:
|
|
35
|
+
only?: ResourceAction[];
|
|
36
|
+
except?: ResourceAction[];
|
|
36
37
|
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
37
|
-
}):
|
|
38
|
+
}): ResourceRoutes<HttpContext, Middleware, Handler>;
|
|
38
39
|
/**
|
|
39
40
|
* Define a GET route
|
|
40
41
|
*
|
package/dist/fastify/router.mjs
CHANGED
|
@@ -55,7 +55,7 @@ var Router = class Router extends CoreRouter {
|
|
|
55
55
|
* @param options Optional configuration for the resource
|
|
56
56
|
*/
|
|
57
57
|
static apiResource(basePath, controller, options) {
|
|
58
|
-
super.apiResource(basePath, controller, options);
|
|
58
|
+
return super.apiResource(basePath, controller, options);
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* Define a GET route
|
|
@@ -159,7 +159,7 @@ var Router = class Router extends CoreRouter {
|
|
|
159
159
|
* @returns The Fastify application instance with the applied routes
|
|
160
160
|
*/
|
|
161
161
|
static apply(app) {
|
|
162
|
-
for (const route of
|
|
162
|
+
for (const route of this.orderedRoutes()) {
|
|
163
163
|
let handlerFunction = null;
|
|
164
164
|
let instance = null;
|
|
165
165
|
let bindingTarget;
|
package/dist/h3/router.cjs
CHANGED
|
@@ -64,7 +64,7 @@ var Router = class Router extends require_router.CoreRouter {
|
|
|
64
64
|
* @param options
|
|
65
65
|
*/
|
|
66
66
|
static apiResource(basePath, controller, options) {
|
|
67
|
-
super.apiResource(basePath, controller, options);
|
|
67
|
+
return super.apiResource(basePath, controller, options);
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* Adds a new GET route to the router with the specified path, handler, and optional middlewares.
|
|
@@ -169,7 +169,7 @@ var Router = class Router extends require_router.CoreRouter {
|
|
|
169
169
|
* @returns
|
|
170
170
|
*/
|
|
171
171
|
static apply(app) {
|
|
172
|
-
for (const route of
|
|
172
|
+
for (const route of this.orderedRoutes()) {
|
|
173
173
|
let handlerFunction = null;
|
|
174
174
|
let instance = null;
|
|
175
175
|
let bindingTarget;
|
package/dist/h3/router.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
2
|
-
import { H3App, Handler, HttpContext, Middleware } from "../types/h3.cjs";
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction } from "../types/basic.cjs";
|
|
2
|
+
import { H3App, Handler, HttpContext, Middleware as Middleware$1 } from "../types/h3.cjs";
|
|
3
3
|
import { Route } from "../Route.cjs";
|
|
4
|
+
import { ResourceRoutes } from "../ResourceRoutes.cjs";
|
|
4
5
|
import { CoreRouter } from "../core/router.cjs";
|
|
5
6
|
import { H3 } from "h3";
|
|
6
7
|
|
|
@@ -24,7 +25,7 @@ declare class Router extends CoreRouter {
|
|
|
24
25
|
* @param handler
|
|
25
26
|
* @param middlewares
|
|
26
27
|
*/
|
|
27
|
-
static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
28
|
+
static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
28
29
|
/**
|
|
29
30
|
* Define a resourceful API controller with standard CRUD routes
|
|
30
31
|
*
|
|
@@ -33,10 +34,10 @@ declare class Router extends CoreRouter {
|
|
|
33
34
|
* @param options
|
|
34
35
|
*/
|
|
35
36
|
static apiResource(basePath: string, controller: any, options?: {
|
|
36
|
-
only?:
|
|
37
|
-
except?:
|
|
38
|
-
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
39
|
-
}):
|
|
37
|
+
only?: ResourceAction[];
|
|
38
|
+
except?: ResourceAction[];
|
|
39
|
+
middlewares?: ApiResourceMiddleware<Middleware$1>;
|
|
40
|
+
}): ResourceRoutes<HttpContext, Middleware$1, Handler>;
|
|
40
41
|
/**
|
|
41
42
|
* Adds a new GET route to the router with the specified path, handler, and optional middlewares.
|
|
42
43
|
*
|
|
@@ -44,7 +45,7 @@ declare class Router extends CoreRouter {
|
|
|
44
45
|
* @param handler
|
|
45
46
|
* @param middlewares
|
|
46
47
|
*/
|
|
47
|
-
static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
48
|
+
static get(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
48
49
|
/**
|
|
49
50
|
* Adds a new POST route to the router with the specified path, handler, and optional middlewares.
|
|
50
51
|
*
|
|
@@ -52,7 +53,7 @@ declare class Router extends CoreRouter {
|
|
|
52
53
|
* @param handler
|
|
53
54
|
* @param middlewares
|
|
54
55
|
*/
|
|
55
|
-
static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
56
|
+
static post(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
56
57
|
/**
|
|
57
58
|
* Adds a new PUT route to the router with the specified path, handler, and optional middlewares.
|
|
58
59
|
*
|
|
@@ -60,7 +61,7 @@ declare class Router extends CoreRouter {
|
|
|
60
61
|
* @param handler
|
|
61
62
|
* @param middlewares
|
|
62
63
|
*/
|
|
63
|
-
static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
64
|
+
static put(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
64
65
|
/**
|
|
65
66
|
* Adds a new DELETE route to the router with the specified path, handler, and optional middlewares.
|
|
66
67
|
*
|
|
@@ -68,7 +69,7 @@ declare class Router extends CoreRouter {
|
|
|
68
69
|
* @param handler
|
|
69
70
|
* @param middlewares
|
|
70
71
|
*/
|
|
71
|
-
static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
72
|
+
static delete(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
72
73
|
/**
|
|
73
74
|
* Adds a new PATCH route to the router with the specified path, handler, and optional middlewares.
|
|
74
75
|
*
|
|
@@ -76,7 +77,7 @@ declare class Router extends CoreRouter {
|
|
|
76
77
|
* @param handler
|
|
77
78
|
* @param middlewares
|
|
78
79
|
*/
|
|
79
|
-
static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
80
|
+
static patch(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
80
81
|
/**
|
|
81
82
|
* Adds a new OPTIONS route to the router with the specified path, handler, and optional middlewares.
|
|
82
83
|
*
|
|
@@ -84,7 +85,7 @@ declare class Router extends CoreRouter {
|
|
|
84
85
|
* @param handler
|
|
85
86
|
* @param middlewares
|
|
86
87
|
*/
|
|
87
|
-
static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
88
|
+
static options(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
88
89
|
/**
|
|
89
90
|
* Adds a new HEAD route to the router.
|
|
90
91
|
*
|
|
@@ -92,7 +93,7 @@ declare class Router extends CoreRouter {
|
|
|
92
93
|
* @param handler
|
|
93
94
|
* @param middlewares
|
|
94
95
|
*/
|
|
95
|
-
static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
96
|
+
static head(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
96
97
|
/**
|
|
97
98
|
* Defines a group of routes with a common prefix.
|
|
98
99
|
*
|
|
@@ -100,25 +101,25 @@ declare class Router extends CoreRouter {
|
|
|
100
101
|
* @param callback
|
|
101
102
|
* @param middlewares
|
|
102
103
|
*/
|
|
103
|
-
static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
|
|
104
|
+
static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware$1[]): Promise<void>;
|
|
104
105
|
/**
|
|
105
106
|
* Adds global middlewares to the router, which will be applied to all routes.
|
|
106
107
|
*
|
|
107
108
|
* @param middlewares
|
|
108
109
|
* @param callback
|
|
109
110
|
*/
|
|
110
|
-
static middleware(middlewares: Middleware[], callback: () => void): void;
|
|
111
|
+
static middleware(middlewares: Middleware$1[], callback: () => void): void;
|
|
111
112
|
/**
|
|
112
113
|
* Retrieves all registered routes in the router, optionally organized by path or method
|
|
113
114
|
* for easier access and management.
|
|
114
115
|
*
|
|
115
116
|
* @param type
|
|
116
117
|
*/
|
|
117
|
-
static allRoutes(): Array<Route<HttpContext, Middleware, Handler>>;
|
|
118
|
-
static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler>>;
|
|
119
|
-
static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler>> };
|
|
120
|
-
static allRoutes(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler>>;
|
|
121
|
-
static route(name: string): Route<HttpContext, Middleware, Handler> | undefined;
|
|
118
|
+
static allRoutes(): Array<Route<HttpContext, Middleware$1, Handler>>;
|
|
119
|
+
static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware$1, Handler>>;
|
|
120
|
+
static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware$1, Handler>> };
|
|
121
|
+
static allRoutes(type: 'name'): Record<string, Route<HttpContext, Middleware$1, Handler>>;
|
|
122
|
+
static route(name: string): Route<HttpContext, Middleware$1, Handler> | undefined;
|
|
122
123
|
/**
|
|
123
124
|
* Applies the registered routes to the given H3 application instance, setting up the
|
|
124
125
|
* necessary handlers and middlewares for each route.
|
package/dist/h3/router.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
2
|
-
import { H3App, Handler, HttpContext, Middleware } from "../types/h3.mjs";
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction } from "../types/basic.mjs";
|
|
2
|
+
import { H3App, Handler, HttpContext, Middleware as Middleware$1 } from "../types/h3.mjs";
|
|
3
3
|
import { Route } from "../Route.mjs";
|
|
4
|
+
import { ResourceRoutes } from "../ResourceRoutes.mjs";
|
|
4
5
|
import { CoreRouter } from "../core/router.mjs";
|
|
5
6
|
import { H3 } from "h3";
|
|
6
7
|
|
|
@@ -24,7 +25,7 @@ declare class Router extends CoreRouter {
|
|
|
24
25
|
* @param handler
|
|
25
26
|
* @param middlewares
|
|
26
27
|
*/
|
|
27
|
-
static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
28
|
+
static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
28
29
|
/**
|
|
29
30
|
* Define a resourceful API controller with standard CRUD routes
|
|
30
31
|
*
|
|
@@ -33,10 +34,10 @@ declare class Router extends CoreRouter {
|
|
|
33
34
|
* @param options
|
|
34
35
|
*/
|
|
35
36
|
static apiResource(basePath: string, controller: any, options?: {
|
|
36
|
-
only?:
|
|
37
|
-
except?:
|
|
38
|
-
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
39
|
-
}):
|
|
37
|
+
only?: ResourceAction[];
|
|
38
|
+
except?: ResourceAction[];
|
|
39
|
+
middlewares?: ApiResourceMiddleware<Middleware$1>;
|
|
40
|
+
}): ResourceRoutes<HttpContext, Middleware$1, Handler>;
|
|
40
41
|
/**
|
|
41
42
|
* Adds a new GET route to the router with the specified path, handler, and optional middlewares.
|
|
42
43
|
*
|
|
@@ -44,7 +45,7 @@ declare class Router extends CoreRouter {
|
|
|
44
45
|
* @param handler
|
|
45
46
|
* @param middlewares
|
|
46
47
|
*/
|
|
47
|
-
static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
48
|
+
static get(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
48
49
|
/**
|
|
49
50
|
* Adds a new POST route to the router with the specified path, handler, and optional middlewares.
|
|
50
51
|
*
|
|
@@ -52,7 +53,7 @@ declare class Router extends CoreRouter {
|
|
|
52
53
|
* @param handler
|
|
53
54
|
* @param middlewares
|
|
54
55
|
*/
|
|
55
|
-
static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
56
|
+
static post(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
56
57
|
/**
|
|
57
58
|
* Adds a new PUT route to the router with the specified path, handler, and optional middlewares.
|
|
58
59
|
*
|
|
@@ -60,7 +61,7 @@ declare class Router extends CoreRouter {
|
|
|
60
61
|
* @param handler
|
|
61
62
|
* @param middlewares
|
|
62
63
|
*/
|
|
63
|
-
static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
64
|
+
static put(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
64
65
|
/**
|
|
65
66
|
* Adds a new DELETE route to the router with the specified path, handler, and optional middlewares.
|
|
66
67
|
*
|
|
@@ -68,7 +69,7 @@ declare class Router extends CoreRouter {
|
|
|
68
69
|
* @param handler
|
|
69
70
|
* @param middlewares
|
|
70
71
|
*/
|
|
71
|
-
static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
72
|
+
static delete(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
72
73
|
/**
|
|
73
74
|
* Adds a new PATCH route to the router with the specified path, handler, and optional middlewares.
|
|
74
75
|
*
|
|
@@ -76,7 +77,7 @@ declare class Router extends CoreRouter {
|
|
|
76
77
|
* @param handler
|
|
77
78
|
* @param middlewares
|
|
78
79
|
*/
|
|
79
|
-
static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
80
|
+
static patch(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
80
81
|
/**
|
|
81
82
|
* Adds a new OPTIONS route to the router with the specified path, handler, and optional middlewares.
|
|
82
83
|
*
|
|
@@ -84,7 +85,7 @@ declare class Router extends CoreRouter {
|
|
|
84
85
|
* @param handler
|
|
85
86
|
* @param middlewares
|
|
86
87
|
*/
|
|
87
|
-
static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
88
|
+
static options(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
88
89
|
/**
|
|
89
90
|
* Adds a new HEAD route to the router.
|
|
90
91
|
*
|
|
@@ -92,7 +93,7 @@ declare class Router extends CoreRouter {
|
|
|
92
93
|
* @param handler
|
|
93
94
|
* @param middlewares
|
|
94
95
|
*/
|
|
95
|
-
static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
|
|
96
|
+
static head(path: string, handler: Handler, middlewares?: Middleware$1[] | Middleware$1): Route<HttpContext, Middleware$1, Handler>;
|
|
96
97
|
/**
|
|
97
98
|
* Defines a group of routes with a common prefix.
|
|
98
99
|
*
|
|
@@ -100,25 +101,25 @@ declare class Router extends CoreRouter {
|
|
|
100
101
|
* @param callback
|
|
101
102
|
* @param middlewares
|
|
102
103
|
*/
|
|
103
|
-
static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
|
|
104
|
+
static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware$1[]): Promise<void>;
|
|
104
105
|
/**
|
|
105
106
|
* Adds global middlewares to the router, which will be applied to all routes.
|
|
106
107
|
*
|
|
107
108
|
* @param middlewares
|
|
108
109
|
* @param callback
|
|
109
110
|
*/
|
|
110
|
-
static middleware(middlewares: Middleware[], callback: () => void): void;
|
|
111
|
+
static middleware(middlewares: Middleware$1[], callback: () => void): void;
|
|
111
112
|
/**
|
|
112
113
|
* Retrieves all registered routes in the router, optionally organized by path or method
|
|
113
114
|
* for easier access and management.
|
|
114
115
|
*
|
|
115
116
|
* @param type
|
|
116
117
|
*/
|
|
117
|
-
static allRoutes(): Array<Route<HttpContext, Middleware, Handler>>;
|
|
118
|
-
static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler>>;
|
|
119
|
-
static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler>> };
|
|
120
|
-
static allRoutes(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler>>;
|
|
121
|
-
static route(name: string): Route<HttpContext, Middleware, Handler> | undefined;
|
|
118
|
+
static allRoutes(): Array<Route<HttpContext, Middleware$1, Handler>>;
|
|
119
|
+
static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware$1, Handler>>;
|
|
120
|
+
static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware$1, Handler>> };
|
|
121
|
+
static allRoutes(type: 'name'): Record<string, Route<HttpContext, Middleware$1, Handler>>;
|
|
122
|
+
static route(name: string): Route<HttpContext, Middleware$1, Handler> | undefined;
|
|
122
123
|
/**
|
|
123
124
|
* Applies the registered routes to the given H3 application instance, setting up the
|
|
124
125
|
* necessary handlers and middlewares for each route.
|
package/dist/h3/router.mjs
CHANGED
|
@@ -64,7 +64,7 @@ var Router = class Router extends CoreRouter {
|
|
|
64
64
|
* @param options
|
|
65
65
|
*/
|
|
66
66
|
static apiResource(basePath, controller, options) {
|
|
67
|
-
super.apiResource(basePath, controller, options);
|
|
67
|
+
return super.apiResource(basePath, controller, options);
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* Adds a new GET route to the router with the specified path, handler, and optional middlewares.
|
|
@@ -169,7 +169,7 @@ var Router = class Router extends CoreRouter {
|
|
|
169
169
|
* @returns
|
|
170
170
|
*/
|
|
171
171
|
static apply(app) {
|
|
172
|
-
for (const route of
|
|
172
|
+
for (const route of this.orderedRoutes()) {
|
|
173
173
|
let handlerFunction = null;
|
|
174
174
|
let instance = null;
|
|
175
175
|
let bindingTarget;
|
package/dist/hono/router.cjs
CHANGED
|
@@ -68,7 +68,7 @@ var Router = class Router extends require_router.CoreRouter {
|
|
|
68
68
|
* @param options
|
|
69
69
|
*/
|
|
70
70
|
static apiResource(basePath, controller, options) {
|
|
71
|
-
super.apiResource(basePath, controller, options);
|
|
71
|
+
return super.apiResource(basePath, controller, options);
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* Define a GET route
|
|
@@ -172,7 +172,7 @@ var Router = class Router extends require_router.CoreRouter {
|
|
|
172
172
|
* @returns The Hono application instance with the applied routes
|
|
173
173
|
*/
|
|
174
174
|
static apply(app) {
|
|
175
|
-
for (const route of
|
|
175
|
+
for (const route of this.orderedRoutes()) {
|
|
176
176
|
let handlerFunction = null;
|
|
177
177
|
let instance = null;
|
|
178
178
|
let bindingTarget;
|
package/dist/hono/router.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction } from "../types/basic.cjs";
|
|
2
2
|
import { Handler, HonoApp, HttpContext, Middleware } from "../types/hono.cjs";
|
|
3
3
|
import { Route } from "../Route.cjs";
|
|
4
|
+
import { ResourceRoutes } from "../ResourceRoutes.cjs";
|
|
4
5
|
import { CoreRouter } from "../core/router.cjs";
|
|
5
6
|
|
|
6
7
|
//#region src/hono/router.d.ts
|
|
@@ -33,10 +34,10 @@ declare class Router extends CoreRouter {
|
|
|
33
34
|
* @param options
|
|
34
35
|
*/
|
|
35
36
|
static apiResource(basePath: string, controller: any, options?: {
|
|
36
|
-
only?:
|
|
37
|
-
except?:
|
|
37
|
+
only?: ResourceAction[];
|
|
38
|
+
except?: ResourceAction[];
|
|
38
39
|
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
39
|
-
}):
|
|
40
|
+
}): ResourceRoutes<HttpContext, Middleware, Handler>;
|
|
40
41
|
/**
|
|
41
42
|
* Define a GET route
|
|
42
43
|
*
|
package/dist/hono/router.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction } from "../types/basic.mjs";
|
|
2
2
|
import { Handler, HonoApp, HttpContext, Middleware } from "../types/hono.mjs";
|
|
3
3
|
import { Route } from "../Route.mjs";
|
|
4
|
+
import { ResourceRoutes } from "../ResourceRoutes.mjs";
|
|
4
5
|
import { CoreRouter } from "../core/router.mjs";
|
|
5
6
|
|
|
6
7
|
//#region src/hono/router.d.ts
|
|
@@ -33,10 +34,10 @@ declare class Router extends CoreRouter {
|
|
|
33
34
|
* @param options
|
|
34
35
|
*/
|
|
35
36
|
static apiResource(basePath: string, controller: any, options?: {
|
|
36
|
-
only?:
|
|
37
|
-
except?:
|
|
37
|
+
only?: ResourceAction[];
|
|
38
|
+
except?: ResourceAction[];
|
|
38
39
|
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
39
|
-
}):
|
|
40
|
+
}): ResourceRoutes<HttpContext, Middleware, Handler>;
|
|
40
41
|
/**
|
|
41
42
|
* Define a GET route
|
|
42
43
|
*
|
package/dist/hono/router.mjs
CHANGED
|
@@ -68,7 +68,7 @@ var Router = class Router extends CoreRouter {
|
|
|
68
68
|
* @param options
|
|
69
69
|
*/
|
|
70
70
|
static apiResource(basePath, controller, options) {
|
|
71
|
-
super.apiResource(basePath, controller, options);
|
|
71
|
+
return super.apiResource(basePath, controller, options);
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* Define a GET route
|
|
@@ -172,7 +172,7 @@ var Router = class Router extends CoreRouter {
|
|
|
172
172
|
* @returns The Hono application instance with the applied routes
|
|
173
173
|
*/
|
|
174
174
|
static apply(app) {
|
|
175
|
-
for (const route of
|
|
175
|
+
for (const route of this.orderedRoutes()) {
|
|
176
176
|
let handlerFunction = null;
|
|
177
177
|
let instance = null;
|
|
178
178
|
let bindingTarget;
|
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ const require_Request = require('./core/Request.cjs');
|
|
|
6
6
|
const require_Response = require('./core/Response.cjs');
|
|
7
7
|
const require_plugins = require('./core/plugins.cjs');
|
|
8
8
|
const require_router = require('./core/router.cjs');
|
|
9
|
+
const require_helpers = require('./core/helpers.cjs');
|
|
9
10
|
require('./core/index.cjs');
|
|
10
11
|
|
|
11
12
|
exports.ClearRequest = require_ClearRequest.ClearRequest;
|
|
@@ -14,4 +15,5 @@ exports.CoreRouter = require_router.CoreRouter;
|
|
|
14
15
|
exports.Request = require_Request.Request;
|
|
15
16
|
exports.Response = require_Response.Response;
|
|
16
17
|
exports.Route = require_Route.Route;
|
|
17
|
-
exports.definePlugin = require_plugins.definePlugin;
|
|
18
|
+
exports.definePlugin = require_plugins.definePlugin;
|
|
19
|
+
exports.wrap = require_helpers.wrap;
|
package/dist/index.d.cts
CHANGED
|
@@ -6,4 +6,5 @@ import { ClearRequest } from "./ClearRequest.cjs";
|
|
|
6
6
|
import { Controller } from "./Controller.cjs";
|
|
7
7
|
import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./core/plugins.cjs";
|
|
8
8
|
import { CoreRouter } from "./core/router.cjs";
|
|
9
|
-
|
|
9
|
+
import { wrap } from "./core/helpers.cjs";
|
|
10
|
+
export { ClearHttpContext, ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, Route, RouteParameter, definePlugin, wrap };
|
package/dist/index.d.mts
CHANGED
|
@@ -6,4 +6,5 @@ import { ClearRequest } from "./ClearRequest.mjs";
|
|
|
6
6
|
import { Controller } from "./Controller.mjs";
|
|
7
7
|
import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./core/plugins.mjs";
|
|
8
8
|
import { CoreRouter } from "./core/router.mjs";
|
|
9
|
-
|
|
9
|
+
import { wrap } from "./core/helpers.mjs";
|
|
10
|
+
export { ClearHttpContext, ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, Route, RouteParameter, definePlugin, wrap };
|
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { Request } from "./core/Request.mjs";
|
|
|
5
5
|
import { Response } from "./core/Response.mjs";
|
|
6
6
|
import { definePlugin } from "./core/plugins.mjs";
|
|
7
7
|
import { CoreRouter } from "./core/router.mjs";
|
|
8
|
+
import { wrap } from "./core/helpers.mjs";
|
|
8
9
|
import "./core/index.mjs";
|
|
9
10
|
|
|
10
|
-
export { ClearRequest, Controller, CoreRouter, Request, Response, Route, definePlugin };
|
|
11
|
+
export { ClearRequest, Controller, CoreRouter, Request, Response, Route, definePlugin, wrap };
|
package/dist/koa/router.cjs
CHANGED
|
@@ -77,7 +77,7 @@ var Router = class Router extends require_router.CoreRouter {
|
|
|
77
77
|
* @param options
|
|
78
78
|
*/
|
|
79
79
|
static apiResource(basePath, controller, options) {
|
|
80
|
-
super.apiResource(basePath, controller, options);
|
|
80
|
+
return super.apiResource(basePath, controller, options);
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Define a GET route
|
|
@@ -182,7 +182,7 @@ var Router = class Router extends require_router.CoreRouter {
|
|
|
182
182
|
* @returns The @koa/router instance with the applied routes
|
|
183
183
|
*/
|
|
184
184
|
static apply(router) {
|
|
185
|
-
for (const route of
|
|
185
|
+
for (const route of this.orderedRoutes()) {
|
|
186
186
|
let handlerFunction = null;
|
|
187
187
|
let instance = null;
|
|
188
188
|
let bindingTarget;
|
package/dist/koa/router.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction } from "../types/basic.cjs";
|
|
2
2
|
import { Handler, HttpContext, KoaRouterApp, Middleware } from "../types/koa.cjs";
|
|
3
3
|
import { Route } from "../Route.cjs";
|
|
4
|
+
import { ResourceRoutes } from "../ResourceRoutes.cjs";
|
|
4
5
|
import { CoreRouter } from "../core/router.cjs";
|
|
5
6
|
|
|
6
7
|
//#region src/koa/router.d.ts
|
|
@@ -33,10 +34,10 @@ declare class Router extends CoreRouter {
|
|
|
33
34
|
* @param options
|
|
34
35
|
*/
|
|
35
36
|
static apiResource(basePath: string, controller: any, options?: {
|
|
36
|
-
only?:
|
|
37
|
-
except?:
|
|
37
|
+
only?: ResourceAction[];
|
|
38
|
+
except?: ResourceAction[];
|
|
38
39
|
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
39
|
-
}):
|
|
40
|
+
}): ResourceRoutes<HttpContext, Middleware, Handler>;
|
|
40
41
|
/**
|
|
41
42
|
* Define a GET route
|
|
42
43
|
*
|
package/dist/koa/router.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction } from "../types/basic.mjs";
|
|
2
2
|
import { Handler, HttpContext, KoaRouterApp, Middleware } from "../types/koa.mjs";
|
|
3
3
|
import { Route } from "../Route.mjs";
|
|
4
|
+
import { ResourceRoutes } from "../ResourceRoutes.mjs";
|
|
4
5
|
import { CoreRouter } from "../core/router.mjs";
|
|
5
6
|
|
|
6
7
|
//#region src/koa/router.d.ts
|
|
@@ -33,10 +34,10 @@ declare class Router extends CoreRouter {
|
|
|
33
34
|
* @param options
|
|
34
35
|
*/
|
|
35
36
|
static apiResource(basePath: string, controller: any, options?: {
|
|
36
|
-
only?:
|
|
37
|
-
except?:
|
|
37
|
+
only?: ResourceAction[];
|
|
38
|
+
except?: ResourceAction[];
|
|
38
39
|
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
39
|
-
}):
|
|
40
|
+
}): ResourceRoutes<HttpContext, Middleware, Handler>;
|
|
40
41
|
/**
|
|
41
42
|
* Define a GET route
|
|
42
43
|
*
|
package/dist/koa/router.mjs
CHANGED
|
@@ -77,7 +77,7 @@ var Router = class Router extends CoreRouter {
|
|
|
77
77
|
* @param options
|
|
78
78
|
*/
|
|
79
79
|
static apiResource(basePath, controller, options) {
|
|
80
|
-
super.apiResource(basePath, controller, options);
|
|
80
|
+
return super.apiResource(basePath, controller, options);
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Define a GET route
|
|
@@ -182,7 +182,7 @@ var Router = class Router extends CoreRouter {
|
|
|
182
182
|
* @returns The @koa/router instance with the applied routes
|
|
183
183
|
*/
|
|
184
184
|
static apply(router) {
|
|
185
|
-
for (const route of
|
|
185
|
+
for (const route of this.orderedRoutes()) {
|
|
186
186
|
let handlerFunction = null;
|
|
187
187
|
let instance = null;
|
|
188
188
|
let bindingTarget;
|
package/dist/types/basic.d.cts
CHANGED
|
@@ -3,19 +3,28 @@
|
|
|
3
3
|
* Controller method reference
|
|
4
4
|
*/
|
|
5
5
|
type ControllerHandler = [any, string];
|
|
6
|
+
type MaybePromise<T = any> = T | Promise<T>;
|
|
7
|
+
type MiddlewareHandle<Args extends any[] = any[], Return = any> = (...args: Args) => MaybePromise<Return>;
|
|
8
|
+
type MiddlewareClass<M extends MiddlewareHandle = MiddlewareHandle> = new () => {
|
|
9
|
+
handle: M;
|
|
10
|
+
};
|
|
11
|
+
type MiddlewareInstance<M extends MiddlewareHandle = MiddlewareHandle> = {
|
|
12
|
+
handle: M;
|
|
13
|
+
};
|
|
14
|
+
type ClassMiddleware<M extends MiddlewareHandle = MiddlewareHandle> = MiddlewareClass<M> | MiddlewareInstance<M>;
|
|
6
15
|
/**
|
|
7
16
|
* HTTP methods supported by the router
|
|
8
17
|
*/
|
|
9
18
|
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
10
19
|
/**
|
|
11
|
-
* Common
|
|
20
|
+
* Common resource action names
|
|
12
21
|
*/
|
|
13
|
-
type
|
|
22
|
+
type ResourceAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
14
23
|
/**
|
|
15
24
|
* Generic Object type for request data
|
|
16
25
|
*/
|
|
17
26
|
type RequestData = Record<string, any>;
|
|
18
|
-
type ApiResourceMiddleware<M = any> = M | M[] | { [K in
|
|
27
|
+
type ApiResourceMiddleware<M = any> = M | M[] | { [K in ResourceAction]?: M | M[] };
|
|
19
28
|
interface RouterConfig {
|
|
20
29
|
/**
|
|
21
30
|
* When enabled, API param name will be infered from the route path.
|
|
@@ -40,4 +49,4 @@ interface RouterConfig {
|
|
|
40
49
|
};
|
|
41
50
|
}
|
|
42
51
|
//#endregion
|
|
43
|
-
export { ApiResourceMiddleware,
|
|
52
|
+
export { ApiResourceMiddleware, ClassMiddleware, ControllerHandler, HttpMethod, MiddlewareHandle, RequestData, ResourceAction, RouterConfig };
|