Skip to content

Commit 7a66e71

Browse files
committed
move baseURL to Client type
1 parent d51bde3 commit 7a66e71

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

Sources/Functions/FunctionsClient.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,6 @@ struct FetchTransportAdapter: ClientTransport {
4646
}
4747
}
4848

49-
extension URL {
50-
/// Returns a new URL which contains only `{scheme}://{host}:{port}`.
51-
fileprivate var baseURL: URL {
52-
guard let components = URLComponents(string: self.absoluteString) else { return self }
53-
54-
var newComponents = URLComponents()
55-
newComponents.scheme = components.scheme
56-
newComponents.host = components.host
57-
newComponents.port = components.port
58-
59-
return newComponents.url ?? self
60-
}
61-
}
62-
6349
/// An actor representing a client for invoking functions.
6450
public final class FunctionsClient: Sendable {
6551
/// Fetch handler used to make requests.
@@ -134,9 +120,9 @@ public final class FunctionsClient: Sendable {
134120
region: region,
135121
logger: logger,
136122
client: Client(
137-
serverURL: url.baseURL,
123+
serverURL: url,
138124
transport: transport ?? URLSessionTransport(),
139-
middlewares: [LoggingMiddleware(logger: Logger(label: "functions"))]
125+
middlewares: [LoggingMiddleware(logger: .functions)]
140126
)
141127
)
142128
}

Sources/Functions/Logger.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Logger.swift
3+
// Supabase
4+
//
5+
// Created by Guilherme Souza on 05/08/25.
6+
//
7+
8+
import Logging
9+
10+
extension Logger {
11+
/// A Logger instance for the Functions module.
12+
static let functions = Logger(label: "Functions")
13+
}

Sources/Helpers/HTTP/Client.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import OpenAPIRuntime
33

44
#if canImport(Darwin)
55
import struct Foundation.URL
6+
import struct Foundation.URLComponents
67
#else
78
@preconcurrency import struct Foundation.URL
9+
@preconcurrency import struct Foundation.URLComponents
810
#endif
911

1012
/// A client that can send HTTP requests and receive HTTP responses.
@@ -26,7 +28,7 @@ package struct Client: Sendable {
2628
transport: any ClientTransport,
2729
middlewares: [any ClientMiddleware] = []
2830
) {
29-
self.serverURL = serverURL
31+
self.serverURL = serverURL.baseURL
3032
self.transport = transport
3133
self.middlewares = middlewares
3234
}
@@ -72,3 +74,17 @@ package struct Client: Sendable {
7274
return try await next(request, body, baseURL)
7375
}
7476
}
77+
78+
extension URL {
79+
/// Returns a new URL which contains only `{scheme}://{host}:{port}`.
80+
fileprivate var baseURL: URL {
81+
guard let components = URLComponents(string: self.absoluteString) else { return self }
82+
83+
var newComponents = URLComponents()
84+
newComponents.scheme = components.scheme
85+
newComponents.host = components.host
86+
newComponents.port = components.port
87+
88+
return newComponents.url ?? self
89+
}
90+
}

0 commit comments

Comments
 (0)