From e36cc9610b11dfd2581ba5e3fda1917e0d5e697a Mon Sep 17 00:00:00 2001 From: Michael Lehenbauer Date: Tue, 17 Apr 2018 15:55:29 -0700 Subject: Integration tests, changelog, and minor fixes for array transforms. (#1108) --- Firestore/Source/API/FIRFieldValue.mm | 10 ++++++++++ Firestore/Source/API/FSTUserDataConverter.mm | 24 ++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) (limited to 'Firestore/Source') 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)parseArrayTransformElements:(NSArray *)elements { std::vector 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::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); -- cgit v1.2.3