@react-native-firebase/database 26.0.0 → 26.1.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 +6 -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 +4 -4
@@ -0,0 +1,38 @@
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
+ // See RNFBDatabaseModuleHelper.h for rationale: plain Objective-C helper
21
+ // that owns all `FIRDatabaseReference`/`FIRTransactionResult` calls and the
22
+ // pending-transaction bookkeeping for RNFBDatabaseTransactionModule.
23
+ @interface RNFBDatabaseTransactionHelper : NSObject
24
+
25
+ + (void)transactionStart:(NSString *)app
26
+ dbURL:(NSString *)dbURL
27
+ path:(NSString *)path
28
+ transactionId:(double)transactionId
29
+ applyLocally:(BOOL)applyLocally;
30
+
31
+ + (void)transactionTryCommit:(NSString *)app
32
+ dbURL:(NSString *)dbURL
33
+ transactionId:(double)transactionId
34
+ updates:(NSDictionary *)updates;
35
+
36
+ + (void)invalidate;
37
+
38
+ @end
@@ -0,0 +1,173 @@
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 "RNFBApp/RNFBSharedUtils.h"
27
+ #import "RNFBDatabaseCommon.h"
28
+ #import "RNFBDatabaseTransactionHelper.h"
29
+ #import "RNFBRCTEventEmitter.h"
30
+
31
+ static __strong NSMutableDictionary *transactions;
32
+ static NSString *const RNFB_DATABASE_TRANSACTION_EVENT = @"database_transaction_event";
33
+
34
+ @implementation RNFBDatabaseTransactionHelper
35
+
36
+ + (dispatch_queue_t)transactionQueue {
37
+ static dispatch_once_t once;
38
+ static dispatch_queue_t sharedInstance;
39
+ dispatch_once(&once, ^{
40
+ transactions = [[NSMutableDictionary alloc] init];
41
+ sharedInstance = dispatch_queue_create(
42
+ "io.invertase.react-native-firebase.database.transactions", DISPATCH_QUEUE_CONCURRENT);
43
+ });
44
+ return sharedInstance;
45
+ }
46
+
47
+ + (void)invalidate {
48
+ dispatch_queue_t queue = [self transactionQueue];
49
+ dispatch_sync(queue, ^{
50
+ for (NSString *key in [transactions allKeys]) {
51
+ NSMutableDictionary *transactionState = transactions[key];
52
+ [transactionState setValue:@true forKey:@"abort"];
53
+ dispatch_semaphore_t sema = [transactionState valueForKey:@"semaphore"];
54
+ if (sema) {
55
+ dispatch_semaphore_signal(sema);
56
+ }
57
+ [transactions removeObjectForKey:key];
58
+ }
59
+ });
60
+ }
61
+
62
+ + (void)transactionStart:(NSString *)app
63
+ dbURL:(NSString *)dbURL
64
+ path:(NSString *)path
65
+ transactionId:(double)transactionId
66
+ applyLocally:(BOOL)applyLocally {
67
+ dispatch_queue_t queue = [self transactionQueue];
68
+ dispatch_async(queue, ^{
69
+ NSMutableDictionary *transactionState = [NSMutableDictionary new];
70
+ dispatch_semaphore_t sema = dispatch_semaphore_create(0);
71
+ #pragma clang diagnostic push
72
+ #pragma ide diagnostic ignored "err_typecheck_convert_incompatible"
73
+ transactionState[@"semaphore"] = sema;
74
+ #pragma clang diagnostic pop
75
+ FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
76
+ FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
77
+ FIRDatabaseReference *firDatabaseReference =
78
+ [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
79
+
80
+ id runTransactionBlock = ^FIRTransactionResult *(FIRMutableData *currentData) {
81
+ dispatch_barrier_async(queue, ^{
82
+ [transactions setValue:transactionState forKey:[@(transactionId) stringValue]];
83
+
84
+ [[RNFBRCTEventEmitter shared]
85
+ sendEventWithName:RNFB_DATABASE_TRANSACTION_EVENT
86
+ body:@{
87
+ @"appName" : [RNFBSharedUtils getAppJavaScriptName:firDatabase.app.name],
88
+ @"id" : @(transactionId),
89
+ @"body" : @{
90
+ @"type" : @"update",
91
+ @"value" : currentData.value,
92
+ }
93
+ }];
94
+ });
95
+
96
+ dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC);
97
+ BOOL timedout = dispatch_semaphore_wait(sema, delayTime) != 0;
98
+
99
+ BOOL abort = [transactionState valueForKey:@"abort"] || timedout;
100
+ id value = [transactionState valueForKey:@"value"];
101
+
102
+ dispatch_barrier_async(queue, ^{
103
+ [transactions removeObjectForKey:[@(transactionId) stringValue]];
104
+ });
105
+
106
+ if (abort) {
107
+ return [FIRTransactionResult abort];
108
+ }
109
+
110
+ currentData.value = value;
111
+ return [FIRTransactionResult successWithValue:currentData];
112
+ };
113
+
114
+ id andCompletionBlock = ^(NSError *error, BOOL committed, FIRDataSnapshot *dataSnapshot) {
115
+ NSMutableDictionary *resultMap = [NSMutableDictionary dictionary];
116
+ resultMap[@"committed"] = @(committed);
117
+
118
+ if (error != nil) {
119
+ NSArray *codeAndMessage = [RNFBDatabaseCommon getCodeAndMessage:error];
120
+ resultMap[@"type"] = @"error";
121
+ resultMap[@"error"] = @{
122
+ @"code" : codeAndMessage[0],
123
+ @"message" : codeAndMessage[1],
124
+ };
125
+ } else {
126
+ resultMap[@"type"] = @"complete";
127
+ resultMap[@"snapshot"] = [RNFBDatabaseCommon snapshotToDictionary:dataSnapshot];
128
+ }
129
+
130
+ [[RNFBRCTEventEmitter shared]
131
+ sendEventWithName:RNFB_DATABASE_TRANSACTION_EVENT
132
+ body:@{
133
+ @"id" : @(transactionId),
134
+ @"appName" : [RNFBSharedUtils getAppJavaScriptName:firDatabase.app.name],
135
+ @"body" : resultMap,
136
+ }];
137
+ };
138
+
139
+ [firDatabaseReference runTransactionBlock:runTransactionBlock
140
+ andCompletionBlock:andCompletionBlock
141
+ withLocalEvents:applyLocally];
142
+ });
143
+ }
144
+
145
+ + (void)transactionTryCommit:(NSString *)app
146
+ dbURL:(NSString *)dbURL
147
+ transactionId:(double)transactionId
148
+ updates:(NSDictionary *)updates {
149
+ dispatch_queue_t queue = [self transactionQueue];
150
+ __block NSMutableDictionary *transactionState;
151
+
152
+ dispatch_sync(queue, ^{
153
+ transactionState = transactions[[@(transactionId) stringValue]];
154
+ });
155
+
156
+ if (!transactionState) {
157
+ NSLog(@"tryCommitTransaction for unknown ID %@", @(transactionId));
158
+ return;
159
+ }
160
+
161
+ BOOL abort = [[updates valueForKey:@"abort"] boolValue];
162
+
163
+ if (abort) {
164
+ [transactionState setValue:@true forKey:@"abort"];
165
+ } else {
166
+ id newValue = [updates valueForKey:@"value"];
167
+ [transactionState setValue:newValue forKey:@"value"];
168
+ }
169
+
170
+ dispatch_semaphore_signal([transactionState valueForKey:@"semaphore"]);
171
+ }
172
+
173
+ @end
@@ -20,5 +20,4 @@
20
20
  #import <React/RCTBridgeModule.h>
