@react-native-firebase/database 26.0.0 → 26.2.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/RNFBDatabase.podspec +2 -1
  3. package/dist/module/version.js +1 -1
  4. package/dist/typescript/lib/index.d.ts +1 -1
  5. package/dist/typescript/lib/version.d.ts +1 -1
  6. package/ios/RNFBDatabase/RNFBDatabaseCommon.h +13 -6
  7. package/ios/RNFBDatabase/RNFBDatabaseCommon.m +2 -10
  8. package/ios/RNFBDatabase/RNFBDatabaseConstants.h +25 -0
  9. package/ios/RNFBDatabase/RNFBDatabaseModule.mm +14 -24
  10. package/ios/RNFBDatabase/RNFBDatabaseModuleHelper.h +39 -0
  11. package/ios/RNFBDatabase/RNFBDatabaseModuleHelper.m +64 -0
  12. package/ios/RNFBDatabase/RNFBDatabaseOnDisconnectHelper.h +59 -0
  13. package/ios/RNFBDatabase/RNFBDatabaseOnDisconnectHelper.m +136 -0
  14. package/ios/RNFBDatabase/RNFBDatabaseOnDisconnectModule.mm +35 -71
  15. package/ios/RNFBDatabase/RNFBDatabaseQuery.h +11 -0
  16. package/ios/RNFBDatabase/RNFBDatabaseQueryHelper.h +49 -0
  17. package/ios/RNFBDatabase/RNFBDatabaseQueryHelper.m +240 -0
  18. package/ios/RNFBDatabase/RNFBDatabaseQueryModule.h +5 -1
  19. package/ios/RNFBDatabase/RNFBDatabaseQueryModule.mm +25 -181
  20. package/ios/RNFBDatabase/RNFBDatabaseQueue.h +29 -0
  21. package/ios/RNFBDatabase/RNFBDatabaseQueue.m +31 -0
  22. package/ios/RNFBDatabase/RNFBDatabaseReferenceHelper.h +59 -0
  23. package/ios/RNFBDatabase/RNFBDatabaseReferenceHelper.m +136 -0
  24. package/ios/RNFBDatabase/RNFBDatabaseReferenceModule.mm +32 -70
  25. package/ios/RNFBDatabase/RNFBDatabaseTransactionHelper.h +38 -0
  26. package/ios/RNFBDatabase/RNFBDatabaseTransactionHelper.m +173 -0
  27. package/ios/RNFBDatabase/RNFBDatabaseTransactionModule.h +0 -1
  28. package/ios/RNFBDatabase/RNFBDatabaseTransactionModule.mm +17 -127
  29. package/lib/version.ts +1 -1
  30. package/package.json +6 -6
@@ -17,15 +17,15 @@
17
17
 
18
18
  #import <React/RCTUtils.h>
19
19
 
20
- #import "RNFBApp/RCTConvert+FIRApp.h"
21
- #import "RNFBDatabaseCommon.h"
22
- #import "RNFBDatabaseQuery.h"
20
+ #import "RNFBDatabaseQueryHelper.h"
23
21
  #import "RNFBDatabaseQueryModule.h"
22
+ #import "RNFBDatabaseQueue.h"
24
23
  #import "RNFBDatabaseTurboModules.h"
25
- #import "RNFBRCTEventEmitter.h"
26
24
 
27
- static __strong NSMutableDictionary *queryDictionary;
28
- static NSString *const RNFB_DATABASE_SYNC = @"database_sync_event";
25
+ // NOTE: This module deliberately never imports Firebase Database headers.
26
+ // See RNFBDatabaseModule.mm for rationale. All Firebase Database calls and
27
+ // query/listener bookkeeping live in the plain Objective-C
28
+ // `RNFBDatabaseQueryHelper`.
29
29
 
30
30
  @interface RNFBDatabaseQueryModule () <NativeRNFBTurboDatabaseQuerySpec, RCTBridgeModule>
