From 424ebfffbc3a6139c08d144107a2f3f4efbc3ef3 Mon Sep 17 00:00:00 2001 From: Corey Date: Tue, 20 Jun 2023 17:31:39 -0400 Subject: [PATCH] fix: remove all generic shadow warnings (#120) --- CHANGELOG.md | 15 ++++---- Sources/ParseSwift/API/API+Command.swift | 38 +++++++++---------- .../API/API+NonParseBodyCommand.swift | 2 +- .../LiveQuery/LiveQueryConstants.swift | 2 +- .../ParseSwift/LiveQuery/ParseLiveQuery.swift | 12 +++--- Sources/ParseSwift/ParseConstants.swift | 2 +- .../ParseSwift/Types/ParseServer+async.swift | 3 ++ .../Types/ParseServer+combine.swift | 3 ++ Sources/ParseSwift/Types/Query.swift | 8 ++-- 9 files changed, 46 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96f1b6ffa..5b34db100 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,19 +2,20 @@ # Parse-Swift Changelog ### main -[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.7.2...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift) +[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.7.3...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift) * _Contributing to this repo? Add info about your change here to be included in the next release_ +### 5.7.2 +[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.7.2...5.7.3), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.7.3/documentation/parseswift) + +__Fixes__ +* Remove all generic shadow warnings in Swift 5.9 ([#120](https://github.com/netreconlab/Parse-Swift/pull/120)), thanks to [Corey Baker](https://github.com/cbaker6). + ### 5.7.2 [Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.7.1...5.7.2), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.7.2/documentation/parseswift) __Fixes__ -* ParsePolygon encoding during a save and decoding resulted in (longitude, latitude) when it should be - (latitude, longitude). If a developer used ParseSwift <= 5.7.1 - to save/update ParsePolygon's, they will need to update the respective ParseObjects by swapping the latitude - and longitude manually. Deprecated withinPolygon() query constraint for geoPoint() and polygonContains() for - polygon() ([#118](https://github.com/netreconlab/Parse-Swift/pull/118)), thanks to -[Corey Baker](https://github.com/cbaker6). +* ParsePolygon encoding during a save and decoding resulted in (longitude, latitude) when it should be (latitude, longitude). If a developer used ParseSwift <= 5.7.1 to save/update ParsePolygon's, they will need to update the respective ParseObjects by swapping the latitude and longitude manually. Deprecated withinPolygon() query constraint for geoPoint() and polygonContains() for polygon() ([#118](https://github.com/netreconlab/Parse-Swift/pull/118)), thanks to [Corey Baker](https://github.com/cbaker6). ### 5.7.1 [Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.7.0...5.7.1), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.7.1/documentation/parseswift) diff --git a/Sources/ParseSwift/API/API+Command.swift b/Sources/ParseSwift/API/API+Command.swift index 4d5f8bcc5..f8c0c8184 100644 --- a/Sources/ParseSwift/API/API+Command.swift +++ b/Sources/ParseSwift/API/API+Command.swift @@ -401,10 +401,10 @@ internal extension API.Command { } // MARK: Saving ParseObjects - static func save(_ object: T, + static func save(_ object: V, original data: Data?, ignoringCustomObjectIdConfig: Bool, - batching: Bool = false) async throws -> API.Command where T: ParseObject { + batching: Bool = false) async throws -> API.Command where V: ParseObject { if Parse.configuration.isRequiringCustomObjectIds && object.objectId == nil && !ignoringCustomObjectIdConfig { throw ParseError(code: .missingObjectId, message: "objectId must not be nil") @@ -417,28 +417,28 @@ internal extension API.Command { return try await create(object) } - static func create(_ object: T) async throws -> API.Command where T: ParseObject { + static func create(_ object: V) async throws -> API.Command where V: ParseObject { var object = object if object.ACL == nil, let acl = try? await ParseACL.defaultACL() { object.ACL = acl } - let mapper = { (data) -> T in + let mapper = { (data) -> V in try ParseCoding.jsonDecoder().decode(CreateResponse.self, from: data).apply(to: object) } - return API.Command(method: .POST, + return API.Command(method: .POST, path: try await object.endpoint(.POST), body: object, mapper: mapper) } - static func replace(_ object: T, - original data: Data?) throws -> API.Command where T: ParseObject { + static func replace(_ object: V, + original data: Data?) throws -> API.Command where V: ParseObject { guard object.objectId != nil else { throw ParseError(code: .missingObjectId, message: "objectId must not be nil") } - let mapper = { (mapperData: Data) -> T in + let mapper = { (mapperData: Data) -> V in var updatedObject = object updatedObject.originalData = nil updatedObject = try ParseCoding @@ -446,26 +446,26 @@ internal extension API.Command { .decode(ReplaceResponse.self, from: mapperData) .apply(to: updatedObject) guard let originalData = data, - let original = try? ParseCoding.jsonDecoder().decode(T.self, + let original = try? ParseCoding.jsonDecoder().decode(V.self, from: originalData), original.hasSameObjectId(as: updatedObject) else { return updatedObject } return try updatedObject.merge(with: original) } - return API.Command(method: .PUT, + return API.Command(method: .PUT, path: object.endpoint, body: object, mapper: mapper) } - static func update(_ object: T, - original data: Data?) throws -> API.Command where T: ParseObject { + static func update(_ object: V, + original data: Data?) throws -> API.Command where V: ParseObject { guard object.objectId != nil else { throw ParseError(code: .missingObjectId, message: "objectId must not be nil") } - let mapper = { (mapperData: Data) -> T in + let mapper = { (mapperData: Data) -> V in var updatedObject = object updatedObject.originalData = nil updatedObject = try ParseCoding @@ -473,21 +473,21 @@ internal extension API.Command { .decode(UpdateResponse.self, from: mapperData) .apply(to: updatedObject) guard let originalData = data, - let original = try? ParseCoding.jsonDecoder().decode(T.self, + let original = try? ParseCoding.jsonDecoder().decode(V.self, from: originalData), original.hasSameObjectId(as: updatedObject) else { return updatedObject } return try updatedObject.merge(with: original) } - return API.Command(method: .PATCH, + return API.Command(method: .PATCH, path: object.endpoint, body: object, mapper: mapper) } // MARK: Fetching ParseObjects - static func fetch(_ object: T, include: [String]?) throws -> API.Command where T: ParseObject { + static func fetch(_ object: V, include: [String]?) throws -> API.Command where V: ParseObject { guard object.objectId != nil else { throw ParseError(code: .missingObjectId, message: "objectId must not be nil") @@ -498,12 +498,12 @@ internal extension API.Command { params = ["include": "\(Set(includeParams))"] } - return API.Command( + return API.Command( method: .GET, path: object.endpoint, params: params - ) { (data) -> T in - try ParseCoding.jsonDecoder().decode(T.self, from: data) + ) { (data) -> V in + try ParseCoding.jsonDecoder().decode(V.self, from: data) } } } diff --git a/Sources/ParseSwift/API/API+NonParseBodyCommand.swift b/Sources/ParseSwift/API/API+NonParseBodyCommand.swift index d1fb47d43..5c932b03b 100644 --- a/Sources/ParseSwift/API/API+NonParseBodyCommand.swift +++ b/Sources/ParseSwift/API/API+NonParseBodyCommand.swift @@ -113,7 +113,7 @@ internal extension API { internal extension API.NonParseBodyCommand { // MARK: Deleting - static func delete(_ object: T) throws -> API.NonParseBodyCommand where T: ParseObject { + static func delete(_ object: V) throws -> API.NonParseBodyCommand where V: ParseObject { guard object.isSaved else { throw ParseError(code: .otherCause, message: "Cannot delete an object without an objectId") diff --git a/Sources/ParseSwift/LiveQuery/LiveQueryConstants.swift b/Sources/ParseSwift/LiveQuery/LiveQueryConstants.swift index 601175c4f..7dbed0b3c 100644 --- a/Sources/ParseSwift/LiveQuery/LiveQueryConstants.swift +++ b/Sources/ParseSwift/LiveQuery/LiveQueryConstants.swift @@ -43,7 +43,7 @@ public enum Event: Equatable { } } - public static func == (lhs: Event, rhs: Event) -> Bool { + public static func == (lhs: Event, rhs: Event) -> Bool { switch (lhs, rhs) { case (.entered(let obj1), .entered(let obj2)): return obj1 == obj2 case (.left(let obj1), .left(let obj2)): return obj1 == obj2 diff --git a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift index 2ad7cb034..0a69b7aa3 100644 --- a/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift +++ b/Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift @@ -893,7 +893,7 @@ public extension Query { - returns: Your subscription handler, for easy chaining. - throws: An error of type `ParseError`. */ - static func subscribe(_ handler: T) async throws -> T { + static func subscribe(_ handler: V) async throws -> V { try await ParseLiveQuery.client().subscribe(handler) } @@ -904,7 +904,7 @@ public extension Query { - returns: Your subscription handler, for easy chaining. - throws: An error of type `ParseError`. */ - static func subscribe(_ handler: T, client: ParseLiveQuery) async throws -> T { + static func subscribe(_ handler: V, client: ParseLiveQuery) async throws -> V { try await ParseLiveQuery.client().subscribe(handler) } @@ -957,7 +957,7 @@ public extension Query { - parameter handler: The specific handler to unsubscribe from. - throws: An error of type `ParseError`. */ - func unsubscribe(_ handler: T) async throws { + func unsubscribe(_ handler: V) async throws { try await ParseLiveQuery.client().unsubscribe(handler) } @@ -968,7 +968,7 @@ public extension Query { - parameter client: A specific client. - throws: An error of type `ParseError`. */ - func unsubscribe(_ handler: T, client: ParseLiveQuery) async throws { + func unsubscribe(_ handler: V, client: ParseLiveQuery) async throws { try await client.unsubscribe(handler) } } @@ -981,7 +981,7 @@ public extension Query { - parameter handler: The specific handler to update. - throws: An error of type `ParseError`. */ - func update(_ handler: T) async throws { + func update(_ handler: V) async throws { try await ParseLiveQuery.client().update(handler) } @@ -992,7 +992,7 @@ public extension Query { - parameter client: A specific client. - throws: An error of type `ParseError`. */ - func update(_ handler: T, client: ParseLiveQuery) async throws { + func update(_ handler: V, client: ParseLiveQuery) async throws { try await client.update(handler) } } diff --git a/Sources/ParseSwift/ParseConstants.swift b/Sources/ParseSwift/ParseConstants.swift index daa8420f0..25bf3dcba 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 = "5.7.2" + static let version = "5.7.3" static let fileManagementDirectory = "parse/" static let fileManagementPrivateDocumentsDirectory = "Private Documents/" static let fileManagementLibraryDirectory = "Library/" diff --git a/Sources/ParseSwift/Types/ParseServer+async.swift b/Sources/ParseSwift/Types/ParseServer+async.swift index e455ba1d5..30af6f810 100644 --- a/Sources/ParseSwift/Types/ParseServer+async.swift +++ b/Sources/ParseSwift/Types/ParseServer+async.swift @@ -50,6 +50,9 @@ public extension ParseServer { - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: Status of ParseServer. - throws: An error of type `ParseError`. + - requires: `.usePrimaryKey` has to be available. It is recommended to only + use the primary key in server-side applications where the key is kept secure and not + exposed to the public. */ static func information(options: API.Options = []) async throws -> Information { try await withCheckedThrowingContinuation { continuation in diff --git a/Sources/ParseSwift/Types/ParseServer+combine.swift b/Sources/ParseSwift/Types/ParseServer+combine.swift index bc0d216bd..08951b19e 100644 --- a/Sources/ParseSwift/Types/ParseServer+combine.swift +++ b/Sources/ParseSwift/Types/ParseServer+combine.swift @@ -49,6 +49,9 @@ public extension ParseServer { Retrieves any information provided by the server *asynchronously*. Publishes when complete. - parameter options: A set of header options sent to the server. Defaults to an empty set. - returns: A publisher that eventually produces a single value and then finishes or fails. + - requires: `.usePrimaryKey` has to be available. It is recommended to only + use the primary key in server-side applications where the key is kept secure and not + exposed to the public. */ static func informationPublisher(options: API.Options = []) -> Future { Future { promise in diff --git a/Sources/ParseSwift/Types/Query.swift b/Sources/ParseSwift/Types/Query.swift index c41aa2b60..7301d5557 100644 --- a/Sources/ParseSwift/Types/Query.swift +++ b/Sources/ParseSwift/Types/Query.swift @@ -46,13 +46,13 @@ public struct Query: ParseTypeable where T: ParseObject { Self.className } - struct AggregateBody: Codable where T: ParseObject { + struct AggregateBody: Codable where V: ParseObject { let pipeline: [[String: AnyCodable]]? let hint: AnyCodable? let explain: Bool? let includeReadPreference: String? - init(query: Query) { + init(query: Query) { pipeline = query.pipeline hint = query.hint explain = query.explain @@ -77,13 +77,13 @@ public struct Query: ParseTypeable where T: ParseObject { } } - struct DistinctBody: Codable where T: ParseObject { + struct DistinctBody: Codable where V: ParseObject { let hint: AnyCodable? let explain: Bool? let includeReadPreference: String? let distinct: String? - init(query: Query) { + init(query: Query) { distinct = query.distinct hint = query.hint explain = query.explain