Skip to content

Commit

Permalink
Remove CreateAPI, add Hashable and Identifiable conformances (#48)
Browse files Browse the repository at this point in the history
* Remove CreateAPI, add Hashable and Identifiable conformances

* Fix method deprecation
  • Loading branch information
grdsdev authored Apr 10, 2023
1 parent c228065 commit b4aa56b
Show file tree
Hide file tree
Showing 8 changed files with 531 additions and 1,118 deletions.
2 changes: 1 addition & 1 deletion Examples/Shared/Sources/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct AppView: View {
ProgressView()
.task {
await client.initialize()
self.clientInitialized = true
clientInitialized = true
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Examples/Shared/Sources/AuthWithEmailAndPasswordView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct AuthWithEmailAndPasswordView: View {
private func signInButtonTapped() {
Task {
do {
self.error = nil
error = nil
try await client.signIn(email: email, password: password)
} catch {
self.error = error
Expand All @@ -60,7 +60,7 @@ struct AuthWithEmailAndPasswordView: View {
private func signUpButtonTapped() {
Task {
do {
self.error = nil
error = nil
try await client.signUp(email: email, password: password)
} catch {
self.error = error
Expand Down
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,4 @@ build-example:
format:
@swiftformat .

api:
create-api generate --output Sources/GoTrue/Generated --config .createapi.yml openapi.yaml
sed -i "" "s/public /internal /g" Sources/GoTrue/Generated/Paths.swift
$(MAKE) format

.PHONY: test-library build-example format test-library create-api
.PHONY: test-library build-example format test-library
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
// Generated by Create API
// https://github.com/CreateAPI/CreateAPI

import Foundation
import Get
import URLQueryEncoder

internal enum Paths {}
enum Paths {}

extension Paths {
internal static var token: Token {
static var token: Token {
Token(path: "/token")
}

internal struct Token {
struct Token {
/// Path: `/token`
internal let path: String
let path: String

internal func post(
func post(
grantType: GrantType,
redirectTo: URL? = nil,
_ body: PostRequest
Expand All @@ -31,17 +28,17 @@ extension Paths {
return encoder.items
}

internal enum GrantType: String, Codable, CaseIterable {
enum GrantType: String, Codable, CaseIterable {
case password
case refreshToken = "refresh_token"
case idToken = "id_token"
}

internal enum PostRequest: Encodable, Equatable {
enum PostRequest: Encodable, Equatable {
case userCredentials(GoTrue.UserCredentials)
case openIDConnectCredentials(GoTrue.OpenIDConnectCredentials)

internal func encode(to encoder: Encoder) throws {
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case let .userCredentials(value): try container.encode(value)
Expand All @@ -53,15 +50,15 @@ extension Paths {
}

extension Paths {
internal static var signup: Signup {
static var signup: Signup {
Signup(path: "/signup")
}

internal struct Signup {
struct Signup {
/// Path: `/signup`
internal let path: String
let path: String

internal func post(
func post(
redirectTo: URL? = nil,
_ body: GoTrue.SignUpRequest
) -> Request<GoTrue.AuthResponse> {
Expand All @@ -77,15 +74,15 @@ extension Paths {
}

extension Paths {
internal static var otp: Otp {
static var otp: Otp {
Otp(path: "/otp")
}

internal struct Otp {
struct Otp {
/// Path: `/otp`
internal let path: String
let path: String

internal func post(redirectTo: URL? = nil, _ body: GoTrue.OTPParams) -> Request<Void> {
func post(redirectTo: URL? = nil, _ body: GoTrue.OTPParams) -> Request<Void> {
Request(method: "POST", url: path, query: makePostQuery(redirectTo), body: body)
}

Expand All @@ -98,15 +95,15 @@ extension Paths {
}

extension Paths {
internal static var verify: Verify {
static var verify: Verify {
Verify(path: "/verify")
}

internal struct Verify {
struct Verify {
/// Path: `/verify`
internal let path: String
let path: String

internal func post(
func post(
redirectTo: URL? = nil,
_ body: GoTrue.VerifyOTPParams
) -> Request<GoTrue.AuthResponse> {
Expand All @@ -122,49 +119,49 @@ extension Paths {
}

extension Paths {
internal static var user: User {
static var user: User {
User(path: "/user")
}

internal struct User {
struct User {
/// Path: `/user`
internal let path: String
let path: String

internal var get: Request<GoTrue.User> {
var get: Request<GoTrue.User> {
Request(method: "GET", url: path)
}

internal func put(_ body: GoTrue.UserAttributes) -> Request<GoTrue.User> {
func put(_ body: GoTrue.UserAttributes) -> Request<GoTrue.User> {
Request(method: "PUT", url: path, body: body)
}
}
}

extension Paths {
internal static var logout: Logout {
static var logout: Logout {
Logout(path: "/logout")
}

internal struct Logout {
struct Logout {
/// Path: `/logout`
internal let path: String
let path: String

internal var post: Request<Void> {
var post: Request<Void> {
Request(method: "POST", url: path)
}
}
}

extension Paths {
internal static var recover: Recover {
static var recover: Recover {
Recover(path: "/recover")
}

internal struct Recover {
struct Recover {
/// Path: `/recover`
internal let path: String
let path: String

internal func post(redirectTo: URL? = nil, _ body: GoTrue.RecoverParams) -> Request<Void> {
func post(redirectTo: URL? = nil, _ body: GoTrue.RecoverParams) -> Request<Void> {
Request(method: "POST", url: path, query: makePostQuery(redirectTo), body: body)
}

Expand Down
Loading

0 comments on commit b4aa56b

Please sign in to comment.