31
31
  @end
@@ -46,16 +46,7 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseQuery);
46
46
  }
47
47
 
48
48
  - (dispatch_queue_t)methodQueue {
49
- return [RNFBDatabaseCommon getDispatchQueue];
50
- }
51
-
52
- - (id)init {
53
- self = [super init];
54
- static dispatch_once_t onceToken;
55
- dispatch_once(&onceToken, ^{
56
- queryDictionary = [[NSMutableDictionary alloc] init];
57
- });
58
- return self;
49
+ return [RNFBDatabaseQueue getDispatchQueue];
59
50
  }
60
51
 
61
52
  - (void)dealloc {
@@ -63,131 +54,7 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseQuery);
63
54
  }
64
55
 
65
56
  - (void)invalidate {
66
- NSArray *queryKeys = [queryDictionary allKeys];
67
- for (NSString *key in queryKeys) {
68
- RNFBDatabaseQuery *query = queryDictionary[key];
69
- [query removeAllEventListeners];
70
- [queryDictionary removeObjectForKey:key];
71
- }
72
- }
73
-
74
- - (RNFBDatabaseQuery *)getDatabaseQueryInstance:(FIRDatabaseReference *)reference
75
- modifiers:(NSArray *)modifiers {
76
- return [[RNFBDatabaseQuery alloc] initWithReferenceAndModifiers:reference modifiers:modifiers];
77
- }
78
-
79
- - (RNFBDatabaseQuery *)getDatabaseQueryInstance:(NSString *)key
80
- reference:(FIRDatabaseReference *)reference
81
- modifiers:(NSArray *)modifiers {
82
- RNFBDatabaseQuery *cachedQuery = queryDictionary[key];
83
-
84
- if (cachedQuery != nil) {
85
- return cachedQuery;
86
- }
87
-
88
- RNFBDatabaseQuery *query = [[RNFBDatabaseQuery alloc] initWithReferenceAndModifiers:reference
89
- modifiers:modifiers];
90
-
91
- queryDictionary[key] = query;
92
- return query;
93
- }
94
-
95
- - (void)addOnceEventListener:(RNFBDatabaseQuery *)databaseQuery
96
- eventType:(NSString *)eventType
97
- resolve:(RCTPromiseResolveBlock)resolve
98
- reject:(RCTPromiseRejectBlock)reject {
99
- FIRDataEventType firDataEventType =
100
- (FIRDataEventType)[RNFBDatabaseCommon getEventTypeFromName:eventType];
101
-
102
- id andPreviousSiblingKeyWithBlock =
103
- ^(FIRDataSnapshot *_Nonnull dataSnapshot, NSString *_Nullable previousChildName) {
104
- NSDictionary *data;
105
- if ([eventType isEqualToString:@"value"]) {
106
- data = [RNFBDatabaseCommon snapshotToDictionary:dataSnapshot];
107
- } else {
108
- data = [RNFBDatabaseCommon snapshotWithPreviousChildToDictionary:dataSnapshot
109
- previousChildName:previousChildName];
110
- }
111
- resolve(data);
112
- };
113
-
114
- id errorBlock = ^(NSError *_Nonnull error) {
115
- [RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
116
- };
117
-
118
- [databaseQuery.query observeSingleEventOfType:firDataEventType
119
- andPreviousSiblingKeyWithBlock:andPreviousSiblingKeyWithBlock
120
- withCancelBlock:errorBlock];
121
- }
122
-
123
- - (void)addEventListener:(RNFBDatabaseQuery *)databaseQuery
124
- eventType:(NSString *)eventType
125
- registration:(NSDictionary *)registration {
126
- NSString *eventRegistrationKey = registration[@"eventRegistrationKey"];
127
-
128
- if (![databaseQuery hasEventListener:eventRegistrationKey]) {
129
- id andPreviousSiblingKeyWithBlock =
130
- ^(FIRDataSnapshot *_Nonnull dataSnapshot, NSString *_Nullable previousChildName) {
131
- [self handleDatabaseEvent:eventRegistrationKey
132
- eventType:eventType
133
- registration:registration
134
- snapshot:dataSnapshot
135
- previousChildName:previousChildName];
136
- };
137
-
138
- id errorBlock = ^(NSError *_Nonnull error) {
139
- [databaseQuery removeEventListener:eventRegistrationKey];
140
- [self handleDatabaseEventError:eventRegistrationKey registration:registration error:error];
141
- };
142
-
143
- FIRDataEventType firDataEventType =
144
- (FIRDataEventType)[RNFBDatabaseCommon getEventTypeFromName:eventType];
145
- FIRDatabaseHandle handle = [databaseQuery.query observeEventType:firDataEventType
146
- andPreviousSiblingKeyWithBlock:andPreviousSiblingKeyWithBlock
147
- withCancelBlock:errorBlock];
148
- [databaseQuery addEventListener:eventRegistrationKey handle:handle];
149
- }
150
- }
151
-
152
- - (void)handleDatabaseEvent:(NSString *)key
153
- eventType:(NSString *)eventType
154
- registration:(NSDictionary *)registration
155
- snapshot:(FIRDataSnapshot *)dataSnapshot
156
- previousChildName:(NSString *)previousChildName {
157
- NSDictionary *data;
158
- if ([eventType isEqualToString:@"value"]) {
159
- data = [RNFBDatabaseCommon snapshotToDictionary:dataSnapshot];
160
- } else {
161
- data = [RNFBDatabaseCommon snapshotWithPreviousChildToDictionary:dataSnapshot
162
- previousChildName:previousChildName];
163
- }
164
-
165
- [[RNFBRCTEventEmitter shared] sendEventWithName:RNFB_DATABASE_SYNC
166
- body:@{
167
- @"body" : @{
168
- @"data" : data,
169
- @"key" : key,
170
- @"eventType" : eventType,
171
- @"registration" : registration,
172
- }
173
- }];
174
- }
175
-
176
- - (void)handleDatabaseEventError:(NSString *)key
177
- registration:(NSDictionary *)registration
178
- error:(NSError *)error {
179
- NSArray *codeAndMessage = [RNFBDatabaseCommon getCodeAndMessage:error];
180
- [[RNFBRCTEventEmitter shared] sendEventWithName:RNFB_DATABASE_SYNC
181
- body:@{
182
- @"body" : @{
183
- @"key" : key,
184
- @"error" : @{
185
- @"code" : codeAndMessage[0],
186
- @"message" : codeAndMessage[1],
187
- },
188
- @"registration" : registration,
189
- }
190
- }];
57
+ [RNFBDatabaseQueryHelper invalidate];
191
58
  }
192
59
 
193
60
  #pragma mark -
@@ -200,44 +67,21 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseQuery);
200
67
  eventType:(NSString *)eventType
