@@ -14,7 +14,7 @@ import { Macroable } from 'macroable'
1414import { lodash } from '@poppinss/utils'
1515
1616import { MiddlewareHandler } from '@ioc:Adonis/Core/Middleware'
17- import { RouteMatchers , RouteResourceContract } from '@ioc:Adonis/Core/Route'
17+ import { RouteMatchers , RouteResourceContract , ResourceRouteNames } from '@ioc:Adonis/Core/Route'
1818
1919import { Route } from './Route'
2020
@@ -58,7 +58,7 @@ export class RouteResource extends Macroable implements RouteResourceContract {
5858 /**
5959 * Add a new route for the given pattern, methods and controller action
6060 */
61- private makeRoute ( pattern : string , methods : string [ ] , action : string ) {
61+ private makeRoute ( pattern : string , methods : string [ ] , action : ResourceRouteNames ) {
6262 const route = new Route ( pattern , methods , `${ this . controller } .${ action } ` , this . globalMatchers )
6363
6464 route . as ( `${ this . resourceName } .${ action } ` )
@@ -90,7 +90,7 @@ export class RouteResource extends Macroable implements RouteResourceContract {
9090 /**
9191 * Filter the routes based on their partial names
9292 */
93- private filter ( names : string [ ] , inverse : boolean ) {
93+ private filter ( names : ResourceRouteNames [ ] , inverse : boolean ) {
9494 return this . routes . filter ( ( route ) => {
9595 const match = names . find ( ( name ) => route . name . endsWith ( name ) )
9696 return inverse ? ! match : match
@@ -100,15 +100,15 @@ export class RouteResource extends Macroable implements RouteResourceContract {
100100 /**
101101 * Register only given routes and remove others
102102 */
103- public only ( names : string [ ] ) : this {
103+ public only ( names : ResourceRouteNames [ ] ) : this {
104104 this . filter ( names , true ) . forEach ( ( route ) => ( route . deleted = true ) )
105105 return this
106106 }
107107
108108 /**
109109 * Register all routes, except the one's defined
110110 */
111- public except ( names : string [ ] ) : this {
111+ public except ( names : ResourceRouteNames [ ] ) : this {
112112 this . filter ( names , false ) . forEach ( ( route ) => ( route . deleted = true ) )
113113 return this
114114 }
@@ -118,13 +118,19 @@ export class RouteResource extends Macroable implements RouteResourceContract {
118118 * are meant to show forms will not be registered
119119 */
120120 public apiOnly ( ) : this {
121- return this . except ( [ '. create' , '. edit' ] )
121+ return this . except ( [ 'create' , 'edit' ] )
122122 }
123123
124124 /**
125125 * Add middleware to routes inside the resource
126126 */
127- public middleware ( middleware : { [ name : string ] : MiddlewareHandler | MiddlewareHandler [ ] } ) : this {
127+ public middleware (
128+ middleware : {
129+ [ P in ResourceRouteNames ] ?: MiddlewareHandler | MiddlewareHandler [ ]
130+ } & {
131+ '*' ?: MiddlewareHandler | MiddlewareHandler [ ]
132+ }
133+ ) : this {
128134 for ( let name in middleware ) {
129135 if ( name === '*' ) {
130136 this . routes . forEach ( ( one ) => one . middleware ( middleware [ name ] ) )
0 commit comments