21
21
 
22
22
  @interface RNFBDatabaseTransactionModule : NSObject <RCTBridgeModule>
23
- @property dispatch_queue_t transactionQueue;
24
23
  @end
@@ -15,18 +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 "RNFBDatabaseTransactionHelper.h"
23
22
  #import "RNFBDatabaseTransactionModule.h"
24
23
  #import "RNFBDatabaseTurboModules.h"
25
- #import "RNFBRCTEventEmitter.h"
26
- #import "RNFBSharedUtils.h"
27
24
 
28
- static __strong NSMutableDictionary *transactions;
29
- static NSString *const RNFB_DATABASE_TRANSACTION_EVENT = @"database_transaction_event";
25
+ // NOTE: This module deliberately never imports Firebase Database headers.
26
+ // See RNFBDatabaseModule.mm for rationale. All Firebase Database calls, and
27
+ // the pending-transaction dispatch queue/bookkeeping, live in the plain
28
+ // Objective-C `RNFBDatabaseTransactionHelper`.
30
29
 
31
30
  @interface RNFBDatabaseTransactionModule () <NativeRNFBTurboDatabaseTransactionSpec,
32
31
  RCTBridgeModule>
@@ -48,19 +47,7 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseTransaction);
48
47
  }
49
48
 
50
49
  - (dispatch_queue_t)methodQueue {
51
- return [RNFBDatabaseCommon getDispatchQueue];
52
- }
53
-
54
- - (id)init {
55
- if (self = [super init]) {
56
- transactions = [[NSMutableDictionary alloc] init];
57
- #pragma clang diagnostic push
58
- #pragma ide diagnostic ignored "BridgeCastIssues"
59
- _transactionQueue = dispatch_queue_create(
60
- "io.invertase.react-native-firebase.database.transactions", DISPATCH_QUEUE_CONCURRENT);
61
- #pragma clang diagnostic pop
62
- }
63
- return self;
50
+ return [RNFBDatabaseQueue getDispatchQueue];
64
51
  }
