Skip to content

Commit 82cbecd

Browse files
authored
Allow generic return types for ParseCloud, hint, and explain (#92)
* Allow generic return types for ParseCloud, hint, and explain * Change encoder/decoder of in memory storage * Make all test cases throw on setup and teardown * nits, improve decoding error reporting * nits and improved error reporting * Update changelog * Improve decode error * Improve decode error reporting and add test case * tweak keychain tests * Remove unnecessary error check * lower codecov patch * Prepare 1.2.0 release * Add date decoding test * nits
1 parent 0b0d775 commit 82cbecd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+380
-433
lines changed

.codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ coverage:
55
status:
66
patch:
77
default:
8-
target: auto
8+
target: 72
99
changes: false
1010
project:
1111
default:

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# Parse-Swift Changelog
22

33
### main
4-
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.1.7...main)
4+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.2.0...main)
55
* _Contributing to this repo? Add info about your change here to be included in the next release_
66

7-
### 1.1.7
8-
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.1.6...1.1.7)
7+
### 1.2.0
8+
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.1.6...1.2.0)
9+
10+
__Breaking changes__
11+
- Allows return types to be specified for `ParseCloud`, query `hint`, and `explain` (see playgrounds for examples). Changed functionality of synchronous `query.first()`. It use to return nil if no values are found. Now it will throw an error if none are found. ([#92](https://github.com/parse-community/Parse-Swift/pull/92)), thanks to [Corey Baker](https://github.com/cbaker6).
912

1013
__New features__
1114
- Add transaction support to batch saveAll and deleteAll ([#89](https://github.com/parse-community/Parse-Swift/pull/89)), thanks to [Corey Baker](https://github.com/cbaker6).
1215
- Add modifiers to containsString, hasPrefix, hasSuffix ([#85](https://github.com/parse-community/Parse-Swift/pull/85)), thanks to [Corey Baker](https://github.com/cbaker6).
1316

1417
__Improvements__
18+
- Better error reporting when decode errors occur ([#92](https://github.com/parse-community/Parse-Swift/pull/92)), thanks to [Corey Baker](https://github.com/cbaker6).
1519
- Can use a variadic version of exclude. Added examples of select and exclude query in playgrounds ([#88](https://github.com/parse-community/Parse-Swift/pull/88)), thanks to [Corey Baker](https://github.com/cbaker6).
1620

1721
### 1.1.6

ParseSwift.playground/Pages/10 - Cloud Code.xcplaygroundpage/Contents.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ initializeParse()
1515

1616
//: Create your own value typed `ParseCloud` type.
1717
struct Cloud: ParseCloud {
18+
19+
//: Return type of your Cloud Function
20+
typealias ReturnType = String
21+
1822
//: These are required for Object
1923
var functionJobName: String
2024

ParseSwift.playground/Pages/7 - GeoPoint.xcplaygroundpage/Contents.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct GameScore: ParseObject {
2222
var ACL: ParseACL?
2323
var location: ParseGeoPoint?
2424
//: Your own properties
25-
var score: Int
25+
var score: Int?
2626

2727
//: A custom initializer.
2828
init(score: Int) {
@@ -126,7 +126,6 @@ query3.find { results in
126126
switch results {
127127
case .success(let scores):
128128

129-
assert(scores.count >= 1)
130129
scores.forEach { (score) in
131130
print("""
132131
Someone has a score of \"\(score.score)\" with no geopoint \(String(describing: score.location))
@@ -164,7 +163,6 @@ query7.find { results in
164163
switch results {
165164
case .success(let scores):
166165

167-
assert(scores.count >= 1)
168166
scores.forEach { (score) in
169167
print("""
170168
Someone has a score of \"\(score.score)\" with geopoint using OR \(String(describing: score.location))
@@ -177,11 +175,19 @@ query7.find { results in
177175
}
178176

179177
//: Explain the previous query.
180-
let explain = try query2.find(explain: true)
178+
let explain: AnyDecodable = try query2.first(explain: true)
181179
print(explain)
182180

183-
let hint = try query2.find(explain: false, hint: "objectId")
184-
print(hint)
181+
//: Hint of the previous query (asynchronous)
182+
query2.find(explain: false,
183+
hint: "_id_") { (result: Result<[GameScore], ParseError>) in
184+
switch result {
185+
case .success(let scores):
186+
print(scores)
187+
case .failure(let error):
188+
print(error.localizedDescription)
189+
}
190+
}
185191

186192
PlaygroundPage.current.finishExecution()
187193
//: [Next](@next)

ParseSwift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "ParseSwift"
3-
s.version = "1.1.7"
3+
s.version = "1.2.0"
44
s.summary = "Parse Pure Swift SDK"
55
s.homepage = "https://github.com/parse-community/Parse-Swift"
66
s.authors = {

Scripts/jazzy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ bundle exec jazzy \
55
--author_url http://parseplatform.org \
66
--github_url https://github.com/parse-community/Parse-Swift \
77
--root-url http://parseplatform.org/Parse-Swift/api/ \
8-
--module-version 1.1.7 \
8+
--module-version 1.2.0 \
99
--theme fullwidth \
1010
--skip-undocumented \
1111
--output ./docs/api \

Sources/ParseSwift/API/API+Commands.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ internal extension API {
224224
var urlRequest = URLRequest(url: urlComponents)
225225
urlRequest.allHTTPHeaderFields = headers
226226
if let urlBody = body {
227-
if (urlBody as? ParseCloud) != nil {
227+
if (urlBody as? CloudType) != nil {
228228
guard let bodyData = try? ParseCoding.parseEncoder().encode(urlBody, skipKeys: .cloud) else {
229229
return .failure(ParseError(code: .unknownError,
230230
message: "couldn't encode body \(urlBody)"))

Sources/ParseSwift/API/Responses.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ internal struct FileUploadResponse: Decodable {
136136
}
137137

138138
// MARK: AnyResultResponse
139-
internal struct AnyResultResponse: Codable {
140-
let result: AnyCodable?
139+
internal struct AnyResultResponse<U: Decodable>: Decodable {
140+
let result: U
141141
}
142142

143143
// MARK: AnyResultsResponse
144-
internal struct AnyResultsResponse: Codable {
145-
let results: AnyCodable?
144+
internal struct AnyResultsResponse<U: Decodable>: Decodable {
145+
let results: [U]
146146
}
147147

148148
// MARK: ConfigResponse

Sources/ParseSwift/API/URLSession+extensions.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,17 @@ extension URLSession {
4343
return .failure(error)
4444
}
4545
guard let parseError = error as? ParseError else {
46+
guard JSONSerialization.isValidJSONObject(responseData) == true,
47+
let json = try? JSONSerialization
48+
.data(withJSONObject: responseData,
49+
options: .prettyPrinted) else {
50+
return .failure(ParseError(code: .unknownError,
51+
// swiftlint:disable:next line_length
52+
message: "Error decoding parse-server response: \(String(describing: urlResponse)) with error: \(error.localizedDescription) Format: \(String(describing: String(data: responseData, encoding: .utf8)))"))
53+
}
4654
return .failure(ParseError(code: .unknownError,
4755
// swiftlint:disable:next line_length
48-
message: "Error decoding parse-server response: \(String(describing: urlResponse)) with error: \(error.localizedDescription)"))
56+
message: "Error decoding parse-server response: \(String(describing: urlResponse)) with error: \(error.localizedDescription) Format: \(String(describing: String(data: json, encoding: .utf8)))"))
4957
}
5058
return .failure(parseError)
5159
}

Sources/ParseSwift/Coding/ParseCoding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ extension ParseCoding {
7676
message: "An invalid date string was provided when decoding dates."
7777
)
7878
}
79-
} catch let error {
79+
} catch {
8080
let container = try decoder.container(keyedBy: DateEncodingKeys.self)
8181

8282
if

0 commit comments

Comments
 (0)