Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
28 changes: 14 additions & 14 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Firestore/Example/Tests/API/FSTAPIHelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#import "Firestore/Source/API/FIRFirestore+Internal.h"
#import "Firestore/Source/API/FIRQuerySnapshot+Internal.h"
#import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h"
#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/API/FSTUserDataReader.h"

#include "Firestore/core/src/core/view_snapshot.h"
#include "Firestore/core/src/model/document.h"
Expand Down Expand Up @@ -85,8 +85,8 @@
BOOL fromCache) {
absl::optional<Document> doc;
if (data) {
FSTUserDataConverter *converter = FSTTestUserDataConverter();
FieldValue parsed = [converter parsedQueryValue:data];
FSTUserDataReader *reader = FSTTestUserDataReader();
FieldValue parsed = [reader parsedQueryValue:data];

doc = Doc(path, version, parsed,
hasMutations ? DocumentState::kLocalMutations : DocumentState::kSynced);
Expand Down Expand Up @@ -115,13 +115,13 @@
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd,
BOOL hasPendingWrites,
BOOL fromCache) {
FSTUserDataConverter *converter = FSTTestUserDataConverter();
FSTUserDataReader *reader = FSTTestUserDataReader();

SnapshotMetadata metadata(hasPendingWrites, fromCache);
DocumentSet oldDocuments(DocumentComparator::ByKey());
DocumentKeySet mutatedKeys;
for (NSString *key in oldDocs) {
FieldValue doc = [converter parsedQueryValue:oldDocs[key]];
FieldValue doc = [reader parsedQueryValue:oldDocs[key]];
std::string documentKey = util::StringFormat("%s/%s", path, key);
oldDocuments = oldDocuments.insert(
Doc(documentKey, 1, doc,
Expand All @@ -134,7 +134,7 @@
DocumentSet newDocuments = oldDocuments;
std::vector<DocumentViewChange> documentChanges;
for (NSString *key in docsToAdd) {
FieldValue doc = [converter parsedQueryValue:docsToAdd[key]];
FieldValue doc = [reader parsedQueryValue:docsToAdd[key]];
std::string documentKey = util::StringFormat("%s/%s", path, key);
Document docToAdd =
Doc(documentKey, 1, doc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/API/FSTUserDataReader.h"

#import <FirebaseFirestore/FIRFieldValue.h>
#import <FirebaseFirestore/FIRGeoPoint.h>
Expand Down Expand Up @@ -47,10 +47,10 @@
using firebase::firestore::nanopb::MakeNSData;
using firebase::firestore::testutil::Field;

@interface FSTUserDataConverterTests : XCTestCase
@interface FSTUserDataReaderTests : XCTestCase
@end

@implementation FSTUserDataConverterTests
@implementation FSTUserDataReaderTests

- (void)testConvertsIntegers {
NSArray<NSNumber *> *values = @[
Expand Down Expand Up @@ -95,7 +95,7 @@ - (void)testConvertsBooleans {
}

- (void)testConvertsUnsignedCharToInteger {
// See comments in FSTUserDataConverter regarding handling of signed char. Essentially, signed
// See comments in FSTUserDataReader regarding handling of signed char. Essentially, signed
// char has to be treated as boolean. Unsigned chars could conceivably be handled consistently
// with signed chars but on arm64 these end up being stored as signed shorts. This forces us to
// choose, and it's more useful to support shorts as Integers than it is to treat unsigned char as
Expand Down
2 changes: 1 addition & 1 deletion Firestore/Example/Tests/Integration/FSTDatastoreTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <vector>

#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/API/FSTUserDataReader.h"

#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"

Expand Down
10 changes: 5 additions & 5 deletions Firestore/Example/Tests/SpecTests/FSTSpecTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <utility>
#include <vector>

#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/API/FSTUserDataReader.h"

#import "Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h"
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
Expand Down Expand Up @@ -204,7 +204,7 @@ @implementation FSTSpecTests {
BOOL _gcEnabled;
size_t _maxConcurrentLimboResolutions;
BOOL _networkEnabled;
FSTUserDataConverter *_converter;
FSTUserDataReader *_reader;
std::shared_ptr<util::Executor> user_executor_;
}

Expand All @@ -230,7 +230,7 @@ - (BOOL)shouldRunWithTags:(NSArray<NSString *> *)tags {
}

- (void)setUpForSpecWithConfig:(NSDictionary *)config {
_converter = FSTTestUserDataConverter();
_reader = FSTTestUserDataReader();
std::unique_ptr<util::Executor> user_executor = util::Executor::CreateSerial("user executor");
user_executor_ = absl::ShareUniquePtr(std::move(user_executor));

Expand Down Expand Up @@ -298,7 +298,7 @@ - (Query)parseQuery:(id)querySpec {
for (NSArray<id> *filter in filters) {
std::string key = util::MakeString(filter[0]);
std::string op = util::MakeString(filter[1]);
FieldValue value = [_converter parsedQueryValue:filter[2]];
FieldValue value = [_reader parsedQueryValue:filter[2]];
query = query.AddingFilter(Filter(key, op, value));
}
}
Expand Down Expand Up @@ -332,7 +332,7 @@ - (DocumentViewChange)parseChange:(NSDictionary *)jsonDoc ofType:(DocumentViewCh
: DocumentState::kSynced);

XCTAssert([jsonDoc[@"key"] isKindOfClass:[NSString class]]);
FieldValue data = [_converter parsedQueryValue:jsonDoc[@"value"]];
FieldValue data = [_reader parsedQueryValue:jsonDoc[@"value"]];
Document doc = Doc(util::MakeString((NSString *)jsonDoc[@"key"]), version.longLongValue, data,
documentState);
return DocumentViewChange{doc, type};
Expand Down
4 changes: 2 additions & 2 deletions Firestore/Example/Tests/Util/FSTHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@class FIRGeoPoint;
@class FSTDocumentKeyReference;
@class FSTUserDataConverter;
@class FSTUserDataReader;

namespace model = firebase::firestore::model;

Expand Down Expand Up @@ -93,7 +93,7 @@ NSData *FSTTestData(int bytes, ...);
FIRGeoPoint *FSTTestGeoPoint(double latitude, double longitude);

/** Creates a user data converter set up for a generic project. */
FSTUserDataConverter *FSTTestUserDataConverter();
FSTUserDataReader *FSTTestUserDataReader();

/**
* Creates a new NSDateComponents from components. Note that year, month, and day are all
Expand Down
28 changes: 14 additions & 14 deletions Firestore/Example/Tests/Util/FSTHelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <set>
#include <utility>

#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/API/FSTUserDataReader.h"

#include "Firestore/core/src/core/user_data.h"
#include "Firestore/core/src/model/delete_mutation.h"
Expand Down Expand Up @@ -94,20 +94,20 @@
return comps;
}

FSTUserDataConverter *FSTTestUserDataConverter() {
FSTUserDataConverter *converter =
[[FSTUserDataConverter alloc] initWithDatabaseID:DatabaseId("project")
preConverter:^id _Nullable(id _Nullable input) {
return input;
}];
return converter;
FSTUserDataReader *FSTTestUserDataReader() {
FSTUserDataReader *reader =
[[FSTUserDataReader alloc] initWithDatabaseID:DatabaseId("project")
preConverter:^id _Nullable(id _Nullable input) {
return input;
}];
return reader;
}

FieldValue FSTTestFieldValue(id _Nullable value) {
FSTUserDataConverter *converter = FSTTestUserDataConverter();
FSTUserDataReader *reader = FSTTestUserDataReader();
// HACK: We use parsedQueryValue: since it accepts scalars as well as arrays / objects, and
// our tests currently use FSTTestFieldValue() pretty generically so we don't know the intent.
return [converter parsedQueryValue:value];
return [reader parsedQueryValue:value];
}

ObjectValue FSTTestObjectValue(NSDictionary<NSString *, id> *data) {
Expand All @@ -126,8 +126,8 @@ DocumentKey FSTTestDocKey(NSString *path) {
}

SetMutation FSTTestSetMutation(NSString *path, NSDictionary<NSString *, id> *values) {
FSTUserDataConverter *converter = FSTTestUserDataConverter();
ParsedSetData result = [converter parsedSetData:values];
FSTUserDataReader *reader = FSTTestUserDataReader();
ParsedSetData result = [reader parsedSetData:values];
return SetMutation(FSTTestDocKey(path), result.data(), Precondition::None(),
result.field_transforms());
}
Expand All @@ -144,8 +144,8 @@ PatchMutation FSTTestPatchMutation(NSString *path,
}
}];

FSTUserDataConverter *converter = FSTTestUserDataConverter();
ParsedUpdateData parsed = [converter parsedUpdateData:mutableValues];
FSTUserDataReader *reader = FSTTestUserDataReader();
ParsedUpdateData parsed = [reader parsedUpdateData:mutableValues];

DocumentKey key = FSTTestDocKey(path);

Expand Down
4 changes: 2 additions & 2 deletions Firestore/Source/API/FIRCollectionReference.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
#import "Firestore/Source/API/FIRFirestore+Internal.h"
#import "Firestore/Source/API/FIRQuery+Internal.h"
#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/API/FSTUserDataReader.h"

#include "Firestore/core/src/api/collection_reference.h"
#include "Firestore/core/src/api/document_reference.h"
Expand Down Expand Up @@ -115,7 +115,7 @@ - (FIRDocumentReference *)addDocumentWithData:(NSDictionary<NSString *, id> *)da
- (FIRDocumentReference *)addDocumentWithData:(NSDictionary<NSString *, id> *)data
completion:
(nullable void (^)(NSError *_Nullable error))completion {
ParsedSetData parsed = [self.firestore.dataConverter parsedSetData:data];
ParsedSetData parsed = [self.firestore.dataReader parsedSetData:data];
DocumentReference docRef =
self.reference.AddDocument(std::move(parsed), util::MakeCallback(completion));
return [[FIRDocumentReference alloc] initWithReference:std::move(docRef)];
Expand Down
14 changes: 7 additions & 7 deletions Firestore/Source/API/FIRDocumentReference.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#import "Firestore/Source/API/FIRFirestore+Internal.h"
#import "Firestore/Source/API/FIRFirestoreSource+Internal.h"
#import "Firestore/Source/API/FIRListenerRegistration+Internal.h"
#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/API/FSTUserDataReader.h"

#include "Firestore/core/src/api/collection_reference.h"
#include "Firestore/core/src/api/document_reference.h"
Expand Down Expand Up @@ -157,17 +157,17 @@ - (void)setData:(NSDictionary<NSString *, id> *)documentData
- (void)setData:(NSDictionary<NSString *, id> *)documentData
merge:(BOOL)merge
completion:(nullable void (^)(NSError *_Nullable error))completion {
auto dataConverter = self.firestore.dataConverter;
ParsedSetData parsed = merge ? [dataConverter parsedMergeData:documentData fieldMask:nil]
: [dataConverter parsedSetData:documentData];
auto dataReader = self.firestore.dataReader;
ParsedSetData parsed = merge ? [dataReader parsedMergeData:documentData fieldMask:nil]
: [dataReader parsedSetData:documentData];
_documentReference.SetData(std::move(parsed), util::MakeCallback(completion));
}

- (void)setData:(NSDictionary<NSString *, id> *)documentData
mergeFields:(NSArray<id> *)mergeFields
completion:(nullable void (^)(NSError *_Nullable error))completion {
ParsedSetData parsed = [self.firestore.dataConverter parsedMergeData:documentData
fieldMask:mergeFields];
ParsedSetData parsed = [self.firestore.dataReader parsedMergeData:documentData
fieldMask:mergeFields];
_documentReference.SetData(std::move(parsed), util::MakeCallback(completion));
}

Expand All @@ -177,7 +177,7 @@ - (void)updateData:(NSDictionary<id, id> *)fields {

- (void)updateData:(NSDictionary<id, id> *)fields
completion:(nullable void (^)(NSError *_Nullable error))completion {
ParsedUpdateData parsed = [self.firestore.dataConverter parsedUpdateData:fields];
ParsedUpdateData parsed = [self.firestore.dataReader parsedUpdateData:fields];
_documentReference.UpdateData(std::move(parsed), util::MakeCallback(completion));
}

Expand Down
2 changes: 2 additions & 0 deletions Firestore/Source/API/FIRDocumentSnapshot.mm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
* Converts a public FIRServerTimestampBehavior into its internal equivalent.
*/
ServerTimestampBehavior InternalServerTimestampBehavior(FIRServerTimestampBehavior behavior) {
// TODO(mutabledocuments): Remove since we only use FIRServerTimestampBehavior
switch (behavior) {
case FIRServerTimestampBehaviorNone:
return ServerTimestampBehavior::kNone;
Expand Down Expand Up @@ -207,6 +208,7 @@ - (FieldValueOptions)optionsForServerTimestampBehavior:
return FieldValueOptions(InternalServerTimestampBehavior(serverTimestampBehavior));
}

// TODO(mutabledocuments): Replace with UserDataWriter
- (id)convertedValue:(FieldValue)value options:(const FieldValueOptions &)options {
switch (value.type()) {
case FieldValue::Type::Null:
Expand Down
4 changes: 2 additions & 2 deletions Firestore/Source/API/FIRFirestore+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@class FIRApp;
@class FSTFirestoreClient;
@class FSTUserDataConverter;
@class FSTUserDataReader;

namespace firebase {
namespace firestore {
Expand Down Expand Up @@ -79,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, assign, readonly) std::shared_ptr<api::Firestore> wrapped;

@property(nonatomic, assign, readonly) const model::DatabaseId &databaseID;
@property(nonatomic, strong, readonly) FSTUserDataConverter *dataConverter;
@property(nonatomic, strong, readonly) FSTUserDataReader *dataReader;

@end

Expand Down
11 changes: 5 additions & 6 deletions Firestore/Source/API/FIRFirestore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#import "Firestore/Source/API/FIRTransaction+Internal.h"
#import "Firestore/Source/API/FIRWriteBatch+Internal.h"
#import "Firestore/Source/API/FSTFirestoreComponent.h"
#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/API/FSTUserDataReader.h"

#include "Firestore/core/src/api/collection_reference.h"
#include "Firestore/core/src/api/document_reference.h"
Expand Down Expand Up @@ -89,7 +89,7 @@

@interface FIRFirestore ()

@property(nonatomic, strong, readonly) FSTUserDataConverter *dataConverter;
@property(nonatomic, strong, readonly) FSTUserDataReader *dataReader;

@end

Expand Down Expand Up @@ -162,8 +162,8 @@ - (instancetype)initWithDatabaseID:(model::DatabaseId)databaseID
}
};

_dataConverter = [[FSTUserDataConverter alloc] initWithDatabaseID:_firestore->database_id()
preConverter:block];
_dataReader = [[FSTUserDataReader alloc] initWithDatabaseID:_firestore->database_id()
preConverter:block];
// Use the property setter so the default settings get plumbed into _firestoreClient.
self.settings = [[FIRFirestoreSettings alloc] init];
}
Expand Down Expand Up @@ -232,8 +232,7 @@ - (FIRQuery *)collectionGroupWithID:(NSString *)collectionID {
}

- (FIRWriteBatch *)batch {
return [FIRWriteBatch writeBatchWithDataConverter:self.dataConverter
writeBatch:_firestore->GetBatch()];
return [FIRWriteBatch writeBatchWithDataReader:self.dataReader writeBatch:_firestore->GetBatch()];
}

- (void)runTransactionWithBlock:(UserUpdateBlock)updateBlock
Expand Down
6 changes: 3 additions & 3 deletions Firestore/Source/API/FIRQuery.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#import "Firestore/Source/API/FIRQuery+Internal.h"
#import "Firestore/Source/API/FIRQuerySnapshot+Internal.h"
#import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h"
#import "Firestore/Source/API/FSTUserDataConverter.h"
#import "Firestore/Source/API/FSTUserDataReader.h"

#include "Firestore/core/src/api/query_core.h"
#include "Firestore/core/src/api/query_listener_registration.h"
Expand Down Expand Up @@ -474,11 +474,11 @@ - (FIRQuery *)queryEndingAtValues:(NSArray *)fieldValues {
#pragma mark - Private Methods

- (FieldValue)parsedQueryValue:(id)value {
return [self.firestore.dataConverter parsedQueryValue:value];
return [self.firestore.dataReader parsedQueryValue:value];
}

- (FieldValue)parsedQueryValue:(id)value allowArrays:(bool)allowArrays {
return [self.firestore.dataConverter parsedQueryValue:value allowArrays:allowArrays];
return [self.firestore.dataReader parsedQueryValue:value allowArrays:allowArrays];
}

- (QuerySnapshotListener)wrapQuerySnapshotBlock:(FIRQuerySnapshotBlock)block {
Expand Down
Loading