Skip to content

Commit

Permalink
Revert some breaking changes and deprecate some initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Jan 16, 2024
1 parent 3106185 commit a859df7
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 9 deletions.
76 changes: 76 additions & 0 deletions Sources/Auth/Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,79 @@ extension JSONDecoder {
AuthClient.Configuration.jsonDecoder
}
}

extension AuthClient.Configuration {
/// Initializes a AuthClient Configuration with optional parameters.
///
/// - Parameters:
/// - url: The base URL of the Auth server.
/// - headers: Custom headers to be included in requests.
/// - flowType: The authentication flow type.
/// - localStorage: The storage mechanism for local data.
/// - encoder: The JSON encoder to use for encoding requests.
/// - decoder: The JSON decoder to use for decoding responses.
/// - fetch: The asynchronous fetch handler for network requests.
@available(
*,
deprecated,
message: "Replace usages of this initializer with new init(url:headers:flowType:localStorage:logger:encoder:decoder:fetch)"
)
public init(
url: URL,
headers: [String: String] = [:],
flowType: AuthFlowType = Self.defaultFlowType,
localStorage: AuthLocalStorage,
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
fetch: @escaping AuthClient.FetchHandler = { try await URLSession.shared.data(for: $0) }
) {
self.init(
url: url,
headers: headers,
flowType: flowType,
localStorage: localStorage,
logger: nil,
encoder: encoder,
decoder: decoder,
fetch: fetch
)
}
}

extension AuthClient {
/// Initializes a AuthClient Configuration with optional parameters.
///
/// - Parameters:
/// - url: The base URL of the Auth server.
/// - headers: Custom headers to be included in requests.
/// - flowType: The authentication flow type.
/// - localStorage: The storage mechanism for local data.
/// - encoder: The JSON encoder to use for encoding requests.
/// - decoder: The JSON decoder to use for decoding responses.
/// - fetch: The asynchronous fetch handler for network requests.
@available(
*,
deprecated,
message: "Replace usages of this initializer with new init(url:headers:flowType:localStorage:logger:encoder:decoder:fetch)"
)
public init(
url: URL,
headers: [String: String] = [:],
flowType: AuthFlowType = Configuration.defaultFlowType,
localStorage: AuthLocalStorage,
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
fetch: @escaping AuthClient.FetchHandler = { try await URLSession.shared.data(for: $0) }
) {
self.init(
url: url,
headers: headers,
flowType: flowType,
localStorage: localStorage,
logger: nil,
encoder: encoder,
decoder: decoder,
fetch: fetch
)
}
}
17 changes: 9 additions & 8 deletions Sources/Auth/Storage/AuthLocalStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ public protocol AuthLocalStorage: Sendable {
}

extension AuthClient.Configuration {
#if os(iOS) || os(macOS) || os(watchOS) || os(tvOS)
public static let defaultAuthLocalStorage = KeychainLocalStorage(
service: "supabase.gotrue.swift",
accessGroup: nil
)
#elseif os(Windows)
public static let defaultAuthLocalStorage =
public static let defaultLocalStorage: AuthLocalStorage = {
#if os(iOS) || os(macOS) || os(watchOS) || os(tvOS)
KeychainLocalStorage(
service: "supabase.gotrue.swift",
accessGroup: nil
)
#elseif os(Windows)
WinCredLocalStorage(service: "supabase.gotrue.swift")
#endif
#endif
}()
}
80 changes: 80 additions & 0 deletions Sources/PostgREST/Deprecated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// Deprecated.swift
//
//
// Created by Guilherme Souza on 16/01/24.
//

import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

extension PostgrestClient.Configuration {
/// Initializes a new configuration for the PostgREST client.
/// - Parameters:
/// - url: The URL of the PostgREST server.
/// - schema: The schema to use.
/// - headers: The headers to include in requests.
/// - fetch: The fetch handler to use for requests.
/// - encoder: The JSONEncoder to use for encoding.
/// - decoder: The JSONDecoder to use for decoding.
@available(
*,
deprecated,
message: "Replace usages of this initializer with new init(url:schema:headers:logger:fetch:encoder:decoder:)"
)
public init(
url: URL,
schema: String? = nil,
headers: [String: String] = [:],
fetch: @escaping PostgrestClient.FetchHandler = { try await URLSession.shared.data(for: $0) },
encoder: JSONEncoder = PostgrestClient.Configuration.jsonEncoder,
decoder: JSONDecoder = PostgrestClient.Configuration.jsonDecoder
) {
self.init(
url: url,
schema: schema,
headers: headers,
logger: nil,
fetch: fetch,
encoder: encoder,
decoder: decoder
)
}
}

