aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Firestore/Source')
-rw-r--r--Firestore/Source/API/FSTUserDataConverter.h15
-rw-r--r--Firestore/Source/API/FSTUserDataConverter.mm54
-rw-r--r--Firestore/Source/Core/FSTTransaction.h1
-rw-r--r--Firestore/Source/Model/FSTMutation.h38
-rw-r--r--Firestore/Source/Model/FSTMutation.mm64
-rw-r--r--Firestore/Source/Remote/FSTSerializerBeta.mm10
6 files changed, 77 insertions, 105 deletions
diff --git a/Firestore/Source/API/FSTUserDataConverter.h b/Firestore/Source/API/FSTUserDataConverter.h
index 3b178be..2b4b340 100644
--- a/Firestore/Source/API/FSTUserDataConverter.h
+++ b/Firestore/Source/API/FSTUserDataConverter.h
@@ -18,10 +18,10 @@
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
+#include "Firestore/core/src/firebase/firestore/model/field_mask.h"
@class FIRSetOptions;
@class FSTObjectValue;
-@class FSTFieldMask;
@class FSTFieldValue;
@class FSTFieldTransform;
@class FSTMutation;
@@ -36,13 +36,17 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithData:(FSTObjectValue *)data
- fieldMask:(nullable FSTFieldMask *)fieldMask
+ fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms
+ NS_DESIGNATED_INITIALIZER;
+
+- (instancetype)initWithData:(FSTObjectValue *)data
+ fieldMask:(firebase::firestore::model::FieldMask)fieldMask
fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms
NS_DESIGNATED_INITIALIZER;
@property(nonatomic, strong, readonly) FSTObjectValue *data;
-@property(nonatomic, strong, readonly, nullable) FSTFieldMask *fieldMask;
@property(nonatomic, strong, readonly) NSArray<FSTFieldTransform *> *fieldTransforms;
+@property(nonatomic, assign, readonly) BOOL isPatch;
/**
* Converts the parsed document data into 1 or 2 mutations (depending on whether there are any
@@ -59,12 +63,13 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithData:(FSTObjectValue *)data
- fieldMask:(FSTFieldMask *)fieldMask
+ fieldMask:(firebase::firestore::model::FieldMask)fieldMask
fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms
NS_DESIGNATED_INITIALIZER;
+- (const firebase::firestore::model::FieldMask &)fieldMask;
+
@property(nonatomic, strong, readonly) FSTObjectValue *data;
-@property(nonatomic, strong, readonly) FSTFieldMask *fieldMask;
@property(nonatomic, strong, readonly) NSArray<FSTFieldTransform *> *fieldTransforms;
/**
diff --git a/Firestore/Source/API/FSTUserDataConverter.mm b/Firestore/Source/API/FSTUserDataConverter.mm
index 7ee16de..34f1015 100644
--- a/Firestore/Source/API/FSTUserDataConverter.mm
+++ b/Firestore/Source/API/FSTUserDataConverter.mm
@@ -35,6 +35,7 @@
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
+#include "Firestore/core/src/firebase/firestore/model/field_mask.h"
#include "Firestore/core/src/firebase/firestore/model/field_path.h"
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
#include "absl/memory/memory.h"
@@ -42,6 +43,7 @@
namespace util = firebase::firestore::util;
using firebase::firestore::model::DatabaseId;
using firebase::firestore::model::DocumentKey;
+using firebase::firestore::model::FieldMask;
using firebase::firestore::model::FieldPath;
NS_ASSUME_NONNULL_BEGIN
@@ -50,15 +52,30 @@ static NSString *const RESERVED_FIELD_DESIGNATOR = @"__";
#pragma mark - FSTParsedSetData
-@implementation FSTParsedSetData
+@implementation FSTParsedSetData {
+ FieldMask _fieldMask;
+}
+
+- (instancetype)initWithData:(FSTObjectValue *)data
+ fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms {
+ self = [super init];
+ if (self) {
+ _data = data;
+ _fieldTransforms = fieldTransforms;
+ _isPatch = NO;
+ }
+ return self;
+}
+
- (instancetype)initWithData:(FSTObjectValue *)data
- fieldMask:(nullable FSTFieldMask *)fieldMask
+ fieldMask:(FieldMask)fieldMask
fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms {
self = [super init];
if (self) {
_data = data;
- _fieldMask = fieldMask;
+ _fieldMask = std::move(fieldMask);
_fieldTransforms = fieldTransforms;
+ _isPatch = YES;
}
return self;
}
@@ -66,9 +83,9 @@ static NSString *const RESERVED_FIELD_DESIGNATOR = @"__";
- (NSArray<FSTMutation *> *)mutationsWithKey:(const DocumentKey &)key
precondition:(FSTPrecondition *)precondition {
NSMutableArray<FSTMutation *> *mutations = [NSMutableArray array];
- if (self.fieldMask) {
+ if (self.isPatch) {
[mutations addObject:[[FSTPatchMutation alloc] initWithKey:key
- fieldMask:self.fieldMask
+ fieldMask:_fieldMask
value:self.data
precondition:precondition]];
} else {
@@ -87,14 +104,17 @@ static NSString *const RESERVED_FIELD_DESIGNATOR = @"__";
#pragma mark - FSTParsedUpdateData
-@implementation FSTParsedUpdateData
+@implementation FSTParsedUpdateData {
+ FieldMask _fieldMask;
+}
+
- (instancetype)initWithData:(FSTObjectValue *)data
- fieldMask:(FSTFieldMask *)fieldMask
+ fieldMask:(FieldMask)fieldMask
fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms {
self = [super init];
if (self) {
_data = data;
- _fieldMask = fieldMask;
+ _fieldMask = std::move(fieldMask);
_fieldTransforms = fieldTransforms;
}
return self;
@@ -114,6 +134,10 @@ static NSString *const RESERVED_FIELD_DESIGNATOR = @"__";
return mutations;
}
+- (const firebase::firestore::model::FieldMask &)fieldMask {
+ return _fieldMask;
+}
+
@end
/**
@@ -364,10 +388,9 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) {
path:absl::make_unique<FieldPath>(FieldPath::EmptyPath())];
FSTObjectValue *updateData = (FSTObjectValue *)[self parseData:input context:context];
- return [[FSTParsedSetData alloc]
- initWithData:updateData
- fieldMask:[[FSTFieldMask alloc] initWithFields:*context.fieldMask]
- fieldTransforms:context.fieldTransforms];
+ return [[FSTParsedSetData alloc] initWithData:updateData
+ fieldMask:FieldMask{*context.fieldMask}
+ fieldTransforms:context.fieldTransforms];
}
- (FSTParsedSetData *)parsedSetData:(id)input {
@@ -382,9 +405,7 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) {
path:absl::make_unique<FieldPath>(FieldPath::EmptyPath())];
FSTObjectValue *updateData = (FSTObjectValue *)[self parseData:input context:context];
- return [[FSTParsedSetData alloc] initWithData:updateData
- fieldMask:nil
- fieldTransforms:context.fieldTransforms];
+ return [[FSTParsedSetData alloc] initWithData:updateData fieldTransforms:context.fieldTransforms];
}
- (FSTParsedUpdateData *)parsedUpdateData:(id)input {
@@ -428,9 +449,8 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) {
}
}];
- FSTFieldMask *mask = [[FSTFieldMask alloc] initWithFields:fieldMaskPaths];
return [[FSTParsedUpdateData alloc] initWithData:updateData
- fieldMask:mask
+ fieldMask:FieldMask{fieldMaskPaths}
fieldTransforms:context.fieldTransforms];
}
diff --git a/Firestore/Source/Core/FSTTransaction.h b/Firestore/Source/Core/FSTTransaction.h
index 676ada9..01c2e20 100644
--- a/Firestore/Source/Core/FSTTransaction.h
+++ b/Firestore/Source/Core/FSTTransaction.h
@@ -24,7 +24,6 @@
@class FIRSetOptions;
@class FSTDatastore;
-@class FSTFieldMask;
@class FSTFieldTransform;
@class FSTMaybeDocument;
@class FSTObjectValue;
diff --git a/Firestore/Source/Model/FSTMutation.h b/Firestore/Source/Model/FSTMutation.h
index 4e4357d..2b81af6 100644
--- a/Firestore/Source/Model/FSTMutation.h
+++ b/Firestore/Source/Model/FSTMutation.h
@@ -19,6 +19,7 @@
#include <vector>
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
+#include "Firestore/core/src/firebase/firestore/model/field_mask.h"
#include "Firestore/core/src/firebase/firestore/model/field_path.h"
@class FSTDocument;
@@ -30,31 +31,6 @@
NS_ASSUME_NONNULL_BEGIN
-#pragma mark - FSTFieldMask
-
-/**
- * Provides a set of fields that can be used to partially patch a document. FieldMask is used in
- * conjunction with ObjectValue.
- *
- * Examples:
- * foo - Overwrites foo entirely with the provided value. If foo is not present in the companion
- * ObjectValue, the field is deleted.
- * foo.bar - Overwrites only the field bar of the object foo. If foo is not an object, foo is
- * replaced with an object containing bar.
- */
-@interface FSTFieldMask : NSObject
-- (id)init __attribute__((unavailable("Use initWithFields:")));
-
-/**
- * Initializes the field mask with the given field paths. Caller is expected to either copy or
- * or release the array of fields.
- */
-- (instancetype)initWithFields:(std::vector<firebase::firestore::model::FieldPath>)fields
- NS_DESIGNATED_INITIALIZER;
-
-- (const std::vector<firebase::firestore::model::FieldPath> &)fields;
-@end
-
#pragma mark - FSTFieldTransform
/** Represents a transform within a TransformMutation. */
@@ -267,7 +243,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) {
precondition:(FSTPrecondition *)precondition NS_UNAVAILABLE;
/**
- * Initializes a new patch mutation with an explicit FSTFieldMask and FSTObjectValue representing
+ * Initializes a new patch mutation with an explicit FieldMask and FSTObjectValue representing
* the updates to perform
*
* @param key Identifies the location of the document to mutate.
@@ -278,18 +254,18 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) {
* @param precondition The precondition for this mutation.
*/
- (instancetype)initWithKey:(firebase::firestore::model::DocumentKey)key
- fieldMask:(FSTFieldMask *)fieldMask
+ fieldMask:(firebase::firestore::model::FieldMask)fieldMask
value:(FSTObjectValue *)value
precondition:(FSTPrecondition *)precondition NS_DESIGNATED_INITIALIZER;
-/** The fields and associated values to use when patching the document. */
-@property(nonatomic, strong, readonly) FSTObjectValue *value;
-
/**
* A mask to apply to |value|, where only fields that are in both the fieldMask and the value
* will be updated.
*/
-@property(nonatomic, strong, readonly) FSTFieldMask *fieldMask;
+- (const firebase::firestore::model::FieldMask &)fieldMask;
+
+/** The fields and associated values to use when patching the document. */
+@property(nonatomic, strong, readonly) FSTObjectValue *value;
@end
diff --git a/Firestore/Source/Model/FSTMutation.mm b/Firestore/Source/Model/FSTMutation.mm
index 253a853..df95155 100644
--- a/Firestore/Source/Model/FSTMutation.mm
+++ b/Firestore/Source/Model/FSTMutation.mm
@@ -27,51 +27,15 @@
#import "Firestore/Source/Util/FSTClasses.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
+#include "Firestore/core/src/firebase/firestore/model/field_mask.h"
#include "Firestore/core/src/firebase/firestore/model/field_path.h"
using firebase::firestore::model::DocumentKey;
+using firebase::firestore::model::FieldMask;
using firebase::firestore::model::FieldPath;
NS_ASSUME_NONNULL_BEGIN
-#pragma mark - FSTFieldMask
-
-@implementation FSTFieldMask {
- std::vector<FieldPath> _fields;
-}
-
-- (instancetype)initWithFields:(std::vector<FieldPath>)fields {
- if (self = [super init]) {
- _fields = std::move(fields);
- }
- return self;
-}
-
-- (BOOL)isEqual:(id)other {
- if (other == self) {
- return YES;
- }
- if (![other isKindOfClass:[FSTFieldMask class]]) {
- return NO;
- }
-
- FSTFieldMask *otherMask = (FSTFieldMask *)other;
- return _fields == otherMask->_fields;
-}
-
-- (NSUInteger)hash {
- NSUInteger hashResult = 0;
- for (const FieldPath &field : _fields) {
- hashResult = hashResult * 31u + field.Hash();
- }
- return hashResult;
-}
-
-- (const std::vector<FieldPath> &)fields {
- return _fields;
-}
-@end
-
#pragma mark - FSTServerTimestampTransform
@implementation FSTServerTimestampTransform
@@ -354,20 +318,26 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - FSTPatchMutation
-@implementation FSTPatchMutation
+@implementation FSTPatchMutation {
+ FieldMask _fieldMask;
+}
- (instancetype)initWithKey:(DocumentKey)key
- fieldMask:(FSTFieldMask *)fieldMask
+ fieldMask:(FieldMask)fieldMask
value:(FSTObjectValue *)value
precondition:(FSTPrecondition *)precondition {
self = [super initWithKey:std::move(key) precondition:precondition];
if (self) {
- _fieldMask = fieldMask;
+ _fieldMask = std::move(fieldMask);
_value = value;
}
return self;
}
+- (const firebase::firestore::model::FieldMask &)fieldMask {
+ return _fieldMask;
+}
+
- (BOOL)isEqual:(id)other {
if (other == self) {
return YES;
@@ -377,7 +347,7 @@ NS_ASSUME_NONNULL_BEGIN
}
FSTPatchMutation *otherMutation = (FSTPatchMutation *)other;
- return [self.key isEqual:otherMutation.key] && [self.fieldMask isEqual:otherMutation.fieldMask] &&
+ return [self.key isEqual:otherMutation.key] && self.fieldMask == otherMutation.fieldMask &&
[self.value isEqual:otherMutation.value] &&
[self.precondition isEqual:otherMutation.precondition];
}
@@ -385,15 +355,15 @@ NS_ASSUME_NONNULL_BEGIN
- (NSUInteger)hash {
NSUInteger result = [self.key hash];
result = 31 * result + [self.precondition hash];
- result = 31 * result + [self.fieldMask hash];
+ result = 31 * result + self.fieldMask.Hash();
result = 31 * result + [self.value hash];
return result;
}
- (NSString *)description {
- return [NSString stringWithFormat:@"<FSTPatchMutation key=%s mask=%@ value=%@ precondition=%@>",
- self.key.ToString().c_str(), self.fieldMask, self.value,
- self.precondition];
+ return [NSString stringWithFormat:@"<FSTPatchMutation key=%s mask=%s value=%@ precondition=%@>",
+ self.key.ToString().c_str(), self.fieldMask.ToString().c_str(),
+ self.value, self.precondition];
}
- (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc
@@ -434,7 +404,7 @@ NS_ASSUME_NONNULL_BEGIN
- (FSTObjectValue *)patchObjectValue:(FSTObjectValue *)objectValue {
FSTObjectValue *result = objectValue;
- for (const FieldPath &fieldPath : self.fieldMask.fields) {
+ for (const FieldPath &fieldPath : self.fieldMask) {
FSTFieldValue *newValue = [self.value valueForPath:fieldPath];
if (newValue) {
result = [result objectBySettingValue:newValue forPath:fieldPath];
diff --git a/Firestore/Source/Remote/FSTSerializerBeta.mm b/Firestore/Source/Remote/FSTSerializerBeta.mm
index 3a22a3f..3b6f052 100644
--- a/Firestore/Source/Remote/FSTSerializerBeta.mm
+++ b/Firestore/Source/Remote/FSTSerializerBeta.mm
@@ -44,6 +44,7 @@
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
+#include "Firestore/core/src/firebase/firestore/model/field_mask.h"
#include "Firestore/core/src/firebase/firestore/model/field_path.h"
#include "Firestore/core/src/firebase/firestore/model/resource_path.h"
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
@@ -51,6 +52,7 @@
namespace util = firebase::firestore::util;
using firebase::firestore::model::DatabaseId;
using firebase::firestore::model::DocumentKey;
+using firebase::firestore::model::FieldMask;
using firebase::firestore::model::FieldPath;
using firebase::firestore::model::ResourcePath;
@@ -539,21 +541,21 @@ NS_ASSUME_NONNULL_BEGIN
}
}
-- (GCFSDocumentMask *)encodedFieldMask:(FSTFieldMask *)fieldMask {
+- (GCFSDocumentMask *)encodedFieldMask:(const FieldMask &)fieldMask {
GCFSDocumentMask *mask = [GCFSDocumentMask message];
- for (const FieldPath &field : fieldMask.fields) {
+ for (const FieldPath &field : fieldMask) {
[mask.fieldPathsArray addObject:util::WrapNSString(field.CanonicalString())];
}
return mask;
}
-- (FSTFieldMask *)decodedFieldMask:(GCFSDocumentMask *)fieldMask {
+- (FieldMask)decodedFieldMask:(GCFSDocumentMask *)fieldMask {
std::vector<FieldPath> fields{};
fields.reserve(fieldMask.fieldPathsArray_Count);
for (NSString *path in fieldMask.fieldPathsArray) {
fields.push_back(FieldPath::FromServerFormat(util::MakeStringView(path)));
}
- return [[FSTFieldMask alloc] initWithFields:std::move(fields)];
+ return FieldMask(std::move(fields));
}
- (NSMutableArray<GCFSDocumentTransform_FieldTransform *> *)encodedFieldTransforms: