@react-native-firebase/firestore 20.3.0 → 20.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/__tests__/firestore.test.ts +292 -1
- package/android/src/main/java/io/invertase/firebase/firestore/UniversalFirebaseFirestoreCommon.java +17 -9
- package/android/src/main/java/io/invertase/firebase/firestore/UniversalFirebaseFirestoreModule.java +28 -26
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreCollectionModule.java +53 -22
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreCommon.java +5 -2
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreDocumentModule.java +35 -21
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreEvent.java +5 -1
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreModule.java +48 -16
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreQuery.java +3 -1
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreSerialize.java +13 -8
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreTransactionModule.java +12 -7
- package/ios/RNFBFirestore/RNFBFirestoreCollectionModule.m +78 -49
- package/ios/RNFBFirestore/RNFBFirestoreCommon.h +6 -2
- package/ios/RNFBFirestore/RNFBFirestoreCommon.m +23 -10
- package/ios/RNFBFirestore/RNFBFirestoreDocumentModule.m +41 -11
- package/ios/RNFBFirestore/RNFBFirestoreModule.m +66 -15
- package/ios/RNFBFirestore/RNFBFirestoreSerialize.h +5 -3
- package/ios/RNFBFirestore/RNFBFirestoreSerialize.m +17 -10
- package/ios/RNFBFirestore/RNFBFirestoreTransactionModule.m +21 -7
- package/lib/FirestorePersistentCacheIndexManager.js +34 -0
- package/lib/index.d.ts +32 -1
- package/lib/index.js +25 -2
- package/lib/modular/index.d.ts +52 -0
- package/lib/modular/index.js +55 -3
- package/lib/version.js +1 -1
- package/lib/web/RNFBFirestoreModule.js +61 -34
- package/package.json +3 -3
|
@@ -62,7 +62,7 @@ public class ReactNativeFirebaseFirestoreTransactionModule extends ReactNativeFi
|
|
|
62
62
|
|
|
63
63
|
@ReactMethod
|
|
64
64
|
public void transactionGetDocument(
|
|
65
|
-
String appName, int transactionId, String path, Promise promise) {
|
|
65
|
+
String appName, String databaseId, int transactionId, String path, Promise promise) {
|
|
66
66
|
ReactNativeFirebaseFirestoreTransactionHandler transactionHandler =
|
|
67
67
|
transactionHandlers.get(transactionId);
|
|
68
68
|
|
|
@@ -74,12 +74,14 @@ public class ReactNativeFirebaseFirestoreTransactionModule extends ReactNativeFi
|
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
FirebaseFirestore firebaseFirestore = getFirestoreForApp(appName);
|
|
77
|
+
FirebaseFirestore firebaseFirestore = getFirestoreForApp(appName, databaseId);
|
|
78
78
|
DocumentReference documentReference = getDocumentForFirestore(firebaseFirestore, path);
|
|
79
79
|
|
|
80
80
|
Tasks.call(
|
|
81
81
|
getTransactionalExecutor(),
|
|
82
|
-
() ->
|
|
82
|
+
() ->
|
|
83
|
+
snapshotToWritableMap(
|
|
84
|
+
appName, databaseId, transactionHandler.getDocument(documentReference)))
|
|
83
85
|
.addOnCompleteListener(
|
|
84
86
|
task -> {
|
|
85
87
|
if (task.isSuccessful()) {
|
|
@@ -91,7 +93,7 @@ public class ReactNativeFirebaseFirestoreTransactionModule extends ReactNativeFi
|
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
@ReactMethod
|
|
94
|
-
public void transactionDispose(String appName, int transactionId) {
|
|
96
|
+
public void transactionDispose(String appName, String databaseId, int transactionId) {
|
|
95
97
|
ReactNativeFirebaseFirestoreTransactionHandler transactionHandler =
|
|
96
98
|
transactionHandlers.get(transactionId);
|
|
97
99
|
|
|
@@ -103,7 +105,7 @@ public class ReactNativeFirebaseFirestoreTransactionModule extends ReactNativeFi
|
|
|
103
105
|
|
|
104
106
|
@ReactMethod
|
|
105
107
|
public void transactionApplyBuffer(
|
|
106
|
-
String appName, int transactionId, ReadableArray commandBuffer) {
|
|
108
|
+
String appName, String databaseId, int transactionId, ReadableArray commandBuffer) {
|
|
107
109
|
ReactNativeFirebaseFirestoreTransactionHandler handler = transactionHandlers.get(transactionId);
|
|
108
110
|
|
|
109
111
|
if (handler != null) {
|
|
@@ -112,12 +114,12 @@ public class ReactNativeFirebaseFirestoreTransactionModule extends ReactNativeFi
|
|
|
112
114
|
}
|
|
113
115
|
|
|
114
116
|
@ReactMethod
|
|
115
|
-
public void transactionBegin(String appName, int transactionId) {
|
|
117
|
+
public void transactionBegin(String appName, String databaseId, int transactionId) {
|
|
116
118
|
ReactNativeFirebaseFirestoreTransactionHandler transactionHandler =
|
|
117
119
|
new ReactNativeFirebaseFirestoreTransactionHandler(appName, transactionId);
|
|
118
120
|
transactionHandlers.put(transactionId, transactionHandler);
|
|
119
121
|
|
|
120
|
-
FirebaseFirestore firebaseFirestore = getFirestoreForApp(appName);
|
|
122
|
+
FirebaseFirestore firebaseFirestore = getFirestoreForApp(appName, databaseId);
|
|
121
123
|
ReactNativeFirebaseEventEmitter emitter = ReactNativeFirebaseEventEmitter.getSharedInstance();
|
|
122
124
|
|
|
123
125
|
// Provides its own executor
|
|
@@ -138,6 +140,7 @@ public class ReactNativeFirebaseFirestoreTransactionModule extends ReactNativeFi
|
|
|
138
140
|
ReactNativeFirebaseFirestoreEvent.TRANSACTION_EVENT_SYNC,
|
|
139
141
|
eventMap,
|
|
140
142
|
transactionHandler.getAppName(),
|
|
143
|
+
databaseId,
|
|
141
144
|
transactionHandler.getTransactionId()));
|
|
142
145
|
});
|
|
143
146
|
|
|
@@ -227,6 +230,7 @@ public class ReactNativeFirebaseFirestoreTransactionModule extends ReactNativeFi
|
|
|
227
230
|
ReactNativeFirebaseFirestoreEvent.TRANSACTION_EVENT_SYNC,
|
|
228
231
|
eventMap,
|
|
229
232
|
transactionHandler.getAppName(),
|
|
233
|
+
databaseId,
|
|
230
234
|
transactionHandler.getTransactionId()));
|
|
231
235
|
} else {
|
|
232
236
|
eventMap.putString("type", "error");
|
|
@@ -247,6 +251,7 @@ public class ReactNativeFirebaseFirestoreTransactionModule extends ReactNativeFi
|
|
|
247
251
|
ReactNativeFirebaseFirestoreEvent.TRANSACTION_EVENT_SYNC,
|
|
248
252
|
eventMap,
|
|
249
253
|
transactionHandler.getAppName(),
|
|
254
|
+
databaseId,
|
|
250
255
|
transactionHandler.getTransactionId()));
|
|
251
256
|
}
|
|
252
257
|
});
|
|
@@ -63,6 +63,7 @@ RCT_EXPORT_MODULE();
|
|
|
63
63
|
|
|
64
64
|
RCT_EXPORT_METHOD(namedQueryOnSnapshot
|
|
65
65
|
: (FIRApp *)firebaseApp
|
|
66
|
+
: (NSString *)databaseId
|
|
66
67
|
: (NSString *)name
|
|
67
68
|
: (NSString *)type
|
|
68
69
|
: (NSArray *)filters
|
|
@@ -74,31 +75,35 @@ RCT_EXPORT_METHOD(namedQueryOnSnapshot
|
|
|
74
75
|
return;
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
78
|
+
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
79
|
+
databaseId:databaseId];
|
|
80
|
+
[firestore getQueryNamed:name
|
|
81
|
+
completion:^(FIRQuery *query) {
|
|
82
|
+
if (query == nil) {
|
|
83
|
+
[self sendSnapshotError:firebaseApp
|
|
84
|
+
databaseId:databaseId
|
|
85
|
+
listenerId:listenerId
|
|
86
|
+
error:nil];
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
RNFBFirestoreQuery *firestoreQuery =
|
|
91
|
+
[[RNFBFirestoreQuery alloc] initWithModifiers:firestore
|
|
92
|
+
query:query
|
|
93
|
+
filters:filters
|
|
94
|
+
orders:orders
|
|
95
|
+
options:options];
|
|
96
|
+
[self handleQueryOnSnapshot:firebaseApp
|
|
97
|
+
databaseId:databaseId
|
|
98
|
+
firestoreQuery:firestoreQuery
|
|
99
|
+
listenerId:listenerId
|
|
100
|
+
listenerOptions:listenerOptions];
|
|
101
|
+
}];
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
RCT_EXPORT_METHOD(collectionOnSnapshot
|
|
101
105
|
: (FIRApp *)firebaseApp
|
|
106
|
+
: (NSString *)databaseId
|
|
102
107
|
: (NSString *)path
|
|
103
108
|
: (NSString *)type
|
|
104
109
|
: (NSArray *)filters
|
|
@@ -110,7 +115,8 @@ RCT_EXPORT_METHOD(collectionOnSnapshot
|
|
|
110
115
|
return;
|
|
111
116
|
}
|
|
112
117
|
|
|
113
|
-
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
118
|
+
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
119
|
+
databaseId:databaseId];
|
|
114
120
|
FIRQuery *query = [RNFBFirestoreCommon getQueryForFirestore:firestore path:path type:type];
|
|
115
121
|
|
|
116
122
|
RNFBFirestoreQuery *firestoreQuery = [[RNFBFirestoreQuery alloc] initWithModifiers:firestore
|
|
@@ -119,12 +125,16 @@ RCT_EXPORT_METHOD(collectionOnSnapshot
|
|
|
119
125
|
orders:orders
|
|
120
126
|
options:options];
|
|
121
127
|
[self handleQueryOnSnapshot:firebaseApp
|
|
128
|
+
databaseId:databaseId
|
|
122
129
|
firestoreQuery:firestoreQuery
|
|
123
130
|
listenerId:listenerId
|
|
124
131
|
listenerOptions:listenerOptions];
|
|
125
132
|
}
|
|
126
133
|
|
|
127
|
-
RCT_EXPORT_METHOD(collectionOffSnapshot
|
|
134
|
+
RCT_EXPORT_METHOD(collectionOffSnapshot
|
|
135
|
+
: (FIRApp *)firebaseApp
|
|
136
|
+
: (NSString *)databaseId
|
|
137
|
+
: (nonnull NSNumber *)listenerId) {
|
|
128
138
|
id<FIRListenerRegistration> listener = collectionSnapshotListeners[listenerId];
|
|
129
139
|
if (listener) {
|
|
130
140
|
[listener remove];
|
|
@@ -134,6 +144,7 @@ RCT_EXPORT_METHOD(collectionOffSnapshot : (FIRApp *)firebaseApp : (nonnull NSNum
|
|
|
134
144
|
|
|
135
145
|
RCT_EXPORT_METHOD(namedQueryGet
|
|
136
146
|
: (FIRApp *)firebaseApp
|
|
147
|
+
: (NSString *)databaseId
|
|
137
148
|
: (NSString *)name
|
|
138
149
|
: (NSString *)type
|
|
139
150
|
: (NSArray *)filters
|
|
@@ -142,31 +153,33 @@ RCT_EXPORT_METHOD(namedQueryGet
|
|
|
142
153
|
: (NSDictionary *)getOptions
|
|
143
154
|
: (RCTPromiseResolveBlock)resolve
|
|
144
155
|
: (RCTPromiseRejectBlock)reject) {
|
|
145
|
-
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
156
|
+
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
157
|
+
databaseId:databaseId];
|
|
158
|
+
[firestore getQueryNamed:name
|
|
159
|
+
completion:^(FIRQuery *query) {
|
|
160
|
+
if (query == nil) {
|
|
161
|
+
return [RNFBFirestoreCommon promiseRejectFirestoreException:reject error:nil];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
RNFBFirestoreQuery *firestoreQuery =
|
|
165
|
+
[[RNFBFirestoreQuery alloc] initWithModifiers:firestore
|
|
166
|
+
query:query
|
|
167
|
+
filters:filters
|
|
168
|
+
orders:orders
|
|
169
|
+
options:options];
|
|
170
|
+
FIRFirestoreSource source = [self getSource:getOptions];
|
|
171
|
+
[self handleQueryGet:firebaseApp
|
|
172
|
+
databaseId:databaseId
|
|
173
|
+
firestoreQuery:firestoreQuery
|
|
174
|
+
source:source
|
|
175
|
+
resolve:resolve
|
|
176
|
+
reject:reject];
|
|
177
|
+
}];
|
|
166
178
|
}
|
|
167
179
|
|
|
168
180
|
RCT_EXPORT_METHOD(collectionCount
|
|
169
181
|
: (FIRApp *)firebaseApp
|
|
182
|
+
: (NSString *)databaseId
|
|
170
183
|
: (NSString *)path
|
|
171
184
|
: (NSString *)type
|
|
172
185
|
: (NSArray *)filters
|
|
@@ -174,7 +187,8 @@ RCT_EXPORT_METHOD(collectionCount
|
|
|
174
187
|
: (NSDictionary *)options
|
|
175
188
|
: (RCTPromiseResolveBlock)resolve
|
|
176
189
|
: (RCTPromiseRejectBlock)reject) {
|
|
177
|
-
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
190
|
+
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
191
|
+
databaseId:databaseId];
|
|
178
192
|
FIRQuery *query = [RNFBFirestoreCommon getQueryForFirestore:firestore path:path type:type];
|
|
179
193
|
RNFBFirestoreQuery *firestoreQuery = [[RNFBFirestoreQuery alloc] initWithModifiers:firestore
|
|
180
194
|
query:query
|
|
@@ -204,6 +218,7 @@ RCT_EXPORT_METHOD(collectionCount
|
|
|
204
218
|
|
|
205
219
|
RCT_EXPORT_METHOD(collectionGet
|
|
206
220
|
: (FIRApp *)firebaseApp
|
|
221
|
+
: (NSString *)databaseId
|
|
207
222
|
: (NSString *)path
|
|
208
223
|
: (NSString *)type
|
|
209
224
|
: (NSArray *)filters
|
|
@@ -212,7 +227,8 @@ RCT_EXPORT_METHOD(collectionGet
|
|
|
212
227
|
: (NSDictionary *)getOptions
|
|
213
228
|
: (RCTPromiseResolveBlock)resolve
|
|
214
229
|
: (RCTPromiseRejectBlock)reject) {
|
|
215
|
-
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
230
|
+
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
231
|
+
databaseId:databaseId];
|
|
216
232
|
FIRQuery *query = [RNFBFirestoreCommon getQueryForFirestore:firestore path:path type:type];
|
|
217
233
|
|
|
218
234
|
RNFBFirestoreQuery *firestoreQuery = [[RNFBFirestoreQuery alloc] initWithModifiers:firestore
|
|
@@ -222,6 +238,7 @@ RCT_EXPORT_METHOD(collectionGet
|
|
|
222
238
|
options:options];
|
|
223
239
|
FIRFirestoreSource source = [self getSource:getOptions];
|
|
224
240
|
[self handleQueryGet:firebaseApp
|
|
241
|
+
databaseId:databaseId
|
|
225
242
|
firestoreQuery:firestoreQuery
|
|
226
243
|
source:source
|
|
227
244
|
resolve:resolve
|
|
@@ -229,6 +246,7 @@ RCT_EXPORT_METHOD(collectionGet
|
|
|
229
246
|
}
|
|
230
247
|
|
|
231
248
|
- (void)handleQueryOnSnapshot:(FIRApp *)firebaseApp
|
|
249
|
+
databaseId:(NSString *)databaseId
|
|
232
250
|
firestoreQuery:(RNFBFirestoreQuery *)firestoreQuery
|
|
233
251
|
listenerId:(nonnull NSNumber *)listenerId
|
|
234
252
|
listenerOptions:(NSDictionary *)listenerOptions {
|
|
@@ -245,9 +263,13 @@ RCT_EXPORT_METHOD(collectionGet
|
|
|
245
263
|
[listener remove];
|
|
246
264
|
[collectionSnapshotListeners removeObjectForKey:listenerId];
|
|
247
265
|
}
|
|
248
|
-
[weakSelf sendSnapshotError:firebaseApp
|
|
266
|
+
[weakSelf sendSnapshotError:firebaseApp
|
|
267
|
+
databaseId:databaseId
|
|
268
|
+
listenerId:listenerId
|
|
269
|
+
error:error];
|
|
249
270
|
} else {
|
|
250
271
|
[weakSelf sendSnapshotEvent:firebaseApp
|
|
272
|
+
databaseId:databaseId
|
|
251
273
|
listenerId:listenerId
|
|
252
274
|
snapshot:snapshot
|
|
253
275
|
includeMetadataChanges:includeMetadataChanges];
|
|
@@ -261,6 +283,7 @@ RCT_EXPORT_METHOD(collectionGet
|
|
|
261
283
|
}
|
|
262
284
|
|
|
263
285
|
- (void)handleQueryGet:(FIRApp *)firebaseApp
|
|
286
|
+
databaseId:(NSString *)databaseId
|
|
264
287
|
firestoreQuery:(RNFBFirestoreQuery *)firestoreQuery
|
|
265
288
|
source:(FIRFirestoreSource)source
|
|
266
289
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
@@ -277,13 +300,15 @@ RCT_EXPORT_METHOD(collectionGet
|
|
|
277
300
|
[RNFBFirestoreSerialize querySnapshotToDictionary:@"get"
|
|
278
301
|
snapshot:snapshot
|
|
279
302
|
includeMetadataChanges:false
|
|
280
|
-
appName:appName
|
|
303
|
+
appName:appName
|
|
304
|
+
databaseId:databaseId];
|
|
281
305
|
resolve(serialized);
|
|
282
306
|
}
|
|
283
307
|
}];
|
|
284
308
|
}
|
|
285
309
|
|
|
286
310
|
- (void)sendSnapshotEvent:(FIRApp *)firApp
|
|
311
|
+
databaseId:(NSString *)databaseId
|
|
287
312
|
listenerId:(nonnull NSNumber *)listenerId
|
|
288
313
|
snapshot:(FIRQuerySnapshot *)snapshot
|
|
289
314
|
includeMetadataChanges:(BOOL)includeMetadataChanges {
|
|
@@ -292,11 +317,13 @@ RCT_EXPORT_METHOD(collectionGet
|
|
|
292
317
|
[RNFBFirestoreSerialize querySnapshotToDictionary:@"onSnapshot"
|
|
293
318
|
snapshot:snapshot
|
|
294
319
|
includeMetadataChanges:includeMetadataChanges
|
|
295
|
-
appName:appName
|
|
320
|
+
appName:appName
|
|
321
|
+
databaseId:databaseId];
|
|
296
322
|
[[RNFBRCTEventEmitter shared]
|
|
297
323
|
sendEventWithName:RNFB_FIRESTORE_COLLECTION_SYNC
|
|
298
324
|
body:@{
|
|
299
325
|
@"appName" : [RNFBSharedUtils getAppJavaScriptName:firApp.name],
|
|
326
|
+
@"databaseId" : databaseId,
|
|
300
327
|
@"listenerId" : listenerId,
|
|
301
328
|
@"body" : @{
|
|
302
329
|
@"snapshot" : serialized,
|
|
@@ -305,6 +332,7 @@ RCT_EXPORT_METHOD(collectionGet
|
|
|
305
332
|
}
|
|
306
333
|
|
|
307
334
|
- (void)sendSnapshotError:(FIRApp *)firApp
|
|
335
|
+
databaseId:(NSString *)databaseId
|
|
308
336
|
listenerId:(nonnull NSNumber *)listenerId
|
|
309
337
|
error:(NSError *)error {
|
|
310
338
|
NSArray *codeAndMessage = [RNFBFirestoreCommon getCodeAndMessage:error];
|
|
@@ -312,6 +340,7 @@ RCT_EXPORT_METHOD(collectionGet
|
|
|
312
340
|
sendEventWithName:RNFB_FIRESTORE_COLLECTION_SYNC
|
|
313
341
|
body:@{
|
|
314
342
|
@"appName" : [RNFBSharedUtils getAppJavaScriptName:firApp.name],
|
|
343
|
+
@"databaseId" : databaseId,
|
|
315
344
|
@"listenerId" : listenerId,
|
|
316
345
|
@"body" : @{
|
|
317
346
|
@"error" : @{
|
|
@@ -23,9 +23,13 @@
|
|
|
23
23
|
|
|
24
24
|
+ (dispatch_queue_t)getFirestoreQueue;
|
|
25
25
|
|
|
26
|
-
+ (FIRFirestore *)getFirestoreForApp:(FIRApp *)firebaseApp;
|
|
26
|
+
+ (FIRFirestore *)getFirestoreForApp:(FIRApp *)firebaseApp databaseId:(NSString *)databaseId;
|
|
27
27
|
|
|
28
|
-
+ (
|
|
28
|
+
+ (NSString *)createFirestoreKeyWithAppName:(NSString *)appName databaseId:(NSString *)databaseId;
|
|
29
|
+
|
|
30
|
+
+ (void)setFirestoreSettings:(FIRFirestore *)firestore
|
|
31
|
+
appName:(NSString *)appName
|
|
32
|
+
databaseId:(NSString *)databaseId;
|
|
29
33
|
|
|
30
34
|
+ (FIRDocumentReference *)getDocumentForFirestore:(FIRFirestore *)firestore path:(NSString *)path;
|
|
31
35
|
|
|
@@ -29,26 +29,33 @@ NSString *const FIRESTORE_SERVER_TIMESTAMP_BEHAVIOR =
|
|
|
29
29
|
NSMutableDictionary *instanceCache;
|
|
30
30
|
|
|
31
31
|
@implementation RNFBFirestoreCommon
|
|
32
|
-
+ (FIRFirestore *)getFirestoreForApp:(FIRApp *)app {
|
|
32
|
+
+ (FIRFirestore *)getFirestoreForApp:(FIRApp *)app databaseId:(NSString *)databaseId {
|
|
33
33
|
if (instanceCache == nil) {
|
|
34
34
|
instanceCache = [[NSMutableDictionary alloc] init];
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
NSString *firestoreKey = [RNFBFirestoreCommon createFirestoreKeyWithAppName:[app name]
|
|
37
|
+
databaseId:databaseId];
|
|
38
|
+
FIRFirestore *cachedInstance = instanceCache[firestoreKey];
|
|
38
39
|
|
|
39
40
|
if (cachedInstance) {
|
|
40
41
|
return cachedInstance;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
FIRFirestore *instance = [FIRFirestore firestoreForApp:app];
|
|
44
|
+
FIRFirestore *instance = [FIRFirestore firestoreForApp:app database:databaseId];
|
|
44
45
|
|
|
45
|
-
[self setFirestoreSettings:instance
|
|
46
|
+
[self setFirestoreSettings:instance
|
|
47
|
+
appName:[RNFBSharedUtils getAppJavaScriptName:app.name]
|
|
48
|
+
databaseId:databaseId];
|
|
46
49
|
|
|
47
50
|
instanceCache[[app name]] = instance;
|
|
48
51
|
|
|
49
52
|
return instance;
|
|
50
53
|
}
|
|
51
54
|
|
|
55
|
+
+ (NSString *)createFirestoreKeyWithAppName:(NSString *)appName databaseId:(NSString *)databaseId {
|
|
56
|
+
return [NSString stringWithFormat:@"%@:%@", appName, databaseId];
|
|
57
|
+
}
|
|
58
|
+
|
|
52
59
|
+ (dispatch_queue_t)getFirestoreQueue {
|
|
53
60
|
static dispatch_queue_t firestoreQueue;
|
|
54
61
|
static dispatch_once_t once;
|
|
@@ -59,13 +66,18 @@ NSMutableDictionary *instanceCache;
|
|
|
59
66
|
return firestoreQueue;
|
|
60
67
|
}
|
|
61
68
|
|
|
62
|
-
+ (void)setFirestoreSettings:(FIRFirestore *)firestore
|
|
69
|
+
+ (void)setFirestoreSettings:(FIRFirestore *)firestore
|
|
70
|
+
appName:(NSString *)appName
|
|
71
|
+
databaseId:(NSString *)databaseId {
|
|
63
72
|
FIRFirestoreSettings *firestoreSettings = [[FIRFirestoreSettings alloc] init];
|
|
64
73
|
RNFBPreferences *preferences = [RNFBPreferences shared];
|
|
65
74
|
|
|
66
75
|
firestoreSettings.dispatchQueue = [self getFirestoreQueue];
|
|
67
76
|
|
|
68
|
-
NSString *
|
|
77
|
+
NSString *firestoreKey = [RNFBFirestoreCommon createFirestoreKeyWithAppName:appName
|
|
78
|
+
databaseId:databaseId];
|
|
79
|
+
|
|
80
|
+
NSString *cacheKey = [NSString stringWithFormat:@"%@_%@", FIRESTORE_CACHE_SIZE, firestoreKey];
|
|
69
81
|
NSInteger size = [preferences getIntegerValue:cacheKey defaultValue:0];
|
|
70
82
|
|
|
71
83
|
if (size == -1) {
|
|
@@ -76,16 +88,17 @@ NSMutableDictionary *instanceCache;
|
|
|
76
88
|
firestoreSettings.cacheSizeBytes = size;
|
|
77
89
|
}
|
|
78
90
|
|
|
79
|
-
NSString *hostKey = [NSString stringWithFormat:@"%@_%@", FIRESTORE_HOST,
|
|
91
|
+
NSString *hostKey = [NSString stringWithFormat:@"%@_%@", FIRESTORE_HOST, firestoreKey];
|
|
80
92
|
firestoreSettings.host = [preferences getStringValue:hostKey
|
|
81
93
|
defaultValue:firestore.settings.host];
|
|
82
94
|
|
|
83
|
-
NSString *persistenceKey =
|
|
95
|
+
NSString *persistenceKey =
|
|
96
|
+
[NSString stringWithFormat:@"%@_%@", FIRESTORE_PERSISTENCE, firestoreKey];
|
|
84
97
|
firestoreSettings.persistenceEnabled =
|
|
85
98
|
(BOOL)[preferences getBooleanValue:persistenceKey
|
|
86
99
|
defaultValue:firestore.settings.persistenceEnabled];
|
|
87
100
|
|
|
88
|
-
NSString *sslKey = [NSString stringWithFormat:@"%@_%@", FIRESTORE_SSL,
|
|
101
|
+
NSString *sslKey = [NSString stringWithFormat:@"%@_%@", FIRESTORE_SSL, firestoreKey];
|
|
89
102
|
firestoreSettings.sslEnabled =
|
|
90
103
|
(BOOL)[preferences getBooleanValue:sslKey defaultValue:firestore.settings.sslEnabled];
|
|
91
104
|
|
|
@@ -63,6 +63,7 @@ RCT_EXPORT_MODULE();
|
|
|
63
63
|
|
|
64
64
|
RCT_EXPORT_METHOD(documentOnSnapshot
|
|
65
65
|
: (FIRApp *)firebaseApp
|
|
66
|
+
: (NSString *)databaseId
|
|
66
67
|
: (NSString *)path
|
|
67
68
|
: (nonnull NSNumber *)listenerId
|
|
68
69
|
: (NSDictionary *)listenerOptions) {
|
|
@@ -70,7 +71,8 @@ RCT_EXPORT_METHOD(documentOnSnapshot
|
|
|
70
71
|
return;
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
74
|
+
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
75
|
+
databaseId:databaseId];
|
|
74
76
|
FIRDocumentReference *documentReference = [RNFBFirestoreCommon getDocumentForFirestore:firestore
|
|
75
77
|
path:path];
|
|
76
78
|
|
|
@@ -82,9 +84,15 @@ RCT_EXPORT_METHOD(documentOnSnapshot
|
|
|
82
84
|
[listener remove];
|
|
83
85
|
[documentSnapshotListeners removeObjectForKey:listenerId];
|
|
84
86
|
}
|
|
85
|
-
[weakSelf sendSnapshotError:firebaseApp
|
|
87
|
+
[weakSelf sendSnapshotError:firebaseApp
|
|
88
|
+
databaseId:databaseId
|
|
89
|
+
listenerId:listenerId
|
|
90
|
+
error:error];
|
|
86
91
|
} else {
|
|
87
|
-
[weakSelf sendSnapshotEvent:firebaseApp
|
|
92
|
+
[weakSelf sendSnapshotEvent:firebaseApp
|
|
93
|
+
databaseId:databaseId
|
|
94
|
+
listenerId:listenerId
|
|
95
|
+
snapshot:snapshot];
|
|
88
96
|
}
|
|
89
97
|
};
|
|
90
98
|
|
|
@@ -99,7 +107,10 @@ RCT_EXPORT_METHOD(documentOnSnapshot
|
|
|
99
107
|
documentSnapshotListeners[listenerId] = listener;
|
|
100
108
|
}
|
|
101
109
|
|
|
102
|
-
RCT_EXPORT_METHOD(documentOffSnapshot
|
|
110
|
+
RCT_EXPORT_METHOD(documentOffSnapshot
|
|
111
|
+
: (FIRApp *)firebaseApp
|
|
112
|
+
: (NSString *)databaseId
|
|
113
|
+
: (nonnull NSNumber *)listenerId) {
|
|
103
114
|
id<FIRListenerRegistration> listener = documentSnapshotListeners[listenerId];
|
|
104
115
|
if (listener) {
|
|
105
116
|
[listener remove];
|
|
@@ -109,11 +120,13 @@ RCT_EXPORT_METHOD(documentOffSnapshot : (FIRApp *)firebaseApp : (nonnull NSNumbe
|
|
|
109
120
|
|
|
110
121
|
RCT_EXPORT_METHOD(documentGet
|
|
111
122
|
: (FIRApp *)firebaseApp
|
|
123
|
+
: (NSString *)databaseId
|
|
112
124
|
: (NSString *)path
|
|
113
125
|
: (NSDictionary *)getOptions
|
|
114
126
|
: (RCTPromiseResolveBlock)resolve
|
|
115
127
|
: (RCTPromiseRejectBlock)reject) {
|
|
116
|
-
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
128
|
+
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
129
|
+
databaseId:databaseId];
|
|
117
130
|
FIRDocumentReference *documentReference = [RNFBFirestoreCommon getDocumentForFirestore:firestore
|
|
118
131
|
path:path];
|
|
119
132
|
|
|
@@ -139,9 +152,12 @@ RCT_EXPORT_METHOD(documentGet
|
|
|
139
152
|
error:error];
|
|
140
153
|
} else {
|
|
141
154
|
NSString *appName = [RNFBSharedUtils getAppJavaScriptName:firebaseApp.name];
|
|
155
|
+
NSString *firestoreKey =
|
|
156
|
+
[RNFBFirestoreCommon createFirestoreKeyWithAppName:appName
|
|
157
|
+
databaseId:databaseId];
|
|
142
158
|
NSDictionary *serialized =
|
|
143
159
|
[RNFBFirestoreSerialize documentSnapshotToDictionary:snapshot
|
|
144
|
-
|
|
160
|
+
firestoreKey:firestoreKey];
|
|
145
161
|
resolve(serialized);
|
|
146
162
|
}
|
|
147
163
|
}];
|
|
@@ -149,10 +165,12 @@ RCT_EXPORT_METHOD(documentGet
|
|
|
149
165
|
|
|
150
166
|
RCT_EXPORT_METHOD(documentDelete
|
|
151
167
|
: (FIRApp *)firebaseApp
|
|
168
|
+
: (NSString *)databaseId
|
|
152
169
|
: (NSString *)path
|
|
153
170
|
: (RCTPromiseResolveBlock)resolve
|
|
154
171
|
: (RCTPromiseRejectBlock)reject) {
|
|
155
|
-
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
172
|
+
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
173
|
+
databaseId:databaseId];
|
|
156
174
|
FIRDocumentReference *documentReference = [RNFBFirestoreCommon getDocumentForFirestore:firestore
|
|
157
175
|
path:path];
|
|
158
176
|
|
|
@@ -167,12 +185,14 @@ RCT_EXPORT_METHOD(documentDelete
|
|
|
167
185
|
|
|
168
186
|
RCT_EXPORT_METHOD(documentSet
|
|
169
187
|
: (FIRApp *)firebaseApp
|
|
188
|
+
: (NSString *)databaseId
|
|
170
189
|
: (NSString *)path
|
|
171
190
|
: (NSDictionary *)data
|
|
172
191
|
: (NSDictionary *)options
|
|
173
192
|
: (RCTPromiseResolveBlock)resolve
|
|
174
193
|
: (RCTPromiseRejectBlock)reject) {
|
|
175
|
-
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
194
|
+
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
195
|
+
databaseId:databaseId];
|
|
176
196
|
FIRDocumentReference *documentReference = [RNFBFirestoreCommon getDocumentForFirestore:firestore
|
|
177
197
|
path:path];
|
|
178
198
|
|
|
@@ -199,11 +219,13 @@ RCT_EXPORT_METHOD(documentSet
|
|
|
199
219
|
|
|
200
220
|
RCT_EXPORT_METHOD(documentUpdate
|
|
201
221
|
: (FIRApp *)firebaseApp
|
|
222
|
+
: (NSString *)databaseId
|
|
202
223
|
: (NSString *)path
|
|
203
224
|
: (NSDictionary *)data
|
|
204
225
|
: (RCTPromiseResolveBlock)resolve
|
|
205
226
|
: (RCTPromiseRejectBlock)reject) {
|
|
206
|
-
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
227
|
+
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
228
|
+
databaseId:databaseId];
|
|
207
229
|
FIRDocumentReference *documentReference = [RNFBFirestoreCommon getDocumentForFirestore:firestore
|
|
208
230
|
path:path];
|
|
209
231
|
|
|
@@ -222,10 +244,12 @@ RCT_EXPORT_METHOD(documentUpdate
|
|
|
222
244
|
|
|
223
245
|
RCT_EXPORT_METHOD(documentBatch
|
|
224
246
|
: (FIRApp *)firebaseApp
|
|
247
|
+
: (NSString *)databaseId
|
|
225
248
|
: (NSArray *)writes
|
|
226
249
|
: (RCTPromiseResolveBlock)resolve
|
|
227
250
|
: (RCTPromiseRejectBlock)reject) {
|
|
228
|
-
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
251
|
+
FIRFirestore *firestore = [RNFBFirestoreCommon getFirestoreForApp:firebaseApp
|
|
252
|
+
databaseId:databaseId];
|
|
229
253
|
FIRWriteBatch *batch = [firestore batch];
|
|
230
254
|
|
|
231
255
|
for (NSDictionary *write in writes) {
|
|
@@ -263,15 +287,19 @@ RCT_EXPORT_METHOD(documentBatch
|
|
|
263
287
|
}
|
|
264
288
|
|
|
265
289
|
- (void)sendSnapshotEvent:(FIRApp *)firApp
|
|
290
|
+
databaseId:(NSString *)databaseId
|
|
266
291
|
listenerId:(nonnull NSNumber *)listenerId
|
|
267
292
|
snapshot:(FIRDocumentSnapshot *)snapshot {
|
|
268
293
|
NSString *appName = [RNFBSharedUtils getAppJavaScriptName:firApp.name];
|
|
294
|
+
NSString *firestoreKey = [RNFBFirestoreCommon createFirestoreKeyWithAppName:appName
|
|
295
|
+
databaseId:databaseId];
|
|
269
296
|
NSDictionary *serialized = [RNFBFirestoreSerialize documentSnapshotToDictionary:snapshot
|
|
270
|
-
|
|
297
|
+
firestoreKey:firestoreKey];
|
|
271
298
|
[[RNFBRCTEventEmitter shared]
|
|
272
299
|
sendEventWithName:RNFB_FIRESTORE_DOCUMENT_SYNC
|
|
273
300
|
body:@{
|
|
274
301
|
@"appName" : [RNFBSharedUtils getAppJavaScriptName:firApp.name],
|
|
302
|
+
@"databaseId" : databaseId,
|
|
275
303
|
@"listenerId" : listenerId,
|
|
276
304
|
@"body" : @{
|
|
277
305
|
@"snapshot" : serialized,
|
|
@@ -280,6 +308,7 @@ RCT_EXPORT_METHOD(documentBatch
|
|
|
280
308
|
}
|
|
281
309
|
|
|
282
310
|
- (void)sendSnapshotError:(FIRApp *)firApp
|
|
311
|
+
databaseId:(NSString *)databaseId
|
|
283
312
|
listenerId:(nonnull NSNumber *)listenerId
|
|
284
313
|
error:(NSError *)error {
|
|
285
314
|
NSArray *codeAndMessage = [RNFBFirestoreCommon getCodeAndMessage:error];
|
|
@@ -287,6 +316,7 @@ RCT_EXPORT_METHOD(documentBatch
|
|
|
287
316
|
sendEventWithName:RNFB_FIRESTORE_DOCUMENT_SYNC
|
|
288
317
|
body:@{
|
|
289
318
|
@"appName" : [RNFBSharedUtils getAppJavaScriptName:firApp.name],
|
|
319
|
+
@"databaseId" : databaseId,
|
|
290
320
|
@"listenerId" : listenerId,
|
|
291
321
|
@"body" : @{
|
|
292
322
|
@"error" : @{
|