From 293c6e252eda4c1dbc3f7fbbc3956079ad979132 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Thu, 7 Dec 2017 06:19:59 -0800 Subject: Add FirebaseFirestore.h to fix Firebase module in source build (#539) --- Firestore/Source/Public/FirebaseFirestore.h | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Firestore/Source/Public/FirebaseFirestore.h (limited to 'Firestore/Source/Public') diff --git a/Firestore/Source/Public/FirebaseFirestore.h b/Firestore/Source/Public/FirebaseFirestore.h new file mode 100644 index 0000000..ff110fd --- /dev/null +++ b/Firestore/Source/Public/FirebaseFirestore.h @@ -0,0 +1,33 @@ +/* + * Copyright 2017 Google + * + * 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 "FIRCollectionReference.h" +#import "FIRDocumentChange.h" +#import "FIRDocumentReference.h" +#import "FIRDocumentSnapshot.h" +#import "FIRFieldPath.h" +#import "FIRFieldValue.h" +#import "FIRFirestore.h" +#import "FIRFirestoreErrors.h" +#import "FIRFirestoreSettings.h" +#import "FIRGeoPoint.h" +#import "FIRListenerRegistration.h" +#import "FIRQuery.h" +#import "FIRQuerySnapshot.h" +#import "FIRSetOptions.h" +#import "FIRSnapshotMetadata.h" +#import "FIRTransaction.h" +#import "FIRWriteBatch.h" -- cgit v1.2.3 From 5da88e4b9b5ce9d1aee8611d03946e19bdfa5b65 Mon Sep 17 00:00:00 2001 From: zxu Date: Thu, 7 Dec 2017 15:36:15 -0500 Subject: Implement NSPredicate-based query (#531) * implement queryFilteredUsingPredicate in FIRQuery; * add unit test and integration test for queryFilteredUsingPredicate; * project change of adding the FIRQueryTests.m file; * refactoring queryFilteredUsingPredicate to split logic into two helpers; --- Firestore/CHANGELOG.md | 1 + .../Example/Firestore.xcodeproj/project.pbxproj | 4 + Firestore/Example/Tests/API/FIRQueryTests.m | 75 ++++++++++++++++++ .../Example/Tests/Integration/API/FIRQueryTests.m | 17 ++++ Firestore/Source/API/FIRQuery+Internal.h | 2 + Firestore/Source/API/FIRQuery.m | 92 ++++++++++++++++++++++ Firestore/Source/Public/FIRQuery.h | 13 +++ 7 files changed, 204 insertions(+) create mode 100644 Firestore/Example/Tests/API/FIRQueryTests.m (limited to 'Firestore/Source/Public') diff --git a/Firestore/CHANGELOG.md b/Firestore/CHANGELOG.md index 0c5bcdc..e6ecf11 100644 --- a/Firestore/CHANGELOG.md +++ b/Firestore/CHANGELOG.md @@ -4,6 +4,7 @@ with persistence enabled. - [fixed] Addressed race condition during the teardown of idle streams (#490). +- [feature] Queries can now be created from an NSPredicate. # v0.9.3 - [changed] Improved performance loading documents matching a query. diff --git a/Firestore/Example/Firestore.xcodeproj/project.pbxproj b/Firestore/Example/Firestore.xcodeproj/project.pbxproj index 437b661..5657b95 100644 --- a/Firestore/Example/Firestore.xcodeproj/project.pbxproj +++ b/Firestore/Example/Firestore.xcodeproj/project.pbxproj @@ -61,6 +61,7 @@ 6ED54761B845349D43DB6B78 /* Pods_Firestore_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 75A6FE51C1A02DF38F62FAAD /* Pods_Firestore_Example.framework */; }; 71719F9F1E33DC2100824A3D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 71719F9D1E33DC2100824A3D /* LaunchScreen.storyboard */; }; 873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; }; + ABAEEF4F1FD5F8B100C966CB /* FIRQueryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */; }; AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; }; C4E749275AD0FBDF9F4716A8 /* Pods_SwiftBuildTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32AD40BF6B0E849B07FFD05E /* Pods_SwiftBuildTest.framework */; }; D5B2532E4676014F57A7EAB9 /* FSTStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D5B25C0D4AADFCA3ADB883E4 /* FSTStreamTests.m */; }; @@ -230,6 +231,7 @@ 8E002F4AD5D9B6197C940847 /* Firestore.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = Firestore.podspec; path = ../Firestore.podspec; sourceTree = ""; }; 9D52E67EE96AA7E5D6F69748 /* Pods-Firestore_IntegrationTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_IntegrationTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_IntegrationTests/Pods-Firestore_IntegrationTests.debug.xcconfig"; sourceTree = ""; }; 9EF477AD4B2B643FD320867A /* Pods-Firestore_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Example/Pods-Firestore_Example.debug.xcconfig"; sourceTree = ""; }; + ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRQueryTests.m; sourceTree = ""; }; B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; CE00BABB5A3AAB44A4C209E2 /* Pods-Firestore_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests/Pods-Firestore_Tests.debug.xcconfig"; sourceTree = ""; }; D3CC3DC5338DCAF43A211155 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; @@ -584,6 +586,7 @@ isa = PBXGroup; children = ( DE51B1841F0D48AC0013853F /* FIRGeoPointTests.m */, + ABAEEF4E1FD5F8B100C966CB /* FIRQueryTests.m */, ); path = API; sourceTree = ""; @@ -1161,6 +1164,7 @@ files = ( DE2EF0881F3D0B6E003D0CDC /* FSTTreeSortedDictionaryTests.m in Sources */, DE51B1FD1F0D492C0013853F /* FSTSpecTests.m in Sources */, + ABAEEF4F1FD5F8B100C966CB /* FIRQueryTests.m in Sources */, DE51B2001F0D493A0013853F /* FSTComparisonTests.m in Sources */, DE51B1CC1F0D48C00013853F /* FIRGeoPointTests.m in Sources */, DE51B1E11F0D490D0013853F /* FSTMemoryRemoteDocumentCacheTests.m in Sources */, diff --git a/Firestore/Example/Tests/API/FIRQueryTests.m b/Firestore/Example/Tests/API/FIRQueryTests.m new file mode 100644 index 0000000..bd0d860 --- /dev/null +++ b/Firestore/Example/Tests/API/FIRQueryTests.m @@ -0,0 +1,75 @@ +/* + * Copyright 2017 Google + * + * 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 FirebaseFirestore; + +#import + +#import "Firestore/Source/API/FIRFirestore+Internal.h" +#import "Firestore/Source/API/FIRQuery+Internal.h" +#import "Firestore/Source/Core/FSTQuery.h" +#import "Firestore/Source/Model/FSTPath.h" + +#import "Firestore/Example/Tests/Util/FSTHelpers.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface FIRQueryTests : XCTestCase +@end + +@implementation FIRQueryTests + +- (void)testFilteringWithPredicate { + // Everything is dummy for unit test here. Filtering does not require any app + // specific setting as far as we do not fetch data. + FIRFirestore *firestore = [[FIRFirestore alloc] initWithProjectID:@"abc" + database:@"abc" + persistenceKey:@"db123" + credentialsProvider:nil + workerDispatchQueue:nil + firebaseApp:nil]; + FSTResourcePath *path = [FSTResourcePath pathWithString:@"foo"]; + FIRQuery *query = [FIRQuery referenceWithQuery:[FSTQuery queryWithPath:path] + firestore:firestore]; + FIRQuery *query1 = [query queryWhereField:@"f" isLessThanOrEqualTo:@1]; + FIRQuery *query2 = [query queryFilteredUsingPredicate: + [NSPredicate predicateWithFormat:@"f<=1"]]; + FIRQuery *query3 = [[query queryWhereField:@"f1" isLessThan:@2] + queryWhereField:@"f2" isEqualTo:@3]; + FIRQuery *query4 = [query queryFilteredUsingPredicate: + [NSPredicate predicateWithFormat:@"f1<2 && f2==3"]]; + FIRQuery *query5 = [[[[[query queryWhereField:@"f1" isLessThan:@2] + queryWhereField:@"f2" isEqualTo:@3] + queryWhereField:@"f1" isLessThanOrEqualTo:@"four"] + queryWhereField:@"f1" isGreaterThanOrEqualTo:@"five"] + queryWhereField:@"f1" isGreaterThan:@6]; + FIRQuery *query6 = [query queryFilteredUsingPredicate: + [NSPredicate predicateWithFormat: + @"f1<2 && f2==3 && f1<='four' && f1>='five' && f1>6"]]; + FIRQuery *query7 = [query queryFilteredUsingPredicate: + [NSPredicate predicateWithFormat: + @"2>f1 && 3==f2 && 'four'>=f1 && 'five'<=f1 && 6 Date: Fri, 8 Dec 2017 09:22:56 -0500 Subject: make FIRDocumentListenOptions.includeMetadataChanges private (#540) * make FIRDocumentListenOptions.includeMetadataChanges private as discussed in Firestore API discussion, the name clashes creates confusion. Android SDK already not exposing the property; here change iOS SDK to match it. * update CHANGELOG --- Firestore/CHANGELOG.md | 2 ++ Firestore/Source/API/FIRDocumentReference.m | 2 ++ Firestore/Source/Public/FIRDocumentReference.h | 2 -- 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'Firestore/Source/Public') diff --git a/Firestore/CHANGELOG.md b/Firestore/CHANGELOG.md index e6ecf11..32cbbfc 100644 --- a/Firestore/CHANGELOG.md +++ b/Firestore/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased - [changed] Firestore no longer has a direct dependency on FirebaseAuth. +- [changed] Removed the includeMetadataChanges property in FIRDocumentListenOptions + to avoid confusion with the factory method of the same name. - [fixed] Fixed a crash when using path names with international characters with persistence enabled. diff --git a/Firestore/Source/API/FIRDocumentReference.m b/Firestore/Source/API/FIRDocumentReference.m index 1c80ea9..6279b7c 100644 --- a/Firestore/Source/API/FIRDocumentReference.m +++ b/Firestore/Source/API/FIRDocumentReference.m @@ -48,6 +48,8 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithIncludeMetadataChanges:(BOOL)includeMetadataChanges NS_DESIGNATED_INITIALIZER; +@property(nonatomic, assign, readonly) BOOL includeMetadataChanges; + @end @implementation FIRDocumentListenOptions diff --git a/Firestore/Source/Public/FIRDocumentReference.h b/Firestore/Source/Public/FIRDocumentReference.h index 439e727..7fcc7a8 100644 --- a/Firestore/Source/Public/FIRDocumentReference.h +++ b/Firestore/Source/Public/FIRDocumentReference.h @@ -36,8 +36,6 @@ NS_SWIFT_NAME(DocumentListenOptions) - (instancetype)init; -@property(nonatomic, assign, readonly) BOOL includeMetadataChanges; - /** * Sets the includeMetadataChanges option which controls whether metadata-only changes (i.e. only * `FIRDocumentSnapshot.metadata` changed) should trigger snapshot events. Default is NO. -- cgit v1.2.3 From 54ba423c87d6e0a409e4fa3dc95cd81ca16b97f7 Mon Sep 17 00:00:00 2001 From: zxu Date: Mon, 11 Dec 2017 15:37:01 -0500 Subject: Revisit commit method in FIRWriteBatch (#541) * revisit FIRWriteBatch commit * make commitWithCompletion completion nullable; * add commit; * add unit test; * add swift build test for commit; * update CHANGELOG. --- Firestore/CHANGELOG.md | 1 + Firestore/Example/SwiftBuildTest/main.swift | 26 ++++++++++++++++++++++ .../Tests/Integration/API/FIRWriteBatchTests.m | 17 ++++++++++++++ Firestore/Source/API/FIRWriteBatch.m | 6 ++++- Firestore/Source/Public/FIRWriteBatch.h | 7 +++++- 5 files changed, 55 insertions(+), 2 deletions(-) (limited to 'Firestore/Source/Public') diff --git a/Firestore/CHANGELOG.md b/Firestore/CHANGELOG.md index 32cbbfc..1a8eb07 100644 --- a/Firestore/CHANGELOG.md +++ b/Firestore/CHANGELOG.md @@ -2,6 +2,7 @@ - [changed] Firestore no longer has a direct dependency on FirebaseAuth. - [changed] Removed the includeMetadataChanges property in FIRDocumentListenOptions to avoid confusion with the factory method of the same name. +- [changed] Added a commit method that takes no completion handler to FIRWriteBatch. - [fixed] Fixed a crash when using path names with international characters with persistence enabled. diff --git a/Firestore/Example/SwiftBuildTest/main.swift b/Firestore/Example/SwiftBuildTest/main.swift index bea8b56..475c1b2 100644 --- a/Firestore/Example/SwiftBuildTest/main.swift +++ b/Firestore/Example/SwiftBuildTest/main.swift @@ -27,6 +27,8 @@ func main() { writeDocument(at: documentRef); + writeDocuments(at: documentRef, database: db); + addDocument(to: collectionRef); readDocument(at: documentRef); @@ -129,6 +131,30 @@ func writeDocument(at docRef: DocumentReference) { } } +func writeDocuments(at docRef: DocumentReference, database db: Firestore) { + var batch: WriteBatch; + + batch = db.batch(); + batch.setData(["a" : "b"], forDocument:docRef); + batch.setData(["c" : "d"], forDocument:docRef); + // commit without completion callback. + batch.commit(); + print("Batch write without completion complete!"); + + batch = db.batch(); + batch.setData(["a" : "b"], forDocument:docRef); + batch.setData(["c" : "d"], forDocument:docRef); + // commit with completion callback via trailing closure syntax. + batch.commit() { error in + if let error = error { + print("Uh oh! \(error)"); + return; + } + print("Batch write callback complete!"); + } + print("Batch write with completion complete!"); +} + func addDocument(to collectionRef: CollectionReference) { collectionRef.addDocument(data: ["foo": 42]); diff --git a/Firestore/Example/Tests/Integration/API/FIRWriteBatchTests.m b/Firestore/Example/Tests/Integration/API/FIRWriteBatchTests.m index 562c29f..23ae7bc 100644 --- a/Firestore/Example/Tests/Integration/API/FIRWriteBatchTests.m +++ b/Firestore/Example/Tests/Integration/API/FIRWriteBatchTests.m @@ -35,6 +35,23 @@ [self awaitExpectations]; } +- (void)testCommitWithoutCompletionHandler { + FIRDocumentReference *doc = [self documentRef]; + FIRWriteBatch *batch1 = [doc.firestore batch]; + [batch1 setData:@{@"aa" : @"bb"} forDocument:doc]; + [batch1 commitWithCompletion:nil]; + FIRDocumentSnapshot *snapshot1 = [self readDocumentForRef:doc]; + XCTAssertTrue(snapshot1.exists); + XCTAssertEqualObjects(snapshot1.data, @{@"aa" : @"bb"}); + + FIRWriteBatch *batch2 = [doc.firestore batch]; + [batch2 setData:@{@"cc" : @"dd"} forDocument:doc]; + [batch2 commit]; + FIRDocumentSnapshot *snapshot2 = [self readDocumentForRef:doc]; + XCTAssertTrue(snapshot2.exists); + XCTAssertEqualObjects(snapshot2.data, @{@"cc" : @"dd"}); +} + - (void)testSetDocuments { FIRDocumentReference *doc = [self documentRef]; XCTestExpectation *batchExpectation = [self expectationWithDescription:@"batch written"]; diff --git a/Firestore/Source/API/FIRWriteBatch.m b/Firestore/Source/API/FIRWriteBatch.m index b918a9a..b1cfa09 100644 --- a/Firestore/Source/API/FIRWriteBatch.m +++ b/Firestore/Source/API/FIRWriteBatch.m @@ -93,7 +93,11 @@ NS_ASSUME_NONNULL_BEGIN return self; } -- (void)commitWithCompletion:(void (^)(NSError *_Nullable error))completion { +- (void)commit { + [self commitWithCompletion:nil]; +} + +- (void)commitWithCompletion:(nullable void (^)(NSError *_Nullable error))completion { [self verifyNotCommitted]; self.committed = TRUE; [self.firestore.client writeMutations:self.mutations completion:completion]; diff --git a/Firestore/Source/Public/FIRWriteBatch.h b/Firestore/Source/Public/FIRWriteBatch.h index 5f0034c..8ff1bec 100644 --- a/Firestore/Source/Public/FIRWriteBatch.h +++ b/Firestore/Source/Public/FIRWriteBatch.h @@ -92,6 +92,11 @@ NS_SWIFT_NAME(WriteBatch) - (FIRWriteBatch *)deleteDocument:(FIRDocumentReference *)document NS_SWIFT_NAME(deleteDocument(_:)); +/** + * Commits all of the writes in this write batch as a single atomic unit. + */ +- (void)commit; + /** * Commits all of the writes in this write batch as a single atomic unit. * @@ -101,7 +106,7 @@ NS_SWIFT_NAME(WriteBatch) * completion handler will not be called when the device is offline, though local * changes will be visible immediately. */ -- (void)commitWithCompletion:(void (^)(NSError *_Nullable error))completion; +- (void)commitWithCompletion:(nullable void (^)(NSError *_Nullable error))completion; @end -- cgit v1.2.3