Skip to content

Commit 66627b5

Browse files
authored
feat: Add concrete types ParseHookTrigger and ParseHookFunction (#122)
* feat: Add concrete types ParseHookTrigger and ParseHookFunction * nit * coverage * lower yield time of SDK init * more coverage * fix testcases * improve docs and codecov * fix mergeAutomatically() error * Update changelog message
1 parent 835083e commit 66627b5

28 files changed

+565
-227
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22
# Parse-Swift Changelog
33

44
### main
5-
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.7.4...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
5+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.8.0...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
66
* _Contributing to this repo? Add info about your change here to be included in the next release_
77

8+
### 5.8.0
9+
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.7.4...5.8.0), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.8.0/documentation/parseswift)
10+
11+
__New features__
12+
* Add concrete types: ParseHookTrigger and ParseHookFunction to reduce code developers need to write. Deprecate triggerName in favor of trigger where possible. The SDK also yields for 0.5 second as oppose to 1 second, which can lead to faster app starts ([#122](https://github.com/netreconlab/Parse-Swift/pull/122)), thanks to [Corey Baker](https://github.com/cbaker6).
13+
14+
__Fixes__
15+
* There was a problem when the developer did not implement merge() on a ParseObject and depended on the internal mergeAutomatically() to merge. If the developer used mergeAutomatically() indirectly for objects with different objectId's, the method allowed the merge. Now the method now throws the proper error ([#122](https://github.com/netreconlab/Parse-Swift/pull/122)), thanks to [Corey Baker](https://github.com/cbaker6).
16+
817
### 5.7.4
918
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.7.3...5.7.4), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.7.4/documentation/parseswift)
1019

