Skip to content

Commit 4130692

Browse files
committed
Merge branch 'main' into feature/m98-release-update-dependencies
2 parents b9cbfcf + 090eb4d commit 4130692

File tree

9 files changed

+151
-1
lines changed

9 files changed

+151
-1
lines changed

cmake/external/firestore.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if(TARGET firestore)
1818
return()
1919
endif()
2020

21-
set(version CocoaPods-7.11.0)
21+
set(version CocoaPods-8.2.0)
2222
ExternalProject_Add(
2323
firestore
2424

firestore/integration_test_internal/Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
source 'https://github.com/CocoaPods/Specs.git'
2+
platform :ios, '10.0'
23
# Cloud Firestore internal test application.
34

45
target 'integration_test' do

firestore/integration_test_internal/integration_test.xcodeproj/project.pbxproj

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

firestore/integration_test_internal/src/bundle_test.cc

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,25 @@ class BundleTest : public FirestoreIntegrationTest {
9494
MapFieldValue{{"k", FieldValue::String("b")},
9595
{"bar", FieldValue::Integer(2)}}));
9696
}
97+
98+
{
99+
Query limit = AwaitResult(db->NamedQuery(kLimitQueryName));
100+
auto limit_snapshot = AwaitResult(limit.Get(Source::kCache));
101+
EXPECT_THAT(
102+
QuerySnapshotToValues(limit_snapshot),
103+
testing::ElementsAre(MapFieldValue{{"k", FieldValue::String("b")},
104+
{"bar", FieldValue::Integer(2)}}));
105+
}
106+
107+
{
108+
Query limit_to_last = AwaitResult(db->NamedQuery(kLimitToLastQueryName));
109+
auto limit_to_last_snapshot =
110+
AwaitResult(limit_to_last.Get(Source::kCache));
111+
EXPECT_THAT(
112+
QuerySnapshotToValues(limit_to_last_snapshot),
113+
testing::ElementsAre(MapFieldValue{{"k", FieldValue::String("a")},
114+
{"bar", FieldValue::Integer(1)}}));
115+
}
97116
}
98117
};
99118

@@ -240,6 +259,21 @@ TEST_F(BundleTest, LoadBundleWithDocumentsAlreadyPulledFromBackend) {
240259
testing::ElementsAre(
241260
MapFieldValue{{"bar", FieldValue::String("newValueA")}},
242261
MapFieldValue{{"bar", FieldValue::String("newValueB")}}));
262+
263+
{
264+
Query limit = AwaitResult(db->NamedQuery(kLimitQueryName));
265+
EXPECT_THAT(QuerySnapshotToValues(AwaitResult(limit.Get(Source::kCache))),
266+
testing::ElementsAre(
267+
MapFieldValue{{"bar", FieldValue::String("newValueB")}}));
268+
}
269+
270+
{
271+
Query limit_to_last = AwaitResult(db->NamedQuery(kLimitToLastQueryName));
272+
EXPECT_THAT(
273+
QuerySnapshotToValues(AwaitResult(limit_to_last.Get(Source::kCache))),
274+
testing::ElementsAre(
275+
MapFieldValue{{"bar", FieldValue::String("newValueA")}}));
276+
}
243277
}
244278

