Skip to content

Commit

Permalink
fix: overload QueryConstraint to accept Pointer<ParseObject> (#281)
Browse files Browse the repository at this point in the history
* fix: overload QueryConstraint to accept Pointer<ParseObject>

* Compile for Windows
  • Loading branch information
cbaker6 authored Nov 16, 2021
1 parent 25b70d9 commit a121bde
Show file tree
Hide file tree
Showing 92 changed files with 315 additions and 239 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

### main

[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.2.4...main)
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.2.5...main)
* _Contributing to this repo? Add info about your change here to be included in the next release_

### 2.2.5
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.2.4...2.2.5)

__Fixes__
- Overload QueryConstraint to accept Pointer<ParseObject> ([#281](https://github.com/parse-community/Parse-Swift/pull/281)), thanks to [Corey Baker](https://github.com/cbaker6).
- Add checks to build for Windows ([#281](https://github.com/parse-community/Parse-Swift/pull/281)), thanks to [Corey Baker](https://github.com/cbaker6).

### 2.2.4
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.2.3...2.2.4)

Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Extensions/URLCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal extension URLCache {
let parseCacheDirectory = "ParseCache"
let diskURL = cacheURL.appendingPathComponent(parseCacheDirectory, isDirectory: true)
if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) {
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
return URLCache(memoryCapacity: ParseSwift.configuration.cacheMemoryCapacity,
diskCapacity: ParseSwift.configuration.cacheDiskCapacity,
directory: diskURL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal struct BaseParseInstallation: ParseInstallation {
guard let installationId = Self.currentContainer.installationId,
Self.currentContainer.currentInstallation?.installationId == installationId else {
try? ParseStorage.shared.delete(valueFor: ParseStorage.Keys.currentInstallation)
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
try? KeychainStore.shared.delete(valueFor: ParseStorage.Keys.currentInstallation)
#endif
_ = Self.currentContainer
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/LiveQuery/LiveQuerySocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Corey Baker on 12/31/20.
// Copyright © 2020 Parse Community. All rights reserved.
//
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/LiveQuery/ParseLiveQuery+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2021 Parse Community. All rights reserved.
//

#if swift(>=5.5) && canImport(_Concurrency) && !os(Linux) && !os(Android)
#if swift(>=5.5) && canImport(_Concurrency) && !os(Linux) && !os(Android) && !os(Windows)
import Foundation

@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Corey Baker on 1/2/21.
// Copyright © 2021 Parse Community. All rights reserved.
//
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Corey Baker on 1/4/21.
// Copyright © 2021 Parse Community. All rights reserved.
//
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by Corey Baker on 1/4/21.
// Copyright © 2021 Parse Community. All rights reserved.
//
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
Expand Down
8 changes: 4 additions & 4 deletions Sources/ParseSwift/Objects/ParseInstallation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public extension ParseInstallation {
get {
guard let installationInMemory: CurrentInstallationContainer<Self> =
try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.currentInstallation) else {
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
guard let installationFromKeyChain: CurrentInstallationContainer<Self> =
try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.currentInstallation)
else {
Expand Down Expand Up @@ -191,14 +191,14 @@ public extension ParseInstallation {
}

internal static func saveCurrentContainerToKeychain() {
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
try? KeychainStore.shared.set(Self.currentContainer, for: ParseStorage.Keys.currentInstallation)
#endif
}

internal static func deleteCurrentContainerFromKeychain() {
try? ParseStorage.shared.delete(valueFor: ParseStorage.Keys.currentInstallation)
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
try? KeychainStore.shared.delete(valueFor: ParseStorage.Keys.currentInstallation)
#endif
//Prepare new installation
Expand Down Expand Up @@ -253,7 +253,7 @@ extension ParseInstallation {
guard let appInfo = Bundle.main.infoDictionary else {
return
}
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
#if TARGET_OS_MACCATALYST
// If using an Xcode new enough to know about Mac Catalyst:
// Mac Catalyst Apps use a prefix to the bundle ID. This should not be transmitted
Expand Down
8 changes: 4 additions & 4 deletions Sources/ParseSwift/Objects/ParseUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public extension ParseUser {
get {
guard let currentUserInMemory: CurrentUserContainer<Self>
= try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.currentUser) else {
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
return try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.currentUser)
#else
return nil
Expand All @@ -115,14 +115,14 @@ public extension ParseUser {
}

internal static func saveCurrentContainerToKeychain() {
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
try? KeychainStore.shared.set(Self.currentContainer, for: ParseStorage.Keys.currentUser)
#endif
}

internal static func deleteCurrentContainerFromKeychain() {
try? ParseStorage.shared.delete(valueFor: ParseStorage.Keys.currentUser)
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
if #available(macOS 10.15, iOS 13.0, macCatalyst 13.0, watchOS 6.0, tvOS 13.0, *) {
URLSession.liveQuery.closeAll()
}
Expand Down Expand Up @@ -992,7 +992,7 @@ extension ParseUser {
var mutableSelf = self
if let currentUser = Self.current,
currentUser.hasSameObjectId(as: mutableSelf) == true {
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
// swiftlint:disable:next line_length
if let currentUserContainerInKeychain: CurrentUserContainer<BaseParseUser> = try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.currentUser),
currentUserContainerInKeychain.currentUser?.email == mutableSelf.email {
Expand Down
8 changes: 4 additions & 4 deletions Sources/ParseSwift/Parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public struct ParseSwift {
let oneNineEightSDKVersion = try ParseVersion("1.9.8")

// All migrations from previous versions to current should occur here:
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
if previousSDKVersion < oneNineEightSDKVersion {
// Old macOS Keychain can't be used because it's global to all apps.
_ = KeychainStore.old
Expand Down Expand Up @@ -200,7 +200,7 @@ public struct ParseSwift {
}
BaseParseInstallation.createNewInstallationIfNeeded()

#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
if configuration.migrateFromObjcSDK {
if let identifier = Bundle.main.bundleIdentifier {
let objcParseKeychain = KeychainStore(service: "\(identifier).com.parse.sdk")
Expand Down Expand Up @@ -326,7 +326,7 @@ public struct ParseSwift {
}

static internal func deleteKeychainIfNeeded() {
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
// Clear items out of the Keychain on app first run.
if UserDefaults.standard.object(forKey: ParseConstants.bundlePrefix) == nil {
if Self.configuration.deleteKeychainIfNeeded == true {
Expand Down Expand Up @@ -357,7 +357,7 @@ public struct ParseSwift {
authentication: authentication)
}

#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
/**
Delete the Parse iOS Objective-C SDK Keychain from the device.
- note: ParseSwift uses a different Keychain. After migration, the iOS Objective-C SDK Keychain is no longer needed.
Expand Down
4 changes: 3 additions & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

enum ParseConstants {
static let sdk = "swift"
static let version = "2.2.4"
static let version = "2.2.5"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
static let fileManagementLibraryDirectory = "Library/"
Expand All @@ -29,5 +29,7 @@ enum ParseConstants {
static let deviceType = "linux"
#elseif os(Android)
static let deviceType = "android"
#elseif os(Windows)
static let deviceType = "windows"
#endif
}
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Storage/KeychainStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
import Security
#endif

#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)

func getKeychainQueryTemplate(forService service: String) -> [String: String] {
var query = [String: String]()
Expand Down
10 changes: 5 additions & 5 deletions Sources/ParseSwift/Storage/ParseFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
public struct ParseFileManager {

private var defaultDirectoryAttributes: [FileAttributeKey: Any]? {
#if os(macOS) || os(Linux) || os(Android)
#if os(macOS) || os(Linux) || os(Android) || os(Windows)
return nil
#else
return [.protectionKey: FileProtectionType.completeUntilFirstUserAuthentication]
Expand All @@ -21,14 +21,14 @@ public struct ParseFileManager {

private var defaultDataWritingOptions: Data.WritingOptions {
var options = Data.WritingOptions.atomic
#if !os(macOS) && !os(Linux) && !os(Android)
#if !os(macOS) && !os(Linux) && !os(Android) && !os(Windows)
options.insert(.completeFileProtectionUntilFirstUserAuthentication)
#endif
return options
}

private var localSandBoxDataDirectoryPath: URL? {
#if os(macOS) || os(Linux) || os(Android)
#if os(macOS) || os(Linux) || os(Android) || os(Windows)
return self.defaultDataDirectoryPath
#else
// swiftlint:disable:next line_length
Expand All @@ -51,7 +51,7 @@ public struct ParseFileManager {

/// The default directory for storing Parse files.
public var defaultDataDirectoryPath: URL? {
#if os(macOS) || os(Linux) || os(Android)
#if os(macOS) || os(Linux) || os(Android) || os(Windows)
var directoryPath: String!
let paths = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true)
guard let directory = paths.first else {
Expand Down Expand Up @@ -87,7 +87,7 @@ public struct ParseFileManager {
/// Creates an instance of `ParseFileManager`.
/// - returns: If an instance can't be created, nil is returned.
public init?() {
#if os(Linux) || os(Android)
#if os(Linux) || os(Android) || os(Windows)
let applicationId = ParseSwift.configuration.applicationId
applicationIdentifier = "\(ParseConstants.bundlePrefix).\(applicationId)"
#else
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Storage/ParseKeyValueStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct InMemoryKeyValueStore: ParseKeyValueStore {
}
}

#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)

// MARK: KeychainStore + ParseKeyValueStore
extension KeychainStore: ParseKeyValueStore {
Expand Down
4 changes: 2 additions & 2 deletions Sources/ParseSwift/Types/ParseACL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ extension ParseACL {

let aclController: DefaultACL?

#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
aclController = try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.defaultACL)
#else
aclController = try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.defaultACL)
Expand Down Expand Up @@ -385,7 +385,7 @@ extension ParseACL {
useCurrentUser: withAccessForCurrentUser)
}

#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
try KeychainStore.shared.set(aclController, for: ParseStorage.Keys.defaultACL)
#else
try ParseStorage.shared.set(aclController, for: ParseStorage.Keys.defaultACL)
Expand Down
6 changes: 3 additions & 3 deletions Sources/ParseSwift/Types/ParseConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public extension ParseConfig {
get {
guard let configInMemory: CurrentConfigContainer<Self> =
try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.currentConfig) else {
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
return try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.currentConfig)
#else
return nil
Expand All @@ -160,14 +160,14 @@ public extension ParseConfig {
}

internal static func saveCurrentContainerToKeychain() {
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
try? KeychainStore.shared.set(Self.currentContainer, for: ParseStorage.Keys.currentConfig)
#endif
}

internal static func deleteCurrentContainerFromKeychain() {
try? ParseStorage.shared.delete(valueFor: ParseStorage.Keys.currentConfig)
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
try? KeychainStore.shared.delete(valueFor: ParseStorage.Keys.currentConfig)
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/ParseSwift/Types/ParseVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct ParseVersion: Encodable {
get {
guard let versionInMemory: String =
try? ParseStorage.shared.get(valueFor: ParseStorage.Keys.currentVersion) else {
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
guard let versionFromKeyChain: String =
try? KeychainStore.shared.get(valueFor: ParseStorage.Keys.currentVersion)
else {
Expand All @@ -39,7 +39,7 @@ public struct ParseVersion: Encodable {
}
set {
try? ParseStorage.shared.set(newValue, for: ParseStorage.Keys.currentVersion)
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
try? KeychainStore.shared.set(newValue, for: ParseStorage.Keys.currentVersion)
#endif
}
Expand Down
36 changes: 25 additions & 11 deletions Sources/ParseSwift/Types/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,20 @@ public func == <T>(key: String, value: T) -> QueryConstraint where T: Encodable
- parameter key: The key that the value is stored in.
- parameter value: The `ParseObject` to compare.
- returns: The same instance of `QueryConstraint` as the receiver.
- throws: An error of type `ParseError`.
*/
public func == <T>(key: String, value: T) throws -> QueryConstraint where T: ParseObject {
let constraint: QueryConstraint!
do {
constraint = try QueryConstraint(key: key, value: value.toPointer())
} catch {
guard let parseError = error as? ParseError else {
throw ParseError(code: .unknownError,
message: error.localizedDescription)
}
throw parseError
}
return constraint
try QueryConstraint(key: key, value: value.toPointer())
}

/**
Add a constraint that requires that a key is equal to a `Pointer`.
- parameter key: The key that the value is stored in.
- parameter value: The `Pointer` to compare.
- returns: The same instance of `QueryConstraint` as the receiver.
*/
public func == <T>(key: String, value: Pointer<T>) -> QueryConstraint where T: ParseObject {
QueryConstraint(key: key, value: value)
}

/**
Expand Down Expand Up @@ -587,6 +588,19 @@ internal struct RelatedCondition <T>: Encodable where T: ParseObject {
- parameter key: The key that should be related.
- parameter object: The object that should be related.
- returns: The same instance of `Query` as the receiver.
- throws: An error of type `ParseError`.
*/
public func related <T>(key: String, object: T) throws -> QueryConstraint where T: ParseObject {
let pointer = try object.toPointer()
let condition = RelatedCondition(object: pointer, key: key)
return .init(key: QueryConstraint.Comparator.relatedTo.rawValue, value: condition)
}

/**
Add a constraint that requires a key is related.
- parameter key: The key that should be related.
- parameter object: The pointer object that should be related.
- returns: The same instance of `Query` as the receiver.
*/
public func related <T>(key: String, object: Pointer<T>) -> QueryConstraint where T: ParseObject {
let condition = RelatedCondition(object: object, key: key)
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/APICommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class APICommandTests: XCTestCase {
override func tearDownWithError() throws {
try super.tearDownWithError()
MockURLProtocol.removeAll()
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
try KeychainStore.shared.deleteAll()
#endif
try ParseStorage.shared.deleteAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class AnyCodableTests: XCTestCase {
}

//Test has objective-c
#if !os(Linux) && !os(Android)
#if !os(Linux) && !os(Android) && !os(Windows)
func testJSONEncoding() {
let dictionary: [String: AnyCodable] = [
"boolean": true,
Expand Down
Loading

0 comments on commit a121bde

Please sign in to comment.