import { ListOptions , ListResult , Reference , SettableMetadata , StringFormat , UploadMetadata } from './interfaces' ; import { AngularFireUploadTask , createUploadTask } from './task' ; import { from , Observable , of } from 'rxjs' ; import { observeOutsideAngular , keepUnstableUntilFirst } from '@angular/fire' ; import { switchMap } from 'rxjs/operators' ; export interface AngularFireStorageReference { getDownloadURL ( ) : Observable < any > ; getMetadata ( ) : Observable < any > ; delete ( ) : Observable < any > ; child ( path ) : AngularFireStorageReference ; updateMetadata ( meta ) : Observable < any > ; put ( data , metadata ? ) : AngularFireUploadTask ; putString ( data , format ? , metadata ? ) : AngularFireUploadTask ; list ( options ? ) : Observable < ListResult > ; listAll ( ) : Observable < ListResult > ; } /**
 * Create an AngularFire wrapped Storage Reference. This object
 * creates observable methods from promise based methods.
 */ export function createStorageRef ( ref ) { return { getDownloadURL : ( ) => of ( undefined ) . pipe ( observeOutsideAngular , switchMap ( ( ) => ref . getDownloadURL ( ) ) , keepUnstableUntilFirst ) , getMetadata : ( ) => of ( undefined ) . pipe ( observeOutsideAngular , switchMap ( ( ) => ref . getMetadata ( ) ) , keepUnstableUntilFirst ) , delete : ( ) => from ( ref . delete ( ) ) , child : ( path ) => createStorageRef ( ref . child ( path ) ) , updateMetadata : ( meta ) => from ( ref . updateMetadata ( meta ) ) , put : ( data , metadata ? ) => { const task = ref . put ( data , metadata ) ; return createUploadTask ( task ) ; } , putString : ( data , format ? , metadata ? ) => { const task = ref . putString ( data , format , metadata ) ; return createUploadTask ( task ) ; } , list : ( options ? ) => from ( ref . list ( options ) ) , listAll : ( ) => from ( ref . listAll ( ) ) } ; }