@@ -19,26 +19,13 @@ class FrontendAPI implements FrontendAPIInterface {
1919 public modalStore :any
2020 public filtersStore :any
2121 public coreStore :any
22- private saveInterceptors : Record < string , Array < ( ctx : { action : 'create' | 'edit' ; values : any ; resource : any ; resourceId : string ; } ) => Promise < { ok : boolean ; error ?: string | null ; extra ?: object ; } > > > = { } ;
23-
24- public list : {
25- refresh ( ) : Promise < { error ? : string } > ;
26- silentRefresh ( ) : Promise < { error ? : string } > ;
27- silentRefreshRow ( pk : any ) : Promise < { error ? : string } > ;
28- closeThreeDotsDropdown ( ) : Promise < { error ? : string } > ;
29- closeUserMenuDropdown : ( ) => void ;
30- setFilter : ( filter : FilterParams ) => void ;
31- updateFilter : ( filter : FilterParams ) => void ;
32- clearFilters : ( ) => void ;
33- }
22+ private saveInterceptors : Record < string , Array < Parameters < FrontendAPIInterface [ 'registerSaveInterceptor' ] > [ 0 ] > > = { } ;
3423
35- public menu : {
36- refreshMenuBadges : ( ) => void ;
37- }
24+ public list : FrontendAPIInterface [ 'list' ] ;
3825
39- public show : {
40- refresh ( ) : void ;
41- }
26+ public menu : FrontendAPIInterface [ 'menu' ] ;
27+
28+ public show : FrontendAPIInterface [ 'show' ] ;
4229
4330 closeUserMenuDropdown ( ) : void {
4431 console . log ( 'closeUserMenuDropdown' )
@@ -70,9 +57,6 @@ class FrontendAPI implements FrontendAPIInterface {
7057 console . log ( 'closeThreeDotsDropdown' )
7158 return { error : 'Not implemented' }
7259 } ,
73- closeUserMenuDropdown : ( ) => {
74- console . log ( 'closeUserMenuDropdown' )
75- } ,
7660 setFilter : this . setListFilter . bind ( this ) ,
7761 updateFilter : this . updateListFilter . bind ( this ) ,
7862 clearFilters : this . clearListFilters . bind ( this ) ,
@@ -83,11 +67,15 @@ class FrontendAPI implements FrontendAPIInterface {
8367 console . log ( 'show.refresh' )
8468 }
8569 }
70+
71+ this . closeUserMenuDropdown = ( ) => {
72+ console . log ( 'closeUserMenuDropdown' )
73+ } ;
8674 }
8775
8876 registerSaveInterceptor (
89- handler : ( ctx : { action : 'create' | 'edit' ; values : any ; resource : any ; } ) => Promise < { ok : boolean ; error ?: string | null ; extra ?: object ; } > ,
90- ) : void {
77+ handler : Parameters < FrontendAPIInterface [ 'registerSaveInterceptor' ] > [ 0 ]
78+ ) : ReturnType < FrontendAPIInterface [ 'registerSaveInterceptor' ] > {
9179 const rid = router . currentRoute . value ?. params ?. resourceId as string ;
9280 if ( ! rid ) {
9381 return ;
@@ -98,7 +86,7 @@ class FrontendAPI implements FrontendAPIInterface {
9886 this . saveInterceptors [ rid ] . push ( handler ) ;
9987 }
10088
101- async runSaveInterceptors ( params : { action : 'create' | 'edit' ; values : any ; resource : any ; resourceId : string ; } ) : Promise < { ok : boolean ; error ?: string | null ; extra ?: object ; } > {
89+ async runSaveInterceptors ( params : Parameters < FrontendAPIInterface [ 'runSaveInterceptors' ] > [ 0 ] ) : ReturnType < FrontendAPIInterface [ 'runSaveInterceptors' ] > {
10290 const list = this . saveInterceptors [ params . resourceId ] || [ ] ;
10391 const aggregatedExtra : Record < string , any > = { } ;
10492 for ( const fn of list ) {
@@ -120,15 +108,15 @@ class FrontendAPI implements FrontendAPIInterface {
120108 return { ok : true , extra : aggregatedExtra } ;
121109 }
122110
123- clearSaveInterceptors ( resourceId ?: string ) : void {
111+ clearSaveInterceptors ( resourceId ?: Parameters < FrontendAPIInterface [ 'clearSaveInterceptors' ] > [ 0 ] ) : ReturnType < FrontendAPIInterface [ 'clearSaveInterceptors' ] > {
124112 if ( resourceId ) {
125113 delete this . saveInterceptors [ resourceId ] ;
126114 } else {
127115 this . saveInterceptors = { } ;
128116 }
129117 }
130118
131- confirm ( params : ConfirmParams ) : Promise < boolean > {
119+ confirm ( params : Parameters < FrontendAPIInterface [ 'confirm' ] > [ 0 ] ) : ReturnType < FrontendAPIInterface [ 'confirm' ] > {
132120 return new Promise ( ( resolve , reject ) => {
133121 this . modalStore . setModalContent ( {
134122 content : params . message ,
@@ -142,7 +130,7 @@ class FrontendAPI implements FrontendAPIInterface {
142130 } )
143131 }
144132
145- alert ( params : AlertParams ) : void | Promise < string > | string {
133+ alert ( params : Parameters < FrontendAPIInterface [ 'alert' ] > [ 0 ] ) : ReturnType < FrontendAPIInterface [ 'alert' ] > {
146134 const toats = {
147135 message : params . message ,
148136 messageHtml : params . messageHtml ,
@@ -162,14 +150,14 @@ class FrontendAPI implements FrontendAPIInterface {
162150 }
163151 }
164152
165- listFilterValidation ( filter : FilterParams ) : boolean {
153+ listFilterValidation ( filter : Parameters < FrontendAPIInterface [ 'list' ] [ 'setFilter' ] > [ 0 ] ) : boolean {
166154 if ( router . currentRoute . value . meta . type !== 'list' ) {
167155 throw new Error ( `Cannot use ${ this . setListFilter . name } filter on a list page` )
168156 }
169157 return true
170158 }
171159
172- setListFilter ( filter : FilterParams ) : void {
160+ setListFilter ( filter : Parameters < FrontendAPIInterface [ 'list' ] [ 'setFilter' ] > [ 0 ] ) : ReturnType < FrontendAPIInterface [ 'list' ] [ 'setFilter' ] > {
173161 if ( this . listFilterValidation ( filter ) ) {
174162 const existingFilterIndex = this . filtersStore . filters . findIndex ( ( f : any ) => {
175163 return f . field === filter . field && f . operator === filter . operator
0 commit comments