Skip to content

Commit f9d2573

Browse files
committed
Share version value with sub packages
1 parent c8581fc commit f9d2573

File tree

42 files changed

+70
-41
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+70
-41
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ let package = Package(
3131
],
3232
targets: [
3333
.target(name: "_Helpers"),
34-
.target(name: "Functions"),
34+
.target(name: "Functions", dependencies: ["_Helpers"]),
3535
.testTarget(name: "FunctionsTests", dependencies: ["Functions"]),
3636
.target(
3737
name: "GoTrue",
@@ -49,7 +49,7 @@ let package = Package(
4949
],
5050
resources: [.process("Resources")]
5151
),
52-
.target(name: "PostgREST"),
52+
.target(name: "PostgREST", dependencies: ["_Helpers"]),
5353
.testTarget(
5454
name: "PostgRESTTests",
5555
dependencies: [

Sources/Functions/FunctionsClient.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import Foundation
2+
@_spi(Internal) import _Helpers
3+
4+
let version = _Helpers.version
25

36
/// An actor representing a client for invoking functions.
47
public actor FunctionsClient {
@@ -27,7 +30,9 @@ public actor FunctionsClient {
2730
) {
2831
self.url = url
2932
self.headers = headers
30-
self.headers["X-Client-Info"] = "functions-swift/\(version)"
33+
if headers["X-Client-Info"] == nil {
34+
self.headers["X-Client-Info"] = "functions-swift/\(version)"
35+
}
3136
self.fetch = fetch
3237
}
3338

Sources/Functions/Version.swift

Lines changed: 0 additions & 1 deletion
This file was deleted.

Sources/GoTrue/Version.swift

Lines changed: 0 additions & 1 deletion
This file was deleted.

Sources/PostgREST/PostgrestClient.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import Foundation
2+
@_spi(Internal) import _Helpers
3+
4+
let version = _Helpers.version
25

36
/// PostgREST client.
47
public actor PostgrestClient {
@@ -46,7 +49,9 @@ public actor PostgrestClient {
4649
/// - Parameter configuration: The configuration for the client.
4750
public init(configuration: Configuration) {
4851
var configuration = configuration
49-
configuration.headers["X-Client-Info"] = "postgrest-swift/\(version)"
52+
if configuration.headers["X-Client-Info"] == nil {
53+
configuration.headers["X-Client-Info"] = "postgrest-swift/\(version)"
54+
}
5055
self.configuration = configuration
5156
}
5257

Sources/PostgREST/Version.swift

Lines changed: 0 additions & 1 deletion
This file was deleted.

Sources/Realtime/PhoenixTransport.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public protocol PhoenixTransport {
4242
- Parameters:
4343
- headers: Headers to include in the URLRequests when opening the Websocket connection. Can be empty [:]
4444
*/
45-
func connect(with headers: [String: Any])
45+
func connect(with headers: [String: String])
4646

4747
/**
4848
Disconnect from the server.
@@ -188,7 +188,7 @@ open class URLSessionTransport: NSObject, PhoenixTransport, URLSessionWebSocketD
188188
public var readyState: PhoenixTransportReadyState = .closed
189189
public var delegate: PhoenixTransportDelegate? = nil
190190

191-
public func connect(with headers: [String: Any]) {
191+
public func connect(with headers: [String: String]) {
192192
// Set the transport state as connecting
193193
readyState = .connecting
194194

Sources/Realtime/RealtimeClient.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public class RealtimeClient: PhoenixTransportDelegate {
9696
public var timeout: TimeInterval = Defaults.timeoutInterval
9797

9898
/// Custom headers to be added to the socket connection request
99-
public var headers: [String: Any] = [:]
99+
public var headers: [String: String] = [:]
100100

101101
/// Interval between sending a heartbeat
102102
public var heartbeatInterval: TimeInterval = Defaults.heartbeatInterval
@@ -176,11 +176,13 @@ public class RealtimeClient: PhoenixTransportDelegate {
176176
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
177177
public convenience init(
178178
_ endPoint: String,
179+
headers: [String: String] = [:],
179180
params: Payload? = nil,
180181
vsn: String = Defaults.vsn
181182
) {
182183
self.init(
183184
endPoint: endPoint,
185+
headers: headers,
184186
transport: { url in URLSessionTransport(url: url) },
185187
paramsClosure: { params },
186188
vsn: vsn
@@ -190,11 +192,13 @@ public class RealtimeClient: PhoenixTransportDelegate {
190192
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
191193
public convenience init(
192194
_ endPoint: String,
195+
headers: [String: String] = [:],
193196
paramsClosure: PayloadClosure?,
194197
vsn: String = Defaults.vsn
195198
) {
196199
self.init(
197200
endPoint: endPoint,
201+
headers: headers,
198202
transport: { url in URLSessionTransport(url: url) },
199203
paramsClosure: paramsClosure,
200204
vsn: vsn
@@ -203,6 +207,7 @@ public class RealtimeClient: PhoenixTransportDelegate {
203207

204208
public init(
205209
endPoint: String,
210+
headers: [String: String] = [:],
206211
transport: @escaping ((URL) -> PhoenixTransport),
207212
paramsClosure: PayloadClosure? = nil,
208213
vsn: String = Defaults.vsn
@@ -211,6 +216,13 @@ public class RealtimeClient: PhoenixTransportDelegate {
211216
self.paramsClosure = paramsClosure
212217
self.endPoint = endPoint
213218
self.vsn = vsn
219+
220+
var headers = headers
221+
if headers["X-Client-Info"] == nil {
222+
headers["X-Client-Info"] = "realtime-swift/\(version)"
223+
}
224+
self.headers = headers
225+
214226
let params = paramsClosure?()
215227
if let jwt = (params?["Authorization"] as? String)?.split(separator: " ").last {
216228
accessToken = String(jwt)

Sources/Storage/StorageApi.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public class StorageApi {
99
public let configuration: StorageClientConfiguration
1010

1111
public init(configuration: StorageClientConfiguration) {
12+
var configuration = configuration
13+
if configuration.headers["X-Client-Info"] == nil {
14+
configuration.headers["X-Client-Info"] = "storage-swift/\(version)"
15+
}
1216
self.configuration = configuration
1317
}
1418

Sources/Supabase/SupabaseClient.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import Foundation
2+
@_spi(Internal) import _Helpers
23
@_exported import Functions
34
@_exported import GoTrue
45
@_exported import PostgREST
56
@_exported import Realtime
67
@_exported import Storage
78

9+
let version = _Helpers.version
10+
811
/// Supabase Client.
912
public class SupabaseClient {
1013
let options: SupabaseClientOptions
@@ -39,6 +42,7 @@ public class SupabaseClient {
3942
/// Realtime client for Supabase
4043
public private(set) lazy var realtime = RealtimeClient(
4144
realtimeURL.absoluteString,
45+
headers: defaultHeaders,
4246
params: defaultHeaders
4347
)
4448

0 commit comments

Comments
 (0)