|
64 | 64 | using firebase::firestore::api::CollectionSource; |
65 | 65 | using firebase::firestore::api::Constant; |
66 | 66 | using firebase::firestore::api::DatabaseSource; |
| 67 | +using firebase::firestore::api::DefineStage; |
67 | 68 | using firebase::firestore::api::DistinctStage; |
68 | 69 | using firebase::firestore::api::DocumentChange; |
69 | 70 | using firebase::firestore::api::DocumentReference; |
|
88 | 89 | using firebase::firestore::api::SelectStage; |
89 | 90 | using firebase::firestore::api::SnapshotMetadata; |
90 | 91 | using firebase::firestore::api::SortStage; |
| 92 | +using firebase::firestore::api::SubcollectionSource; |
91 | 93 | using firebase::firestore::api::Union; |
92 | 94 | using firebase::firestore::api::Unnest; |
| 95 | +using firebase::firestore::api::Variable; |
93 | 96 | using firebase::firestore::api::Where; |
94 | 97 | using firebase::firestore::core::EventListener; |
95 | 98 | using firebase::firestore::core::ViewSnapshot; |
@@ -148,6 +151,30 @@ - (NSString *)field_name { |
148 | 151 |
|
149 | 152 | @end |
150 | 153 |
|
| 154 | +@implementation FIRVariableBridge { |
| 155 | + std::shared_ptr<Variable> cpp_variable; |
| 156 | + NSString *_name; |
| 157 | + Boolean isUserDataRead; |
| 158 | +} |
| 159 | + |
| 160 | +- (id)initWithName:(NSString *)name { |
| 161 | + self = [super init]; |
| 162 | + if (self) { |
| 163 | + _name = name; |
| 164 | + isUserDataRead = NO; |
| 165 | + } |
| 166 | + return self; |
| 167 | +} |
| 168 | + |
| 169 | +- (std::shared_ptr<api::Expr>)cppExprWithReader:(FSTUserDataReader *)reader { |
| 170 | + if (!isUserDataRead) { |
| 171 | + cpp_variable = std::make_shared<Variable>(MakeString(_name)); |
| 172 | + } |
| 173 | + isUserDataRead = YES; |
| 174 | + return cpp_variable; |
| 175 | +} |
| 176 | +@end |
| 177 | + |
151 | 178 | @implementation FIRConstantBridge { |
152 | 179 | std::shared_ptr<Constant> cpp_constant; |
153 | 180 | id _input; |
@@ -302,6 +329,27 @@ - (NSString *)name { |
302 | 329 | } |
303 | 330 | @end |
304 | 331 |
|
| 332 | +@implementation FIRSubcollectionSourceStageBridge { |
| 333 | + std::shared_ptr<SubcollectionSource> cpp_subcollection_source; |
| 334 | +} |
| 335 | + |
| 336 | +- (id)initWithPath:(NSString *)path { |
| 337 | + self = [super init]; |
| 338 | + if (self) { |
| 339 | + cpp_subcollection_source = std::make_shared<SubcollectionSource>(MakeString(path)); |
| 340 | + } |
| 341 | + return self; |
| 342 | +} |
| 343 | + |
| 344 | +- (std::shared_ptr<api::Stage>)cppStageWithReader:(FSTUserDataReader *)reader { |
| 345 | + return cpp_subcollection_source; |
| 346 | +} |
| 347 | + |
| 348 | +- (NSString *)name { |
| 349 | + return @"subcollection"; |
| 350 | +} |
| 351 | +@end |
| 352 | + |
305 | 353 | @implementation FIRDatabaseSourceStageBridge { |
306 | 354 | std::shared_ptr<DatabaseSource> cpp_database_source; |
307 | 355 | } |
@@ -617,6 +665,38 @@ - (NSString *)name { |
617 | 665 | } |
618 | 666 | @end |
619 | 667 |
|
| 668 | +@implementation FIRDefineStageBridge { |
| 669 | + NSDictionary<NSString *, FIRExprBridge *> *_variables; |
| 670 | + Boolean isUserDataRead; |
| 671 | + std::shared_ptr<DefineStage> cpp_define; |
| 672 | +} |
| 673 | + |
| 674 | +- (id)initWithVariables:(NSDictionary<NSString *, FIRExprBridge *> *)variables { |
| 675 | + self = [super init]; |
| 676 | + if (self) { |
| 677 | + _variables = variables; |
| 678 | + isUserDataRead = NO; |
| 679 | + } |
| 680 | + return self; |
| 681 | +} |
| 682 | + |
| 683 | +- (std::shared_ptr<api::Stage>)cppStageWithReader:(FSTUserDataReader *)reader { |
| 684 | + if (!isUserDataRead) { |
| 685 | + std::unordered_map<std::string, std::shared_ptr<Expr>> cpp_fields; |
| 686 | + for (NSString *key in _variables) { |
| 687 | + cpp_fields[MakeString(key)] = [_variables[key] cppExprWithReader:reader]; |
| 688 | + } |
| 689 | + cpp_define = std::make_shared<DefineStage>(std::move(cpp_fields)); |
| 690 | + } |
| 691 | + isUserDataRead = YES; |
| 692 | + return cpp_define; |
| 693 | +} |
| 694 | + |
| 695 | +- (NSString *)name { |
| 696 | + return @"let"; |
| 697 | +} |
| 698 | +@end |
| 699 | + |
620 | 700 | @implementation FIRDistinctStageBridge { |
621 | 701 | NSDictionary<NSString *, FIRExprBridge *> *_groups; |
622 | 702 | Boolean isUserDataRead; |
@@ -1205,7 +1285,30 @@ - (id)initWithCppChange:(api::PipelineResultChange)change db:(std::shared_ptr<ap |
1205 | 1285 |
|
1206 | 1286 | return self; |
1207 | 1287 | } |
| 1288 | +@end |
1208 | 1289 |
|
| 1290 | +@implementation FIRPipelineExprBridge { |
| 1291 | + NSArray<FIRStageBridge *> *_stages; |
| 1292 | + Boolean isUserDataRead; |
| 1293 | + std::vector<std::shared_ptr<api::Stage>> cpp_stages; |
| 1294 | +} |
| 1295 | +- (id)initWithStages:(NSArray<FIRStageBridge *> *)stages { |
| 1296 | + self = [super init]; |
| 1297 | + if (self) { |
| 1298 | + _stages = stages; |
| 1299 | + isUserDataRead = NO; |
| 1300 | + } |
| 1301 | + return self; |
| 1302 | +} |
| 1303 | +- (std::shared_ptr<api::Expr>)cppExprWithReader:(FSTUserDataReader *)reader { |
| 1304 | + if (!isUserDataRead) { |
| 1305 | + for (FIRStageBridge *stage in _stages) { |
| 1306 | + cpp_stages.push_back([stage cppStageWithReader:reader]); |
| 1307 | + } |
| 1308 | + isUserDataRead = YES; |
| 1309 | + } |
| 1310 | + return std::make_shared<api::PipelineExpr>(cpp_stages); |
| 1311 | +} |
1209 | 1312 | @end |
1210 | 1313 |
|
1211 | 1314 | @implementation FIRPipelineBridge { |
@@ -1240,7 +1343,7 @@ - (void)executeWithCompletion:(void (^)(__FIRPipelineSnapshotBridge *_Nullable r |
1240 | 1343 | if (!isUserDataRead) { |
1241 | 1344 | std::vector<std::shared_ptr<firebase::firestore::api::Stage>> cpp_stages; |
1242 | 1345 | for (FIRStageBridge *stage in _stages) { |
1243 | | - cpp_stages.push_back([stage cppStageWithReader:firestore.dataReader]); |
| 1346 | + cpp_stages.push_back([stage cppStageWithReader:reader]); |
1244 | 1347 | } |
1245 | 1348 | cpp_pipeline = std::make_shared<Pipeline>(cpp_stages, firestore.wrapped); |
1246 | 1349 | } |
|
0 commit comments