From d90209c8117e02f3149aa1e1800737415c26b7cb Mon Sep 17 00:00:00 2001 From: Corey Date: Mon, 21 Jun 2021 19:06:09 -0400 Subject: [PATCH 01/22] Switched context header X-Parse-Context to X-Parse-Cloud-Context to match server --- CHANGELOG.md | 8 +++++++- ParseSwift.podspec | 2 +- ParseSwift.xcodeproj/project.pbxproj | 16 ++++++++-------- Scripts/jazzy.sh | 2 +- Sources/ParseSwift/API/API.swift | 2 +- Sources/ParseSwift/ParseConstants.swift | 2 +- Tests/ParseSwiftTests/APICommandTests.swift | 4 ++-- 7 files changed, 21 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 495691149..9be4c135d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,15 @@ # Parse-Swift Changelog ### main -[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.8.3...main) +[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.8.4...main) * _Contributing to this repo? Add info about your change here to be included in the next release_ +### 1.8.4 +[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.8.3...1.8.4) + +__Fixes__ +- Switched context header X-Parse-Context to X-Parse-Cloud-Context to match server ([#170](https://github.com/parse-community/Parse-Swift/pull/170)), thanks to [Corey Baker](https://github.com/cbaker6). + ### 1.8.3 [Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.8.2...1.8.3) diff --git a/ParseSwift.podspec b/ParseSwift.podspec index 5b58a472e..fb5f9dc8f 100644 --- a/ParseSwift.podspec +++ b/ParseSwift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "ParseSwift" - s.version = "1.8.3" + s.version = "1.8.4" s.summary = "Parse Pure Swift SDK" s.homepage = "https://github.com/parse-community/Parse-Swift" s.authors = { diff --git a/ParseSwift.xcodeproj/project.pbxproj b/ParseSwift.xcodeproj/project.pbxproj index 2a2ea96a7..9ecde3795 100644 --- a/ParseSwift.xcodeproj/project.pbxproj +++ b/ParseSwift.xcodeproj/project.pbxproj @@ -2433,7 +2433,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.8.3; + MARKETING_VERSION = 1.8.4; PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift; PRODUCT_NAME = ParseSwift; SKIP_INSTALL = YES; @@ -2457,7 +2457,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.8.3; + MARKETING_VERSION = 1.8.4; PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift; PRODUCT_NAME = ParseSwift; SKIP_INSTALL = YES; @@ -2523,7 +2523,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 1.8.3; + MARKETING_VERSION = 1.8.4; PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift; PRODUCT_NAME = ParseSwift; SDKROOT = macosx; @@ -2549,7 +2549,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 1.8.3; + MARKETING_VERSION = 1.8.4; PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift; PRODUCT_NAME = ParseSwift; SDKROOT = macosx; @@ -2696,7 +2696,7 @@ INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.8.3; + MARKETING_VERSION = 1.8.4; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS"; @@ -2725,7 +2725,7 @@ INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.8.3; + MARKETING_VERSION = 1.8.4; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS"; PRODUCT_NAME = ParseSwift; @@ -2752,7 +2752,7 @@ INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.8.3; + MARKETING_VERSION = 1.8.4; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS"; @@ -2780,7 +2780,7 @@ INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.8.3; + MARKETING_VERSION = 1.8.4; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS"; PRODUCT_NAME = ParseSwift; diff --git a/Scripts/jazzy.sh b/Scripts/jazzy.sh index 847065d8e..b38ebb8c9 100755 --- a/Scripts/jazzy.sh +++ b/Scripts/jazzy.sh @@ -5,7 +5,7 @@ bundle exec jazzy \ --author_url http://parseplatform.org \ --github_url https://github.com/parse-community/Parse-Swift \ --root-url http://parseplatform.org/Parse-Swift/api/ \ - --module-version 1.8.3 \ + --module-version 1.8.4 \ --theme fullwidth \ --skip-undocumented \ --output ./docs/api \ diff --git a/Sources/ParseSwift/API/API.swift b/Sources/ParseSwift/API/API.swift index 6e71bc20d..a35a850bb 100644 --- a/Sources/ParseSwift/API/API.swift +++ b/Sources/ParseSwift/API/API.swift @@ -201,7 +201,7 @@ public struct API { let context = AnyEncodable(context) if let encoded = try? ParseCoding.jsonEncoder().encode(context), let encodedString = String(data: encoded, encoding: .utf8) { - headers["X-Parse-Context"] = encodedString + headers["X-Parse-Cloud-Context"] = encodedString } } } diff --git a/Sources/ParseSwift/ParseConstants.swift b/Sources/ParseSwift/ParseConstants.swift index 7abbddf5d..ba5f4ec0b 100644 --- a/Sources/ParseSwift/ParseConstants.swift +++ b/Sources/ParseSwift/ParseConstants.swift @@ -10,7 +10,7 @@ import Foundation enum ParseConstants { static let sdk = "swift" - static let version = "1.8.1" + static let version = "1.8.4" static let hashingKey = "parseSwift" static let fileManagementDirectory = "parse/" static let fileManagementPrivateDocumentsDirectory = "Private Documents/" diff --git a/Tests/ParseSwiftTests/APICommandTests.swift b/Tests/ParseSwiftTests/APICommandTests.swift index 601266558..7b38df1aa 100644 --- a/Tests/ParseSwiftTests/APICommandTests.swift +++ b/Tests/ParseSwiftTests/APICommandTests.swift @@ -673,7 +673,7 @@ class APICommandTests: XCTestCase { func testContextHeader() { let headers = API.getHeaders(options: []) - XCTAssertNil(headers["X-Parse-Context"]) + XCTAssertNil(headers["X-Parse-Cloud-Context"]) let post = API.NonParseBodyCommand(method: .POST, path: .login) { _ in return nil @@ -682,7 +682,7 @@ class APICommandTests: XCTestCase { switch post.prepareURLRequest(options: [.context(["hello": "world"])]) { case .success(let request): - XCTAssertEqual(request.allHTTPHeaderFields?["X-Parse-Context"], "{\"hello\":\"world\"}") + XCTAssertEqual(request.allHTTPHeaderFields?["X-Parse-Cloud-Context"], "{\"hello\":\"world\"}") case .failure(let error): XCTFail(error.localizedDescription) } From cc1579b64b16464c82b878e22e5490e8718342fc Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 13:16:45 -0400 Subject: [PATCH 02/22] change min version in readme --- README.md | 2 +- android/.gradle/5.5/fileChanges/last-build.bin | Bin 1 -> 0 bytes android/.gradle/5.5/fileHashes/fileHashes.lock | Bin 17 -> 0 bytes android/.gradle/5.5/gc.properties | 0 .../buildOutputCleanup/buildOutputCleanup.lock | Bin 17 -> 0 bytes .../.gradle/buildOutputCleanup/cache.properties | 2 -- android/.gradle/vcs-1/gc.properties | 0 7 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 android/.gradle/5.5/fileChanges/last-build.bin delete mode 100644 android/.gradle/5.5/fileHashes/fileHashes.lock delete mode 100644 android/.gradle/5.5/gc.properties delete mode 100644 android/.gradle/buildOutputCleanup/buildOutputCleanup.lock delete mode 100644 android/.gradle/buildOutputCleanup/cache.properties delete mode 100644 android/.gradle/vcs-1/gc.properties diff --git a/README.md b/README.md index 15f56c85e..23474c05b 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ import PackageDescription let package = Package( name: "YOUR_PROJECT_NAME", dependencies: [ - .package(url: "https://github.com/parse-community/Parse-Swift", from: "1.8.3"), + .package(url: "https://github.com/parse-community/Parse-Swift", from: "1.8.4"), ] ) ``` diff --git a/android/.gradle/5.5/fileChanges/last-build.bin b/android/.gradle/5.5/fileChanges/last-build.bin deleted file mode 100644 index f76dd238ade08917e6712764a16a22005a50573d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1 IcmZPo000310RR91 diff --git a/android/.gradle/5.5/fileHashes/fileHashes.lock b/android/.gradle/5.5/fileHashes/fileHashes.lock deleted file mode 100644 index fa45df431248cd60ca226cebb198981158a7896c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17 ScmZQ}%Wp4n-(Bdy00jUlasy`o diff --git a/android/.gradle/5.5/gc.properties b/android/.gradle/5.5/gc.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock deleted file mode 100644 index df58d2eb378496500722db4dd5c68e00e3715e72..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 17 UcmZQ(JXa;WZQ`{e1_)pT052;8@Bjb+ diff --git a/android/.gradle/buildOutputCleanup/cache.properties b/android/.gradle/buildOutputCleanup/cache.properties deleted file mode 100644 index 43a8f09a5..000000000 --- a/android/.gradle/buildOutputCleanup/cache.properties +++ /dev/null @@ -1,2 +0,0 @@ -#Sat May 15 14:35:06 EDT 2021 -gradle.version=5.5 diff --git a/android/.gradle/vcs-1/gc.properties b/android/.gradle/vcs-1/gc.properties deleted file mode 100644 index e69de29bb..000000000 From bd51e0dab69d1a1dd4a46e358fc7e8dcdc0db80a Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 13:25:49 -0400 Subject: [PATCH 03/22] nit --- Tests/ParseSwiftTests/ParseLiveQueryTests.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift index 1f716639b..2c973ec17 100644 --- a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift +++ b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift @@ -544,13 +544,13 @@ class ParseLiveQueryTests: XCTestCase { guard let subscribed = subscription.subscribed else { XCTFail("Should unwrap subscribed.") expectation1.fulfill() + expectation2.fulfill() return } XCTAssertEqual(query, subscribed.query) XCTAssertTrue(subscribed.isNew) XCTAssertNil(subscription.unsubscribed) XCTAssertNil(subscription.event) - expectation1.fulfill() //Unsubscribe DispatchQueue.main.asyncAfter(deadline: .now() + 2) { @@ -581,6 +581,7 @@ class ParseLiveQueryTests: XCTestCase { client.received(encoded2) XCTAssertEqual(client.pendingSubscriptions.count, 0) XCTAssertEqual(client.subscriptions.count, 0) + expectation1.fulfill() } XCTAssertFalse(try client.isSubscribed(query)) From 9a1c94c3ab7e0c0fad431a362f7d8f633821e54f Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 17:48:32 -0400 Subject: [PATCH 04/22] Update flaky LiveQuery test case --- Tests/ParseSwiftTests/ParseLiveQueryTests.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift index 2c973ec17..414fa38a5 100644 --- a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift +++ b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift @@ -690,7 +690,7 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertNotNil(ParseLiveQuery.client?.task) originalTask = ParseLiveQuery.client?.task expectation1.fulfill() - } else if count == 2 { + } else { XCTAssertNotNil(ParseLiveQuery.client?.task) XCTAssertFalse(originalTask == ParseLiveQuery.client?.task) expectation2.fulfill() @@ -704,6 +704,8 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertFalse(socketEstablished) } else { XCTFail("Should have socket that isn't established") + expectation2.fulfill() + return } //Resubscribe @@ -712,15 +714,17 @@ class ParseLiveQueryTests: XCTestCase { subscription = try Query.subscribe(handler) } catch { XCTFail("\(error)") + expectation2.fulfill() + return } try? self.pretendToBeConnected() - let response2 = PreliminaryMessageResponse(op: .subscribed, requestId: 2, clientId: "yolo", installationId: "naw") guard let encoded2 = try? ParseCoding.jsonEncoder().encode(response2) else { + XCTFail("Should have encoded second response") expectation2.fulfill() return } From 676ff1c775a65a02a50a2197279bc4a2f1463be5 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 18:43:05 -0400 Subject: [PATCH 05/22] Improve LiveQuery playgrounds and test cases --- .../Contents.swift | 61 ++++++++----------- .../ParseSwiftTests/ParseLiveQueryTests.swift | 14 +++-- 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/ParseSwift.playground/Pages/11 - LiveQuery.xcplaygroundpage/Contents.swift b/ParseSwift.playground/Pages/11 - LiveQuery.xcplaygroundpage/Contents.swift index cf5fee33b..d5104d757 100644 --- a/ParseSwift.playground/Pages/11 - LiveQuery.xcplaygroundpage/Contents.swift +++ b/ParseSwift.playground/Pages/11 - LiveQuery.xcplaygroundpage/Contents.swift @@ -157,6 +157,9 @@ do { print(error) } +//: If you look at your server log, you will notice the client and server disconnnected. +//: This is because there is no more LiveQuery subscriptions. + //: Ping the LiveQuery server. This should produce an error //: because LiveQuery is disconnected. ParseLiveQuery.client?.sendPing { error in @@ -176,7 +179,7 @@ query2.fields("score") //: Subscribe to your new query. let subscription2 = query2.subscribeCallback! -//: As before, setup your subscription and event handlers. +//: As before, setup your subscription, event, and unsubscribe handlers. subscription2.handleSubscribe { subscribedQuery, isNew in //: You can check this subscription is for this query. @@ -203,6 +206,10 @@ subscription2.handleEvent { _, event in } } +subscription2.handleUnsubscribe { query in + print("Unsubscribed from \(query)") +} + //: To close the current LiveQuery connection. ParseLiveQuery.client?.close() @@ -219,41 +226,15 @@ ParseLiveQuery.client?.sendPing { error in } } -//: Subscribe to your new query. +//: Resubscribe to your previous query. +//: Since we never unsubscribed you can use your previous handlers. let subscription3 = query2.subscribeCallback! -//: As before, setup your subscription and event handlers. -subscription3.handleSubscribe { subscribedQuery, isNew in - - //: You can check this subscription is for this query. - if isNew { - print("Successfully subscribed to new query \(subscribedQuery)") - } else { - print("Successfully updated subscription to new query \(subscribedQuery)") - } -} - -subscription3.handleEvent { _, event in - switch event { - - case .entered(let object): - print("Entered: \(object)") - case .left(let object): - print("Left: \(object)") - case .created(let object): - print("Created: \(object)") - case .updated(let object): - print("Updated: \(object)") - case .deleted(let object): - print("Deleted: \(object)") - } -} - -//: Now lets subscribe to an additional query. +//: Resubscribe to another previous query. +//: This one needs new handlers. let subscription4 = query.subscribeCallback! -//: This is how you receive notifications about the success -//: of your subscription. +//: Need a new handler because we previously unsubscribed. subscription4.handleSubscribe { subscribedQuery, isNew in //: You can check this subscription is for this query @@ -264,7 +245,7 @@ subscription4.handleSubscribe { subscribedQuery, isNew in } } -//: This is how you register to receive notifications of events related to your LiveQuery. +//: Need a new event handler because we previously unsubscribed. subscription4.handleEvent { _, event in switch event { @@ -281,8 +262,8 @@ subscription4.handleEvent { _, event in } } -//: Now we will will unsubscribe from one of the subsriptions, but maintain the connection. -subscription3.handleUnsubscribe { query in +//: Need a new unsubscribe handler because we previously unsubscribed. +subscription4.handleUnsubscribe { query in print("Unsubscribed from \(query)") } @@ -302,5 +283,15 @@ ParseLiveQuery.client?.sendPing { error in } } +//: To unsubscribe from your your last query. +do { + try query.unsubscribe() +} catch { + print(error) +} + +//: If you look at your server log, you will notice the client and server disconnnected. +//: This is because there is no more LiveQuery subscriptions. + PlaygroundPage.current.finishExecution() //: [Next](@next) diff --git a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift index 414fa38a5..72d48aff4 100644 --- a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift +++ b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift @@ -67,6 +67,7 @@ class ParseLiveQueryTests: XCTestCase { guard let originalURL = URL(string: "http://localhost:1337/1"), var components = URLComponents(url: originalURL, resolvingAgainstBaseURL: false) else { + XCTFail("Should have retrieved URL components") return } components.scheme = (components.scheme == "https" || components.scheme == "wss") ? "wss" : "ws" @@ -93,6 +94,7 @@ class ParseLiveQueryTests: XCTestCase { guard let originalURL = URL(string: "http://parse:1337/1"), var components = URLComponents(url: originalURL, resolvingAgainstBaseURL: false) else { + XCTFail("Should have retrieved URL components") return } components.scheme = (components.scheme == "https" || components.scheme == "wss") ? "wss" : "ws" @@ -514,8 +516,8 @@ class ParseLiveQueryTests: XCTestCase { func pretendToBeConnected() throws { guard let client = ParseLiveQuery.getDefault() else { - XCTFail("Should be able to get client") - return + throw ParseError(code: .unknownError, + message: "Should be able to get client") } client.task = URLSession.liveQuery.createTask(client.url) client.status(.open) @@ -571,10 +573,11 @@ class ParseLiveQueryTests: XCTestCase { //Received Unsubscribe let response2 = PreliminaryMessageResponse(op: .unsubscribed, - requestId: 1, - clientId: "yolo", - installationId: "naw") + requestId: 1, + clientId: "yolo", + installationId: "naw") guard let encoded2 = try? ParseCoding.jsonEncoder().encode(response2) else { + XCTFail("Should have encoded second response") expectation2.fulfill() return } @@ -639,6 +642,7 @@ class ParseLiveQueryTests: XCTestCase { clientId: "yolo", installationId: "naw") guard let encoded2 = try? ParseCoding.jsonEncoder().encode(response2) else { + XCTFail("Should have encoded second response") expectation2.fulfill() return } From ed7cf9968bb4ebd8913b5e1a9148989de8394cf1 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 19:05:10 -0400 Subject: [PATCH 06/22] Make ParseError CustomDebugStringConvertible --- Sources/ParseSwift/Types/ParseError.swift | 34 ++++++++++++--------- Tests/ParseSwiftTests/ParseErrorTests.swift | 4 +-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Sources/ParseSwift/Types/ParseError.swift b/Sources/ParseSwift/Types/ParseError.swift index aca7dd7ec..543fd2fa8 100644 --- a/Sources/ParseSwift/Types/ParseError.swift +++ b/Sources/ParseSwift/Types/ParseError.swift @@ -11,7 +11,7 @@ import Foundation /** An object with a Parse code and message. */ -public struct ParseError: ParseType, Decodable, Swift.Error { +public struct ParseError: ParseType, Decodable, Swift.Error, CustomDebugStringConvertible { /// The value representing the error from the Parse Server. public let code: Code /// The text representing the error from the Parse Server. @@ -24,15 +24,6 @@ public struct ParseError: ParseType, Decodable, Swift.Error { self.otherCode = nil } - /// A textual representation of this error. - public var localizedDescription: String { - if let otherCode = otherCode { - return "ParseError code=\(code.rawValue) error=\(message) otherCode=\(otherCode)" - } else { - return "ParseError code=\(code.rawValue) error=\(message)" - } - } - enum CodingKeys: String, CodingKey { case code case message = "error" @@ -368,6 +359,17 @@ public struct ParseError: ParseType, Decodable, Swift.Error { } } +// MARK: Encodable +extension ParseError { + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(code, forKey: .code) + try container.encode(message, forKey: .message) + } +} + +// MARK: Decodable extension ParseError { public init(from decoder: Decoder) throws { @@ -381,10 +383,14 @@ extension ParseError { } message = try values.decode(String.self, forKey: .message) } +} - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(code, forKey: .code) - try container.encode(message, forKey: .message) +// MARK: CustomDebugStringConvertible +extension ParseError { + public var debugDescription: String { + guard let otherCode = otherCode else { + return "ParseError code=\(code.rawValue) error=\(message)" + } + return "ParseError code=\(code.rawValue) error=\(message) otherCode=\(otherCode)" } } diff --git a/Tests/ParseSwiftTests/ParseErrorTests.swift b/Tests/ParseSwiftTests/ParseErrorTests.swift index 18bcd68bf..7c5ffabb8 100644 --- a/Tests/ParseSwiftTests/ParseErrorTests.swift +++ b/Tests/ParseSwiftTests/ParseErrorTests.swift @@ -44,7 +44,7 @@ class ParseErrorTests: XCTestCase { let decoded = try ParseCoding.jsonDecoder().decode(ParseError.self, from: encoded) XCTAssertEqual(decoded.code.rawValue, code) XCTAssertEqual(decoded.message, message) - XCTAssertEqual(decoded.localizedDescription, "ParseError code=\(code) error=\(message)") + XCTAssertEqual(decoded.debugDescription, "ParseError code=\(code) error=\(message)") } func testEncodeOther() throws { @@ -57,7 +57,7 @@ class ParseErrorTests: XCTestCase { let decoded = try ParseCoding.jsonDecoder().decode(ParseError.self, from: encoded) XCTAssertEqual(decoded.code, .other) XCTAssertEqual(decoded.message, message) - XCTAssertEqual(decoded.localizedDescription, + XCTAssertEqual(decoded.debugDescription, "ParseError code=\(ParseError.Code.other.rawValue) error=\(message) otherCode=\(code)") XCTAssertEqual(decoded.otherCode, code) } From d0cdb1c86f152e15289da9d8ed7015e35c323dab Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 19:25:03 -0400 Subject: [PATCH 07/22] Use web socket cancel codes when closing --- Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift index 28877a5d2..6a6c2a5b3 100644 --- a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift +++ b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift @@ -543,7 +543,7 @@ extension ParseLiveQuery { public func close() { synchronizationQueue.sync { if self.isConnected { - self.task.cancel() + self.task.cancel(with: .goingAway, reason: nil) self.isDisconnectedByUser = true } if task != nil { @@ -582,14 +582,14 @@ extension ParseLiveQuery { if useDedicatedQueue { synchronizationQueue.async { if self.isConnected { - self.task.cancel() + self.task.cancel(with: .goingAway, reason: nil) } URLSession.liveQuery.delegates.removeValue(forKey: self.task) self.task = nil } } else { if self.isConnected { - self.task.cancel() + self.task.cancel(with: .goingAway, reason: nil) } if self.task != nil { URLSession.liveQuery.delegates.removeValue(forKey: self.task) From 0d9257612283e3fbb6c69ce7a0de3a9b09a6716d Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 20:39:46 -0400 Subject: [PATCH 08/22] setup autoversioning WIP --- ParseSwift.podspec => ParseSwift.podtemplate | 2 +- Scripts/jazzy.sh | 4 ++-- Sources/ParseSwift/ParseConstants.swift | 2 +- update_build | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) rename ParseSwift.podspec => ParseSwift.podtemplate (98%) create mode 100755 update_build diff --git a/ParseSwift.podspec b/ParseSwift.podtemplate similarity index 98% rename from ParseSwift.podspec rename to ParseSwift.podtemplate index fb5f9dc8f..28d3cd101 100644 --- a/ParseSwift.podspec +++ b/ParseSwift.podtemplate @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "ParseSwift" - s.version = "1.8.4" + s.version = "[[VERSION]]" s.summary = "Parse Pure Swift SDK" s.homepage = "https://github.com/parse-community/Parse-Swift" s.authors = { diff --git a/Scripts/jazzy.sh b/Scripts/jazzy.sh index b38ebb8c9..7092ccb95 100755 --- a/Scripts/jazzy.sh +++ b/Scripts/jazzy.sh @@ -1,11 +1,11 @@ -ver=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" ParseSwift-iOS/Info.plist` +ver=`cat ParseSwift.xcodeproj/project.pbxproj | grep -m1 'MARKETING_VERSION' | cut -d'=' -f2 | tr -d ';' | tr -d ' '` bundle exec jazzy \ --clean \ --author "Parse Community" \ --author_url http://parseplatform.org \ --github_url https://github.com/parse-community/Parse-Swift \ --root-url http://parseplatform.org/Parse-Swift/api/ \ - --module-version 1.8.4 \ + --module-version ${ver} \ --theme fullwidth \ --skip-undocumented \ --output ./docs/api \ diff --git a/Sources/ParseSwift/ParseConstants.swift b/Sources/ParseSwift/ParseConstants.swift index ba5f4ec0b..7abbddf5d 100644 --- a/Sources/ParseSwift/ParseConstants.swift +++ b/Sources/ParseSwift/ParseConstants.swift @@ -10,7 +10,7 @@ import Foundation enum ParseConstants { static let sdk = "swift" - static let version = "1.8.4" + static let version = "1.8.1" static let hashingKey = "parseSwift" static let fileManagementDirectory = "parse/" static let fileManagementPrivateDocumentsDirectory = "Private Documents/" diff --git a/update_build b/update_build new file mode 100755 index 000000000..097da5ee8 --- /dev/null +++ b/update_build @@ -0,0 +1,15 @@ +#!/bin/bash + +BUILD_VERSION=$(cat ParseSwift.xcodeproj/project.pbxproj | grep -m1 'MARKETING_VERSION' | cut -d'=' -f2 | tr -d ';' | tr -d ' ') + +#Update framework files +sed -i 's/1\.8\.3/${BUILD_VERSION}/g' Sources/ParseSwift/ParseConstants.swift + +# Prepare podspec update +TEMPLATE_FILE_NAME="ParseSwift.podtemplate" +OUT_FILE_NAME="ParseSwift.podspec" + +# Load the template podspec and replace version +TEMPLATE=$(cat "$TEMPLATE_FILE_NAME" | sed "s/\[\[VERSION\]\]/${BUILD_VERSION}/g") + +echo "$TEMPLATE" > "$OUT_FILE_NAME" From 751d4f70db91858292d02fa846bc674afd054935 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 20:59:58 -0400 Subject: [PATCH 09/22] working version update --- .github/workflows/ci.yml | 4 ++++ .github/workflows/release.yml | 4 ++++ Sources/ParseSwift/ParseConstants.swift | 2 +- update_build | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4972adc90..3d8b1acb9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,6 +126,8 @@ jobs: run: | bundle config path vendor/bundle bundle install + - name: Update Framework Version + run: ./update_build - name: Create Jazzy Docs run: ./Scripts/jazzy.sh @@ -134,6 +136,8 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v2 + - name: Update Framework Version + run: ./update_build - name: CocoaPods run: pod lib lint --allow-warnings diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c86433369..ff052d05c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,6 +10,8 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v2 + - name: Update Framework Version + run: ./update_build - name: CocoaPods run: set -o pipefail && env NSUnbufferedIO=YES pod lib lint --allow-warnings --verbose - name: Deploy CocoaPods @@ -33,6 +35,8 @@ jobs: run: | bundle config path vendor/bundle bundle install + - name: Update Framework Version + run: ./update_build - name: Create Jazzy Docs run: ./Scripts/jazzy.sh - name: Deploy Jazzy Docs diff --git a/Sources/ParseSwift/ParseConstants.swift b/Sources/ParseSwift/ParseConstants.swift index 7abbddf5d..1d7575e74 100644 --- a/Sources/ParseSwift/ParseConstants.swift +++ b/Sources/ParseSwift/ParseConstants.swift @@ -1,5 +1,5 @@ // -// ParseConstants.swift +// ParseConstants.${BUILD_VERSION} // ParseSwift // // Created by Corey Baker on 9/7/20. diff --git a/update_build b/update_build index 097da5ee8..4fdb496c0 100755 --- a/update_build +++ b/update_build @@ -3,7 +3,7 @@ BUILD_VERSION=$(cat ParseSwift.xcodeproj/project.pbxproj | grep -m1 'MARKETING_VERSION' | cut -d'=' -f2 | tr -d ';' | tr -d ' ') #Update framework files -sed -i 's/1\.8\.3/${BUILD_VERSION}/g' Sources/ParseSwift/ParseConstants.swift +sed -i '' -e "s/1\.8\.1/${BUILD_VERSION}/g" Sources/ParseSwift/ParseConstants.swift # Prepare podspec update TEMPLATE_FILE_NAME="ParseSwift.podtemplate" From ae9365e639620f7a4182efbab7cd7a109a407762 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 21:16:28 -0400 Subject: [PATCH 10/22] use actions tag for framework build release number --- .github/workflows/ci.yml | 4 ++++ .github/workflows/release.yml | 8 ++++++++ update_build | 2 -- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3d8b1acb9..d489d18e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -128,6 +128,8 @@ jobs: bundle install - name: Update Framework Version run: ./update_build + env: + BUILD_VERSION: '1.8.4' - name: Create Jazzy Docs run: ./Scripts/jazzy.sh @@ -138,6 +140,8 @@ jobs: - uses: actions/checkout@v2 - name: Update Framework Version run: ./update_build + env: + BUILD_VERSION: '1.8.4' - name: CocoaPods run: pod lib lint --allow-warnings diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ff052d05c..9f0ab42a9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,8 +10,12 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v2 + - name: Get release version + run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - name: Update Framework Version run: ./update_build + env: + BUILD_VERSION: ${{ env.TAG }} - name: CocoaPods run: set -o pipefail && env NSUnbufferedIO=YES pod lib lint --allow-warnings --verbose - name: Deploy CocoaPods @@ -23,6 +27,8 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v2 + - name: Get release version + run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - name: Cache Gems id: cache-gems uses: actions/cache@v2 @@ -39,6 +45,8 @@ jobs: run: ./update_build - name: Create Jazzy Docs run: ./Scripts/jazzy.sh + env: + BUILD_VERSION: ${{ env.TAG }} - name: Deploy Jazzy Docs uses: peaceiris/actions-gh-pages@v3 with: diff --git a/update_build b/update_build index 4fdb496c0..225e51604 100755 --- a/update_build +++ b/update_build @@ -1,7 +1,5 @@ #!/bin/bash -BUILD_VERSION=$(cat ParseSwift.xcodeproj/project.pbxproj | grep -m1 'MARKETING_VERSION' | cut -d'=' -f2 | tr -d ';' | tr -d ' ') - #Update framework files sed -i '' -e "s/1\.8\.1/${BUILD_VERSION}/g" Sources/ParseSwift/ParseConstants.swift From 2773746c13b398ee24a1b709973ad25bcd816a7d Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 21:22:14 -0400 Subject: [PATCH 11/22] make all dummy versions 1.8.3 --- .github/workflows/ci.yml | 4 ++-- ParseSwift.xcodeproj/project.pbxproj | 16 ++++++++-------- Sources/ParseSwift/ParseConstants.swift | 2 +- update_build | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d489d18e6..6657f2ac1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,7 +129,7 @@ jobs: - name: Update Framework Version run: ./update_build env: - BUILD_VERSION: '1.8.4' + BUILD_VERSION: '1.8.3' - name: Create Jazzy Docs run: ./Scripts/jazzy.sh @@ -141,7 +141,7 @@ jobs: - name: Update Framework Version run: ./update_build env: - BUILD_VERSION: '1.8.4' + BUILD_VERSION: '1.8.3' - name: CocoaPods run: pod lib lint --allow-warnings diff --git a/ParseSwift.xcodeproj/project.pbxproj b/ParseSwift.xcodeproj/project.pbxproj index 18c3914c3..d4755c232 100644 --- a/ParseSwift.xcodeproj/project.pbxproj +++ b/ParseSwift.xcodeproj/project.pbxproj @@ -2451,7 +2451,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.8.4; + MARKETING_VERSION = 1.8.3; PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift; PRODUCT_NAME = ParseSwift; SKIP_INSTALL = YES; @@ -2475,7 +2475,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.8.4; + MARKETING_VERSION = 1.8.3; PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift; PRODUCT_NAME = ParseSwift; SKIP_INSTALL = YES; @@ -2541,7 +2541,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 1.8.4; + MARKETING_VERSION = 1.8.3; PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift; PRODUCT_NAME = ParseSwift; SDKROOT = macosx; @@ -2567,7 +2567,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 1.8.4; + MARKETING_VERSION = 1.8.3; PRODUCT_BUNDLE_IDENTIFIER = com.parse.ParseSwift; PRODUCT_NAME = ParseSwift; SDKROOT = macosx; @@ -2714,7 +2714,7 @@ INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.8.4; + MARKETING_VERSION = 1.8.3; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS"; @@ -2743,7 +2743,7 @@ INFOPLIST_FILE = "ParseSwift-watchOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.8.4; + MARKETING_VERSION = 1.8.3; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-watchOS"; PRODUCT_NAME = ParseSwift; @@ -2770,7 +2770,7 @@ INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.8.4; + MARKETING_VERSION = 1.8.3; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS"; @@ -2798,7 +2798,7 @@ INFOPLIST_FILE = "ParseSwift-tvOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 1.8.4; + MARKETING_VERSION = 1.8.3; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.parse.ParseSwift-tvOS"; PRODUCT_NAME = ParseSwift; diff --git a/Sources/ParseSwift/ParseConstants.swift b/Sources/ParseSwift/ParseConstants.swift index 1d7575e74..559a3e158 100644 --- a/Sources/ParseSwift/ParseConstants.swift +++ b/Sources/ParseSwift/ParseConstants.swift @@ -10,7 +10,7 @@ import Foundation enum ParseConstants { static let sdk = "swift" - static let version = "1.8.1" + static let version = "1.8.3" static let hashingKey = "parseSwift" static let fileManagementDirectory = "parse/" static let fileManagementPrivateDocumentsDirectory = "Private Documents/" diff --git a/update_build b/update_build index 225e51604..668425133 100755 --- a/update_build +++ b/update_build @@ -1,7 +1,7 @@ #!/bin/bash #Update framework files -sed -i '' -e "s/1\.8\.1/${BUILD_VERSION}/g" Sources/ParseSwift/ParseConstants.swift +sed -i '' -e "s/1\.8\.3/${BUILD_VERSION}/g" Sources/ParseSwift/ParseConstants.swift # Prepare podspec update TEMPLATE_FILE_NAME="ParseSwift.podtemplate" From 18e8185f0b0c886539069b4afbf2d56665c1ca33 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 22:12:08 -0400 Subject: [PATCH 12/22] update ParseConstants.swift manually --- .github/workflows/ci.yml | 4 ---- .github/workflows/release.yml | 4 ---- Sources/ParseSwift/ParseConstants.swift | 2 +- update_build | 3 --- 4 files changed, 1 insertion(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6657f2ac1..1afe6b7c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,10 +126,6 @@ jobs: run: | bundle config path vendor/bundle bundle install - - name: Update Framework Version - run: ./update_build - env: - BUILD_VERSION: '1.8.3' - name: Create Jazzy Docs run: ./Scripts/jazzy.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9f0ab42a9..03d2461b0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,12 +41,8 @@ jobs: run: | bundle config path vendor/bundle bundle install - - name: Update Framework Version - run: ./update_build - name: Create Jazzy Docs run: ./Scripts/jazzy.sh - env: - BUILD_VERSION: ${{ env.TAG }} - name: Deploy Jazzy Docs uses: peaceiris/actions-gh-pages@v3 with: diff --git a/Sources/ParseSwift/ParseConstants.swift b/Sources/ParseSwift/ParseConstants.swift index 559a3e158..e4946dedf 100644 --- a/Sources/ParseSwift/ParseConstants.swift +++ b/Sources/ParseSwift/ParseConstants.swift @@ -10,7 +10,7 @@ import Foundation enum ParseConstants { static let sdk = "swift" - static let version = "1.8.3" + static let version = "1.8.4" static let hashingKey = "parseSwift" static let fileManagementDirectory = "parse/" static let fileManagementPrivateDocumentsDirectory = "Private Documents/" diff --git a/update_build b/update_build index 668425133..cb28eda12 100755 --- a/update_build +++ b/update_build @@ -1,8 +1,5 @@ #!/bin/bash -#Update framework files -sed -i '' -e "s/1\.8\.3/${BUILD_VERSION}/g" Sources/ParseSwift/ParseConstants.swift - # Prepare podspec update TEMPLATE_FILE_NAME="ParseSwift.podtemplate" OUT_FILE_NAME="ParseSwift.podspec" From b5dd8a1d2a1eab07597738b98af7c7b21d9586a1 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 23:12:58 -0400 Subject: [PATCH 13/22] Replace socket task instead of nil --- .../ParseSwift/LiveQuery/ParseLiveQuery.swift | 37 +++++++++---------- .../ParseSwiftTests/ParseLiveQueryTests.swift | 5 +-- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift index 6a6c2a5b3..f190eee85 100644 --- a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift +++ b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift @@ -199,7 +199,8 @@ public final class ParseLiveQuery: NSObject { } components.scheme = (components.scheme == "https" || components.scheme == "wss") ? "wss" : "ws" url = components.url - self.createTask() + self.task = URLSession.liveQuery.createTask(self.url) + self.resumeTask() if isDefault { Self.setDefault(self) @@ -226,12 +227,11 @@ extension ParseLiveQuery { return Int.random(in: 0 ..< Int(truncating: min)) } - func createTask() { + func resumeTask() { synchronizationQueue.sync { - if self.task == nil { - self.task = URLSession.liveQuery.createTask(self.url) + if self.task.state == .suspended { + self.task.resume() } - self.task.resume() URLSession.liveQuery.receive(self.task) URLSession.liveQuery.delegates[self.task] = self } @@ -317,7 +317,7 @@ extension ParseLiveQuery: LiveQuerySocketDelegate { self.isSocketEstablished = false if !self.isDisconnectedByUser { //Try to reconnect - self.createTask() + self.resumeTask() } } } @@ -329,7 +329,7 @@ extension ParseLiveQuery: LiveQuerySocketDelegate { if self.isConnected { self.close(useDedicatedQueue: true) //Try to reconnect - self.createTask() + self.resumeTask() } } return @@ -529,7 +529,7 @@ extension ParseLiveQuery { self.synchronizationQueue .asyncAfter(deadline: .now() + DispatchTimeInterval .seconds(reconnectInterval)) { - self.createTask() + self.resumeTask() self.attempts += 1 let error = ParseError(code: .unknownError, message: "Attempted to open socket \(self.attempts) time(s)") @@ -546,10 +546,9 @@ extension ParseLiveQuery { self.task.cancel(with: .goingAway, reason: nil) self.isDisconnectedByUser = true } - if task != nil { - URLSession.liveQuery.delegates.removeValue(forKey: self.task) - } - self.task = nil + URLSession.liveQuery.delegates.removeValue(forKey: self.task) + isSocketEstablished = false + self.task = URLSession.liveQuery.createTask(self.url) // Prepare new task for future use. } } @@ -568,11 +567,12 @@ extension ParseLiveQuery { */ public func sendPing(pongReceiveHandler: @escaping (Error?) -> Void) { synchronizationQueue.sync { - if isSocketEstablished { + if self.task.state == .running { URLSession.liveQuery.sendPing(task, pongReceiveHandler: pongReceiveHandler) } else { let error = ParseError(code: .unknownError, - message: "Need to open the websocket before it can be pinged.") + // swiftlint:disable:next line_length + message: "Socket status needs to be \"\(URLSessionTask.State.running.rawValue)\" before pinging server. Current status is \"\(self.task.state.rawValue)\".") pongReceiveHandler(error) } } @@ -585,16 +585,15 @@ extension ParseLiveQuery { self.task.cancel(with: .goingAway, reason: nil) } URLSession.liveQuery.delegates.removeValue(forKey: self.task) - self.task = nil + self.task = URLSession.liveQuery.createTask(self.url) // Prepare new task for future use. } } else { if self.isConnected { self.task.cancel(with: .goingAway, reason: nil) } - if self.task != nil { - URLSession.liveQuery.delegates.removeValue(forKey: self.task) - } - self.task = nil + URLSession.liveQuery.delegates.removeValue(forKey: self.task) + isSocketEstablished = false + self.task = URLSession.liveQuery.createTask(self.url) // Prepare new task for future use. } } diff --git a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift index 72d48aff4..bb3da61be 100644 --- a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift +++ b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift @@ -426,7 +426,6 @@ class ParseLiveQueryTests: XCTestCase { client.closeAll() client.synchronizationQueue.asyncAfter(deadline: .now() + 2) { XCTAssertFalse(client.isSocketEstablished) - XCTAssertNil(client.task) } } @@ -439,14 +438,13 @@ class ParseLiveQueryTests: XCTestCase { let expectation1 = XCTestExpectation(description: "Send Ping") client.sendPing { error in XCTAssertEqual(client.isSocketEstablished, false) - XCTAssertNil(client.task) guard let parseError = error as? ParseError else { XCTFail("Should have casted to ParseError.") expectation1.fulfill() return } XCTAssertEqual(parseError.code, ParseError.Code.unknownError) - XCTAssertTrue(parseError.message.contains("pinged")) + XCTAssertTrue(parseError.message.contains("Socket status")) expectation1.fulfill() } wait(for: [expectation1], timeout: 20.0) @@ -703,7 +701,6 @@ class ParseLiveQueryTests: XCTestCase { ParseLiveQuery.client?.close() ParseLiveQuery.client?.synchronizationQueue.sync { - XCTAssertNil(ParseLiveQuery.client?.task) if let socketEstablished = ParseLiveQuery.client?.isSocketEstablished { XCTAssertFalse(socketEstablished) } else { From ee0cdf20c5bc6b9073ee3e1f05e29657ce9460a8 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 23:17:06 -0400 Subject: [PATCH 14/22] nit actions release doc --- .github/workflows/release.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 03d2461b0..194de0639 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,8 +27,6 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v2 - - name: Get release version - run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - name: Cache Gems id: cache-gems uses: actions/cache@v2 From d59450cbb34cc4a8fd5806c0027eb880f4e63641 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 23:18:38 -0400 Subject: [PATCH 15/22] nit --- Sources/ParseSwift/ParseConstants.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ParseSwift/ParseConstants.swift b/Sources/ParseSwift/ParseConstants.swift index e4946dedf..ba5f4ec0b 100644 --- a/Sources/ParseSwift/ParseConstants.swift +++ b/Sources/ParseSwift/ParseConstants.swift @@ -1,5 +1,5 @@ // -// ParseConstants.${BUILD_VERSION} +// ParseConstants.swift // ParseSwift // // Created by Corey Baker on 9/7/20. From e7fb9f334d9e474b5eeba4b70379c88b8153c7fc Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 23:24:53 -0400 Subject: [PATCH 16/22] Fix ParseLiveQueryCombineTests --- Tests/ParseSwiftTests/ParseLiveQueryCombineTests.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Tests/ParseSwiftTests/ParseLiveQueryCombineTests.swift b/Tests/ParseSwiftTests/ParseLiveQueryCombineTests.swift index 538c9fbff..2a0a3f7cd 100644 --- a/Tests/ParseSwiftTests/ParseLiveQueryCombineTests.swift +++ b/Tests/ParseSwiftTests/ParseLiveQueryCombineTests.swift @@ -86,14 +86,13 @@ class ParseLiveQueryCombineTests: XCTestCase { XCTFail("Should have produced failure") case .failure(let error): XCTAssertEqual(client.isSocketEstablished, false) - XCTAssertNil(client.task) guard let parseError = error as? ParseError else { XCTFail("Should have casted to ParseError.") expectation1.fulfill() return } XCTAssertEqual(parseError.code, ParseError.Code.unknownError) - XCTAssertTrue(parseError.message.contains("pinged")) + XCTAssertTrue(parseError.message.contains("Socket status")) } expectation1.fulfill() From abe571f6babf1068b18aa50119a38d1306de1ec0 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 23:39:52 -0400 Subject: [PATCH 17/22] move update_build to scripts folder --- .github/workflows/release.yml | 2 +- update_build => Scripts/update_build | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename update_build => Scripts/update_build (100%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 194de0639..e99c2a18c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,7 +13,7 @@ jobs: - name: Get release version run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - name: Update Framework Version - run: ./update_build + run: ./Scripts/update_build env: BUILD_VERSION: ${{ env.TAG }} - name: CocoaPods diff --git a/update_build b/Scripts/update_build similarity index 100% rename from update_build rename to Scripts/update_build From dfc60a97aa0078ab91fbb1e6927ec9dfc6bbbb87 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 23:49:08 -0400 Subject: [PATCH 18/22] update cocoapods script in ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1afe6b7c6..0c0c13f38 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -135,7 +135,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Update Framework Version - run: ./update_build + run: ./Scripts/update_build env: BUILD_VERSION: '1.8.3' - name: CocoaPods From 4fc6e679a89ff7c93702d364181c4cb5b47a2811 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sat, 26 Jun 2021 23:55:31 -0400 Subject: [PATCH 19/22] fix jazzy docs to use tag for release number --- .github/workflows/ci.yml | 2 ++ .github/workflows/release.yml | 4 ++++ Scripts/jazzy.sh | 3 +-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c0c13f38..0313e4a5a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -128,6 +128,8 @@ jobs: bundle install - name: Create Jazzy Docs run: ./Scripts/jazzy.sh + env: + BUILD_VERSION: '1.8.3' cocoapods: needs: xcode-build-watchos diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e99c2a18c..ad3a57f74 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,8 +39,12 @@ jobs: run: | bundle config path vendor/bundle bundle install + - name: Get release version + run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV - name: Create Jazzy Docs run: ./Scripts/jazzy.sh + env: + BUILD_VERSION: ${{ env.TAG }} - name: Deploy Jazzy Docs uses: peaceiris/actions-gh-pages@v3 with: diff --git a/Scripts/jazzy.sh b/Scripts/jazzy.sh index 7092ccb95..297d9ac14 100755 --- a/Scripts/jazzy.sh +++ b/Scripts/jazzy.sh @@ -1,11 +1,10 @@ -ver=`cat ParseSwift.xcodeproj/project.pbxproj | grep -m1 'MARKETING_VERSION' | cut -d'=' -f2 | tr -d ';' | tr -d ' '` bundle exec jazzy \ --clean \ --author "Parse Community" \ --author_url http://parseplatform.org \ --github_url https://github.com/parse-community/Parse-Swift \ --root-url http://parseplatform.org/Parse-Swift/api/ \ - --module-version ${ver} \ + --module-version ${BUILD_VERSION} \ --theme fullwidth \ --skip-undocumented \ --output ./docs/api \ From 48dc40d210a92a813e4db4d8ca82623d36da066b Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sun, 27 Jun 2021 09:07:50 -0400 Subject: [PATCH 20/22] Add more details to error --- Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift index f190eee85..7a6555b24 100644 --- a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift +++ b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift @@ -572,7 +572,7 @@ extension ParseLiveQuery { } else { let error = ParseError(code: .unknownError, // swiftlint:disable:next line_length - message: "Socket status needs to be \"\(URLSessionTask.State.running.rawValue)\" before pinging server. Current status is \"\(self.task.state.rawValue)\".") + message: "Socket status needs to be \"\(URLSessionTask.State.running.rawValue)\" before pinging server. Current status is \"\(self.task.state.rawValue)\". Try calling \"open()\" to change socket status.") pongReceiveHandler(error) } } From badf39cbf63d15e13441847ac75da6b0099e4ae7 Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sun, 27 Jun 2021 09:14:57 -0400 Subject: [PATCH 21/22] Improve error descriptions. --- Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift | 6 +++--- Tests/ParseSwiftTests/ParseLiveQueryCombineTests.swift | 2 +- Tests/ParseSwiftTests/ParseLiveQueryTests.swift | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift index 7a6555b24..69e95a2c1 100644 --- a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift +++ b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift @@ -344,7 +344,7 @@ extension ParseLiveQuery: LiveQuerySocketDelegate { guard let parseError = try? ParseCoding.jsonDecoder().decode(ParseError.self, from: data) else { //Turn LiveQuery error into ParseError let parseError = ParseError(code: .unknownError, - message: "LiveQuery error code: \(error.code) message: \(error.error)") + message: "ParseLiveQuery error code: \(error.code), message: \(error.error)") self.notificationQueue.async { self.receiveDelegate?.received(parseError) } @@ -532,7 +532,7 @@ extension ParseLiveQuery { self.resumeTask() self.attempts += 1 let error = ParseError(code: .unknownError, - message: "Attempted to open socket \(self.attempts) time(s)") + message: "ParseLiveQuery Error: attempted to open socket \(self.attempts) time(s)") completion(error) } } @@ -572,7 +572,7 @@ extension ParseLiveQuery { } else { let error = ParseError(code: .unknownError, // swiftlint:disable:next line_length - message: "Socket status needs to be \"\(URLSessionTask.State.running.rawValue)\" before pinging server. Current status is \"\(self.task.state.rawValue)\". Try calling \"open()\" to change socket status.") + message: "ParseLiveQuery Error: socket status needs to be \"\(URLSessionTask.State.running.rawValue)\" before pinging server. Current status is \"\(self.task.state.rawValue)\". Try calling \"open()\" to change socket status.") pongReceiveHandler(error) } } diff --git a/Tests/ParseSwiftTests/ParseLiveQueryCombineTests.swift b/Tests/ParseSwiftTests/ParseLiveQueryCombineTests.swift index 2a0a3f7cd..88b8e7687 100644 --- a/Tests/ParseSwiftTests/ParseLiveQueryCombineTests.swift +++ b/Tests/ParseSwiftTests/ParseLiveQueryCombineTests.swift @@ -92,7 +92,7 @@ class ParseLiveQueryCombineTests: XCTestCase { return } XCTAssertEqual(parseError.code, ParseError.Code.unknownError) - XCTAssertTrue(parseError.message.contains("Socket status")) + XCTAssertTrue(parseError.message.contains("socket status")) } expectation1.fulfill() diff --git a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift index bb3da61be..83f0fe031 100644 --- a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift +++ b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift @@ -444,7 +444,7 @@ class ParseLiveQueryTests: XCTestCase { return } XCTAssertEqual(parseError.code, ParseError.Code.unknownError) - XCTAssertTrue(parseError.message.contains("Socket status")) + XCTAssertTrue(parseError.message.contains("socket status")) expectation1.fulfill() } wait(for: [expectation1], timeout: 20.0) From c2d25fca8d5777b4e34a2b4e96ae04670b86f05b Mon Sep 17 00:00:00 2001 From: Corey's iMac Date: Sun, 27 Jun 2021 09:18:53 -0400 Subject: [PATCH 22/22] nits --- Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift index 69e95a2c1..c1bf5163c 100644 --- a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift +++ b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift @@ -344,7 +344,8 @@ extension ParseLiveQuery: LiveQuerySocketDelegate { guard let parseError = try? ParseCoding.jsonDecoder().decode(ParseError.self, from: data) else { //Turn LiveQuery error into ParseError let parseError = ParseError(code: .unknownError, - message: "ParseLiveQuery error code: \(error.code), message: \(error.error)") + // swiftlint:disable:next line_length + message: "ParseLiveQuery Error: code: \(error.code), message: \(error.error)") self.notificationQueue.async { self.receiveDelegate?.received(parseError) } @@ -532,6 +533,7 @@ extension ParseLiveQuery { self.resumeTask() self.attempts += 1 let error = ParseError(code: .unknownError, + // swiftlint:disable:next line_length message: "ParseLiveQuery Error: attempted to open socket \(self.attempts) time(s)") completion(error) }