201
68
  resolve:(RCTPromiseResolveBlock)resolve
202
69
  reject:(RCTPromiseRejectBlock)reject {
203
- FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
204
- FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
205
- FIRDatabaseReference *firDatabaseReference =
206
- [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
207
- RNFBDatabaseQuery *databaseQuery = [self getDatabaseQueryInstance:firDatabaseReference
208
- modifiers:modifiers];
209
-
210
- [self addOnceEventListener:databaseQuery eventType:eventType resolve:resolve reject:reject];
70
+ [RNFBDatabaseQueryHelper once:app
71
+ dbURL:dbURL
72
+ path:path
73
+ modifiers:modifiers
74
+ eventType:eventType
75
+ resolve:resolve
76
+ reject:reject];
211
77
  }
212
78
 
213
79
  - (void)on:(NSString *)app dbURL:(NSString *)dbURL props:(NSDictionary *)props {
214
- NSString *key = [props valueForKey:@"key"];
215
- NSString *path = [props valueForKey:@"path"];
216
- NSString *eventType = [props valueForKey:@"eventType"];
217
- NSArray *modifiers = [props valueForKey:@"modifiers"];
218
- NSDictionary *registration = [props valueForKey:@"registration"];
219
-
220
- FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
221
- FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
222
- FIRDatabaseReference *firDatabaseReference =
223
- [RNFBDatabaseCommon getReferenceForDatabase:key firebaseDatabase:firDatabase path:path];
224
- RNFBDatabaseQuery *databaseQuery = [self getDatabaseQueryInstance:key
225
- reference:firDatabaseReference
226
- modifiers:modifiers];
227
- [self addEventListener:databaseQuery eventType:eventType registration:registration];
80
+ [RNFBDatabaseQueryHelper on:app dbURL:dbURL props:props];
228
81
  }
229
82
 
230
83
  - (void)off:(NSString *)queryKey eventRegistrationKey:(NSString *)eventRegistrationKey {
231
- RNFBDatabaseQuery *databaseQuery = queryDictionary[queryKey];
232
-
233
- if (databaseQuery != nil) {
234
- [databaseQuery removeEventListener:eventRegistrationKey];
235
-
236
- if (![databaseQuery hasListeners]) {
237
- [queryDictionary removeObjectForKey:queryKey];
238
- [RNFBDatabaseCommon removeReferenceByKey:queryKey];
239
- }
240
- }
84
+ [RNFBDatabaseQueryHelper off:queryKey eventRegistrationKey:eventRegistrationKey];
241
85
  }
242
86
 
243
87
  - (void)keepSynced:(NSString *)app
@@ -248,14 +92,14 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseQuery);
248
92
  enabled:(BOOL)value
