From a859df79d8da65c30e69db592efbfb392bdb7f19 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Tue, 16 Jan 2024 17:49:24 -0300 Subject: [PATCH] Revert some breaking changes and deprecate some initializers --- Sources/Auth/Deprecated.swift | 76 ++++++++++++++++++++ Sources/Auth/Storage/AuthLocalStorage.swift | 17 ++--- Sources/PostgREST/Deprecated.swift | 80 +++++++++++++++++++++ Sources/Realtime/Deprecated.swift | 67 +++++++++++++++++ Sources/Storage/Deprecated.swift | 32 +++++++++ Sources/Supabase/Types.swift | 2 +- 6 files changed, 265 insertions(+), 9 deletions(-) create mode 100644 Sources/PostgREST/Deprecated.swift create mode 100644 Sources/Realtime/Deprecated.swift create mode 100644 Sources/Storage/Deprecated.swift diff --git a/Sources/Auth/Deprecated.swift b/Sources/Auth/Deprecated.swift index 3e1721a2..73d9800b 100644 --- a/Sources/Auth/Deprecated.swift +++ b/Sources/Auth/Deprecated.swift @@ -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 + ) + } +} diff --git a/Sources/Auth/Storage/AuthLocalStorage.swift b/Sources/Auth/Storage/AuthLocalStorage.swift index 561e7211..2b28f7e1 100644 --- a/Sources/Auth/Storage/AuthLocalStorage.swift +++ b/Sources/Auth/Storage/AuthLocalStorage.swift @@ -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 + }() } diff --git a/Sources/PostgREST/Deprecated.swift b/Sources/PostgREST/Deprecated.swift new file mode 100644 index 00000000..1dcd9884 --- /dev/null +++ b/Sources/PostgREST/Deprecated.swift @@ -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 + ) + } +} diff --git a/Sources/Realtime/Deprecated.swift b/Sources/Realtime/Deprecated.swift new file mode 100644 index 00000000..99238b03 --- /dev/null +++ b/Sources/Realtime/Deprecated.swift @@ -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 + ) + } +} diff --git a/Sources/Storage/Deprecated.swift b/Sources/Storage/Deprecated.swift new file mode 100644 index 00000000..c4ffccc6 --- /dev/null +++ b/Sources/Storage/Deprecated.swift @@ -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 + ) + } +} diff --git a/Sources/Supabase/Types.swift b/Sources/Supabase/Types.swift index 29ba6734..d659d2b0 100644 --- a/Sources/Supabase/Types.swift +++ b/Sources/Supabase/Types.swift @@ -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