ParseSwift.playground/Pages/12 - Roles and Relations.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ Task {
373373
Task {
374374
let score1 = GameScore(points: 53)
375375
//: You can also do
376-
// let specificRelation = try await User.current().relation("scores", className: "GameScore")
376+
// let specificRelation = try await User.current().relation("scores", object: GameScore.self)
377377
do {
378378
let currentUser = try await User.current()
379379
let specificRelation = try currentUser.relation("scores", child: score1)

ParseSwift.playground/Pages/22 - Cloud Hook Functions.xcplaygroundpage/Contents.swift

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,12 @@ Task {
2020
}
2121
}
2222

23-
/*:
24-
Parse Hook Functions can be created by conforming to
25-
`ParseHookFunctionable`.
26-
*/
27-
struct HookFunction: ParseHookFunctionable {
28-
var functionName: String?
29-
var url: URL?
30-
}
31-
3223
/*:
3324
Lets create our first Hook function by first creating an instance
3425
with the name of the function and url for the hook.
3526
*/
36-
var myFunction = HookFunction(name: "foo",
37-
url: URL(string: "https://api.example.com/foo"))
27+
var myFunction = ParseHookFunction(name: "foo",
28+
url: URL(string: "https://api.example.com/foo"))
3829

3930
//: Then, create the function on the server.
4031
myFunction.create { result in
@@ -101,7 +92,7 @@ myFunction.delete { result in
10192
You can also use the fetchAll type method to fetch all of
10293
the current Hook functions.
10394
*/
104-
HookFunction.fetchAll { result in
95+
ParseHookFunction.fetchAll { result in
10596
switch result {
10697
case .success(let functions):
10798
print("Current: \"\(functions)\"")

ParseSwift.playground/Pages/23 - Cloud Hook Triggers.xcplaygroundpage/Contents.swift

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,14 @@ struct GameScore: ParseObject {
4646
}
4747
}
4848

49-
/*:
50-
Parse Hook Triggers can be created by conforming to
51-
`ParseHookFunctionable`.
52-
*/
53-
struct HookTrigger: ParseHookTriggerable {
54-
var className: String?
55-
var triggerName: ParseHookTriggerType?
56-
var url: URL?
57-
}
58-
5949
/*:
6050
Lets create our first Hook trigger by first creating an instance
6151
with the name of the trigger and url for the hook.
6252
*/
6353
let gameScore = GameScore()
64-
var myTrigger = HookTrigger(object: gameScore,
65-
triggerName: .afterSave,
66-
url: URL(string: "https://api.example.com/bar")!)
54+
var myTrigger = ParseHookTrigger(object: gameScore,
55+
trigger: .afterSave,
56+
url: URL(string: "https://api.example.com/bar")!)
6757

6858
//: Then, create the trigger on the server.
6959
myTrigger.create { result in
@@ -130,7 +120,7 @@ myTrigger.delete { result in
130120
You can also use the fetchAll type method to fetch all of
131121
the current Hook triggers.
132122
*/
133-
HookTrigger.fetchAll { result in
123+
ParseHookTrigger.fetchAll { result in
134124
switch result {
135125
case .success(let triggers):
136126
print("Current: \"\(triggers)\"")

ParseSwift.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
7030E09029BBBFFA0021970D /* ParseConfigCodable+combine.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7030E08F29BBBFFA0021970D /* ParseConfigCodable+combine.swift */; };
5353
7030E09529BBC5740021970D /* ParseConfigCodableCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7030E09429BBC5740021970D /* ParseConfigCodableCombineTests.swift */; };
5454
7031F356296F553200E077CC /* APICommandMultipleAttemptsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7031F355296F553200E077CC /* APICommandMultipleAttemptsTests.swift */; };
55+
7034B9FD2A46380B00395CBC /* ParseHookTrigger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7034B9FC2A46380B00395CBC /* ParseHookTrigger.swift */; };
56+
7034B9FF2A46391200395CBC /* ParseHookFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7034B9FE2A46391200395CBC /* ParseHookFunction.swift */; };
5557
7037DAB226384DE1005D7E62 /* TestParseEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7037DAB126384DE1005D7E62 /* TestParseEncoder.swift */; };
5658
70385E6428563FD10084D306 /* ParsePushPayloadFirebaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70385E6328563FD10084D306 /* ParsePushPayloadFirebaseTests.swift */; };
5759
70385E68285640A30084D306 /* ParsePushPayloadAnyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70385E67285640A30084D306 /* ParsePushPayloadAnyTests.swift */; };
@@ -394,6 +396,8 @@
394396
7030E08F29BBBFFA0021970D /* ParseConfigCodable+combine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ParseConfigCodable+combine.swift"; sourceTree = "<group>"; };
395397
7030E09429BBC5740021970D /* ParseConfigCodableCombineTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseConfigCodableCombineTests.swift; sourceTree = "<group>"; };
396398
7031F355296F553200E077CC /* APICommandMultipleAttemptsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APICommandMultipleAttemptsTests.swift; sourceTree = "<group>"; };
399+
7034B9FC2A46380B00395CBC /* ParseHookTrigger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseHookTrigger.swift; sourceTree = "<group>"; };
400+
7034B9FE2A46391200395CBC /* ParseHookFunction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseHookFunction.swift; sourceTree = "<group>"; };
397401
7037DAB126384DE1005D7E62 /* TestParseEncoder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestParseEncoder.swift; sourceTree = "<group>"; };
398402
70385E6328563FD10084D306 /* ParsePushPayloadFirebaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParsePushPayloadFirebaseTests.swift; sourceTree = "<group>"; };
399403
70385E67285640A30084D306 /* ParsePushPayloadAnyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParsePushPayloadAnyTests.swift; sourceTree = "<group>"; };
@@ -1226,8 +1230,10 @@
12261230
7044C19025C4F5B60011F6E7 /* ParseFile+combine.swift */,
12271231
704E781B28CFFAF80075F952 /* ParseFileDefaultTransfer.swift */,
12281232
F97B45BC24D9C6F200F4A88B /* ParseGeoPoint.swift */,
1233+
7034B9FE2A46391200395CBC /* ParseHookFunction.swift */,
12291234
70385E7F2858EAA90084D306 /* ParseHookFunctionRequest.swift */,
12301235
70CE0A9328590A0A00DAEA86 /* ParseHookResponse.swift */,
1236+
7034B9FC2A46380B00395CBC /* ParseHookTrigger.swift */,
12311237
70CE0AB1285963A300DAEA86 /* ParseHookTriggerObjectRequest.swift */,
12321238
70B412B329801AFB00F706EA /* ParseHookTriggerRequest.swift */,
12331239
70D41D7F28B520E200613510 /* ParseKeychainAccessGroup.swift */,
@@ -1530,6 +1536,7 @@
15301536
70385E712858D2DD0084D306 /* ParseHookTriggerable.swift in Sources */,
15311537
91679D64268E596300F71809 /* ParseVersion.swift in Sources */,
15321538
91285B1C26990D7F0051B544 /* ParsePolygon.swift in Sources */,
1539+
7034B9FD2A46380B00395CBC /* ParseHookTrigger.swift in Sources */,
15331540
91BB8FCA2690AC99005A6BA5 /* QueryViewModel.swift in Sources */,
15341541
70B412B429801AFB00F706EA /* ParseHookTriggerRequest.swift in Sources */,
15351542
7085DD9426CBF3A70033B977 /* Documentation.docc in Sources */,
@@ -1595,6 +1602,7 @@
15951602
F97B465A24D9C78C00F4A88B /* ParseOperationIncrement.swift in Sources */,
15961603
7045769326BD8F8100F86F71 /* ParseInstallation+async.swift in Sources */,
15971604
7C55F9E72860CD6B002A352D /* ParseSpotify.swift in Sources */,
1605+
7034B9FF2A46391200395CBC /* ParseHookFunction.swift in Sources */,
15981606
7003960925A184EF0052CB31 /* ParseLiveQuery.swift in Sources */,
15991607
7044C17525C4ECFF0011F6E7 /* ParseCloudable+combine.swift in Sources */,
16001608
705025B32845C302008D6624 /* ParsePushStatus.swift in Sources */,

Sources/ParseSwift/API/API.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public struct API {
121121
case .hookTriggers:
122122
return "/hooks/triggers/"
123123
case .hookTrigger(let request):
124-
return "/hooks/triggers/\(request.className)/\(request.triggerName)"
124+
return "/hooks/triggers/\(request.className)/\(request.trigger)"
125125
case .serverInfo:
126126
return "/serverInfo"
127127
case .any(let path):

Sources/ParseSwift/Objects/ParseObject.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ public extension ParseObject {
357357
extension ParseObject {
358358

359359
func mergeAutomatically(_ originalObject: Self) throws -> Self {
360+
guard hasSameObjectId(as: originalObject) else {
361+
throw ParseError(code: .otherCause,
362+
message: "objectId's of objects do not match")
363+
}
360364
let updatedEncoded = try ParseCoding.jsonEncoder().encode(self)
361365
let originalData = try ParseCoding.jsonEncoder().encode(originalObject)
362366
guard let updated = try JSONSerialization.jsonObject(with: updatedEncoded) as? [String: AnyObject],

Sources/ParseSwift/Objects/ParseRole.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ public extension ParseRole {
8484
}
8585

8686
var users: ParseRelation<Self>? {
87-
try? ParseRelation(parent: self, key: "users", className: RoleUser.className)
87+
try? ParseRelation(parent: self, key: "users", object: RoleUser.self)
8888
}
8989

9090
var roles: ParseRelation<Self>? {
91-
try? ParseRelation(parent: self, key: "roles", className: Self.className)
91+
try? ParseRelation(parent: self, key: "roles", object: Self.self)
9292
}
9393

9494
init(name: String) throws {

Sources/ParseSwift/Parse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ internal func initialize(applicationId: String,
7070

7171
internal func yieldIfNotInitialized(_ iteration: Int = 0) async throws {
7272
guard ParseConfiguration.checkIfConfigured() else {
73-
guard iteration < 5 else {
73+
guard iteration < 10 else {
7474
throw ParseError(code: .otherCause,
7575
message: "The SDK needs to be initialized")
7676
}
77-
let nanoSeconds = UInt64(1 * 1_000_000_000)
77+
let nanoSeconds = UInt64(1 * 500_000_000)
7878
try await Task.sleep(nanoseconds: nanoSeconds)
7979
try await yieldIfNotInitialized(iteration + 1)
8080
return

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
enum ParseConstants {
1212
static let sdk = "swift"
13-
static let version = "5.7.4"
13+
static let version = "5.8.0"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
1616
static let fileManagementLibraryDirectory = "Library/"

0 commit comments

Comments
 (0)