import { Inject , Injectable , InjectionToken , NgZone , Optional , PLATFORM_ID } from '@angular/core' ; import { AngularFireList , AngularFireObject , DatabaseQuery , PathReference , QueryFn } from './interfaces' ; import { getRef } from './utils' ; import { createListReference } from './list/create-reference' ; import { createObjectReference } from './object/create-reference' ; import { ɵAngularFireSchedulers } from '@angular/fire' ; import { FirebaseOptions } from 'firebase/app' ; import { ɵfirebaseAppFactory , FIREBASE_APP_NAME , FIREBASE_OPTIONS , ɵcacheInstance } from '@angular/fire/compat' ; import 'firebase/compat/auth' ; import 'firebase/compat/database' ; import { AngularFireAuth , USE_EMULATOR as USE_AUTH_EMULATOR , SETTINGS as AUTH_SETTINGS , TENANT_ID , LANGUAGE_CODE , USE_DEVICE_LANGUAGE , PERSISTENCE , ɵauthFactory , } from '@angular/fire/compat/auth' ; import firebase from 'firebase/compat/app' ; import { AppCheckInstances } from '@angular/fire/app-check' ; export const URL = new InjectionToken < string > ( 'angularfire2.realtimeDatabaseURL' ) ; type UseEmulatorArguments = Parameters < firebase . database . Database [ 'useEmulator' ] > ; export const USE_EMULATOR = new InjectionToken < UseEmulatorArguments > ( 'angularfire2.database.use-emulator' ) ; @ Injectable ( { providedIn : 'any' } ) export class AngularFireDatabase { public readonly database : firebase . database . Database ; constructor ( @ Inject ( FIREBASE_OPTIONS ) options , @ Optional ( ) @ Inject ( FIREBASE_APP_NAME ) name , @ Optional ( ) @ Inject ( URL ) databaseURL , @ Inject ( PLATFORM_ID ) platformId , zone , public schedulers , @ Optional ( ) @ Inject ( USE_EMULATOR ) _useEmulator , @ Optional ( ) auth , @ Optional ( ) @ Inject ( USE_AUTH_EMULATOR ) useAuthEmulator , @ Optional ( ) @ Inject ( AUTH_SETTINGS ) authSettings , @ Optional ( ) @ Inject ( TENANT_ID ) tenantId , @ Optional ( ) @ Inject ( LANGUAGE_CODE ) languageCode , @ Optional ( ) @ Inject ( USE_DEVICE_LANGUAGE ) useDeviceLanguage , @ Optional ( ) @ Inject ( PERSISTENCE ) persistence , @ Optional ( ) _appCheckInstances ) { const useEmulator = _useEmulator ; const app = ɵfirebaseAppFactory ( options , zone , name ) ; if ( auth ) { ɵauthFactory ( app , zone , useAuthEmulator , tenantId , languageCode , useDeviceLanguage , authSettings , persistence ) ; } this . database = ɵcacheInstance ( `${ app . name }.database.${ databaseURL }` , 'AngularFireDatabase' , app . name , ( ) => { const database = zone . runOutsideAngular ( ( ) => app . database ( databaseURL || undefined ) ) ; if ( useEmulator ) { database . useEmulator ( ... useEmulator ) ; } return database ; } , [ useEmulator ] ) ; } list < T > ( pathOrRef , queryFn ? ) { const ref = this . schedulers . ngZone . runOutsideAngular ( ( ) => getRef ( this . database , pathOrRef ) ) ; let query = ref ; if ( queryFn ) { query = queryFn ( ref ) ; } return createListReference < T > ( query , this ) ; } object < T > ( pathOrRef ) { const ref = this . schedulers . ngZone . runOutsideAngular ( ( ) => getRef ( this . database , pathOrRef ) ) ; return createObjectReference < T > ( ref , this ) ; } createPushId ( ) { const ref = this . schedulers . ngZone . runOutsideAngular ( ( ) => this . database . ref ( ) ) ; return ref . push ( ) . key ; } } export { PathReference , DatabaseSnapshot , ChildEvent , ListenEvent , QueryFn , AngularFireList , AngularFireObject , AngularFireAction , Action , SnapshotAction } from './interfaces' ;