Skip to content

Commit a859df7

Browse files
author
Guilherme Souza
committed
Revert some breaking changes and deprecate some initializers
1 parent 3106185 commit a859df7

File tree

6 files changed

+265
-9
lines changed

6 files changed

+265
-9
lines changed

Sources/Auth/Deprecated.swift

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,79 @@ extension JSONDecoder {
4545
AuthClient.Configuration.jsonDecoder
4646
}
4747
}
48+
49+
extension AuthClient.Configuration {
50+
/// Initializes a AuthClient Configuration with optional parameters.
51+
///
52+
/// - Parameters:
53+
/// - url: The base URL of the Auth server.
54+
/// - headers: Custom headers to be included in requests.
55+
/// - flowType: The authentication flow type.
56+
/// - localStorage: The storage mechanism for local data.
57+
/// - encoder: The JSON encoder to use for encoding requests.
58+
/// - decoder: The JSON decoder to use for decoding responses.
59+
/// - fetch: The asynchronous fetch handler for network requests.
60+
@available(
61+
*,
62+
deprecated,
63+
message: "Replace usages of this initializer with new init(url:headers:flowType:localStorage:logger:encoder:decoder:fetch)"
64+
)
65+
public init(
66+
url: URL,
67+
headers: [String: String] = [:],
68+
flowType: AuthFlowType = Self.defaultFlowType,
69+
localStorage: AuthLocalStorage,
70+
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
71+
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
72+
fetch: @escaping AuthClient.FetchHandler = { try await URLSession.shared.data(for: $0) }
73+
) {
74+
self.init(
75+
url: url,
76+
headers: headers,
77+
flowType: flowType,
78+
localStorage: localStorage,
79+
logger: nil,
80+
encoder: encoder,
81+
decoder: decoder,
82+
fetch: fetch
83+
)
84+
}
85+
}
86+
87+
extension AuthClient {
88+
/// Initializes a AuthClient Configuration with optional parameters.
89+
///
90+
/// - Parameters:
91+
/// - url: The base URL of the Auth server.
92+
/// - headers: Custom headers to be included in requests.
93+
/// - flowType: The authentication flow type.
94+
/// - localStorage: The storage mechanism for local data.
95+
/// - encoder: The JSON encoder to use for encoding requests.
96+
/// - decoder: The JSON decoder to use for decoding responses.
97+
/// - fetch: The asynchronous fetch handler for network requests.
98+
@available(
99+
*,
100+
deprecated,
101+
message: "Replace usages of this initializer with new init(url:headers:flowType:localStorage:logger:encoder:decoder:fetch)"
102+
)
103+
public init(
104+
url: URL,
105+
headers: [String: String] = [:],
106+
flowType: AuthFlowType = Configuration.defaultFlowType,
107+
localStorage: AuthLocalStorage,
108+
encoder: JSONEncoder = AuthClient.Configuration.jsonEncoder,
109+
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder,
110+
fetch: @escaping AuthClient.FetchHandler = { try await URLSession.shared.data(for: $0) }
111+
) {
112+
self.init(
113+
url: url,
114+
headers: headers,
115+
flowType: flowType,
116+
localStorage: localStorage,
117+
logger: nil,
118+
encoder: encoder,
119+
decoder: decoder,
120+
fetch: fetch
121+
)
122+
}
123+
}

Sources/Auth/Storage/AuthLocalStorage.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ public protocol AuthLocalStorage: Sendable {
77
}
88

99
extension AuthClient.Configuration {
10-
#if os(iOS) || os(macOS) || os(watchOS) || os(tvOS)
11-
public static let defaultAuthLocalStorage = KeychainLocalStorage(
12-
service: "supabase.gotrue.swift",
13-
accessGroup: nil
14-
)
15-
#elseif os(Windows)
16-
public static let defaultAuthLocalStorage =
10+
public static let defaultLocalStorage: AuthLocalStorage = {
11+
#if os(iOS) || os(macOS) || os(watchOS) || os(tvOS)
12+
KeychainLocalStorage(
13+
service: "supabase.gotrue.swift",
14+
accessGroup: nil
15+
)
16+
#elseif os(Windows)
1717
WinCredLocalStorage(service: "supabase.gotrue.swift")
18-
#endif
18+
#endif
19+
}()
1920
}