65
52
 
66
53
  - (void)dealloc {
@@ -68,17 +55,7 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseTransaction);
68
55
  }
69
56
 
70
57
  - (void)invalidate {
71
- dispatch_sync(_transactionQueue, ^{
72
- for (NSString *key in [transactions allKeys]) {
73
- NSMutableDictionary *transactionState = transactions[key];
74
- [transactionState setValue:@true forKey:@"abort"];
75
- dispatch_semaphore_t sema = [transactionState valueForKey:@"semaphore"];
76
- if (sema) {
77
- dispatch_semaphore_signal(sema);
78
- }
79
- [transactions removeObjectForKey:key];
80
- }
81
- });
58
+ [RNFBDatabaseTransactionHelper invalidate];
82
59
  }
83
60
 
84
61
  #pragma mark -
@@ -89,108 +66,21 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseTransaction);
89
66
  path:(NSString *)path
90
67
  transactionId:(double)transactionId
91
68
  applyLocally:(BOOL)applyLocally {
92
- dispatch_async(_transactionQueue, ^{
93
- NSMutableDictionary *transactionState = [NSMutableDictionary new];
94
- dispatch_semaphore_t sema = dispatch_semaphore_create(0);
95
- #pragma clang diagnostic push
96
- #pragma ide diagnostic ignored "err_typecheck_convert_incompatible"
97
- transactionState[@"semaphore"] = sema;
98
- #pragma clang diagnostic pop
99
- FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
100
- FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
101
- FIRDatabaseReference *firDatabaseReference =
102
- [RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
103
-
104
- id runTransactionBlock = ^FIRTransactionResult *(FIRMutableData *currentData) {
105
- dispatch_barrier_async(self->_transactionQueue, ^{
106
- [transactions setValue:transactionState forKey:[@(transactionId) stringValue]];
107
-
108
- [[RNFBRCTEventEmitter shared]
109
- sendEventWithName:RNFB_DATABASE_TRANSACTION_EVENT
110
- body:@{
111
- @"appName" : [RNFBSharedUtils getAppJavaScriptName:firDatabase.app.name],
112
- @"id" : @(transactionId),
113
- @"body" : @{
114
- @"type" : @"update",
115
- @"value" : currentData.value,
116
- }
117
- }];
118
- });
119
-
120
- dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC);
121
- BOOL timedout = dispatch_semaphore_wait(sema, delayTime) != 0;
122
-
123
- BOOL abort = [transactionState valueForKey:@"abort"] || timedout;
124
- id value = [transactionState valueForKey:@"value"];
125
-
126
- dispatch_barrier_async(self->_transactionQueue, ^{
127
- [transactions removeObjectForKey:[@(transactionId) stringValue]];
128
- });
129
-
130
- if (abort) {
131
- return [FIRTransactionResult abort];
132
- }
133
-
134
- currentData.value = value;
135
- return [FIRTransactionResult successWithValue:currentData];
136
- };
137
-
138
- id andCompletionBlock = ^(NSError *error, BOOL committed, FIRDataSnapshot *dataSnapshot) {
139
- NSMutableDictionary *resultMap = [NSMutableDictionary dictionary];
140
- resultMap[@"committed"] = @(committed);
141
-
142
- if (error != nil) {
143
- NSArray *codeAndMessage = [RNFBDatabaseCommon getCodeAndMessage:error];
144
- resultMap[@"type"] = @"error";
145
- resultMap[@"error"] = @{
146
- @"code" : codeAndMessage[0],
147
- @"message" : codeAndMessage[1],
148
- };
149
- } else {
150
- resultMap[@"type"] = @"complete";
151
- resultMap[@"snapshot"] = [RNFBDatabaseCommon snapshotToDictionary:dataSnapshot];
152
- }
153
-
154
- [[RNFBRCTEventEmitter shared]
155
- sendEventWithName:RNFB_DATABASE_TRANSACTION_EVENT
156
- body:@{
157
- @"id" : @(transactionId),
158
- @"appName" : [RNFBSharedUtils getAppJavaScriptName:firDatabase.app.name],
159
- @"body" : resultMap,
160
- }];
161
- };
162
-
163
- [firDatabaseReference runTransactionBlock:runTransactionBlock
164
- andCompletionBlock:andCompletionBlock
165
- withLocalEvents:applyLocally];
166
- });
69
+ [RNFBDatabaseTransactionHelper transactionStart:app
70
+ dbURL:dbURL
71
+ path:path
72
+ transactionId:transactionId
73
+ applyLocally:applyLocally];
167
74
  }
