clear-router 2.8.4 → 2.8.6

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.
Files changed (43) hide show
  1. package/dist/ResourceRoutes.cjs +1 -1
  2. package/dist/ResourceRoutes.mjs +1 -1
  3. package/dist/RouteGroup.d.cts +4 -4
  4. package/dist/RouteGroup.d.mts +4 -4
  5. package/dist/core/CoreRouter.cjs +2 -2
  6. package/dist/core/CoreRouter.d.cts +1 -1
  7. package/dist/core/CoreRouter.d.mts +1 -1
  8. package/dist/core/CoreRouter.mjs +2 -2
  9. package/dist/core/index.cjs +9 -0
  10. package/dist/core/index.mjs +2 -2
  11. package/dist/express/router.d.cts +14 -14
  12. package/dist/express/router.d.mts +14 -14
  13. package/dist/fastify/router.d.cts +14 -14
  14. package/dist/fastify/router.d.mts +14 -14
  15. package/dist/h3/router.d.cts +14 -14
  16. package/dist/h3/router.d.mts +14 -14
  17. package/dist/hono/router.d.cts +14 -14
  18. package/dist/hono/router.d.mts +14 -14
  19. package/dist/index.d.cts +3 -3
  20. package/dist/index.d.mts +3 -3
  21. package/dist/koa/router.d.cts +16 -16
  22. package/dist/koa/router.d.mts +16 -16
  23. package/dist/types/basic.cjs +0 -0
  24. package/dist/types/basic.d.cts +8 -5
  25. package/dist/types/basic.d.mts +9 -6
  26. package/dist/types/express.cjs +0 -0
  27. package/dist/types/express.d.cts +2 -2
  28. package/dist/types/express.d.mts +2 -2
  29. package/dist/types/fastify.cjs +0 -0
  30. package/dist/types/fastify.d.cts +2 -2
  31. package/dist/types/fastify.d.mts +2 -2
  32. package/dist/types/h3.cjs +0 -0
  33. package/dist/types/h3.d.cts +7 -5
  34. package/dist/types/h3.d.mts +7 -5
  35. package/dist/types/hono.cjs +0 -0
  36. package/dist/types/hono.d.cts +3 -2
  37. package/dist/types/hono.d.mts +3 -2
  38. package/dist/types/koa.cjs +0 -0
  39. package/dist/types/koa.d.cts +3 -2
  40. package/dist/types/koa.d.mts +3 -2
  41. package/package.json +25 -7
  42. package/dist/Route-tq-rge1g.d.mts +0 -136
  43. package/dist/types/index.d.mts +0 -1
