Skip to content

Commit 38cefe1

Browse files
UserDataReader (#7843)
1 parent 1d7f0d5 commit 38cefe1

21 files changed

+1326
-154
lines changed

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 14 additions & 14 deletions
Large diffs are not rendered by default.

Firestore/Example/Tests/API/FSTAPIHelpers.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#import "Firestore/Source/API/FIRFirestore+Internal.h"
3232
#import "Firestore/Source/API/FIRQuerySnapshot+Internal.h"
3333
#import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h"
34-
#import "Firestore/Source/API/FSTUserDataConverter.h"
34+
#import "Firestore/Source/API/FSTUserDataReader.h"
3535

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

9191
doc = Doc(path, version, parsed,
9292
hasMutations ? DocumentState::kLocalMutations : DocumentState::kSynced);
@@ -115,13 +115,13 @@
115115
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd,
116116
BOOL hasPendingWrites,
117117
BOOL fromCache) {
118-
FSTUserDataConverter *converter = FSTTestUserDataConverter();
118+
FSTUserDataReader *reader = FSTTestUserDataReader();
119119

120120
SnapshotMetadata metadata(hasPendingWrites, fromCache);
121121
DocumentSet oldDocuments(DocumentComparator::ByKey());
122122
DocumentKeySet mutatedKeys;
123123
for (NSString *key in oldDocs) {
124-
FieldValue doc = [converter parsedQueryValue:oldDocs[key]];
124+
FieldValue doc = [reader parsedQueryValue:oldDocs[key]];
125125
std::string documentKey = util::StringFormat("%s/%s", path, key);
126126
oldDocuments = oldDocuments.insert(
127127
Doc(documentKey, 1, doc,
@@ -134,7 +134,7 @@
134134
DocumentSet newDocuments = oldDocuments;
135135
std::vector<DocumentViewChange> documentChanges;
136136
for (NSString *key in docsToAdd) {
137-
FieldValue doc = [converter parsedQueryValue:docsToAdd[key]];
137+
FieldValue doc = [reader parsedQueryValue:docsToAdd[key]];
138138
std::string documentKey = util::StringFormat("%s/%s", path, key);
139139
Document docToAdd =
140140
Doc(documentKey, 1, doc,

Firestore/Example/Tests/API/FSTUserDataConverterTests.mm renamed to Firestore/Example/Tests/API/FSTUserDataReaderTests.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#import "Firestore/Source/API/FSTUserDataConverter.h"
17+
#import "Firestore/Source/API/FSTUserDataReader.h"
1818

1919
#import <FirebaseFirestore/FIRFieldValue.h>
2020
#import <FirebaseFirestore/FIRGeoPoint.h>
@@ -47,10 +47,10 @@
4747
using firebase::firestore::nanopb::MakeNSData;
4848
using firebase::firestore::testutil::Field;
4949

50-
@interface FSTUserDataConverterTests : XCTestCase
50+
@interface FSTUserDataReaderTests : XCTestCase
5151
@end
5252

53-
@implementation FSTUserDataConverterTests
53+
@implementation FSTUserDataReaderTests
5454

5555
- (void)testConvertsIntegers {
5656
NSArray<NSNumber *> *values = @[
@@ -95,7 +95,7 @@ - (void)testConvertsBooleans {
9595
}
9696

9797
- (void)testConvertsUnsignedCharToInteger {
98-
// See comments in FSTUserDataConverter regarding handling of signed char. Essentially, signed
98+
// See comments in FSTUserDataReader regarding handling of signed char. Essentially, signed
9999
// char has to be treated as boolean. Unsigned chars could conceivably be handled consistently
100100
// with signed chars but on arm64 these end up being stored as signed shorts. This forces us to
101101
// choose, and it's more useful to support shorts as Integers than it is to treat unsigned char as

Firestore/Example/Tests/Integration/FSTDatastoreTests.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <vector>
2424

2525
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
26-
#import "Firestore/Source/API/FSTUserDataConverter.h"
26+
#import "Firestore/Source/API/FSTUserDataReader.h"
2727

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

Firestore/Example/Tests/SpecTests/FSTSpecTests.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <utility>
3232
#include <vector>
3333

34-
#import "Firestore/Source/API/FSTUserDataConverter.h"
34+
#import "Firestore/Source/API/FSTUserDataReader.h"
3535

3636
#import "Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h"
3737
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
@@ -204,7 +204,7 @@ @implementation FSTSpecTests {
204204
BOOL _gcEnabled;
205205
size_t _maxConcurrentLimboResolutions;
206206
BOOL _networkEnabled;
207-
FSTUserDataConverter *_converter;
207+
FSTUserDataReader *_reader;
208208
std::shared_ptr<util::Executor> user_executor_;
209209
}
210210

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

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

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

334334
XCTAssert([jsonDoc[@"key"] isKindOfClass:[NSString class]]);
335-
FieldValue data = [_converter parsedQueryValue:jsonDoc[@"value"]];
335+
FieldValue data = [_reader parsedQueryValue:jsonDoc[@"value"]];
336336
Document doc = Doc(util::MakeString((NSString *)jsonDoc[@"key"]), version.longLongValue, data,
337337
documentState);
338338
return DocumentViewChange{doc, type};

Firestore/Example/Tests/Util/FSTHelpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
@class FIRGeoPoint;
2626
@class FSTDocumentKeyReference;
27-
@class FSTUserDataConverter;
27+
@class FSTUserDataReader;
2828

2929
namespace model = firebase::firestore::model;
3030

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

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

9898
/**
9999
* Creates a new NSDateComponents from components. Note that year, month, and day are all

Firestore/Example/Tests/Util/FSTHelpers.mm

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <set>
2323
#include <utility>
2424

25-
#import "Firestore/Source/API/FSTUserDataConverter.h"
25+
#import "Firestore/Source/API/FSTUserDataReader.h"
2626

2727
#include "Firestore/core/src/core/user_data.h"
2828
#include "Firestore/core/src/model/delete_mutation.h"
@@ -94,20 +94,20 @@
9494
return comps;
9595
}
9696

97-
FSTUserDataConverter *FSTTestUserDataConverter() {
98-
FSTUserDataConverter *converter =
99-
[[FSTUserDataConverter alloc] initWithDatabaseID:DatabaseId("project")
100-
preConverter:^id _Nullable(id _Nullable input) {
101-
return input;
102-
}];
103-
return converter;
97+
FSTUserDataReader *FSTTestUserDataReader() {
98+
FSTUserDataReader *reader =
99+
[[FSTUserDataReader alloc] initWithDatabaseID:DatabaseId("project")
100+
preConverter:^id _Nullable(id _Nullable input) {
101+
return input;
102+
}];
103+
return reader;
104104
}
105105

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

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

128128
SetMutation FSTTestSetMutation(NSString *path, NSDictionary<NSString *, id> *values) {
129-
FSTUserDataConverter *converter = FSTTestUserDataConverter();
130-
ParsedSetData result = [converter parsedSetData:values];
129+
FSTUserDataReader *reader = FSTTestUserDataReader();
130+
ParsedSetData result = [reader parsedSetData:values];
131131
return SetMutation(FSTTestDocKey(path), result.data(), Precondition::None(),
132132
result.field_transforms());
133133
}
@@ -144,8 +144,8 @@ PatchMutation FSTTestPatchMutation(NSString *path,
144144
}
145145
}];
146146

147-
FSTUserDataConverter *converter = FSTTestUserDataConverter();
148-
ParsedUpdateData parsed = [converter parsedUpdateData:mutableValues];
147+
FSTUserDataReader *reader = FSTTestUserDataReader();
148+
ParsedUpdateData parsed = [reader parsedUpdateData:mutableValues];
149149

150150
DocumentKey key = FSTTestDocKey(path);
151151

Firestore/Source/API/FIRCollectionReference.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
2222
#import "Firestore/Source/API/FIRFirestore+Internal.h"
2323
#import "Firestore/Source/API/FIRQuery+Internal.h"
24-
#import "Firestore/Source/API/FSTUserDataConverter.h"
24+
#import "Firestore/Source/API/FSTUserDataReader.h"
2525

2626
#include "Firestore/core/src/api/collection_reference.h"
2727
#include "Firestore/core/src/api/document_reference.h"
@@ -115,7 +115,7 @@ - (FIRDocumentReference *)addDocumentWithData:(NSDictionary<NSString *, id> *)da
115115
- (FIRDocumentReference *)addDocumentWithData:(NSDictionary<NSString *, id> *)data
116116
completion:
117117
(nullable void (^)(NSError *_Nullable error))completion {
118-
ParsedSetData parsed = [self.firestore.dataConverter parsedSetData:data];
118+
ParsedSetData parsed = [self.firestore.dataReader parsedSetData:data];
119119
DocumentReference docRef =
120120
self.reference.AddDocument(std::move(parsed), util::MakeCallback(completion));
121121
return [[FIRDocumentReference alloc] initWithReference:std::move(docRef)];

Firestore/Source/API/FIRDocumentReference.mm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#import "Firestore/Source/API/FIRFirestore+Internal.h"
2727
#import "Firestore/Source/API/FIRFirestoreSource+Internal.h"
2828
#import "Firestore/Source/API/FIRListenerRegistration+Internal.h"
29-
#import "Firestore/Source/API/FSTUserDataConverter.h"
29+
#import "Firestore/Source/API/FSTUserDataReader.h"
3030

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

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

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

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

Firestore/Source/API/FIRDocumentSnapshot.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
* Converts a public FIRServerTimestampBehavior into its internal equivalent.
7373
*/
7474
ServerTimestampBehavior InternalServerTimestampBehavior(FIRServerTimestampBehavior behavior) {
75+
// TODO(mutabledocuments): Remove since we only use FIRServerTimestampBehavior
7576
switch (behavior) {
7677
case FIRServerTimestampBehaviorNone:
7778
return ServerTimestampBehavior::kNone;
@@ -207,6 +208,7 @@ - (FieldValueOptions)optionsForServerTimestampBehavior:
207208
return FieldValueOptions(InternalServerTimestampBehavior(serverTimestampBehavior));
208209
}
209210

211+
// TODO(mutabledocuments): Replace with UserDataWriter
210212
- (id)convertedValue:(FieldValue)value options:(const FieldValueOptions &)options {
211213
switch (value.type()) {
212214
case FieldValue::Type::Null:

Firestore/Source/API/FIRFirestore+Internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
@class FIRApp;
2727
@class FSTFirestoreClient;
28-
@class FSTUserDataConverter;
28+
@class FSTUserDataReader;
2929

3030
namespace firebase {
3131
namespace firestore {
@@ -79,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
7979
@property(nonatomic, assign, readonly) std::shared_ptr<api::Firestore> wrapped;
8080

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

8484
@end
8585

Firestore/Source/API/FIRFirestore.mm

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#import "Firestore/Source/API/FIRTransaction+Internal.h"
3232
#import "Firestore/Source/API/FIRWriteBatch+Internal.h"
3333
#import "Firestore/Source/API/FSTFirestoreComponent.h"
34-
#import "Firestore/Source/API/FSTUserDataConverter.h"
34+
#import "Firestore/Source/API/FSTUserDataReader.h"
3535

3636
#include "Firestore/core/src/api/collection_reference.h"
3737
#include "Firestore/core/src/api/document_reference.h"
@@ -89,7 +89,7 @@
8989

9090
@interface FIRFirestore ()
9191

92-
@property(nonatomic, strong, readonly) FSTUserDataConverter *dataConverter;
92+
@property(nonatomic, strong, readonly) FSTUserDataReader *dataReader;
9393

9494
@end
9595

@@ -162,8 +162,8 @@ - (instancetype)initWithDatabaseID:(model::DatabaseId)databaseID
162162
}
163163
};
164164

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

234234
- (FIRWriteBatch *)batch {
235-
return [FIRWriteBatch writeBatchWithDataConverter:self.dataConverter
236-
writeBatch:_firestore->GetBatch()];
235+
return [FIRWriteBatch writeBatchWithDataReader:self.dataReader writeBatch:_firestore->GetBatch()];
237236
}
238237

239238
- (void)runTransactionWithBlock:(UserUpdateBlock)updateBlock

Firestore/Source/API/FIRQuery.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#import "Firestore/Source/API/FIRQuery+Internal.h"
3333
#import "Firestore/Source/API/FIRQuerySnapshot+Internal.h"
3434
#import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h"
35-
#import "Firestore/Source/API/FSTUserDataConverter.h"
35+
#import "Firestore/Source/API/FSTUserDataReader.h"
3636

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

476476
- (FieldValue)parsedQueryValue:(id)value {
477-
return [self.firestore.dataConverter parsedQueryValue:value];
477+
return [self.firestore.dataReader parsedQueryValue:value];
478478
}
479479

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

484484
- (QuerySnapshotListener)wrapQuerySnapshotBlock:(FIRQuerySnapshotBlock)block {

0 commit comments

Comments
 (0)