File tree Expand file tree Collapse file tree 6 files changed +12
-8
lines changed Expand file tree Collapse file tree 6 files changed +12
-8
lines changed Original file line number Diff line number Diff line change 11import { Hono } from "hono" ;
2- import type { RouteMetadata , ServerOptions } from "@/types" ;
2+ import type { Constructor , RouteMetadata , ServerOptions } from "@/types" ;
33import { defaultOptions } from "@/utils/constants" ;
44import { controllerMetadata , routeMetadata } from "@/utils/meta-data" ;
55import { Container } from "@/di/Container" ;
@@ -38,7 +38,7 @@ export class Application {
3838
3939 this . app . route ( this . options . basePath ?? '' , baseGroup ) ;
4040 }
41- private getControllerPath ( Controller : Function ) : string {
41+ private getControllerPath ( Controller : Constructor ) : string {
4242 const path = controllerMetadata . get ( Controller ) ?? "" ;
4343 return path . replace ( / \/ $ / , "" ) ; // Normalize trailing slash
4444 }
Original file line number Diff line number Diff line change 11import { Container } from "@/di/Container" ;
2+ import type { Constructor } from "@/types" ;
23import { controllerMetadata } from "@/utils/meta-data" ;
34
45export function Controller ( path : string ) {
5- return ( target : Function ) => {
6+ return < T extends Constructor > ( target : T ) => {
67 controllerMetadata . set ( target , path ) ;
78 // Auto-register the controller as a singleton
89 Container . register ( target , ( ) => new ( target as any ) ( ) , "singleton" ) ;
Original file line number Diff line number Diff line change 11import { Application } from './core/Application' ;
2- import type { ServerOptions } from './types' ;
2+ import type { Constructor , ServerOptions } from './types' ;
33
44// -------------------------------------------------------------------------
55// Main exports
Original file line number Diff line number Diff line change 1+ export type Constructor < T = { } > = new ( ...args : any [ ] ) => T ;
2+
3+
14export type ServerOptions = {
25 basePath ?: string ;
3- controllers ?: Function [ ] ;
6+ controllers ?: Constructor [ ] ;
47 middlewares ?: any [ ] ;
58} ;
69
Original file line number Diff line number Diff line change @@ -26,6 +26,6 @@ export class Logger {
2626 }
2727
2828 public static debug ( message : string ) : void {
29- console . log ( `\x1b[34mDEBUG : ${ message } \x1b[0m` ) ;
29+ console . log ( `\x1b[35mDEBUG : ${ message } \x1b[0m` ) ;
3030 }
3131}
Original file line number Diff line number Diff line change 1- import type { RouteMetadata } from "@/types" ;
1+ import type { Constructor , RouteMetadata } from "@/types" ;
22
3- export const controllerMetadata = new WeakMap < Function , string > ( ) ;
3+ export const controllerMetadata = new WeakMap < Constructor , string > ( ) ;
44export const routeMetadata = new WeakMap < object , RouteMetadata [ ] > ( ) ;
55export const injectionMetadata = new WeakMap < object , unknown [ ] > ( ) ;
You can’t perform that action at this time.
0 commit comments