@@ -26,7 +26,7 @@ declare class Router extends CoreRouter {
26
26
  * @param handler
27
27
  * @param middlewares
28
28
  */
29
- static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
29
+ static add<T = any>(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
30
30
  /**
31
31
  * Define a resourceful API controller with standard CRUD routes
32
32
  *
@@ -34,11 +34,11 @@ declare class Router extends CoreRouter {
34
34
  * @param controller
35
35
  * @param options
36
36
  */
37
- static apiResource(basePath: string, controller: any, options?: {
37
+ static apiResource<T = any>(basePath: string, controller: any, options?: {
38
38
  only?: ResourceAction[];
39
39
  except?: ResourceAction[];
40
40
  middlewares?: ApiResourceMiddleware<Middleware>;
41
- }): ResourceRoutes<HttpContext, Middleware, Handler>;
41
+ }): ResourceRoutes<HttpContext, Middleware, Handler<T>>;
42
42
  /**
43
43
  * Define a GET route
44
44
  *
@@ -46,7 +46,7 @@ declare class Router extends CoreRouter {
46
46
  * @param handler
47
47
  * @param middlewares
48
48
  */
49
- static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
49
+ static get<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
50
50
  /**
51
51
  * Define a POST route
52
52
  *
@@ -54,7 +54,7 @@ declare class Router extends CoreRouter {
54
54
  * @param handler
55
55
  * @param middlewares
56
56
  */
57
- static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
57
+ static post<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
58
58
  /**
59
59
  * Define a PUT route
60
60
  *
@@ -62,7 +62,7 @@ declare class Router extends CoreRouter {
62
62
  * @param handler
63
63
  * @param middlewares
64
64
  */
65
- static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
65
+ static put<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
66
66
  /**
67
67
  * Define a DELETE route
68
68
  *
@@ -70,7 +70,7 @@ declare class Router extends CoreRouter {
70
70
  * @param handler
71
71
  * @param middlewares
72
72
  */
73
- static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
73
+ static delete<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
74
74
  /**
75
75
  * Define a PATCH route
76
76
  *
@@ -78,7 +78,7 @@ declare class Router extends CoreRouter {
78
78
  * @param handler
79
79
  * @param middlewares
80
80
  */
81
- static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
81
+ static patch<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
82
82
  /**
83
83
  * Define an OPTIONS route
84
84
  *
@@ -86,7 +86,7 @@ declare class Router extends CoreRouter {
86
86
  * @param handler
87
87
  * @param middlewares
88
88
  */
89
- static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
89
+ static options<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
90
90
  /**
91
91
  * Adds a new HEAD route to the router.
92
92
  *
@@ -95,7 +95,7 @@ declare class Router extends CoreRouter {
95
95
  * @param handler
96
96
  * @param middlewares
97
97
  */
98
- static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
98
+ static head<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
99
99
  /**
100
100
  * Defines a group of routes with a common prefix.
101
101
  *
@@ -103,7 +103,7 @@ declare class Router extends CoreRouter {
103
103
  * @param callback
104
104
  * @param middlewares
105
105
  */
106
- static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): RouteGroup<HttpContext, Middleware, Handler>;
106
+ static group<T = any, S extends RouteGroupSource = RouteGroupSource>(prefix: string, source: S, middlewares?: Middleware[]): RouteGroup<HttpContext, Middleware, Handler<T>, S>;
107
107
  /**
108
108
  * Apply middlewares to a group of routes defined within the callback
109
109
  *
@@ -114,17 +114,17 @@ declare class Router extends CoreRouter {
114
114
  /**
115
115
  * Get all defined routes, optionally organized by path or method
116
116
  */
117
- static allRoutes(): Array<Route<HttpContext, Middleware, Handler>>;
117
+ static allRoutes<T = any>(): Array<Route<HttpContext, Middleware, Handler<T>>>;
118
118
  /**
119
119
  * @param type - 'path' to get routes organized by path
120
120
  */
121
- static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler>>;
121
+ static allRoutes<T = any>(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler<T>>>;
122
122
  /**
123
123
  * @param type - 'method' to get routes organized by method
124
124
  */
125
- static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler>> };
126
- static allRoutes(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler>>;
127
- static route(name: string): Route<HttpContext, Middleware, Handler> | undefined;
125
+ static allRoutes<T = any>(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler<T>>> };
126
+ static allRoutes<T = any>(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler<T>>>;
127
+ static route<T = any>(name: string): Route<HttpContext, Middleware, Handler<T>> | undefined;
128
128
  /**
129
129
  * Apply the defined routes to a @koa/router instance
130
130
  *
File without changes
@@ -3,14 +3,17 @@ import { JitiOptions, JitiResolveOptions } from "jiti";
3
3
  import { AsyncLocalStorage } from "node:async_hooks";
4
4
 
5
5
  //#region src/types/basic.d.ts
6
+ type OwnStatics<T> = Omit<T, keyof Function | 'prototype'>;
6
7
  /**
7
8
  * Controller method reference
8
9
  */
9
- type ControllerHandler = [any, string];
10
+ type ControllerHandler<T = any> = T extends (abstract new (...args: any[]) => infer I) ? [T, ({ [K in keyof I]: I[K] extends ((...args: any[]) => any) ? K : never }[keyof I] & string) | ({ [K in keyof OwnStatics<T>]: OwnStatics<T>[K] extends ((...args: any[]) => any) ? K : never }[keyof OwnStatics<T>] & string)] : [any, string];
10
11
  type MaybePromise<T = any> = T | Promise<T>;
11
12
  type RouteGroupCallback = () => MaybePromise<any>;
12
13
  type RouteGroupEntry = RouteGroupCallback | string;
13
14
  type RouteGroupSource = RouteGroupEntry | RouteGroupEntry[];
15
+ type RouteGroupConditionEntry<S extends RouteGroupEntry> = S extends string ? string : S;
16
+ type RouteGroupConditionSource<S extends RouteGroupSource> = RouteGroupConditionEntry<S extends RouteGroupEntry[] ? S[number] : Extract<S, RouteGroupEntry>>;
14
17
  type MiddlewareHandle<Args extends any[] = any[], Return = any> = (...args: Args) => MaybePromise<Return>;
15
18
  type MiddlewareClass<M extends MiddlewareHandle = MiddlewareHandle> = new () => {
16
19
  handle: M;
@@ -78,9 +81,9 @@ interface RouteGroupContext {
78
81
  groupMiddlewares: any[];
79
82
  routeCollectors?: Array<Set<Route<any, any, any>>>;
80
83
  }
81
- interface RouteGroupOptions {
84
+ interface RouteGroupOptions<S extends RouteGroupSource = RouteGroupSource> {
82
85
  prefix: string;
83
- source: RouteGroupSource;
86
+ source: S;
84
87
  middlewares?: any[];
85
88
  context: AsyncLocalStorage<RouteGroupContext>;
86
89
  defaultPrefix: string;
@@ -88,7 +91,7 @@ interface RouteGroupOptions {
88
91
  normalizePath: (path: string) => string;
89
92
  removeRoute: (route: Route<any, any, any>) => void;
90
93
  }
91
- type RouteGroupCondition = (source: RouteGroupEntry) => MaybePromise<unknown>;
94
+ type RouteGroupCondition<S extends RouteGroupSource = RouteGroupSource> = (source: RouteGroupConditionSource<S>) => MaybePromise<unknown>;
92
95
  interface FileImporter {
93
96
  <T = unknown>(filePath: string): Promise<T>;
94
97
  <T = unknown>(filePath: string, userOptions?: JitiOptions | undefined): Promise<T>;
@@ -97,4 +100,4 @@ interface FileImporter {
97
100
  })): Promise<T>;
98
101
  }
99
102
  //#endregion
100
- export { ApiResourceMiddleware, ClassMiddleware, ControllerHandler, FileImporter, HttpMethod, MiddlewareHandle, RequestData, ResourceAction, ResourceRouteDefinition, ResourceRouteRegistrar, ResourceRouteRemover, ResourceRoutesOptions, RouteGroupCondition, RouteGroupContext, RouteGroupOptions, RouteGroupSource, RouterConfig };
103
+ export { ApiResourceMiddleware, ClassMiddleware, ControllerHandler, FileImporter, HttpMethod, MaybePromise, MiddlewareClass, MiddlewareHandle, MiddlewareInstance, RequestData, ResourceAction, ResourceRouteDefinition, ResourceRouteRegistrar, ResourceRouteRemover, ResourceRoutesOptions, RouteGroupCallback, RouteGroupCondition, RouteGroupConditionEntry, RouteGroupConditionSource, RouteGroupContext, RouteGroupEntry, RouteGroupOptions, RouteGroupSource, RouterConfig };
@@ -1,16 +1,19 @@
1
1
  import { Route } from "../Route.mjs";
2
- import { AsyncLocalStorage } from "node:async_hooks";
3
2
  import { JitiOptions, JitiResolveOptions } from "jiti";
3
+ import { AsyncLocalStorage } from "node:async_hooks";
4
4
 
5
5
  //#region src/types/basic.d.ts
6
+ type OwnStatics<T> = Omit<T, keyof Function | 'prototype'>;
6
7
  /**
7
8
  * Controller method reference
8
9
  */
9
- type ControllerHandler = [any, string];
10
+ type ControllerHandler<T = any> = T extends (abstract new (...args: any[]) => infer I) ? [T, ({ [K in keyof I]: I[K] extends ((...args: any[]) => any) ? K : never }[keyof I] & string) | ({ [K in keyof OwnStatics<T>]: OwnStatics<T>[K] extends ((...args: any[]) => any) ? K : never }[keyof OwnStatics<T>] & string)] : [any, string];
10
11
  type MaybePromise<T = any> = T | Promise<T>;
11
12
  type RouteGroupCallback = () => MaybePromise<any>;
12
13
  type RouteGroupEntry = RouteGroupCallback | string;
13
14
  type RouteGroupSource = RouteGroupEntry | RouteGroupEntry[];
15
+ type RouteGroupConditionEntry<S extends RouteGroupEntry> = S extends string ? string : S;
16
+ type RouteGroupConditionSource<S extends RouteGroupSource> = RouteGroupConditionEntry<S extends RouteGroupEntry[] ? S[number] : Extract<S, RouteGroupEntry>>;
14
17
  type MiddlewareHandle<Args extends any[] = any[], Return = any> = (...args: Args) => MaybePromise<Return>;
15
18
  type MiddlewareClass<M extends MiddlewareHandle = MiddlewareHandle> = new () => {
16
19
  handle: M;
@@ -78,9 +81,9 @@ interface RouteGroupContext {
78
81
  groupMiddlewares: any[];
79
82
  routeCollectors?: Array<Set<Route<any, any, any>>>;
80
83
  }
81
- interface RouteGroupOptions {
84
+ interface RouteGroupOptions<S extends RouteGroupSource = RouteGroupSource> {
82
85
  prefix: string;
83
- source: RouteGroupSource;
86
+ source: S;
84
87
  middlewares?: any[];
85
88
  context: AsyncLocalStorage<RouteGroupContext>;
86
89
  defaultPrefix: string;
@@ -88,7 +91,7 @@ interface RouteGroupOptions {
88
91
  normalizePath: (path: string) => string;
89
92
  removeRoute: (route: Route<any, any, any>) => void;
90
93
  }
91
- type RouteGroupCondition = (source: RouteGroupEntry) => MaybePromise<unknown>;
94
+ type RouteGroupCondition<S extends RouteGroupSource = RouteGroupSource> = (source: RouteGroupConditionSource<S>) => MaybePromise<unknown>;
92
95
  interface FileImporter {
93
96
  <T = unknown>(filePath: string): Promise<T>;
94
97
  <T = unknown>(filePath: string, userOptions?: JitiOptions | undefined): Promise<T>;
@@ -97,4 +100,4 @@ interface FileImporter {
97
100
  })): Promise<T>;
98
101
  }
99
102
  //#endregion
100
- export { ApiResourceMiddleware, ClassMiddleware, ControllerHandler, FileImporter, HttpMethod, MaybePromise, MiddlewareClass, MiddlewareHandle, MiddlewareInstance, RequestData, ResourceAction, ResourceRouteDefinition, ResourceRouteRegistrar, ResourceRouteRemover, ResourceRoutesOptions, RouteGroupCallback, RouteGroupCondition, RouteGroupContext, RouteGroupEntry, RouteGroupOptions, RouteGroupSource, RouterConfig };
103
+ export { ApiResourceMiddleware, ClassMiddleware, ControllerHandler, FileImporter, HttpMethod, MaybePromise, MiddlewareClass, MiddlewareHandle, MiddlewareInstance, RequestData, ResourceAction, ResourceRouteDefinition, ResourceRouteRegistrar, ResourceRouteRemover, ResourceRoutesOptions, RouteGroupCallback, RouteGroupCondition, RouteGroupConditionEntry, RouteGroupConditionSource, RouteGroupContext, RouteGroupEntry, RouteGroupOptions, RouteGroupSource, RouterConfig };
File without changes
@@ -35,7 +35,7 @@ req: Request$1) => any | Promise<any>;
35
35
  /**
36
36
  * Handler can be either a function or controller reference
37
37
  */
38
- type Handler = RouteHandler | ControllerHandler;
38
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
39
39
  /**
40
40
  * Middleware function type
41
41
  */
@@ -45,4 +45,4 @@ type MiddlewareFunction = MiddlewareHandle<[Request, Response, NextFunction]>;
45
45
  */
46
46
  type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
47
47
  //#endregion
48
- export { Handler, HttpContext, Middleware };
48
+ export { Handler, HttpContext, Middleware, MiddlewareFunction, RequestWithGetBody, RouteHandler };
@@ -35,7 +35,7 @@ req: Request$1) => any | Promise<any>;
35
35
  /**
36
36
  * Handler can be either a function or controller reference
37
37
  */
38
- type Handler = RouteHandler | ControllerHandler;
38
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
39
39
  /**
40
40
  * Middleware function type
41
41
  */
@@ -45,4 +45,4 @@ type MiddlewareFunction = MiddlewareHandle<[Request, Response, NextFunction]>;
45
45
  */
46
46
  type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
47
47
  //#endregion
48
- export { Handler, HttpContext, Middleware };
48
+ export { Handler, HttpContext, Middleware, MiddlewareFunction, RequestWithGetBody, RouteHandler };
File without changes
@@ -15,10 +15,10 @@ interface HttpContext extends ClearHttpContext {
15
15
  clearResponse: Response;
16
16
  }
17
17
  type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
18
- type Handler = RouteHandler | ControllerHandler;
18
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
19
19
  type NextFunction = (err?: Error) => void;
20
20
  type MiddlewareFunction = MiddlewareHandle<[req: RequestWithGetBody, reply: FastifyReply, next: NextFunction]>;
21
21
  type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
22
22
  type FastifyApp = FastifyInstance;
23
23
  //#endregion
24
- export { FastifyApp, Handler, HttpContext, Middleware };
24
+ export { FastifyApp, Handler, HttpContext, Middleware, MiddlewareFunction, NextFunction, RequestWithGetBody, RouteHandler };
@@ -15,10 +15,10 @@ interface HttpContext extends ClearHttpContext {
15
15
  clearResponse: Response;
16
16
  }
17
17
  type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
18
- type Handler = RouteHandler | ControllerHandler;
18
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
19
19
  type NextFunction = (err?: Error) => void;
20
20
  type MiddlewareFunction = MiddlewareHandle<[req: RequestWithGetBody, reply: FastifyReply, next: NextFunction]>;
21
21
  type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
22
22
  type FastifyApp = FastifyInstance;
23
23
  //#endregion
24
- export { FastifyApp, Handler, HttpContext, Middleware };
24
+ export { FastifyApp, Handler, HttpContext, Middleware, MiddlewareFunction, NextFunction, RequestWithGetBody, RouteHandler };
File without changes
@@ -2,12 +2,13 @@ import { ClearHttpContext } from "../Contracts.cjs";
2
2
  import { Response as Response$1 } from "../core/Response.cjs";
3
3
  import { ClassMiddleware, ControllerHandler } from "./basic.cjs";
4
4
  import { Request } from "../core/Request.cjs";
5
- import { EventHandlerRequest, H3, H3Event, Middleware, TypedServerRequest } from "h3";
5
+ import { EventHandlerRequest, H3, H3Event, Middleware as Middleware$1, TypedServerRequest } from "h3";
6
6
 
7
7
  //#region src/types/h3.d.ts
8
8
  type H3App = Omit<H3, 'fetch'> & {
9
9
  fetch: (request: TypedServerRequest<EventHandlerRequest>) => Promise<Response>;
10
10
  };
11
+ type MaybePromise<T = unknown> = T | Promise<T>;
11
12
  interface HttpRequest extends TypedServerRequest<EventHandlerRequest> {
12
13
  getBody: () => Record<string, any>;
13
14
  }
@@ -36,11 +37,12 @@ req: Request) => any | Promise<any>;
36
37
  /**
37
38
  * Handler can be either a function or controller reference
38
39
  */
39
- type Handler = RouteHandler | ControllerHandler;
40
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
41
+ type NextFunction = () => MaybePromise<unknown | undefined>;
40
42
  /**
41
43
  * Middleware function type
42
44
  */
43
- type MiddlewareFunction = Middleware;
44
- type Middleware$1 = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
45
+ type MiddlewareFunction = Middleware$1;
46
+ type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
45
47
  //#endregion
46
- export { H3App, Handler, HttpContext, Middleware$1 as Middleware };
48
+ export { H3App, Handler, HttpContext, HttpRequest, MaybePromise, Middleware, MiddlewareFunction, NextFunction, RouteHandler };
@@ -2,12 +2,13 @@ import { ClearHttpContext } from "../Contracts.mjs";
2
2
  import { Response as Response$1 } from "../core/Response.mjs";
3
3
  import { ClassMiddleware, ControllerHandler } from "./basic.mjs";
4
4
  import { Request } from "../core/Request.mjs";
5
- import { EventHandlerRequest, H3, H3Event, Middleware, TypedServerRequest } from "h3";
5
+ import { EventHandlerRequest, H3, H3Event, Middleware as Middleware$1, TypedServerRequest } from "h3";
6
6
 
7
7
  //#region src/types/h3.d.ts
8
8
  type H3App = Omit<H3, 'fetch'> & {
9
9
  fetch: (request: TypedServerRequest<EventHandlerRequest>) => Promise<Response>;
10
10
  };
11
+ type MaybePromise<T = unknown> = T | Promise<T>;
11
12
  interface HttpRequest extends TypedServerRequest<EventHandlerRequest> {
12
13
  getBody: () => Record<string, any>;
13
14
  }
@@ -36,11 +37,12 @@ req: Request) => any | Promise<any>;
36
37
  /**
37
38
  * Handler can be either a function or controller reference
38
39
  */
39
- type Handler = RouteHandler | ControllerHandler;
40
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
41
+ type NextFunction = () => MaybePromise<unknown | undefined>;
40
42
  /**
41
43
  * Middleware function type
42
44
  */
43
- type MiddlewareFunction = Middleware;
44
- type Middleware$1 = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
45
+ type MiddlewareFunction = Middleware$1;
46
+ type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
45
47
  //#endregion
46
- export { H3App, Handler, HttpContext, Middleware$1 as Middleware };
48
+ export { H3App, Handler, HttpContext, HttpRequest, MaybePromise, Middleware, MiddlewareFunction, NextFunction, RouteHandler };
File without changes
@@ -14,9 +14,10 @@ interface HttpContext extends Context, ClearHttpContext {
14
14
  clearResponse: Response;
15
15
  }
16
16
  type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
17
- type Handler = RouteHandler | ControllerHandler;
17
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
18
+ type NextFunction = () => Promise<void>;
18
19
  type MiddlewareFunction = MiddlewareHandler;
19
20
  type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
20
21
  type HonoApp = { [K in 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head']: (path: string, ...handlers: MiddlewareFunction[]) => any };
21
22
  //#endregion
22
- export { Handler, HonoApp, HttpContext, Middleware };
23
+ export { Handler, HonoApp, HttpContext, Middleware, MiddlewareFunction, NextFunction, RequestWithGetBody, RouteHandler };
@@ -14,9 +14,10 @@ interface HttpContext extends Context, ClearHttpContext {
14
14
  clearResponse: Response;
15
15
  }
16
16
  type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
17
- type Handler = RouteHandler | ControllerHandler;
17
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
18
+ type NextFunction = () => Promise<void>;
18
19
  type MiddlewareFunction = MiddlewareHandler;
19
20
  type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
20
21
  type HonoApp = { [K in 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head']: (path: string, ...handlers: MiddlewareFunction[]) => any };
21
22
  //#endregion
22
- export { Handler, HonoApp, HttpContext, Middleware };
23
+ export { Handler, HonoApp, HttpContext, Middleware, MiddlewareFunction, NextFunction, RequestWithGetBody, RouteHandler };
File without changes
@@ -18,9 +18,10 @@ interface HttpContext extends Koa.Context, ClearHttpContext {
18
18
  query: Record<string, any>;
19
19
  }
20
20
  type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
21
- type Handler = RouteHandler | ControllerHandler;
21
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
22
+ type NextFunction = Koa.Next;
22
23
  type MiddlewareFunction = Koa.Middleware<any, any>;
23
24
  type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
24
25
  type KoaRouterApp = Router<any, any>;
25
26
  //#endregion
26
- export { Handler, HttpContext, KoaRouterApp, Middleware };
27
+ export { Handler, HttpContext, KoaRouterApp, Middleware, NextFunction, RequestWithGetBody, RouteHandler };
@@ -18,9 +18,10 @@ interface HttpContext extends Koa.Context, ClearHttpContext {
18
18
  query: Record<string, any>;
19
19
  }
20
20
  type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
21
- type Handler = RouteHandler | ControllerHandler;
21
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
22
+ type NextFunction = Koa.Next;
22
23
  type MiddlewareFunction = Koa.Middleware<any, any>;
23
24
  type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
24
25
  type KoaRouterApp = Router<any, any>;
25
26
  //#endregion
26
- export { Handler, HttpContext, KoaRouterApp, Middleware };
27
+ export { Handler, HttpContext, KoaRouterApp, Middleware, NextFunction, RequestWithGetBody, RouteHandler };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-router",
3
- "version": "2.8.4",
3
+ "version": "2.8.6",
4
4
  "description": "Laravel-style routing for Node.js with support for Express, H3, Fastify, Hono, and Koa, including CommonJS, ESM, and TypeScript support.",
5
5
  "keywords": [
6
6
  "h3",
@@ -68,12 +68,30 @@
68
68
  "import": "./dist/koa/index.mjs",
69
69
  "require": "./dist/koa/index.cjs"
70
70
  },
71
- "./types/basic": "./dist/types/basic.mjs",
72
- "./types/express": "./dist/types/express.mjs",
73
- "./types/fastify": "./dist/types/fastify.mjs",
74
- "./types/h3": "./dist/types/h3.mjs",
75
- "./types/hono": "./dist/types/hono.mjs",
76
- "./types/koa": "./dist/types/koa.mjs",
71
+ "./types/basic": {
72
+ "import": "./dist/types/basic.mjs",
73
+ "require": "./dist/types/basic.cjs"
74
+ },
75
+ "./types/express": {
76
+ "import": "./dist/types/express.mjs",
77
+ "require": "./dist/types/express.cjs"
78
+ },
79
+ "./types/fastify": {
80
+ "import": "./dist/types/fastify.mjs",
81
+ "require": "./dist/types/fastify.cjs"
82
+ },
83
+ "./types/h3": {
84
+ "import": "./dist/types/h3.mjs",
85
+ "require": "./dist/types/h3.cjs"
86
+ },
87
+ "./types/hono": {
88
+ "import": "./dist/types/hono.mjs",
89
+ "require": "./dist/types/hono.cjs"
90
+ },
91
+ "./types/koa": {
92
+ "import": "./dist/types/koa.mjs",
93
+ "require": "./dist/types/koa.cjs"
94
+ },
77
95
  "./package.json": "./package.json"
78
96
  },
79
97
  "files": [
@@ -1,136 +0,0 @@
1
- import { Middleware } from "./types/express.mjs";
2
- import { Middleware as Middleware$1 } from "./types/fastify.mjs";
3
- import { Middleware as Middleware$2 } from "./types/h3.mjs";
4
- import { Middleware as Middleware$3 } from "./types/hono.mjs";
5
- import { Middleware as Middleware$4 } from "./types/koa.mjs";
6
- import { HttpMethod, RequestData } from "./types/basic.mjs";
7
-
8
- //#region src/Contracts.d.ts
9
- /**
10
- * HTTP context passed to route handlers
11
- */
12
- interface ClearHttpContext {}
13
- interface RouteParameter {
14
- name: string;
15
- field?: string;
16
- optional: boolean;
17
- }
18
- //#endregion
19
- //#region src/core/Request.d.ts
20
- declare class Request<X = any, M = any> extends ClearRequest<X, M> {
21
- original?: any;
22
- method: string;
23
- path: string;
24
- url: string;
25
- headers: Headers | Record<string, any>;
26
- constructor(init?: Partial<Request<X, M>> & {
27
- body?: RequestData;
28
- query?: RequestData;
29
- params?: RequestData;
30
- route?: Route<X, M>;
31
- });
32
- getBody(): RequestData;
33
- header(name: string): string;
34
- param(name: string): any;
35
- input(name: string): any;
36
- is(method: HttpMethod | string): boolean;
37
- }
38
- //#endregion
39
- //#region src/core/Response.d.ts
40
- declare class Response {
41
- [key: string]: any;
42
- body: any;
43
- headers: Headers;
44
- sent: boolean;
45
- statusCode: number;
46
- statusText: string;
47
- constructor(init?: Partial<Response | globalThis.Response>);
48
- status(code: number): this;
49
- setStatusText(text: string): this;
50
- code(code: number): this;
51
- setHeader(name: string, value: string): this;
52
- header(name: string, value: string): this;
53
- set(name: string, value: string): this;
54
- type(contentType: string): this;
55
- send(body?: any): this;
56
- json(body: any): this;
57
- html(body: string): this;
58
- text(body: string): this;
59
- noContent(): this;
60
- }
61
- //#endregion
62
- //#region src/ClearRequest.d.ts
63
- declare class ClearRequest<X = any, M = Middleware$2 | Middleware | Middleware$1 | Middleware$3 | Middleware$4> {
64
- [key: string]: any;
65
- /**
66
- * @param body - Parsed request body
67
- */
68
- body: RequestData;
69
- /**
70
- * @param query - Parsed query parameters
71
- */
72
- query: RequestData;
73
- /**
74
- * @param params - Parsed route parameters
75
- */
76
- params: RequestData;
77
- route: Route<X, M>;
78
- constructor(init?: Partial<ClearRequest>);
79
- }
80
- //#endregion
81
- //#region src/Route.d.ts
82
- /**
83
- * @class clear-router Route
84
- * @description A route describes a single enpoint on clear-router
85
- * @author 3m1n3nc3
86
- * @repository https://github.com/arkstack-tmp/clear-router
87
- */
88
- declare class Route<X = any, M = Middleware$2 | Middleware, H = any> {
89
- ctx: X;
90
- body: RequestData;
91
- query: RequestData;
92
- params: RequestData;
93
- clearRequest: ClearRequest;
94
- methods: HttpMethod[];
95
- path: string;
96
- registrationPaths: string[];
97
- parameters: RouteParameter[];
98
- routeName?: string;
99
- handler: H;
100
- middlewares: M[];
101
- controllerName?: string;
102
- actionName?: string;
103
- handlerType: 'function' | 'controller';
104
- middlewareCount: number;
105
- constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[], options?: {
106
- registrationPaths?: string[];
107
- parameters?: RouteParameter[];
108
- onName?: (name: string, route: Route<X, M, H>, previousName?: string) => void;
109
- normalizeMiddleware?: (middleware: M) => M;
110
- });
111
- private onName?;
112
- private normalizeMiddleware?;
113
- /**
114
- * Set the route name
115
- *
116
- * @param name
117
- * @returns
118
- */
119
- name(name: string): this;
120
- /**
121
- * Register one or more middleware that will be executed before the route.
122
- *
123
- * @param middlewares
124
- * @returns
125
- */
126
- middleware(middlewares: M[] | M): this;
127
- /**
128
- * Get the path generated and accessible by this route
129
- *
130
- * @param params
131
- * @returns
132
- */
133
- toPath(params?: RequestData): string;
134
- }
135
- //#endregion
136
- export { ClearHttpContext as i, Response as n, Request as r, Route as t };
@@ -1 +0,0 @@
1
- import { ApiResourceMiddleware, ClassMiddleware, ControllerHandler, FileImporter, HttpMethod, MaybePromise, MiddlewareClass, MiddlewareHandle, MiddlewareInstance, RequestData, ResourceAction, ResourceRouteDefinition, ResourceRouteRegistrar, ResourceRouteRemover, ResourceRoutesOptions, RouteGroupCallback, RouteGroupCondition, RouteGroupContext, RouteGroupEntry, RouteGroupOptions, RouteGroupSource, RouterConfig } from "./basic.mjs";