@@ -55,7 +55,20 @@ import {
55
55
OfflineComponentProvider ,
56
56
OnlineComponentProvider
57
57
} from '../core/component_provider' ;
58
- import { FirestoreClient } from '../core/firestore_client' ;
58
+ import {
59
+ FirestoreClient ,
60
+ firestoreClientAddSnapshotsInSyncListener ,
61
+ firestoreClientDisableNetwork ,
62
+ firestoreClientEnableNetwork ,
63
+ firestoreClientGetDocumentFromLocalCache ,
64
+ firestoreClientGetDocumentsFromLocalCache ,
65
+ firestoreClientGetDocumentsViaSnapshotListener ,
66
+ firestoreClientGetDocumentViaSnapshotListener ,
67
+ firestoreClientListen ,
68
+ firestoreClientTransaction ,
69
+ firestoreClientWaitForPendingWrites ,
70
+ firestoreClientWrite
71
+ } from '../core/firestore_client' ;
59
72
import {
60
73
Bound ,
61
74
Direction ,
@@ -101,7 +114,7 @@ import {
101
114
validateSetOptions ,
102
115
valueDescription
103
116
} from '../util/input_validation' ;
104
- import { setLogLevel as setClientLogLevel , logWarn } from '../util/log' ;
117
+ import { logWarn , setLogLevel as setClientLogLevel } from '../util/log' ;
105
118
import { AutoId } from '../util/misc' ;
106
119
import { Deferred } from '../util/promise' ;
107
120
import { FieldPath as ExternalFieldPath } from './field_path' ;
@@ -461,12 +474,12 @@ export class Firestore implements PublicFirestore, FirebaseService {
461
474
462
475
enableNetwork ( ) : Promise < void > {
463
476
this . ensureClientConfigured ( ) ;
464
- return this . _firestoreClient ! . enableNetwork ( ) ;
477
+ return firestoreClientEnableNetwork ( this . _firestoreClient ! ) ;
465
478
}
466
479
467
480
disableNetwork ( ) : Promise < void > {
468
481
this . ensureClientConfigured ( ) ;
469
- return this . _firestoreClient ! . disableNetwork ( ) ;
482
+ return firestoreClientDisableNetwork ( this . _firestoreClient ! ) ;
470
483
}
471
484
472
485
enablePersistence ( settings ?: PublicPersistenceSettings ) : Promise < void > {
@@ -528,7 +541,7 @@ export class Firestore implements PublicFirestore, FirebaseService {
528
541
529
542
waitForPendingWrites ( ) : Promise < void > {
530
543
this . ensureClientConfigured ( ) ;
531
- return this . _firestoreClient ! . waitForPendingWrites ( ) ;
544
+ return firestoreClientWaitForPendingWrites ( this . _firestoreClient ! ) ;
532
545
}
533
546
534
547
onSnapshotsInSync ( observer : PartialObserver < void > ) : Unsubscribe ;
@@ -537,14 +550,18 @@ export class Firestore implements PublicFirestore, FirebaseService {
537
550
this . ensureClientConfigured ( ) ;
538
551
539
552
if ( isPartialObserver ( arg ) ) {
540
- return this . _firestoreClient ! . addSnapshotsInSyncListener (
553
+ return firestoreClientAddSnapshotsInSyncListener (
554
+ this . _firestoreClient ! ,
541
555
arg as PartialObserver < void >
542
556
) ;
543
557
} else {
544
558
const observer : PartialObserver < void > = {
545
559
next : arg as ( ) => void
546
560
} ;
547
- return this . _firestoreClient ! . addSnapshotsInSyncListener ( observer ) ;
561
+ return firestoreClientAddSnapshotsInSyncListener (
562
+ this . _firestoreClient ! ,
563
+ observer
564
+ ) ;
548
565
}
549
566
}
550
567
@@ -676,7 +693,9 @@ export class Firestore implements PublicFirestore, FirebaseService {
676
693
runTransaction < T > (
677
694
updateFunction : ( transaction : PublicTransaction ) => Promise < T >
678
695
) : Promise < T > {
679
- return this . ensureClientConfigured ( ) . transaction (
696
+ const firestoreClient = this . ensureClientConfigured ( ) ;
697
+ return firestoreClientTransaction (
698
+ firestoreClient ,
680
699
( transaction : InternalTransaction ) => {
681
700
return updateFunction ( new Transaction ( this , transaction ) ) ;
682
701
}
@@ -685,7 +704,6 @@ export class Firestore implements PublicFirestore, FirebaseService {
685
704
686
705
batch ( ) : PublicWriteBatch {
687
706
this . ensureClientConfigured ( ) ;
688
-
689
707
return new WriteBatch ( this ) ;
690
708
}
691
709
@@ -966,7 +984,8 @@ export class WriteBatch implements PublicWriteBatch {
966
984
this . verifyNotCommitted ( ) ;
967
985
this . _committed = true ;
968
986
if ( this . _mutations . length > 0 ) {
969
- return this . _firestore . ensureClientConfigured ( ) . write ( this . _mutations ) ;
987
+ const firestoreClient = this . _firestore . ensureClientConfigured ( ) ;
988
+ return firestoreClientWrite ( firestoreClient , this . _mutations ) ;
970
989
}
971
990
972
991
return Promise . resolve ( ) ;
@@ -1080,7 +1099,8 @@ export class DocumentReference<T = DocumentData>
1080
1099
this . _converter !== null ,
1081
1100
options
1082
1101
) ;
1083
- return this . _firestoreClient . write (
1102
+ return firestoreClientWrite (
1103
+ this . _firestoreClient ,
1084
1104
parsed . toMutations ( this . _key , Precondition . none ( ) )
1085
1105
) ;
1086
1106
}
@@ -1119,13 +1139,14 @@ export class DocumentReference<T = DocumentData>
1119
1139
) ;
1120
1140
}
1121
1141
1122
- return this . _firestoreClient . write (
1142
+ return firestoreClientWrite (
1143
+ this . _firestoreClient ,
1123
1144
parsed . toMutations ( this . _key , Precondition . exists ( true ) )
1124
1145
) ;
1125
1146
}
1126
1147
1127
1148
delete ( ) : Promise < void > {
1128
- return this . _firestoreClient . write ( [
1149
+ return firestoreClientWrite ( this . _firestoreClient , [
1129
1150
new DeleteMutation ( this . _key , Precondition . none ( ) )
1130
1151
] ) ;
1131
1152
}
@@ -1185,7 +1206,8 @@ export class DocumentReference<T = DocumentData>
1185
1206
complete : args [ currArg + 2 ] as CompleteFn
1186
1207
} ;
1187
1208
1188
- return this . _firestoreClient . listen (
1209
+ return firestoreClientListen (
1210
+ this . _firestoreClient ,
1189
1211
newQueryForPath ( this . _key . path ) ,
1190
1212
internalOptions ,
1191
1213
observer
@@ -1195,23 +1217,26 @@ export class DocumentReference<T = DocumentData>
1195
1217
get ( options ?: GetOptions ) : Promise < PublicDocumentSnapshot < T > > {
1196
1218
const firestoreClient = this . firestore . ensureClientConfigured ( ) ;
1197
1219
if ( options && options . source === 'cache' ) {
1198
- return firestoreClient
1199
- . getDocumentFromLocalCache ( this . _key )
1200
- . then (
1201
- doc =>
1202
- new DocumentSnapshot (
1203
- this . firestore ,
1204
- this . _key ,
1205
- doc ,
1206
- /*fromCache=*/ true ,
1207
- doc instanceof Document ? doc . hasLocalMutations : false ,
1208
- this . _converter
1209
- )
1210
- ) ;
1220
+ return firestoreClientGetDocumentFromLocalCache (
1221
+ firestoreClient ,
1222
+ this . _key
1223
+ ) . then (
1224
+ doc =>
1225
+ new DocumentSnapshot (
1226
+ this . firestore ,
1227
+ this . _key ,
1228
+ doc ,
1229
+ /*fromCache=*/ true ,
1230
+ doc instanceof Document ? doc . hasLocalMutations : false ,
1231
+ this . _converter
1232
+ )
1233
+ ) ;
1211
1234
} else {
1212
- return firestoreClient
1213
- . getDocumentViaSnapshotListener ( this . _key , options )
1214
- . then ( snapshot => this . _convertToDocSnapshot ( snapshot ) ) ;
1235
+ return firestoreClientGetDocumentViaSnapshotListener (
1236
+ firestoreClient ,
1237
+ this . _key ,
1238
+ options
1239
+ ) . then ( snapshot => this . _convertToDocSnapshot ( snapshot ) ) ;
1215
1240
}
1216
1241
}
1217
1242
@@ -2036,7 +2061,12 @@ export class Query<T = DocumentData> implements PublicQuery<T> {
2036
2061
2037
2062
validateHasExplicitOrderByForLimitToLast ( this . _query ) ;
2038
2063
const firestoreClient = this . firestore . ensureClientConfigured ( ) ;
2039
- return firestoreClient . listen ( this . _query , options , observer ) ;
2064
+ return firestoreClientListen (
2065
+ firestoreClient ,
2066
+ this . _query ,
2067
+ options ,
2068
+ observer
2069
+ ) ;
2040
2070
}
2041
2071
2042
2072
get ( options ?: GetOptions ) : Promise < PublicQuerySnapshot < T > > {
@@ -2045,8 +2075,12 @@ export class Query<T = DocumentData> implements PublicQuery<T> {
2045
2075
2046
2076
const firestoreClient = this . firestore . ensureClientConfigured ( ) ;
2047
2077
return ( options && options . source === 'cache'
2048
- ? firestoreClient . getDocumentsFromLocalCache ( this . _query )
2049
- : firestoreClient . getDocumentsViaSnapshotListener ( this . _query , options )
2078
+ ? firestoreClientGetDocumentsFromLocalCache ( firestoreClient , this . _query )
2079
+ : firestoreClientGetDocumentsViaSnapshotListener (
2080
+ firestoreClient ,
2081
+ this . _query ,
2082
+ options
2083
+ )
2050
2084
) . then (
2051
2085
snap =>
2052
2086
new QuerySnapshot ( this . firestore , this . _query , snap , this . _converter )
0 commit comments