aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source
diff options
context:
space:
mode:
authorGravatar Gil <mcg@google.com>2018-04-15 13:06:06 -0700
committerGravatar GitHub <noreply@github.com>2018-04-15 13:06:06 -0700
commit5368c9e22f9a6b427466e9422645d688953013c0 (patch)
tree96ce766691fb24ffc0382cac472945b2190ecabe /Firestore/Source
parent33b12f6c70729d56c6e6350d435559cec1c44c61 (diff)
Replace the `SetOptions` object with a simple boolean. (#1098)
Instead of calling `setData(["a": "b"], options: SetOptions.merge())` call `setData(["a": "b"], merge: true)`
Diffstat (limited to 'Firestore/Source')
-rw-r--r--Firestore/Source/API/FIRDocumentReference.mm16
-rw-r--r--Firestore/Source/API/FIRSetOptions+Internal.h33
-rw-r--r--Firestore/Source/API/FIRSetOptions.mm63
-rw-r--r--Firestore/Source/API/FIRTransaction.mm9
-rw-r--r--Firestore/Source/API/FIRWriteBatch.mm9
-rw-r--r--Firestore/Source/API/FSTUserDataConverter.h3
-rw-r--r--Firestore/Source/API/FSTUserDataConverter.mm7
-rw-r--r--Firestore/Source/Core/FSTTransaction.h1
-rw-r--r--Firestore/Source/Core/FSTTransaction.mm1
-rw-r--r--Firestore/Source/Public/FIRDocumentReference.h19
-rw-r--r--Firestore/Source/Public/FIRSetOptions.h46
-rw-r--r--Firestore/Source/Public/FIRTransaction.h11
-rw-r--r--Firestore/Source/Public/FIRWriteBatch.h11
-rw-r--r--Firestore/Source/Public/FirebaseFirestore.h1
14 files changed, 38 insertions, 192 deletions
diff --git a/Firestore/Source/API/FIRDocumentReference.mm b/Firestore/Source/API/FIRDocumentReference.mm
index d3a9295..2423472 100644
--- a/Firestore/Source/API/FIRDocumentReference.mm
+++ b/Firestore/Source/API/FIRDocumentReference.mm
@@ -28,7 +28,6 @@
#import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h"
#import "Firestore/Source/API/FIRFirestore+Internal.h"
#import "Firestore/Source/API/FIRListenerRegistration+Internal.h"
-#import "Firestore/Source/API/FIRSetOptions+Internal.h"
#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/Core/FSTEventManager.h"
#import "Firestore/Source/Core/FSTFirestoreClient.h"
@@ -117,24 +116,23 @@ NS_ASSUME_NONNULL_BEGIN
}
- (void)setData:(NSDictionary<NSString *, id> *)documentData {
- return [self setData:documentData options:[FIRSetOptions overwrite] completion:nil];
+ return [self setData:documentData merge:NO completion:nil];
}
-- (void)setData:(NSDictionary<NSString *, id> *)documentData options:(FIRSetOptions *)options {
- return [self setData:documentData options:options completion:nil];
+- (void)setData:(NSDictionary<NSString *, id> *)documentData merge:(BOOL)merge {
+ return [self setData:documentData merge:merge completion:nil];
}
- (void)setData:(NSDictionary<NSString *, id> *)documentData
completion:(nullable void (^)(NSError *_Nullable error))completion {
- return [self setData:documentData options:[FIRSetOptions overwrite] completion:completion];
+ return [self setData:documentData merge:NO completion:completion];
}
- (void)setData:(NSDictionary<NSString *, id> *)documentData
- options:(FIRSetOptions *)options
+ merge:(BOOL)merge
completion:(nullable void (^)(NSError *_Nullable error))completion {
- FSTParsedSetData *parsed = options.isMerge
- ? [self.firestore.dataConverter parsedMergeData:documentData]
- : [self.firestore.dataConverter parsedSetData:documentData];
+ FSTParsedSetData *parsed = merge ? [self.firestore.dataConverter parsedMergeData:documentData]
+ : [self.firestore.dataConverter parsedSetData:documentData];
return [self.firestore.client
writeMutations:[parsed mutationsWithKey:self.key precondition:Precondition::None()]
completion:completion];
diff --git a/Firestore/Source/API/FIRSetOptions+Internal.h b/Firestore/Source/API/FIRSetOptions+Internal.h
deleted file mode 100644
index 9118096..0000000
--- a/Firestore/Source/API/FIRSetOptions+Internal.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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 "FIRSetOptions.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-@interface FIRSetOptions ()
-
-- (instancetype)initWithMerge:(BOOL)merge NS_DESIGNATED_INITIALIZER;
-
-@end
-
-@interface FIRSetOptions (Internal)
-
-+ (instancetype)overwrite;
-
-@end
-
-NS_ASSUME_NONNULL_END
diff --git a/Firestore/Source/API/FIRSetOptions.mm b/Firestore/Source/API/FIRSetOptions.mm
deleted file mode 100644
index b41086c..0000000
--- a/Firestore/Source/API/FIRSetOptions.mm
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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 "Firestore/Source/API/FIRSetOptions+Internal.h"
-
-NS_ASSUME_NONNULL_BEGIN
-
-@implementation FIRSetOptions
-
-- (instancetype)initWithMerge:(BOOL)merge {
- if (self = [super init]) {
- _merge = merge;
- }
- return self;
-}
-
-+ (instancetype)merge {
- return [[FIRSetOptions alloc] initWithMerge:YES];
-}
-
-- (BOOL)isEqual:(id)other {
- if (self == other) {
- return YES;
- } else if (![other isKindOfClass:[FIRSetOptions class]]) {
- return NO;
- }
-
- FIRSetOptions *otherOptions = (FIRSetOptions *)other;
- return otherOptions.merge == self.merge;
-}
-
-- (NSUInteger)hash {
- return self.merge ? 1231 : 1237;
-}
-@end
-
-@implementation FIRSetOptions (Internal)
-
-+ (instancetype)overwrite {
- static FIRSetOptions *overwriteInstance = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- overwriteInstance = [[FIRSetOptions alloc] initWithMerge:NO];
- });
- return overwriteInstance;
-}
-
-@end
-
-NS_ASSUME_NONNULL_END
diff --git a/Firestore/Source/API/FIRTransaction.mm b/Firestore/Source/API/FIRTransaction.mm
index 2d1dd68..668a359 100644
--- a/Firestore/Source/API/FIRTransaction.mm
+++ b/Firestore/Source/API/FIRTransaction.mm
@@ -19,7 +19,6 @@
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
#import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h"
#import "Firestore/Source/API/FIRFirestore+Internal.h"
-#import "Firestore/Source/API/FIRSetOptions+Internal.h"
#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/Core/FSTTransaction.h"
#import "Firestore/Source/Model/FSTDocument.h"
@@ -62,15 +61,15 @@ NS_ASSUME_NONNULL_BEGIN
- (FIRTransaction *)setData:(NSDictionary<NSString *, id> *)data
forDocument:(FIRDocumentReference *)document {
- return [self setData:data forDocument:document options:[FIRSetOptions overwrite]];
+ return [self setData:data forDocument:document merge:NO];
}
- (FIRTransaction *)setData:(NSDictionary<NSString *, id> *)data
forDocument:(FIRDocumentReference *)document
- options:(FIRSetOptions *)options {
+ merge:(BOOL)merge {
[self validateReference:document];
- FSTParsedSetData *parsed = options.isMerge ? [self.firestore.dataConverter parsedMergeData:data]
- : [self.firestore.dataConverter parsedSetData:data];
+ FSTParsedSetData *parsed = merge ? [self.firestore.dataConverter parsedMergeData:data]
+ : [self.firestore.dataConverter parsedSetData:data];
[self.internalTransaction setData:parsed forDocument:document.key];
return self;
}
diff --git a/Firestore/Source/API/FIRWriteBatch.mm b/Firestore/Source/API/FIRWriteBatch.mm
index df6e5e0..1185dae 100644
--- a/Firestore/Source/API/FIRWriteBatch.mm
+++ b/Firestore/Source/API/FIRWriteBatch.mm
@@ -18,7 +18,6 @@
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
#import "Firestore/Source/API/FIRFirestore+Internal.h"
-#import "Firestore/Source/API/FIRSetOptions+Internal.h"
#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/Core/FSTFirestoreClient.h"
#import "Firestore/Source/Model/FSTMutation.h"
@@ -63,16 +62,16 @@ NS_ASSUME_NONNULL_BEGIN
- (FIRWriteBatch *)setData:(NSDictionary<NSString *, id> *)data
forDocument:(FIRDocumentReference *)document {
- return [self setData:data forDocument:document options:[FIRSetOptions overwrite]];
+ return [self setData:data forDocument:document merge:NO];
}
- (FIRWriteBatch *)setData:(NSDictionary<NSString *, id> *)data
forDocument:(FIRDocumentReference *)document
- options:(FIRSetOptions *)options {
+ merge:(BOOL)merge {
[self verifyNotCommitted];
[self validateReference:document];
- FSTParsedSetData *parsed = options.isMerge ? [self.firestore.dataConverter parsedMergeData:data]
- : [self.firestore.dataConverter parsedSetData:data];
+ FSTParsedSetData *parsed = merge ? [self.firestore.dataConverter parsedMergeData:data]
+ : [self.firestore.dataConverter parsedSetData:data];
[self.mutations
addObjectsFromArray:[parsed mutationsWithKey:document.key precondition:Precondition::None()]];
return self;
diff --git a/Firestore/Source/API/FSTUserDataConverter.h b/Firestore/Source/API/FSTUserDataConverter.h
index ea20b3e..98a65ae 100644
--- a/Firestore/Source/API/FSTUserDataConverter.h
+++ b/Firestore/Source/API/FSTUserDataConverter.h
@@ -24,7 +24,6 @@
#include "Firestore/core/src/firebase/firestore/model/field_transform.h"
#include "Firestore/core/src/firebase/firestore/model/precondition.h"
-@class FIRSetOptions;
@class FSTObjectValue;
@class FSTFieldValue;
@class FSTMutation;
@@ -130,7 +129,7 @@ typedef id _Nullable (^FSTPreConverterBlock)(id _Nullable);
/** Parse document data from a non-merge setData call.*/
- (FSTParsedSetData *)parsedSetData:(id)input;
-/** Parse document data from a setData call with '[FIRSetOptions merge]'. */
+/** Parse document data from a setData call with `merge:YES`. */
- (FSTParsedSetData *)parsedMergeData:(id)input;
/** Parse update data from an updateData call. */
diff --git a/Firestore/Source/API/FSTUserDataConverter.mm b/Firestore/Source/API/FSTUserDataConverter.mm
index 90d68d8..719f6f5 100644
--- a/Firestore/Source/API/FSTUserDataConverter.mm
+++ b/Firestore/Source/API/FSTUserDataConverter.mm
@@ -20,14 +20,13 @@
#include <utility>
#include <vector>
+#import "FIRGeoPoint.h"
#import "FIRTimestamp.h"
-#import "FIRGeoPoint.h"
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
#import "Firestore/Source/API/FIRFieldPath+Internal.h"
#import "Firestore/Source/API/FIRFieldValue+Internal.h"
#import "Firestore/Source/API/FIRFirestore+Internal.h"
-#import "Firestore/Source/API/FIRSetOptions+Internal.h"
#import "Firestore/Source/Model/FSTFieldValue.h"
#import "Firestore/Source/Model/FSTMutation.h"
#import "Firestore/Source/Util/FSTAssert.h"
@@ -595,7 +594,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) {
// We shouldn't encounter delete sentinels for queries or non-merge setData calls.
FSTThrowInvalidArgument(
@"FieldValue.delete() can only be used with updateData() and setData() with "
- @"SetOptions.merge()%@",
+ @"merge:true%@",
[context fieldDescription]);
}
@@ -748,7 +747,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) {
// We shouldn't encounter delete sentinels for queries or non-merge setData calls.
FSTThrowInvalidArgument(
@"FieldValue.delete() can only be used with updateData() and setData() with "
- @"SetOptions.merge().");
+ @"merge: true.");
}
} else if ([input isKindOfClass:[FSTServerTimestampFieldValue class]]) {
if (![context isWrite]) {
diff --git a/Firestore/Source/Core/FSTTransaction.h b/Firestore/Source/Core/FSTTransaction.h
index 581a5fa..ab59bde 100644
--- a/Firestore/Source/Core/FSTTransaction.h
+++ b/Firestore/Source/Core/FSTTransaction.h
@@ -22,7 +22,6 @@
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
-@class FIRSetOptions;
@class FSTDatastore;
@class FSTMaybeDocument;
@class FSTObjectValue;
diff --git a/Firestore/Source/Core/FSTTransaction.mm b/Firestore/Source/Core/FSTTransaction.mm
index 681f9ca..4aabd5a 100644
--- a/Firestore/Source/Core/FSTTransaction.mm
+++ b/Firestore/Source/Core/FSTTransaction.mm
@@ -22,7 +22,6 @@
#include <vector>
#import "FIRFirestoreErrors.h"
-#import "FIRSetOptions.h"
#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/Core/FSTSnapshotVersion.h"
#import "Firestore/Source/Model/FSTDocument.h"
diff --git a/Firestore/Source/Public/FIRDocumentReference.h b/Firestore/Source/Public/FIRDocumentReference.h
index dd2d106..e7ba6eb 100644
--- a/Firestore/Source/Public/FIRDocumentReference.h
+++ b/Firestore/Source/Public/FIRDocumentReference.h
@@ -18,10 +18,9 @@
#import "FIRListenerRegistration.h"
-@class FIRFirestore;
@class FIRCollectionReference;
@class FIRDocumentSnapshot;
-@class FIRSetOptions;
+@class FIRFirestore;
NS_ASSUME_NONNULL_BEGIN
@@ -82,14 +81,14 @@ NS_SWIFT_NAME(DocumentReference)
/**
* Writes to the document referred to by this DocumentReference. If the document does not yet
- * exist, it will be created. If you pass `FIRSetOptions`, the provided data will be merged into
- * an existing document.
+ * exist, it will be created. If you pass `merge:YES`, the provided data will be merged into
+ * any existing document.
*
* @param documentData An `NSDictionary` that contains the fields and data to write to the
* document.
- * @param options A `FIRSetOptions` used to configure the set behavior.
+ * @param merge Whether to merge the provided data into any existing document.
*/
-- (void)setData:(NSDictionary<NSString *, id> *)documentData options:(FIRSetOptions *)options;
+- (void)setData:(NSDictionary<NSString *, id> *)documentData merge:(BOOL)merge;
/**
* Overwrites the document referred to by this `FIRDocumentReference`. If no document exists, it
@@ -106,18 +105,18 @@ NS_SWIFT_NAME(DocumentReference)
/**
* Writes to the document referred to by this DocumentReference. If the document does not yet
- * exist, it will be created. If you pass `FIRSetOptions`, the provided data will be merged into
- * an existing document.
+ * exist, it will be created. If you pass `merge:YES`, the provided data will be merged into
+ * any existing document.
*
* @param documentData An `NSDictionary` containing the fields that make up the document
* to be written.
- * @param options A `FIRSetOptions` used to configure the set behavior.
+ * @param merge Whether to merge the provided data into any existing document.
* @param completion A block to execute once the document has been successfully written to the
* server. This block will not be called while the client is offline, though local
* changes will be visible immediately.
*/
- (void)setData:(NSDictionary<NSString *, id> *)documentData
- options:(FIRSetOptions *)options
+ merge:(BOOL)merge
completion:(nullable void (^)(NSError *_Nullable error))completion;
/**
diff --git a/Firestore/Source/Public/FIRSetOptions.h b/Firestore/Source/Public/FIRSetOptions.h
deleted file mode 100644
index c865e06..0000000
--- a/Firestore/Source/Public/FIRSetOptions.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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 <Foundation/Foundation.h>
-
-NS_ASSUME_NONNULL_BEGIN
-
-/**
- * An options object that configures the behavior of setData() calls. By providing the
- * `FIRSetOptions` objects returned by `merge:`, the setData() methods in `FIRDocumentReference`,
- * `FIRWriteBatch` and `FIRTransaction` can be configured to perform granular merges instead
- * of overwriting the target documents in their entirety.
- */
-NS_SWIFT_NAME(SetOptions)
-@interface FIRSetOptions : NSObject
-
-/** */
-- (id)init NS_UNAVAILABLE;
-/**
- * Changes the behavior of setData() calls to only replace the values specified in its data
- * argument. Fields with no corresponding values in the data passed to setData() will remain
- * untouched.
- *
- * @return The created `FIRSetOptions` object
- */
-+ (instancetype)merge;
-
-/** Whether setData() should merge existing data instead of performing an overwrite. */
-@property(nonatomic, readonly, getter=isMerge) BOOL merge;
-
-@end
-
-NS_ASSUME_NONNULL_END
diff --git a/Firestore/Source/Public/FIRTransaction.h b/Firestore/Source/Public/FIRTransaction.h
index 51a6e90..2fa4430 100644
--- a/Firestore/Source/Public/FIRTransaction.h
+++ b/Firestore/Source/Public/FIRTransaction.h
@@ -20,7 +20,6 @@ NS_ASSUME_NONNULL_BEGIN
@class FIRDocumentReference;
@class FIRDocumentSnapshot;
-@class FIRSetOptions;
/**
* `FIRTransaction` provides methods to read and write data within a transaction.
@@ -50,19 +49,19 @@ NS_SWIFT_NAME(Transaction)
/**
* Writes to the document referred to by `document`. If the document doesn't yet exist,
- * this method creates it and then sets the data. If you pass `FIRSetOptions`, the provided data
- * will be merged into an existing document.
+ * this method creates it and then sets the data. If you pass `merge:YES`, the provided data will be
+ * merged into any existing document.
*
* @param data An `NSDictionary` that contains the fields and data to write to the document.
* @param document A reference to the document whose data should be overwritten.
- * @param options A `FIRSetOptions` used to configure the set behavior.
+ * @param merge Whether to merge the provided data into any existing document.
* @return This `FIRTransaction` instance. Used for chaining method calls.
*/
// clang-format off
- (FIRTransaction *)setData:(NSDictionary<NSString *, id> *)data
forDocument:(FIRDocumentReference *)document
- options:(FIRSetOptions *)options
- NS_SWIFT_NAME(setData(_:forDocument:options:));
+ merge:(BOOL)merge
+ NS_SWIFT_NAME(setData(_:forDocument:merge:));
// clang-format on
/**
diff --git a/Firestore/Source/Public/FIRWriteBatch.h b/Firestore/Source/Public/FIRWriteBatch.h
index 8ff1bec..1568723 100644
--- a/Firestore/Source/Public/FIRWriteBatch.h
+++ b/Firestore/Source/Public/FIRWriteBatch.h
@@ -19,7 +19,6 @@
NS_ASSUME_NONNULL_BEGIN
@class FIRDocumentReference;
-@class FIRSetOptions;
/**
* A write batch is used to perform multiple writes as a single atomic unit.
@@ -53,19 +52,19 @@ NS_SWIFT_NAME(WriteBatch)
/**
* Writes to the document referred to by `document`. If the document doesn't yet exist,
- * this method creates it and then sets the data. If you pass `FIRSetOptions`, the provided data
- * will be merged into an existing document.
+ * this method creates it and then sets the data. If you pass `merge:YES`, the provided data will be
+ * merged into any existing document.
*
* @param data An `NSDictionary` that contains the fields and data to write to the document.
* @param document A reference to the document whose data should be overwritten.
- * @param options A `FIRSetOptions` used to configure the set behavior.
+ * @param merge Whether to merge the provided data into any existing document.
* @return This `FIRWriteBatch` instance. Used for chaining method calls.
*/
// clang-format off
- (FIRWriteBatch *)setData:(NSDictionary<NSString *, id> *)data
forDocument:(FIRDocumentReference *)document
- options:(FIRSetOptions *)options
- NS_SWIFT_NAME(setData(_:forDocument:options:));
+ merge:(BOOL)merge
+ NS_SWIFT_NAME(setData(_:forDocument:merge:));
// clang-format on
/**
diff --git a/Firestore/Source/Public/FirebaseFirestore.h b/Firestore/Source/Public/FirebaseFirestore.h
index 36f9fb7..127c935 100644
--- a/Firestore/Source/Public/FirebaseFirestore.h
+++ b/Firestore/Source/Public/FirebaseFirestore.h
@@ -27,7 +27,6 @@
#import "FIRListenerRegistration.h"
#import "FIRQuery.h"
#import "FIRQuerySnapshot.h"
-#import "FIRSetOptions.h"
#import "FIRSnapshotMetadata.h"
#import "FIRTimestamp.h"
#import "FIRTransaction.h"