Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ab52c7

Browse files
committed
feat: add importExpression and controller method to the route handler
1 parent c04fdee commit 6ab52c7

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/router/route.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424
MiddlewareFn,
2525
ParsedNamedMiddleware,
2626
ParsedGlobalMiddleware,
27+
RouteHandlerInfo,
2728
} from '../types/middleware.ts'
2829

2930
import type {
@@ -155,10 +156,12 @@ export class Route<Controller extends Constructor<any> = any> extends Macroable
155156

156157
return {
157158
handler: {
159+
method,
158160
reference: handler,
161+
importExpression: moduleRefId,
159162
...moduleImporter(() => this.#app.import(moduleRefId), method).toHandleMethod(),
160163
name: handler,
161-
},
164+
} satisfies StoreRouteHandler,
162165
routeName: `${new StringBuilder(moduleRefId.split('/').pop()!)
163166
.removeSuffix('controller')
164167
.snakeCase()}.${string.snakeCase(method)}`,
@@ -178,9 +181,11 @@ export class Route<Controller extends Constructor<any> = any> extends Macroable
178181
if (is.class(controller)) {
179182
return {
180183
handler: {
184+
method,
181185
reference: handler,
186+
importExpression: null,
182187
...moduleCaller(controller, method).toHandleMethod(),
183-
},
188+
} satisfies StoreRouteHandler,
184189
routeName: `${new StringBuilder(controller.name)
185190
.removeSuffix('controller')
186191
.snakeCase()}.${string.snakeCase(method)}`,
@@ -193,9 +198,11 @@ export class Route<Controller extends Constructor<any> = any> extends Macroable
193198
*/
194199
return {
195200
handler: {
201+
method,
196202
reference: handler,
203+
importExpression: String(controller),
197204
...moduleImporter(controller, method).toHandleMethod(),
198-
},
205+
} satisfies StoreRouteHandler,
199206
routeName: `${new StringBuilder(controller.name)
200207
.removeSuffix('controller')
201208
.snakeCase()}.${string.snakeCase(method)}`,

src/types/route.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export type RouteFn = (ctx: HttpContext) => any
5757
export type StoreRouteHandler =
5858
| RouteFn
5959
| {
60+
name?: string
61+
method: string
62+
importExpression: string | null
6063
reference: string | [LazyImport<Constructor<any>> | Constructor<any>, any?]
6164
handle: (
6265
resolver: ContainerResolver<any>,

0 commit comments

Comments
 (0)