Skip to content
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

fix: build for Swift 5.9 #577

Merged
merged 4 commits into from
Oct 24, 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
matrix:
command: [test, ""]
platform: [IOS, MAC_CATALYST, MACOS, TVOS, VISIONOS, WATCHOS]
xcode: [15.4, "16.0"]
xcode: ["15.4", "16.0"]
exclude:
- { platform: VISIONOS }
include:
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ test-docs:
format:
@swift format -i -r --ignore-unparsable-files .


test-linux:
docker run \
--rm \
-v "$(PWD):$(PWD)" \
-w "$(PWD)" \
swift:5.10 \
bash -c 'swift test -c $(CONFIG)'

build-linux:
docker run \
--rm \
-v "$(PWD):$(PWD)" \
-w "$(PWD)" \
swift:5.9 \
bash -c 'swift build -c $(CONFIG)'
.PHONY: build-for-library-evolution format xcodebuild test-docs test-integration

define udid_for
Expand Down
98 changes: 61 additions & 37 deletions Sources/Auth/AuthClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

private var api: APIClient { Dependencies[clientID].api }
var configuration: AuthClient.Configuration { Dependencies[clientID].configuration }
private var codeVerifierStorage: CodeVerifierStorage { Dependencies[clientID].codeVerifierStorage }
private var codeVerifierStorage: CodeVerifierStorage {
Dependencies[clientID].codeVerifierStorage
}
private var date: @Sendable () -> Date { Dependencies[clientID].date }
private var sessionManager: SessionManager { Dependencies[clientID].sessionManager }
private var eventEmitter: AuthStateChangeEventEmitter { Dependencies[clientID].eventEmitter }
Expand Down Expand Up @@ -77,10 +79,11 @@
sessionManager: .live(clientID: clientID)
)

observeAppLifecycleChanges()
Task { @MainActor in observeAppLifecycleChanges() }
}

#if canImport(ObjectiveC)
@MainActor
private func observeAppLifecycleChanges() {
#if canImport(UIKit)
#if canImport(WatchKit)
Expand Down Expand Up @@ -165,14 +168,20 @@
/// Listen for auth state changes.
///
/// An `.initialSession` is always emitted when this method is called.
public var authStateChanges: AsyncStream<(
event: AuthChangeEvent,
session: Session?
)> {
let (stream, continuation) = AsyncStream<(
event: AuthChangeEvent,
session: Session?
)>.makeStream()
public var authStateChanges:
AsyncStream<
(
event: AuthChangeEvent,
session: Session?
)
>
{
let (stream, continuation) = AsyncStream<
(
event: AuthChangeEvent,
session: Session?
)
>.makeStream()

Task {
let handle = await onAuthStateChange { event, session in
Expand Down Expand Up @@ -209,10 +218,12 @@
url: configuration.url.appendingPathComponent("signup"),
method: .post,
query: [
(redirectTo ?? configuration.redirectToURL).map { URLQueryItem(
name: "redirect_to",
value: $0.absoluteString
) },
(redirectTo ?? configuration.redirectToURL).map {
URLQueryItem(
name: "redirect_to",
value: $0.absoluteString
)
}
].compactMap { $0 },
body: configuration.encoder.encode(
SignUpRequest(
Expand Down Expand Up @@ -288,7 +299,7 @@
method: .post,
query: [URLQueryItem(name: "grant_type", value: "password")],
body: configuration.encoder.encode(
UserCredentials(

Check warning on line 302 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 15.4)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 302 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 15.4)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 302 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 16.0)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 302 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MACOS, 15.4)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 302 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MACOS, 16.0)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 302 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, TVOS, 15.4)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 302 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 16.0)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 302 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, WATCHOS, 15.4)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 302 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, TVOS, 16.0)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 302 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, WATCHOS, 16.0)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.
email: email,
password: password,
gotrueMetaSecurity: captchaToken.map(AuthMetaSecurity.init(captchaToken:))
Expand All @@ -315,7 +326,7 @@
method: .post,
query: [URLQueryItem(name: "grant_type", value: "password")],
body: configuration.encoder.encode(
UserCredentials(

Check warning on line 329 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 15.4)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 329 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 15.4)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 329 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 16.0)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 329 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MACOS, 15.4)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 329 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, TVOS, 15.4)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.

Check warning on line 329 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, WATCHOS, 15.4)

