Skip to content

Port FieldTransform to C++ #1033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#import <GRPCClient/GRPCCall.h>
#import <XCTest/XCTest.h>

#include <vector>

#import "Firestore/Protos/objc/firestore/local/MaybeDocument.pbobjc.h"
#import "Firestore/Protos/objc/firestore/local/Mutation.pbobjc.h"
#import "Firestore/Protos/objc/google/firestore/v1beta1/Common.pbobjc.h"
Expand All @@ -47,13 +49,15 @@

#include "Firestore/core/src/firebase/firestore/model/database_id.h"
#include "Firestore/core/src/firebase/firestore/model/field_mask.h"
#include "Firestore/core/src/firebase/firestore/model/field_transform.h"
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
#include "Firestore/core/test/firebase/firestore/testutil/testutil.h"

namespace testutil = firebase::firestore::testutil;
namespace util = firebase::firestore::util;
using firebase::firestore::model::DatabaseId;
using firebase::firestore::model::FieldMask;
using firebase::firestore::model::FieldTransform;

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -67,7 +71,7 @@ - (GCFSValue *)encodedDate:(NSDate *)value;

- (GCFSDocumentMask *)encodedFieldMask:(const FieldMask &)fieldMask;
- (NSMutableArray<GCFSDocumentTransform_FieldTransform *> *)encodedFieldTransforms:
(NSArray<FSTFieldTransform *> *)fieldTransforms;
(const std::vector<FieldTransform> &)fieldTransforms;

- (GCFSStructuredQuery_Filter *)encodedRelationFilter:(FSTRelationFilter *)filter;
@end
Expand Down
12 changes: 6 additions & 6 deletions Firestore/Example/Tests/Util/FSTHelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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_transform.h"
#include "Firestore/core/src/firebase/firestore/model/field_value.h"
#include "Firestore/core/src/firebase/firestore/model/resource_path.h"
#include "Firestore/core/src/firebase/firestore/model/transform_operations.h"
Expand All @@ -59,6 +60,7 @@
using firebase::firestore::model::DocumentKey;
using firebase::firestore::model::FieldMask;
using firebase::firestore::model::FieldPath;
using firebase::firestore::model::FieldTransform;
using firebase::firestore::model::FieldValue;
using firebase::firestore::model::ResourcePath;
using firebase::firestore::model::ServerTimestampTransform;
Expand Down Expand Up @@ -279,15 +281,13 @@ NSComparator FSTTestDocComparator(const absl::string_view fieldPath) {
FSTTransformMutation *FSTTestTransformMutation(NSString *path,
NSArray<NSString *> *serverTimestampFields) {
FSTDocumentKey *key = [FSTDocumentKey keyWithPath:testutil::Resource(util::MakeStringView(path))];
NSMutableArray<FSTFieldTransform *> *fieldTransforms = [NSMutableArray array];
std::vector<FieldTransform> fieldTransforms;
for (NSString *field in serverTimestampFields) {
const FieldPath fieldPath = testutil::Field(util::MakeStringView(field));
FieldPath fieldPath = testutil::Field(util::MakeStringView(field));
auto transformOp = absl::make_unique<ServerTimestampTransform>(ServerTimestampTransform::Get());
FSTFieldTransform *transform =
[[FSTFieldTransform alloc] initWithPath:fieldPath transform:std::move(transformOp)];
[fieldTransforms addObject:transform];
fieldTransforms.emplace_back(std::move(fieldPath), std::move(transformOp));
}
return [[FSTTransformMutation alloc] initWithKey:key fieldTransforms:fieldTransforms];
return [[FSTTransformMutation alloc] initWithKey:key fieldTransforms:std::move(fieldTransforms)];
}

FSTDeleteMutation *FSTTestDeleteMutation(NSString *path) {
Expand Down
18 changes: 12 additions & 6 deletions Firestore/Source/API/FSTUserDataConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@

#import <Foundation/Foundation.h>

#include <vector>

#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_transform.h"

@class FIRSetOptions;
@class FSTObjectValue;
@class FSTFieldValue;
@class FSTFieldTransform;
@class FSTMutation;
@class FSTPrecondition;
@class FSTSnapshotVersion;
Expand All @@ -36,16 +38,19 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init NS_UNAVAILABLE;

- (instancetype)initWithData:(FSTObjectValue *)data
fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms
fieldTransforms:
(std::vector<firebase::firestore::model::FieldTransform>)fieldTransforms
NS_DESIGNATED_INITIALIZER;

- (instancetype)initWithData:(FSTObjectValue *)data
fieldMask:(firebase::firestore::model::FieldMask)fieldMask
fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms
fieldTransforms:
(std::vector<firebase::firestore::model::FieldTransform>)fieldTransforms
NS_DESIGNATED_INITIALIZER;

- (const std::vector<firebase::firestore::model::FieldTransform> &)fieldTransforms;

@property(nonatomic, strong, readonly) FSTObjectValue *data;
@property(nonatomic, strong, readonly) NSArray<FSTFieldTransform *> *fieldTransforms;
@property(nonatomic, assign, readonly) BOOL isPatch;

/**
Expand All @@ -64,13 +69,14 @@ NS_ASSUME_NONNULL_BEGIN

- (instancetype)initWithData:(FSTObjectValue *)data
fieldMask:(firebase::firestore::model::FieldMask)fieldMask
fieldTransforms:(NSArray<FSTFieldTransform *> *)fieldTransforms
fieldTransforms:
(std::vector<firebase::firestore::model::FieldTransform>)fieldTransforms
NS_DESIGNATED_INITIALIZER;

- (const firebase::firestore::model::FieldMask &)fieldMask;
- (const std::vector<firebase::firestore::model::FieldTransform> &)fieldTransforms;

@property(nonatomic, strong, readonly) FSTObjectValue *data;
@property(nonatomic, strong, readonly) NSArray<FSTFieldTransform *> *fieldTransforms;

/**
* Converts the parsed update data into 1 or 2 mutations (depending on whether there are any
Expand Down
Loading