@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.
- package/CHANGELOG.md +6 -0
- package/RNFBDatabase.podspec +2 -1
- package/dist/module/version.js +1 -1
- package/dist/typescript/lib/index.d.ts +1 -1
- package/dist/typescript/lib/version.d.ts +1 -1
- package/ios/RNFBDatabase/RNFBDatabaseCommon.h +13 -6
- package/ios/RNFBDatabase/RNFBDatabaseCommon.m +2 -10
- package/ios/RNFBDatabase/RNFBDatabaseConstants.h +25 -0
- package/ios/RNFBDatabase/RNFBDatabaseModule.mm +14 -24
- package/ios/RNFBDatabase/RNFBDatabaseModuleHelper.h +39 -0
- package/ios/RNFBDatabase/RNFBDatabaseModuleHelper.m +64 -0
- package/ios/RNFBDatabase/RNFBDatabaseOnDisconnectHelper.h +59 -0
- package/ios/RNFBDatabase/RNFBDatabaseOnDisconnectHelper.m +136 -0
- package/ios/RNFBDatabase/RNFBDatabaseOnDisconnectModule.mm +35 -71
- package/ios/RNFBDatabase/RNFBDatabaseQuery.h +11 -0
- package/ios/RNFBDatabase/RNFBDatabaseQueryHelper.h +49 -0
- package/ios/RNFBDatabase/RNFBDatabaseQueryHelper.m +240 -0
- package/ios/RNFBDatabase/RNFBDatabaseQueryModule.h +5 -1
- package/ios/RNFBDatabase/RNFBDatabaseQueryModule.mm +25 -181
- package/ios/RNFBDatabase/RNFBDatabaseQueue.h +29 -0
- package/ios/RNFBDatabase/RNFBDatabaseQueue.m +31 -0
- package/ios/RNFBDatabase/RNFBDatabaseReferenceHelper.h +59 -0
- package/ios/RNFBDatabase/RNFBDatabaseReferenceHelper.m +136 -0
- package/ios/RNFBDatabase/RNFBDatabaseReferenceModule.mm +32 -70
- package/ios/RNFBDatabase/RNFBDatabaseTransactionHelper.h +38 -0
- package/ios/RNFBDatabase/RNFBDatabaseTransactionHelper.m +173 -0
- package/ios/RNFBDatabase/RNFBDatabaseTransactionModule.h +0 -1
- package/ios/RNFBDatabase/RNFBDatabaseTransactionModule.mm +17 -127
- package/lib/version.ts +1 -1
- package/package.json +4 -4
|
@@ -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 "
|
|
22
|
-
#import "RNFBDatabaseCommon.h"
|
|
20
|
+
#import "RNFBDatabaseOnDisconnectHelper.h"
|
|
23
21
|
#import "RNFBDatabaseOnDisconnectModule.h"
|
|
22
|
+
#import "RNFBDatabaseQueue.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 `RNFBDatabaseOnDisconnectHelper`.
|
|
28
|
+
|
|
26
29
|
@interface RNFBDatabaseOnDisconnectModule () <NativeRNFBTurboDatabaseOnDisconnectSpec,
|
|
27
30
|
RCTBridgeModule>
|
|
28
31
|
@end
|
|
@@ -43,7 +46,7 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseOnDisconnect);
|
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
- (dispatch_queue_t)methodQueue {
|
|
46
|
-
return [
|
|
49
|
+
return [RNFBDatabaseQueue getDispatchQueue];
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
#pragma mark -
|
|
@@ -54,19 +57,11 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseOnDisconnect);
|
|
|
54
57
|
path:(NSString *)path
|
|
55
58
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
56
59
|
reject:(RCTPromiseRejectBlock)reject {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
[firDatabaseReference
|
|
63
|
-
cancelDisconnectOperationsWithCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
|
|
64
|
-
if (error != nil) {
|
|
65
|
-
[RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
|
|
66
|
-
} else {
|
|
67
|
-
resolve([NSNull null]);
|
|
68
|
-
}
|
|
69
|
-
}];
|
|
60
|
+
[RNFBDatabaseOnDisconnectHelper onDisconnectCancel:app
|
|
61
|
+
dbURL:dbURL
|
|
62
|
+
path:path
|
|
63
|
+
resolve:resolve
|
|
64
|
+
reject:reject];
|
|
70
65
|
}
|
|
71
66
|
|
|
72
67
|
- (void)onDisconnectRemove:(NSString *)app
|
|
@@ -74,19 +69,11 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseOnDisconnect);
|
|
|
74
69
|
path:(NSString *)path
|
|
75
70
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
76
71
|
reject:(RCTPromiseRejectBlock)reject {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
[firDatabaseReference
|
|
83
|
-
onDisconnectRemoveValueWithCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
|
|
84
|
-
if (error != nil) {
|
|
85
|
-
[RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
|
|
86
|
-
} else {
|
|
87
|
-
resolve([NSNull null]);
|
|
88
|
-
}
|
|
89
|
-
}];
|
|
72
|
+
[RNFBDatabaseOnDisconnectHelper onDisconnectRemove:app
|
|
73
|
+
dbURL:dbURL
|
|
74
|
+
path:path
|
|
75
|
+
resolve:resolve
|
|
76
|
+
reject:reject];
|
|
90
77
|
}
|
|
91
78
|
|
|
92
79
|
- (void)onDisconnectSet:(NSString *)app
|
|
@@ -95,19 +82,12 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseOnDisconnect);
|
|
|
95
82
|
props:(NSDictionary *)props
|
|
96
83
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
97
84
|
reject:(RCTPromiseRejectBlock)reject {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
|
|
105
|
-
if (error != nil) {
|
|
106
|
-
[RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
|
|
107
|
-
} else {
|
|
108
|
-
resolve([NSNull null]);
|
|
109
|
-
}
|
|
110
|
-
}];
|
|
85
|
+
[RNFBDatabaseOnDisconnectHelper onDisconnectSet:app
|
|
86
|
+
dbURL:dbURL
|
|
87
|
+
path:path
|
|
88
|
+
props:props
|
|
89
|
+
resolve:resolve
|
|
90
|
+
reject:reject];
|
|
111
91
|
}
|
|
112
92
|
|
|
113
93
|
- (void)onDisconnectSetWithPriority:(NSString *)app
|
|
@@ -116,20 +96,12 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseOnDisconnect);
|
|
|
116
96
|
props:(NSDictionary *)props
|
|
117
97
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
118
98
|
reject:(RCTPromiseRejectBlock)reject {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
andPriority:[props valueForKey:@"priority"]
|
|
126
|
-
withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
|
|
127
|
-
if (error != nil) {
|
|
128
|
-
[RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
|
|
129
|
-
} else {
|
|
130
|
-
resolve([NSNull null]);
|
|
131
|
-
}
|
|
132
|
-
}];
|
|
99
|
+
[RNFBDatabaseOnDisconnectHelper onDisconnectSetWithPriority:app
|
|
100
|
+
dbURL:dbURL
|
|
101
|
+
path:path
|
|
102
|
+
props:props
|
|
103
|
+
resolve:resolve
|
|
104
|
+
reject:reject];
|
|
133
105
|
}
|
|
134
106
|
|
|
135
107
|
- (void)onDisconnectUpdate:(NSString *)app
|
|
@@ -138,20 +110,12 @@ RCT_EXPORT_MODULE(NativeRNFBTurboDatabaseOnDisconnect);
|
|
|
138
110
|
props:(NSDictionary *)props
|
|
139
111
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
140
112
|
reject:(RCTPromiseRejectBlock)reject {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
|
|
148
|
-
if (error != nil) {
|
|
149
|
-
[RNFBDatabaseCommon promiseRejectDatabaseException:reject
|
|
150
|
-
error:error];
|
|
151
|
-
} else {
|
|
152
|
-
resolve([NSNull null]);
|
|
153
|
-
}
|
|
154
|
-
}];
|
|
113
|
+
[RNFBDatabaseOnDisconnectHelper onDisconnectUpdate:app
|
|
114
|
+
dbURL:dbURL
|
|
115
|
+
path:path
|
|
116
|
+
props:props
|
|
117
|
+
resolve:resolve
|
|
118
|
+
reject:reject];
|
|
155
119
|
}
|
|
156
120
|
|
|
157
121
|
@end
|
|
@@ -15,7 +15,18 @@
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
#if __has_include(<Firebase/Firebase.h>)
|
|
18
19
|
#import <Firebase/Firebase.h>
|
|
20
|
+
#elif __has_include(<FirebaseDatabase/FirebaseDatabase-Swift.h>)
|
|
21
|
+
// SPM: the declared product is the thin Swift wrapper `FirebaseDatabase`
|
|
22
|
+
// (which depends on `FirebaseDatabaseInternal`, not exposed to us directly).
|
|
23
|
+
// Its generated ObjC interface header is what's importable here.
|
|
24
|
+
#import <FirebaseCore/FirebaseCore.h>
|
|
25
|
+
#import <FirebaseDatabase/FirebaseDatabase-Swift.h>
|
|
26
|
+
#else
|
|
27
|
+
@import FirebaseCore;
|
|
28
|
+
@import FirebaseDatabaseInternal;
|
|
29
|
+
#endif
|
|
19
30
|
#import <React/RCTBridgeModule.h>
|
|
20
31
|
|
|
21
32
|
@interface RNFBDatabaseQuery : NSObject
|
|
@@ -0,0 +1,49 @@
|
|
|
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 `FIRDatabaseQuery`/`FIRDataSnapshot` calls and the query
|
|
23
|
+
// listener bookkeeping for RNFBDatabaseQueryModule.
|
|
24
|
+
@interface RNFBDatabaseQueryHelper : NSObject
|
|
25
|
+
|
|
26
|
+
+ (void)once:(NSString *)app
|
|
27
|
+
dbURL:(NSString *)dbURL
|
|
28
|
+
path:(NSString *)path
|
|
29
|
+
modifiers:(NSArray *)modifiers
|
|
30
|
+
eventType:(NSString *)eventType
|
|
31
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
32
|
+
reject:(RCTPromiseRejectBlock)reject;
|
|
33
|
+
|
|
34
|
+
+ (void)on:(NSString *)app dbURL:(NSString *)dbURL props:(NSDictionary *)props;
|
|
35
|
+
|
|
36
|
+
+ (void)off:(NSString *)queryKey eventRegistrationKey:(NSString *)eventRegistrationKey;
|
|
37
|
+
|
|
38
|
+
+ (void)keepSynced:(NSString *)app
|
|
39
|
+
dbURL:(NSString *)dbURL
|
|
40
|
+
key:(NSString *)key
|
|
41
|
+
path:(NSString *)path
|
|
42
|
+
modifiers:(NSArray *)modifiers
|
|
43
|
+
enabled:(BOOL)value
|
|
44
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
45
|
+
reject:(RCTPromiseRejectBlock)reject;
|
|
46
|
+
|
|
47
|
+
+ (void)invalidate;
|
|
48
|
+
|
|
49
|
+
@end
|
|
@@ -0,0 +1,240 @@
|
|
|
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 "RNFBDatabaseQuery.h"
|
|
28
|
+
#import "RNFBDatabaseQueryHelper.h"
|
|
29
|
+
#import "RNFBRCTEventEmitter.h"
|
|
30
|
+
|
|
31
|
+
static __strong NSMutableDictionary *queryDictionary;
|
|
32
|
+
static NSString *const RNFB_DATABASE_SYNC = @"database_sync_event";
|
|
33
|
+
|
|
34
|
+
@implementation RNFBDatabaseQueryHelper
|
|
35
|
+
|
|
36
|
+
+ (NSMutableDictionary *)queryDictionary {
|
|
37
|
+
static dispatch_once_t onceToken;
|
|
38
|
+
dispatch_once(&onceToken, ^{
|
|
39
|
+
queryDictionary = [[NSMutableDictionary alloc] init];
|
|
40
|
+
});
|
|
41
|
+
return queryDictionary;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
+ (void)invalidate {
|
|
45
|
+
NSMutableDictionary *queries = [self queryDictionary];
|
|
46
|
+
NSArray *queryKeys = [queries allKeys];
|
|
47
|
+
for (NSString *key in queryKeys) {
|
|
48
|
+
RNFBDatabaseQuery *query = queries[key];
|
|
49
|
+
[query removeAllEventListeners];
|
|
50
|
+
[queries removeObjectForKey:key];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
+ (RNFBDatabaseQuery *)getDatabaseQueryInstance:(FIRDatabaseReference *)reference
|
|
55
|
+
modifiers:(NSArray *)modifiers {
|
|
56
|
+
return [[RNFBDatabaseQuery alloc] initWithReferenceAndModifiers:reference modifiers:modifiers];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
+ (RNFBDatabaseQuery *)getDatabaseQueryInstance:(NSString *)key
|
|
60
|
+
reference:(FIRDatabaseReference *)reference
|
|
61
|
+
modifiers:(NSArray *)modifiers {
|
|
62
|
+
NSMutableDictionary *queries = [self queryDictionary];
|
|
63
|
+
RNFBDatabaseQuery *cachedQuery = queries[key];
|
|
64
|
+
|
|
65
|
+
if (cachedQuery != nil) {
|
|
66
|
+
return cachedQuery;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
RNFBDatabaseQuery *query = [[RNFBDatabaseQuery alloc] initWithReferenceAndModifiers:reference
|
|
70
|
+
modifiers:modifiers];
|
|
71
|
+
|
|
72
|
+
queries[key] = query;
|
|
73
|
+
return query;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
+ (void)addOnceEventListener:(RNFBDatabaseQuery *)databaseQuery
|
|
77
|
+
eventType:(NSString *)eventType
|
|
78
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
79
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
80
|
+
FIRDataEventType firDataEventType =
|
|
81
|
+
(FIRDataEventType)[RNFBDatabaseCommon getEventTypeFromName:eventType];
|
|
82
|
+
|
|
83
|
+
id andPreviousSiblingKeyWithBlock =
|
|
84
|
+
^(FIRDataSnapshot *_Nonnull dataSnapshot, NSString *_Nullable previousChildName) {
|
|
85
|
+
NSDictionary *data;
|
|
86
|
+
if ([eventType isEqualToString:@"value"]) {
|
|
87
|
+
data = [RNFBDatabaseCommon snapshotToDictionary:dataSnapshot];
|
|
88
|
+
} else {
|
|
89
|
+
data = [RNFBDatabaseCommon snapshotWithPreviousChildToDictionary:dataSnapshot
|
|
90
|
+
previousChildName:previousChildName];
|
|
91
|
+
}
|
|
92
|
+
resolve(data);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
id errorBlock = ^(NSError *_Nonnull error) {
|
|
96
|
+
[RNFBDatabaseCommon promiseRejectDatabaseException:reject error:error];
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
[databaseQuery.query observeSingleEventOfType:firDataEventType
|
|
100
|
+
andPreviousSiblingKeyWithBlock:andPreviousSiblingKeyWithBlock
|
|
101
|
+
withCancelBlock:errorBlock];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
+ (void)handleDatabaseEvent:(NSString *)key
|
|
105
|
+
eventType:(NSString *)eventType
|
|
106
|
+
registration:(NSDictionary *)registration
|
|
107
|
+
snapshot:(FIRDataSnapshot *)dataSnapshot
|
|
108
|
+
previousChildName:(NSString *)previousChildName {
|
|
109
|
+
NSDictionary *data;
|
|
110
|
+
if ([eventType isEqualToString:@"value"]) {
|
|
111
|
+
data = [RNFBDatabaseCommon snapshotToDictionary:dataSnapshot];
|
|
112
|
+
} else {
|
|
113
|
+
data = [RNFBDatabaseCommon snapshotWithPreviousChildToDictionary:dataSnapshot
|
|
114
|
+
previousChildName:previousChildName];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
[[RNFBRCTEventEmitter shared] sendEventWithName:RNFB_DATABASE_SYNC
|
|
118
|
+
body:@{
|
|
119
|
+
@"body" : @{
|
|
120
|
+
@"data" : data,
|
|
121
|
+
@"key" : key,
|
|
122
|
+
@"eventType" : eventType,
|
|
123
|
+
@"registration" : registration,
|
|
124
|
+
}
|
|
125
|
+
}];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
+ (void)handleDatabaseEventError:(NSString *)key
|
|
129
|
+
registration:(NSDictionary *)registration
|
|
130
|
+
error:(NSError *)error {
|
|
131
|
+
NSArray *codeAndMessage = [RNFBDatabaseCommon getCodeAndMessage:error];
|
|
132
|
+
[[RNFBRCTEventEmitter shared] sendEventWithName:RNFB_DATABASE_SYNC
|
|
133
|
+
body:@{
|
|
134
|
+
@"body" : @{
|
|
135
|
+
@"key" : key,
|
|
136
|
+
@"error" : @{
|
|
137
|
+
@"code" : codeAndMessage[0],
|
|
138
|
+
@"message" : codeAndMessage[1],
|
|
139
|
+
},
|
|
140
|
+
@"registration" : registration,
|
|
141
|
+
}
|
|
142
|
+
}];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
+ (void)addEventListener:(RNFBDatabaseQuery *)databaseQuery
|
|
146
|
+
eventType:(NSString *)eventType
|
|
147
|
+
registration:(NSDictionary *)registration {
|
|
148
|
+
NSString *eventRegistrationKey = registration[@"eventRegistrationKey"];
|
|
149
|
+
|
|
150
|
+
if (![databaseQuery hasEventListener:eventRegistrationKey]) {
|
|
151
|
+
id andPreviousSiblingKeyWithBlock =
|
|
152
|
+
^(FIRDataSnapshot *_Nonnull dataSnapshot, NSString *_Nullable previousChildName) {
|
|
153
|
+
[self handleDatabaseEvent:eventRegistrationKey
|
|
154
|
+
eventType:eventType
|
|
155
|
+
registration:registration
|
|
156
|
+
snapshot:dataSnapshot
|
|
157
|
+
previousChildName:previousChildName];
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
id errorBlock = ^(NSError *_Nonnull error) {
|
|
161
|
+
[databaseQuery removeEventListener:eventRegistrationKey];
|
|
162
|
+
[self handleDatabaseEventError:eventRegistrationKey registration:registration error:error];
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
FIRDataEventType firDataEventType =
|
|
166
|
+
(FIRDataEventType)[RNFBDatabaseCommon getEventTypeFromName:eventType];
|
|
167
|
+
FIRDatabaseHandle handle = [databaseQuery.query observeEventType:firDataEventType
|
|
168
|
+
andPreviousSiblingKeyWithBlock:andPreviousSiblingKeyWithBlock
|
|
169
|
+
withCancelBlock:errorBlock];
|
|
170
|
+
[databaseQuery addEventListener:eventRegistrationKey handle:handle];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
+ (void)once:(NSString *)app
|
|
175
|
+
dbURL:(NSString *)dbURL
|
|
176
|
+
path:(NSString *)path
|
|
177
|
+
modifiers:(NSArray *)modifiers
|
|
178
|
+
eventType:(NSString *)eventType
|
|
179
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
180
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
181
|
+
FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
|
|
182
|
+
FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
|
|
183
|
+
FIRDatabaseReference *firDatabaseReference =
|
|
184
|
+
[RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
|
|
185
|
+
RNFBDatabaseQuery *databaseQuery = [self getDatabaseQueryInstance:firDatabaseReference
|
|
186
|
+
modifiers:modifiers];
|
|
187
|
+
|
|
188
|
+
[self addOnceEventListener:databaseQuery eventType:eventType resolve:resolve reject:reject];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
+ (void)on:(NSString *)app dbURL:(NSString *)dbURL props:(NSDictionary *)props {
|
|
192
|
+
NSString *key = [props valueForKey:@"key"];
|
|
193
|
+
NSString *path = [props valueForKey:@"path"];
|
|
194
|
+
NSString *eventType = [props valueForKey:@"eventType"];
|
|
195
|
+
NSArray *modifiers = [props valueForKey:@"modifiers"];
|
|
196
|
+
NSDictionary *registration = [props valueForKey:@"registration"];
|
|
197
|
+
|
|
198
|
+
FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
|
|
199
|
+
FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
|
|
200
|
+
FIRDatabaseReference *firDatabaseReference =
|
|
201
|
+
[RNFBDatabaseCommon getReferenceForDatabase:key firebaseDatabase:firDatabase path:path];
|
|
202
|
+
RNFBDatabaseQuery *databaseQuery = [self getDatabaseQueryInstance:key
|
|
203
|
+
reference:firDatabaseReference
|
|
204
|
+
modifiers:modifiers];
|
|
205
|
+
[self addEventListener:databaseQuery eventType:eventType registration:registration];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
+ (void)off:(NSString *)queryKey eventRegistrationKey:(NSString *)eventRegistrationKey {
|
|
209
|
+
NSMutableDictionary *queries = [self queryDictionary];
|
|
210
|
+
RNFBDatabaseQuery *databaseQuery = queries[queryKey];
|
|
211
|
+
|
|
212
|
+
if (databaseQuery != nil) {
|
|
213
|
+
[databaseQuery removeEventListener:eventRegistrationKey];
|
|
214
|
+
|
|
215
|
+
if (![databaseQuery hasListeners]) {
|
|
216
|
+
[queries removeObjectForKey:queryKey];
|
|
217
|
+
[RNFBDatabaseCommon removeReferenceByKey:queryKey];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
+ (void)keepSynced:(NSString *)app
|
|
223
|
+
dbURL:(NSString *)dbURL
|
|
224
|
+
key:(NSString *)key
|
|
225
|
+
path:(NSString *)path
|
|
226
|
+
modifiers:(NSArray *)modifiers
|
|
227
|
+
enabled:(BOOL)value
|
|
228
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
229
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
230
|
+
FIRApp *firebaseApp = [RCTConvert firAppFromString:app];
|
|
231
|
+
FIRDatabase *firDatabase = [RNFBDatabaseCommon getDatabaseForApp:firebaseApp dbURL:dbURL];
|
|
232
|
+
FIRDatabaseReference *firDatabaseReference =
|
|
233
|
+
[RNFBDatabaseCommon getReferenceForDatabase:firDatabase path:path];
|
|
234
|
+
RNFBDatabaseQuery *databaseQuery = [self getDatabaseQueryInstance:firDatabaseReference
|
|
235
|
+
modifiers:modifiers];
|
|
236
|
+
[databaseQuery.query keepSynced:value];
|
|
237
|
+
resolve([NSNull null]);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
@end
|
|
@@ -15,9 +15,13 @@
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
#import <Firebase/Firebase.h>
|
|
19
18
|
#import <Foundation/Foundation.h>
|
|
20
19
|
#import <React/RCTBridgeModule.h>
|
|
21
20
|
|
|
21
|
+
// NOTE: This header must stay Firebase-free. It is imported by
|
|
22
|
+
// RNFBDatabaseQueryModule.mm, and `FirebaseDatabase` is a Swift-only SPM
|
|
23
|
+
// product whose `@import` cannot be used from Objective-C++ (.mm) files
|
|
24
|
+
// when C++ modules are disabled. See RNFBDatabaseModule.mm for details.
|
|
25
|
+
|
|
22
26
|
@interface RNFBDatabaseQueryModule : NSObject <RCTBridgeModule>
|
|
23
27
|
@end
|