Skip to content

feat: add Sendable conformances and fix warnings #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main
pull_request:
branches:
- '*'
- "*"
workflow_dispatch:

concurrency:
Expand Down Expand Up @@ -37,41 +37,33 @@ jobs:
library-linux:
runs-on: ubuntu-latest
name: Test Library (Linux)
strategy:
matrix:
swift-version: ["5.8", "5.9"]
steps:
- uses: swift-actions/setup-swift@v1
with:
swift-version: "5.9"
swift-version: "${{ matrix.swift-version }}"
- uses: actions/checkout@v3
- name: Run Tests
run: swift test

library-compatibility:
runs-on: ubuntu-latest
name: Test Library (Swift 5.8)
library-windows:
runs-on: windows-latest
name: Test Library (Windows)
steps:
- uses: swift-actions/setup-swift@v1
# We use BCNY's repo since they have newer builds of Swift
# which have fixed libcurl in Foundation.
- uses: compnerd/gha-setup-swift@main
with:
swift-version: "5.8"
release-tag-name: "20231203.0"
github-repo: "thebrowsercompany/swift-build"
release-asset-name: installer-amd64.exe
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v3
- name: Run Tests
run: swift test

library-windows:
runs-on: windows-latest
name: Test Library (Windows)
steps:
# We use BCNY's repo since they have newer builds of Swift
# which have fixed libcurl in Foundation.
- uses: compnerd/gha-setup-swift@main
with:
release-tag-name: "20231203.0"
github-repo: "thebrowsercompany/swift-build"
release-asset-name: installer-amd64.exe
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v3
- name: Run Tests
run: swift test

examples:
runs-on: macos-14
name: Build Examples
Expand Down
2 changes: 1 addition & 1 deletion Examples/Examples/Auth/GoogleSignInSDKFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Created by Guilherme Souza on 05/03/24.
//

import SwiftUI
@preconcurrency import GoogleSignIn
import GoogleSignInSwift
import Supabase
import SwiftUI

