/**
 * GeoFire is an open-source library that allows you to store and query a set
 * of keys based on their geographic location. At its heart, GeoFire simply
 * stores locations with string keys. Its main benefit, however, is the
 * possibility of retrieving only those keys within a given geographic area -
 * all in realtime.
 *
 * GeoFire 0.0.0
 * https://github.com/firebase/geofire-js/
 * License: MIT
 */ import { GeoQuery , QueryCriteria } from './GeoQuery' ; import { geohashForLocation , validateLocation , validateKey , Geopoint } from 'geofire-common' ; import { decodeGeoFireObject , encodeGeoFireObject } from './databaseUtils' ; import * as GeoFireTypes from './GeoFireTypes' ; import * as DatabaseTypes from '@firebase/database-types' ; /**
 * Creates a GeoFire instance.
 */ export class GeoFire { param _firebaseRef constructor ( private _firebaseRef ) { if ( Object . prototype . toString . call ( this . _firebaseRef ) !== '[object Object]' ) { throw new Error ( 'firebaseRef must be an instance of Firebase' ) ; } } /********************/ /********************/ param key returns public get ( key ) { validateKey ( key ) ; return this . _firebaseRef . child ( key ) . once ( 'value' ) . then ( ( dataSnapshot ) => { const snapshotVal = dataSnapshot . val ( ) ; if ( snapshotVal === null ) { return null ; } else { return decodeGeoFireObject ( snapshotVal ) ; } } ) ; } returns public ref ( ) { return this . _firebaseRef ; } param key returns public remove ( key ) { return this . set ( key , null ) ; } param keyOrLocations param location returns public set ( keyOrLocations , location ? ) { let locations ; if ( typeof keyOrLocations === 'string' && keyOrLocations . length !== 0 ) { locations = { } ; locations [ keyOrLocations ] = location ; } else if ( typeof keyOrLocations === 'object' ) { if ( typeof location !== 'undefined' ) { throw new Error ( 'The location argument should not be used if you pass an object to set().' ) ; } locations = keyOrLocations ; } else { throw new Error ( 'keyOrLocations must be a string or a mapping of key - location pairs.' ) ; } const newData = { } ; Object . keys ( locations ) . forEach ( ( key ) => { validateKey ( key ) ; const location = locations [ key ] ; if ( location === null ) { newData [ key ] = null ; } else { validateLocation ( location ) ; const geohash = geohashForLocation ( location ) ; newData [ key ] = encodeGeoFireObject ( location , geohash ) ; } } ) ; return this . _firebaseRef . update ( newData ) ; } param queryCriteria return public query ( queryCriteria ) { return new GeoQuery ( this . _firebaseRef , queryCriteria ) ; } }