@@ -52,9 +52,9 @@ function _getValueProto(data: any, resource: string, valueFieldName: string) {
52
52
}
53
53
54
54
/** @internal */
55
- export function createSnapshotFromProtobuf ( data : Uint8Array , path : string ) {
55
+ export function createSnapshotFromProtobuf ( data : Uint8Array , path : string , databaseId : string ) {
56
56
if ( ! firestoreInstance ) {
57
- firestoreInstance = firestore . getFirestore ( getApp ( ) ) ;
57
+ firestoreInstance = firestore . getFirestore ( databaseId ) ;
58
58
}
59
59
try {
60
60
const dataBuffer = Buffer . from ( data ) ;
@@ -68,9 +68,13 @@ export function createSnapshotFromProtobuf(data: Uint8Array, path: string) {
68
68
}
69
69
70
70
/** @internal */
71
- export function createBeforeSnapshotFromProtobuf ( data : Uint8Array , path : string ) {
71
+ export function createBeforeSnapshotFromProtobuf (
72
+ data : Uint8Array ,
73
+ path : string ,
74
+ databaseId : string
75
+ ) {
72
76
if ( ! firestoreInstance ) {
73
- firestoreInstance = firestore . getFirestore ( getApp ( ) ) ;
77
+ firestoreInstance = firestore . getFirestore ( databaseId ) ;
74
78
}
75
79
try {
76
80
const dataBuffer = Buffer . from ( data ) ;
@@ -88,10 +92,13 @@ export function createSnapshotFromJson(
88
92
data : any ,
89
93
source : string ,
90
94
createTime : string | undefined ,
91
- updateTime : string | undefined
95
+ updateTime : string | undefined ,
96
+ databaseId ?: string
92
97
) {
93
98
if ( ! firestoreInstance ) {
94
- firestoreInstance = firestore . getFirestore ( getApp ( ) ) ;
99
+ firestoreInstance = databaseId
100
+ ? firestore . getFirestore ( databaseId )
101
+ : firestore . getFirestore ( getApp ( ) ) ;
95
102
}
96
103
const valueProto = _getValueProto ( data , source , "value" ) ;
97
104
let timeString = createTime || updateTime ;
@@ -110,11 +117,15 @@ export function createBeforeSnapshotFromJson(
110
117
data : any ,
111
118
source : string ,
112
119
createTime : string | undefined ,
113
- updateTime : string | undefined
120
+ updateTime : string | undefined ,
121
+ databaseId ?: string
114
122
) {
115
123
if ( ! firestoreInstance ) {
116
- firestoreInstance = firestore . getFirestore ( getApp ( ) ) ;
124
+ firestoreInstance = databaseId
125
+ ? firestore . getFirestore ( databaseId )
126
+ : firestore . getFirestore ( getApp ( ) ) ;
117
127
}
128
+
118
129
const oldValueProto = _getValueProto ( data , source , "oldValue" ) ;
119
130
const oldReadTime = dateToTimestampProto ( createTime || updateTime ) ;
120
131
return firestoreInstance . snapshot_ ( oldValueProto , oldReadTime , "json" ) ;
0 commit comments