@@ -546,7 +546,7 @@ export class KubernetesObjectApi extends ApisApi {
546
546
*
547
547
* @returns WatchResult object that can be used to abort the watch.
548
548
*/
549
- public async watch < T > ( {
549
+ public async watch < T extends KubernetesObject | KubernetesObject > ( {
550
550
resource,
551
551
options = { } ,
552
552
callback,
@@ -564,8 +564,39 @@ export class KubernetesObjectApi extends ApisApi {
564
564
if ( ! this . watcher ) {
565
565
throw new Error ( 'Watcher not initialized' ) ;
566
566
}
567
- const resourcePath = await this . specUriPath ( resource , 'list' ) ;
568
- const res : RequestResult = await this . watcher . watch ( resourcePath , options , callback , done ) ;
567
+ const resourcePath = new URL (
568
+ await this . specUriPath (
569
+ {
570
+ apiVersion : resource . apiVersion ,
571
+ kind : resource . kind ,
572
+ metadata : {
573
+ namespace : resource . namespace ,
574
+ } ,
575
+ } ,
576
+ 'list' ,
577
+ ) ,
578
+ ) . pathname ;
579
+ const type = await this . getSerializationType ( resource . apiVersion , resource . kind ) ;
580
+ const cb : WatchCallback < T > = ( phase : KubernetesEventType , apiObj : T , watchObj ?: WatchObject < T > ) => {
581
+ const obj = ObjectSerializer . deserialize ( apiObj , type ) ;
582
+ callback (
583
+ phase ,
584
+ obj ,
585
+ watchObj
586
+ ? {
587
+ ...watchObj ,
588
+ object : obj ,
589
+ }
590
+ : undefined ,
591
+ ) ;
592
+ } ;
593
+ const res : RequestResult = await this . watcher . watch (
594
+ resourcePath ,
595
+ options ,
596
+ // required to convert to less strict type.
597
+ cb as ( phase : string , apiObj : any , watchObj ?: any ) => void ,
598
+ done ,
599
+ ) ;
569
600
return {
570
601
abort : ( ) => res . abort ( ) ,
571
602
} ;
0 commit comments