Skip to content

Commit

Permalink
refactor: Update dependencies (#36)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cbaker6 committed Jun 20, 2023
1 parent a021d96 commit 9619d3c
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- uses: actions/checkout@v3
- uses: sersoft-gmbh/SwiftyActions@v2
with:
release-version: "5.7"
release-version: "5"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Test
run: set -o pipefail && env NSUnbufferedIO=YES swift test --enable-test-discovery --enable-code-coverage
Expand Down
1 change: 1 addition & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ builder:
configs:
- platform: macos-spm
documentation_targets: [ParseServerSwift]
swift_version: 5.9
12 changes: 6 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/netreconlab/Parse-Swift.git",
"state" : {
"revision" : "8ae529657e32d4b65c8c429dc5296ab865c4721d",
"version" : "5.7.0"
"revision" : "df20af5bdcbe349ffd65ad3626c86bddb1cfdd37",
"version" : "5.7.3"
}
},
{
Expand Down Expand Up @@ -122,8 +122,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "2d8e6ca36fe3e8ed74b0883f593757a45463c34d",
"version" : "2.53.0"
"revision" : "6213ba7a06febe8fef60563a4a7d26a4085783cf",
"version" : "2.54.0"
}
},
{
Expand All @@ -140,8 +140,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-http2.git",
"state" : {
"revision" : "6d021a48483dbb273a9be43f65234bdc9185b364",
"version" : "1.26.0"
"revision" : "a8ccf13fa62775277a5d56844878c828bbb3be1a",
"version" : "1.27.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "4.77.0")),
.package(url: "https://github.com/netreconlab/Parse-Swift.git",
.upToNextMajor(from: "5.7.0"))
.upToNextMajor(from: "5.7.3"))
],
targets: [
.target(
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ Cloud Code Functions can also take parameters. It's recommended to place all par
[ParseServerSwift/Sources/ParseServerSwift/Models/Parameters](https://github.com/netreconlab/ParseServerSwift/blob/main/Sources/ParseServerSwift/Models/Parameters)

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

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

// If a User called the request, fetch the complete user.
// If a User made the request, fetch the complete user.
if parseRequest.user != nil {
parseRequest = try await parseRequest.hydrateUser(request: req)
}
Expand Down
56 changes: 53 additions & 3 deletions Sources/ParseServerSwift/routes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func routes(_ app: Application) throws {
return "foo bar"
}

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

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

// Another simple Parse Hook Function route that returns the version of the server.
app.post("version",
name: "version") { req async throws -> ParseHookResponse<String> in
// Note that `ParseHookResponse<String>` means a "successfull"
// response will return a "String" type.
if let error: ParseHookResponse<String> = checkHeaders(req) {
return error
}
var parseRequest = try req.content
.decode(ParseHookFunctionRequest<User, FooParameters>.self)

// If a non-User made the request, they cannot see the version.
guard parseRequest.user != nil else {
let error = ParseError(code: .invalidSessionToken,
message: "User must be signed in to access server version")
return ParseHookResponse<String>(error: error)
}

do {
// If a User made the request, fetch the complete user to ensure
// their sessionToken is valid.
parseRequest = try await parseRequest.hydrateUser(request: req)
} catch {
guard let parseError = error as? ParseError else {
let error = ParseError(code: .otherCause,
swift: error)
return ParseHookResponse<String>(error: error)
}
return ParseHookResponse<String>(error: parseError)
}

do {
// Attempt to get version of the server.
guard let version = try await ParseServer.information().version else {
let error = ParseError(code: .otherCause,
message: "Could not retrieve any information from the Server")
return ParseHookResponse<String>(error: error)
}
req.logger.info("Server version is: \(version)")
return ParseHookResponse(success: "\(version)")
} catch {
guard let parseError = error as? ParseError else {
let error = ParseError(code: .otherCause,
swift: error)
return ParseHookResponse<String>(error: error)
}
return ParseHookResponse<String>(error: parseError)
}
}

// A Parse Hook Trigger route.
app.post("score", "save", "before",
className: GameScore.className,
Expand All @@ -50,7 +100,7 @@ func routes(_ app: Application) throws {
var parseRequest = try req.content
.decode(ParseHookTriggerObjectRequest<User, GameScore>.self)

// If a User called the request, fetch the complete user.
// If a User made the request, fetch the complete user.
if parseRequest.user != nil {
parseRequest = try await parseRequest.hydrateUser(request: req)
}
Expand Down

0 comments on commit 9619d3c

Please sign in to comment.