'UserCredentials' is deprecated: Access to UserCredentials will be removed on the next major release.
password: password,
phone: phone,
gotrueMetaSecurity: captchaToken.map(AuthMetaSecurity.init(captchaToken:))
Expand Down Expand Up @@ -401,10 +412,12 @@
url: configuration.url.appendingPathComponent("otp"),
method: .post,
query: [
(redirectTo ?? configuration.redirectToURL).map { URLQueryItem(
name: "redirect_to",
value: $0.absoluteString
) },
(redirectTo ?? configuration.redirectToURL).map {
URLQueryItem(
name: "redirect_to",
value: $0.absoluteString
)
}
].compactMap { $0 },
body: configuration.encoder.encode(
OTPParams(
Expand Down Expand Up @@ -524,7 +537,8 @@
let codeVerifier = codeVerifierStorage.get()

if codeVerifier == nil {
logger?.error("code verifier not found, a code verifier should exist when calling this method.")
logger?.error(
"code verifier not found, a code verifier should exist when calling this method.")
}

let session: Session = try await api.execute(
Expand Down Expand Up @@ -878,7 +892,9 @@
headers: [.authorization: "Bearer \(accessToken)"]
)
)
} catch let AuthError.api(_, _, _, response) where [404, 403, 401].contains(response.statusCode) {
} catch let AuthError.api(_, _, _, response)
where [404, 403, 401].contains(response.statusCode)
{
// ignore 404s since user might not exist anymore
// ignore 401s, and 403s since an invalid or expired JWT should sign out the current session.
}
Expand All @@ -898,10 +914,12 @@
url: configuration.url.appendingPathComponent("verify"),
method: .post,
query: [
(redirectTo ?? configuration.redirectToURL).map { URLQueryItem(
name: "redirect_to",
value: $0.absoluteString
) },
(redirectTo ?? configuration.redirectToURL).map {
URLQueryItem(
name: "redirect_to",
value: $0.absoluteString
)
}
].compactMap { $0 },
body: configuration.encoder.encode(
VerifyOTPParams.email(
Expand Down Expand Up @@ -991,10 +1009,12 @@
url: configuration.url.appendingPathComponent("resend"),
method: .post,
query: [
(emailRedirectTo ?? configuration.redirectToURL).map { URLQueryItem(
name: "redirect_to",
value: $0.absoluteString
) },
(emailRedirectTo ?? configuration.redirectToURL).map {
URLQueryItem(
name: "redirect_to",
value: $0.absoluteString
)
}
].compactMap { $0 },
body: configuration.encoder.encode(
ResendEmailParams(
Expand Down Expand Up @@ -1078,10 +1098,12 @@
url: configuration.url.appendingPathComponent("user"),
method: .put,
query: [
(redirectTo ?? configuration.redirectToURL).map { URLQueryItem(
name: "redirect_to",
value: $0.absoluteString
) },
(redirectTo ?? configuration.redirectToURL).map {
URLQueryItem(
name: "redirect_to",
value: $0.absoluteString
)
}
].compactMap { $0 },
body: configuration.encoder.encode(user)
)
Expand Down Expand Up @@ -1213,10 +1235,12 @@
url: configuration.url.appendingPathComponent("recover"),
method: .post,
query: [
(redirectTo ?? configuration.redirectToURL).map { URLQueryItem(
name: "redirect_to",
value: $0.absoluteString
) },
(redirectTo ?? configuration.redirectToURL).map {
URLQueryItem(
name: "redirect_to",
value: $0.absoluteString
)
}
].compactMap { $0 },
body: configuration.encoder.encode(
RecoverParams(
Expand Down Expand Up @@ -1300,7 +1324,7 @@
}

var queryItems: [URLQueryItem] = [
URLQueryItem(name: "provider", value: provider.rawValue),
URLQueryItem(name: "provider", value: provider.rawValue)
]

if let scopes {
Expand Down Expand Up @@ -1357,7 +1381,7 @@
final class DefaultPresentationContextProvider: NSObject,
ASWebAuthenticationPresentationContextProviding
{
func presentationAnchor(for _: ASWebAuthenticationSession) -> ASPresentationAnchor {

Check warning on line 1384 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 15.4)

main actor-isolated instance method 'presentationAnchor(for:)' cannot be used to satisfy nonisolated protocol requirement

Check warning on line 1384 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, IOS, 15.4)

main actor-isolated instance method 'presentationAnchor(for:)' cannot be used to satisfy nonisolated protocol requirement

Check warning on line 1384 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 15.4)

main actor-isolated instance method 'presentationAnchor(for:)' cannot be used to satisfy nonisolated protocol requirement

Check warning on line 1384 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MAC_CATALYST, 15.4)

main actor-isolated instance method 'presentationAnchor(for:)' cannot be used to satisfy nonisolated protocol requirement

Check warning on line 1384 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MACOS, 15.4)

main actor-isolated instance method 'presentationAnchor(for:)' cannot be used to satisfy nonisolated protocol requirement

Check warning on line 1384 in Sources/Auth/AuthClient.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (test, MACOS, 15.4)

main actor-isolated instance method 'presentationAnchor(for:)' cannot be used to satisfy nonisolated protocol requirement
ASPresentationAnchor()
}
}
Expand Down
11 changes: 3 additions & 8 deletions Sources/Storage/StorageFileApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,8 @@ enum FileUpload {
}

#if DEBUG
#if compiler(>=6)
// It is safe to mark it as unsafe, since this property is only used in tests for overriding the
// boundary value, instead of using the random one.
nonisolated(unsafe) var testingBoundary: String?
#else
var testingBoundary: String?
#endif
import ConcurrencyExtras
let testingBoundary = LockIsolated<String?>(nil)
#endif

/// Supabase Storage File API
Expand Down Expand Up @@ -94,7 +89,7 @@ public class StorageFileApi: StorageApi, @unchecked Sendable {
headers[.duplex] = options.duplex

#if DEBUG
let formData = MultipartFormData(boundary: testingBoundary)
let formData = MultipartFormData(boundary: testingBoundary.value)
#else
let formData = MultipartFormData()
#endif
Expand Down
4 changes: 2 additions & 2 deletions Tests/StorageTests/SupabaseStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ final class SupabaseStorageTests: XCTestCase {

#if !os(Linux)
func testUploadData() async throws {
testingBoundary = "alamofire.boundary.c21f947c1c7b0c57"
testingBoundary.setValue("alamofire.boundary.c21f947c1c7b0c57")

sessionMock.fetch = { request in
assertInlineSnapshot(of: request, as: .curl) {
Expand Down Expand Up @@ -155,7 +155,7 @@ final class SupabaseStorageTests: XCTestCase {
}

func testUploadFileURL() async throws {
testingBoundary = "alamofire.boundary.c21f947c1c7b0c57"
testingBoundary.setValue("alamofire.boundary.c21f947c1c7b0c57")

sessionMock.fetch = { request in
assertInlineSnapshot(of: request, as: .curl) {
Expand Down
Loading