@MainActor
struct GoogleSignInSDKFlow: View {
Expand Down
2 changes: 1 addition & 1 deletion Examples/Examples/ExamplesApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// Created by Guilherme Souza on 22/12/22.
//

import GoogleSignIn
import Supabase
import SwiftUI
import GoogleSignIn

@main
struct ExamplesApp: App {
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ let package = Package(

for target in package.targets where !target.isTest {
target.swiftSettings = [
.enableUpcomingFeature("StrictConcurrency=complete"),
.enableUpcomingFeature("ExistentialAny"),
.enableExperimentalFeature("StrictConcurrency"),
]
}
26 changes: 13 additions & 13 deletions Sources/Auth/AuthClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public actor AuthClient {
public let url: URL
public var headers: [String: String]
public let flowType: AuthFlowType
public let localStorage: AuthLocalStorage
public let logger: SupabaseLogger?
public let localStorage: any AuthLocalStorage
public let logger: (any SupabaseLogger)?
public let encoder: JSONEncoder
public let decoder: JSONDecoder
public let fetch: FetchHandler
Expand All @@ -37,8 +37,8 @@ public actor AuthClient {
url: URL,
headers: [String: String] = [:],
flowType: AuthFlowType = Configuration.defaultFlowType,
localStorage: AuthLocalStorage,
logger: SupabaseLogger? = nil,
localStorage: any AuthLocalStorage,
logger: (any SupabaseLogger)? = nil,
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
fetch: @escaping FetchHandler = { try await URLSession.shared.data(for: $0) }
Expand All @@ -64,23 +64,23 @@ public actor AuthClient {
Dependencies.current.value!.api
}

private var sessionManager: SessionManager {
private var sessionManager: any SessionManager {
Dependencies.current.value!.sessionManager
}

private var codeVerifierStorage: CodeVerifierStorage {
Dependencies.current.value!.codeVerifierStorage
}

private var eventEmitter: EventEmitter {
private var eventEmitter: any EventEmitter {
Dependencies.current.value!.eventEmitter
}

private var currentDate: @Sendable () -> Date {
Dependencies.current.value!.currentDate
}

private var logger: SupabaseLogger? {
private var logger: (any SupabaseLogger)? {
Dependencies.current.value!.logger
}

Expand Down Expand Up @@ -116,8 +116,8 @@ public actor AuthClient {
url: URL,
headers: [String: String] = [:],
flowType: AuthFlowType = AuthClient.Configuration.defaultFlowType,
localStorage: AuthLocalStorage,
logger: SupabaseLogger? = nil,
localStorage: any AuthLocalStorage,
logger: (any SupabaseLogger)? = nil,
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
fetch: @escaping FetchHandler = { try await URLSession.shared.data(for: $0) }
Expand Down Expand Up @@ -160,12 +160,12 @@ public actor AuthClient {
/// This internal initializer is here only for easy injecting mock instances when testing.
init(
configuration: Configuration,
sessionManager: SessionManager,
sessionManager: any SessionManager,
codeVerifierStorage: CodeVerifierStorage,
api: APIClient,
eventEmitter: EventEmitter,
eventEmitter: any EventEmitter,
sessionStorage: SessionStorage,
logger: SupabaseLogger?
logger: (any SupabaseLogger)?
) {
mfa = AuthMFA()
admin = AuthAdmin()
Expand Down Expand Up @@ -198,7 +198,7 @@ public actor AuthClient {
@discardableResult
public func onAuthStateChange(
_ listener: @escaping AuthStateChangeListener
) async -> AuthStateChangeListenerRegistration {
) async -> some AuthStateChangeListenerRegistration {
let handle = eventEmitter.attachListener(listener)
await emitInitialSession(forHandle: handle)
return handle
Expand Down
4 changes: 2 additions & 2 deletions Sources/Auth/AuthMFA.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ public actor AuthMFA {
Dependencies.current.value!.api
}

private var sessionManager: SessionManager {
private var sessionManager: any SessionManager {
Dependencies.current.value!.sessionManager
}

private var configuration: AuthClient.Configuration {
Dependencies.current.value!.configuration
}

private var eventEmitter: EventEmitter {
private var eventEmitter: any EventEmitter {
Dependencies.current.value!.eventEmitter
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Auth/Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extension AuthClient.Configuration {
url: URL,
headers: [String: String] = [:],
flowType: AuthFlowType = Self.defaultFlowType,
localStorage: AuthLocalStorage,
localStorage: any AuthLocalStorage,
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
fetch: @escaping AuthClient.FetchHandler = { try await URLSession.shared.data(for: $0) }
Expand Down Expand Up @@ -109,7 +109,7 @@ extension AuthClient {
url: URL,
headers: [String: String] = [:],
flowType: AuthFlowType = Configuration.defaultFlowType,
localStorage: AuthLocalStorage,
localStorage: any AuthLocalStorage,
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
fetch: @escaping AuthClient.FetchHandler = { try await URLSession.shared.data(for: $0) }
Expand Down
2 changes: 1 addition & 1 deletion Sources/Auth/Internal/CodeVerifierStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct CodeVerifierStorage: Sendable {

extension CodeVerifierStorage {
static var live: Self = {
var localStorage: AuthLocalStorage {
var localStorage: any AuthLocalStorage {
Dependencies.current.value!.configuration.localStorage
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Auth/Internal/Dependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ struct Dependencies: Sendable {
static let current = LockIsolated(Dependencies?.none)

var configuration: AuthClient.Configuration
var sessionManager: SessionManager
var sessionManager: any SessionManager
var api: APIClient
var eventEmitter: EventEmitter
var eventEmitter: any EventEmitter
var sessionStorage: SessionStorage
var sessionRefresher: SessionRefresher
var codeVerifierStorage: CodeVerifierStorage
var currentDate: @Sendable () -> Date = { Date() }
var logger: SupabaseLogger?
var logger: (any SupabaseLogger)?
}
2 changes: 1 addition & 1 deletion Sources/Auth/Internal/SessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ actor DefaultSessionManager: SessionManager {

private init() {}

private var task: Task<Session, Error>?
private var task: Task<Session, any Error>?

private var storage: SessionStorage {
Dependencies.current.value!.sessionStorage
Expand Down
2 changes: 1 addition & 1 deletion Sources/Auth/Internal/SessionStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct SessionStorage: Sendable {

extension SessionStorage {
static var live: Self = {
var localStorage: AuthLocalStorage {
var localStorage: any AuthLocalStorage {
Dependencies.current.value!.configuration.localStorage
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Auth/Storage/AuthLocalStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public protocol AuthLocalStorage: Sendable {

extension AuthClient.Configuration {
#if !os(Linux) && !os(Windows)
public static let defaultLocalStorage: AuthLocalStorage = KeychainLocalStorage(
public static let defaultLocalStorage: any AuthLocalStorage = KeychainLocalStorage(
service: "supabase.gotrue.swift",
accessGroup: nil
)
#elseif os(Windows)
public static let defaultLocalStorage: AuthLocalStorage =
public static let defaultLocalStorage: any AuthLocalStorage =
WinCredLocalStorage(service: "supabase.gotrue.swift")
#endif
}
6 changes: 3 additions & 3 deletions Sources/Auth/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ enum VerifyOTPParams: Encodable {
case email(VerifyEmailOTPParams)
case mobile(VerifyMobileOTPParams)

func encode(to encoder: Encoder) throws {
func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case let .email(value):
Expand Down Expand Up @@ -342,7 +342,7 @@ public enum AuthResponse: Codable, Hashable, Sendable {
case session(Session)
case user(User)

public init(from decoder: Decoder) throws {
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
if let value = try? container.decode(Session.self) {
self = .session(value)
Expand All @@ -356,7 +356,7 @@ public enum AuthResponse: Codable, Hashable, Sendable {
}
}

public func encode(to encoder: Encoder) throws {
public func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case let .session(value): try container.encode(value)
Expand Down
10 changes: 5 additions & 5 deletions Sources/PostgREST/PostgrestClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public actor PostgrestClient {
)

/// The configuration struct for the PostgREST client.
public struct Configuration {
public struct Configuration: Sendable {
public var url: URL
public var schema: String?
public var headers: [String: String]
public var fetch: FetchHandler
public var encoder: JSONEncoder
public var decoder: JSONDecoder

let logger: SupabaseLogger?
let logger: (any SupabaseLogger)?

/// Initializes a new configuration for the PostgREST client.
/// - Parameters:
Expand All @@ -37,7 +37,7 @@ public actor PostgrestClient {
url: URL,
schema: String? = nil,
headers: [String: String] = [:],
logger: SupabaseLogger? = nil,
logger: (any SupabaseLogger)? = nil,
fetch: @escaping FetchHandler = { try await URLSession.shared.data(for: $0) },
encoder: JSONEncoder = PostgrestClient.Configuration.jsonEncoder,
decoder: JSONDecoder = PostgrestClient.Configuration.jsonDecoder
Expand Down Expand Up @@ -75,7 +75,7 @@ public actor PostgrestClient {
url: URL,
schema: String? = nil,
headers: [String: String] = [:],
logger: SupabaseLogger? = nil,
logger: (any SupabaseLogger)? = nil,
fetch: @escaping FetchHandler = { try await URLSession.shared.data(for: $0) },
encoder: JSONEncoder = PostgrestClient.Configuration.jsonEncoder,
decoder: JSONDecoder = PostgrestClient.Configuration.jsonDecoder
Expand Down Expand Up @@ -126,7 +126,7 @@ public actor PostgrestClient {
/// - Throws: An error if the function call fails.
public func rpc(
_ fn: String,
params: some Encodable,
params: some Encodable & Sendable,
count: CountOption? = nil
) throws -> PostgrestFilterBuilder {
try PostgrestRpcBuilder(
Expand Down
Loading