Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ coverage:
status:
patch:
default:
target: auto
target: 79
changes: false
project:
default:
target: 87
target: 89
comment:
require_changes: true
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches: '*'
env:
CI_XCODE_VER: '/Applications/Xcode_12.5.1.app/Contents/Developer'
CI_XCODE_13: '/Applications/Xcode_13.4.app/Contents/Developer'
CI_XCODE_13: '/Applications/Xcode_13.4.1.app/Contents/Developer'

jobs:
xcode-test-ios:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
release:
types: [published]
env:
CI_XCODE_13: '/Applications/Xcode_13.4.app/Contents/Developer'
CI_XCODE_13: '/Applications/Xcode_13.4.1.app/Contents/Developer'

jobs:
cocoapods:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### main

__New features__
- Enable query caching by using GET instead of POST. GET is now used by default. To switch back to POST, set usingPostForQuery = true when initializing the SDK which will automatically disable all query caching ([#386](https://github.com/parse-community/Parse-Swift/pull/386)), thanks to [Corey Baker](https://github.com/cbaker6).

__Improvements__
- Added discardableResult to allow developers to choose whether or not certain functions should return a result ([#385](https://github.com/parse-community/Parse-Swift/pull/385)), thanks to [Damian Van de Kauter](https://github.com/vdkdamian).

Expand Down
133 changes: 112 additions & 21 deletions ParseSwift.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Sources/ParseSwift/API/API+Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ internal extension API {
func prepareURLRequest(options: API.Options,
childObjects: [String: PointerType]? = nil,
childFiles: [UUID: ParseFile]? = nil) -> Result<URLRequest, ParseError> {
let params = self.params?.getQueryItems()
let params = self.params?.getURLQueryItems()
var headers = API.getHeaders(options: options)
if method == .GET || method == .DELETE {
headers.removeValue(forKey: "X-Parse-Request-Id")
Expand Down
12 changes: 10 additions & 2 deletions Sources/ParseSwift/API/API+NonParseBodyCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal extension API {
let path: API.Endpoint
let body: T?
let mapper: ((Data) throws -> U)
let params: [String: String?]?

init(method: API.Method,
path: API.Endpoint,
Expand All @@ -27,6 +28,7 @@ internal extension API {
mapper: @escaping ((Data) throws -> U)) {
self.method = method
self.path = path
self.params = params
self.body = body
self.mapper = mapper
}
Expand Down Expand Up @@ -83,17 +85,23 @@ internal extension API {

// MARK: URL Preperation
func prepareURLRequest(options: API.Options) -> Result<URLRequest, ParseError> {
let params = self.params?.getURLQueryItems()
var headers = API.getHeaders(options: options)
if method == .GET || method == .DELETE {
headers.removeValue(forKey: "X-Parse-Request-Id")
}
let url = ParseSwift.configuration.serverURL.appendingPathComponent(path.urlComponent)

guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
let urlComponents = components.url else {
guard var components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
return .failure(ParseError(code: .unknownError,
message: "couldn't unrwrap url components for \(url)"))
}
components.queryItems = params

guard let urlComponents = components.url else {
return .failure(ParseError(code: .unknownError,
message: "couldn't create url from components for \(components)"))
}

var urlRequest = URLRequest(url: urlComponents)
urlRequest.allHTTPHeaderFields = headers
Expand Down
8 changes: 0 additions & 8 deletions Sources/ParseSwift/API/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,3 @@ public struct API {
ParseConstants.sdk+ParseConstants.version
}
}

internal extension Dictionary where Key == String, Value == String? {
func getQueryItems() -> [URLQueryItem] {
return map { (key, value) -> URLQueryItem in
return URLQueryItem(name: key, value: value)
}
}
}
17 changes: 17 additions & 0 deletions Sources/ParseSwift/Extensions/Dictionary.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Dictionary.swift
// ParseSwift
//
// Created by Corey Baker on 7/14/22.
// Copyright © 2022 Parse Community. All rights reserved.
//

import Foundation

internal extension Dictionary where Key == String, Value == String? {
func getURLQueryItems() -> [URLQueryItem] {
sorted { $0.key < $1.key }.map { (key, value) -> URLQueryItem in
URLQueryItem(name: key, value: value)
}
}
}
18 changes: 18 additions & 0 deletions Sources/ParseSwift/Parse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public struct ParseConfiguration {
/// - warning: This is known not to work for LiveQuery on Parse Servers <= 5.0.0.
public internal(set) var isUsingEqualQueryConstraint = false

/// Use **POST** instead of **GET** when making query calls.
/// Defaults to **false**.
/// - warning: **POST** calls are not cached and will require all queries to access the
/// server instead of following the `requestCachePolicy`.
public internal(set) var isUsingPostForQuery = false

/// The default caching policy for all http requests that determines when to
/// return a response from the cache. Defaults to `useProtocolCachePolicy`.
/// See Apple's [documentation](https://developer.apple.com/documentation/foundation/url_loading_system/accessing_cached_data)
Expand Down Expand Up @@ -85,6 +91,8 @@ public struct ParseConfiguration {
side for each object. Must be enabled on the server to work.
- parameter usingTransactions: Use transactions when saving/updating multiple objects.
- parameter usingEqualQueryConstraint: Use the **$eq** query constraint when querying.
- parameter usingPostForQuery: Use **POST** instead of **GET** when making query calls.
Defaults to **false**.
- parameter keyValueStore: A key/value store that conforms to the `ParseKeyValueStore`
protocol. Defaults to `nil` in which one will be created an memory, but never persisted. For Linux, this
this is the only store available since there is no Keychain. Linux users should replace this store with an
Expand All @@ -110,6 +118,7 @@ public struct ParseConfiguration {
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
- warning: `usingTransactions` is experimental.
- warning: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
- warning: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
*/
public init(applicationId: String,
clientKey: String? = nil,
Expand All @@ -121,6 +130,7 @@ public struct ParseConfiguration {
allowingCustomObjectIds: Bool = false,
usingTransactions: Bool = false,
usingEqualQueryConstraint: Bool = false,
usingPostForQuery: Bool = false,
keyValueStore: ParseKeyValueStore? = nil,
requestCachePolicy: URLRequest.CachePolicy = .useProtocolCachePolicy,
cacheMemoryCapacity: Int = 512_000,
Expand All @@ -140,6 +150,7 @@ public struct ParseConfiguration {
self.isAllowingCustomObjectIds = allowingCustomObjectIds
self.isUsingTransactions = usingTransactions
self.isUsingEqualQueryConstraint = usingEqualQueryConstraint
self.isUsingPostForQuery = usingPostForQuery
self.mountPath = "/" + serverURL.pathComponents
.filter { $0 != "/" }
.joined(separator: "/")
Expand Down Expand Up @@ -253,6 +264,8 @@ public struct ParseSwift {
side for each object. Must be enabled on the server to work.
- parameter usingTransactions: Use transactions when saving/updating multiple objects.
- parameter usingEqualQueryConstraint: Use the **$eq** query constraint when querying.
- parameter usingPostForQuery: Use **POST** instead of **GET** when making query calls.
Defaults to **false**.
- parameter keyValueStore: A key/value store that conforms to the `ParseKeyValueStore`
protocol. Defaults to `nil` in which one will be created an memory, but never persisted. For Linux, this
this is the only store available since there is no Keychain. Linux users should replace this store with an
Expand All @@ -276,6 +289,7 @@ public struct ParseSwift {
See Apple's [documentation](https://developer.apple.com/documentation/foundation/urlsessiontaskdelegate/1411595-urlsession) for more for details.
- warning: `usingTransactions` is experimental.
- warning: It is recomended to only specify `masterKey` when using the SDK on a server. Do not use this key on the client.
- warning: Setting `usingPostForQuery` to **true** will require all queries to access the server instead of following the `requestCachePolicy`.
*/
static public func initialize(
applicationId: String,
Expand All @@ -286,6 +300,7 @@ public struct ParseSwift {
allowingCustomObjectIds: Bool = false,
usingTransactions: Bool = false,
usingEqualQueryConstraint: Bool = false,
usingPostForQuery: Bool = false,
keyValueStore: ParseKeyValueStore? = nil,
requestCachePolicy: URLRequest.CachePolicy = .useProtocolCachePolicy,
cacheMemoryCapacity: Int = 512_000,
Expand All @@ -306,6 +321,7 @@ public struct ParseSwift {
allowingCustomObjectIds: allowingCustomObjectIds,
usingTransactions: usingTransactions,
usingEqualQueryConstraint: usingEqualQueryConstraint,
usingPostForQuery: usingPostForQuery,
keyValueStore: keyValueStore,
requestCachePolicy: requestCachePolicy,
cacheMemoryCapacity: cacheMemoryCapacity,
Expand All @@ -325,6 +341,7 @@ public struct ParseSwift {
allowingCustomObjectIds: Bool = false,
usingTransactions: Bool = false,
usingEqualQueryConstraint: Bool = false,
usingPostForQuery: Bool = false,
keyValueStore: ParseKeyValueStore? = nil,
requestCachePolicy: URLRequest.CachePolicy = .useProtocolCachePolicy,
cacheMemoryCapacity: Int = 512_000,
Expand All @@ -345,6 +362,7 @@ public struct ParseSwift {
allowingCustomObjectIds: allowingCustomObjectIds,
usingTransactions: usingTransactions,
usingEqualQueryConstraint: usingEqualQueryConstraint,
usingPostForQuery: usingPostForQuery,
keyValueStore: keyValueStore,
requestCachePolicy: requestCachePolicy,
cacheMemoryCapacity: cacheMemoryCapacity,
Expand Down
Loading