extension PostgrestClient {
/// Creates a PostgREST client with the specified parameters.
/// - Parameters:
/// - url: The URL of the PostgREST server.
/// - schema: The schema to use.
/// - headers: The headers to include in requests.
/// - session: The URLSession to use for requests.
/// - encoder: The JSONEncoder to use for encoding.
/// - decoder: The JSONDecoder to use for decoding.
@available(
*,
deprecated,
message: "Replace usages of this initializer with new init(url:schema:headers:logger:fetch:encoder:decoder:)"
)
public init(
url: URL,
schema: String? = nil,
headers: [String: String] = [:],
fetch: @escaping FetchHandler = { try await URLSession.shared.data(for: $0) },
encoder: JSONEncoder = PostgrestClient.Configuration.jsonEncoder,
decoder: JSONDecoder = PostgrestClient.Configuration.jsonDecoder
) {
self.init(
url: url,
schema: schema,
headers: headers,
logger: nil,
fetch: fetch,
encoder: encoder,
decoder: decoder
)
}
}
67 changes: 67 additions & 0 deletions Sources/Realtime/Deprecated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// Deprecated.swift
//
//
// Created by Guilherme Souza on 16/01/24.
//

import Foundation

extension RealtimeClient {
@available(
*,
deprecated,
message: "Replace usages of this initializer with new init(_:headers:params:vsn:logger)"
)
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
public convenience init(
_ endPoint: String,
headers: [String: String] = [:],
params: Payload? = nil,
vsn: String = Defaults.vsn
) {
self.init(endPoint, headers: headers, params: params, vsn: vsn, logger: nil)
}

@available(
*,
deprecated,
message: "Replace usages of this initializer with new init(_:headers:paramsClosure:vsn:logger)"
)
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
public convenience init(
_ endPoint: String,
headers: [String: String] = [:],
paramsClosure: PayloadClosure?,
vsn: String = Defaults.vsn
) {
self.init(
endPoint,
headers: headers, paramsClosure: paramsClosure,
vsn: vsn,
logger: nil
)
}

@available(
*,
deprecated,
message: "Replace usages of this initializer with new init(endPoint:headers:transport:paramsClosure:vsn:logger)"
)
public convenience init(
endPoint: String,
headers: [String: String] = [:],
transport: @escaping ((URL) -> PhoenixTransport),
paramsClosure: PayloadClosure? = nil,
vsn: String = Defaults.vsn
) {
self.init(
endPoint: endPoint,
headers: headers,
transport: transport,
paramsClosure: paramsClosure,
vsn: vsn,
logger: nil
)
}
}
32 changes: 32 additions & 0 deletions Sources/Storage/Deprecated.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Deprecated.swift
//
//
// Created by Guilherme Souza on 16/01/24.
//

import Foundation

extension StorageClientConfiguration {
@available(
*,
deprecated,
message: "Replace usages of this initializer with new init(url:headers:encoder:decoder:session:logger)"
)
public init(
url: URL,
headers: [String: String],
encoder: JSONEncoder = .defaultStorageEncoder,
decoder: JSONDecoder = .defaultStorageDecoder,
session: StorageHTTPSession = .init()
) {
self.init(
url: url,
headers: headers,
encoder: encoder,
decoder: decoder,
session: session,
logger: nil
)
}
}
2 changes: 1 addition & 1 deletion Sources/Supabase/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ extension SupabaseClientOptions.AuthOptions {
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder
) {
self.init(
storage: AuthClient.Configuration.defaultAuthLocalStorage,
storage: AuthClient.Configuration.defaultLocalStorage,
flowType: flowType,
encoder: encoder,
decoder: decoder
Expand Down

0 comments on commit a859df7

Please sign in to comment.