aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source
diff options
context:
space:
mode:
authorGravatar Michael Lehenbauer <mikelehen@gmail.com>2018-04-17 15:55:29 -0700
committerGravatar GitHub <noreply@github.com>2018-04-17 15:55:29 -0700
commite36cc9610b11dfd2581ba5e3fda1917e0d5e697a (patch)
tree1a2861ce32463a225f1960c20e2f25b195d39183 /Firestore/Source
parent2f86a297446b7b2e4832bc2868fe63d54211144f (diff)
Integration tests, changelog, and minor fixes for array transforms. (#1108)
Diffstat (limited to 'Firestore/Source')
-rw-r--r--Firestore/Source/API/FIRFieldValue.mm10
-rw-r--r--Firestore/Source/API/FSTUserDataConverter.mm24
2 files changed, 26 insertions, 8 deletions
diff --git a/Firestore/Source/API/FIRFieldValue.mm b/Firestore/Source/API/FIRFieldValue.mm
index e0ed8c7..5f7fbd7 100644
--- a/Firestore/Source/API/FIRFieldValue.mm
+++ b/Firestore/Source/API/FIRFieldValue.mm
@@ -95,6 +95,11 @@ NS_ASSUME_NONNULL_BEGIN
}
return self;
}
+
+- (NSString *)methodName {
+ return @"FieldValue.arrayUnion()";
+}
+
@end
#pragma mark - FSTArrayRemoveFieldValue
@@ -110,6 +115,11 @@ NS_ASSUME_NONNULL_BEGIN
}
return self;
}
+
+- (NSString *)methodName {
+ return @"FieldValue.arrayRemove()";
+}
+
@end
#pragma mark - FIRFieldValue
diff --git a/Firestore/Source/API/FSTUserDataConverter.mm b/Firestore/Source/API/FSTUserDataConverter.mm
index cd32cef..2794398 100644
--- a/Firestore/Source/API/FSTUserDataConverter.mm
+++ b/Firestore/Source/API/FSTUserDataConverter.mm
@@ -515,6 +515,15 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) {
input = self.preConverter(input);
if ([input isKindOfClass:[NSDictionary class]]) {
return [self parseDictionary:(NSDictionary *)input context:context];
+
+ } else if ([input isKindOfClass:[FIRFieldValue class]]) {
+ // FieldValues usually parse into transforms (except FieldValue.delete()) in which case we
+ // do not want to include this field in our parsed data (as doing so will overwrite the field
+ // directly prior to the transform trying to transform it). So we don't call appendToFieldMask
+ // and we return nil as our parsing result.
+ [self parseSentinelFieldValue:(FIRFieldValue *)input context:context];
+ return nil;
+
} else {
// If context.path is nil we are already inside an array and we don't support field mask paths
// more granular than the top-level array.
@@ -528,11 +537,6 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) {
FSTThrowInvalidArgument(@"Nested arrays are not supported");
}
return [self parseArray:(NSArray *)input context:context];
- } else if ([input isKindOfClass:[FIRFieldValue class]]) {
- // parseSentinelFieldValue may add an FSTFieldTransform, but we return nil since nothing
- // should be included in the actual parsed data.
- [self parseSentinelFieldValue:(FIRFieldValue *)input context:context];
- return nil;
} else {
return [self parseScalarValue:input context:context];
}
@@ -582,7 +586,9 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) {
if ([fieldValue isKindOfClass:[FSTDeleteFieldValue class]]) {
if (context.dataSource == FSTUserDataSourceMergeSet) {
- // No transform to add for a delete, so we do nothing.
+ // No transform to add for a delete, but we need to add it to our fieldMask so it gets
+ // deleted.
+ [context appendToFieldMaskWithFieldPath:*context.path];
} else if (context.dataSource == FSTUserDataSourceUpdate) {
FSTAssert(context.path->size() > 0,
@"FieldValue.delete() at the top level should have already been handled.");
@@ -777,13 +783,15 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) {
- (std::vector<FSTFieldValue *>)parseArrayTransformElements:(NSArray<id> *)elements {
std::vector<FSTFieldValue *> results;
- for (id element in elements) {
+ for (NSUInteger i = 0; i < elements.count; i++) {
+ id element = elements[i];
// Although array transforms are used with writes, the actual elements being unioned or removed
// are not considered writes since they cannot contain any FieldValue sentinels, etc.
FSTParseContext *context =
[FSTParseContext contextWithSource:FSTUserDataSourceArgument
path:absl::make_unique<FieldPath>(FieldPath::EmptyPath())];
- FSTFieldValue *parsedElement = [self parseData:element context:context];
+ FSTFieldValue *parsedElement =
+ [self parseData:element context:[context contextForArrayIndex:i]];
FSTAssert(parsedElement && context.fieldTransforms->size() == 0,
@"Failed to properly parse array transform element: %@", element);
results.push_back(parsedElement);