|
31 | 31 | #import "Firestore/Source/API/FIRFirestore+Internal.h"
|
32 | 32 | #import "Firestore/Source/API/FIRQuerySnapshot+Internal.h"
|
33 | 33 | #import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h"
|
34 |
| -#import "Firestore/Source/API/FSTUserDataConverter.h" |
| 34 | +#import "Firestore/Source/API/FSTUserDataReader.h" |
35 | 35 |
|
36 | 36 | #include "Firestore/core/src/core/view_snapshot.h"
|
37 | 37 | #include "Firestore/core/src/model/document.h"
|
38 | 38 | #include "Firestore/core/src/model/document_set.h"
|
| 39 | +#include "Firestore/core/src/model/mutable_document.h" |
| 40 | +#include "Firestore/core/src/nanopb/message.h" |
39 | 41 | #include "Firestore/core/src/remote/firebase_metadata_provider.h"
|
40 | 42 | #include "Firestore/core/src/util/string_apple.h"
|
41 | 43 | #include "Firestore/core/test/unit/testutil/testutil.h"
|
|
45 | 47 | using firebase::firestore::api::SnapshotMetadata;
|
46 | 48 | using firebase::firestore::core::DocumentViewChange;
|
47 | 49 | using firebase::firestore::core::ViewSnapshot;
|
| 50 | +using firebase::firestore::google_firestore_v1_Value; |
48 | 51 | using firebase::firestore::model::DatabaseId;
|
49 | 52 | using firebase::firestore::model::Document;
|
50 | 53 | using firebase::firestore::model::DocumentComparator;
|
51 | 54 | using firebase::firestore::model::DocumentKeySet;
|
52 | 55 | using firebase::firestore::model::DocumentSet;
|
53 |
| -using firebase::firestore::model::DocumentState; |
54 |
| -using firebase::firestore::model::FieldValue; |
| 56 | +using firebase::firestore::model::MutableDocument; |
| 57 | +using firebase::firestore::nanopb::Message; |
55 | 58 |
|
56 | 59 | using testutil::Doc;
|
57 | 60 | using testutil::Query;
|
|
82 | 85 | NSDictionary<NSString *, id> *_Nullable data,
|
83 | 86 | BOOL hasMutations,
|
84 | 87 | BOOL fromCache) {
|
85 |
| - absl::optional<Document> doc; |
| 88 | + absl::optional<MutableDocument> doc; |
86 | 89 | if (data) {
|
87 |
| - FSTUserDataConverter *converter = FSTTestUserDataConverter(); |
88 |
| - FieldValue parsed = [converter parsedQueryValue:data]; |
| 90 | + FSTUserDataReader *reader = FSTTestUserDataReader(); |
| 91 | + Message<google_firestore_v1_Value> parsed = [reader parsedQueryValue:data]; |
89 | 92 |
|
90 |
| - doc = Doc(path, version, parsed, |
91 |
| - hasMutations ? DocumentState::kLocalMutations : DocumentState::kSynced); |
| 93 | + doc = Doc(path, version, std::move(parsed)); |
| 94 | + if (hasMutations) doc->SetHasLocalMutations(); |
92 | 95 | }
|
93 |
| - return [[FIRDocumentSnapshot alloc] initWithFirestore:FSTTestFirestore().wrapped |
| 96 | + return [[FIRDocumentSnapshot alloc] initWithFirestore:FSTTestFirestore() |
94 | 97 | documentKey:testutil::Key(path)
|
95 | 98 | document:doc
|
96 | 99 | fromCache:fromCache
|
|
114 | 117 | NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd,
|
115 | 118 | BOOL hasPendingWrites,
|
116 | 119 | BOOL fromCache) {
|
117 |
| - FSTUserDataConverter *converter = FSTTestUserDataConverter(); |
| 120 | + FSTUserDataReader *reader = FSTTestUserDataReader(); |
118 | 121 |
|
119 | 122 | SnapshotMetadata metadata(hasPendingWrites, fromCache);
|
120 | 123 | DocumentSet oldDocuments(DocumentComparator::ByKey());
|
121 | 124 | DocumentKeySet mutatedKeys;
|
122 | 125 | for (NSString *key in oldDocs) {
|
123 |
| - FieldValue doc = [converter parsedQueryValue:oldDocs[key]]; |
| 126 | + Message<google_firestore_v1_Value> value = [reader parsedQueryValue:oldDocs[key]]; |
124 | 127 | std::string documentKey = util::StringFormat("%s/%s", path, key);
|
125 |
| - oldDocuments = oldDocuments.insert( |
126 |
| - Doc(documentKey, 1, doc, |
127 |
| - hasPendingWrites ? DocumentState::kLocalMutations : DocumentState::kSynced)); |
| 128 | + MutableDocument doc = Doc(documentKey, 1, std::move(value)); |
128 | 129 | if (hasPendingWrites) {
|
129 | 130 | mutatedKeys = mutatedKeys.insert(testutil::Key(documentKey));
|
| 131 | + doc.SetHasLocalMutations(); |
130 | 132 | }
|
| 133 | + oldDocuments = oldDocuments.insert(doc); |
131 | 134 | }
|
132 | 135 |
|
133 | 136 | DocumentSet newDocuments = oldDocuments;
|
134 | 137 | std::vector<DocumentViewChange> documentChanges;
|
135 | 138 | for (NSString *key in docsToAdd) {
|
136 |
| - FieldValue doc = [converter parsedQueryValue:docsToAdd[key]]; |
| 139 | + Message<google_firestore_v1_Value> value = [reader parsedQueryValue:docsToAdd[key]]; |
137 | 140 | std::string documentKey = util::StringFormat("%s/%s", path, key);
|
138 |
| - Document docToAdd = |
139 |
| - Doc(documentKey, 1, doc, |
140 |
| - hasPendingWrites ? DocumentState::kLocalMutations : DocumentState::kSynced); |
141 |
| - newDocuments = newDocuments.insert(docToAdd); |
142 |
| - documentChanges.emplace_back(docToAdd, DocumentViewChange::Type::Added); |
| 141 | + MutableDocument doc = Doc(documentKey, 1, std::move(value)); |
| 142 | + documentChanges.emplace_back(doc, DocumentViewChange::Type::Added); |
143 | 143 | if (hasPendingWrites) {
|
144 | 144 | mutatedKeys = mutatedKeys.insert(testutil::Key(documentKey));
|
| 145 | + doc.SetHasLocalMutations(); |
145 | 146 | }
|
| 147 | + newDocuments = newDocuments.insert(doc); |
146 | 148 | }
|
147 | 149 | ViewSnapshot viewSnapshot{Query(path),
|
148 | 150 | newDocuments,
|
|
0 commit comments