168
75
 
169
76
  - (void)transactionTryCommit:(NSString *)app
170
77
  dbURL:(NSString *)dbURL
171
78
  transactionId:(double)transactionId
172
79
  updates:(NSDictionary *)updates {
173
- __block NSMutableDictionary *transactionState;
174
-
175
- dispatch_sync(_transactionQueue, ^{
176
- transactionState = transactions[[@(transactionId) stringValue]];
177
- });
178
-
179
- if (!transactionState) {
180
- NSLog(@"tryCommitTransaction for unknown ID %@", @(transactionId));
181
- return;
182
- }
183
-
184
- BOOL abort = [[updates valueForKey:@"abort"] boolValue];
185
-
186
- if (abort) {
187
- [transactionState setValue:@true forKey:@"abort"];
188
- } else {
189
- id newValue = [updates valueForKey:@"value"];
190
- [transactionState setValue:newValue forKey:@"value"];
191
- }
192
-
193
- dispatch_semaphore_signal([transactionState valueForKey:@"semaphore"]);
80
+ [RNFBDatabaseTransactionHelper transactionTryCommit:app
81
+ dbURL:dbURL
82
+ transactionId:transactionId
83
+ updates:updates];
194
84
  }
195
85
 
196
86
  @end
package/lib/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '26.0.0';
2
+ export const version = '26.1.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-firebase/database",
3
- "version": "26.0.0",
3
+ "version": "26.1.0",
4
4
  "author": "Invertase <oss@invertase.io> (http://invertase.io)",
5
5
  "description": "React Native Firebase - The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON and synchronized in realtime to every connected client. React Native Firebase provides native integration with the Android & iOS Firebase SDKs, supporting both realtime data sync and offline capabilities.",
6
6
  "main": "./dist/module/index.js",
@@ -47,10 +47,10 @@
47
47
  "realtome database"
48
48
  ],
49
49
  "peerDependencies": {
50
- "@react-native-firebase/app": "26.0.0"
50
+ "@react-native-firebase/app": "26.1.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@react-native-firebase/app": "26.0.0",
53
+ "@react-native-firebase/app": "26.1.0",
54
54
  "react-native-builder-bob": "^0.41.0"
55
55
  },
56
56
  "publishConfig": {
@@ -88,5 +88,5 @@
88
88
  "node_modules/",
89
89
  "dist/"
90
90
  ],
91
- "gitHead": "2a360acb2aebdd39dd40e31be386b30697270626"
91
+ "gitHead": "59d053eca14ab8aa80e5ac76887014925c67e52b"
92
92
  }