245279
TEST_F(BundleTest, LoadedDocumentsShouldNotBeGarbageCollectedRightAway) {
@@ -282,6 +316,28 @@ TEST_F(BundleTest, LoadDocumentsFromOtherProjectsShouldFail) {
282316
VerifyErrorProgress(progresses[1]);
283317
}
284318

319+
TEST_F(BundleTest, GetInvalidNamedQuery) {
320+
Firestore* db = TestFirestore();
321+
{
322+
auto future = db->NamedQuery("DOES_NOT_EXIST");
323+
Await(future);
324+
EXPECT_EQ(future.status(), FutureStatus::kFutureStatusComplete);
325+
EXPECT_EQ(future.error(), Error::kErrorNotFound);
326+
}
327+
{
328+
auto future = db->NamedQuery("");
329+
Await(future);
330+
EXPECT_EQ(future.status(), FutureStatus::kFutureStatusComplete);
331+
EXPECT_EQ(future.error(), Error::kErrorNotFound);
332+
}
333+
{
334+
auto future = db->NamedQuery("\xc3\x28");
335+
Await(future);
336+
EXPECT_EQ(future.status(), FutureStatus::kFutureStatusComplete);
337+
EXPECT_EQ(future.error(), Error::kErrorNotFound);
338+
}
339+
}
340+
285341
} // namespace
286342
} // namespace firestore
287343
} // namespace firebase

firestore/src/common/firestore.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,5 +338,10 @@ Future<LoadBundleTaskProgress> Firestore::LoadBundle(
338338
return internal_->LoadBundle(bundle, std::move(progress_callback));
339339
}
340340

341+
Future<Query> Firestore::NamedQuery(const std::string& query_name) {
342+
if (!internal_) return FailedFuture<Query>();
343+
return internal_->NamedQuery(query_name);
344+
}
345+
341346
} // namespace firestore
342347
} // namespace firebase

firestore/src/include/firebase/firestore.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,21 @@ class Firestore {
429429
const std::string& bundle,
430430
std::function<void(const LoadBundleTaskProgress&)> progress_callback);
431431

432+
/**
433+
* Reads a Firestore `Query` from the local cache, identified by the given
434+
* name.
435+
*
436+
* Named queries are packaged into bundles on the server side (along with the
437+
* resulting documents) and loaded into local cache using `LoadBundle`. Once
438+
* in the local cache, you can use this method to extract a query by name.
439+
*
440+
* If a query cannot be found, the returned future will complete with its
441+
* `error()` set to a non-zero error code.
442+
*
443+
* @param query_name The name of the query to read from saved bundles.
444+
*/
445+
virtual Future<Query> NamedQuery(const std::string& query_name);
446+
432447
protected:
433448
/**
434449
* Default constructor, to be used only for mocking `Firestore`.

firestore/src/main/firestore_main.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,5 +377,21 @@ Future<LoadBundleTaskProgress> FirestoreInternal::LoadBundle(
377377
return promise.future();
378378
}
379379

380+
Future<Query> FirestoreInternal::NamedQuery(const std::string& query_name) {
381+
auto promise = promise_factory_.CreatePromise<Query>(AsyncApi::kNamedQuery);
382+
firestore_core_->GetNamedQuery(
383+
query_name,
384+
[this, promise](const core::Query& query, bool found) mutable {
385+
if (found) {
386+
promise.SetValue(MakePublic(api::Query(query, firestore_core_)));
387+
} else {
388+
promise.SetError(
389+
Status(Error::kErrorNotFound, "Named query cannot be found"));
390+
}
391+
});
392+
393+
return promise.future();
394+
}
395+
380396
} // namespace firestore
381397
} // namespace firebase

firestore/src/main/firestore_main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class FirestoreInternal {
9292
Future<LoadBundleTaskProgress> LoadBundle(
9393
const std::string& bundle,
9494
std::function<void(const LoadBundleTaskProgress&)> progress_callback);
95+
Future<Query> NamedQuery(const std::string& query_name);
9596

9697
// Manages the ListenerRegistrationInternal objects.
9798
void RegisterListenerRegistration(ListenerRegistrationInternal* registration);

release_build_files/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ code.
571571
- Changes
572572
- Firestore: Fixed a linker error when `DocumentChange::npos` was used.
573573
([#474](https://github.com/firebase/firebase-cpp-sdk/pull/474)).
574+
- Firestore: Added `Firestore::NamedQuery` that allows reading the queries
575+
used to build a Firestore Data Bundle.
574576

575577
### 8.0.0
576578
- Changes

0 commit comments

Comments
 (0)