{"version":3,"file":"angular-fire-compat-storage.js","sources":["../../../src/compat/storage/observable/fromTask.ts","../../../src/compat/storage/task.ts","../../../src/compat/storage/ref.ts","../../../src/compat/storage/storage.ts","../../../src/compat/storage/pipes/storageUrl.pipe.ts","../../../src/compat/storage/storage.module.ts","../../../src/compat/storage/angular-fire-compat-storage.ts"],"sourcesContent":["import { Observable } from 'rxjs';\nimport { debounceTime } from 'rxjs/operators';\nimport { UploadTask, UploadTaskSnapshot } from '../interfaces';\n\n// need to import, else the types become import('firebase/compat/app').default.storage.UploadTask\n// and it no longer works w/Firebase v7\nimport firebase from 'firebase/compat/app';\n\n// Things aren't working great, I'm having to put in a lot of work-arounds for what\n// appear to be Firebase JS SDK bugs https://github.com/firebase/firebase-js-sdk/issues/4158\nexport function fromTask(task: UploadTask) {\n return new Observable(subscriber => {\n const progress = (snap: UploadTaskSnapshot) => subscriber.next(snap);\n const error = e => subscriber.error(e);\n const complete = () => subscriber.complete();\n // emit the current snapshot, so they don't have to wait for state_changes\n // to fire next... this is stale if the task is no longer running :(\n progress(task.snapshot);\n const unsub = task.on('state_changed', progress);\n // it turns out that neither task snapshot nor 'state_changed' fire the last\n // snapshot before completion, the one with status 'success\" and 100% progress\n // so let's use the promise form of the task for that\n task.then(snapshot => {\n progress(snapshot);\n complete();\n }, e => {\n // TODO investigate, again this is stale, we never fire a canceled or error it seems\n progress(task.snapshot);\n error(e);\n });\n // on's type if Function, rather than () => void, need to wrap\n return function unsubscribe() {\n unsub();\n };\n }).pipe(\n // deal with sync emissions from first emitting `task.snapshot`, this makes sure\n // that if the task is already finished we don't emit the old running state\n debounceTime(0)\n );\n}\n","import { UploadTask, UploadTaskSnapshot } from './interfaces';\nimport { fromTask } from './observable/fromTask';\nimport { Observable } from 'rxjs';\nimport { map } from 'rxjs/operators';\n\nexport interface AngularFireUploadTask {\n task: UploadTask;\n snapshotChanges(): Observable;\n percentageChanges(): Observable;\n pause(): boolean;\n cancel(): boolean;\n resume(): boolean;\n then(\n onFulfilled?: ((a: UploadTaskSnapshot) => any) | null,\n onRejected?: ((a: Error) => any) | null\n ): Promise;\n catch(onRejected: (a: Error) => any): Promise;\n}\n\n/**\n * Create an AngularFireUploadTask from a regular UploadTask from the Storage SDK.\n * This method creates an observable of the upload and returns on object that provides\n * multiple methods for controlling and monitoring the file upload.\n */\nexport function createUploadTask(task: UploadTask): AngularFireUploadTask {\n const inner$ = fromTask(task);\n return {\n task,\n then: task.then.bind(task),\n catch: task.catch.bind(task),\n pause: task.pause.bind(task),\n cancel: task.cancel.bind(task),\n resume: task.resume.bind(task),\n snapshotChanges: () => inner$,\n percentageChanges: () => inner$.pipe(\n map(s => s.bytesTransferred / s.totalBytes * 100)\n )\n };\n}\n","import { ListOptions, ListResult, Reference, SettableMetadata, StringFormat, UploadMetadata } from './interfaces';\nimport { AngularFireUploadTask, createUploadTask } from './task';\nimport { from, Observable, of } from 'rxjs';\nimport { observeOutsideAngular, keepUnstableUntilFirst } from '@angular/fire';\nimport { switchMap } from 'rxjs/operators';\n\nexport interface AngularFireStorageReference {\n getDownloadURL(): Observable;\n getMetadata(): Observable;\n delete(): Observable;\n child(path: string): AngularFireStorageReference;\n updateMetadata(meta: SettableMetadata): Observable;\n put(data: any, metadata?: UploadMetadata | undefined): AngularFireUploadTask;\n putString(data: string, format?: string | undefined, metadata?: UploadMetadata | undefined): AngularFireUploadTask;\n list(options?: ListOptions): Observable;\n listAll(): Observable;\n}\n\n/**\n * Create an AngularFire wrapped Storage Reference. This object\n * creates observable methods from promise based methods.\n */\nexport function createStorageRef(\n ref: Reference\n): AngularFireStorageReference {\n return {\n getDownloadURL: () => of(undefined).pipe(\n observeOutsideAngular,\n switchMap(() => ref.getDownloadURL()),\n keepUnstableUntilFirst\n ),\n getMetadata: () => of(undefined).pipe(\n observeOutsideAngular,\n switchMap(() => ref.getMetadata()),\n keepUnstableUntilFirst\n ),\n delete: () => from(ref.delete()),\n child: (path: string) => createStorageRef(ref.child(path)),\n updateMetadata: (meta: SettableMetadata) => from(ref.updateMetadata(meta)),\n put: (data: any, metadata?: UploadMetadata) => {\n const task = ref.put(data, metadata);\n return createUploadTask(task);\n },\n putString: (data: string, format?: StringFormat, metadata?: UploadMetadata) => {\n const task = ref.putString(data, format, metadata);\n return createUploadTask(task);\n },\n list: (options?: ListOptions) => from(ref.list(options)),\n listAll: () => from(ref.listAll())\n };\n}\n","import { Inject, Injectable, InjectionToken, NgZone, Optional, PLATFORM_ID } from '@angular/core';\nimport { createStorageRef } from './ref';\nimport { ɵAngularFireSchedulers } from '@angular/fire';\nimport { FirebaseOptions } from 'firebase/app';\nimport { ɵfirebaseAppFactory, FIREBASE_APP_NAME, FIREBASE_OPTIONS, ɵcacheInstance } from '@angular/fire/compat';\nimport { UploadMetadata } from './interfaces';\nimport 'firebase/compat/storage';\nimport firebase from 'firebase/compat/app';\nimport { AppCheckInstances } from '@angular/fire/app-check';\n\nexport const BUCKET = new InjectionToken('angularfire2.storageBucket');\nexport const MAX_UPLOAD_RETRY_TIME = new InjectionToken('angularfire2.storage.maxUploadRetryTime');\nexport const MAX_OPERATION_RETRY_TIME = new InjectionToken('angularfire2.storage.maxOperationRetryTime');\n\ntype UseEmulatorArguments = Parameters;\nexport const USE_EMULATOR = new InjectionToken('angularfire2.storage.use-emulator');\n\n/**\n * AngularFireStorage Service\n *\n * This service is the main entry point for this feature module. It provides\n * an API for uploading and downloading binary files from Cloud Storage for\n * Firebase.\n */\n@Injectable({\n providedIn: 'any'\n})\nexport class AngularFireStorage {\n public readonly storage: firebase.storage.Storage;\n\n constructor(\n @Inject(FIREBASE_OPTIONS) options: FirebaseOptions,\n @Optional() @Inject(FIREBASE_APP_NAME) name: string | null | undefined,\n @Optional() @Inject(BUCKET) storageBucket: string | null,\n // tslint:disable-next-line:ban-types\n @Inject(PLATFORM_ID) platformId: Object,\n zone: NgZone,\n schedulers: ɵAngularFireSchedulers,\n @Optional() @Inject(MAX_UPLOAD_RETRY_TIME) maxUploadRetryTime: number | any,\n @Optional() @Inject(MAX_OPERATION_RETRY_TIME) maxOperationRetryTime: number | any,\n @Optional() @Inject(USE_EMULATOR) _useEmulator: any,\n @Optional() _appCheckInstances: AppCheckInstances,\n ) {\n const app = ɵfirebaseAppFactory(options, zone, name);\n this.storage = ɵcacheInstance(`${app.name}.storage.${storageBucket}`, 'AngularFireStorage', app.name, () => {\n const storage = zone.runOutsideAngular(() => app.storage(storageBucket || undefined));\n const useEmulator = _useEmulator as UseEmulatorArguments|null;\n if (useEmulator) {\n storage.useEmulator(...useEmulator);\n }\n if (maxUploadRetryTime) {\n storage.setMaxUploadRetryTime(maxUploadRetryTime);\n }\n if (maxOperationRetryTime) {\n storage.setMaxOperationRetryTime(maxOperationRetryTime);\n }\n return storage;\n }, [maxUploadRetryTime, maxOperationRetryTime]);\n }\n\n ref(path: string) {\n return createStorageRef(this.storage.ref(path));\n }\n\n refFromURL(path: string) {\n return createStorageRef(this.storage.refFromURL(path));\n }\n\n upload(path: string, data: any, metadata?: UploadMetadata) {\n const storageRef = this.storage.ref(path);\n const ref = createStorageRef(storageRef);\n return ref.put(data, metadata);\n }\n\n}\n","import { AsyncPipe } from '@angular/common';\nimport { ChangeDetectorRef, NgModule, OnDestroy, Optional, Pipe, PipeTransform } from '@angular/core';\nimport { makeStateKey, TransferState } from '@angular/platform-browser';\nimport { Observable, of } from 'rxjs';\nimport { tap } from 'rxjs/operators';\nimport { AngularFireStorage } from '../storage';\n\n/** to be used with in combination with | async */\n@Pipe({\n name: 'getDownloadURL',\n pure: false,\n})\nexport class GetDownloadURLPipe implements PipeTransform, OnDestroy {\n\n private asyncPipe: AsyncPipe;\n private path: string;\n private downloadUrl$: Observable;\n\n constructor(\n private storage: AngularFireStorage,\n cdr: ChangeDetectorRef,\n @Optional() private state: TransferState\n ) {\n this.asyncPipe = new AsyncPipe(cdr);\n }\n\n transform(path: string) {\n if (path !== this.path) {\n this.path = path;\n const key = makeStateKey(`|getDownloadURL|${path}`);\n const existing = this.state?.get(key, undefined);\n this.downloadUrl$ = existing ? of(existing) : this.storage.ref(path).getDownloadURL().pipe(\n tap(it => this.state?.set(key, it))\n );\n }\n return this.asyncPipe.transform(this.downloadUrl$);\n }\n\n ngOnDestroy() {\n this.asyncPipe.ngOnDestroy();\n }\n\n}\n\n@NgModule({\n declarations: [ GetDownloadURLPipe ],\n exports: [ GetDownloadURLPipe ],\n})\nexport class GetDownloadURLPipeModule {}\n","import { NgModule } from '@angular/core';\nimport { GetDownloadURLPipeModule } from './pipes/storageUrl.pipe';\nimport { AngularFireStorage } from './storage';\nimport firebase from 'firebase/compat/app';\nimport { VERSION } from '@angular/fire';\n\n@NgModule({\n exports: [ GetDownloadURLPipeModule ],\n providers: [ AngularFireStorage ]\n})\nexport class AngularFireStorageModule {\n constructor() {\n firebase.registerVersion('angularfire', VERSION.full, 'gcs-compat');\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;;;;;;;;AAQA;AACA;SACgB,QAAQ,CAAC,IAAgB;IACvC,OAAO,IAAI,UAAU,CAAqB,UAAU;QAClD,MAAM,QAAQ,GAAG,CAAC,IAAwB,KAAK,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrE,MAAM,KAAK,GAAG,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACvC,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC;;;QAG7C,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxB,MAAM,KAAK,GAAG,IAAI,CAAC,EAAE,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;;;;QAIjD,IAAI,CAAC,IAAI,CAAC,QAAQ;YAChB,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACnB,QAAQ,EAAE,CAAC;SACZ,EAAE,CAAC;;YAEF,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACxB,KAAK,CAAC,CAAC,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