Skip to content

Commit 9619d3c

Browse files
authored
refactor: Update dependencies (#36)
* refactor: Update dependencies * add simple version CloudCode function * Update to ParseSwift latest version * lint * try swift 5.8 toolchain * Update ci.yml * Still use 5.7 docker image
1 parent a021d96 commit 9619d3c

File tree

6 files changed

+65
-14
lines changed

6 files changed

+65
-14
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
- uses: actions/checkout@v3
5151
- uses: sersoft-gmbh/SwiftyActions@v2
5252
with:
53-
release-version: "5.7"
53+
release-version: "5"
5454
github-token: ${{ secrets.GITHUB_TOKEN }}
5555
- name: Build and Test
5656
run: set -o pipefail && env NSUnbufferedIO=YES swift test --enable-test-discovery --enable-code-coverage

.spi.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ builder:
33
configs:
44
- platform: macos-spm
55
documentation_targets: [ParseServerSwift]
6+
swift_version: 5.9

Package.resolved

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let package = Package(
1818
dependencies: [
1919
.package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "4.77.0")),
2020
.package(url: "https://github.com/netreconlab/Parse-Swift.git",
21-
.upToNextMajor(from: "5.7.0"))
21+
.upToNextMajor(from: "5.7.3"))
2222
],
2323
targets: [
2424
.target(

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ Cloud Code Functions can also take parameters. It's recommended to place all par
258258
[ParseServerSwift/Sources/ParseServerSwift/Models/Parameters](https://github.com/netreconlab/ParseServerSwift/blob/main/Sources/ParseServerSwift/Models/Parameters)
259259

260260
```swift
261-
// A Parse Hook Function route.
261+
// A simple Parse Hook Function route that returns "Hello World".
262262
app.post("hello",
263263
name: "hello") { req async throws -> ParseHookResponse<String> in
264264
// Note that `ParseHookResponse<String>` means a "successfull"
@@ -269,7 +269,7 @@ app.post("hello",
269269
var parseRequest = try req.content
270270
.decode(ParseHookFunctionRequest<User, FooParameters>.self)
271271

272-
// If a User called the request, fetch the complete user.
272+
// If a User made the request, fetch the complete user.
273273
if parseRequest.user != nil {
274274
parseRequest = try await parseRequest.hydrateUser(request: req)
275275
}
@@ -297,7 +297,7 @@ app.post("score", "save", "before",
297297
var parseRequest = try req.content
298298
.decode(ParseHookTriggerObjectRequest<User, GameScore>.self)
299299

300-
// If a User called the request, fetch the complete user.
300+
// If a User made the request, fetch the complete user.
301301
if parseRequest.user != nil {
302302
parseRequest = try await parseRequest.hydrateUser(request: req)
303303
}

Sources/ParseServerSwift/routes.swift

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func routes(_ app: Application) throws {
1414
return "foo bar"
1515
}
1616

17-
// A Parse Hook Function route.
17+
// A simple Parse Hook Function route that returns "Hello World".
1818
app.post("hello",
1919
name: "hello") { req async throws -> ParseHookResponse<String> in
2020
// Note that `ParseHookResponse<String>` means a "successfull"
@@ -25,7 +25,7 @@ func routes(_ app: Application) throws {
2525
var parseRequest = try req.content
2626
.decode(ParseHookFunctionRequest<User, FooParameters>.self)
2727

28-
// If a User called the request, fetch the complete user.
28+
// If a User made the request, fetch the complete user.
2929
if parseRequest.user != nil {
3030
parseRequest = try await parseRequest.hydrateUser(request: req)
3131
}
@@ -38,6 +38,56 @@ func routes(_ app: Application) throws {
3838
return ParseHookResponse(success: "Hello world!")
3939
}
4040

41+
// Another simple Parse Hook Function route that returns the version of the server.
42+
app.post("version",
43+
name: "version") { req async throws -> ParseHookResponse<String> in
44+
// Note that `ParseHookResponse<String>` means a "successfull"
45+
// response will return a "String" type.
46+
if let error: ParseHookResponse<String> = checkHeaders(req) {
47+
return error
48+
}
49+
var parseRequest = try req.content
50+
.decode(ParseHookFunctionRequest<User, FooParameters>.self)
51+
52+
// If a non-User made the request, they cannot see the version.
53+
guard parseRequest.user != nil else {
54+
let error = ParseError(code: .invalidSessionToken,
55+
message: "User must be signed in to access server version")
56+
return ParseHookResponse<String>(error: error)
57+
}
58+
59+
do {
60+
// If a User made the request, fetch the complete user to ensure
61+
// their sessionToken is valid.
62+
parseRequest = try await parseRequest.hydrateUser(request: req)
63+
} catch {
64+
guard let parseError = error as? ParseError else {
65+
let error = ParseError(code: .otherCause,
66+
swift: error)
67+
return ParseHookResponse<String>(error: error)
68+
}
69+
return ParseHookResponse<String>(error: parseError)
70+
}
71+
72+
do {
73+
// Attempt to get version of the server.
74+
guard let version = try await ParseServer.information().version else {
75+
let error = ParseError(code: .otherCause,
76+
message: "Could not retrieve any information from the Server")
77+
return ParseHookResponse<String>(error: error)
78+
}
79+
req.logger.info("Server version is: \(version)")
80+
return ParseHookResponse(success: "\(version)")
81+
} catch {
82+
guard let parseError = error as? ParseError else {
83+
let error = ParseError(code: .otherCause,
84+
swift: error)
85+
return ParseHookResponse<String>(error: error)
86+
}
87+
return ParseHookResponse<String>(error: parseError)
88+
}
89+
}
90+
4191
// A Parse Hook Trigger route.
4292
app.post("score", "save", "before",
4393
className: GameScore.className,
@@ -50,7 +100,7 @@ func routes(_ app: Application) throws {
50100
var parseRequest = try req.content
51101
.decode(ParseHookTriggerObjectRequest<User, GameScore>.self)
52102

53-
// If a User called the request, fetch the complete user.
103+
// If a User made the request, fetch the complete user.
54104
if parseRequest.user != nil {
55105
parseRequest = try await parseRequest.hydrateUser(request: req)
56106
}

0 commit comments

Comments
 (0)