diff --git a/Packages/Ngrokit/Scripts/lint.sh b/Packages/Ngrokit/Scripts/lint.sh index e7aa376..f847023 100755 --- a/Packages/Ngrokit/Scripts/lint.sh +++ b/Packages/Ngrokit/Scripts/lint.sh @@ -13,10 +13,10 @@ MINT_RUN="/opt/homebrew/bin/mint run $MINT_ARGS" if [ -z "$SRCROOT" ]; then SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) PACKAGE_DIR="${SCRIPT_DIR}/.." - PERIPHERY_OPTIONS="--skip-build" -else - PACKAGE_DIR="${SRCROOT}" PERIPHERY_OPTIONS="" +else + PACKAGE_DIR="${SRCROOT}" + PERIPHERY_OPTIONS="--skip-build" fi @@ -32,6 +32,10 @@ fi echo "LINT Mode is $LINT_MODE" +if [ "$LINT_MODE" == "INSTALL" ]; then + exit +fi + if [ -z "$CI" ]; then $MINT_RUN swift-format format --recursive --parallel --in-place $PACKAGE_DIR/Sources else diff --git a/Packages/Ngrokit/Sources/NgrokOpenAPIClient/Client.swift b/Packages/Ngrokit/Sources/NgrokOpenAPIClient/Client.swift index a7b26a5..f9f5109 100644 --- a/Packages/Ngrokit/Sources/NgrokOpenAPIClient/Client.swift +++ b/Packages/Ngrokit/Sources/NgrokOpenAPIClient/Client.swift @@ -1,305 +1,263 @@ +// +// Client.swift +// Ngrokit +// +// Created by Leo Dion. +// Copyright © 2024 BrightDigit. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the “Software”), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// + +import HTTPTypes // Generated by swift-openapi-generator, do not modify. @_spi(Generated) import OpenAPIRuntime + #if os(Linux) -@preconcurrency import struct Foundation.URL -@preconcurrency import struct Foundation.Data -@preconcurrency import struct Foundation.Date + @preconcurrency import struct Foundation.URL + @preconcurrency import struct Foundation.Data + @preconcurrency import struct Foundation.Date #else -import struct Foundation.URL -import struct Foundation.Data -import struct Foundation.Date + import struct Foundation.URL + import struct Foundation.Data + import struct Foundation.Date #endif -import HTTPTypes package struct Client: APIProtocol { - /// The underlying HTTP client. - private let client: UniversalClient - /// Creates a new client. - /// - Parameters: - /// - serverURL: The server URL that the client connects to. Any server - /// URLs defined in the OpenAPI document are available as static methods - /// on the ``Servers`` type. - /// - configuration: A set of configuration values for the client. - /// - transport: A transport that performs HTTP operations. - /// - middlewares: A list of middlewares to call before the transport. - package init( - serverURL: Foundation.URL, - configuration: Configuration = .init(), - transport: any ClientTransport, - middlewares: [any ClientMiddleware] = [] - ) { - self.client = .init( - serverURL: serverURL, - configuration: configuration, - transport: transport, - middlewares: middlewares - ) - } - private var converter: Converter { - client.converter - } - /// Access the root API resource of a running ngrok agent - /// - /// - Remark: HTTP `GET /api`. - /// - Remark: Generated from `#/paths//api/get`. - package func get_sol_api(_ input: Operations.get_sol_api.Input) async throws -> Operations.get_sol_api.Output { - try await client.send( - input: input, - forOperation: Operations.get_sol_api.id, - serializer: { _ in - let path = try converter.renderedPath( - template: "/api", - parameters: [] - ) - var request: HTTPTypes.HTTPRequest = .init( - soar_path: path, - method: .get - ) - suppressMutabilityWarning(&request) - return (request, nil) - }, - deserializer: { response, responseBody in - switch response.status.code { - case 200: - return .ok(.init()) - default: - return .undocumented( - statusCode: response.status.code, - .init( - headerFields: response.headerFields, - body: responseBody - ) - ) - } - } - ) - } - /// List Tunnels - /// - /// - Remark: HTTP `GET /api/tunnels`. - /// - Remark: Generated from `#/paths//api/tunnels/get(listTunnels)`. - package func listTunnels(_ input: Operations.listTunnels.Input) async throws -> Operations.listTunnels.Output { - try await client.send( - input: input, - forOperation: Operations.listTunnels.id, - serializer: { input in - let path = try converter.renderedPath( - template: "/api/tunnels", - parameters: [] - ) - var request: HTTPTypes.HTTPRequest = .init( - soar_path: path, - method: .get - ) - suppressMutabilityWarning(&request) - converter.setAcceptHeader( - in: &request.headerFields, - contentTypes: input.headers.accept - ) - return (request, nil) - }, - deserializer: { response, responseBody in - switch response.status.code { - case 200: - let contentType = converter.extractContentTypeIfPresent(in: response.headerFields) - let body: Operations.listTunnels.Output.Ok.Body - let chosenContentType = try converter.bestContentType( - received: contentType, - options: [ - "application/json" - ] - ) - switch chosenContentType { - case "application/json": - body = try await converter.getResponseBodyAsJSON( - Components.Schemas.TunnelList.self, - from: responseBody, - transforming: { value in - .json(value) - } - ) - default: - preconditionFailure("bestContentType chose an invalid content type.") - } - return .ok(.init(body: body)) - default: - return .undocumented( - statusCode: response.status.code, - .init( - headerFields: response.headerFields, - body: responseBody - ) - ) - } - } - ) - } - /// Start tunnel - /// - /// - Remark: HTTP `POST /api/tunnels`. - /// - Remark: Generated from `#/paths//api/tunnels/post(startTunnel)`. - package func startTunnel(_ input: Operations.startTunnel.Input) async throws -> Operations.startTunnel.Output { - try await client.send( - input: input, - forOperation: Operations.startTunnel.id, - serializer: { input in - let path = try converter.renderedPath( - template: "/api/tunnels", - parameters: [] - ) - var request: HTTPTypes.HTTPRequest = .init( - soar_path: path, - method: .post - ) - suppressMutabilityWarning(&request) - converter.setAcceptHeader( - in: &request.headerFields, - contentTypes: input.headers.accept - ) - let body: OpenAPIRuntime.HTTPBody? - switch input.body { - case let .json(value): - body = try converter.setRequiredRequestBodyAsJSON( - value, - headerFields: &request.headerFields, - contentType: "application/json; charset=utf-8" - ) - } - return (request, body) - }, - deserializer: { response, responseBody in - switch response.status.code { - case 201: - let contentType = converter.extractContentTypeIfPresent(in: response.headerFields) - let body: Operations.startTunnel.Output.Created.Body - let chosenContentType = try converter.bestContentType( - received: contentType, - options: [ - "application/json" - ] - ) - switch chosenContentType { - case "application/json": - body = try await converter.getResponseBodyAsJSON( - Components.Schemas.TunnelResponse.self, - from: responseBody, - transforming: { value in - .json(value) - } - ) - default: - preconditionFailure("bestContentType chose an invalid content type.") - } - return .created(.init(body: body)) - default: - return .undocumented( - statusCode: response.status.code, - .init( - headerFields: response.headerFields, - body: responseBody - ) - ) - } - } - ) - } - /// Tunnel detail - /// - /// - Remark: HTTP `GET /api/tunnels/{name}`. - /// - Remark: Generated from `#/paths//api/tunnels/{name}/get(getTunnel)`. - package func getTunnel(_ input: Operations.getTunnel.Input) async throws -> Operations.getTunnel.Output { - try await client.send( - input: input, - forOperation: Operations.getTunnel.id, - serializer: { input in - let path = try converter.renderedPath( - template: "/api/tunnels/{}", - parameters: [ - input.path.name - ] - ) - var request: HTTPTypes.HTTPRequest = .init( - soar_path: path, - method: .get - ) - suppressMutabilityWarning(&request) - converter.setAcceptHeader( - in: &request.headerFields, - contentTypes: input.headers.accept - ) - return (request, nil) - }, - deserializer: { response, responseBody in - switch response.status.code { - case 200: - let contentType = converter.extractContentTypeIfPresent(in: response.headerFields) - let body: Operations.getTunnel.Output.Ok.Body - let chosenContentType = try converter.bestContentType( - received: contentType, - options: [ - "application/json" - ] - ) - switch chosenContentType { - case "application/json": - body = try await converter.getResponseBodyAsJSON( - OpenAPIRuntime.OpenAPIValueContainer.self, - from: responseBody, - transforming: { value in - .json(value) - } - ) - default: - preconditionFailure("bestContentType chose an invalid content type.") - } - return .ok(.init(body: body)) - default: - return .undocumented( - statusCode: response.status.code, - .init( - headerFields: response.headerFields, - body: responseBody - ) - ) - } - } + /// The underlying HTTP client. + private let client: UniversalClient + /// Creates a new client. + /// - Parameters: + /// - serverURL: The server URL that the client connects to. Any server + /// URLs defined in the OpenAPI document are available as static methods + /// on the ``Servers`` type. + /// - configuration: A set of configuration values for the client. + /// - transport: A transport that performs HTTP operations. + /// - middlewares: A list of middlewares to call before the transport. + package init( + serverURL: Foundation.URL, + configuration: Configuration = .init(), + transport: any ClientTransport, + middlewares: [any ClientMiddleware] = [] + ) { + self.client = .init( + serverURL: serverURL, + configuration: configuration, + transport: transport, + middlewares: middlewares + ) + } + private var converter: Converter { client.converter } + /// Access the root API resource of a running ngrok agent + /// + /// - Remark: HTTP `GET /api`. + /// - Remark: Generated from `#/paths//api/get`. + package func get_sol_api(_ input: Operations.get_sol_api.Input) async throws + -> Operations.get_sol_api.Output + { + try await client.send( + input: input, + forOperation: Operations.get_sol_api.id, + serializer: { _ in + let path = try converter.renderedPath(template: "/api", parameters: []) + var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .get) + suppressMutabilityWarning(&request) + return (request, nil) + }, + deserializer: { response, responseBody in + switch response.status.code { case 200: return .ok(.init()) default: + return .undocumented( + statusCode: response.status.code, + .init(headerFields: response.headerFields, body: responseBody) + ) + } + } + ) + } + /// List Tunnels + /// + /// - Remark: HTTP `GET /api/tunnels`. + /// - Remark: Generated from `#/paths//api/tunnels/get(listTunnels)`. + package func listTunnels(_ input: Operations.listTunnels.Input) async throws + -> Operations.listTunnels.Output + { + try await client.send( + input: input, + forOperation: Operations.listTunnels.id, + serializer: { input in + let path = try converter.renderedPath(template: "/api/tunnels", parameters: []) + var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .get) + suppressMutabilityWarning(&request) + converter.setAcceptHeader(in: &request.headerFields, contentTypes: input.headers.accept) + return (request, nil) + }, + deserializer: { response, responseBody in + switch response.status.code { case 200: + let contentType = converter.extractContentTypeIfPresent(in: response.headerFields) + let body: Operations.listTunnels.Output.Ok.Body + let chosenContentType = try converter.bestContentType( + received: contentType, + options: ["application/json"] + ) + switch chosenContentType { case "application/json": + body = try await converter.getResponseBodyAsJSON( + Components.Schemas.TunnelList.self, + from: responseBody, + transforming: { value in .json(value) } + ) + default: preconditionFailure("bestContentType chose an invalid content type.") + } + return .ok(.init(body: body)) + default: + return .undocumented( + statusCode: response.status.code, + .init(headerFields: response.headerFields, body: responseBody) + ) + } + } + ) + } + /// Start tunnel + /// + /// - Remark: HTTP `POST /api/tunnels`. + /// - Remark: Generated from `#/paths//api/tunnels/post(startTunnel)`. + package func startTunnel(_ input: Operations.startTunnel.Input) async throws + -> Operations.startTunnel.Output + { + try await client.send( + input: input, + forOperation: Operations.startTunnel.id, + serializer: { input in + let path = try converter.renderedPath(template: "/api/tunnels", parameters: []) + var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .post) + suppressMutabilityWarning(&request) + converter.setAcceptHeader(in: &request.headerFields, contentTypes: input.headers.accept) + let body: OpenAPIRuntime.HTTPBody? + switch input.body { case let .json(value): + body = try converter.setRequiredRequestBodyAsJSON( + value, + headerFields: &request.headerFields, + contentType: "application/json; charset=utf-8" + ) + } + return (request, body) + }, + deserializer: { response, responseBody in + switch response.status.code { case 201: + let contentType = converter.extractContentTypeIfPresent(in: response.headerFields) + let body: Operations.startTunnel.Output.Created.Body + let chosenContentType = try converter.bestContentType( + received: contentType, + options: ["application/json"] + ) + switch chosenContentType { case "application/json": + body = try await converter.getResponseBodyAsJSON( + Components.Schemas.TunnelResponse.self, + from: responseBody, + transforming: { value in .json(value) } + ) + default: preconditionFailure("bestContentType chose an invalid content type.") + } + return .created(.init(body: body)) + default: + return .undocumented( + statusCode: response.status.code, + .init(headerFields: response.headerFields, body: responseBody) + ) + } + } + ) + } + /// Tunnel detail + /// + /// - Remark: HTTP `GET /api/tunnels/{name}`. + /// - Remark: Generated from `#/paths//api/tunnels/{name}/get(getTunnel)`. + package func getTunnel(_ input: Operations.getTunnel.Input) async throws + -> Operations.getTunnel.Output + { + try await client.send( + input: input, + forOperation: Operations.getTunnel.id, + serializer: { input in + let path = try converter.renderedPath( + template: "/api/tunnels/{}", + parameters: [input.path.name] ) - } - /// Stop tunnel - /// - /// - Remark: HTTP `DELETE /api/tunnels/{name}`. - /// - Remark: Generated from `#/paths//api/tunnels/{name}/delete(stopTunnel)`. - package func stopTunnel(_ input: Operations.stopTunnel.Input) async throws -> Operations.stopTunnel.Output { - try await client.send( - input: input, - forOperation: Operations.stopTunnel.id, - serializer: { input in - let path = try converter.renderedPath( - template: "/api/tunnels/{}", - parameters: [ - input.path.name - ] - ) - var request: HTTPTypes.HTTPRequest = .init( - soar_path: path, - method: .delete - ) - suppressMutabilityWarning(&request) - return (request, nil) - }, - deserializer: { response, responseBody in - switch response.status.code { - case 204: - return .noContent(.init()) - default: - return .undocumented( - statusCode: response.status.code, - .init( - headerFields: response.headerFields, - body: responseBody - ) - ) - } - } + var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .get) + suppressMutabilityWarning(&request) + converter.setAcceptHeader(in: &request.headerFields, contentTypes: input.headers.accept) + return (request, nil) + }, + deserializer: { response, responseBody in + switch response.status.code { case 200: + let contentType = converter.extractContentTypeIfPresent(in: response.headerFields) + let body: Operations.getTunnel.Output.Ok.Body + let chosenContentType = try converter.bestContentType( + received: contentType, + options: ["application/json"] + ) + switch chosenContentType { case "application/json": + body = try await converter.getResponseBodyAsJSON( + OpenAPIRuntime.OpenAPIValueContainer.self, + from: responseBody, + transforming: { value in .json(value) } + ) + default: preconditionFailure("bestContentType chose an invalid content type.") + } + return .ok(.init(body: body)) + default: + return .undocumented( + statusCode: response.status.code, + .init(headerFields: response.headerFields, body: responseBody) + ) + } + } + ) + } + /// Stop tunnel + /// + /// - Remark: HTTP `DELETE /api/tunnels/{name}`. + /// - Remark: Generated from `#/paths//api/tunnels/{name}/delete(stopTunnel)`. + package func stopTunnel(_ input: Operations.stopTunnel.Input) async throws + -> Operations.stopTunnel.Output + { + try await client.send( + input: input, + forOperation: Operations.stopTunnel.id, + serializer: { input in + let path = try converter.renderedPath( + template: "/api/tunnels/{}", + parameters: [input.path.name] ) - } + var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .delete) + suppressMutabilityWarning(&request) + return (request, nil) + }, + deserializer: { response, responseBody in + switch response.status.code { case 204: return .noContent(.init()) default: + return .undocumented( + statusCode: response.status.code, + .init(headerFields: response.headerFields, body: responseBody) + ) + } + } + ) + } } diff --git a/Packages/Ngrokit/Sources/NgrokOpenAPIClient/Types.swift b/Packages/Ngrokit/Sources/NgrokOpenAPIClient/Types.swift index 2984cc7..c056256 100644 --- a/Packages/Ngrokit/Sources/NgrokOpenAPIClient/Types.swift +++ b/Packages/Ngrokit/Sources/NgrokOpenAPIClient/Types.swift @@ -1,846 +1,786 @@ -// Generated by swift-openapi-generator, do not modify. +// +// Types.swift +// Ngrokit +// +// Created by Leo Dion. +// Copyright © 2024 BrightDigit. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the “Software”), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. +// + @_spi(Generated) import OpenAPIRuntime + #if os(Linux) -@preconcurrency import struct Foundation.URL -@preconcurrency import struct Foundation.Data -@preconcurrency import struct Foundation.Date + @preconcurrency import struct Foundation.URL + @preconcurrency import struct Foundation.Data + @preconcurrency import struct Foundation.Date #else -import struct Foundation.URL -import struct Foundation.Data -import struct Foundation.Date + import struct Foundation.URL + import struct Foundation.Data + import struct Foundation.Date #endif /// A type that performs HTTP operations defined by the OpenAPI document. package protocol APIProtocol: Sendable { - /// Access the root API resource of a running ngrok agent - /// - /// - Remark: HTTP `GET /api`. - /// - Remark: Generated from `#/paths//api/get`. - func get_sol_api(_ input: Operations.get_sol_api.Input) async throws -> Operations.get_sol_api.Output - /// List Tunnels - /// - /// - Remark: HTTP `GET /api/tunnels`. - /// - Remark: Generated from `#/paths//api/tunnels/get(listTunnels)`. - func listTunnels(_ input: Operations.listTunnels.Input) async throws -> Operations.listTunnels.Output - /// Start tunnel - /// - /// - Remark: HTTP `POST /api/tunnels`. - /// - Remark: Generated from `#/paths//api/tunnels/post(startTunnel)`. - func startTunnel(_ input: Operations.startTunnel.Input) async throws -> Operations.startTunnel.Output - /// Tunnel detail - /// - /// - Remark: HTTP `GET /api/tunnels/{name}`. - /// - Remark: Generated from `#/paths//api/tunnels/{name}/get(getTunnel)`. - func getTunnel(_ input: Operations.getTunnel.Input) async throws -> Operations.getTunnel.Output - /// Stop tunnel - /// - /// - Remark: HTTP `DELETE /api/tunnels/{name}`. - /// - Remark: Generated from `#/paths//api/tunnels/{name}/delete(stopTunnel)`. - func stopTunnel(_ input: Operations.stopTunnel.Input) async throws -> Operations.stopTunnel.Output + /// Access the root API resource of a running ngrok agent + /// + /// - Remark: HTTP `GET /api`. + /// - Remark: Generated from `#/paths//api/get`. + func get_sol_api(_ input: Operations.get_sol_api.Input) async throws + -> Operations.get_sol_api.Output + /// List Tunnels + /// + /// - Remark: HTTP `GET /api/tunnels`. + /// - Remark: Generated from `#/paths//api/tunnels/get(listTunnels)`. + func listTunnels(_ input: Operations.listTunnels.Input) async throws + -> Operations.listTunnels.Output + /// Start tunnel + /// + /// - Remark: HTTP `POST /api/tunnels`. + /// - Remark: Generated from `#/paths//api/tunnels/post(startTunnel)`. + func startTunnel(_ input: Operations.startTunnel.Input) async throws + -> Operations.startTunnel.Output + /// Tunnel detail + /// + /// - Remark: HTTP `GET /api/tunnels/{name}`. + /// - Remark: Generated from `#/paths//api/tunnels/{name}/get(getTunnel)`. + func getTunnel(_ input: Operations.getTunnel.Input) async throws -> Operations.getTunnel.Output + /// Stop tunnel + /// + /// - Remark: HTTP `DELETE /api/tunnels/{name}`. + /// - Remark: Generated from `#/paths//api/tunnels/{name}/delete(stopTunnel)`. + func stopTunnel(_ input: Operations.stopTunnel.Input) async throws -> Operations.stopTunnel.Output } /// Convenience overloads for operation inputs. extension APIProtocol { - /// Access the root API resource of a running ngrok agent - /// - /// - Remark: HTTP `GET /api`. - /// - Remark: Generated from `#/paths//api/get`. - package func get_sol_api() async throws -> Operations.get_sol_api.Output { - try await get_sol_api(Operations.get_sol_api.Input()) - } - /// List Tunnels - /// - /// - Remark: HTTP `GET /api/tunnels`. - /// - Remark: Generated from `#/paths//api/tunnels/get(listTunnels)`. - package func listTunnels(headers: Operations.listTunnels.Input.Headers = .init()) async throws -> Operations.listTunnels.Output { - try await listTunnels(Operations.listTunnels.Input(headers: headers)) - } - /// Start tunnel - /// - /// - Remark: HTTP `POST /api/tunnels`. - /// - Remark: Generated from `#/paths//api/tunnels/post(startTunnel)`. - package func startTunnel( - headers: Operations.startTunnel.Input.Headers = .init(), - body: Operations.startTunnel.Input.Body - ) async throws -> Operations.startTunnel.Output { - try await startTunnel(Operations.startTunnel.Input( - headers: headers, - body: body - )) - } - /// Tunnel detail - /// - /// - Remark: HTTP `GET /api/tunnels/{name}`. - /// - Remark: Generated from `#/paths//api/tunnels/{name}/get(getTunnel)`. - package func getTunnel( - path: Operations.getTunnel.Input.Path, - headers: Operations.getTunnel.Input.Headers = .init() - ) async throws -> Operations.getTunnel.Output { - try await getTunnel(Operations.getTunnel.Input( - path: path, - headers: headers - )) - } - /// Stop tunnel - /// - /// - Remark: HTTP `DELETE /api/tunnels/{name}`. - /// - Remark: Generated from `#/paths//api/tunnels/{name}/delete(stopTunnel)`. - package func stopTunnel(path: Operations.stopTunnel.Input.Path) async throws -> Operations.stopTunnel.Output { - try await stopTunnel(Operations.stopTunnel.Input(path: path)) - } + /// Access the root API resource of a running ngrok agent + /// + /// - Remark: HTTP `GET /api`. + /// - Remark: Generated from `#/paths//api/get`. + package func get_sol_api() async throws -> Operations.get_sol_api.Output { + try await get_sol_api(Operations.get_sol_api.Input()) + } + /// List Tunnels + /// + /// - Remark: HTTP `GET /api/tunnels`. + /// - Remark: Generated from `#/paths//api/tunnels/get(listTunnels)`. + package func listTunnels(headers: Operations.listTunnels.Input.Headers = .init()) async throws + -> Operations.listTunnels.Output + { try await listTunnels(Operations.listTunnels.Input(headers: headers)) } + /// Start tunnel + /// + /// - Remark: HTTP `POST /api/tunnels`. + /// - Remark: Generated from `#/paths//api/tunnels/post(startTunnel)`. + package func startTunnel( + headers: Operations.startTunnel.Input.Headers = .init(), + body: Operations.startTunnel.Input.Body + ) async throws -> Operations.startTunnel.Output { + try await startTunnel(Operations.startTunnel.Input(headers: headers, body: body)) + } + /// Tunnel detail + /// + /// - Remark: HTTP `GET /api/tunnels/{name}`. + /// - Remark: Generated from `#/paths//api/tunnels/{name}/get(getTunnel)`. + package func getTunnel( + path: Operations.getTunnel.Input.Path, + headers: Operations.getTunnel.Input.Headers = .init() + ) async throws -> Operations.getTunnel.Output { + try await getTunnel(Operations.getTunnel.Input(path: path, headers: headers)) + } + /// Stop tunnel + /// + /// - Remark: HTTP `DELETE /api/tunnels/{name}`. + /// - Remark: Generated from `#/paths//api/tunnels/{name}/delete(stopTunnel)`. + package func stopTunnel(path: Operations.stopTunnel.Input.Path) async throws + -> Operations.stopTunnel.Output + { try await stopTunnel(Operations.stopTunnel.Input(path: path)) } } /// Server URLs defined in the OpenAPI document. package enum Servers { - /// Default Local Server - package static func server1() throws -> Foundation.URL { - try Foundation.URL( - validatingOpenAPIServerURL: "http://127.0.0.1:4040", - variables: [] - ) - } + /// Default Local Server + package static func server1() throws -> Foundation.URL { + try Foundation.URL(validatingOpenAPIServerURL: "http://127.0.0.1:4040", variables: []) + } } /// Types generated from the components section of the OpenAPI document. package enum Components { - /// Types generated from the `#/components/schemas` section of the OpenAPI document. - package enum Schemas { - /// - Remark: Generated from `#/components/schemas/TunnelList`. - package struct TunnelList: Codable, Hashable, Sendable { - /// - Remark: Generated from `#/components/schemas/TunnelList/tunnels`. - package var tunnels: [Components.Schemas.TunnelResponse] - /// Creates a new `TunnelList`. - /// - /// - Parameters: - /// - tunnels: - package init(tunnels: [Components.Schemas.TunnelResponse]) { - self.tunnels = tunnels - } - package enum CodingKeys: String, CodingKey { - case tunnels - } + /// Types generated from the `#/components/schemas` section of the OpenAPI document. + package enum Schemas { + /// - Remark: Generated from `#/components/schemas/TunnelList`. + package struct TunnelList: Codable, Hashable, Sendable { + /// - Remark: Generated from `#/components/schemas/TunnelList/tunnels`. + package var tunnels: [Components.Schemas.TunnelResponse] + /// Creates a new `TunnelList`. + /// + /// - Parameters: + /// - tunnels: + package init(tunnels: [Components.Schemas.TunnelResponse]) { self.tunnels = tunnels } + package enum CodingKeys: String, CodingKey { case tunnels } + } + /// - Remark: Generated from `#/components/schemas/TunnelRequest`. + package struct TunnelRequest: Codable, Hashable, Sendable { + /// - Remark: Generated from `#/components/schemas/TunnelRequest/addr`. + package var addr: Swift.String + /// - Remark: Generated from `#/components/schemas/TunnelRequest/proto`. + package var proto: Swift.String + /// - Remark: Generated from `#/components/schemas/TunnelRequest/name`. + package var name: Swift.String + /// Creates a new `TunnelRequest`. + /// + /// - Parameters: + /// - addr: + /// - proto: + /// - name: + package init(addr: Swift.String, proto: Swift.String, name: Swift.String) { + self.addr = addr + self.proto = proto + self.name = name + } + package enum CodingKeys: String, CodingKey { + case addr + case proto + case name + } + } + /// - Remark: Generated from `#/components/schemas/TunnelResponse`. + package struct TunnelResponse: Codable, Hashable, Sendable { + /// - Remark: Generated from `#/components/schemas/TunnelResponse/name`. + package var name: Swift.String + /// - Remark: Generated from `#/components/schemas/TunnelResponse/uri`. + package var uri: Swift.String? + /// - Remark: Generated from `#/components/schemas/TunnelResponse/public_url`. + package var public_url: Swift.String + /// - Remark: Generated from `#/components/schemas/TunnelResponse/proto`. + package var proto: Swift.String? + /// - Remark: Generated from `#/components/schemas/TunnelResponse/config`. + package struct configPayload: Codable, Hashable, Sendable { + /// - Remark: Generated from `#/components/schemas/TunnelResponse/config/addr`. + package var addr: Swift.String + /// - Remark: Generated from `#/components/schemas/TunnelResponse/config/inspect`. + package var inspect: Swift.Bool + /// Creates a new `configPayload`. + /// + /// - Parameters: + /// - addr: + /// - inspect: + package init(addr: Swift.String, inspect: Swift.Bool) { + self.addr = addr + self.inspect = inspect } - /// - Remark: Generated from `#/components/schemas/TunnelRequest`. - package struct TunnelRequest: Codable, Hashable, Sendable { - /// - Remark: Generated from `#/components/schemas/TunnelRequest/addr`. - package var addr: Swift.String - /// - Remark: Generated from `#/components/schemas/TunnelRequest/proto`. - package var proto: Swift.String - /// - Remark: Generated from `#/components/schemas/TunnelRequest/name`. - package var name: Swift.String - /// Creates a new `TunnelRequest`. - /// - /// - Parameters: - /// - addr: - /// - proto: - /// - name: - package init( - addr: Swift.String, - proto: Swift.String, - name: Swift.String - ) { - self.addr = addr - self.proto = proto - self.name = name - } - package enum CodingKeys: String, CodingKey { - case addr - case proto - case name - } + package enum CodingKeys: String, CodingKey { + case addr + case inspect } - /// - Remark: Generated from `#/components/schemas/TunnelResponse`. - package struct TunnelResponse: Codable, Hashable, Sendable { - /// - Remark: Generated from `#/components/schemas/TunnelResponse/name`. - package var name: Swift.String - /// - Remark: Generated from `#/components/schemas/TunnelResponse/uri`. - package var uri: Swift.String? - /// - Remark: Generated from `#/components/schemas/TunnelResponse/public_url`. - package var public_url: Swift.String - /// - Remark: Generated from `#/components/schemas/TunnelResponse/proto`. - package var proto: Swift.String? - /// - Remark: Generated from `#/components/schemas/TunnelResponse/config`. - package struct configPayload: Codable, Hashable, Sendable { - /// - Remark: Generated from `#/components/schemas/TunnelResponse/config/addr`. - package var addr: Swift.String - /// - Remark: Generated from `#/components/schemas/TunnelResponse/config/inspect`. - package var inspect: Swift.Bool - /// Creates a new `configPayload`. - /// - /// - Parameters: - /// - addr: - /// - inspect: - package init( - addr: Swift.String, - inspect: Swift.Bool - ) { - self.addr = addr - self.inspect = inspect - } - package enum CodingKeys: String, CodingKey { - case addr - case inspect - } - } - /// - Remark: Generated from `#/components/schemas/TunnelResponse/config`. - package var config: Components.Schemas.TunnelResponse.configPayload - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics`. - package struct metricsPayload: Codable, Hashable, Sendable { - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns`. - package struct connsPayload: Codable, Hashable, Sendable { - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/count`. - package var count: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/gauge`. - package var gauge: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/rate1`. - package var rate1: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/rate5`. - package var rate5: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/rate15`. - package var rate15: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/p50`. - package var p50: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/p90`. - package var p90: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/p95`. - package var p95: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/p99`. - package var p99: Swift.Int - /// Creates a new `connsPayload`. - /// - /// - Parameters: - /// - count: - /// - gauge: - /// - rate1: - /// - rate5: - /// - rate15: - /// - p50: - /// - p90: - /// - p95: - /// - p99: - package init( - count: Swift.Int, - gauge: Swift.Int, - rate1: Swift.Int, - rate5: Swift.Int, - rate15: Swift.Int, - p50: Swift.Int, - p90: Swift.Int, - p95: Swift.Int, - p99: Swift.Int - ) { - self.count = count - self.gauge = gauge - self.rate1 = rate1 - self.rate5 = rate5 - self.rate15 = rate15 - self.p50 = p50 - self.p90 = p90 - self.p95 = p95 - self.p99 = p99 - } - package enum CodingKeys: String, CodingKey { - case count - case gauge - case rate1 - case rate5 - case rate15 - case p50 - case p90 - case p95 - case p99 - } - } - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns`. - package var conns: Components.Schemas.TunnelResponse.metricsPayload.connsPayload? - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http`. - package struct httpPayload: Codable, Hashable, Sendable { - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/count`. - package var count: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/rate1`. - package var rate1: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/rate5`. - package var rate5: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/rate15`. - package var rate15: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/p50`. - package var p50: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/p90`. - package var p90: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/p95`. - package var p95: Swift.Int - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/p99`. - package var p99: Swift.Int - /// Creates a new `httpPayload`. - /// - /// - Parameters: - /// - count: - /// - rate1: - /// - rate5: - /// - rate15: - /// - p50: - /// - p90: - /// - p95: - /// - p99: - package init( - count: Swift.Int, - rate1: Swift.Int, - rate5: Swift.Int, - rate15: Swift.Int, - p50: Swift.Int, - p90: Swift.Int, - p95: Swift.Int, - p99: Swift.Int - ) { - self.count = count - self.rate1 = rate1 - self.rate5 = rate5 - self.rate15 = rate15 - self.p50 = p50 - self.p90 = p90 - self.p95 = p95 - self.p99 = p99 - } - package enum CodingKeys: String, CodingKey { - case count - case rate1 - case rate5 - case rate15 - case p50 - case p90 - case p95 - case p99 - } - } - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http`. - package var http: Components.Schemas.TunnelResponse.metricsPayload.httpPayload? - /// Creates a new `metricsPayload`. - /// - /// - Parameters: - /// - conns: - /// - http: - package init( - conns: Components.Schemas.TunnelResponse.metricsPayload.connsPayload? = nil, - http: Components.Schemas.TunnelResponse.metricsPayload.httpPayload? = nil - ) { - self.conns = conns - self.http = http - } - package enum CodingKeys: String, CodingKey { - case conns - case http - } - } - /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics`. - package var metrics: Components.Schemas.TunnelResponse.metricsPayload? - /// Creates a new `TunnelResponse`. - /// - /// - Parameters: - /// - name: - /// - uri: - /// - public_url: - /// - proto: - /// - config: - /// - metrics: - package init( - name: Swift.String, - uri: Swift.String? = nil, - public_url: Swift.String, - proto: Swift.String? = nil, - config: Components.Schemas.TunnelResponse.configPayload, - metrics: Components.Schemas.TunnelResponse.metricsPayload? = nil - ) { - self.name = name - self.uri = uri - self.public_url = public_url - self.proto = proto - self.config = config - self.metrics = metrics - } - package enum CodingKeys: String, CodingKey { - case name - case uri - case public_url - case proto - case config - case metrics - } + } + /// - Remark: Generated from `#/components/schemas/TunnelResponse/config`. + package var config: Components.Schemas.TunnelResponse.configPayload + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics`. + package struct metricsPayload: Codable, Hashable, Sendable { + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns`. + package struct connsPayload: Codable, Hashable, Sendable { + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/count`. + package var count: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/gauge`. + package var gauge: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/rate1`. + package var rate1: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/rate5`. + package var rate5: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/rate15`. + package var rate15: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/p50`. + package var p50: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/p90`. + package var p90: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/p95`. + package var p95: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns/p99`. + package var p99: Swift.Int + /// Creates a new `connsPayload`. + /// + /// - Parameters: + /// - count: + /// - gauge: + /// - rate1: + /// - rate5: + /// - rate15: + /// - p50: + /// - p90: + /// - p95: + /// - p99: + package init( + count: Swift.Int, + gauge: Swift.Int, + rate1: Swift.Int, + rate5: Swift.Int, + rate15: Swift.Int, + p50: Swift.Int, + p90: Swift.Int, + p95: Swift.Int, + p99: Swift.Int + ) { + self.count = count + self.gauge = gauge + self.rate1 = rate1 + self.rate5 = rate5 + self.rate15 = rate15 + self.p50 = p50 + self.p90 = p90 + self.p95 = p95 + self.p99 = p99 + } + package enum CodingKeys: String, CodingKey { + case count + case gauge + case rate1 + case rate5 + case rate15 + case p50 + case p90 + case p95 + case p99 + } + } + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/conns`. + package var conns: Components.Schemas.TunnelResponse.metricsPayload.connsPayload? + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http`. + package struct httpPayload: Codable, Hashable, Sendable { + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/count`. + package var count: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/rate1`. + package var rate1: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/rate5`. + package var rate5: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/rate15`. + package var rate15: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/p50`. + package var p50: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/p90`. + package var p90: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/p95`. + package var p95: Swift.Int + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http/p99`. + package var p99: Swift.Int + /// Creates a new `httpPayload`. + /// + /// - Parameters: + /// - count: + /// - rate1: + /// - rate5: + /// - rate15: + /// - p50: + /// - p90: + /// - p95: + /// - p99: + package init( + count: Swift.Int, + rate1: Swift.Int, + rate5: Swift.Int, + rate15: Swift.Int, + p50: Swift.Int, + p90: Swift.Int, + p95: Swift.Int, + p99: Swift.Int + ) { + self.count = count + self.rate1 = rate1 + self.rate5 = rate5 + self.rate15 = rate15 + self.p50 = p50 + self.p90 = p90 + self.p95 = p95 + self.p99 = p99 + } + package enum CodingKeys: String, CodingKey { + case count + case rate1 + case rate5 + case rate15 + case p50 + case p90 + case p95 + case p99 + } } + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics/http`. + package var http: Components.Schemas.TunnelResponse.metricsPayload.httpPayload? + /// Creates a new `metricsPayload`. + /// + /// - Parameters: + /// - conns: + /// - http: + package init( + conns: Components.Schemas.TunnelResponse.metricsPayload.connsPayload? = nil, + http: Components.Schemas.TunnelResponse.metricsPayload.httpPayload? = nil + ) { + self.conns = conns + self.http = http + } + package enum CodingKeys: String, CodingKey { + case conns + case http + } + } + /// - Remark: Generated from `#/components/schemas/TunnelResponse/metrics`. + package var metrics: Components.Schemas.TunnelResponse.metricsPayload? + /// Creates a new `TunnelResponse`. + /// + /// - Parameters: + /// - name: + /// - uri: + /// - public_url: + /// - proto: + /// - config: + /// - metrics: + package init( + name: Swift.String, + uri: Swift.String? = nil, + public_url: Swift.String, + proto: Swift.String? = nil, + config: Components.Schemas.TunnelResponse.configPayload, + metrics: Components.Schemas.TunnelResponse.metricsPayload? = nil + ) { + self.name = name + self.uri = uri + self.public_url = public_url + self.proto = proto + self.config = config + self.metrics = metrics + } + package enum CodingKeys: String, CodingKey { + case name + case uri + case public_url + case proto + case config + case metrics + } } - /// Types generated from the `#/components/parameters` section of the OpenAPI document. - package enum Parameters {} - /// Types generated from the `#/components/requestBodies` section of the OpenAPI document. - package enum RequestBodies {} - /// Types generated from the `#/components/responses` section of the OpenAPI document. - package enum Responses {} - /// Types generated from the `#/components/headers` section of the OpenAPI document. - package enum Headers {} + } + /// Types generated from the `#/components/parameters` section of the OpenAPI document. + package enum Parameters {} + /// Types generated from the `#/components/requestBodies` section of the OpenAPI document. + package enum RequestBodies {} + /// Types generated from the `#/components/responses` section of the OpenAPI document. + package enum Responses {} + /// Types generated from the `#/components/headers` section of the OpenAPI document. + package enum Headers {} } /// API operations, with input and output types, generated from `#/paths` in the OpenAPI document. package enum Operations { - /// Access the root API resource of a running ngrok agent - /// - /// - Remark: HTTP `GET /api`. - /// - Remark: Generated from `#/paths//api/get`. - package enum get_sol_api { - package static let id: Swift.String = "get/api" - package struct Input: Sendable, Hashable { - /// Creates a new `Input`. - package init() {} - } - @frozen package enum Output: Sendable, Hashable { - package struct Ok: Sendable, Hashable { - /// Creates a new `Ok`. - package init() {} - } - /// Successful response - /// - /// - Remark: Generated from `#/paths//api/get/responses/200`. - /// - /// HTTP response code: `200 ok`. - case ok(Operations.get_sol_api.Output.Ok) - /// The associated value of the enum case if `self` is `.ok`. - /// - /// - Throws: An error if `self` is not `.ok`. - /// - SeeAlso: `.ok`. - package var ok: Operations.get_sol_api.Output.Ok { - get throws { - switch self { - case let .ok(response): - return response - default: - try throwUnexpectedResponseStatus( - expectedStatus: "ok", - response: self - ) - } - } - } - /// Undocumented response. - /// - /// A response with a code that is not documented in the OpenAPI document. - case undocumented(statusCode: Swift.Int, OpenAPIRuntime.UndocumentedPayload) + /// Access the root API resource of a running ngrok agent + /// + /// - Remark: HTTP `GET /api`. + /// - Remark: Generated from `#/paths//api/get`. + package enum get_sol_api { + package static let id: Swift.String = "get/api" + package struct Input: Sendable, Hashable { + /// Creates a new `Input`. + package init() {} + } + @frozen package enum Output: Sendable, Hashable { + package struct Ok: Sendable, Hashable { + /// Creates a new `Ok`. + package init() {} + } + /// Successful response + /// + /// - Remark: Generated from `#/paths//api/get/responses/200`. + /// + /// HTTP response code: `200 ok`. + case ok(Operations.get_sol_api.Output.Ok) + /// The associated value of the enum case if `self` is `.ok`. + /// + /// - Throws: An error if `self` is not `.ok`. + /// - SeeAlso: `.ok`. + package var ok: Operations.get_sol_api.Output.Ok { + get throws { + switch self { case let .ok(response): return response default: + try throwUnexpectedResponseStatus(expectedStatus: "ok", response: self) + } } + } + /// Undocumented response. + /// + /// A response with a code that is not documented in the OpenAPI document. + case undocumented(statusCode: Swift.Int, OpenAPIRuntime.UndocumentedPayload) } - /// List Tunnels - /// - /// - Remark: HTTP `GET /api/tunnels`. - /// - Remark: Generated from `#/paths//api/tunnels/get(listTunnels)`. - package enum listTunnels { - package static let id: Swift.String = "listTunnels" - package struct Input: Sendable, Hashable { - /// - Remark: Generated from `#/paths/api/tunnels/GET/header`. - package struct Headers: Sendable, Hashable { - package var accept: [OpenAPIRuntime.AcceptHeaderContentType] - /// Creates a new `Headers`. - /// - /// - Parameters: - /// - accept: - package init(accept: [OpenAPIRuntime.AcceptHeaderContentType] = .defaultValues()) { - self.accept = accept - } - } - package var headers: Operations.listTunnels.Input.Headers - /// Creates a new `Input`. - /// - /// - Parameters: - /// - headers: - package init(headers: Operations.listTunnels.Input.Headers = .init()) { - self.headers = headers - } + } + /// List Tunnels + /// + /// - Remark: HTTP `GET /api/tunnels`. + /// - Remark: Generated from `#/paths//api/tunnels/get(listTunnels)`. + package enum listTunnels { + package static let id: Swift.String = "listTunnels" + package struct Input: Sendable, Hashable { + /// - Remark: Generated from `#/paths/api/tunnels/GET/header`. + package struct Headers: Sendable, Hashable { + package var accept: + [OpenAPIRuntime.AcceptHeaderContentType] + /// Creates a new `Headers`. + /// + /// - Parameters: + /// - accept: + package init( + accept: [OpenAPIRuntime.AcceptHeaderContentType< + Operations.listTunnels.AcceptableContentType + >] = .defaultValues() + ) { self.accept = accept } + } + package var headers: Operations.listTunnels.Input.Headers + /// Creates a new `Input`. + /// + /// - Parameters: + /// - headers: + package init(headers: Operations.listTunnels.Input.Headers = .init()) { + self.headers = headers + } + } + @frozen package enum Output: Sendable, Hashable { + package struct Ok: Sendable, Hashable { + /// - Remark: Generated from `#/paths/api/tunnels/GET/responses/200/content`. + @frozen package enum Body: Sendable, Hashable { + /// - Remark: Generated from `#/paths/api/tunnels/GET/responses/200/content/application\/json`. + case json(Components.Schemas.TunnelList) + /// The associated value of the enum case if `self` is `.json`. + /// + /// - Throws: An error if `self` is not `.json`. + /// - SeeAlso: `.json`. + package var json: Components.Schemas.TunnelList { + get throws { + switch self { case let .json(body): return body + } + } + } } - @frozen package enum Output: Sendable, Hashable { - package struct Ok: Sendable, Hashable { - /// - Remark: Generated from `#/paths/api/tunnels/GET/responses/200/content`. - @frozen package enum Body: Sendable, Hashable { - /// - Remark: Generated from `#/paths/api/tunnels/GET/responses/200/content/application\/json`. - case json(Components.Schemas.TunnelList) - /// The associated value of the enum case if `self` is `.json`. - /// - /// - Throws: An error if `self` is not `.json`. - /// - SeeAlso: `.json`. - package var json: Components.Schemas.TunnelList { - get throws { - switch self { - case let .json(body): - return body - } - } - } - } - /// Received HTTP response body - package var body: Operations.listTunnels.Output.Ok.Body - /// Creates a new `Ok`. - /// - /// - Parameters: - /// - body: Received HTTP response body - package init(body: Operations.listTunnels.Output.Ok.Body) { - self.body = body - } - } - /// Successful response - /// - /// - Remark: Generated from `#/paths//api/tunnels/get(listTunnels)/responses/200`. - /// - /// HTTP response code: `200 ok`. - case ok(Operations.listTunnels.Output.Ok) - /// The associated value of the enum case if `self` is `.ok`. - /// - /// - Throws: An error if `self` is not `.ok`. - /// - SeeAlso: `.ok`. - package var ok: Operations.listTunnels.Output.Ok { - get throws { - switch self { - case let .ok(response): - return response - default: - try throwUnexpectedResponseStatus( - expectedStatus: "ok", - response: self - ) - } - } - } - /// Undocumented response. - /// - /// A response with a code that is not documented in the OpenAPI document. - case undocumented(statusCode: Swift.Int, OpenAPIRuntime.UndocumentedPayload) - } - @frozen package enum AcceptableContentType: AcceptableProtocol { - case json - case other(Swift.String) - package init?(rawValue: Swift.String) { - switch rawValue.lowercased() { - case "application/json": - self = .json - default: - self = .other(rawValue) - } - } - package var rawValue: Swift.String { - switch self { - case let .other(string): - return string - case .json: - return "application/json" - } - } - package static var allCases: [Self] { - [ - .json - ] - } + /// Received HTTP response body + package var body: Operations.listTunnels.Output.Ok.Body + /// Creates a new `Ok`. + /// + /// - Parameters: + /// - body: Received HTTP response body + package init(body: Operations.listTunnels.Output.Ok.Body) { self.body = body } + } + /// Successful response + /// + /// - Remark: Generated from `#/paths//api/tunnels/get(listTunnels)/responses/200`. + /// + /// HTTP response code: `200 ok`. + case ok(Operations.listTunnels.Output.Ok) + /// The associated value of the enum case if `self` is `.ok`. + /// + /// - Throws: An error if `self` is not `.ok`. + /// - SeeAlso: `.ok`. + package var ok: Operations.listTunnels.Output.Ok { + get throws { + switch self { case let .ok(response): return response default: + try throwUnexpectedResponseStatus(expectedStatus: "ok", response: self) + } } + } + /// Undocumented response. + /// + /// A response with a code that is not documented in the OpenAPI document. + case undocumented(statusCode: Swift.Int, OpenAPIRuntime.UndocumentedPayload) } - /// Start tunnel - /// - /// - Remark: HTTP `POST /api/tunnels`. - /// - Remark: Generated from `#/paths//api/tunnels/post(startTunnel)`. - package enum startTunnel { - package static let id: Swift.String = "startTunnel" - package struct Input: Sendable, Hashable { - /// - Remark: Generated from `#/paths/api/tunnels/POST/header`. - package struct Headers: Sendable, Hashable { - package var accept: [OpenAPIRuntime.AcceptHeaderContentType] - /// Creates a new `Headers`. - /// - /// - Parameters: - /// - accept: - package init(accept: [OpenAPIRuntime.AcceptHeaderContentType] = .defaultValues()) { - self.accept = accept - } - } - package var headers: Operations.startTunnel.Input.Headers - /// - Remark: Generated from `#/paths/api/tunnels/POST/requestBody`. - @frozen package enum Body: Sendable, Hashable { - /// - Remark: Generated from `#/paths/api/tunnels/POST/requestBody/content/application\/json`. - case json(Components.Schemas.TunnelRequest) - } - package var body: Operations.startTunnel.Input.Body - /// Creates a new `Input`. - /// - /// - Parameters: - /// - headers: - /// - body: - package init( - headers: Operations.startTunnel.Input.Headers = .init(), - body: Operations.startTunnel.Input.Body - ) { - self.headers = headers - self.body = body - } + @frozen package enum AcceptableContentType: AcceptableProtocol { + case json + case other(Swift.String) + package init?(rawValue: Swift.String) { + switch rawValue.lowercased() { case "application/json": self = .json default: + self = .other(rawValue) } - @frozen package enum Output: Sendable, Hashable { - package struct Created: Sendable, Hashable { - /// - Remark: Generated from `#/paths/api/tunnels/POST/responses/201/content`. - @frozen package enum Body: Sendable, Hashable { - /// - Remark: Generated from `#/paths/api/tunnels/POST/responses/201/content/application\/json`. - case json(Components.Schemas.TunnelResponse) - /// The associated value of the enum case if `self` is `.json`. - /// - /// - Throws: An error if `self` is not `.json`. - /// - SeeAlso: `.json`. - package var json: Components.Schemas.TunnelResponse { - get throws { - switch self { - case let .json(body): - return body - } - } - } - } - /// Received HTTP response body - package var body: Operations.startTunnel.Output.Created.Body - /// Creates a new `Created`. - /// - /// - Parameters: - /// - body: Received HTTP response body - package init(body: Operations.startTunnel.Output.Created.Body) { - self.body = body - } - } - /// Tunnel started successfully - /// - /// - Remark: Generated from `#/paths//api/tunnels/post(startTunnel)/responses/201`. - /// - /// HTTP response code: `201 created`. - case created(Operations.startTunnel.Output.Created) - /// The associated value of the enum case if `self` is `.created`. - /// - /// - Throws: An error if `self` is not `.created`. - /// - SeeAlso: `.created`. - package var created: Operations.startTunnel.Output.Created { - get throws { - switch self { - case let .created(response): - return response - default: - try throwUnexpectedResponseStatus( - expectedStatus: "created", - response: self - ) - } - } - } - /// Undocumented response. - /// - /// A response with a code that is not documented in the OpenAPI document. - case undocumented(statusCode: Swift.Int, OpenAPIRuntime.UndocumentedPayload) + } + package var rawValue: Swift.String { + switch self { case let .other(string): return string case .json: return "application/json" } - @frozen package enum AcceptableContentType: AcceptableProtocol { - case json - case other(Swift.String) - package init?(rawValue: Swift.String) { - switch rawValue.lowercased() { - case "application/json": - self = .json - default: - self = .other(rawValue) - } - } - package var rawValue: Swift.String { - switch self { - case let .other(string): - return string - case .json: - return "application/json" - } - } - package static var allCases: [Self] { - [ - .json - ] - } + } + package static var allCases: [Self] { [.json] } + } + } + /// Start tunnel + /// + /// - Remark: HTTP `POST /api/tunnels`. + /// - Remark: Generated from `#/paths//api/tunnels/post(startTunnel)`. + package enum startTunnel { + package static let id: Swift.String = "startTunnel" + package struct Input: Sendable, Hashable { + /// - Remark: Generated from `#/paths/api/tunnels/POST/header`. + package struct Headers: Sendable, Hashable { + package var accept: + [OpenAPIRuntime.AcceptHeaderContentType] + /// Creates a new `Headers`. + /// + /// - Parameters: + /// - accept: + package init( + accept: [OpenAPIRuntime.AcceptHeaderContentType< + Operations.startTunnel.AcceptableContentType + >] = .defaultValues() + ) { self.accept = accept } + } + package var headers: Operations.startTunnel.Input.Headers + /// - Remark: Generated from `#/paths/api/tunnels/POST/requestBody`. + @frozen package enum Body: Sendable, Hashable { + /// - Remark: Generated from `#/paths/api/tunnels/POST/requestBody/content/application\/json`. + case json(Components.Schemas.TunnelRequest) + } + package var body: Operations.startTunnel.Input.Body + /// Creates a new `Input`. + /// + /// - Parameters: + /// - headers: + /// - body: + package init( + headers: Operations.startTunnel.Input.Headers = .init(), + body: Operations.startTunnel.Input.Body + ) { + self.headers = headers + self.body = body + } + } + @frozen package enum Output: Sendable, Hashable { + package struct Created: Sendable, Hashable { + /// - Remark: Generated from `#/paths/api/tunnels/POST/responses/201/content`. + @frozen package enum Body: Sendable, Hashable { + /// - Remark: Generated from `#/paths/api/tunnels/POST/responses/201/content/application\/json`. + case json(Components.Schemas.TunnelResponse) + /// The associated value of the enum case if `self` is `.json`. + /// + /// - Throws: An error if `self` is not `.json`. + /// - SeeAlso: `.json`. + package var json: Components.Schemas.TunnelResponse { + get throws { + switch self { case let .json(body): return body + } + } + } } + /// Received HTTP response body + package var body: Operations.startTunnel.Output.Created.Body + /// Creates a new `Created`. + /// + /// - Parameters: + /// - body: Received HTTP response body + package init(body: Operations.startTunnel.Output.Created.Body) { self.body = body } + } + /// Tunnel started successfully + /// + /// - Remark: Generated from `#/paths//api/tunnels/post(startTunnel)/responses/201`. + /// + /// HTTP response code: `201 created`. + case created(Operations.startTunnel.Output.Created) + /// The associated value of the enum case if `self` is `.created`. + /// + /// - Throws: An error if `self` is not `.created`. + /// - SeeAlso: `.created`. + package var created: Operations.startTunnel.Output.Created { + get throws { + switch self { case let .created(response): return response default: + try throwUnexpectedResponseStatus(expectedStatus: "created", response: self) + } + } + } + /// Undocumented response. + /// + /// A response with a code that is not documented in the OpenAPI document. + case undocumented(statusCode: Swift.Int, OpenAPIRuntime.UndocumentedPayload) } - /// Tunnel detail - /// - /// - Remark: HTTP `GET /api/tunnels/{name}`. - /// - Remark: Generated from `#/paths//api/tunnels/{name}/get(getTunnel)`. - package enum getTunnel { - package static let id: Swift.String = "getTunnel" - package struct Input: Sendable, Hashable { - /// - Remark: Generated from `#/paths/api/tunnels/{name}/GET/path`. - package struct Path: Sendable, Hashable { - /// - Remark: Generated from `#/paths/api/tunnels/{name}/GET/path/name`. - package var name: Swift.String - /// Creates a new `Path`. - /// - /// - Parameters: - /// - name: - package init(name: Swift.String) { - self.name = name - } - } - package var path: Operations.getTunnel.Input.Path - /// - Remark: Generated from `#/paths/api/tunnels/{name}/GET/header`. - package struct Headers: Sendable, Hashable { - package var accept: [OpenAPIRuntime.AcceptHeaderContentType] - /// Creates a new `Headers`. - /// - /// - Parameters: - /// - accept: - package init(accept: [OpenAPIRuntime.AcceptHeaderContentType] = .defaultValues()) { - self.accept = accept - } - } - package var headers: Operations.getTunnel.Input.Headers - /// Creates a new `Input`. - /// - /// - Parameters: - /// - path: - /// - headers: - package init( - path: Operations.getTunnel.Input.Path, - headers: Operations.getTunnel.Input.Headers = .init() - ) { - self.path = path - self.headers = headers - } + @frozen package enum AcceptableContentType: AcceptableProtocol { + case json + case other(Swift.String) + package init?(rawValue: Swift.String) { + switch rawValue.lowercased() { case "application/json": self = .json default: + self = .other(rawValue) } - @frozen package enum Output: Sendable, Hashable { - package struct Ok: Sendable, Hashable { - /// - Remark: Generated from `#/paths/api/tunnels/{name}/GET/responses/200/content`. - @frozen package enum Body: Sendable, Hashable { - /// - Remark: Generated from `#/paths/api/tunnels/{name}/GET/responses/200/content/application\/json`. - case json(OpenAPIRuntime.OpenAPIValueContainer) - /// The associated value of the enum case if `self` is `.json`. - /// - /// - Throws: An error if `self` is not `.json`. - /// - SeeAlso: `.json`. - package var json: OpenAPIRuntime.OpenAPIValueContainer { - get throws { - switch self { - case let .json(body): - return body - } - } - } - } - /// Received HTTP response body - package var body: Operations.getTunnel.Output.Ok.Body - /// Creates a new `Ok`. - /// - /// - Parameters: - /// - body: Received HTTP response body - package init(body: Operations.getTunnel.Output.Ok.Body) { - self.body = body - } - } - /// Successful response - /// - /// - Remark: Generated from `#/paths//api/tunnels/{name}/get(getTunnel)/responses/200`. - /// - /// HTTP response code: `200 ok`. - case ok(Operations.getTunnel.Output.Ok) - /// The associated value of the enum case if `self` is `.ok`. - /// - /// - Throws: An error if `self` is not `.ok`. - /// - SeeAlso: `.ok`. - package var ok: Operations.getTunnel.Output.Ok { - get throws { - switch self { - case let .ok(response): - return response - default: - try throwUnexpectedResponseStatus( - expectedStatus: "ok", - response: self - ) - } - } - } - /// Undocumented response. - /// - /// A response with a code that is not documented in the OpenAPI document. - case undocumented(statusCode: Swift.Int, OpenAPIRuntime.UndocumentedPayload) + } + package var rawValue: Swift.String { + switch self { case let .other(string): return string case .json: return "application/json" } - @frozen package enum AcceptableContentType: AcceptableProtocol { - case json - case other(Swift.String) - package init?(rawValue: Swift.String) { - switch rawValue.lowercased() { - case "application/json": - self = .json - default: - self = .other(rawValue) - } - } - package var rawValue: Swift.String { - switch self { - case let .other(string): - return string - case .json: - return "application/json" - } - } - package static var allCases: [Self] { - [ - .json - ] - } + } + package static var allCases: [Self] { [.json] } + } + } + /// Tunnel detail + /// + /// - Remark: HTTP `GET /api/tunnels/{name}`. + /// - Remark: Generated from `#/paths//api/tunnels/{name}/get(getTunnel)`. + package enum getTunnel { + package static let id: Swift.String = "getTunnel" + package struct Input: Sendable, Hashable { + /// - Remark: Generated from `#/paths/api/tunnels/{name}/GET/path`. + package struct Path: Sendable, Hashable { + /// - Remark: Generated from `#/paths/api/tunnels/{name}/GET/path/name`. + package var name: Swift.String + /// Creates a new `Path`. + /// + /// - Parameters: + /// - name: + package init(name: Swift.String) { self.name = name } + } + package var path: Operations.getTunnel.Input.Path + /// - Remark: Generated from `#/paths/api/tunnels/{name}/GET/header`. + package struct Headers: Sendable, Hashable { + package var accept: + [OpenAPIRuntime.AcceptHeaderContentType] + /// Creates a new `Headers`. + /// + /// - Parameters: + /// - accept: + package init( + accept: [OpenAPIRuntime.AcceptHeaderContentType< + Operations.getTunnel.AcceptableContentType + >] = .defaultValues() + ) { self.accept = accept } + } + package var headers: Operations.getTunnel.Input.Headers + /// Creates a new `Input`. + /// + /// - Parameters: + /// - path: + /// - headers: + package init( + path: Operations.getTunnel.Input.Path, + headers: Operations.getTunnel.Input.Headers = .init() + ) { + self.path = path + self.headers = headers + } + } + @frozen package enum Output: Sendable, Hashable { + package struct Ok: Sendable, Hashable { + /// - Remark: Generated from `#/paths/api/tunnels/{name}/GET/responses/200/content`. + @frozen package enum Body: Sendable, Hashable { + /// - Remark: Generated from `#/paths/api/tunnels/{name}/GET/responses/200/content/application\/json`. + case json(OpenAPIRuntime.OpenAPIValueContainer) + /// The associated value of the enum case if `self` is `.json`. + /// + /// - Throws: An error if `self` is not `.json`. + /// - SeeAlso: `.json`. + package var json: OpenAPIRuntime.OpenAPIValueContainer { + get throws { + switch self { case let .json(body): return body + } + } + } } + /// Received HTTP response body + package var body: Operations.getTunnel.Output.Ok.Body + /// Creates a new `Ok`. + /// + /// - Parameters: + /// - body: Received HTTP response body + package init(body: Operations.getTunnel.Output.Ok.Body) { self.body = body } + } + /// Successful response + /// + /// - Remark: Generated from `#/paths//api/tunnels/{name}/get(getTunnel)/responses/200`. + /// + /// HTTP response code: `200 ok`. + case ok(Operations.getTunnel.Output.Ok) + /// The associated value of the enum case if `self` is `.ok`. + /// + /// - Throws: An error if `self` is not `.ok`. + /// - SeeAlso: `.ok`. + package var ok: Operations.getTunnel.Output.Ok { + get throws { + switch self { case let .ok(response): return response default: + try throwUnexpectedResponseStatus(expectedStatus: "ok", response: self) + } + } + } + /// Undocumented response. + /// + /// A response with a code that is not documented in the OpenAPI document. + case undocumented(statusCode: Swift.Int, OpenAPIRuntime.UndocumentedPayload) } - /// Stop tunnel - /// - /// - Remark: HTTP `DELETE /api/tunnels/{name}`. - /// - Remark: Generated from `#/paths//api/tunnels/{name}/delete(stopTunnel)`. - package enum stopTunnel { - package static let id: Swift.String = "stopTunnel" - package struct Input: Sendable, Hashable { - /// - Remark: Generated from `#/paths/api/tunnels/{name}/DELETE/path`. - package struct Path: Sendable, Hashable { - /// - Remark: Generated from `#/paths/api/tunnels/{name}/DELETE/path/name`. - package var name: Swift.String - /// Creates a new `Path`. - /// - /// - Parameters: - /// - name: - package init(name: Swift.String) { - self.name = name - } - } - package var path: Operations.stopTunnel.Input.Path - /// Creates a new `Input`. - /// - /// - Parameters: - /// - path: - package init(path: Operations.stopTunnel.Input.Path) { - self.path = path - } + @frozen package enum AcceptableContentType: AcceptableProtocol { + case json + case other(Swift.String) + package init?(rawValue: Swift.String) { + switch rawValue.lowercased() { case "application/json": self = .json default: + self = .other(rawValue) } - @frozen package enum Output: Sendable, Hashable { - package struct NoContent: Sendable, Hashable { - /// Creates a new `NoContent`. - package init() {} - } - /// Tunnel stopped successfully - /// - /// - Remark: Generated from `#/paths//api/tunnels/{name}/delete(stopTunnel)/responses/204`. - /// - /// HTTP response code: `204 noContent`. - case noContent(Operations.stopTunnel.Output.NoContent) - /// The associated value of the enum case if `self` is `.noContent`. - /// - /// - Throws: An error if `self` is not `.noContent`. - /// - SeeAlso: `.noContent`. - package var noContent: Operations.stopTunnel.Output.NoContent { - get throws { - switch self { - case let .noContent(response): - return response - default: - try throwUnexpectedResponseStatus( - expectedStatus: "noContent", - response: self - ) - } - } - } - /// Undocumented response. - /// - /// A response with a code that is not documented in the OpenAPI document. - case undocumented(statusCode: Swift.Int, OpenAPIRuntime.UndocumentedPayload) + } + package var rawValue: Swift.String { + switch self { case let .other(string): return string case .json: return "application/json" + } + } + package static var allCases: [Self] { [.json] } + } + } + /// Stop tunnel + /// + /// - Remark: HTTP `DELETE /api/tunnels/{name}`. + /// - Remark: Generated from `#/paths//api/tunnels/{name}/delete(stopTunnel)`. + package enum stopTunnel { + package static let id: Swift.String = "stopTunnel" + package struct Input: Sendable, Hashable { + /// - Remark: Generated from `#/paths/api/tunnels/{name}/DELETE/path`. + package struct Path: Sendable, Hashable { + /// - Remark: Generated from `#/paths/api/tunnels/{name}/DELETE/path/name`. + package var name: Swift.String + /// Creates a new `Path`. + /// + /// - Parameters: + /// - name: + package init(name: Swift.String) { self.name = name } + } + package var path: Operations.stopTunnel.Input.Path + /// Creates a new `Input`. + /// + /// - Parameters: + /// - path: + package init(path: Operations.stopTunnel.Input.Path) { self.path = path } + } + @frozen package enum Output: Sendable, Hashable { + package struct NoContent: Sendable, Hashable { + /// Creates a new `NoContent`. + package init() {} + } + /// Tunnel stopped successfully + /// + /// - Remark: Generated from `#/paths//api/tunnels/{name}/delete(stopTunnel)/responses/204`. + /// + /// HTTP response code: `204 noContent`. + case noContent(Operations.stopTunnel.Output.NoContent) + /// The associated value of the enum case if `self` is `.noContent`. + /// + /// - Throws: An error if `self` is not `.noContent`. + /// - SeeAlso: `.noContent`. + package var noContent: Operations.stopTunnel.Output.NoContent { + get throws { + switch self { case let .noContent(response): return response default: + try throwUnexpectedResponseStatus(expectedStatus: "noContent", response: self) + } } + } + /// Undocumented response. + /// + /// A response with a code that is not documented in the OpenAPI document. + case undocumented(statusCode: Swift.Int, OpenAPIRuntime.UndocumentedPayload) } + } } diff --git a/Packages/Ngrokit/Sources/Ngrokit/FileHandle.swift b/Packages/Ngrokit/Sources/Ngrokit/FileHandle.swift index e904947..44bbf55 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/FileHandle.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/FileHandle.swift @@ -1,6 +1,6 @@ // // FileHandle.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -30,7 +30,7 @@ public import Foundation // swiftlint:disable:next force_try -private let ngrokCLIErrorRegex = try! NSRegularExpression(pattern: "ERR_NGROK_([0-9]+)") +fileprivate let ngrokCLIErrorRegex = try! NSRegularExpression(pattern: "ERR_NGROK_([0-9]+)") /// A protocol for handling data. public protocol DataHandle { @@ -49,24 +49,20 @@ extension DataHandle { /// - Returns: The parsed ngrok error code. /// - Throws: An error if there was a problem parsing the error code. internal func parseNgrokErrorCode() throws -> NgrokError { - guard let data = try readToEnd() else { - throw RuntimeError.unknownError - } + guard let data = try readToEnd() else { throw RuntimeError.unknownError } let text = String(decoding: data, as: UTF8.self) - guard let match = ngrokCLIErrorRegex.firstMatch( - in: text, - range: .init(location: 0, length: text.count) - ), match.numberOfRanges > 0 else { - throw RuntimeError.unknownEarlyTermination(text) - } + guard + let match = ngrokCLIErrorRegex.firstMatch( + in: text, + range: .init(location: 0, length: text.count) + ), match.numberOfRanges > 0 + else { throw RuntimeError.unknownEarlyTermination(text) } guard let range = Range(match.range(at: 1), in: text) else { throw RuntimeError.unknownEarlyTermination(text) } - guard let code = Int(text[range]) else { - throw RuntimeError.unknownEarlyTermination(text) - } + guard let code = Int(text[range]) else { throw RuntimeError.unknownEarlyTermination(text) } guard let error = NgrokError(rawValue: code) else { throw RuntimeError.unknownNgrokErrorCode(code) } diff --git a/Packages/Ngrokit/Sources/Ngrokit/NgrokCLIAPI.swift b/Packages/Ngrokit/Sources/Ngrokit/NgrokCLIAPI.swift index dde9d32..6a16af0 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/NgrokCLIAPI.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/NgrokCLIAPI.swift @@ -1,6 +1,6 @@ // // NgrokCLIAPI.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/Ngrokit/Sources/Ngrokit/NgrokClient.swift b/Packages/Ngrokit/Sources/Ngrokit/NgrokClient.swift index 2491d27..cbfca92 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/NgrokClient.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/NgrokClient.swift @@ -1,6 +1,6 @@ // // NgrokClient.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -74,13 +74,8 @@ public struct NgrokClient: Sendable { self.init(underlyingClient: underlyingClient) } - internal init(underlyingClient: any APIProtocol) { - self.underlyingClient = underlyingClient - } - - public func status() async throws { - _ = try await self.underlyingClient.get_sol_api().ok - } + internal init(underlyingClient: any APIProtocol) { self.underlyingClient = underlyingClient } + public func status() async throws { _ = try await self.underlyingClient.get_sol_api().ok } /// Starts a new tunnel. /// @@ -92,11 +87,8 @@ public struct NgrokClient: Sendable { public func startTunnel(_ request: TunnelRequest) async throws -> NgrokTunnel { let tunnelRequest: Components.Schemas.TunnelRequest tunnelRequest = .init(request: request) - let response = try await underlyingClient.startTunnel( - .init( - body: .json(tunnelRequest) - ) - ).created.body.json + let response = try await underlyingClient.startTunnel(.init(body: .json(tunnelRequest))).created + .body.json let tunnel: NgrokTunnel = try .init(response: response) return tunnel } @@ -116,9 +108,6 @@ public struct NgrokClient: Sendable { /// /// - Throws: An error if the tunnel listing fails. public func listTunnels() async throws -> [NgrokTunnel] { - try await underlyingClient - .listTunnels() - .ok.body.json.tunnels - .map(NgrokTunnel.init(response:)) + try await underlyingClient.listTunnels().ok.body.json.tunnels.map(NgrokTunnel.init(response:)) } } diff --git a/Packages/Ngrokit/Sources/Ngrokit/NgrokError.swift b/Packages/Ngrokit/Sources/Ngrokit/NgrokError.swift index 54ae124..4ec9144 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/NgrokError.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/NgrokError.swift @@ -1,6 +1,6 @@ // // NgrokError.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -27,7 +27,7 @@ // OTHER DEALINGS IN THE SOFTWARE. // -import Foundation +public import Foundation // swiftlint:disable line_length @@ -69,40 +69,32 @@ public enum NgrokError: Int, LocalizedError { case tunnelConnectionFailed = 8_012 public var errorDescription: String? { - switch self { - case .invalidMetadataLength: - "Invalid metadata length" - case .accountLimitExceeded: + switch self { case .invalidMetadataLength: "Invalid metadata length" case .accountLimitExceeded: "You've hit your account limit for simultaneous ngrok agent sessions. Try stopping an existing agent or upgrading your account." - case .unsupportedAgentVersion: - "Your ngrok agent version is no longer supported. Only the most recent version of the ngrok agent is supported without an account. Update to a newer version with ngrok update or by downloading from https://ngrok.com/download. Sign up for an account to avoid forced version upgrades: https://ngrok.com/signup." - case .captchaFailed: - "You failed to solve the captcha, please try again." - case .accountViolation: - "You are disallowed from creating an ngrok account due to violation of the terms of service." - case .gatewayError: - "Ngrok gateway error. The server returned an invalid or incomplete HTTP response. Try starting ngrok with the full upstream service URL (e.g. ngrok http https://localhost:8081)" - case .tunnelNotFound: - "Tunnel not found. This could be because your agent is not online or your tunnel has been flagged by our automated moderation system." - case .accountBanned: - "The account associated with this hostname has been banned. We've determined this account to be in violation of ngrok's terms of service. If you are the account owner and believe this is a mistake, please contact support@ngrok.com." - case .passwordTooShort: - "Your password must be at least 10 characters." - case .accountCreationNotAllowed: - "You may not create a new account because you are already a member of a free account. Upgrade or delete that account first before creating a new account." - case .invalidCredentials: - "The email or password you entered is not valid." - case .userAlreadyExists: - "A user with the email address already exists." - case .disallowedEmailProvider: - "Sign-ups are disallowed for the email provider. Please sign up with a different email provider." - case .htmlContentSignupRequired: - "Before you can serve HTML content, you must sign up for an ngrok account and install your authtoken." - case .websiteVisitWarning: - "You are about to visit HOSTPORT, served by SERVINGIP. This website is served for free through ngrok.com. You should only visit this website if you trust whoever sent the link to you." - case .tunnelConnectionFailed: - "Traffic was successfully tunneled to the ngrok agent, but the agent failed to establish a connection to the upstream web service" + case .unsupportedAgentVersion: + "Your ngrok agent version is no longer supported. Only the most recent version of the ngrok agent is supported without an account. Update to a newer version with ngrok update or by downloading from https://ngrok.com/download. Sign up for an account to avoid forced version upgrades: https://ngrok.com/signup." + case .captchaFailed: "You failed to solve the captcha, please try again." + case .accountViolation: + "You are disallowed from creating an ngrok account due to violation of the terms of service." + case .gatewayError: + "Ngrok gateway error. The server returned an invalid or incomplete HTTP response. Try starting ngrok with the full upstream service URL (e.g. ngrok http https://localhost:8081)" + case .tunnelNotFound: + "Tunnel not found. This could be because your agent is not online or your tunnel has been flagged by our automated moderation system." + case .accountBanned: + "The account associated with this hostname has been banned. We've determined this account to be in violation of ngrok's terms of service. If you are the account owner and believe this is a mistake, please contact support@ngrok.com." + case .passwordTooShort: "Your password must be at least 10 characters." + case .accountCreationNotAllowed: + "You may not create a new account because you are already a member of a free account. Upgrade or delete that account first before creating a new account." + case .invalidCredentials: "The email or password you entered is not valid." + case .userAlreadyExists: "A user with the email address already exists." + case .disallowedEmailProvider: + "Sign-ups are disallowed for the email provider. Please sign up with a different email provider." + case .htmlContentSignupRequired: + "Before you can serve HTML content, you must sign up for an ngrok account and install your authtoken." + case .websiteVisitWarning: + "You are about to visit HOSTPORT, served by SERVINGIP. This website is served for free through ngrok.com. You should only visit this website if you trust whoever sent the link to you." + case .tunnelConnectionFailed: + "Traffic was successfully tunneled to the ngrok agent, but the agent failed to establish a connection to the upstream web service" } - } - // swiftlint:enable line_length + } // swiftlint:enable line_length } diff --git a/Packages/Ngrokit/Sources/Ngrokit/NgrokMacProcess.swift b/Packages/Ngrokit/Sources/Ngrokit/NgrokMacProcess.swift index 428a28e..cb75f7e 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/NgrokMacProcess.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/NgrokMacProcess.swift @@ -1,6 +1,6 @@ // // NgrokMacProcess.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -43,7 +43,6 @@ import Foundation /// - SeeAlso: `NgrokProcess` public actor NgrokMacProcess: NgrokProcess { - private var terminationHandler: (@Sendable (any Error) -> Void)? internal let process: ProcessType private let pipe: ProcessType.PipeType @@ -56,18 +55,8 @@ public actor NgrokMacProcess: NgrokProcess { /// - processType: The type of process to use. /// /// - Returns: A new instance of `NgrokMacProcess`. - public init( - ngrokPath: String, - httpPort: Int, - processType _: ProcessType.Type - ) { - self.init( - process: .init( - executableFilePath: ngrokPath, - scheme: "http", - port: httpPort - ) - ) + public init(ngrokPath: String, httpPort: Int, processType _: ProcessType.Type) { + self.init(process: .init(executableFilePath: ngrokPath, scheme: "http", port: httpPort)) } private init( @@ -79,7 +68,8 @@ public actor NgrokMacProcess: NgrokProcess { self.process = process if let pipe { self.pipe = pipe - } else { + } + else { let newPipe: ProcessType.PipeType = process.createPipe() self.process.standardError = newPipe self.pipe = newPipe @@ -90,15 +80,11 @@ public actor NgrokMacProcess: NgrokProcess { /// /// - Parameters: /// - forProcess: The process that has terminated. - @Sendable - private nonisolated func terminationHandler(forProcess _: any Processable) { + @Sendable private nonisolated func terminationHandler(forProcess _: any Processable) { Task { let error: any Error - do { - error = try self.pipe.fileHandleForReading.parseNgrokErrorCode() - } catch let runtimeError as RuntimeError { - error = runtimeError - } + do { error = try self.pipe.fileHandleForReading.parseNgrokErrorCode() } + catch let runtimeError as RuntimeError { error = runtimeError } await self.terminationHandler?(error) } } @@ -114,8 +100,5 @@ public actor NgrokMacProcess: NgrokProcess { terminationHandler = onError try process.run() } - - nonisolated public func terminate() { - self.process.terminate() - } + nonisolated public func terminate() { self.process.terminate() } } diff --git a/Packages/Ngrokit/Sources/Ngrokit/NgrokProcess.swift b/Packages/Ngrokit/Sources/Ngrokit/NgrokProcess.swift index 3624bc2..7e209fe 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/NgrokProcess.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/NgrokProcess.swift @@ -1,6 +1,6 @@ // // NgrokProcess.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -44,6 +44,5 @@ public protocol NgrokProcess: Sendable { /// /// - Parameter onError: A closure to handle any errors that occur during the process. func run(onError: @Sendable @escaping (any Error) -> Void) async throws - - func terminate () + func terminate() } diff --git a/Packages/Ngrokit/Sources/Ngrokit/NgrokProcessCLIAPI.swift b/Packages/Ngrokit/Sources/Ngrokit/NgrokProcessCLIAPI.swift index 6d73a14..2e5b65e 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/NgrokProcessCLIAPI.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/NgrokProcessCLIAPI.swift @@ -1,6 +1,6 @@ // // NgrokProcessCLIAPI.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -46,9 +46,7 @@ public struct NgrokProcessCLIAPI { /// Initializes a new instance of `NgrokProcessCLIAPI`. /// /// - Parameter ngrokPath: The path to the Ngrok executable. - public init(ngrokPath: String) { - self.ngrokPath = ngrokPath - } + public init(ngrokPath: String) { self.ngrokPath = ngrokPath } } extension NgrokProcessCLIAPI: NgrokCLIAPI { @@ -58,10 +56,6 @@ extension NgrokProcessCLIAPI: NgrokCLIAPI { /// /// - Returns: An instance of `NgrokProcess` for the specified HTTP port. public func process(forHTTPPort httpPort: Int) -> any NgrokProcess { - NgrokMacProcess( - ngrokPath: ngrokPath, - httpPort: httpPort, - processType: ProcessType.self - ) + NgrokMacProcess(ngrokPath: ngrokPath, httpPort: httpPort, processType: ProcessType.self) } } diff --git a/Packages/Ngrokit/Sources/Ngrokit/NgrokTunnel.swift b/Packages/Ngrokit/Sources/Ngrokit/NgrokTunnel.swift index dd36924..f883e8c 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/NgrokTunnel.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/NgrokTunnel.swift @@ -1,6 +1,6 @@ // // NgrokTunnel.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -97,10 +97,7 @@ extension NgrokTunnel { self.init( name: response.name, publicURL: publicURL, - config: .init( - addr: addr, - inspect: response.config.inspect - ) + config: .init(addr: addr, inspect: response.config.inspect) ) } } diff --git a/Packages/Ngrokit/Sources/Ngrokit/NgrokTunnelConfiguration.swift b/Packages/Ngrokit/Sources/Ngrokit/NgrokTunnelConfiguration.swift index f17590b..79a04c6 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/NgrokTunnelConfiguration.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/NgrokTunnelConfiguration.swift @@ -1,6 +1,6 @@ // // NgrokTunnelConfiguration.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/Ngrokit/Sources/Ngrokit/Pipable.swift b/Packages/Ngrokit/Sources/Ngrokit/Pipable.swift index c745b58..1ab6780 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/Pipable.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/Pipable.swift @@ -1,6 +1,6 @@ // // Pipable.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/Ngrokit/Sources/Ngrokit/Processable.swift b/Packages/Ngrokit/Sources/Ngrokit/Processable.swift index cb4985e..eb7fda2 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/Processable.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/Processable.swift @@ -1,6 +1,6 @@ // // Processable.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -100,6 +100,5 @@ public protocol Processable: Sendable, AnyObject { /// /// - Requires: This method must be implemented. func run() throws - - func terminate () + func terminate() } diff --git a/Packages/Ngrokit/Sources/Ngrokit/ProcessableProcess.swift b/Packages/Ngrokit/Sources/Ngrokit/ProcessableProcess.swift index 27651fc..c59ab46 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/ProcessableProcess.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/ProcessableProcess.swift @@ -1,6 +1,6 @@ // // ProcessableProcess.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -39,31 +39,22 @@ public import Foundation /// property before executing the process. /// /// - SeeAlso: `Processable` -public final class ProcessableProcess: Processable { + public final class ProcessableProcess: Processable { - /// The type of pipe used for standard error. public typealias PipeType = Pipe private let process: Process - public var terminationReason: TerminationReason { - process.terminationReason - } + public var terminationReason: TerminationReason { process.terminationReason } /// The pipe used for standard error. public var standardError: Pipe? { - get { - process.standardError as? Pipe - } - set { - process.standardError = newValue - } + get { process.standardError as? Pipe } + set { process.standardError = newValue } } - private init(process: Process) { - self.process = process - } + private init(process: Process) { self.process = process } /// Initializes a new `ProcessableProcess` instance. /// @@ -84,9 +75,7 @@ public final class ProcessableProcess: Processable { /// Sets the termination handler closure for the process. /// /// - Parameter closure: The closure to be called when the process terminates. - public func setTerminationHandler( - _ closure: @escaping @Sendable (ProcessableProcess) -> Void - ) { + public func setTerminationHandler(_ closure: @escaping @Sendable (ProcessableProcess) -> Void) { process.terminationHandler = { process in assert(process == self.process) closure(self) @@ -96,17 +85,10 @@ public final class ProcessableProcess: Processable { /// Creates a new pipe. /// /// - Returns: A new `Pipe` instance. - public func createPipe() -> Pipe { - Pipe() - } + public func createPipe() -> Pipe { Pipe() } - public func run() throws { - try process.run() - } - - public func terminate() { - process.terminate() - } + public func run() throws { try process.run() } + public func terminate() { process.terminate() } } extension Pipe: Pipable {} diff --git a/Packages/Ngrokit/Sources/Ngrokit/RuntimeError.swift b/Packages/Ngrokit/Sources/Ngrokit/RuntimeError.swift index 0cd9ba8..e2b88a1 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/RuntimeError.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/RuntimeError.swift @@ -1,6 +1,6 @@ // // RuntimeError.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/Ngrokit/Sources/Ngrokit/TerminationReason.swift b/Packages/Ngrokit/Sources/Ngrokit/TerminationReason.swift index eaf850a..74f5e59 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/TerminationReason.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/TerminationReason.swift @@ -1,6 +1,6 @@ // // TerminationReason.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -27,14 +27,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // -public import Foundation + // swiftlint:disable file_types_order #if os(macOS) + public import Foundation /// Represents the reason for the termination of a process. public typealias TerminationReason = Process.TerminationReason #else - /// Represents the reason for the termination of a process. /// /// - exit: The process exited normally. @@ -43,5 +43,4 @@ public import Foundation case exit = 1 case uncaughtSignal = 2 } -#endif -// swiftlint:enable file_types_order +#endif // swiftlint:enable file_types_order diff --git a/Packages/Ngrokit/Sources/Ngrokit/TunnelRequest.swift b/Packages/Ngrokit/Sources/Ngrokit/TunnelRequest.swift index 1255f11..69fc4ee 100644 --- a/Packages/Ngrokit/Sources/Ngrokit/TunnelRequest.swift +++ b/Packages/Ngrokit/Sources/Ngrokit/TunnelRequest.swift @@ -1,6 +1,6 @@ // // TunnelRequest.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/Ngrokit/Sources/NgrokitMocks/MockAPI.swift b/Packages/Ngrokit/Sources/NgrokitMocks/MockAPI.swift index ad6dde1..d5da344 100644 --- a/Packages/Ngrokit/Sources/NgrokitMocks/MockAPI.swift +++ b/Packages/Ngrokit/Sources/NgrokitMocks/MockAPI.swift @@ -1,6 +1,6 @@ // // MockAPI.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -55,37 +55,32 @@ package final actor MockAPI: APIProtocol { } // swiftlint:disable unavailable_function force_unwrapping - package func getTunnel( - _: NgrokOpenAPIClient.Operations.getTunnel.Input - ) async throws -> NgrokOpenAPIClient.Operations.getTunnel.Output { - fatalError("not implemented") - } + package func getTunnel(_: NgrokOpenAPIClient.Operations.getTunnel.Input) async throws + -> NgrokOpenAPIClient.Operations.getTunnel.Output + { fatalError("not implemented") } - package func stopTunnel( - _ input: Operations.stopTunnel.Input - ) async throws -> Operations.stopTunnel.Output { + package func stopTunnel(_ input: Operations.stopTunnel.Input) async throws + -> Operations.stopTunnel.Output + { stopTunnelPassed.append(input) return try actualStopTunnelResult!.get() } - package func startTunnel( - _ input: Operations.startTunnel.Input - ) async throws -> Operations.startTunnel.Output { + package func startTunnel(_ input: Operations.startTunnel.Input) async throws + -> Operations.startTunnel.Output + { startTunnelPassed.append(input) return try actualStartTunnelResult!.get() } - package func listTunnels( - _ input: NgrokOpenAPIClient.Operations.listTunnels.Input - ) async throws -> NgrokOpenAPIClient.Operations.listTunnels.Output { + package func listTunnels(_ input: NgrokOpenAPIClient.Operations.listTunnels.Input) async throws + -> NgrokOpenAPIClient.Operations.listTunnels.Output + { listTunnelPassed.append(input) return try actualListTunnelResult!.get() } - package func get_sol_api( - _: NgrokOpenAPIClient.Operations.get_sol_api.Input - ) async throws -> NgrokOpenAPIClient.Operations.get_sol_api.Output { - fatalError("not implemented") - } - // swiftlint:enable unavailable_function force_unwrapping + package func get_sol_api(_: NgrokOpenAPIClient.Operations.get_sol_api.Input) async throws + -> NgrokOpenAPIClient.Operations.get_sol_api.Output + { fatalError("not implemented") } // swiftlint:enable unavailable_function force_unwrapping } diff --git a/Packages/Ngrokit/Sources/NgrokitMocks/MockDataHandle.swift b/Packages/Ngrokit/Sources/NgrokitMocks/MockDataHandle.swift index a033a7d..9087367 100644 --- a/Packages/Ngrokit/Sources/NgrokitMocks/MockDataHandle.swift +++ b/Packages/Ngrokit/Sources/NgrokitMocks/MockDataHandle.swift @@ -1,6 +1,6 @@ // // MockDataHandle.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -27,33 +27,30 @@ // OTHER DEALINGS IN THE SOFTWARE. // -package import Foundation -import Ngrokit +public import Foundation +public import Ngrokit -package struct MockDataHandle: DataHandle { - package static let code: Data = .init(""" - ERROR: authentication failed: Your account is limited to 1 simultaneous ngrok agent session. - ERROR: You can run multiple tunnels on a single agent session using a configuration file. - ERROR: To learn more, see https://ngrok.com/docs/secure-tunnels/ngrok-agent/reference/config/ - ERROR: - ERROR: Active ngrok agent sessions in region 'us': - ERROR: - ts_2bjiyVxWh6dMoaZUfjXNsHWFNta (2607:fb90:8da8:5b15:900b:13fd:c5e7:f9c6) - ERROR: - ERROR: ERR_NGROK_108 - ERROR: - """.utf8) +public struct MockDataHandle: DataHandle, Sendable { + package static let code: Data = .init( + """ + ERROR: authentication failed: Your account is limited to 1 simultaneous ngrok agent session. + ERROR: You can run multiple tunnels on a single agent session using a configuration file. + ERROR: To learn more, see https://ngrok.com/docs/secure-tunnels/ngrok-agent/reference/config/ + ERROR: + ERROR: Active ngrok agent sessions in region 'us': + ERROR: - ts_2bjiyVxWh6dMoaZUfjXNsHWFNta (2607:fb90:8da8:5b15:900b:13fd:c5e7:f9c6) + ERROR: + ERROR: ERR_NGROK_108 + ERROR: + """ + .utf8 + ) private let actualResult: Result - package init(_ actualResult: Result) { - self.actualResult = actualResult - } + package init(_ actualResult: Result) { self.actualResult = actualResult } - package static func withNgrokCode() -> MockDataHandle { - .init(.success(code)) - } + package static func withNgrokCode() -> MockDataHandle { .init(.success(code)) } - package func readToEnd() throws -> Data? { - try actualResult.get() - } + public func readToEnd() throws -> Data? { try actualResult.get() } } diff --git a/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokCLIAPI.swift b/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokCLIAPI.swift index b66212e..aa6cb81 100644 --- a/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokCLIAPI.swift +++ b/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokCLIAPI.swift @@ -1,6 +1,6 @@ // // MockNgrokCLIAPI.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -28,21 +28,15 @@ // public import Foundation -package import Ngrokit +public import Ngrokit -public final class MockNgrokCLIAPI: NgrokCLIAPI { +public final actor MockNgrokCLIAPI: NgrokCLIAPI { package let process: any NgrokProcess package private(set) var httpPorts = [Int]() - public convenience init(id: UUID) { - self.init(process: MockNgrokProcess(id: id)) - } + public init(id: UUID) { self.init(process: MockNgrokProcess(id: id)) } - internal init(process: any NgrokProcess) { - self.process = process - } + internal init(process: any NgrokProcess) { self.process = process } - package func process(forHTTPPort _: Int) -> any Ngrokit.NgrokProcess { - process - } + public nonisolated func process(forHTTPPort _: Int) -> any Ngrokit.NgrokProcess { process } } diff --git a/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokProcess.swift b/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokProcess.swift index 292b63d..a1ae3c0 100644 --- a/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokProcess.swift +++ b/Packages/Ngrokit/Sources/NgrokitMocks/MockNgrokProcess.swift @@ -1,6 +1,6 @@ // // MockNgrokProcess.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -28,18 +28,13 @@ // public import Foundation -import Ngrokit +public import Ngrokit public final class MockNgrokProcess: NgrokProcess { - public func terminate() { - - } - + public func terminate() {} public let id: UUID - public init(id: UUID) { - self.id = id - } + public init(id: UUID) { self.id = id } public func run(onError _: @escaping @Sendable (any Error) -> Void) async throws {} } diff --git a/Packages/Ngrokit/Sources/NgrokitMocks/MockPipe.swift b/Packages/Ngrokit/Sources/NgrokitMocks/MockPipe.swift index da7186d..986bf85 100644 --- a/Packages/Ngrokit/Sources/NgrokitMocks/MockPipe.swift +++ b/Packages/Ngrokit/Sources/NgrokitMocks/MockPipe.swift @@ -1,6 +1,6 @@ // // MockPipe.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -28,12 +28,12 @@ // import Foundation -import Ngrokit +public import Ngrokit -package final class MockPipe: Pipable { - package typealias DataHandleType = MockDataHandle +public final class MockPipe: Pipable { + public typealias DataHandleType = MockDataHandle - package let fileHandleForReading: MockDataHandle + public let fileHandleForReading: MockDataHandle internal init(fileHandleForReading: MockDataHandle) { self.fileHandleForReading = fileHandleForReading diff --git a/Packages/Ngrokit/Sources/NgrokitMocks/MockProcess.swift b/Packages/Ngrokit/Sources/NgrokitMocks/MockProcess.swift index 00eb34c..280b022 100644 --- a/Packages/Ngrokit/Sources/NgrokitMocks/MockProcess.swift +++ b/Packages/Ngrokit/Sources/NgrokitMocks/MockProcess.swift @@ -1,6 +1,6 @@ // // MockProcess.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -27,26 +27,23 @@ // OTHER DEALINGS IN THE SOFTWARE. // -package import Foundation -package import Ngrokit +public import Foundation +public import Ngrokit public final class MockProcess: Processable { - package func terminate() { - - } - - package typealias PipeType = MockPipe + public func terminate() {} + public typealias PipeType = MockPipe package let executableFilePath: String package let scheme: String package let port: Int package let pipeDataResult: Result package let runError: (any Error)? - package let terminationReason: Ngrokit.TerminationReason - package var standardError: MockPipe? + public let terminationReason: Ngrokit.TerminationReason + public nonisolated(unsafe) var standardError: MockPipe? - package private(set) var isTerminationHandlerSet = false - package private(set) var isRunCalled = false + package private(set) nonisolated(unsafe) var isTerminationHandlerSet = false + package private(set) nonisolated(unsafe) var isRunCalled = false internal init( executableFilePath: String, @@ -66,11 +63,7 @@ public final class MockProcess: Processable { self.runError = runError } - package convenience init( - executableFilePath: String, - scheme: String, - port: Int - ) { + public convenience init(executableFilePath: String, scheme: String, port: Int) { self.init( executableFilePath: executableFilePath, scheme: scheme, @@ -79,18 +72,16 @@ public final class MockProcess: Processable { ) } - package nonisolated func createPipe() -> MockPipe { + public nonisolated func createPipe() -> MockPipe { .init(fileHandleForReading: .init(pipeDataResult)) } - package func setTerminationHandler(_: @escaping @Sendable (MockProcess) -> Void) { + public func setTerminationHandler(_: @escaping @Sendable (MockProcess) -> Void) { isTerminationHandlerSet = true } - package func run() throws { + public func run() throws { isRunCalled = true - if let error = runError { - throw error - } + if let error = runError { throw error } } } diff --git a/Packages/Ngrokit/Sources/NgrokitMocks/URL.swift b/Packages/Ngrokit/Sources/NgrokitMocks/URL.swift index bebc1f1..5bc013a 100644 --- a/Packages/Ngrokit/Sources/NgrokitMocks/URL.swift +++ b/Packages/Ngrokit/Sources/NgrokitMocks/URL.swift @@ -1,6 +1,6 @@ // // URL.swift -// Sublimation +// Ngrokit // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -30,11 +30,9 @@ package import Foundation #if canImport(FoundationNetworking) -package import FoundationNetworking + package import FoundationNetworking #endif extension URL { - package static func temporaryDirectory() -> URL { - URL(fileURLWithPath: NSTemporaryDirectory()) - } + package static func temporaryDirectory() -> URL { URL(fileURLWithPath: NSTemporaryDirectory()) } } diff --git a/Packages/SublimationBonjour/Scripts/lint.sh b/Packages/SublimationBonjour/Scripts/lint.sh index e8b0009..65560e4 100755 --- a/Packages/SublimationBonjour/Scripts/lint.sh +++ b/Packages/SublimationBonjour/Scripts/lint.sh @@ -13,10 +13,10 @@ MINT_RUN="/opt/homebrew/bin/mint run $MINT_ARGS" if [ -z "$SRCROOT" ]; then SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) PACKAGE_DIR="${SCRIPT_DIR}/.." - PERIPHERY_OPTIONS="--skip-build" -else - PACKAGE_DIR="${SRCROOT}" PERIPHERY_OPTIONS="" +else + PACKAGE_DIR="${SRCROOT}" + PERIPHERY_OPTIONS="--skip-build" fi @@ -32,6 +32,10 @@ fi echo "LINT Mode is $LINT_MODE" +if [ "$LINT_MODE" == "INSTALL" ]; then + exit +fi + if [ -z "$CI" ]; then $MINT_RUN swift-format format --recursive --parallel --in-place $PACKAGE_DIR/Sources else diff --git a/Packages/SublimationBonjour/Sources/SublimationBonjour/BindingConfiguration+Protobuf.swift b/Packages/SublimationBonjour/Sources/SublimationBonjour/BindingConfiguration+Protobuf.swift index 1f5600d..a6c49dd 100644 --- a/Packages/SublimationBonjour/Sources/SublimationBonjour/BindingConfiguration+Protobuf.swift +++ b/Packages/SublimationBonjour/Sources/SublimationBonjour/BindingConfiguration+Protobuf.swift @@ -1,5 +1,5 @@ // -// ServerConfiguration.pb.swift +// BindingConfiguration+Protobuf.swift // SublimationBonjour // // Created by Leo Dion. diff --git a/Packages/SublimationBonjour/Sources/SublimationBonjour/Client/BindingConfiguration+URL.swift b/Packages/SublimationBonjour/Sources/SublimationBonjour/Client/BindingConfiguration+URL.swift index 831a948..faacace 100644 --- a/Packages/SublimationBonjour/Sources/SublimationBonjour/Client/BindingConfiguration+URL.swift +++ b/Packages/SublimationBonjour/Sources/SublimationBonjour/Client/BindingConfiguration+URL.swift @@ -1,5 +1,5 @@ // -// BindingConfiguration.swift +// BindingConfiguration+URL.swift // SublimationBonjour // // Created by Leo Dion. @@ -34,7 +34,7 @@ internal import Network extension BindingConfiguration { - internal func urls(defaults : URLDefaultConfiguration) -> [URL] { + internal func urls(defaults: URLDefaultConfiguration) -> [URL] { let isSecure = self.hasIsSecure ? self.isSecure : defaults.isSecure let port = self.hasPort ? Int(self.port) : defaults.port return self.hosts.compactMap { host in diff --git a/Packages/SublimationBonjour/Sources/SublimationBonjour/Client/BonjourClient.swift b/Packages/SublimationBonjour/Sources/SublimationBonjour/Client/BonjourClient.swift index 9546ae3..3413f82 100644 --- a/Packages/SublimationBonjour/Sources/SublimationBonjour/Client/BonjourClient.swift +++ b/Packages/SublimationBonjour/Sources/SublimationBonjour/Client/BonjourClient.swift @@ -38,15 +38,14 @@ public import Logging #endif -public struct URLDefaultConfiguration { - public init(isSecure: Bool = false, port: Int = 8080) { - self.isSecure = isSecure - self.port = port + public struct URLDefaultConfiguration { + public init(isSecure: Bool = false, port: Int = 8080) { + self.isSecure = isSecure + self.port = port + } + public let isSecure: Bool + public let port: Int } - - public let isSecure: Bool - public let port: Int -} public actor BonjourClient { private let browser: NWBrowser @@ -74,12 +73,10 @@ public struct URLDefaultConfiguration { } } - public init(logger: Logger? = nil, defaultURLConfiguration : URLDefaultConfiguration = .init()) { - + public init(logger: Logger? = nil, defaultURLConfiguration: URLDefaultConfiguration = .init()) { assert(logger != nil) let descriptor: NWBrowser.Descriptor - - descriptor = .bonjourWithTXTRecord(type: "_sublimation._tcp", domain: nil) + descriptor = .bonjourWithTXTRecord(type: "_sublimation._tcp", domain: nil) let browser = NWBrowser(for: descriptor, using: .tcp) self.defaultURLConfiguration = defaultURLConfiguration @@ -111,7 +108,6 @@ public struct URLDefaultConfiguration { case indexMismatch(Int) case base64Decoding } - private static func bindingConfiguration(txtRecordDictionary: [String: String]) throws -> BindingConfiguration { diff --git a/Packages/SublimationNgrok/Scripts/lint.sh b/Packages/SublimationNgrok/Scripts/lint.sh index 0ccd97b..0bace07 100755 --- a/Packages/SublimationNgrok/Scripts/lint.sh +++ b/Packages/SublimationNgrok/Scripts/lint.sh @@ -13,10 +13,10 @@ MINT_RUN="/opt/homebrew/bin/mint run $MINT_ARGS" if [ -z "$SRCROOT" ]; then SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) PACKAGE_DIR="${SCRIPT_DIR}/.." - PERIPHERY_OPTIONS="--skip-build" -else - PACKAGE_DIR="${SRCROOT}" PERIPHERY_OPTIONS="" +else + PACKAGE_DIR="${SRCROOT}" + PERIPHERY_OPTIONS="--skip-build" fi @@ -32,6 +32,10 @@ fi echo "LINT Mode is $LINT_MODE" +if [ "$LINT_MODE" == "INSTALL" ]; then + exit +fi + if [ -z "$CI" ]; then $MINT_RUN swift-format format --recursive --parallel --in-place $PACKAGE_DIR/Sources else diff --git a/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdb.swift b/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdb.swift index e7c37dc..e32e2dd 100644 --- a/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdb.swift +++ b/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdb.swift @@ -1,6 +1,6 @@ // // KVdb.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -74,32 +74,29 @@ public enum KVdb { forKey key: some Any, atBucket bucketName: String ) -> URLType { - URLType( - kvDBBase: baseString, - keyBucketPath: path(forKey: key, atBucket: bucketName) - ) + URLType(kvDBBase: baseString, keyBucketPath: path(forKey: key, atBucket: bucketName)) } -// /// Retrieves the URL for a given key in a bucket. -// /// -// /// - Parameters: -// /// - key: The key for the value. -// /// - bucketName: The name of the bucket. -// /// - session: The URLSession to use for the request. Defaults to `.ephemeral`. -// /// -// /// - Returns: The URL for the key, or `nil` if it doesn't exist. -// /// -// /// - Throws: An error if the request fails. -// @available(*, deprecated) -// public static func url( -// withKey key: Key, -// atBucket bucketName: String, -// using session: URLSession = .ephemeral() -// ) async throws -> URL? { -// let repository = KVdbTunnelRepository( -// client: URLSessionClient(session: session), -// bucketName: bucketName -// ) -// return try await repository.tunnel(forKey: key) -// } + // /// Retrieves the URL for a given key in a bucket. + // /// + // /// - Parameters: + // /// - key: The key for the value. + // /// - bucketName: The name of the bucket. + // /// - session: The URLSession to use for the request. Defaults to `.ephemeral`. + // /// + // /// - Returns: The URL for the key, or `nil` if it doesn't exist. + // /// + // /// - Throws: An error if the request fails. + // @available(*, deprecated) + // public static func url( + // withKey key: Key, + // atBucket bucketName: String, + // using session: URLSession = .ephemeral() + // ) async throws -> URL? { + // let repository = KVdbTunnelRepository( + // client: URLSessionClient(session: session), + // bucketName: bucketName + // ) + // return try await repository.tunnel(forKey: key) + // } } diff --git a/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbServerError.swift b/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbServerError.swift index 634bd50..eb649bb 100644 --- a/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbServerError.swift +++ b/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbServerError.swift @@ -1,6 +1,6 @@ // // KVdbServerError.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -37,8 +37,8 @@ public import Foundation /// - invalidURL: The URL is invalid. /// - cantSaveTunnel: Unable to save the tunnel with the given ID and data. public enum KVdbServerError: Error { -// case clientNotSetup -// case noTunnelFound + // case clientNotSetup + // case noTunnelFound case invalidURL case cantSaveTunnel(Int?, Data?) case cantSaveTunnelError(any Error) diff --git a/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbTunnelClient 2.swift b/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbTunnelClient 2.swift index 5b725d6..10ad281 100644 --- a/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbTunnelClient 2.swift +++ b/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbTunnelClient 2.swift @@ -1,6 +1,6 @@ // // KVdbTunnelClient 2.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbTunnelClient.swift b/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbTunnelClient.swift index 700b993..cda71b1 100644 --- a/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbTunnelClient.swift +++ b/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbTunnelClient.swift @@ -1,6 +1,6 @@ // // KVdbTunnelClient.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -65,19 +65,12 @@ public struct KVdbTunnelClient: Sendable { /// - Throws: `NgrokServerError.invalidURL` if the retrieved URL is invalid. /// /// - Returns: The URL associated with the key in the specified bucket. - public func getValue( - ofKey key: Key, - fromBucket bucketName: String - ) async throws -> URL { + public func getValue(ofKey key: Key, fromBucket bucketName: String) async throws -> URL { let uri = KVdb.construct(URL.self, forKey: key, atBucket: bucketName) let url: URL? - url = try await get(uri) - .map { String(decoding: $0, as: UTF8.self) } - .flatMap(URL.init(string:)) + url = try await get(uri).map { String(decoding: $0, as: UTF8.self) }.flatMap(URL.init(string:)) - guard let url else { - throw KVdbServerError.invalidURL - } + guard let url else { throw KVdbServerError.invalidURL } return url } @@ -88,16 +81,9 @@ public struct KVdbTunnelClient: Sendable { /// - Parameter bucketName: The name of the bucket where the value will be stored. /// /// - Throws: `NgrokServerError.cantSaveTunnel` if the tunnel cannot be saved. - public func saveValue( - _ value: URL, - withKey key: Key, - inBucket bucketName: String - ) async throws { + public func saveValue(_ value: URL, withKey key: Key, inBucket bucketName: String) async throws { let uri = KVdb.construct(URL.self, forKey: key, atBucket: bucketName) - do { - try await self.post(uri, value.absoluteString.data(using: .utf8)) - } catch { - throw KVdbServerError.cantSaveTunnelError(error) - } + do { try await self.post(uri, value.absoluteString.data(using: .utf8)) } + catch { throw KVdbServerError.cantSaveTunnelError(error) } } } diff --git a/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbURLConstructable.swift b/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbURLConstructable.swift index c27276d..2f54c1c 100644 --- a/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbURLConstructable.swift +++ b/Packages/SublimationNgrok/Sources/SublimationKVdb/KVdbURLConstructable.swift @@ -1,6 +1,6 @@ // // KVdbURLConstructable.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationKVdb/Optional.swift b/Packages/SublimationNgrok/Sources/SublimationKVdb/Optional.swift index e1d1be8..03ff12e 100644 --- a/Packages/SublimationNgrok/Sources/SublimationKVdb/Optional.swift +++ b/Packages/SublimationNgrok/Sources/SublimationKVdb/Optional.swift @@ -1,6 +1,6 @@ // // Optional.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -36,8 +36,6 @@ extension Optional { /// - Returns: A tuple containing the wrapped value of the optional and `other`, /// or `nil` if either the optional or `other` is `nil`. internal func flatTuple(_ other: OtherType?) -> (Wrapped, OtherType)? { - flatMap { wrapped in - other.map { (wrapped, $0) } - } + flatMap { wrapped in other.map { (wrapped, $0) } } } } diff --git a/Packages/SublimationNgrok/Sources/SublimationKVdb/Result.swift b/Packages/SublimationNgrok/Sources/SublimationKVdb/Result.swift index d79dc96..9691bb6 100644 --- a/Packages/SublimationNgrok/Sources/SublimationKVdb/Result.swift +++ b/Packages/SublimationNgrok/Sources/SublimationKVdb/Result.swift @@ -1,6 +1,6 @@ // // Result.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -33,9 +33,11 @@ extension Result { internal init(success: Success?, failure: Failure?) where Failure == any Error { if let failure { self = .failure(failure) - } else if let success { + } + else if let success { self = .success(success) - } else { + } + else { self = .failure(EmptyError()) } } diff --git a/Packages/SublimationNgrok/Sources/SublimationKVdb/URL+KVdbURLConstructable.swift b/Packages/SublimationNgrok/Sources/SublimationKVdb/URL+KVdbURLConstructable.swift index e5e0c24..e0293c8 100644 --- a/Packages/SublimationNgrok/Sources/SublimationKVdb/URL+KVdbURLConstructable.swift +++ b/Packages/SublimationNgrok/Sources/SublimationKVdb/URL+KVdbURLConstructable.swift @@ -1,6 +1,6 @@ // // URL+KVdbURLConstructable.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationKVdb/URLSession.swift b/Packages/SublimationNgrok/Sources/SublimationKVdb/URLSession.swift index ba3d9c2..ee5b3a6 100644 --- a/Packages/SublimationNgrok/Sources/SublimationKVdb/URLSession.swift +++ b/Packages/SublimationNgrok/Sources/SublimationKVdb/URLSession.swift @@ -1,6 +1,6 @@ // // URLSession.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -38,9 +38,7 @@ extension URLSession { /// Creates a new ephemeral `URLSession` instance. /// /// - Returns: A new ephemeral `URLSession` instance. - public static func ephemeral() -> URLSession { - URLSession(configuration: .ephemeral) - } + public static func ephemeral() -> URLSession { URLSession(configuration: .ephemeral) } /// Fetches data asynchronously for the given request. /// @@ -58,12 +56,7 @@ extension URLSession { return try await withCheckedThrowingContinuation { continuation in let task = self.dataTask(with: request) { data, response, error in - continuation.resume( - with: .init( - success: data.flatTuple(response), - failure: error - ) - ) + continuation.resume(with: .init(success: data.flatTuple(response), failure: error)) } task.resume() } diff --git a/Packages/SublimationNgrok/Sources/SublimationKVdb/URLSessionClient.swift b/Packages/SublimationNgrok/Sources/SublimationKVdb/URLSessionClient.swift index 0042c57..ac687c2 100644 --- a/Packages/SublimationNgrok/Sources/SublimationKVdb/URLSessionClient.swift +++ b/Packages/SublimationNgrok/Sources/SublimationKVdb/URLSessionClient.swift @@ -1,6 +1,6 @@ // // URLSessionClient.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -51,9 +51,7 @@ public struct URLSessionClient: TunnelClient { /// /// - Parameter session: The URLSession to use for network requests. /// Defaults to an ephemeral session. - public init(session: URLSession = .ephemeral()) { - self.session = session - } + public init(session: URLSession = .ephemeral()) { self.session = session } /// Retrieves the value associated with a key from a specific bucket. /// @@ -64,18 +62,13 @@ public struct URLSessionClient: TunnelClient { /// - Returns: The URL value associated with the key. /// /// - Throws: A `NgrokServerError` if the retrieval operation fails. - public func getValue( - ofKey key: Key, - fromBucket bucketName: String - ) async throws -> URL { + public func getValue(ofKey key: Key, fromBucket bucketName: String) async throws -> URL { let url = KVdb.construct(URL.self, forKey: key, atBucket: bucketName) let data = try await session.dataAsync(from: url).0 let urlString = String(decoding: data, as: UTF8.self) - guard let url = URL(string: urlString) else { - throw KVdbServerError.invalidURL - } + guard let url = URL(string: urlString) else { throw KVdbServerError.invalidURL } return url } @@ -88,11 +81,7 @@ public struct URLSessionClient: TunnelClient { /// - bucketName: The name of the bucket to save the value in. /// /// - Throws: A `NgrokServerError` if the save operation fails. - public func saveValue( - _ value: URL, - withKey key: Key, - inBucket bucketName: String - ) async throws { + public func saveValue(_ value: URL, withKey key: Key, inBucket bucketName: String) async throws { let url = KVdb.construct(URL.self, forKey: key, atBucket: bucketName) var request = URLRequest(url: url) request.httpBody = value.absoluteString.data(using: .utf8) diff --git a/Packages/SublimationNgrok/Sources/SublimationMocks/MockError.swift b/Packages/SublimationNgrok/Sources/SublimationMocks/MockError.swift index e13b594..7b0b660 100644 --- a/Packages/SublimationNgrok/Sources/SublimationMocks/MockError.swift +++ b/Packages/SublimationNgrok/Sources/SublimationMocks/MockError.swift @@ -1,6 +1,6 @@ // // MockError.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationMocks/MockServerApplication.swift b/Packages/SublimationNgrok/Sources/SublimationMocks/MockServerApplication.swift index 55ee8cf..3348c2e 100644 --- a/Packages/SublimationNgrok/Sources/SublimationMocks/MockServerApplication.swift +++ b/Packages/SublimationNgrok/Sources/SublimationMocks/MockServerApplication.swift @@ -1,6 +1,6 @@ // // MockServerApplication.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationMocks/MockURL.swift b/Packages/SublimationNgrok/Sources/SublimationMocks/MockURL.swift index 8b4a18a..0495882 100644 --- a/Packages/SublimationNgrok/Sources/SublimationMocks/MockURL.swift +++ b/Packages/SublimationNgrok/Sources/SublimationMocks/MockURL.swift @@ -1,6 +1,6 @@ // // MockURL.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationMocks/URL.swift b/Packages/SublimationNgrok/Sources/SublimationMocks/URL.swift index 057b80d..2bacfdf 100644 --- a/Packages/SublimationNgrok/Sources/SublimationMocks/URL.swift +++ b/Packages/SublimationNgrok/Sources/SublimationMocks/URL.swift @@ -1,6 +1,6 @@ // // URL.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -30,7 +30,7 @@ package import Foundation #if canImport(FoundationNetworking) -package import FoundationNetworking + package import FoundationNetworking #endif extension URL { diff --git a/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIConfiguration.swift b/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIConfiguration.swift index 212f0a4..32ff255 100644 --- a/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIConfiguration.swift +++ b/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIConfiguration.swift @@ -1,6 +1,6 @@ // // NgrokCLIAPIConfiguration.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -55,10 +55,7 @@ extension NgrokCLIAPIConfiguration { /// /// - Parameter serverApplication: The server application to use for configuration. internal init(serverApplication: any Application) { - self.init( - port: serverApplication.httpServerConfigurationPort, - logger: serverApplication.logger - ) + self.init(port: serverApplication.httpServerConfigurationPort, logger: serverApplication.logger) } /// Initializes a new instance of `NgrokCLIAPIConfiguration` @@ -66,7 +63,5 @@ extension NgrokCLIAPIConfiguration { /// /// - Parameter application: The Vapor application to use for configuration. - public init(application: any Application) { - self.init(serverApplication: application) - } + public init(application: any Application) { self.init(serverApplication: application) } } diff --git a/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIServer+TunnelServer.swift b/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIServer+TunnelServer.swift index cb41af1..d0b3e60 100644 --- a/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIServer+TunnelServer.swift +++ b/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIServer+TunnelServer.swift @@ -1,6 +1,6 @@ // // NgrokCLIAPIServer+TunnelServer.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -28,19 +28,17 @@ // import Foundation +import Ngrokit public import OpenAPIRuntime import SublimationTunnel -import Ngrokit extension NgrokCLIAPIServer { /// Runs the server. - public func begin( - isConnectionRefused: @escaping (ClientError) -> Bool) async { + public func begin(isConnectionRefused: @escaping (ClientError) -> Bool) async { let start = Date() let newTunnel: any Tunnel - do { - newTunnel = try await self.newTunnel(isConnectionRefused: isConnectionRefused) - } catch { + do { newTunnel = try await self.newTunnel(isConnectionRefused: isConnectionRefused) } + catch { delegate.server(self, errorDidOccur: error) return } @@ -51,33 +49,25 @@ extension NgrokCLIAPIServer { } /// Starts the server. - public func start( - isConnectionRefused: @escaping @Sendable (ClientError) -> Bool) { - Task { - await begin(isConnectionRefused: isConnectionRefused) - } + public func start(isConnectionRefused: @escaping @Sendable (ClientError) -> Bool) { + Task { await begin(isConnectionRefused: isConnectionRefused) } } actor HasStarted { internal private(set) var isStarted = false - - func started() { - isStarted = true - } - } - - public func shutdown() { - self.process.terminate() + func started() { isStarted = true } } + public func shutdown() { self.process.terminate() } public func run(isConnectionRefused: @escaping @Sendable (ClientError) -> Bool) async throws { - try await withThrowingTaskGroup(of: Void.self, body: { group in - let started = HasStarted() - group.addTask{ - try await withCheckedThrowingContinuation { continuation in - - let start = Date() - Task { - let newTunnel = try await self.newTunnel( - isConnectionRefused: isConnectionRefused) { error in + try await withThrowingTaskGroup( + of: Void.self, + body: { group in + let started = HasStarted() + group.addTask { + try await withCheckedThrowingContinuation { continuation in + let start = Date() + Task { + let newTunnel = try await self.newTunnel(isConnectionRefused: isConnectionRefused) { + error in if let error = error as? RuntimeError { if case let .unknownEarlyTermination(string) = error { continuation.resume() @@ -86,24 +76,22 @@ extension NgrokCLIAPIServer { } continuation.resume(throwing: error) } - let seconds = Int(-start.timeIntervalSinceNow) - logger.notice("New Tunnel Created in \(seconds) secs: \(newTunnel.publicURL)") - delegate.server(self, updatedTunnel: newTunnel) - await started.started() + let seconds = Int(-start.timeIntervalSinceNow) + logger.notice("New Tunnel Created in \(seconds) secs: \(newTunnel.publicURL)") + delegate.server(self, updatedTunnel: newTunnel) + await started.started() + } } } - } - group.addTask{ - var isActive = true - - while isActive { - try await Task.sleep(for: .seconds(5.0), tolerance: .seconds(2.5)) - if await started.isStarted { - try await self.status() + group.addTask { + var isActive = true + while isActive { + try await Task.sleep(for: .seconds(5.0), tolerance: .seconds(2.5)) + if await started.isStarted { try await self.status() } } } + try await group.waitForAll() } - try await group.waitForAll() - }) + ) } } diff --git a/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIServer.swift b/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIServer.swift index feb61d5..19f9adf 100644 --- a/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIServer.swift +++ b/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIServer.swift @@ -1,6 +1,6 @@ // // NgrokCLIAPIServer.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -87,14 +87,10 @@ public struct NgrokCLIAPIServer: TunnelServer, Sendable { /// Handles a CLI error. /// /// - Parameter error: The error that occurred. - @Sendable - @available(*, deprecated) - private func cliError(_ error: any Error) { + @Sendable @available(*, deprecated) private func cliError(_ error: any Error) { delegate.server(self, errorDidOccur: error) } - - @available(*, deprecated) - private func searchForExistingTunnel( + @available(*, deprecated) private func searchForExistingTunnel( within timeout: TimeInterval, isConnectionRefused: @escaping (ClientError) -> Bool ) async throws -> TunnelResult? { @@ -109,16 +105,14 @@ public struct NgrokCLIAPIServer: TunnelServer, Sendable { return tunnel } - return try await client.searchForCreatedTunnel( - within: timeout, - logger: logger, - isConnectionRefused: isConnectionRefused - ) - .map { - .init(isOld: false, tunnel: $0) - } + return + try await client.searchForCreatedTunnel( + within: timeout, + logger: logger, + isConnectionRefused: isConnectionRefused + ) + .map { .init(isOld: false, tunnel: $0) } } - private func searchForExistingTunnel( within timeout: TimeInterval, isConnectionRefused: @escaping (ClientError) -> Bool, @@ -135,37 +129,31 @@ public struct NgrokCLIAPIServer: TunnelServer, Sendable { return tunnel } - return try await client.searchForCreatedTunnel( - within: timeout, - logger: logger, - isConnectionRefused: isConnectionRefused - ) - .map { - .init(isOld: false, tunnel: $0) - } + return + try await client.searchForCreatedTunnel( + within: timeout, + logger: logger, + isConnectionRefused: isConnectionRefused + ) + .map { .init(isOld: false, tunnel: $0) } } private func getTunnel( from result: NetworkResult, onTerminationError: @Sendable @escaping (any Error) -> Void ) async throws -> TunnelResult?? { - switch result { - case .connectionRefused: - logger.notice( - "Ngrok not running. Waiting for Process and New Tunnel... (about 30 secs)" - ) + switch result { case .connectionRefused: + logger.notice("Ngrok not running. Waiting for Process and New Tunnel... (about 30 secs)") try await process.run(onError: onTerminationError) - case let .success(tunnel): - logger.debug("Process Already Running.") - return TunnelResult??.some(tunnel.map { .init(isOld: true, tunnel: $0) }) + case let .success(tunnel): + logger.debug("Process Already Running.") + return TunnelResult??.some(tunnel.map { .init(isOld: true, tunnel: $0) }) - case let .failure(error): - throw error + case let .failure(error): throw error } return nil } - internal func newTunnel( isConnectionRefused: @Sendable @escaping (ClientError) -> Bool, @@ -179,26 +167,19 @@ public struct NgrokCLIAPIServer: TunnelServer, Sendable { if tunnel.isOld { try await client.stopTunnel(withName: tunnel.tunnel.name) logger.info("Existing Tunnel Stopped. \(tunnel.tunnel.publicURL)") - } else { + } + else { return tunnel.tunnel } } - return try await client.startTunnel( - .init( - port: port, - name: "vapor-development" - ) - ) - } - - internal func status () async throws { - try await self.client.status() + return try await client.startTunnel(.init(port: port, name: "vapor-development")) } + internal func status() async throws { try await self.client.status() } - internal func newTunnel( - isConnectionRefused: @escaping (ClientError) -> Bool - ) async throws -> any Tunnel { + internal func newTunnel(isConnectionRefused: @escaping (ClientError) -> Bool) async throws + -> any Tunnel + { if let tunnel = try await searchForExistingTunnel( within: 60.0, isConnectionRefused: isConnectionRefused @@ -206,16 +187,12 @@ public struct NgrokCLIAPIServer: TunnelServer, Sendable { if tunnel.isOld { try await client.stopTunnel(withName: tunnel.tunnel.name) logger.info("Existing Tunnel Stopped. \(tunnel.tunnel.publicURL)") - } else { + } + else { return tunnel.tunnel } } - return try await client.startTunnel( - .init( - port: port, - name: "vapor-development" - ) - ) + return try await client.startTunnel(.init(port: port, name: "vapor-development")) } } diff --git a/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIServerFactory.swift b/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIServerFactory.swift index 03b1d4a..5d0e350 100644 --- a/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIServerFactory.swift +++ b/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokCLIAPIServerFactory.swift @@ -1,6 +1,6 @@ // // NgrokCLIAPIServerFactory.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -47,18 +47,12 @@ public struct NgrokCLIAPIServerFactory: TunnelServerFa private let ngrokClient: @Sendable () -> NgrokClient - public init( - cliAPI: any NgrokCLIAPI, - ngrokClient: @escaping @Sendable () -> NgrokClient - ) { + public init(cliAPI: any NgrokCLIAPI, ngrokClient: @escaping @Sendable () -> NgrokClient) { self.cliAPI = cliAPI self.ngrokClient = ngrokClient } - public init( - ngrokPath: String, - ngrokClient: @escaping @Sendable () -> NgrokClient - ) { + public init(ngrokPath: String, ngrokClient: @escaping @Sendable () -> NgrokClient) { self.init( cliAPI: NgrokProcessCLIAPI(ngrokPath: ngrokPath), ngrokClient: ngrokClient @@ -73,10 +67,9 @@ public struct NgrokCLIAPIServerFactory: TunnelServerFa /// /// - Returns: A new `NgrokCLIAPIServer` instance. - public func server( - from configuration: Configuration, - handler: any TunnelServerDelegate - ) -> NgrokCLIAPIServer { + public func server(from configuration: Configuration, handler: any TunnelServerDelegate) + -> NgrokCLIAPIServer + { let process = cliAPI.process(forHTTPPort: configuration.port) return .init( delegate: handler, diff --git a/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokClient.swift b/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokClient.swift index 2949de2..a12a0a5 100644 --- a/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokClient.swift +++ b/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokClient.swift @@ -1,6 +1,6 @@ // // NgrokClient.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -34,18 +34,16 @@ import OpenAPIRuntime import SublimationTunnel extension NgrokClient { - internal func attemptTunnel( - isConnectionRefused: @escaping (ClientError) -> Bool - ) async -> TunnelAttemptResult { - let networkResult = await AnyTunnelNetworkResult({ - try await self.listTunnels().first - }, isConnectionRefused: isConnectionRefused) - switch networkResult { - case let .connectionRefused(error): - return .error(error) + internal func attemptTunnel(isConnectionRefused: @escaping (ClientError) -> Bool) async + -> TunnelAttemptResult + { + let networkResult = await AnyTunnelNetworkResult( + { try await self.listTunnels().first }, + isConnectionRefused: isConnectionRefused + ) + switch networkResult { case let .connectionRefused(error): return .error(error) - default: - return .network(networkResult) + default: return .network(networkResult) } } @@ -63,12 +61,9 @@ extension NgrokClient { try await Task.sleep(for: .seconds(5), tolerance: .seconds(5)) let result = await self.attemptTunnel(isConnectionRefused: isConnectionRefused) attempts += 1 - switch result { - case let .network(newNetworkResult): - networkResult = newNetworkResult + switch result { case let .network(newNetworkResult): networkResult = newNetworkResult - case let .error(error): - lastError = error + case let .error(error): lastError = error } } diff --git a/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokTunnel.swift b/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokTunnel.swift index 56718de..8ceb5c7 100644 --- a/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokTunnel.swift +++ b/Packages/SublimationNgrok/Sources/SublimationNgrok/NgrokTunnel.swift @@ -1,6 +1,6 @@ // // NgrokTunnel.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationNgrok/TunnelAttemptResult.swift b/Packages/SublimationNgrok/Sources/SublimationNgrok/TunnelAttemptResult.swift index 928b089..3f858fe 100644 --- a/Packages/SublimationNgrok/Sources/SublimationNgrok/TunnelAttemptResult.swift +++ b/Packages/SublimationNgrok/Sources/SublimationNgrok/TunnelAttemptResult.swift @@ -1,6 +1,6 @@ // // TunnelAttemptResult.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/MockServerDelegate.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/MockServerDelegate.swift index 757b9be..887035a 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/MockServerDelegate.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/MockServerDelegate.swift @@ -1,6 +1,6 @@ // // MockServerDelegate.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -26,18 +26,15 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // + package import Foundation package final class MockServerDelegate: TunnelServerDelegate { package let id: UUID - package init(id: UUID) { - self.id = id - } + package init(id: UUID) { self.id = id } - package func server( - _: any TunnelServer, updatedTunnel _: any Tunnel - ) {} + package func server(_: any TunnelServer, updatedTunnel _: any Tunnel) {} package func server(_: any TunnelServer, errorDidOccur _: any Error) {} } diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/MockTunnelClient.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/MockTunnelClient.swift index 762b4d2..575758b 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/MockTunnelClient.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/MockTunnelClient.swift @@ -1,6 +1,6 @@ // // MockTunnelClient.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/NetworkResult.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/NetworkResult.swift index 60badb4..e91ecb4 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/NetworkResult.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/NetworkResult.swift @@ -1,6 +1,6 @@ // // NetworkResult.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -29,8 +29,9 @@ import Foundation -package typealias AnyTunnelNetworkResult = - NetworkResult<(any Tunnel)?, ConnectionErrorType> +package typealias AnyTunnelNetworkResult = NetworkResult< + (any Tunnel)?, ConnectionErrorType +> /// Represents the result of a network operation. /// @@ -64,23 +65,16 @@ extension NetworkResult { _ closure: @escaping () async throws -> T, isConnectionRefused: @escaping (ConnectionErrorType) -> Bool ) async { - do { - self = try await .success(closure()) - } catch { - self = .init(error: error, isConnectionRefused: isConnectionRefused) - } + do { self = try await .success(closure()) } + catch { self = .init(error: error, isConnectionRefused: isConnectionRefused) } } public func get() throws -> T? { - switch self { - case .connectionRefused: - return nil + switch self { case .connectionRefused: return nil - case let .failure(error): - throw error + case let .failure(error): throw error - case let .success(item): - return item + case let .success(item): return item } } } diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/Tunnel.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/Tunnel.swift index c0e1613..97ffb87 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/Tunnel.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/Tunnel.swift @@ -1,6 +1,6 @@ // // Tunnel.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelBucketRepositoryFactory.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelBucketRepositoryFactory.swift index 4e03e4e..484b804 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelBucketRepositoryFactory.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelBucketRepositoryFactory.swift @@ -1,6 +1,6 @@ // // TunnelBucketRepositoryFactory.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -35,8 +35,7 @@ import Foundation /// This factory is used to set up and configure a /// `KVdbTunnelRepository` with a specific bucket name. -public struct TunnelBucketRepositoryFactory: - WritableTunnelRepositoryFactory { +public struct TunnelBucketRepositoryFactory: WritableTunnelRepositoryFactory { /// The type of tunnel repository created by this factory. public typealias TunnelRepositoryType = TunnelClientRepository @@ -46,18 +45,15 @@ public struct TunnelBucketRepositoryFactory: /// Initializes a new instance of the factory with the specified bucket name. /// /// - Parameter bucketName: The name of the bucket to use. - public init(bucketName: String) { - self.bucketName = bucketName - } + public init(bucketName: String) { self.bucketName = bucketName } /// Sets up a client and returns a new `KVdbTunnelRepository` instance. /// /// - Parameter client: The tunnel client to use. /// - Returns: A new `KVdbTunnelRepository` instance. - public func setupClient( - _ client: TunnelClientType - ) -> TunnelClientRepository - where TunnelClientType: TunnelClient, TunnelClientType.Key == Key { + public func setupClient(_ client: TunnelClientType) -> TunnelClientRepository< + Key + > where TunnelClientType: TunnelClient, TunnelClientType.Key == Key { .init(client: client, bucketName: bucketName) } } diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelClient.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelClient.swift index 8d917e0..696f542 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelClient.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelClient.swift @@ -1,6 +1,6 @@ // // TunnelClient.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelClientRepository.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelClientRepository.swift index 2a4924f..611c46c 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelClientRepository.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelClientRepository.swift @@ -1,6 +1,6 @@ // // TunnelClientRepository.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelRepository.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelRepository.swift index 6f57936..8257ae1 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelRepository.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelRepository.swift @@ -1,6 +1,6 @@ // // TunnelRepository.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelRepositoryFactory.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelRepositoryFactory.swift index 648a580..49b8ba3 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelRepositoryFactory.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelRepositoryFactory.swift @@ -1,6 +1,6 @@ // // TunnelRepositoryFactory.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -63,7 +63,6 @@ public protocol TunnelRepositoryFactory: Sendable { /// /// - Note: The `TunnelClientType` must have a `Key` type /// that matches the `Key` type of the `TunnelRepositoryType`. - func setupClient( - _ client: TunnelClientType - ) -> TunnelRepositoryType where TunnelClientType.Key == TunnelRepositoryType.Key + func setupClient(_ client: TunnelClientType) + -> TunnelRepositoryType where TunnelClientType.Key == TunnelRepositoryType.Key } diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServer.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServer.swift index c297d58..fd9897e 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServer.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServer.swift @@ -1,6 +1,6 @@ // // TunnelServer.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -34,17 +34,16 @@ /// - Note: The Ngrok server allows you to expose a local server to the internet. /// /// - Important: Make sure to call the `start()` method to start the Ngrok server. -public protocol TunnelServer : Sendable { +public protocol TunnelServer: Sendable { /// Type of connection error which denotes whether the service isn't available. associatedtype ConnectionErrorType: Error /// Starts the Ngrok server. /// /// Call this method to start the Ngrok server and /// expose your local server to the internet. - @available(*, deprecated) - func start(isConnectionRefused: @escaping @Sendable (ConnectionErrorType) -> Bool) - + @available(*, deprecated) func start( + isConnectionRefused: @escaping @Sendable (ConnectionErrorType) -> Bool + ) func run(isConnectionRefused: @escaping @Sendable (ConnectionErrorType) -> Bool) async throws - func shutdown() } diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServerConfiguration.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServerConfiguration.swift index a3de424..a2be936 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServerConfiguration.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServerConfiguration.swift @@ -1,6 +1,6 @@ // // TunnelServerConfiguration.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServerDelegate.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServerDelegate.swift index a1f5d75..74dbcba 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServerDelegate.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServerDelegate.swift @@ -1,6 +1,6 @@ // // TunnelServerDelegate.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -30,8 +30,7 @@ import Foundation /// A delegate protocol for `NgrokServer` that handles server events and errors. -@available(*, deprecated) -public protocol TunnelServerDelegate: AnyObject, Sendable { +@available(*, deprecated) public protocol TunnelServerDelegate: AnyObject, Sendable { /// Notifies the delegate that a tunnel has been updated. /// /// - Parameters: diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServerFactory.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServerFactory.swift index 84ff8f4..4d110f6 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServerFactory.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelServerFactory.swift @@ -1,6 +1,6 @@ // // TunnelServerFactory.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -39,8 +39,6 @@ public protocol TunnelServerFactory: Sendable { /// - handler: The delegate object that handles server events. /// /// - Returns: A server instance based on the provided configuration. - func server( - from configuration: Configuration, - handler: any TunnelServerDelegate - ) -> Configuration.Server + func server(from configuration: Configuration, handler: any TunnelServerDelegate) + -> Configuration.Server } diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelSublimatory.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelSublimatory.swift index 4714441..2e1b5e0 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelSublimatory.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/TunnelSublimatory.swift @@ -1,6 +1,6 @@ // // TunnelSublimatory.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -32,17 +32,17 @@ import Logging public import SublimationCore /// Closure which returns a ``TunnelClient`` from the ``Application``. -public typealias RepositoryClientFactory = - (@Sendable @escaping () -> any Application) -> any TunnelClient +public typealias RepositoryClientFactory = (@Sendable @escaping () -> any Application) -> + any TunnelClient public actor TunnelSublimatory< WritableTunnelRepositoryFactoryType: WritableTunnelRepositoryFactory, TunnelServerFactoryType: TunnelServerFactory >: Sublimatory, TunnelServerDelegate { - public typealias Key = WritableTunnelRepositoryFactoryType.TunnelRepositoryType.Key - public typealias ConnectionErrorType = TunnelServerFactoryType.Configuration.Server.ConnectionErrorType + public typealias ConnectionErrorType = TunnelServerFactoryType.Configuration.Server + .ConnectionErrorType private let factory: TunnelServerFactoryType private let repoFactory: WritableTunnelRepositoryFactoryType private let key: Key @@ -68,9 +68,7 @@ public actor TunnelSublimatory< isConnectionRefused: @escaping @Sendable (ConnectionErrorType) -> Bool ) async { let logger = application().logger - let tunnelRepo = repoFactory.setupClient( - repoClientFactory(application) - ) + let tunnelRepo = repoFactory.setupClient(repoClientFactory(application)) await self.init( factory: factory, repoFactory: repoFactory, @@ -95,7 +93,9 @@ public actor TunnelSublimatory< logger: Logger, repoClientFactory: @escaping RepositoryClientFactory, isConnectionRefused: @escaping @Sendable (ConnectionErrorType) -> Bool, - server: @escaping @Sendable (TunnelSublimatory) -> TunnelServerFactoryType.Configuration.Server + server: @escaping @Sendable ( + TunnelSublimatory + ) -> TunnelServerFactoryType.Configuration.Server ) async { self.factory = factory self.repoFactory = repoFactory @@ -116,17 +116,14 @@ public actor TunnelSublimatory< /// /// - SeeAlso: `Tunnel` private func saveTunnel(_ tunnel: any Tunnel) async { - do { - try await tunnelRepo.saveURL(tunnel.publicURL, withKey: key) - } catch { - logger.error( - "Unable to save url to repository: \(error.localizedDescription)" - ) + do { try await tunnelRepo.saveURL(tunnel.publicURL, withKey: key) } + catch { + logger.error("Unable to save url to repository: \(error.localizedDescription)") return } -// logger?.notice( -// "Saved url \(tunnel.publicURL) to repository with key \(key)" -// ) + // logger?.notice( + // "Saved url \(tunnel.publicURL) to repository with key \(key)" + // ) } /// Handles an error that occurred during tunnel operation. @@ -150,9 +147,7 @@ public actor TunnelSublimatory< /// - SeeAlso: `NgrokServer` /// - SeeAlso: `Tunnel` public nonisolated func server(_: any TunnelServer, updatedTunnel tunnel: any Tunnel) { - Task { - await self.saveTunnel(tunnel) - } + Task { await self.saveTunnel(tunnel) } } /// Called when an error occurs in the Ngrok server. @@ -165,9 +160,7 @@ public actor TunnelSublimatory< /// /// - SeeAlso: `NgrokServer` public nonisolated func server(_: any TunnelServer, errorDidOccur error: any Error) { - Task { - await self.onError(error) - } + Task { await self.onError(error) } } /// Begins the Sublimation application from the given application. @@ -178,18 +171,18 @@ public actor TunnelSublimatory< /// - Note: This method is private and asynchronous. /// /// - SeeAlso: `Application` -// private func beginFromApplication(_ application: @Sendable @escaping () -> any Application) async { -// let server = factory.server( -// from: TunnelServerFactoryType.Configuration(application: application()), -// handler: self -// ) -// logger = application().logger -// tunnelRepo = repoFactory.setupClient( -// repoClientFactory(application) -// ) -// self.server = server -// server.start(isConnectionRefused: isConnectionRefused) -// } + // private func beginFromApplication(_ application: @Sendable @escaping () -> any Application) async { + // let server = factory.server( + // from: TunnelServerFactoryType.Configuration(application: application()), + // handler: self + // ) + // logger = application().logger + // tunnelRepo = repoFactory.setupClient( + // repoClientFactory(application) + // ) + // self.server = server + // server.start(isConnectionRefused: isConnectionRefused) + // } /// Called when the application is about to boot. /// @@ -201,41 +194,33 @@ public actor TunnelSublimatory< /// - Note: This method is nonisolated. /// /// - SeeAlso: `Application` -// public func willBoot(from application: @escaping @Sendable () -> any Application) async { -// await self.beginFromApplication(application) -// } -// -// func setupForApplication(_ application: @escaping @Sendable () -> any Application) { -// let server = factory.server( -// from: TunnelServerFactoryType.Configuration(application: application()), -// handler: self -// ) -// logger = application().logger -// tunnelRepo = repoFactory.setupClient( -// repoClientFactory(application) -// ) -// self.server = server -// } -// -// public nonisolated func initialize(for application: @escaping @Sendable () -> any Application) { -// Task { -// await self.setupForApplication(application) -// } -// } -// - func shutdownServer () { - server.shutdown() - } - public nonisolated func shutdown() { - Task { - await self.shutdownServer() - } - } + // public func willBoot(from application: @escaping @Sendable () -> any Application) async { + // await self.beginFromApplication(application) + // } + // + // func setupForApplication(_ application: @escaping @Sendable () -> any Application) { + // let server = factory.server( + // from: TunnelServerFactoryType.Configuration(application: application()), + // handler: self + // ) + // logger = application().logger + // tunnelRepo = repoFactory.setupClient( + // repoClientFactory(application) + // ) + // self.server = server + // } + // + // public nonisolated func initialize(for application: @escaping @Sendable () -> any Application) { + // Task { + // await self.setupForApplication(application) + // } + // } + // + func shutdownServer() { server.shutdown() } + public nonisolated func shutdown() { Task { await self.shutdownServer() } } public func run() async throws { - let isConnectionRefused = self.isConnectionRefused - try await server.run(isConnectionRefused: isConnectionRefused) } } diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/WritableTunnelRepository.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/WritableTunnelRepository.swift index 2f4d6e5..f908703 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/WritableTunnelRepository.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/WritableTunnelRepository.swift @@ -1,6 +1,6 @@ // // WritableTunnelRepository.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationNgrok/Sources/SublimationTunnel/WritableTunnelRepositoryFactory.swift b/Packages/SublimationNgrok/Sources/SublimationTunnel/WritableTunnelRepositoryFactory.swift index 5dd1ab6..10f20cf 100644 --- a/Packages/SublimationNgrok/Sources/SublimationTunnel/WritableTunnelRepositoryFactory.swift +++ b/Packages/SublimationNgrok/Sources/SublimationTunnel/WritableTunnelRepositoryFactory.swift @@ -1,6 +1,6 @@ // // WritableTunnelRepositoryFactory.swift -// Sublimation +// SublimationNgrok // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -27,11 +27,6 @@ // OTHER DEALINGS IN THE SOFTWARE. // -// #if os(macOS) -// @_exported import class Ngrokit.ProcessableProcess -// #endif -// @_exported import struct Ngrokit.NgrokClient - import Foundation #if canImport(FoundationNetworking) @@ -49,4 +44,4 @@ import Foundation /// - SeeAlso: `TunnelRepositoryFactory` /// - SeeAlso: `WritableTunnelRepository` public protocol WritableTunnelRepositoryFactory: TunnelRepositoryFactory - where TunnelRepositoryType: WritableTunnelRepository {} +where TunnelRepositoryType: WritableTunnelRepository {} diff --git a/Packages/SublimationService/Scripts/lint.sh b/Packages/SublimationService/Scripts/lint.sh index 87f21fa..4653602 100755 --- a/Packages/SublimationService/Scripts/lint.sh +++ b/Packages/SublimationService/Scripts/lint.sh @@ -13,10 +13,10 @@ MINT_RUN="/opt/homebrew/bin/mint run $MINT_ARGS" if [ -z "$SRCROOT" ]; then SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) PACKAGE_DIR="${SCRIPT_DIR}/.." - PERIPHERY_OPTIONS="--skip-build" -else - PACKAGE_DIR="${SRCROOT}" PERIPHERY_OPTIONS="" +else + PACKAGE_DIR="${SRCROOT}" + PERIPHERY_OPTIONS="--skip-build" fi @@ -32,6 +32,10 @@ fi echo "LINT Mode is $LINT_MODE" +if [ "$LINT_MODE" == "INSTALL" ]; then + exit +fi + if [ -z "$CI" ]; then $MINT_RUN swift-format format --recursive --parallel --in-place $PACKAGE_DIR/Sources else diff --git a/Packages/SublimationService/Sources/SublimationService/Service.swift b/Packages/SublimationService/Sources/SublimationService/Service.swift index b4c15ac..b0acec9 100644 --- a/Packages/SublimationService/Sources/SublimationService/Service.swift +++ b/Packages/SublimationService/Sources/SublimationService/Service.swift @@ -1,6 +1,6 @@ // // Service.swift -// Sublimation +// SublimationVapor // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -27,14 +27,8 @@ // OTHER DEALINGS IN THE SOFTWARE. // -// -// Service.swift -// SublimationService -// -// Created by Leo Dion on 7/22/24. -// - public import ServiceLifecycle + @_exported public import class Sublimation.Sublimation extension Sublimation: @retroactive Service { diff --git a/Packages/SublimationVapor/Scripts/lint.sh b/Packages/SublimationVapor/Scripts/lint.sh index 87f21fa..4653602 100755 --- a/Packages/SublimationVapor/Scripts/lint.sh +++ b/Packages/SublimationVapor/Scripts/lint.sh @@ -13,10 +13,10 @@ MINT_RUN="/opt/homebrew/bin/mint run $MINT_ARGS" if [ -z "$SRCROOT" ]; then SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) PACKAGE_DIR="${SCRIPT_DIR}/.." - PERIPHERY_OPTIONS="--skip-build" -else - PACKAGE_DIR="${SRCROOT}" PERIPHERY_OPTIONS="" +else + PACKAGE_DIR="${SRCROOT}" + PERIPHERY_OPTIONS="--skip-build" fi @@ -32,6 +32,10 @@ fi echo "LINT Mode is $LINT_MODE" +if [ "$LINT_MODE" == "INSTALL" ]; then + exit +fi + if [ -z "$CI" ]; then $MINT_RUN swift-format format --recursive --parallel --in-place $PACKAGE_DIR/Sources else diff --git a/Packages/SublimationVapor/Sources/SublimationVapor/ClientError.swift b/Packages/SublimationVapor/Sources/SublimationVapor/ClientError.swift index 54f0db6..dfb6b04 100644 --- a/Packages/SublimationVapor/Sources/SublimationVapor/ClientError.swift +++ b/Packages/SublimationVapor/Sources/SublimationVapor/ClientError.swift @@ -1,6 +1,6 @@ // // ClientError.swift -// Sublimation +// SublimationVapor // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationVapor/Sources/SublimationVapor/KVdbTunnelClient.swift b/Packages/SublimationVapor/Sources/SublimationVapor/KVdbTunnelClient.swift index 1f9fc89..6188fb6 100644 --- a/Packages/SublimationVapor/Sources/SublimationVapor/KVdbTunnelClient.swift +++ b/Packages/SublimationVapor/Sources/SublimationVapor/KVdbTunnelClient.swift @@ -1,6 +1,6 @@ // // KVdbTunnelClient.swift -// Sublimation +// SublimationVapor // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationVapor/Sources/SublimationVapor/Sublimation+Ngrok.swift b/Packages/SublimationVapor/Sources/SublimationVapor/Sublimation+Ngrok.swift index ccc0349..92bcf6e 100644 --- a/Packages/SublimationVapor/Sources/SublimationVapor/Sublimation+Ngrok.swift +++ b/Packages/SublimationVapor/Sources/SublimationVapor/Sublimation+Ngrok.swift @@ -1,6 +1,6 @@ // // Sublimation+Ngrok.swift -// Sublimation +// SublimationVapor // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationVapor/Sources/SublimationVapor/Sublimation.swift b/Packages/SublimationVapor/Sources/SublimationVapor/Sublimation.swift index fcddaa6..97f6074 100644 --- a/Packages/SublimationVapor/Sources/SublimationVapor/Sublimation.swift +++ b/Packages/SublimationVapor/Sources/SublimationVapor/Sublimation.swift @@ -1,6 +1,6 @@ // // Sublimation.swift -// Sublimation +// SublimationVapor // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -35,15 +35,8 @@ public import Vapor extension Sublimation: @retroactive LifecycleHandler { public func willBoot(_ application: Vapor.Application) throws { - Task { - try await self.sublimatory.run() - } + Task { try await self.sublimatory.run() } } - - public func shutdown(_ application: Vapor.Application) { - Task { - self.sublimatory.shutdown() - } - } + public func shutdown(_ application: Vapor.Application) { Task { self.sublimatory.shutdown() } } } diff --git a/Packages/SublimationVapor/Sources/SublimationVapor/TunnelSublimatory.swift b/Packages/SublimationVapor/Sources/SublimationVapor/TunnelSublimatory.swift index f9afc78..16a3c91 100644 --- a/Packages/SublimationVapor/Sources/SublimationVapor/TunnelSublimatory.swift +++ b/Packages/SublimationVapor/Sources/SublimationVapor/TunnelSublimatory.swift @@ -1,6 +1,6 @@ // // TunnelSublimatory.swift -// Sublimation +// SublimationVapor // // Created by Leo Dion. // Copyright © 2024 BrightDigit. diff --git a/Packages/SublimationVapor/Sources/SublimationVapor/Vapor.Application.swift b/Packages/SublimationVapor/Sources/SublimationVapor/Vapor.Application.swift index 0903c7d..c0362e7 100644 --- a/Packages/SublimationVapor/Sources/SublimationVapor/Vapor.Application.swift +++ b/Packages/SublimationVapor/Sources/SublimationVapor/Vapor.Application.swift @@ -1,6 +1,6 @@ // // Vapor.Application.swift -// Sublimation +// SublimationVapor // // Created by Leo Dion. // Copyright © 2024 BrightDigit. @@ -27,17 +27,14 @@ // OTHER DEALINGS IN THE SOFTWARE. // -import protocol SublimationCore.Application public import Vapor +import protocol SublimationCore.Application + extension Vapor.Application: @retroactive Application { - public var httpServerConfigurationPort: Int { - self.http.server.configuration.port - } + public var httpServerConfigurationPort: Int { self.http.server.configuration.port } - public var httpServerTLS: Bool { - self.http.server.configuration.tlsConfiguration != nil - } + public var httpServerTLS: Bool { self.http.server.configuration.tlsConfiguration != nil } public func post(to url: URL, body: Data?) async throws { _ = try await client.post(.init(string: url.absoluteString)) { request in diff --git a/Packages/SublimationVapor/Tests/SublimationVaporTests/SublimationVaporTests.swift b/Packages/SublimationVapor/Tests/SublimationVaporTests/SublimationVaporTests.swift new file mode 100644 index 0000000..02bd873 --- /dev/null +++ b/Packages/SublimationVapor/Tests/SublimationVaporTests/SublimationVaporTests.swift @@ -0,0 +1,35 @@ +// +// SublimationVaporTests.swift +// SublimationVapor +// +// Created by Leo Dion on 8/9/24. +// + +import XCTest + +final class SublimationVaporTests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + // Any test you write for XCTest can be annotated as throws and async. + // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error. + // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards. + } + + func testPerformanceExample() throws { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/Scripts/lint.sh b/Scripts/lint.sh index b6d5ce7..887aea6 100755 --- a/Scripts/lint.sh +++ b/Scripts/lint.sh @@ -13,10 +13,10 @@ MINT_RUN="/opt/homebrew/bin/mint run $MINT_ARGS" if [ -z "$SRCROOT" ]; then SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) PACKAGE_DIR="${SCRIPT_DIR}/.." - PERIPHERY_OPTIONS="--skip-build" -else - PACKAGE_DIR="${SRCROOT}" PERIPHERY_OPTIONS="" +else + PACKAGE_DIR="${SRCROOT}" + PERIPHERY_OPTIONS="--skip-build" fi @@ -32,6 +32,10 @@ fi echo "LINT Mode is $LINT_MODE" +if [ "$LINT_MODE" == "INSTALL" ]; then + exit +fi + if [ -z "$CI" ]; then $MINT_RUN swift-format format --recursive --parallel --in-place $PACKAGE_DIR/Sources else diff --git a/Scripts/lints.sh b/Scripts/lints.sh new file mode 100755 index 0000000..b1fba26 --- /dev/null +++ b/Scripts/lints.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +if [ -z "$SRCROOT" ]; then + script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +else + script_dir="${SRCROOT}/Scripts" +fi + +directories=( + "Packages/Ngrokit" + "Packages/SublimationBonjour" + "Packages/SublimationNgrok" + "Packages/SublimationService" + "Packages/SublimationVapor" + "." +) + +cd "$script_dir/.." || exit 1 + +for i in "${!directories[@]}"; do + dir="${directories[$i]}" + if [ -f "$dir/Scripts/lint.sh" ]; then + echo "Running lint.sh in $dir" + (cd "$dir" && LINT_MODE="$LINT_MODE" ./Scripts/lint.sh) + + # Check if the script failed + if [ $? -ne 0 ]; then + echo "Lint script failed in $dir" + exit 1 + fi + + # Copy .mint folder to the next directory if it's not the last one + if [ $i -lt $((${#directories[@]} - 1)) ]; then + next_dir="${directories[$i+1]}" + if [ -d "$dir/.mint" ]; then + echo "Copying .mint folder from $dir to $next_dir" + cp -R "$dir/.mint" "$next_dir/" + else + echo "No .mint folder found in $dir" + fi + fi + else + echo "lint.sh not found in $dir" + fi +done + +echo "All lint processes completed successfully." diff --git a/Sources/Sublimation/Sublimation.swift b/Sources/Sublimation/Sublimation.swift index f4bdc26..7fbdf94 100644 --- a/Sources/Sublimation/Sublimation.swift +++ b/Sources/Sublimation/Sublimation.swift @@ -31,6 +31,7 @@ import Foundation import Logging public import SublimationCore +/// Adds the ability to auto-discover development urls to your full stack applicaiton. public final class Sublimation: Sendable { public let sublimatory: any Sublimatory diff --git a/Sources/SublimationCore/Application.swift b/Sources/SublimationCore/Application.swift index 47238eb..4e20a65 100644 --- a/Sources/SublimationCore/Application.swift +++ b/Sources/SublimationCore/Application.swift @@ -45,10 +45,12 @@ public protocol Application { /// - Parameters: /// - url: The url to post to. /// - body: The optional data. + /// - Throws: If there's an issue with the request. func post(to url: URL, body: Data?) async throws /// Makes a client call to a url. /// - Parameter url: The url to call. - /// - Returns: <#description#> + /// - Returns: The data returned from that request. + /// - Throws: If there's an issue with the request. func get(from url: URL) async throws -> Data? } diff --git a/Sources/SublimationCore/Sublimatory.swift b/Sources/SublimationCore/Sublimatory.swift index 81c9ded..65b1f4b 100644 --- a/Sources/SublimationCore/Sublimatory.swift +++ b/Sources/SublimationCore/Sublimatory.swift @@ -34,5 +34,6 @@ public protocol Sublimatory: Sendable { } extension Sublimatory { + /// Shutdown any active services. public func shutdown() {} } diff --git a/Sources/SublimationMocks/MockError.swift b/Sources/SublimationMocks/MockError.swift index e13b594..84478bc 100644 --- a/Sources/SublimationMocks/MockError.swift +++ b/Sources/SublimationMocks/MockError.swift @@ -31,14 +31,14 @@ package enum MockError: Error { case value(T) } extension Result { package var error: (any Error)? { - guard case let .failure(failure) = self else { return nil } + guard case .failure(let failure) = self else { return nil } return failure } package func mockErrorValue() -> T? { guard let mockError = error as? MockError else { return nil } - switch mockError { case let .value(value): return value + switch mockError { case .value(let value): return value } } } diff --git a/Sources/SublimationMocks/MockTunnelClient.swift b/Sources/SublimationMocks/MockTunnelClient.swift index d8933fc..d4f1fa8 100644 --- a/Sources/SublimationMocks/MockTunnelClient.swift +++ b/Sources/SublimationMocks/MockTunnelClient.swift @@ -54,7 +54,7 @@ package actor MockTunnelClient: TunnelClient { package func getValue(ofKey key: Key, fromBucket bucketName: String) async throws -> URL { getValuesPassed.append(.init(key: key, bucketName: bucketName)) - // swiftlint:disable:next force_unwrapping + // swift-format-ignore: NeverForceUnwrap return try getValueResult!.get() }