@@ -444,15 +444,16 @@ export class StacksRouter implements RouterInterface {
444444
445445 /**
446446 * Create a route group with shared attributes
447+ * Supports both sync and async callbacks
447448 */
448- group ( options : string | RouteGroupOptions , callback ?: ( ) => void ) : this {
449+ group ( options : string | RouteGroupOptions , callback ?: ( ( ) => void ) | ( ( ) => Promise < void > ) ) : this {
449450 // Handle string prefix shorthand
450451 if ( typeof options === 'string' ) {
451452 options = { prefix : options . startsWith ( '/' ) ? options . slice ( 1 ) : options }
452453 }
453454
454455 // Handle function-only call
455- let cb : ( ) => void
456+ let cb : ( ( ) => void ) | ( ( ) => Promise < void > )
456457 if ( typeof options === 'function' ) {
457458 cb = options
458459 options = { }
@@ -479,18 +480,33 @@ export class StacksRouter implements RouterInterface {
479480 // Create temporary routes array to track routes in this group
480481 this . _stacksRoutes = [ ]
481482
482- // Execute callback
483- cb ( )
483+ // Execute callback (handle both sync and async)
484+ const result = cb ( )
484485
485- // Merge group routes back to main routes
486- for ( const route of this . _stacksRoutes ) {
487- previousRoutes . push ( route )
486+ // If callback returns a promise, track it for later awaiting
487+ if ( result instanceof Promise ) {
488+ const groupPromise = result . then ( ( ) => {
489+ // Merge group routes back to main routes after async completion
490+ for ( const route of this . _stacksRoutes ) {
491+ previousRoutes . push ( route )
492+ }
493+ // Restore previous state
494+ this . _groupPrefix = previousPrefix
495+ this . _groupMiddleware = previousMiddleware
496+ this . _stacksRoutes = previousRoutes
497+ } )
498+ this . _pendingRoutes . push ( groupPromise )
499+ }
500+ else {
501+ // Sync callback - merge immediately
502+ for ( const route of this . _stacksRoutes ) {
503+ previousRoutes . push ( route )
504+ }
505+ // Restore previous state
506+ this . _groupPrefix = previousPrefix
507+ this . _groupMiddleware = previousMiddleware
508+ this . _stacksRoutes = previousRoutes
488509 }
489-
490- // Restore previous state
491- this . _groupPrefix = previousPrefix
492- this . _groupMiddleware = previousMiddleware
493- this . _stacksRoutes = previousRoutes
494510
495511 return this
496512 }
@@ -511,10 +527,13 @@ export class StacksRouter implements RouterInterface {
511527
512528 /**
513529 * Set middleware for the last registered route
530+ * Accepts a string name, array of strings, or middleware handlers
514531 */
515- middleware ( middleware : StacksRoute [ 'middleware' ] ) : this {
532+ middleware ( middleware : string | string [ ] | StacksRoute [ 'middleware' ] ) : this {
516533 if ( this . _stacksRoutes . length > 0 ) {
517- this . _stacksRoutes [ this . _stacksRoutes . length - 1 ] . middleware = middleware
534+ // Normalize to array if single string
535+ const normalizedMiddleware = typeof middleware === 'string' ? [ middleware ] : middleware
536+ this . _stacksRoutes [ this . _stacksRoutes . length - 1 ] . middleware = normalizedMiddleware
518537 }
519538 return this
520539 }
@@ -763,6 +782,10 @@ export class StacksRouter implements RouterInterface {
763782 prepareUri ( path : string ) : string {
764783 if ( path . startsWith ( '/' ) ) path = path . slice ( 1 )
765784 path = `/${ path } `
785+
786+ // Normalize :param syntax to {param} syntax for bun-router compatibility
787+ path = path . replace ( / : ( \w + ) / g, '{$1}' )
788+
766789 return path . endsWith ( '/' ) ? path . slice ( 0 , - 1 ) : path
767790 }
768791
0 commit comments