@@ -30,14 +30,55 @@ import {
30
30
} from '../../../src/api/database' ;
31
31
import { ViewSnapshot } from '../../../src/core/view_snapshot' ;
32
32
import { DocumentReference } from '../../../lite/src/api/reference' ;
33
+ import { Document } from '../../../src/model/document' ;
33
34
34
35
export function getDoc < T > (
35
36
reference : firestore . DocumentReference < T >
36
37
) : Promise < firestore . DocumentSnapshot < T > > {
37
38
const ref = cast < DocumentReference < T > > ( reference , DocumentReference ) ;
38
39
const firestore = cast < Firestore > ( ref . firestore , Firestore ) ;
39
40
return firestore . _getFirestoreClient ( ) . then ( async firestoreClient => {
40
- const viewSnapshot = await getDocViaSnapshotListener ( firestoreClient , ref ) ;
41
+ const viewSnapshot = await getDocViaSnapshotListener (
42
+ firestoreClient ,
43
+ ref . _key
44
+ ) ;
45
+ return convertToDocSnapshot ( firestore , ref , viewSnapshot ) ;
46
+ } ) ;
47
+ }
48
+
49
+ // TODO(firestorexp): Make sure we don't include Datastore/RemoteStore in builds
50
+ // that only include `getDocFromCache`.
51
+ export function getDocFromCache < T > (
52
+ reference : firestore . DocumentReference < T >
53
+ ) : Promise < firestore . DocumentSnapshot < T > > {
54
+ const ref = cast < DocumentReference < T > > ( reference , DocumentReference ) ;
55
+ const firestore = cast < Firestore > ( ref . firestore , Firestore ) ;
56
+ return firestore . _getFirestoreClient ( ) . then ( async firestoreClient => {
57
+ const doc = await firestoreClient . getDocumentFromLocalCache ( ref . _key ) ;
58
+ return new DocumentSnapshot (
59
+ firestore ,
60
+ ref . _key ,
61
+ doc ,
62
+ ref . _converter ,
63
+ new SnapshotMetadata (
64
+ doc instanceof Document ? doc . hasLocalMutations : false ,
65
+ /* fromCache= */ true
66
+ )
67
+ ) ;
68
+ } ) ;
69
+ }
70
+
71
+ export function getDocFromServer < T > (
72
+ reference : firestore . DocumentReference < T >
73
+ ) : Promise < firestore . DocumentSnapshot < T > > {
74
+ const ref = cast < DocumentReference < T > > ( reference , DocumentReference ) ;
75
+ const firestore = cast < Firestore > ( ref . firestore , Firestore ) ;
76
+ return firestore . _getFirestoreClient ( ) . then ( async firestoreClient => {
77
+ const viewSnapshot = await getDocViaSnapshotListener (
78
+ firestoreClient ,
79
+ ref . _key ,
80
+ { source : 'server' }
81
+ ) ;
41
82
return convertToDocSnapshot ( firestore , ref , viewSnapshot ) ;
42
83
} ) ;
43
84
}
0 commit comments