@@ -1673,6 +1673,10 @@ const ensureFirestore = (): void => {
16731673 if ( typeof ( FIRFirestore ) === "undefined" ) {
16741674 throw new Error ( "Make sure 'firestore' is enabled in 'firebase.nativescript.json', then clean the node_modules and platforms folders" ) ;
16751675 }
1676+
1677+ if ( ! firebase . initialized ) {
1678+ throw new Error ( "Please run firebase.init() before using Firestore" ) ;
1679+ }
16761680} ;
16771681
16781682firebase . firestore . WriteBatch = ( nativeWriteBatch : FIRWriteBatch ) : firestore . WriteBatch => {
@@ -1785,18 +1789,23 @@ firebase.firestore.clearPersistence = (): Promise<void> => {
17851789firebase . firestore . collection = ( collectionPath : string ) : firestore . CollectionReference => {
17861790 ensureFirestore ( ) ;
17871791 try {
1788- if ( ! firebase . initialized ) {
1789- console . log ( "Please run firebase.init() before firebase.firestore.collection()" ) ;
1790- return null ;
1791- }
1792-
17931792 return firebase . firestore . _getCollectionReference ( FIRFirestore . firestore ( ) . collectionWithPath ( collectionPath ) ) ;
17941793 } catch ( ex ) {
17951794 console . log ( "Error in firebase.firestore.collection: " + ex ) ;
17961795 return null ;
17971796 }
17981797} ;
17991798
1799+ firebase . firestore . collectionGroup = ( id : string ) : firestore . CollectionGroup => {
1800+ ensureFirestore ( ) ;
1801+ try {
1802+ return firebase . firestore . _getCollectionGroupQuery ( FIRFirestore . firestore ( ) . collectionGroupWithID ( id ) ) ;
1803+ } catch ( ex ) {
1804+ console . log ( "Error in firebase.firestore.collectionGroup: " + ex ) ;
1805+ return null ;
1806+ }
1807+ } ;
1808+
18001809firebase . firestore . onDocumentSnapshot = ( docRef : FIRDocumentReference , optionsOrCallback : firestore . SnapshotListenOptions | ( ( snapshot : DocumentSnapshot ) => void ) , callbackOrOnError : ( docOrError : DocumentSnapshot | Error ) => void , onError : ( error : Error ) => void ) : ( ) => void => {
18011810 let includeMetadataChanges = false ;
18021811 let onNextCallback : ( snapshot : DocumentSnapshot ) => void ;
@@ -1897,6 +1906,16 @@ firebase.firestore._getCollectionReference = (colRef?: FIRCollectionReference):
18971906 } ;
18981907} ;
18991908
1909+ firebase . firestore . _getCollectionGroupQuery = ( query ?: FIRQuery ) : firestore . CollectionGroup => {
1910+ if ( ! query ) {
1911+ return null ;
1912+ }
1913+
1914+ return {
1915+ where : ( property : string , opStr : firestore . WhereFilterOp , value : any ) => firebase . firestore . where ( undefined , property , opStr , value , query )
1916+ } ;
1917+ } ;
1918+
19001919firebase . firestore . _getDocumentReference = ( docRef ?: FIRDocumentReference ) : firestore . DocumentReference => {
19011920 if ( ! docRef ) {
19021921 return null ;
@@ -1922,11 +1941,6 @@ firebase.firestore._getDocumentReference = (docRef?: FIRDocumentReference): fire
19221941firebase . firestore . doc = ( collectionPath : string , documentPath ?: string ) : firestore . DocumentReference => {
19231942 ensureFirestore ( ) ;
19241943 try {
1925- if ( ! firebase . initialized ) {
1926- console . log ( "Please run firebase.init() before firebase.firestore.doc()" ) ;
1927- return null ;
1928- }
1929-
19301944 const fIRCollectionReference = FIRFirestore . firestore ( ) . collectionWithPath ( collectionPath ) ;
19311945 const fIRDocumentReference = documentPath ? fIRCollectionReference . documentWithPath ( documentPath ) : fIRCollectionReference . documentWithAutoID ( ) ;
19321946 return firebase . firestore . _getDocumentReference ( fIRDocumentReference ) ;
0 commit comments