Skip to content

Commit ae75d0f

Browse files
committed
finishing prep
1 parent a7809f9 commit ae75d0f

File tree

11 files changed

+45
-13
lines changed

11 files changed

+45
-13
lines changed

Packages/SublimationNgrok/Sources/SublimationKVdb/URLSessionClient.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ public import SublimationTunnel
4444
/// a `NgrokServerError` if the save operation fails.
4545
///
4646
/// - SeeAlso: `KVdbTunnelClient`
47-
public struct URLSessionClient<Key: Sendable>: TunnelClient {
47+
internal struct URLSessionClient<Key: Sendable>: TunnelClient {
4848
private let session: URLSession
4949

5050
/// Initializes a new `URLSessionClient` with the specified session.
5151
///
5252
/// - Parameter session: The URLSession to use for network requests.
5353
/// Defaults to an ephemeral session.
54-
public init(session: URLSession = .ephemeral()) { self.session = session }
54+
internal init(session: URLSession = .ephemeral()) { self.session = session }
5555

5656
/// Retrieves the value associated with a key from a specific bucket.
5757
///
@@ -62,7 +62,7 @@ public struct URLSessionClient<Key: Sendable>: TunnelClient {
6262
/// - Returns: The URL value associated with the key.
6363
///
6464
/// - Throws: A `NgrokServerError` if the retrieval operation fails.
65-
public func getValue(ofKey key: Key, fromBucket bucketName: String) async throws -> URL {
65+
internal func getValue(ofKey key: Key, fromBucket bucketName: String) async throws -> URL {
6666
let url = KVdb.construct(URL.self, forKey: key, atBucket: bucketName)
6767

6868
let data = try await session.data(from: url).0
@@ -81,7 +81,8 @@ public struct URLSessionClient<Key: Sendable>: TunnelClient {
8181
/// - bucketName: The name of the bucket to save the value in.
8282
///
8383
/// - Throws: A `NgrokServerError` if the save operation fails.
84-
public func saveValue(_ value: URL, withKey key: Key, inBucket bucketName: String) async throws {
84+
internal func saveValue(_ value: URL, withKey key: Key, inBucket bucketName: String) async throws
85+
{
8586
let url = KVdb.construct(URL.self, forKey: key, atBucket: bucketName)
8687
var request = URLRequest(url: url)
8788
request.httpBody = value.absoluteString.data(using: .utf8)

Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIConfiguration.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,5 @@ extension NgrokCLIAPIConfiguration {
6262
/// using a `Vapor.Application`.
6363
///
6464
/// - Parameter application: The Vapor application to use for configuration.
65-
6665
public init(application: any Application) { self.init(serverApplication: application) }
6766
}

Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIServer+TunnelServer.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import SublimationTunnel
3434

3535
extension NgrokCLIAPIServer {
3636
/// Runs the server.
37-
public func begin(isConnectionRefused: @escaping (ClientError) -> Bool) async {
37+
private func begin(isConnectionRefused: @escaping (ClientError) -> Bool) async {
3838
let start = Date()
3939
let newTunnel: any Tunnel
4040
do { newTunnel = try await self.newTunnel(isConnectionRefused: isConnectionRefused) }
@@ -56,7 +56,11 @@ extension NgrokCLIAPIServer {
5656
internal private(set) var isStarted = false
5757
func started() { isStarted = true }
5858
}
59+
/// Terminate the `NgrokProcess`.
5960
public func shutdown() { self.process.terminate() }
61+
/// Starts the process for Ngrok if nessecary and creates a new tunnel.
62+
/// - Parameter isConnectionRefused: Closure to test whether the ``ClientError`` is because the server still needs to be started.
63+
/// - Throws: If there's an issue starting the server.
6064
public func run(isConnectionRefused: @escaping @Sendable (ClientError) -> Bool) async throws {
6165
try await withThrowingTaskGroup(
6266
of: Void.self,

Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension NgrokClient {
4141
{ try await self.listTunnels().first },
4242
isConnectionRefused: isConnectionRefused
4343
)
44-
switch networkResult { case let .connectionRefused(error): return .error(error)
44+
switch networkResult { case .connectionRefused(let error): return .error(error)
4545

4646
default: return .network(networkResult)
4747
}

Packages/SublimationNgrok/Sources/SublimationTunnel/NetworkResult.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public enum NetworkResult<T, ConnectionErrorType: Error> {
4747
}
4848

4949
extension NetworkResult {
50-
public init(error: any Error, isConnectionRefused: @escaping (ConnectionErrorType) -> Bool) {
50+
package init(error: any Error, isConnectionRefused: @escaping (ConnectionErrorType) -> Bool) {
5151
guard let error = error as? ConnectionErrorType else {
5252
self = .failure(error)
5353
return
@@ -61,15 +61,15 @@ extension NetworkResult {
6161
self = .failure(error)
6262
}
6363

64-
public init(
64+
package init(
6565
_ closure: @escaping () async throws -> T,
6666
isConnectionRefused: @escaping (ConnectionErrorType) -> Bool
6767
) async {
6868
do { self = try await .success(closure()) }
6969
catch { self = .init(error: error, isConnectionRefused: isConnectionRefused) }
7070
}
7171

72-
public func get() throws -> T? {
72+
package func get() throws -> T? {
7373
switch self { case .connectionRefused: return nil
7474

7575
case .failure(let error): throw error

Packages/SublimationNgrok/Sources/SublimationTunnel/Tunnel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
public import Foundation
3131

32+
/// A tunnel with a name and public url for the server.
3233
public protocol Tunnel: Sendable {
3334
var name: String { get }
3435
var publicURL: URL { get }

Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelClientRepository.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,39 @@ public import Foundation
3333
public import FoundationNetworking
3434
#endif
3535

36+
/// A repository for managing writable ``Tunnel`` objects using a ``TunnelClient``.
3637
public final class TunnelClientRepository<Key: Sendable>: WritableTunnelRepository {
3738
private let client: any TunnelClient<Key>
3839
private let bucketName: String
40+
/// Create a ``TunnelClientRepository`` using the ``TunnelClient`` and the name of the bucket for the key value pair.
41+
/// - Parameters:
42+
/// - client: The ``TunnelClient`` to communicate with.
43+
/// - bucketName: The bucket name for the key value pair.
3944
public init(client: any TunnelClient<Key>, bucketName: String) {
4045
self.client = client
4146
self.bucketName = bucketName
4247
}
4348

49+
/// Retrieves a tunnel for the specified key.
50+
///
51+
/// - Parameter key: The key used to retrieve the tunnel.
52+
///
53+
/// - Throws: An error if the tunnel cannot be retrieved.
54+
///
55+
/// - Returns: The URL of the retrieved tunnel, if available.
4456
public func tunnel(forKey key: Key) async throws -> URL? {
4557
try await client.getValue(ofKey: key, fromBucket: bucketName)
4658
}
4759

60+
/// Saves a URL with a key.
61+
///
62+
/// - Parameters:
63+
/// - url: The URL to save.
64+
/// - key: The key to associate with the URL.
65+
///
66+
/// - Throws: An error if the save operation fails.
67+
///
68+
/// - Note: This method is asynchronous.
4869
public func saveURL(_ url: URL, withKey key: Key) async throws {
4970
try await client.saveValue(url, withKey: key, inBucket: bucketName)
5071
}

Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelRepository.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,5 @@ public protocol TunnelRepository<Key>: Sendable {
5151
/// - Throws: An error if the tunnel cannot be retrieved.
5252
///
5353
/// - Returns: The URL of the retrieved tunnel, if available.
54-
5554
func tunnel(forKey key: Key) async throws -> URL?
5655
}

Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServer.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public protocol TunnelServer: Sendable {
4444
@available(*, deprecated) func start(
4545
isConnectionRefused: @escaping @Sendable (ConnectionErrorType) -> Bool
4646
)
47+
/// Runs TunnelServeer.
48+
/// - Parameter isConnectionRefused: Closure to test whether the ``ConnectionErrorType`` is because the server still needs to be started.
49+
/// - Throws: If there's an issue starting the server.
4750
func run(isConnectionRefused: @escaping @Sendable (ConnectionErrorType) -> Bool) async throws
51+
/// Shutdown the ``TunnelServer``.
4852
func shutdown()
4953
}

Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelSublimatory.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@ public import SublimationCore
3535
public typealias RepositoryClientFactory<Key> = (@Sendable @escaping () -> any Application) ->
3636
any TunnelClient<Key>
3737

38+
/// A `Sublimatory` which uses creates and saves a``Tunnel``.
3839
public actor TunnelSublimatory<
3940
WritableTunnelRepositoryFactoryType: WritableTunnelRepositoryFactory,
4041
TunnelServerFactoryType: TunnelServerFactory
4142
>: Sublimatory, TunnelServerDelegate {
4243

44+
/// `Key type
4345
public typealias Key = WritableTunnelRepositoryFactoryType.TunnelRepositoryType.Key
46+
/// Type of Error which can be thrown by the Network Client.
4447
public typealias ConnectionErrorType = TunnelServerFactoryType.Configuration.Server
4548
.ConnectionErrorType
4649
private let factory: TunnelServerFactoryType
@@ -164,7 +167,7 @@ public actor TunnelSublimatory<
164167
public nonisolated func server(_: any TunnelServer, errorDidOccur error: any Error) {
165168
Task { await self.onError(error) }
166169
}
167-
func shutdownServer() { server.shutdown() }
170+
private func shutdownServer() { server.shutdown() }
168171
public nonisolated func shutdown() { Task { await self.shutdownServer() } }
169172
public func run() async throws {
170173

Packages/SublimationNgrok/Sources/SublimationTunnel/WritableTunnelRepository.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
public import Foundation
3131

32-
/// A repository for managing writable tunnels.
32+
/// A repository for managing writable ``Tunnel`` objects.
3333
///
3434
/// This protocol extends the `TunnelRepository` protocol
3535
/// and adds the ability to save a URL with a key.

0 commit comments

Comments
 (0)