import { NgZone } from '@angular/core' ; import { Observable } from 'rxjs' ; type FunctionPropertyNames < T > = { [ K in keyof T ] : T [ K ] extends Function ? K : never ; } [ keyof T ] ; type PromiseReturningFunctionPropertyNames < T > = { [ K in FunctionPropertyNames < T > ] : ReturnType < T [ K ] > extends Promise < any > ? K : never ; } [ FunctionPropertyNames < T > ] ; type NonPromiseReturningFunctionPropertyNames < T > = { [ K in FunctionPropertyNames < T > ] : ReturnType < T [ K ] > extends Promise < any > ? never : K ; } [ FunctionPropertyNames < T > ] ; type NonFunctionPropertyNames < T > = { [ K in keyof T ] : T [ K ] extends Function ? never : K ; } [ keyof T ] ; export type ɵPromiseProxy < T > = { [ K in NonFunctionPropertyNames < T > ] : Promise < T [ K ] > ; } & { [ K in NonPromiseReturningFunctionPropertyNames < T > ] : ( ... args : Parameters < T [ K ] > ) => Promise < ReturnType < T [ K ] > > ; } & { [ K in PromiseReturningFunctionPropertyNames < T > ] : ( ... args : Parameters < T [ K ] > ) => ReturnType < T [ K ] > ; } ; const noopFunctions = [ 'ngOnDestroy' ] ; export const ɵlazySDKProxy = ( klass , observable , zone , options = { } ) => { return new Proxy ( klass , { get : ( _ , name ) => zone . runOutsideAngular ( ( ) => { if ( klass [ name ] ) { if ( options ?. spy ?. get ) { options . spy . get ( name , klass [ name ] ) ; } return klass [ name ] ; } if ( noopFunctions . indexOf ( name ) > - 1 ) { return ( ) => { } ; } const promise = observable . toPromise ( ) . then ( mod => { const ret = mod && mod [ name ] ; if ( typeof ret === 'function' ) { return ret . bind ( mod ) ; } else if ( ret && ret . then ) { return ret . then ( ( res ) => zone . run ( ( ) => res ) ) ; } else { return zone . run ( ( ) => ret ) ; } } ) ; return new Proxy ( ( ) => { } , { get : ( _ , name ) => promise [ name ] , apply : ( self , _ , args ) => promise . then ( it => { const res = it && it ( ... args ) ; if ( options ?. spy ?. apply ) { options . spy . apply ( name , args , res ) ; } return res ; } ) } ) ; } ) } ) ; } ; export const ɵapplyMixins = ( derivedCtor , constructors ) => { constructors . forEach ( ( baseCtor ) => { Object . getOwnPropertyNames ( baseCtor . prototype || baseCtor ) . forEach ( ( name ) => { Object . defineProperty ( derivedCtor . prototype , name , Object . getOwnPropertyDescriptor ( baseCtor . prototype || baseCtor , name ) ) ; } ) ; } ) ; } ;