2017-05-15 12:27:07 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright 2017 Google
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#import "FIRDatabaseReference.h"
|
2019-08-05 13:27:47 -07:00
|
|
|
#import "FIRDatabase.h"
|
2017-05-15 12:27:07 -07:00
|
|
|
#import "FIRDatabaseConfig.h"
|
|
|
|
|
#import "FIRDatabaseConfig_Private.h"
|
2019-08-05 13:27:47 -07:00
|
|
|
#import "FIRDatabaseQuery_Private.h"
|
|
|
|
|
#import "FIRDatabaseReference_Private.h"
|
|
|
|
|
#import "FNextPushId.h"
|
2017-05-15 12:27:07 -07:00
|
|
|
#import "FQueryParams.h"
|
2019-08-05 13:27:47 -07:00
|
|
|
#import "FSnapshotUtilities.h"
|
|
|
|
|
#import "FStringUtilities.h"
|
|
|
|
|
#import "FUtilities.h"
|
|
|
|
|
#import "FValidation.h"
|
|
|
|
|
#import <FirebaseCore/FIRApp.h>
|
|
|
|
|
#import <FirebaseCore/FIROptions.h>
|
2017-05-15 12:27:07 -07:00
|
|
|
|
|
|
|
|
@implementation FIRDatabaseReference
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
#pragma mark Constructors
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (id)initWithConfig:(FIRDatabaseConfig *)config {
|
|
|
|
|
FParsedUrl *parsedUrl =
|
|
|
|
|
[FUtilities parseUrl:[[FIRApp defaultApp] options].databaseURL];
|
2017-05-15 12:27:07 -07:00
|
|
|
[FValidation validateFrom:@"initWithUrl:" validURL:parsedUrl];
|
2019-08-05 13:27:47 -07:00
|
|
|
return [self initWithRepo:[FRepoManager getRepo:parsedUrl.repoInfo
|
|
|
|
|
config:config]
|
|
|
|
|
path:parsedUrl.path];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (id)initWithRepo:(FRepo *)repo path:(FPath *)path {
|
2017-05-15 12:27:07 -07:00
|
|
|
return [super initWithRepo:repo
|
|
|
|
|
path:path
|
|
|
|
|
params:[FQueryParams defaultInstance]
|
|
|
|
|
orderByCalled:NO
|
|
|
|
|
priorityMethodCalled:NO];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
#pragma mark Ancillary methods
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (nullable NSString *)key {
|
|
|
|
|
if ([self.path isEmpty]) {
|
2017-05-15 12:27:07 -07:00
|
|
|
return nil;
|
2019-08-05 13:27:47 -07:00
|
|
|
} else {
|
2017-05-15 12:27:07 -07:00
|
|
|
return [self.path getBack];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (FIRDatabase *)database {
|
2017-05-15 12:27:07 -07:00
|
|
|
return self.repo.database;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (FIRDatabaseReference *)parent {
|
|
|
|
|
FPath *parentPath = [self.path parent];
|
|
|
|
|
FIRDatabaseReference *parent = nil;
|
|
|
|
|
if (parentPath != nil) {
|
|
|
|
|
parent = [[FIRDatabaseReference alloc] initWithRepo:self.repo
|
|
|
|
|
path:parentPath];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
return parent;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (NSString *)URL {
|
|
|
|
|
FIRDatabaseReference *parent = [self parent];
|
|
|
|
|
return parent == nil
|
|
|
|
|
? [self.repo description]
|
|
|
|
|
: [NSString
|
|
|
|
|
stringWithFormat:@"%@/%@", [parent description],
|
|
|
|
|
[FStringUtilities urlEncoded:self.key]];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (NSString *)description {
|
2017-05-15 12:27:07 -07:00
|
|
|
return [self URL];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (FIRDatabaseReference *)root {
|
|
|
|
|
return [[FIRDatabaseReference alloc]
|
|
|
|
|
initWithRepo:self.repo
|
|
|
|
|
path:[[FPath alloc] initWith:@""]];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
#pragma mark Child methods
|
|
|
|
|
|
|
|
|
|
- (FIRDatabaseReference *)child:(NSString *)pathString {
|
|
|
|
|
if ([self.path getFront] == nil) {
|
|
|
|
|
// we're at the root
|
|
|
|
|
[FValidation validateFrom:@"child:" validRootPathString:pathString];
|
|
|
|
|
} else {
|
|
|
|
|
[FValidation validateFrom:@"child:" validPathString:pathString];
|
|
|
|
|
}
|
2019-08-05 13:27:47 -07:00
|
|
|
FPath *path = [self.path childFromString:pathString];
|
|
|
|
|
FIRDatabaseReference *firebaseRef =
|
|
|
|
|
[[FIRDatabaseReference alloc] initWithRepo:self.repo path:path];
|
2017-05-15 12:27:07 -07:00
|
|
|
return firebaseRef;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (FIRDatabaseReference *)childByAutoId {
|
2017-05-15 12:27:07 -07:00
|
|
|
[FValidation validateFrom:@"childByAutoId:" writablePath:self.path];
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
NSString *name = [FNextPushId get:self.repo.serverTime];
|
2017-05-15 12:27:07 -07:00
|
|
|
return [self child:name];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
#pragma mark Basic write methods
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)setValue:(id)value {
|
|
|
|
|
[self setValueInternal:value
|
|
|
|
|
andPriority:nil
|
|
|
|
|
withCompletionBlock:nil
|
|
|
|
|
from:@"setValue:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)setValue:(id)value withCompletionBlock:(fbt_void_nserror_ref)block {
|
|
|
|
|
[self setValueInternal:value
|
|
|
|
|
andPriority:nil
|
|
|
|
|
withCompletionBlock:block
|
|
|
|
|
from:@"setValue:withCompletionBlock:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)setValue:(id)value andPriority:(id)priority {
|
|
|
|
|
[self setValueInternal:value
|
|
|
|
|
andPriority:priority
|
|
|
|
|
withCompletionBlock:nil
|
|
|
|
|
from:@"setValue:andPriority:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)setValue:(id)value
|
|
|
|
|
andPriority:(id)priority
|
|
|
|
|
withCompletionBlock:(fbt_void_nserror_ref)block {
|
|
|
|
|
[self setValueInternal:value
|
|
|
|
|
andPriority:priority
|
|
|
|
|
withCompletionBlock:block
|
|
|
|
|
from:@"setValue:andPriority:withCompletionBlock:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)setValueInternal:(id)value
|
|
|
|
|
andPriority:(id)priority
|
|
|
|
|
withCompletionBlock:(fbt_void_nserror_ref)block
|
|
|
|
|
from:(NSString *)fn {
|
2017-05-15 12:27:07 -07:00
|
|
|
[FValidation validateFrom:fn writablePath:self.path];
|
|
|
|
|
|
|
|
|
|
fbt_void_nserror_ref userCallback = [block copy];
|
2019-08-05 13:27:47 -07:00
|
|
|
id<FNode> newNode = [FSnapshotUtilities nodeFrom:value
|
|
|
|
|
priority:priority
|
|
|
|
|
withValidationFrom:fn];
|
2017-05-15 12:27:07 -07:00
|
|
|
|
|
|
|
|
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
|
2019-08-05 13:27:47 -07:00
|
|
|
[self.repo set:self.path withNode:newNode withCallback:userCallback];
|
2017-05-15 12:27:07 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)removeValue {
|
|
|
|
|
[self setValueInternal:nil
|
|
|
|
|
andPriority:nil
|
|
|
|
|
withCompletionBlock:nil
|
|
|
|
|
from:@"removeValue:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)removeValueWithCompletionBlock:(fbt_void_nserror_ref)block {
|
|
|
|
|
[self setValueInternal:nil
|
|
|
|
|
andPriority:nil
|
|
|
|
|
withCompletionBlock:block
|
|
|
|
|
from:@"removeValueWithCompletionBlock:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)setPriority:(id)priority {
|
|
|
|
|
[self setPriorityInternal:priority
|
|
|
|
|
withCompletionBlock:nil
|
|
|
|
|
from:@"setPriority:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)setPriority:(id)priority
|
|
|
|
|
withCompletionBlock:(fbt_void_nserror_ref)block {
|
2017-05-15 12:27:07 -07:00
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
[self setPriorityInternal:priority
|
|
|
|
|
withCompletionBlock:block
|
|
|
|
|
from:@"setPriority:withCompletionBlock:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)setPriorityInternal:(id)priority
|
|
|
|
|
withCompletionBlock:(fbt_void_nserror_ref)block
|
|
|
|
|
from:(NSString *)fn {
|
2017-05-15 12:27:07 -07:00
|
|
|
[FValidation validateFrom:fn writablePath:self.path];
|
|
|
|
|
|
|
|
|
|
fbt_void_nserror_ref userCallback = [block copy];
|
|
|
|
|
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
|
2019-08-05 13:27:47 -07:00
|
|
|
[self.repo set:[self.path childFromString:@".priority"]
|
|
|
|
|
withNode:[FSnapshotUtilities nodeFrom:priority]
|
|
|
|
|
withCallback:userCallback];
|
2017-05-15 12:27:07 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)updateChildValues:(NSDictionary *)values {
|
|
|
|
|
[self updateChildValuesInternal:values
|
|
|
|
|
withCompletionBlock:nil
|
|
|
|
|
from:@"updateChildValues:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)updateChildValues:(NSDictionary *)values
|
|
|
|
|
withCompletionBlock:(fbt_void_nserror_ref)block {
|
|
|
|
|
[self updateChildValuesInternal:values
|
|
|
|
|
withCompletionBlock:block
|
|
|
|
|
from:@"updateChildValues:withCompletionBlock:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)updateChildValuesInternal:(NSDictionary *)values
|
|
|
|
|
withCompletionBlock:(fbt_void_nserror_ref)block
|
|
|
|
|
from:(NSString *)fn {
|
2017-05-15 12:27:07 -07:00
|
|
|
[FValidation validateFrom:fn writablePath:self.path];
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
FCompoundWrite *merge =
|
|
|
|
|
[FSnapshotUtilities compoundWriteFromDictionary:values
|
|
|
|
|
withValidationFrom:fn];
|
2017-05-15 12:27:07 -07:00
|
|
|
|
|
|
|
|
fbt_void_nserror_ref userCallback = [block copy];
|
|
|
|
|
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
|
2019-08-05 13:27:47 -07:00
|
|
|
[self.repo update:self.path withNodes:merge withCallback:userCallback];
|
2017-05-15 12:27:07 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
#pragma mark Disconnect Operations
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)onDisconnectSetValue:(id)value {
|
|
|
|
|
[self onDisconnectSetValueInternal:value
|
|
|
|
|
andPriority:nil
|
|
|
|
|
withCompletionBlock:nil
|
|
|
|
|
from:@"onDisconnectSetValue:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)onDisconnectSetValue:(id)value
|
|
|
|
|
withCompletionBlock:(fbt_void_nserror_ref)block {
|
|
|
|
|
[self onDisconnectSetValueInternal:value
|
|
|
|
|
andPriority:nil
|
|
|
|
|
withCompletionBlock:block
|
|
|
|
|
from:@"onDisconnectSetValue:"
|
|
|
|
|
@"withCompletionBlock:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)onDisconnectSetValue:(id)value andPriority:(id)priority {
|
|
|
|
|
[self onDisconnectSetValueInternal:value
|
|
|
|
|
andPriority:priority
|
|
|
|
|
withCompletionBlock:nil
|
|
|
|
|
from:@"onDisconnectSetValue:andPriority:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)onDisconnectSetValue:(id)value
|
|
|
|
|
andPriority:(id)priority
|
|
|
|
|
withCompletionBlock:(fbt_void_nserror_ref)block {
|
|
|
|
|
[self onDisconnectSetValueInternal:value
|
|
|
|
|
andPriority:priority
|
|
|
|
|
withCompletionBlock:block
|
|
|
|
|
from:@"onDisconnectSetValue:andPriority:"
|
|
|
|
|
@"withCompletionBlock:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)onDisconnectSetValueInternal:(id)value
|
|
|
|
|
andPriority:(id)priority
|
|
|
|
|
withCompletionBlock:(fbt_void_nserror_ref)block
|
|
|
|
|
from:(NSString *)fn {
|
2017-05-15 12:27:07 -07:00
|
|
|
[FValidation validateFrom:fn writablePath:self.path];
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
id<FNode> newNodeUnresolved = [FSnapshotUtilities nodeFrom:value
|
|
|
|
|
priority:priority
|
|
|
|
|
withValidationFrom:fn];
|
2017-05-15 12:27:07 -07:00
|
|
|
|
|
|
|
|
fbt_void_nserror_ref userCallback = [block copy];
|
|
|
|
|
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
|
2019-08-05 13:27:47 -07:00
|
|
|
[self.repo onDisconnectSet:self.path
|
|
|
|
|
withNode:newNodeUnresolved
|
|
|
|
|
withCallback:userCallback];
|
2017-05-15 12:27:07 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)onDisconnectRemoveValue {
|
|
|
|
|
[self onDisconnectSetValueInternal:nil
|
|
|
|
|
andPriority:nil
|
|
|
|
|
withCompletionBlock:nil
|
|
|
|
|
from:@"onDisconnectRemoveValue:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)onDisconnectRemoveValueWithCompletionBlock:(fbt_void_nserror_ref)block {
|
|
|
|
|
[self onDisconnectSetValueInternal:nil
|
|
|
|
|
andPriority:nil
|
|
|
|
|
withCompletionBlock:block
|
|
|
|
|
from:@"onDisconnectRemoveValueWithCompletionB"
|
|
|
|
|
@"lock:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)onDisconnectUpdateChildValues:(NSDictionary *)values {
|
|
|
|
|
[self
|
|
|
|
|
onDisconnectUpdateChildValuesInternal:values
|
|
|
|
|
withCompletionBlock:nil
|
|
|
|
|
from:
|
|
|
|
|
@"onDisconnectUpdateChildValues:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)onDisconnectUpdateChildValues:(NSDictionary *)values
|
|
|
|
|
withCompletionBlock:(fbt_void_nserror_ref)block {
|
|
|
|
|
[self onDisconnectUpdateChildValuesInternal:values
|
|
|
|
|
withCompletionBlock:block
|
|
|
|
|
from:@"onDisconnectUpdateChildValues"
|
|
|
|
|
@":withCompletionBlock:"];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)onDisconnectUpdateChildValuesInternal:(NSDictionary *)values
|
|
|
|
|
withCompletionBlock:(fbt_void_nserror_ref)block
|
|
|
|
|
from:(NSString *)fn {
|
2017-05-15 12:27:07 -07:00
|
|
|
[FValidation validateFrom:fn writablePath:self.path];
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
FCompoundWrite *merge =
|
|
|
|
|
[FSnapshotUtilities compoundWriteFromDictionary:values
|
|
|
|
|
withValidationFrom:fn];
|
2017-05-15 12:27:07 -07:00
|
|
|
|
|
|
|
|
fbt_void_nserror_ref userCallback = [block copy];
|
|
|
|
|
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
|
2019-08-05 13:27:47 -07:00
|
|
|
[self.repo onDisconnectUpdate:self.path
|
|
|
|
|
withNodes:merge
|
|
|
|
|
withCallback:userCallback];
|
2017-05-15 12:27:07 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)cancelDisconnectOperations {
|
2017-05-15 12:27:07 -07:00
|
|
|
[self cancelDisconnectOperationsWithCompletionBlock:nil];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)cancelDisconnectOperationsWithCompletionBlock:
|
|
|
|
|
(fbt_void_nserror_ref)block {
|
2017-05-15 12:27:07 -07:00
|
|
|
fbt_void_nserror_ref callback = nil;
|
|
|
|
|
if (block != nil) {
|
|
|
|
|
callback = [block copy];
|
|
|
|
|
}
|
|
|
|
|
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
|
2019-08-05 13:27:47 -07:00
|
|
|
[self.repo onDisconnectCancel:self.path withCallback:callback];
|
2017-05-15 12:27:07 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
#pragma mark Connection management methods
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
+ (void)goOffline {
|
2017-05-15 12:27:07 -07:00
|
|
|
[FRepoManager interruptAll];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
+ (void)goOnline {
|
2017-05-15 12:27:07 -07:00
|
|
|
[FRepoManager resumeAll];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
#pragma mark Data reading methods deferred to FQuery
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (FIRDatabaseHandle)observeEventType:(FIRDataEventType)eventType
|
|
|
|
|
withBlock:(fbt_void_datasnapshot)block {
|
|
|
|
|
return [self observeEventType:eventType
|
|
|
|
|
withBlock:block
|
|
|
|
|
withCancelBlock:nil];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (FIRDatabaseHandle)observeEventType:(FIRDataEventType)eventType
|
|
|
|
|
andPreviousSiblingKeyWithBlock:(fbt_void_datasnapshot_nsstring)block {
|
|
|
|
|
return [self observeEventType:eventType
|
|
|
|
|
andPreviousSiblingKeyWithBlock:block
|
|
|
|
|
withCancelBlock:nil];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (FIRDatabaseHandle)observeEventType:(FIRDataEventType)eventType
|
|
|
|
|
withBlock:(fbt_void_datasnapshot)block
|
|
|
|
|
withCancelBlock:(fbt_void_nserror)cancelBlock {
|
|
|
|
|
return [super observeEventType:eventType
|
|
|
|
|
withBlock:block
|
|
|
|
|
withCancelBlock:cancelBlock];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (FIRDatabaseHandle)observeEventType:(FIRDataEventType)eventType
|
|
|
|
|
andPreviousSiblingKeyWithBlock:(fbt_void_datasnapshot_nsstring)block
|
|
|
|
|
withCancelBlock:(fbt_void_nserror)cancelBlock {
|
|
|
|
|
return [super observeEventType:eventType
|
|
|
|
|
andPreviousSiblingKeyWithBlock:block
|
|
|
|
|
withCancelBlock:cancelBlock];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)removeObserverWithHandle:(FIRDatabaseHandle)handle {
|
2017-05-15 12:27:07 -07:00
|
|
|
[super removeObserverWithHandle:handle];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)removeAllObservers {
|
2017-05-15 12:27:07 -07:00
|
|
|
[super removeAllObservers];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)keepSynced:(BOOL)keepSynced {
|
2017-05-15 12:27:07 -07:00
|
|
|
[super keepSynced:keepSynced];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)observeSingleEventOfType:(FIRDataEventType)eventType
|
|
|
|
|
withBlock:(fbt_void_datasnapshot)block {
|
|
|
|
|
[self observeSingleEventOfType:eventType
|
|
|
|
|
withBlock:block
|
|
|
|
|
withCancelBlock:nil];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)observeSingleEventOfType:(FIRDataEventType)eventType
|
|
|
|
|
andPreviousSiblingKeyWithBlock:(fbt_void_datasnapshot_nsstring)block {
|
|
|
|
|
[self observeSingleEventOfType:eventType
|
|
|
|
|
andPreviousSiblingKeyWithBlock:block
|
|
|
|
|
withCancelBlock:nil];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)observeSingleEventOfType:(FIRDataEventType)eventType
|
|
|
|
|
withBlock:(fbt_void_datasnapshot)block
|
|
|
|
|
withCancelBlock:(fbt_void_nserror)cancelBlock {
|
|
|
|
|
[super observeSingleEventOfType:eventType
|
|
|
|
|
withBlock:block
|
|
|
|
|
withCancelBlock:cancelBlock];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)observeSingleEventOfType:(FIRDataEventType)eventType
|
|
|
|
|
andPreviousSiblingKeyWithBlock:(fbt_void_datasnapshot_nsstring)block
|
|
|
|
|
withCancelBlock:(fbt_void_nserror)cancelBlock {
|
|
|
|
|
[super observeSingleEventOfType:eventType
|
|
|
|
|
andPreviousSiblingKeyWithBlock:block
|
|
|
|
|
withCancelBlock:cancelBlock];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
#pragma mark Query methods
|
2019-08-05 13:27:47 -07:00
|
|
|
// These methods suppress warnings from having method definitions in
|
|
|
|
|
// FIRDatabaseReference.h for docs generation.
|
2017-05-15 12:27:07 -07:00
|
|
|
|
|
|
|
|
- (FIRDatabaseQuery *)queryLimitedToFirst:(NSUInteger)limit {
|
|
|
|
|
return [super queryLimitedToFirst:limit];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (FIRDatabaseQuery *)queryLimitedToLast:(NSUInteger)limit {
|
|
|
|
|
return [super queryLimitedToLast:limit];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (FIRDatabaseQuery *)queryOrderedByChild:(NSString *)key {
|
|
|
|
|
return [super queryOrderedByChild:key];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (FIRDatabaseQuery *)queryOrderedByKey {
|
2017-05-15 12:27:07 -07:00
|
|
|
return [super queryOrderedByKey];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (FIRDatabaseQuery *)queryOrderedByPriority {
|
2017-05-15 12:27:07 -07:00
|
|
|
return [super queryOrderedByPriority];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (FIRDatabaseQuery *)queryStartingAtValue:(id)startValue {
|
|
|
|
|
return [super queryStartingAtValue:startValue];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (FIRDatabaseQuery *)queryStartingAtValue:(id)startValue
|
|
|
|
|
childKey:(NSString *)childKey {
|
2017-05-15 12:27:07 -07:00
|
|
|
return [super queryStartingAtValue:startValue childKey:childKey];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (FIRDatabaseQuery *)queryEndingAtValue:(id)endValue {
|
|
|
|
|
return [super queryEndingAtValue:endValue];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (FIRDatabaseQuery *)queryEndingAtValue:(id)endValue
|
|
|
|
|
childKey:(NSString *)childKey {
|
2017-05-15 12:27:07 -07:00
|
|
|
return [super queryEndingAtValue:endValue childKey:childKey];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (FIRDatabaseQuery *)queryEqualToValue:(id)value {
|
|
|
|
|
return [super queryEqualToValue:value];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (FIRDatabaseQuery *)queryEqualToValue:(id)value
|
|
|
|
|
childKey:(NSString *)childKey {
|
2017-05-15 12:27:07 -07:00
|
|
|
return [super queryEqualToValue:value childKey:childKey];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
#pragma mark Transaction methods
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)runTransactionBlock:(fbt_transactionresult_mutabledata)block {
|
2017-05-15 12:27:07 -07:00
|
|
|
[FValidation validateFrom:@"runTransactionBlock:" writablePath:self.path];
|
|
|
|
|
[self runTransactionBlock:block andCompletionBlock:nil withLocalEvents:YES];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)runTransactionBlock:(fbt_transactionresult_mutabledata)update
|
|
|
|
|
andCompletionBlock:
|
|
|
|
|
(fbt_void_nserror_bool_datasnapshot)completionBlock {
|
|
|
|
|
[FValidation validateFrom:@"runTransactionBlock:andCompletionBlock:"
|
|
|
|
|
writablePath:self.path];
|
|
|
|
|
[self runTransactionBlock:update
|
|
|
|
|
andCompletionBlock:completionBlock
|
|
|
|
|
withLocalEvents:YES];
|
2017-05-15 12:27:07 -07:00
|
|
|
}
|
|
|
|
|
|
2019-08-05 13:27:47 -07:00
|
|
|
- (void)runTransactionBlock:(fbt_transactionresult_mutabledata)block
|
|
|
|
|
andCompletionBlock:(fbt_void_nserror_bool_datasnapshot)completionBlock
|
|
|
|
|
withLocalEvents:(BOOL)localEvents {
|
|
|
|
|
[FValidation
|
|
|
|
|
validateFrom:@"runTransactionBlock:andCompletionBlock:withLocalEvents:"
|
|
|
|
|
writablePath:self.path];
|
2017-05-15 12:27:07 -07:00
|
|
|
fbt_transactionresult_mutabledata updateCopy = [block copy];
|
|
|
|
|
fbt_void_nserror_bool_datasnapshot onCompleteCopy = [completionBlock copy];
|
|
|
|
|
dispatch_async([FIRDatabaseQuery sharedQueue], ^{
|
2019-08-05 13:27:47 -07:00
|
|
|
[self.repo startTransactionOnPath:self.path
|
|
|
|
|
update:updateCopy
|
|
|
|
|
onComplete:onCompleteCopy
|
|
|
|
|
withLocalEvents:localEvents];
|
2017-05-15 12:27:07 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|