Sources/PostgREST/Deprecated.swift

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//
2+
// Deprecated.swift
3+
//
4+
//
5+
// Created by Guilherme Souza on 16/01/24.
6+
//
7+
8+
import Foundation
9+
10+
#if canImport(FoundationNetworking)
11+
import FoundationNetworking
12+
#endif
13+
14+
extension PostgrestClient.Configuration {
15+
/// Initializes a new configuration for the PostgREST client.
16+
/// - Parameters:
17+
/// - url: The URL of the PostgREST server.
18+
/// - schema: The schema to use.
19+
/// - headers: The headers to include in requests.
20+
/// - fetch: The fetch handler to use for requests.
21+
/// - encoder: The JSONEncoder to use for encoding.
22+
/// - decoder: The JSONDecoder to use for decoding.
23+
@available(
24+
*,
25+
deprecated,
26+
message: "Replace usages of this initializer with new init(url:schema:headers:logger:fetch:encoder:decoder:)"
27+
)
28+
public init(
29+
url: URL,
30+
schema: String? = nil,
31+
headers: [String: String] = [:],
32+
fetch: @escaping PostgrestClient.FetchHandler = { try await URLSession.shared.data(for: $0) },
33+
encoder: JSONEncoder = PostgrestClient.Configuration.jsonEncoder,
34+
decoder: JSONDecoder = PostgrestClient.Configuration.jsonDecoder
35+
) {
36+
self.init(
37+
url: url,
38+
schema: schema,
39+
headers: headers,
40+
logger: nil,
41+
fetch: fetch,
42+
encoder: encoder,
43+
decoder: decoder
44+
)
45+
}
46+
}
47+
48+
extension PostgrestClient {
49+
/// Creates a PostgREST client with the specified parameters.
50+
/// - Parameters:
51+
/// - url: The URL of the PostgREST server.
52+
/// - schema: The schema to use.
53+
/// - headers: The headers to include in requests.
54+
/// - session: The URLSession to use for requests.
55+
/// - encoder: The JSONEncoder to use for encoding.
56+
/// - decoder: The JSONDecoder to use for decoding.
57+
@available(
58+
*,
59+
deprecated,
60+
message: "Replace usages of this initializer with new init(url:schema:headers:logger:fetch:encoder:decoder:)"
61+
)
62+
public init(
63+
url: URL,
64+
schema: String? = nil,
65+
headers: [String: String] = [:],
66+
fetch: @escaping FetchHandler = { try await URLSession.shared.data(for: $0) },
67+
encoder: JSONEncoder = PostgrestClient.Configuration.jsonEncoder,
68+
decoder: JSONDecoder = PostgrestClient.Configuration.jsonDecoder
69+
) {
70+
self.init(
71+
url: url,
72+
schema: schema,
73+
headers: headers,
74+
logger: nil,
75+
fetch: fetch,
76+
encoder: encoder,
77+
decoder: decoder
78+
)
79+
}
80+
}

Sources/Realtime/Deprecated.swift

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// Deprecated.swift
3+
//
4+
//
5+
// Created by Guilherme Souza on 16/01/24.
6+
//
7+
8+
import Foundation
9+
10+
extension RealtimeClient {
11+
@available(
12+
*,
13+
deprecated,
14+
message: "Replace usages of this initializer with new init(_:headers:params:vsn:logger)"
15+
)
16+
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
17+
public convenience init(
18+
_ endPoint: String,
19+
headers: [String: String] = [:],
20+
params: Payload? = nil,
21+
vsn: String = Defaults.vsn
22+
) {
23+
self.init(endPoint, headers: headers, params: params, vsn: vsn, logger: nil)
24+
}
25+
26+
@available(
27+
*,
28+
deprecated,
29+
message: "Replace usages of this initializer with new init(_:headers:paramsClosure:vsn:logger)"
30+
)
31+
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
32+
public convenience init(
33+
_ endPoint: String,
34+
headers: [String: String] = [:],
35+
paramsClosure: PayloadClosure?,
36+
vsn: String = Defaults.vsn
37+
) {
38+
self.init(
39+
endPoint,
40+
headers: headers, paramsClosure: paramsClosure,
41+
vsn: vsn,
42+
logger: nil
43+
)
44+
}
45+
46+
@available(
47+
*,
48+
deprecated,
49+
message: "Replace usages of this initializer with new init(endPoint:headers:transport:paramsClosure:vsn:logger)"
50+
)
51+
public convenience init(
52+
endPoint: String,
53+
headers: [String: String] = [:],
54+
transport: @escaping ((URL) -> PhoenixTransport),
55+
paramsClosure: PayloadClosure? = nil,
56+
vsn: String = Defaults.vsn
57+
) {
58+
self.init(
59+
endPoint: endPoint,
60+
headers: headers,
61+
transport: transport,
62+
paramsClosure: paramsClosure,
63+
vsn: vsn,
64+
logger: nil
65+
)
66+
}
67+
}

Sources/Storage/Deprecated.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Deprecated.swift
3+
//
4+
//
5+
// Created by Guilherme Souza on 16/01/24.
6+
//
7+
8+
import Foundation
9+
10+
extension StorageClientConfiguration {
11+
@available(
12+
*,
13+
deprecated,
14+
message: "Replace usages of this initializer with new init(url:headers:encoder:decoder:session:logger)"
15+
)
16+
public init(
17+
url: URL,
18+
headers: [String: String],
19+
encoder: JSONEncoder = .defaultStorageEncoder,
20+
decoder: JSONDecoder = .defaultStorageDecoder,
21+
session: StorageHTTPSession = .init()
22+
) {
23+
self.init(
24+
url: url,
25+
headers: headers,
26+
encoder: encoder,
27+
decoder: decoder,
28+
session: session,
29+
logger: nil
30+
)
31+
}
32+
}

Sources/Supabase/Types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ extension SupabaseClientOptions.AuthOptions {
114114
decoder: JSONDecoder = AuthClient.Configuration.jsonDecoder
115115
) {
116116
self.init(
117-
storage: AuthClient.Configuration.defaultAuthLocalStorage,
117+
storage: AuthClient.Configuration.defaultLocalStorage,
118118
flowType: flowType,
119119
encoder: encoder,
120120
decoder: decoder

0 commit comments

Comments
 (0)