249
93
  resolve:(RCTPromiseResolveBlock)resolve
250
94
  reject:(RCTPromiseRejectBlock)reject {
251
- FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
252
- FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
253
- FIRDatabaseReference *firDatabaseReference =
254
- [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
255
- RNFBDatabaseQuery *databaseQuery = [self getDatabaseQueryInstance:firDatabaseReference
256
- modifiers:modifiers];
257
- [databaseQuery.query keepSynced:value];
258
- resolve([NSNull null]);
95
+ [RNFBDatabaseQueryHelper keepSynced:app
96
+ dbURL:dbURL
97
+ key:key
98
+ path:path
99
+ modifiers:modifiers
100
+ enabled:value
101
+ resolve:resolve
102
+ reject:reject];
259
103
  }
260
104
 
261
105
  @end
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ #import <Foundation/Foundation.h>
19
+
20
+ // Deliberately Firebase-free: this header is imported by Objective-C++ (.mm)
21
+ // modules that must not pull in any Firebase Database headers directly (see
22
+ // RNFBDatabaseCommon.h for why). Keeping it isolated means the shared serial
23
+ // queue used as `methodQueue` can be obtained without ever importing
24
+ // Firebase from a .mm translation unit.
25
+ @interface RNFBDatabaseQueue : NSObject
26
+
27
+ + (dispatch_queue_t)getDispatchQueue;
28
+
29
+ @end
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ #import "RNFBDatabaseQueue.h"
19
+
20
+ @implementation RNFBDatabaseQueue
21
+
22
+ + (dispatch_queue_t)getDispatchQueue {
23
+ static dispatch_once_t once;
24
+ static dispatch_queue_t sharedInstance;
25
+ dispatch_once(&once, ^{
26
+ sharedInstance = dispatch_queue_create("io.invertase.firebase.database", DISPATCH_QUEUE_SERIAL);
27
+ });
28
+ return sharedInstance;
29
+ }
30
+
31
+ @end
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ #import <Foundation/Foundation.h>
19
+ #import <React/RCTBridgeModule.h>
20
+
21
+ // See RNFBDatabaseModuleHelper.h for rationale: plain Objective-C helper
22
+ // that owns all `FIRDatabaseReference` calls for RNFBDatabaseReferenceModule.
23
+ @interface RNFBDatabaseReferenceHelper : NSObject
24
+
25
+ + (void)set:(NSString *)app
26
+ dbURL:(NSString *)dbURL
27
+ path:(NSString *)path
28
+ props:(NSDictionary *)props
29
+ resolve:(RCTPromiseResolveBlock)resolve
30
+ reject:(RCTPromiseRejectBlock)reject;
31
+
32
+ + (void)update:(NSString *)app
33
+ dbURL:(NSString *)dbURL
34
+ path:(NSString *)path
35
+ props:(NSDictionary *)props
36
+ resolve:(RCTPromiseResolveBlock)resolve
37
+ reject:(RCTPromiseRejectBlock)reject;
38
+
39
+ + (void)setWithPriority:(NSString *)app
40
+ dbURL:(NSString *)dbURL
41
+ path:(NSString *)path
42
+ props:(NSDictionary *)props
43
+ resolve:(RCTPromiseResolveBlock)resolve
44
+ reject:(RCTPromiseRejectBlock)reject;
45
+
46
+ + (void)remove:(NSString *)app
47
+ dbURL:(NSString *)dbURL
48
+ path:(NSString *)path
49
+ resolve:(RCTPromiseResolveBlock)resolve
50
+ reject:(RCTPromiseRejectBlock)reject;
51
+
52
+ + (void)setPriority:(NSString *)app
53
+ dbURL:(NSString *)dbURL
54
+ path:(NSString *)path
55
+ props:(NSDictionary *)props
56
+ resolve:(RCTPromiseResolveBlock)resolve
57
+ reject:(RCTPromiseRejectBlock)reject;
58
+
59
+ @end
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Copyright (c) 2016-present Invertase Limited & Contributors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this library except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ #if __has_include(<Firebase/Firebase.h>)
19
+ #import <Firebase/Firebase.h>
20
+ #else
21
+ @import FirebaseCore;
22
+ @import FirebaseDatabaseInternal;
23
+ #endif
24
+
25
+ #import "RNFBApp/RCTConvert+FIRApp.h"
26
+ #import "RNFBDatabaseCommon.h"
27
+ #import "RNFBDatabaseReferenceHelper.h"
28
+
29
+ @implementation RNFBDatabaseReferenceHelper
30
+
31
+ + (void)set:(NSString *)app
32
+ dbURL:(NSString *)dbURL
33
+ path:(NSString *)path
34
+ props:(NSDictionary *)props
35
+ resolve:(RCTPromiseResolveBlock)resolve
36
+ reject:(RCTPromiseRejectBlock)reject {
37
+ FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
38
+ FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
39
+ FIRDatabaseReference *firDatabaseReference =
40
+ [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
41
+
42
+ [firDatabaseReference setValue:[props valueForKey:@"value"]
43
+ withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
44
+ if (error != nil) {
45
+ [RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
46
+ } else {
47
+ resolve([NSNull null]);
48
+ }
49
+ }];
50
+ }
51
+
52
+ + (void)update:(NSString *)app
53
+ dbURL:(NSString *)dbURL
54
+ path:(NSString *)path
55
+ props:(NSDictionary *)props
56
+ resolve:(RCTPromiseResolveBlock)resolve
57
+ reject:(RCTPromiseRejectBlock)reject {
58
+ FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
59
+ FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
60
+ FIRDatabaseReference *firDatabaseReference =
61
+ [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
62
+
63
+ [firDatabaseReference updateChildValues:[props valueForKey:@"values"]
64
+ withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
65
+ if (error != nil) {
66
+ [RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
67
+ } else {
68
+ resolve([NSNull null]);
69
+ }
70
+ }];
71
+ }
72
+
73
+ + (void)setWithPriority:(NSString *)app
74
+ dbURL:(NSString *)dbURL
75
+ path:(NSString *)path
76
+ props:(NSDictionary *)props
77
+ resolve:(RCTPromiseResolveBlock)resolve
78
+ reject:(RCTPromiseRejectBlock)reject {
79
+ FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
80
+ FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
81
+ FIRDatabaseReference *firDatabaseReference =
82
+ [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
83
+
84
+ [firDatabaseReference setValue:[props valueForKey:@"value"]
85
+ andPriority:[props valueForKey:@"priority"]
86
+ withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
87
+ if (error != nil) {
88
+ [RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
89
+ } else {
90
+ resolve([NSNull null]);
91
+ }
92
+ }];
93
+ }
94
+
95
+ + (void)remove:(NSString *)app
96
+ dbURL:(NSString *)dbURL
97
+ path:(NSString *)path
98
+ resolve:(RCTPromiseResolveBlock)resolve
99
+ reject:(RCTPromiseRejectBlock)reject {
100
+ FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
101
+ FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
102
+ FIRDatabaseReference *firDatabaseReference =
103
+ [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
104
+
105
+ [firDatabaseReference
106
+ removeValueWithCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
107
+ if (error != nil) {
108
+ [RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
109
+ } else {
110
+ resolve([NSNull null]);
111
+ }
112
+ }];
113
+ }
114
+
115
+ + (void)setPriority:(NSString *)app
116
+ dbURL:(NSString *)dbURL
117
+ path:(NSString *)path
118
+ props:(NSDictionary *)props
119
+ resolve:(RCTPromiseResolveBlock)resolve
120
+ reject:(RCTPromiseRejectBlock)reject {
121
+ FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
122
+ FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
123
+ FIRDatabaseReference *firDatabaseReference =
124
+ [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
125
+
126
+ [firDatabaseReference setPriority:[props valueForKey:@"priority"]
127
+ withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
128
+ if (error != nil) {
129
+ [RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
130
+ } else {
131
+ resolve([NSNull null]);
132
+ }
133
+ }];
134
+ }
135
+
136
+ @end
@@ -15,14 +15,17 @@
15
15
  *
16
16
  */
17
17
 
18
- #import <Firebase/Firebase.h>
19
18
  #import <React/RCTUtils.h>
20
19
 
21
- #import "RNFBApp/RCTConvert+FIRApp.h"
22
- #import "RNFBDatabaseCommon.h"
20
+ #import "RNFBDatabaseQueue.h"
21
+ #import "RNFBDatabaseReferenceHelper.h"
23
22
  #import "RNFBDatabaseReferenceModule.h"
24
23
  #import "RNFBDatabaseTurboModules.h"
25
24
 
25
+ // NOTE: This module deliberately never imports Firebase Database headers.
26
+ // See RNFBDatabaseModule.mm for rationale. All Firebase Database calls are
27
+ // delegated to the plain Objective-C `RNFBDatabaseReferenceHelper`.
28
+
26
29
  @interface RNFBDatabaseReferenceModule () <NativeRNFBTurboDatabaseReferenceSpec, RCTBridgeModule>
27
30
  @end
28
31
 
@@ -42,7 +45,7 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseReference);
42
45
  }
43
46
 
44
47
  - (dispatch_queue_t)methodQueue {
45
- return [RNFBDatabaseCommon getDispatchQueue];
48
+ return [RNFBDatabaseQueue getDispatchQueue];
46
49
  }
47
50
 
48
51
  - (void)dealloc {
@@ -61,19 +64,12 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseReference);
61
64
  props:(NSDictionary *)props
62
65
  resolve:(RCTPromiseResolveBlock)resolve
63
66
  reject:(RCTPromiseRejectBlock)reject {
64
- FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
65
- FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
66
- FIRDatabaseReference *firDatabaseReference =
67
- [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
68
-
69
- [firDatabaseReference setValue:[props valueForKey:@"value"]
70
- withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
71
- if (error != nil) {
72
- [RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
73
- } else {
74
- resolve([NSNull null]);
75
- }
76
- }];
67
+ [RNFBDatabaseReferenceHelper set:app
68
+ dbURL:dbURL
69
+ path:path
70
+ props:props
71
+ resolve:resolve
72
+ reject:reject];
77
73
  }
78
74
 
79
75
  - (void)update:(NSString *)app
@@ -82,19 +78,12 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseReference);
82
78
  props:(NSDictionary *)props
83
79
  resolve:(RCTPromiseResolveBlock)resolve
84
80
  reject:(RCTPromiseRejectBlock)reject {
85
- FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
86
- FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
87
- FIRDatabaseReference *firDatabaseReference =
88
- [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
89
-
90
- [firDatabaseReference updateChildValues:[props valueForKey:@"values"]
91
- withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
92
- if (error != nil) {
93
- [RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
94
- } else {
95
- resolve([NSNull null]);
96
- }
97
- }];
81
+ [RNFBDatabaseReferenceHelper update:app
82
+ dbURL:dbURL
83
+ path:path
84
+ props:props
85
+ resolve:resolve
86
+ reject:reject];
98
87
  }
99
88
 
100
89
  - (void)setWithPriority:(NSString *)app
@@ -103,20 +92,12 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseReference);
103
92
  props:(NSDictionary *)props
104
93
  resolve:(RCTPromiseResolveBlock)resolve
105
94
  reject:(RCTPromiseRejectBlock)reject {
106
- FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
107
- FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
108
- FIRDatabaseReference *firDatabaseReference =
109
- [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
110
-
111
- [firDatabaseReference setValue:[props valueForKey:@"value"]
112
- andPriority:[props valueForKey:@"priority"]
113
- withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
114
- if (error != nil) {
115
- [RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
116
- } else {
117
- resolve([NSNull null]);
118
- }
119
- }];
95
+ [RNFBDatabaseReferenceHelper setWithPriority:app
96
+ dbURL:dbURL
97
+ path:path
98
+ props:props
99
+ resolve:resolve
100
+ reject:reject];
120
101
  }
121
102
 
122
103
  - (void)remove:(NSString *)app
@@ -124,19 +105,7 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseReference);
124
105
  path:(NSString *)path
125
106
  resolve:(RCTPromiseResolveBlock)resolve
126
107
  reject:(RCTPromiseRejectBlock)reject {
127
- FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
128
- FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
129
- FIRDatabaseReference *firDatabaseReference =
130
- [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
131
-
132
- [firDatabaseReference
133
- removeValueWithCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
134
- if (error != nil) {
135
- [RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
136
- } else {
137
- resolve([NSNull null]);
138
- }
139
- }];
108
+ [RNFBDatabaseReferenceHelper remove:app dbURL:dbURL path:path resolve:resolve reject:reject];
140
109
  }
141
110
 
142
111
  - (void)setPriority:(NSString *)app
@@ -145,19 +114,12 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseReference);
145
114
  props:(NSDictionary *)props
146
115
  resolve:(RCTPromiseResolveBlock)resolve
147
116
  reject:(RCTPromiseRejectBlock)reject {
148
- FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
149
- FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
150
- FIRDatabaseReference *firDatabaseReference =
151
- [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
152
-
153
- [firDatabaseReference setPriority:[props valueForKey:@"priority"]
154
- withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
155
- if (error != nil) {
156
- [RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
157
- } else {
158
- resolve([NSNull null]);
159
- }
160
- }];
117
+ [RNFBDatabaseReferenceHelper setPriority:app
118
+ dbURL:dbURL
119
+ path:path
120
+ props:props
121
+ resolve:resolve
122
+ reject:reject];
161
123
  }
162
124
 
163
125
  @end