clear-router 2.7.7 → 2.8.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/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 +60 -0
- package/dist/ResourceRoutes.d.cts +37 -0
- package/dist/ResourceRoutes.d.mts +37 -0
- package/dist/ResourceRoutes.mjs +60 -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/index.cjs +6 -0
- package/dist/core/router.cjs +57 -4
- package/dist/core/router.d.cts +13 -1
- package/dist/core/router.d.mts +13 -1
- package/dist/core/router.mjs +57 -4
- package/dist/decorators/setup.d.mts +0 -1
- package/dist/express/router.cjs +2 -2
- package/dist/express/router.d.cts +2 -1
- package/dist/express/router.d.mts +2 -1
- package/dist/express/router.mjs +2 -2
- package/dist/fastify/router.cjs +2 -2
- package/dist/fastify/router.d.cts +2 -1
- package/dist/fastify/router.d.mts +2 -1
- package/dist/fastify/router.mjs +2 -2
- package/dist/h3/router.cjs +2 -2
- package/dist/h3/router.d.cts +19 -18
- package/dist/h3/router.d.mts +19 -18
- package/dist/h3/router.mjs +2 -2
- package/dist/hono/router.cjs +2 -2
- package/dist/hono/router.d.cts +2 -1
- package/dist/hono/router.d.mts +2 -1
- package/dist/hono/router.mjs +2 -2
- package/dist/koa/router.cjs +2 -2
- package/dist/koa/router.d.cts +2 -1
- package/dist/koa/router.d.mts +2 -1
- package/dist/koa/router.mjs +2 -2
- package/dist/types/basic.d.cts +11 -1
- package/dist/types/basic.d.mts +11 -1
- 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/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
1
|
import { ApiResourceMiddleware, ControllerAction, HttpMethod } 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
|
|
@@ -36,7 +37,7 @@ declare class Router extends CoreRouter {
|
|
|
36
37
|
only?: ControllerAction[];
|
|
37
38
|
except?: ControllerAction[];
|
|
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
1
|
import { ApiResourceMiddleware, ControllerAction, HttpMethod } 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
|
|
@@ -36,7 +37,7 @@ declare class Router extends CoreRouter {
|
|
|
36
37
|
only?: ControllerAction[];
|
|
37
38
|
except?: ControllerAction[];
|
|
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,6 +3,16 @@
|
|
|
3
3
|
* Controller method reference
|
|
4
4
|
*/
|
|
5
5
|
type ControllerHandler = [any, string];
|
|
6
|
+
type MaybePromise<T = any> = T | Promise<T>;
|
|
7
|
+
type ResourceAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
8
|
+
type MiddlewareHandle<Args extends any[] = any[], Return = any> = (...args: Args) => MaybePromise<Return>;
|
|
9
|
+
type MiddlewareClass<M extends MiddlewareHandle = MiddlewareHandle> = new () => {
|
|
10
|
+
handle: M;
|
|
11
|
+
};
|
|
12
|
+
type MiddlewareInstance<M extends MiddlewareHandle = MiddlewareHandle> = {
|
|
13
|
+
handle: M;
|
|
14
|
+
};
|
|
15
|
+
type ClassMiddleware<M extends MiddlewareHandle = MiddlewareHandle> = MiddlewareClass<M> | MiddlewareInstance<M>;
|
|
6
16
|
/**
|
|
7
17
|
* HTTP methods supported by the router
|
|
8
18
|
*/
|
|
@@ -40,4 +50,4 @@ interface RouterConfig {
|
|
|
40
50
|
};
|
|
41
51
|
}
|
|
42
52
|
//#endregion
|
|
43
|
-
export { ApiResourceMiddleware, ControllerAction, ControllerHandler, HttpMethod, RequestData, RouterConfig };
|
|
53
|
+
export { ApiResourceMiddleware, ClassMiddleware, ControllerAction, ControllerHandler, HttpMethod, MiddlewareHandle, RequestData, ResourceAction, RouterConfig };
|
package/dist/types/basic.d.mts
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
* Controller method reference
|
|
4
4
|
*/
|
|
5
5
|
type ControllerHandler = [any, string];
|
|
6
|
+
type MaybePromise<T = any> = T | Promise<T>;
|
|
7
|
+
type ResourceAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
8
|
+
type MiddlewareHandle<Args extends any[] = any[], Return = any> = (...args: Args) => MaybePromise<Return>;
|
|
9
|
+
type MiddlewareClass<M extends MiddlewareHandle = MiddlewareHandle> = new () => {
|
|
10
|
+
handle: M;
|
|
11
|
+
};
|
|
12
|
+
type MiddlewareInstance<M extends MiddlewareHandle = MiddlewareHandle> = {
|
|
13
|
+
handle: M;
|
|
14
|
+
};
|
|
15
|
+
type ClassMiddleware<M extends MiddlewareHandle = MiddlewareHandle> = MiddlewareClass<M> | MiddlewareInstance<M>;
|
|
6
16
|
/**
|
|
7
17
|
* HTTP methods supported by the router
|
|
8
18
|
*/
|
|
@@ -40,4 +50,4 @@ interface RouterConfig {
|
|
|
40
50
|
};
|
|
41
51
|
}
|
|
42
52
|
//#endregion
|
|
43
|
-
export { ApiResourceMiddleware, ControllerAction, ControllerHandler, HttpMethod, RequestData, RouterConfig };
|
|
53
|
+
export { ApiResourceMiddleware, ClassMiddleware, ControllerAction, ControllerHandler, HttpMethod, MiddlewareHandle, RequestData, ResourceAction, RouterConfig };
|
package/dist/types/express.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControllerHandler } from "./basic.cjs";
|
|
1
|
+
import { ClassMiddleware, ControllerHandler, MiddlewareHandle } from "./basic.cjs";
|
|
2
2
|
import { ClearHttpContext } from "../Contracts.cjs";
|
|
3
3
|
import { Response as Response$1 } from "../core/Response.cjs";
|
|
4
4
|
import { Request as Request$1 } from "../core/Request.cjs";
|
|
@@ -39,6 +39,10 @@ type Handler = RouteHandler | ControllerHandler;
|
|
|
39
39
|
/**
|
|
40
40
|
* Middleware function type
|
|
41
41
|
*/
|
|
42
|
-
type
|
|
42
|
+
type MiddlewareFunction = MiddlewareHandle<[Request, Response, NextFunction]>;
|
|
43
|
+
/**
|
|
44
|
+
* Middleware class or instance with a framework-aware handle method.
|
|
45
|
+
*/
|
|
46
|
+
type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
|
|
43
47
|
//#endregion
|
|
44
48
|
export { Handler, HttpContext, Middleware };
|
package/dist/types/express.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControllerHandler } from "./basic.mjs";
|
|
1
|
+
import { ClassMiddleware, ControllerHandler, MiddlewareHandle } from "./basic.mjs";
|
|
2
2
|
import { ClearHttpContext } from "../Contracts.mjs";
|
|
3
3
|
import { Response as Response$1 } from "../core/Response.mjs";
|
|
4
4
|
import { Request as Request$1 } from "../core/Request.mjs";
|
|
@@ -39,6 +39,10 @@ type Handler = RouteHandler | ControllerHandler;
|
|
|
39
39
|
/**
|
|
40
40
|
* Middleware function type
|
|
41
41
|
*/
|
|
42
|
-
type
|
|
42
|
+
type MiddlewareFunction = MiddlewareHandle<[Request, Response, NextFunction]>;
|
|
43
|
+
/**
|
|
44
|
+
* Middleware class or instance with a framework-aware handle method.
|
|
45
|
+
*/
|
|
46
|
+
type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
|
|
43
47
|
//#endregion
|
|
44
48
|
export { Handler, HttpContext, Middleware };
|
package/dist/types/fastify.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControllerHandler } from "./basic.cjs";
|
|
1
|
+
import { ClassMiddleware, ControllerHandler, MiddlewareHandle } from "./basic.cjs";
|
|
2
2
|
import { ClearHttpContext } from "../Contracts.cjs";
|
|
3
3
|
import { Response } from "../core/Response.cjs";
|
|
4
4
|
import { Request } from "../core/Request.cjs";
|
|
@@ -17,7 +17,8 @@ interface HttpContext extends ClearHttpContext {
|
|
|
17
17
|
type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
|
|
18
18
|
type Handler = RouteHandler | ControllerHandler;
|
|
19
19
|
type NextFunction = (err?: Error) => void;
|
|
20
|
-
type
|
|
20
|
+
type MiddlewareFunction = MiddlewareHandle<[req: RequestWithGetBody, reply: FastifyReply, next: NextFunction]>;
|
|
21
|
+
type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
|
|
21
22
|
type FastifyApp = FastifyInstance;
|
|
22
23
|
//#endregion
|
|
23
24
|
export { FastifyApp, Handler, HttpContext, Middleware };
|
package/dist/types/fastify.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControllerHandler } from "./basic.mjs";
|
|
1
|
+
import { ClassMiddleware, ControllerHandler, MiddlewareHandle } from "./basic.mjs";
|
|
2
2
|
import { ClearHttpContext } from "../Contracts.mjs";
|
|
3
3
|
import { Response } from "../core/Response.mjs";
|
|
4
4
|
import { Request } from "../core/Request.mjs";
|
|
@@ -17,7 +17,8 @@ interface HttpContext extends ClearHttpContext {
|
|
|
17
17
|
type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
|
|
18
18
|
type Handler = RouteHandler | ControllerHandler;
|
|
19
19
|
type NextFunction = (err?: Error) => void;
|
|
20
|
-
type
|
|
20
|
+
type MiddlewareFunction = MiddlewareHandle<[req: RequestWithGetBody, reply: FastifyReply, next: NextFunction]>;
|
|
21
|
+
type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
|
|
21
22
|
type FastifyApp = FastifyInstance;
|
|
22
23
|
//#endregion
|
|
23
24
|
export { FastifyApp, Handler, HttpContext, Middleware };
|
package/dist/types/h3.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControllerHandler } from "./basic.cjs";
|
|
1
|
+
import { ClassMiddleware, ControllerHandler } from "./basic.cjs";
|
|
2
2
|
import { ClearHttpContext } from "../Contracts.cjs";
|
|
3
3
|
import { Response as Response$1 } from "../core/Response.cjs";
|
|
4
4
|
import { Request } from "../core/Request.cjs";
|
|
@@ -37,5 +37,10 @@ req: Request) => any | Promise<any>;
|
|
|
37
37
|
* Handler can be either a function or controller reference
|
|
38
38
|
*/
|
|
39
39
|
type Handler = RouteHandler | ControllerHandler;
|
|
40
|
+
/**
|
|
41
|
+
* Middleware function type
|
|
42
|
+
*/
|
|
43
|
+
type MiddlewareFunction = Middleware;
|
|
44
|
+
type Middleware$1 = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
|
|
40
45
|
//#endregion
|
|
41
|
-
export { H3App, Handler, HttpContext,
|
|
46
|
+
export { H3App, Handler, HttpContext, Middleware$1 as Middleware };
|
package/dist/types/h3.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControllerHandler } from "./basic.mjs";
|
|
1
|
+
import { ClassMiddleware, ControllerHandler } from "./basic.mjs";
|
|
2
2
|
import { ClearHttpContext } from "../Contracts.mjs";
|
|
3
3
|
import { Response as Response$1 } from "../core/Response.mjs";
|
|
4
4
|
import { Request } from "../core/Request.mjs";
|
|
@@ -37,5 +37,10 @@ req: Request) => any | Promise<any>;
|
|
|
37
37
|
* Handler can be either a function or controller reference
|
|
38
38
|
*/
|
|
39
39
|
type Handler = RouteHandler | ControllerHandler;
|
|
40
|
+
/**
|
|
41
|
+
* Middleware function type
|
|
42
|
+
*/
|
|
43
|
+
type MiddlewareFunction = Middleware;
|
|
44
|
+
type Middleware$1 = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
|
|
40
45
|
//#endregion
|
|
41
|
-
export { H3App, Handler, HttpContext,
|
|
46
|
+
export { H3App, Handler, HttpContext, Middleware$1 as Middleware };
|
package/dist/types/hono.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControllerHandler } from "./basic.cjs";
|
|
1
|
+
import { ClassMiddleware, ControllerHandler } from "./basic.cjs";
|
|
2
2
|
import { ClearHttpContext } from "../Contracts.cjs";
|
|
3
3
|
import { Response } from "../core/Response.cjs";
|
|
4
4
|
import { Request } from "../core/Request.cjs";
|
|
@@ -15,7 +15,8 @@ interface HttpContext extends Context, ClearHttpContext {
|
|
|
15
15
|
}
|
|
16
16
|
type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
|
|
17
17
|
type Handler = RouteHandler | ControllerHandler;
|
|
18
|
-
type
|
|
19
|
-
type
|
|
18
|
+
type MiddlewareFunction = MiddlewareHandler;
|
|
19
|
+
type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
|
|
20
|
+
type HonoApp = { [K in 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head']: (path: string, ...handlers: MiddlewareFunction[]) => any };
|
|
20
21
|
//#endregion
|
|
21
22
|
export { Handler, HonoApp, HttpContext, Middleware };
|
package/dist/types/hono.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControllerHandler } from "./basic.mjs";
|
|
1
|
+
import { ClassMiddleware, ControllerHandler } from "./basic.mjs";
|
|
2
2
|
import { ClearHttpContext } from "../Contracts.mjs";
|
|
3
3
|
import { Response } from "../core/Response.mjs";
|
|
4
4
|
import { Request } from "../core/Request.mjs";
|
|
@@ -15,7 +15,8 @@ interface HttpContext extends Context, ClearHttpContext {
|
|
|
15
15
|
}
|
|
16
16
|
type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
|
|
17
17
|
type Handler = RouteHandler | ControllerHandler;
|
|
18
|
-
type
|
|
19
|
-
type
|
|
18
|
+
type MiddlewareFunction = MiddlewareHandler;
|
|
19
|
+
type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
|
|
20
|
+
type HonoApp = { [K in 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head']: (path: string, ...handlers: MiddlewareFunction[]) => any };
|
|
20
21
|
//#endregion
|
|
21
22
|
export { Handler, HonoApp, HttpContext, Middleware };
|
package/dist/types/koa.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControllerHandler } from "./basic.cjs";
|
|
1
|
+
import { ClassMiddleware, ControllerHandler } from "./basic.cjs";
|
|
2
2
|
import { ClearHttpContext } from "../Contracts.cjs";
|
|
3
3
|
import { Response } from "../core/Response.cjs";
|
|
4
4
|
import { Request } from "../core/Request.cjs";
|
|
@@ -19,7 +19,8 @@ interface HttpContext extends Koa.Context, ClearHttpContext {
|
|
|
19
19
|
}
|
|
20
20
|
type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
|
|
21
21
|
type Handler = RouteHandler | ControllerHandler;
|
|
22
|
-
type
|
|
22
|
+
type MiddlewareFunction = Koa.Middleware<any, any>;
|
|
23
|
+
type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
|
|
23
24
|
type KoaRouterApp = Router<any, any>;
|
|
24
25
|
//#endregion
|
|
25
26
|
export { Handler, HttpContext, KoaRouterApp, Middleware };
|
package/dist/types/koa.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ControllerHandler } from "./basic.mjs";
|
|
1
|
+
import { ClassMiddleware, ControllerHandler } from "./basic.mjs";
|
|
2
2
|
import { ClearHttpContext } from "../Contracts.mjs";
|
|
3
3
|
import { Response } from "../core/Response.mjs";
|
|
4
4
|
import { Request } from "../core/Request.mjs";
|
|
@@ -19,7 +19,8 @@ interface HttpContext extends Koa.Context, ClearHttpContext {
|
|
|
19
19
|
}
|
|
20
20
|
type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
|
|
21
21
|
type Handler = RouteHandler | ControllerHandler;
|
|
22
|
-
type
|
|
22
|
+
type MiddlewareFunction = Koa.Middleware<any, any>;
|
|
23
|
+
type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
|
|
23
24
|
type KoaRouterApp = Router<any, any>;
|
|
24
25
|
//#endregion
|
|
25
26
|
export { Handler, HttpContext, KoaRouterApp, Middleware };
|
package/package.json
CHANGED