From 38eafc0490fa9d698685911fd950e9ebf3357eb0 Mon Sep 17 00:00:00 2001 From: fummicc1 Date: Sun, 24 Nov 2024 21:17:25 +0900 Subject: [PATCH] Update Firebase version and add contains filter --- .swiftpm/EasyFirebase-Package.xctestplan | 31 +++ ...xcscheme => EasyFirebase-Package.xcscheme} | 61 +++-- ...uth.xcscheme => EasyFirebaseAuth.xcscheme} | 24 +- ...cscheme => EasyFirebaseFirestore.xcscheme} | 34 +-- .../xcschemes/EasyFirebaseStorage.xcscheme | 67 +++++ .../EasyFirebaseSwift-Package.xcscheme | 199 --------------- Examples/Example/FirestoreExample/Model.swift | 1 - .../BoardApplication/Message.swift | 1 - FirestoreClient.md | 3 +- Package.resolved | 241 +++++++++--------- Package.swift | 6 +- Sources/Auth/AppleAuthClient.swift | 2 +- Sources/Auth/FirebaseAuthClient.swift | 6 +- Sources/Firestore/FirestoreClient.swift | 48 ++-- .../FirestoreClientTests.swift | 1 - 15 files changed, 322 insertions(+), 403 deletions(-) create mode 100644 .swiftpm/EasyFirebase-Package.xctestplan rename .swiftpm/xcode/xcshareddata/xcschemes/{EasyFirebaseSwiftStorage.xcscheme => EasyFirebase-Package.xcscheme} (56%) rename .swiftpm/xcode/xcshareddata/xcschemes/{EasyFirebaseSwiftAuth.xcscheme => EasyFirebaseAuth.xcscheme} (78%) rename .swiftpm/xcode/xcshareddata/xcschemes/{EasyFirebaseSwiftFirestore.xcscheme => EasyFirebaseFirestore.xcscheme} (66%) create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseStorage.xcscheme delete mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseSwift-Package.xcscheme diff --git a/.swiftpm/EasyFirebase-Package.xctestplan b/.swiftpm/EasyFirebase-Package.xctestplan new file mode 100644 index 0000000..6f7493e --- /dev/null +++ b/.swiftpm/EasyFirebase-Package.xctestplan @@ -0,0 +1,31 @@ +{ + "configurations" : [ + { + "id" : "D325B07B-16DE-4CCE-9A75-B696B8133B45", + "name" : "Configuration 1", + "options" : { + + } + } + ], + "defaultOptions" : { + + }, + "testTargets" : [ + { + "target" : { + "containerPath" : "container:", + "identifier" : "EasyFirebaseStorageTests", + "name" : "EasyFirebaseStorageTests" + } + }, + { + "target" : { + "containerPath" : "container:", + "identifier" : "EasyFirebaseFirestoreTests", + "name" : "EasyFirebaseFirestoreTests" + } + } + ], + "version" : 1 +} diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseSwiftStorage.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebase-Package.xcscheme similarity index 56% rename from .swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseSwiftStorage.xcscheme rename to .swiftpm/xcode/xcshareddata/xcschemes/EasyFirebase-Package.xcscheme index bae0238..001a844 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseSwiftStorage.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebase-Package.xcscheme @@ -1,10 +1,11 @@ + LastUpgradeVersion = "1610" + version = "1.7"> + buildImplicitDependencies = "YES" + buildArchitectures = "Automatic"> @@ -28,9 +29,23 @@ buildForAnalyzing = "YES"> + + + + @@ -41,14 +56,30 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "YES"> + + + + + + + + @@ -74,9 +105,9 @@ diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseSwiftAuth.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseAuth.xcscheme similarity index 78% rename from .swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseSwiftAuth.xcscheme rename to .swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseAuth.xcscheme index 8e004b0..d4656c4 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseSwiftAuth.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseAuth.xcscheme @@ -1,10 +1,11 @@ + LastUpgradeVersion = "1610" + version = "1.7"> + buildImplicitDependencies = "YES" + buildArchitectures = "Automatic"> @@ -26,9 +27,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> - - + shouldUseLaunchSchemeArgsEnv = "YES" + shouldAutocreateTestPlan = "YES"> diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseSwiftFirestore.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseFirestore.xcscheme similarity index 66% rename from .swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseSwiftFirestore.xcscheme rename to .swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseFirestore.xcscheme index dddcbbe..b6af0cc 100644 --- a/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseSwiftFirestore.xcscheme +++ b/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseFirestore.xcscheme @@ -1,10 +1,11 @@ + LastUpgradeVersion = "1610" + version = "1.7"> + buildImplicitDependencies = "YES" + buildArchitectures = "Automatic"> @@ -26,19 +27,8 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> - - - - - - + shouldUseLaunchSchemeArgsEnv = "YES" + shouldAutocreateTestPlan = "YES"> diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseStorage.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseStorage.xcscheme new file mode 100644 index 0000000..ea280f0 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseStorage.xcscheme @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseSwift-Package.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseSwift-Package.xcscheme deleted file mode 100644 index d871cd1..0000000 --- a/.swiftpm/xcode/xcshareddata/xcschemes/EasyFirebaseSwift-Package.xcscheme +++ /dev/null @@ -1,199 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Examples/Example/FirestoreExample/Model.swift b/Examples/Example/FirestoreExample/Model.swift index bd5db11..e8d1fee 100644 --- a/Examples/Example/FirestoreExample/Model.swift +++ b/Examples/Example/FirestoreExample/Model.swift @@ -7,7 +7,6 @@ import EasyFirebaseFirestore import FirebaseFirestore -import FirebaseFirestoreSwift import Foundation struct Model: FirestoreModel { diff --git a/Examples/Practical/BoardApplication/BoardApplication/Message.swift b/Examples/Practical/BoardApplication/BoardApplication/Message.swift index 191d14b..f8ef669 100644 --- a/Examples/Practical/BoardApplication/BoardApplication/Message.swift +++ b/Examples/Practical/BoardApplication/BoardApplication/Message.swift @@ -1,6 +1,5 @@ import EasyFirebaseSwift import FirebaseFirestore -import FirebaseFirestoreSwift import Foundation struct Message: FirestoreModel { diff --git a/FirestoreClient.md b/FirestoreClient.md index 4fa4603..7cb5e67 100644 --- a/FirestoreClient.md +++ b/FirestoreClient.md @@ -9,7 +9,6 @@ First of all, create Model layer inheriting `FirestoreModel` protocol. ```swift import EasyFirebaseSwift -import FirebaseFirestoreSwift import FirebaseFirestore // Note: FirestoreModel inherits `Codable` Protocol @@ -20,7 +19,7 @@ struct Model: FirestoreModel { // collectionName corresponding to Firestore's CollectionName. static var collectionName: String = "models" - // NOTE: To use PropertyWrapper such as @DocumentID, @ServerTimestamp, please import FirebaseFirestoreSwift. + // NOTE: To use PropertyWrapper such as @DocumentID, @ServerTimestamp @DocumentID var ref: DocumentReference? diff --git a/Package.resolved b/Package.resolved index d9f84e6..c89e4ed 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,124 +1,123 @@ { - "object": { - "pins": [ - { - "package": "abseil", - "repositoryURL": "https://github.com/google/abseil-cpp-binary.git", - "state": { - "branch": null, - "revision": "748c7837511d0e6a507737353af268484e1745e2", - "version": "1.2024011601.1" - } - }, - { - "package": "AppCheck", - "repositoryURL": "https://github.com/google/app-check.git", - "state": { - "branch": null, - "revision": "076b241a625e25eac22f8849be256dfb960fcdfe", - "version": "10.19.1" - } - }, - { - "package": "Firebase", - "repositoryURL": "https://github.com/firebase/firebase-ios-sdk", - "state": { - "branch": null, - "revision": "9d17b500cd98d9a7009751ad62f802e152e97021", - "version": "10.26.0" - } - }, - { - "package": "GoogleAppMeasurement", - "repositoryURL": "https://github.com/google/GoogleAppMeasurement.git", - "state": { - "branch": null, - "revision": "16244d177c4e989f87b25e9db1012b382cfedc55", - "version": "10.25.0" - } - }, - { - "package": "GoogleDataTransport", - "repositoryURL": "https://github.com/google/GoogleDataTransport.git", - "state": { - "branch": null, - "revision": "a637d318ae7ae246b02d7305121275bc75ed5565", - "version": "9.4.0" - } - }, - { - "package": "GoogleUtilities", - "repositoryURL": "https://github.com/google/GoogleUtilities.git", - "state": { - "branch": null, - "revision": "57a1d307f42df690fdef2637f3e5b776da02aad6", - "version": "7.13.3" - } - }, - { - "package": "gRPC", - "repositoryURL": "https://github.com/google/grpc-binary.git", - "state": { - "branch": null, - "revision": "e9fad491d0673bdda7063a0341fb6b47a30c5359", - "version": "1.62.2" - } - }, - { - "package": "GTMSessionFetcher", - "repositoryURL": "https://github.com/google/gtm-session-fetcher.git", - "state": { - "branch": null, - "revision": "0382ca27f22fb3494cf657d8dc356dc282cd1193", - "version": "3.4.1" - } - }, - { - "package": "InteropForGoogle", - "repositoryURL": "https://github.com/google/interop-ios-for-google-sdks.git", - "state": { - "branch": null, - "revision": "2d12673670417654f08f5f90fdd62926dc3a2648", - "version": "100.0.0" - } - }, - { - "package": "leveldb", - "repositoryURL": "https://github.com/firebase/leveldb.git", - "state": { - "branch": null, - "revision": "a0bc79961d7be727d258d33d5a6b2f1023270ba1", - "version": "1.22.5" - } - }, - { - "package": "nanopb", - "repositoryURL": "https://github.com/firebase/nanopb.git", - "state": { - "branch": null, - "revision": "b7e1104502eca3a213b46303391ca4d3bc8ddec1", - "version": "2.30910.0" - } - }, - { - "package": "Promises", - "repositoryURL": "https://github.com/google/promises.git", - "state": { - "branch": null, - "revision": "540318ecedd63d883069ae7f1ed811a2df00b6ac", - "version": "2.4.0" - } - }, - { - "package": "SwiftProtobuf", - "repositoryURL": "https://github.com/apple/swift-protobuf.git", - "state": { - "branch": null, - "revision": "9f0c76544701845ad98716f3f6a774a892152bcb", - "version": "1.26.0" - } + "originHash" : "207bccc96cf2c88e6350c88ce46354196cc457fdf45bde70d7f9d18a7946fbd0", + "pins" : [ + { + "identity" : "abseil-cpp-binary", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/abseil-cpp-binary.git", + "state" : { + "revision" : "194a6706acbd25e4ef639bcaddea16e8758a3e27", + "version" : "1.2024011602.0" } - ] - }, - "version": 1 + }, + { + "identity" : "app-check", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/app-check.git", + "state" : { + "revision" : "61b85103a1aeed8218f17c794687781505fbbef5", + "version" : "11.2.0" + } + }, + { + "identity" : "firebase-ios-sdk", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/firebase-ios-sdk", + "state" : { + "revision" : "dbdfdc44bee8b8e4eaa5ec27eb12b9338f3f2bc1", + "version" : "11.5.0" + } + }, + { + "identity" : "googleappmeasurement", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GoogleAppMeasurement.git", + "state" : { + "revision" : "4f234bcbdae841d7015258fbbf8e7743a39b8200", + "version" : "11.4.0" + } + }, + { + "identity" : "googledatatransport", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GoogleDataTransport.git", + "state" : { + "revision" : "617af071af9aa1d6a091d59a202910ac482128f9", + "version" : "10.1.0" + } + }, + { + "identity" : "googleutilities", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/GoogleUtilities.git", + "state" : { + "revision" : "53156c7ec267db846e6b64c9f4c4e31ba4cf75eb", + "version" : "8.0.2" + } + }, + { + "identity" : "grpc-binary", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/grpc-binary.git", + "state" : { + "revision" : "f56d8fc3162de9a498377c7b6cea43431f4f5083", + "version" : "1.65.1" + } + }, + { + "identity" : "gtm-session-fetcher", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/gtm-session-fetcher.git", + "state" : { + "revision" : "5cfe5f090c982de9c58605d2a82a4fc77b774fbd", + "version" : "4.1.0" + } + }, + { + "identity" : "interop-ios-for-google-sdks", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/interop-ios-for-google-sdks.git", + "state" : { + "revision" : "2d12673670417654f08f5f90fdd62926dc3a2648", + "version" : "100.0.0" + } + }, + { + "identity" : "leveldb", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/leveldb.git", + "state" : { + "revision" : "a0bc79961d7be727d258d33d5a6b2f1023270ba1", + "version" : "1.22.5" + } + }, + { + "identity" : "nanopb", + "kind" : "remoteSourceControl", + "location" : "https://github.com/firebase/nanopb.git", + "state" : { + "revision" : "b7e1104502eca3a213b46303391ca4d3bc8ddec1", + "version" : "2.30910.0" + } + }, + { + "identity" : "promises", + "kind" : "remoteSourceControl", + "location" : "https://github.com/google/promises.git", + "state" : { + "revision" : "540318ecedd63d883069ae7f1ed811a2df00b6ac", + "version" : "2.4.0" + } + }, + { + "identity" : "swift-protobuf", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-protobuf.git", + "state" : { + "revision" : "ebc7251dd5b37f627c93698e4374084d98409633", + "version" : "1.28.2" + } + } + ], + "version" : 3 } diff --git a/Package.swift b/Package.swift index 0fbeb75..eec7dbd 100644 --- a/Package.swift +++ b/Package.swift @@ -25,7 +25,7 @@ let package = Package( dependencies: [ .package( url: "https://github.com/firebase/firebase-ios-sdk", - .upToNextMajor(from: "10.24.0") + .upToNextMajor(from: "11.0.0") ) ], targets: [ @@ -43,10 +43,6 @@ let package = Package( name: "FirebaseFirestore", package: "firebase-ios-sdk" ), - .product( - name: "FirebaseFirestoreSwift", - package: "firebase-ios-sdk" - ), ], path: "Sources/Firestore" ), diff --git a/Sources/Auth/AppleAuthClient.swift b/Sources/Auth/AppleAuthClient.swift index 4970a24..b014aa8 100644 --- a/Sources/Auth/AppleAuthClient.swift +++ b/Sources/Auth/AppleAuthClient.swift @@ -199,7 +199,7 @@ extension AppleAuthClient { return } let firCredential = OAuthProvider.credential( - withProviderID: "apple.com", + providerID: .apple, idToken: idTokenString, rawNonce: nonce ) diff --git a/Sources/Auth/FirebaseAuthClient.swift b/Sources/Auth/FirebaseAuthClient.swift index 5591d35..d940a16 100644 --- a/Sources/Auth/FirebaseAuthClient.swift +++ b/Sources/Auth/FirebaseAuthClient.swift @@ -53,10 +53,10 @@ public class FirebaseAuthClient { internal func getAppleCredential( idToken token: String, - nonce: String? + nonce: String ) -> AuthCredential { let credential = OAuthProvider.credential( - withProviderID: "apple.com", + providerID: .apple, idToken: token, rawNonce: nonce ) @@ -71,7 +71,7 @@ public class FirebaseAuthClient { return data.user } - public func signInWithApple(idToken token: String, nonce: String?) async throws + public func signInWithApple(idToken token: String, nonce: String) async throws -> FirebaseAuth.User { let credential = getAppleCredential(idToken: token, nonce: nonce) diff --git a/Sources/Firestore/FirestoreClient.swift b/Sources/Firestore/FirestoreClient.swift index c4a32f8..e36affc 100644 --- a/Sources/Firestore/FirestoreClient.swift +++ b/Sources/Firestore/FirestoreClient.swift @@ -5,7 +5,6 @@ // import FirebaseFirestore -import FirebaseFirestoreSwift import Foundation public protocol FirestoreModel: Codable, Identifiable { @@ -36,7 +35,7 @@ public protocol SubCollectionModel: FirestoreModel { } public protocol FirestoreQueryFilter { - var fieldPath: String? { get } + var fieldPath: String { get } func build(type: Model.Type) -> Query func build(from: Query) -> Query @@ -57,18 +56,18 @@ public struct FirestoreQueryOrder { } public struct FirestoreRangeFilter: FirestoreQueryFilter { - public var fieldPath: String? + public var fieldPath: String public var minValue: Value private var maxValue: Value - public init(fieldPath: String? = nil, minValue: Value, maxValue: Value) { + public init(fieldPath: String, minValue: Value, maxValue: Value) { self.fieldPath = fieldPath self.minValue = minValue self.maxValue = maxValue } public func build(from: Query) -> Query { - guard let fieldPath = fieldPath, maxValue > minValue else { + guard maxValue > minValue else { return from } return @@ -79,7 +78,7 @@ public struct FirestoreRangeFilter: FirestoreQueryFilter { public func build(type: Model.Type) -> Query where Model: FirestoreModel { let from = Firestore.firestore().collection(type.collectionName) - guard let fieldPath = fieldPath, maxValue > minValue else { + guard maxValue > minValue else { return from } return @@ -89,46 +88,55 @@ public struct FirestoreRangeFilter: FirestoreQueryFilter { } } +public struct FirestoreInFilter: FirestoreQueryFilter { + public var fieldPath: String + public var values: [Any] + + public init(fieldPath: String, values: [Any]) { + self.fieldPath = fieldPath + self.values = values + } + + public func build(from: Query) -> Query { + from.whereField(fieldPath, in: values) + } + + public func build(type: Model.Type) -> Query where Model : FirestoreModel { + let from = Firestore.firestore().collection(type.collectionName) + return from.whereField(fieldPath, in: values) + } +} + public struct FirestoreEqualFilter: FirestoreQueryFilter { - public var fieldPath: String? + public var fieldPath: String public var value: Any? - public init(fieldPath: String?, value: Any?) { + public init(fieldPath: String, value: Any?) { self.fieldPath = fieldPath self.value = value } public func build(from: Query) -> Query { - - guard let fieldPath = fieldPath else { - return from - } return from.whereField(fieldPath, isEqualTo: value as Any) } public func build(type: Model.Type) -> Query where Model: FirestoreModel { let from = Firestore.firestore().collection(type.collectionName) - guard let fieldPath = fieldPath else { - return from - } return from.whereField(fieldPath, isEqualTo: value as Any) } } public struct FirestoreContainFilter: FirestoreQueryFilter { - public var fieldPath: String? + public var fieldPath: String public var value: Any - public init(fieldPath: String?, value: Any) { + public init(fieldPath: String, value: Any) { self.fieldPath = fieldPath self.value = value } public func build(from: Query) -> Query { - guard let fieldPath = fieldPath else { - return from - } return from.whereField(fieldPath, arrayContains: value) } diff --git a/Tests/EasyFirebaseFirestoreTests/FirestoreClientTests.swift b/Tests/EasyFirebaseFirestoreTests/FirestoreClientTests.swift index 9c229ca..e91a9b2 100644 --- a/Tests/EasyFirebaseFirestoreTests/FirestoreClientTests.swift +++ b/Tests/EasyFirebaseFirestoreTests/FirestoreClientTests.swift @@ -7,7 +7,6 @@ import Combine import FirebaseFirestore -import FirebaseFirestoreSwift import XCTest @testable import EasyFirebaseFirestore