diff --git a/Firestore/CHANGELOG.md b/Firestore/CHANGELOG.md index b4bec1f0956..3fe548fa2e2 100644 --- a/Firestore/CHANGELOG.md +++ b/Firestore/CHANGELOG.md @@ -1,6 +1,4 @@ # Unreleased -- [feature] Added `Query.count()`, which fetches the number of documents in the - result set without actually downloading the documents (#10246). - [fixed] Fixed compiler warning about `@param comparator` (#10226). # 9.6.0 diff --git a/Firestore/Example/Tests/Integration/API/FIRCountTests.mm b/Firestore/Example/Tests/Integration/API/FIRCountTests.mm index 7f27ffb2fb5..5a89aeb49dc 100644 --- a/Firestore/Example/Tests/Integration/API/FIRCountTests.mm +++ b/Firestore/Example/Tests/Integration/API/FIRCountTests.mm @@ -19,9 +19,9 @@ #import #import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h" -#import "Firestore/Source/Public/FirebaseFirestore/FIRAggregateQuery.h" -#import "Firestore/Source/Public/FirebaseFirestore/FIRAggregateQuerySnapshot.h" -#import "Firestore/Source/Public/FirebaseFirestore/FIRAggregateSource.h" +#import "Firestore/Source/API/FIRAggregateQuery+Internal.h" +#import "Firestore/Source/API/FIRAggregateQuerySnapshot+Internal.h" +#import "Firestore/Source/API/FIRQuery+Internal.h" @interface FIRCountTests : FSTIntegrationTestCase @end diff --git a/Firestore/Source/API/FIRAggregateQuery+Internal.h b/Firestore/Source/API/FIRAggregateQuery+Internal.h index 0be28a8faa4..1627abf7b5b 100644 --- a/Firestore/Source/API/FIRAggregateQuery+Internal.h +++ b/Firestore/Source/API/FIRAggregateQuery+Internal.h @@ -14,12 +14,35 @@ * limitations under the License. */ -#import "FIRAggregateQuery.h" +// TODO(b/246760853): Move FIRAggregateQuery to public headers to release it. + +#import "FIRAggregateSource+Internal.h" #import "FIRQuery.h" -@interface FIRAggregateQuery (/* init */) +@class FIRAggregateQuerySnapshot; + +/** + * An `AggregateQuery` computes some aggregation statistics from the result set of a base + * `Query`. + */ +NS_SWIFT_NAME(AggregateQuery) +@interface FIRAggregateQuery : NSObject - (instancetype _Nonnull)init NS_UNAVAILABLE; - (instancetype _Nonnull)initWithQuery:(FIRQuery *_Nonnull)query NS_DESIGNATED_INITIALIZER; +/** The base `Query` for this aggregate query. */ +@property(nonatomic, readonly) FIRQuery *_Nonnull query; + +/** + * Executes the aggregate query and reads back the results as a `FIRAggregateQuerySnapshot`. + * + * @param source indicates where the results should be fetched from. + * @param completion a block to execute once the results have been successfully read. + * snapshot will be `nil` only if error is `non-nil`. + */ +- (void)aggregationWithSource:(FIRAggregateSource)source + completion:(void (^_Nonnull)(FIRAggregateQuerySnapshot *_Nullable snapshot, + NSError *_Nullable error))completion + NS_SWIFT_NAME(aggregation(source:completion:)); @end diff --git a/Firestore/Source/API/FIRAggregateQuerySnapshot+Internal.h b/Firestore/Source/API/FIRAggregateQuerySnapshot+Internal.h index f462730ba19..7f6a197b31c 100644 --- a/Firestore/Source/API/FIRAggregateQuerySnapshot+Internal.h +++ b/Firestore/Source/API/FIRAggregateQuerySnapshot+Internal.h @@ -14,14 +14,29 @@ * limitations under the License. */ -#import "FIRAggregateQuerySnapshot.h" +// TODO(b/246760853): Move FIRAggregateQuerySnapshot to public headers to release it. + +#import "FIRAggregateQuery+Internal.h" @class FIRAggregateQuery; -@interface FIRAggregateQuerySnapshot (/* init */) +/** + * An `AggregateQuerySnapshot` contains results of a `AggregateQuery`. + */ +NS_SWIFT_NAME(AggregateQuerySnapshot) +@interface FIRAggregateQuerySnapshot : NSObject - (instancetype _Nonnull)init NS_UNAVAILABLE; - (instancetype _Nonnull)initWithCount:(int64_t)result Query:(FIRAggregateQuery* _Nonnull)query NS_DESIGNATED_INITIALIZER; +/** The original `AggregateQuery` this snapshot is a result of. */ +@property(nonatomic, readonly) FIRAggregateQuery* _Nonnull query; + +/** + * The result of a document count aggregation. Null if no count aggregation is + * available in the result. + */ +@property(nonatomic, readonly) NSNumber* _Nullable count; + @end diff --git a/Firestore/Source/Public/FirebaseFirestore/FIRAggregateSource.h b/Firestore/Source/API/FIRAggregateSource+Internal.h similarity index 93% rename from Firestore/Source/Public/FirebaseFirestore/FIRAggregateSource.h rename to Firestore/Source/API/FIRAggregateSource+Internal.h index a0561023e02..7a65035bc4d 100644 --- a/Firestore/Source/Public/FirebaseFirestore/FIRAggregateSource.h +++ b/Firestore/Source/API/FIRAggregateSource+Internal.h @@ -14,9 +14,9 @@ * limitations under the License. */ -#import +// TODO(b/246760853): Move FIRAggregateSource to public headers to release it. -NS_ASSUME_NONNULL_BEGIN +#import /** Configures the behavior of `AggregateQuery.aggregateWithSource(source:completion:)`. */ typedef NS_ENUM(NSUInteger, FIRAggregateSource) { @@ -28,5 +28,3 @@ typedef NS_ENUM(NSUInteger, FIRAggregateSource) { */ FIRAggregateSourceServer, } NS_SWIFT_NAME(AggregateSource); - -NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/API/FIRQuery+Internal.h b/Firestore/Source/API/FIRQuery+Internal.h index 1d2e74a36e7..052e9b920db 100644 --- a/Firestore/Source/API/FIRQuery+Internal.h +++ b/Firestore/Source/API/FIRQuery+Internal.h @@ -14,6 +14,7 @@ * limitations under the License. */ +#import "FIRAggregateQuery+Internal.h" #import "FIRQuery.h" #include @@ -47,6 +48,12 @@ NS_ASSUME_NONNULL_BEGIN // TODO(orquery): This method will become public API. Change visibility and add documentation. - (FIRQuery *)queryWhereFilter:(FIRFilter *)filter; +// TODO(b/246760853): This property will become public API. +/** + * An `AggregateQuery` counting the number of documents matching this query. + */ +@property(nonatomic, readonly) FIRAggregateQuery *count; + @end NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/API/FIRQuery.mm b/Firestore/Source/API/FIRQuery.mm index 330ff3b73bc..eecf7bdd324 100644 --- a/Firestore/Source/API/FIRQuery.mm +++ b/Firestore/Source/API/FIRQuery.mm @@ -20,7 +20,6 @@ #include #include -#import "FIRAggregateQuery+Internal.h" #import "FIRDocumentReference.h" #import "FIRFirestoreErrors.h" #import "Firestore/Source/API/FIRDocumentReference+Internal.h" diff --git a/Firestore/Source/Public/FirebaseFirestore/FIRAggregateQuery.h b/Firestore/Source/Public/FirebaseFirestore/FIRAggregateQuery.h deleted file mode 100644 index 8e3270667a7..00000000000 --- a/Firestore/Source/Public/FirebaseFirestore/FIRAggregateQuery.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import - -#import "FIRAggregateSource.h" - -NS_ASSUME_NONNULL_BEGIN - -@class FIRQuery; -@class FIRAggregateQuerySnapshot; - -/** - * An `AggregateQuery` computes some aggregation statistics from the result set of a base - * `Query`. - */ -NS_SWIFT_NAME(AggregateQuery) -@interface FIRAggregateQuery : NSObject - -/** The base `Query` for this aggregate query. */ -@property(nonatomic, readonly) FIRQuery *query; - -/** - * Executes the aggregate query and reads back the results as a `FIRAggregateQuerySnapshot`. - * - * @param source indicates where the results should be fetched from. - * @param completion a block to execute once the results have been successfully read. - * snapshot will be `nil` only if error is `non-nil`. - */ -- (void)aggregationWithSource:(FIRAggregateSource)source - completion:(void (^)(FIRAggregateQuerySnapshot *_Nullable snapshot, - NSError *_Nullable error))completion - NS_SWIFT_NAME(getAggregation(source:completion:)); -@end - -NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/Public/FirebaseFirestore/FIRAggregateQuerySnapshot.h b/Firestore/Source/Public/FirebaseFirestore/FIRAggregateQuerySnapshot.h deleted file mode 100644 index c777798d38d..00000000000 --- a/Firestore/Source/Public/FirebaseFirestore/FIRAggregateQuerySnapshot.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2022 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import - -NS_ASSUME_NONNULL_BEGIN - -@class FIRAggregateQuery; - -/** - * An `AggregateQuerySnapshot` contains results of a `AggregateQuery`. - */ -NS_SWIFT_NAME(AggregateQuerySnapshot) -@interface FIRAggregateQuerySnapshot : NSObject - -/** The original `AggregateQuery` this snapshot is a result of. */ -@property(nonatomic, readonly) FIRAggregateQuery* query; - -/** - * The result of a document count aggregation. Null if no count aggregation is - * available in the result. - */ -@property(nonatomic, readonly) NSNumber* count; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/Public/FirebaseFirestore/FIRQuery.h b/Firestore/Source/Public/FirebaseFirestore/FIRQuery.h index bf037b8abe3..e01f6af4105 100644 --- a/Firestore/Source/Public/FirebaseFirestore/FIRQuery.h +++ b/Firestore/Source/Public/FirebaseFirestore/FIRQuery.h @@ -19,7 +19,6 @@ #import "FIRFirestoreSource.h" #import "FIRListenerRegistration.h" -@class FIRAggregateQuery; @class FIRFieldPath; @class FIRFirestore; @class FIRQuerySnapshot; @@ -543,13 +542,6 @@ NS_SWIFT_NAME(Query) */ - (FIRQuery *)queryEndingAtValues:(NSArray *)fieldValues NS_SWIFT_NAME(end(at:)); -#pragma mark - Aggregation - -/** - * An `AggregateQuery` counting the number of documents matching this query. - */ -@property(nonatomic, readonly) FIRAggregateQuery *count; - @end NS_ASSUME_NONNULL_END diff --git a/Firestore/Swift/Tests/Integration/AsyncAwaitIntegrationTests.swift b/Firestore/Swift/Tests/Integration/AsyncAwaitIntegrationTests.swift index 309e0276e81..5f7da2c53a8 100644 --- a/Firestore/Swift/Tests/Integration/AsyncAwaitIntegrationTests.swift +++ b/Firestore/Swift/Tests/Integration/AsyncAwaitIntegrationTests.swift @@ -73,12 +73,5 @@ let emptyBundle = """ XCTAssertNil(value, "value should be nil on success") } - - func testCount() async throws { - let collection = collectionRef() - try await collection.addDocument(data: [:]) - let snapshot = try await collection.count.getAggregation(source: .server) - XCTAssertEqual(snapshot.count, 1) - } } #endif