diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a23541f..9c3490c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,35 +9,28 @@ on: pull_request: branches: - main - push: - branches: - - main jobs: - swiftlint: - runs-on: ubuntu-latest - container: - image: swift:5.10-noble + lint: + runs-on: macos-latest steps: - - uses: actions/checkout@v2 - - name: Set Up swiftlint - run: | - sudo apt-get update && sudo apt-get install -y unzip curl - unzip ci/swiftlint.zip -d /usr/local/bin/ - chmod +x /usr/local/bin/swiftlint - - name: Lint Using swiftlint + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set Up SwiftLint + run: brew install swiftlint + + - name: Lint Using SwiftLint run: swiftlint lint --strict . - swiftformat: - runs-on: ubuntu-latest - container: - image: swift:5.10-noble + format: + runs-on: macos-latest steps: - - uses: actions/checkout@v2 - - name: Set Up swiftformat - run: | - sudo apt-get update && sudo apt-get install -y unzip curl - unzip ci/swiftformat.zip -d /usr/local/bin/ - chmod +x /usr/local/bin/swiftformat - - name: Lint Using swiftformat - run: swiftformat --lint . + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Set Up swift-format + run: brew install swift-format + + - name: Lint Using swift-format + run: swift format lint -r . diff --git a/.swift-format b/.swift-format new file mode 100644 index 0000000..1ab0d1e --- /dev/null +++ b/.swift-format @@ -0,0 +1,7 @@ +{ + "version": 1, + "lineLength": 120, + "indentation": { + "spaces": 4 + } +} diff --git a/.swiftformat b/.swiftformat deleted file mode 100644 index b617f3f..0000000 --- a/.swiftformat +++ /dev/null @@ -1,2 +0,0 @@ ---disable wrapMultilineStatementBraces ---commas inline diff --git a/Package.swift b/Package.swift index 4192f0f..2182228 100644 --- a/Package.swift +++ b/Package.swift @@ -6,7 +6,7 @@ let package = Package( name: "VoltaserveCore", platforms: [ .iOS(.v13), - .macOS(.v12) + .macOS(.v12), ], products: [ .library( @@ -24,6 +24,6 @@ let package = Package( dependencies: ["VoltaserveCore"], path: "Tests", resources: [.process("Resources")] - ) + ), ] ) diff --git a/Sources/Account.swift b/Sources/Account.swift index 4dc43df..c752c7d 100644 --- a/Sources/Account.swift +++ b/Sources/Account.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif @@ -53,7 +54,8 @@ public struct VOAccount { } public func sendResetPasswordEmail(_ options: SendResetPasswordEmailOptions) async throws { - try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + try await withCheckedThrowingContinuation { + (continuation: CheckedContinuation) in var request = URLRequest(url: urlForSendPasswordEmail()) request.httpMethod = "POST" request.setJSONBody(options, continuation: continuation) @@ -70,7 +72,8 @@ public struct VOAccount { } public func resetPassword(_ options: ResetPasswordOptions) async throws { - try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + try await withCheckedThrowingContinuation { + (continuation: CheckedContinuation) in var request = URLRequest(url: urlForResetPassword()) request.httpMethod = "POST" request.setJSONBody(options, continuation: continuation) @@ -87,7 +90,8 @@ public struct VOAccount { } public func confirmEmail(_ options: ConfirmEmailOptions) async throws { - try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + try await withCheckedThrowingContinuation { + (continuation: CheckedContinuation) in var request = URLRequest(url: urlForConfirmEmail()) request.httpMethod = "POST" request.setJSONBody(options, continuation: continuation) @@ -174,7 +178,9 @@ public struct VOAccount { public let minNumbers: Int public let minSymbols: Int - public init(minLength: Int, minLowercase: Int, minUppercase: Int, minNumbers: Int, minSymbols: Int) { + public init( + minLength: Int, minLowercase: Int, minUppercase: Int, minNumbers: Int, minSymbols: Int + ) { self.minLength = minLength self.minLowercase = minLowercase self.minUppercase = minUppercase diff --git a/Sources/Common/Error.swift b/Sources/Common/Error.swift index b4a344c..bb73896 100644 --- a/Sources/Common/Error.swift +++ b/Sources/Common/Error.swift @@ -69,7 +69,8 @@ public struct VOErrorResponse: Decodable, Error { case userNotAllowedToDeleteInvitation = "user_not_allowed_to_delete_invitation" case userAlreadyMemberOfOrganization = "user_already_member_of_organization" case invalidApiKey = "invalid_api_key" - case pathVariablesAndBodyParametersNotConsistent = "path_variables_and_body_parameters_not_consistent" + case pathVariablesAndBodyParametersNotConsistent = + "path_variables_and_body_parameters_not_consistent" /* IdP */ case usernameUnavailable = "username_unavailable" diff --git a/Sources/Common/Request.swift b/Sources/Common/Request.swift index e716c20..147da9e 100644 --- a/Sources/Common/Request.swift +++ b/Sources/Common/Request.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif @@ -30,13 +31,15 @@ func handleJSONResponse( return } let stringData = String(data: data, encoding: .utf8) - if (200 ... 299).contains(httpResponse.statusCode) { + if (200...299).contains(httpResponse.statusCode) { do { let result = try JSONDecoder().decode(T.self, from: data) continuation.resume(returning: result) } catch { if let stringData { - print("Failed to decode JSON: \(stringData), error: \(error.localizedDescription)") + print( + "Failed to decode JSON: \(stringData), error: \(error.localizedDescription)" + ) } else { print("Failed to decode JSON with error: \(error.localizedDescription)") } @@ -45,9 +48,13 @@ func handleJSONResponse( } else { if let stringData { // swiftlint:disable:next line_length - print("Request to URL: \(httpResponse.url!), failed with status code: \(httpResponse.statusCode), data: \(stringData)") + print( + "Request to URL: \(httpResponse.url!), failed with status code: \(httpResponse.statusCode), data: \(stringData)" + ) } else { - print("Request to URL: \(httpResponse.url!), failed with status code: \(httpResponse.statusCode)") + print( + "Request to URL: \(httpResponse.url!), failed with status code: \(httpResponse.statusCode)" + ) } handleErrorResponse(continuation: continuation, data: data) } @@ -71,7 +78,7 @@ func handleDataResponse( continuation.resume(throwing: VONoDataError()) return } - if (200 ... 299).contains(httpResponse.statusCode) { + if (200...299).contains(httpResponse.statusCode) { continuation.resume(returning: data) } else { handleErrorResponse(continuation: continuation, data: data) @@ -96,7 +103,7 @@ func handleEmptyResponse( continuation.resume(throwing: VONoDataError()) return } - if (200 ... 299).contains(httpResponse.statusCode) { + if (200...299).contains(httpResponse.statusCode) { continuation.resume() } else { handleErrorResponse(continuation: continuation, data: data) diff --git a/Sources/Common/URLRequest+AuthHeader.swift b/Sources/Common/URLRequest+AuthHeader.swift index 26e495f..cc99ee2 100644 --- a/Sources/Common/URLRequest+AuthHeader.swift +++ b/Sources/Common/URLRequest+AuthHeader.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif diff --git a/Sources/Common/URLRequest+JSON.swift b/Sources/Common/URLRequest+JSON.swift index 417fbc8..87b1422 100644 --- a/Sources/Common/URLRequest+JSON.swift +++ b/Sources/Common/URLRequest+JSON.swift @@ -4,12 +4,15 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif extension URLRequest { - mutating func setJSONBody(_ body: Encodable, continuation: CheckedContinuation) { + mutating func setJSONBody( + _ body: Encodable, continuation: CheckedContinuation + ) { setValue("application/json", forHTTPHeaderField: "Content-Type") do { httpBody = try JSONEncoder().encode(body) diff --git a/Sources/File+Wait.swift b/Sources/File+Wait.swift index 43e00bb..63632f1 100644 --- a/Sources/File+Wait.swift +++ b/Sources/File+Wait.swift @@ -5,8 +5,8 @@ import Foundation -public extension VOFile { - func wait(_ id: String, sleepSeconds: UInt32 = 1) async throws -> Entity { +extension VOFile { + public func wait(_ id: String, sleepSeconds: UInt32 = 1) async throws -> Entity { var file: Entity repeat { file = try await fetch(id) diff --git a/Sources/File.swift b/Sources/File.swift index 71f7a76..be52acd 100644 --- a/Sources/File.swift +++ b/Sources/File.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif @@ -113,9 +114,12 @@ public struct VOFile { } } - public func fetchSegmentedPage(_ id: String, page: Int, fileExtension: String) async throws -> Data { + public func fetchSegmentedPage(_ id: String, page: Int, fileExtension: String) async throws + -> Data + { try await withCheckedThrowingContinuation { continuation in - var request = URLRequest(url: urlForSegmentedPage(id, page: page, fileExtension: fileExtension)) + var request = URLRequest( + url: urlForSegmentedPage(id, page: page, fileExtension: fileExtension)) request.httpMethod = "GET" request.appendAuthorizationHeader(accessToken) let task = URLSession.shared.dataTask(with: request) { data, response, error in @@ -130,13 +134,16 @@ public struct VOFile { } } - public func fetchSegmentedThumbnail(_ id: String, page: Int, fileExtension: String) async throws -> Data { + public func fetchSegmentedThumbnail(_ id: String, page: Int, fileExtension: String) async throws + -> Data + { try await withCheckedThrowingContinuation { continuation in - var request = URLRequest(url: urlForSegmentedThumbnail( - id, - page: page, - fileExtension: String(fileExtension.dropFirst()) - )) + var request = URLRequest( + url: urlForSegmentedThumbnail( + id, + page: page, + fileExtension: String(fileExtension.dropFirst()) + )) request.httpMethod = "GET" request.appendAuthorizationHeader(accessToken) let task = URLSession.shared.dataTask(with: request) { data, response, error in @@ -188,7 +195,8 @@ public struct VOFile { } public func createFile(_ options: CreateFileOptions) async throws -> Entity { - try await upload(urlForCreateFile(options), method: "POST", data: options.data, fileName: options.name) + try await upload( + urlForCreateFile(options), method: "POST", data: options.data, fileName: options.name) } public func createFolder(_ options: CreateFolderOptions) async throws -> Entity { @@ -234,13 +242,17 @@ public struct VOFile { var httpBody = Data() httpBody.append(Data("--\(boundary)\r\n".utf8)) - httpBody.append(Data("Content-Disposition: form-data; name=\"file\"; filename=\"\(fileName)\"\r\n".utf8)) + httpBody.append( + Data( + "Content-Disposition: form-data; name=\"file\"; filename=\"\(fileName)\"\r\n" + .utf8)) httpBody.append(Data("Content-Type: application/octet-stream\r\n\r\n".utf8)) httpBody.append(data) httpBody.append(Data("\r\n--\(boundary)--\r\n".utf8)) - let task = URLSession.shared.uploadTask(with: request, from: httpBody) { responseData, response, error in + let task = URLSession.shared.uploadTask(with: request, from: httpBody) { + responseData, response, error in handleJSONResponse( continuation: continuation, response: response, @@ -396,7 +408,8 @@ public struct VOFile { } public func grantUserPermission(_ options: GrantUserPermissionOptions) async throws { - try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + try await withCheckedThrowingContinuation { + (continuation: CheckedContinuation) in var request = URLRequest(url: urlForGrantUserPermission()) request.httpMethod = "POST" request.appendAuthorizationHeader(accessToken) @@ -414,7 +427,8 @@ public struct VOFile { } public func revokeUserPermission(_ options: RevokeUserPermissionOptions) async throws { - try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + try await withCheckedThrowingContinuation { + (continuation: CheckedContinuation) in var request = URLRequest(url: urlForRevokeUserPermission()) request.httpMethod = "POST" request.appendAuthorizationHeader(accessToken) @@ -432,7 +446,8 @@ public struct VOFile { } public func grantGroupPermission(_ options: GrantGroupPermissionOptions) async throws { - try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + try await withCheckedThrowingContinuation { + (continuation: CheckedContinuation) in var request = URLRequest(url: urlForGrantGroupPermission()) request.httpMethod = "POST" request.appendAuthorizationHeader(accessToken) @@ -450,7 +465,8 @@ public struct VOFile { } public func revokeGroupPermission(_ options: RevokeGroupPermissionOptions) async throws { - try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + try await withCheckedThrowingContinuation { + (continuation: CheckedContinuation) in var request = URLRequest(url: urlForRevokeGroupPermission()) request.httpMethod = "POST" request.appendAuthorizationHeader(accessToken) @@ -526,7 +542,7 @@ public struct VOFile { urlComponents.queryItems = [ .init(name: "type", value: FileType.file.rawValue), .init(name: "workspace_id", value: options.workspaceID), - .init(name: "name", value: options.name) + .init(name: "name", value: options.name), ] if let parentID = options.parentID { urlComponents.queryItems?.append(.init(name: "parent_id", value: parentID)) @@ -540,7 +556,7 @@ public struct VOFile { urlComponents.queryItems = [ .init(name: "type", value: FileType.folder.rawValue), .init(name: "workspace_id", value: options.workspaceID), - .init(name: "name", value: options.name) + .init(name: "name", value: options.name), ] if let parentID = options.parentID { urlComponents.queryItems?.append(URLQueryItem(name: "parent_id", value: parentID)) @@ -550,28 +566,27 @@ public struct VOFile { } public func urlForOriginal(_ id: String, fileExtension: String) -> URL { - URL(string: "\(urlForID(id))/original.\(fileExtension)?" + - "access_token=\(accessToken)")! + URL(string: "\(urlForID(id))/original.\(fileExtension)?" + "access_token=\(accessToken)")! } public func urlForPreview(_ id: String, fileExtension: String) -> URL { - URL(string: "\(urlForID(id))/preview.\(fileExtension)?" + - "access_token=\(accessToken)")! + URL(string: "\(urlForID(id))/preview.\(fileExtension)?" + "access_token=\(accessToken)")! } public func urlForThumbnail(_ id: String, fileExtension: String) -> URL { - URL(string: "\(urlForID(id))/thumbnail.\(fileExtension)?" + - "access_token=\(accessToken)")! + URL(string: "\(urlForID(id))/thumbnail.\(fileExtension)?" + "access_token=\(accessToken)")! } public func urlForSegmentedPage(_ id: String, page: Int, fileExtension: String) -> URL { - URL(string: "\(urlForID(id))/segmentation/pages/\(page).\(fileExtension)?" + - "access_token=\(accessToken)")! + URL( + string: "\(urlForID(id))/segmentation/pages/\(page).\(fileExtension)?" + + "access_token=\(accessToken)")! } public func urlForSegmentedThumbnail(_ id: String, page: Int, fileExtension: String) -> URL { - URL(string: "\(urlForID(id))/segmentation/thumbnails/\(page).\(fileExtension)?" + - "access_token=\(accessToken)")! + URL( + string: "\(urlForID(id))/segmentation/thumbnails/\(page).\(fileExtension)?" + + "access_token=\(accessToken)")! } public func urlForUserPermissions(_ id: String) -> URL { diff --git a/Sources/Group.swift b/Sources/Group.swift index 8a293ec..7ddacf4 100644 --- a/Sources/Group.swift +++ b/Sources/Group.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif @@ -129,7 +130,8 @@ public struct VOGroup { } public func addMember(_ id: String, options: AddMemberOptions) async throws { - try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + try await withCheckedThrowingContinuation { + (continuation: CheckedContinuation) in var request = URLRequest(url: urlForMembers(id)) request.httpMethod = "POST" request.appendAuthorizationHeader(accessToken) @@ -147,7 +149,8 @@ public struct VOGroup { } public func removeMember(_ id: String, options: AddMemberOptions) async throws { - try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + try await withCheckedThrowingContinuation { + (continuation: CheckedContinuation) in var request = URLRequest(url: urlForMembers(id)) request.httpMethod = "POST" request.appendAuthorizationHeader(accessToken) diff --git a/Sources/IdentityUser.swift b/Sources/IdentityUser.swift index 339acf1..4264888 100644 --- a/Sources/IdentityUser.swift +++ b/Sources/IdentityUser.swift @@ -35,7 +35,8 @@ public struct VOIdentityUser { } public func delete(_ options: DeleteOptions) async throws { - try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + try await withCheckedThrowingContinuation { + (continuation: CheckedContinuation) in var request = URLRequest(url: urlForMe()) request.httpMethod = "DELETE" request.appendAuthorizationHeader(accessToken) @@ -90,7 +91,9 @@ public struct VOIdentityUser { } } - public func updateEmailConfirmation(_ options: UpdateEmailConfirmationOptions) async throws -> Entity { + public func updateEmailConfirmation(_ options: UpdateEmailConfirmationOptions) async throws + -> Entity + { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: urlForUpdateEmailConfirmation()) request.httpMethod = "POST" @@ -128,7 +131,9 @@ public struct VOIdentityUser { } } - public func updatePicture(data: Data, onProgress: ((Double) -> Void)? = nil) async throws -> Entity { + public func updatePicture(data: Data, onProgress: ((Double) -> Void)? = nil) async throws + -> Entity + { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: urlForUpdatePicture()) request.httpMethod = "POST" @@ -142,13 +147,15 @@ public struct VOIdentityUser { var httpBody = Data() httpBody.append(Data("--\(boundary)\r\n".utf8)) - httpBody.append(Data("Content-Disposition: form-data; name=\"file\"; filename=\"file\"\r\n".utf8)) + httpBody.append( + Data("Content-Disposition: form-data; name=\"file\"; filename=\"file\"\r\n".utf8)) httpBody.append(Data("Content-Type: application/octet-stream\r\n\r\n".utf8)) httpBody.append(data) httpBody.append(Data("\r\n--\(boundary)--\r\n".utf8)) - let task = URLSession.shared.uploadTask(with: request, from: httpBody) { responseData, response, error in + let task = URLSession.shared.uploadTask(with: request, from: httpBody) { + responseData, response, error in handleJSONResponse( continuation: continuation, response: response, diff --git a/Sources/Insights.swift b/Sources/Insights.swift index 125b098..e4bd715 100644 --- a/Sources/Insights.swift +++ b/Sources/Insights.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif @@ -37,7 +38,9 @@ public struct VOInsights { } } - public func fetchEntityList(_ id: String, options: ListEntitiesOptions) async throws -> EntityList { + public func fetchEntityList(_ id: String, options: ListEntitiesOptions) async throws + -> EntityList + { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: urlForListEntities(id, options: options)) request.httpMethod = "GET" @@ -55,7 +58,9 @@ public struct VOInsights { } } - public func fetchEntityProbe(_ id: String, options: ListEntitiesOptions) async throws -> EntityProbe { + public func fetchEntityProbe(_ id: String, options: ListEntitiesOptions) async throws + -> EntityProbe + { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: urlForProbeEntities(id, options: options)) request.httpMethod = "GET" diff --git a/Sources/Invitation.swift b/Sources/Invitation.swift index 78377c5..c879f50 100644 --- a/Sources/Invitation.swift +++ b/Sources/Invitation.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif diff --git a/Sources/Mosaic.swift b/Sources/Mosaic.swift index 0a2a913..bd0f028 100644 --- a/Sources/Mosaic.swift +++ b/Sources/Mosaic.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif @@ -44,13 +45,14 @@ public struct VOMosaic { fileExtension: String ) async throws -> Data { try await withCheckedThrowingContinuation { continuation in - var request = URLRequest(url: urlForTile( - id, - zoomLevel: zoomLevel, - row: row, - column: column, - fileExtension: fileExtension - )) + var request = URLRequest( + url: urlForTile( + id, + zoomLevel: zoomLevel, + row: row, + column: column, + fileExtension: fileExtension + )) request.httpMethod = "GET" request.appendAuthorizationHeader(accessToken) let task = URLSession.shared.dataTask(with: request) { data, response, error in @@ -122,9 +124,10 @@ public struct VOMosaic { column: Int, fileExtension: String ) -> URL { - URL(string: "\(urlForFile(id))/zoom_level/\(zoomLevel.index)" + - "/row/\(row)/column/\(column)/extension/\(fileExtension)?" + - "access_token=\(accessToken)")! + URL( + string: "\(urlForFile(id))/zoom_level/\(zoomLevel.index)" + + "/row/\(row)/column/\(column)/extension/\(fileExtension)?" + + "access_token=\(accessToken)")! } // MARK: - Types @@ -135,7 +138,9 @@ public struct VOMosaic { public var snapshot: VOSnapshot.Entity? public var metadata: Metadata - public init(isAvailable: Bool, isOutdated: Bool, snapshot: VOSnapshot.Entity?, metadata: Metadata) { + public init( + isAvailable: Bool, isOutdated: Bool, snapshot: VOSnapshot.Entity?, metadata: Metadata + ) { self.isAvailable = isAvailable self.isOutdated = isOutdated self.snapshot = snapshot diff --git a/Sources/Organization.swift b/Sources/Organization.swift index 50a19b8..5926b34 100644 --- a/Sources/Organization.swift +++ b/Sources/Organization.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif @@ -146,7 +147,8 @@ public struct VOOrganization { } public func removeMember(_ id: String, options: RemoveMemberOptions) async throws { - try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in + try await withCheckedThrowingContinuation { + (continuation: CheckedContinuation) in var request = URLRequest(url: urlForMembers(id)) request.httpMethod = "DELETE" request.appendAuthorizationHeader(accessToken) diff --git a/Sources/Permission.swift b/Sources/Permission.swift index ecd61f3..ddf058f 100644 --- a/Sources/Permission.swift +++ b/Sources/Permission.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif diff --git a/Sources/Snapshot.swift b/Sources/Snapshot.swift index 1d99a14..f7fa9d5 100644 --- a/Sources/Snapshot.swift +++ b/Sources/Snapshot.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif diff --git a/Sources/Storage.swift b/Sources/Storage.swift index 1b30a64..7ffcb4e 100644 --- a/Sources/Storage.swift +++ b/Sources/Storage.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif diff --git a/Sources/Task+Wait.swift b/Sources/Task+Wait.swift index 65e686a..8361d08 100644 --- a/Sources/Task+Wait.swift +++ b/Sources/Task+Wait.swift @@ -5,8 +5,8 @@ import Foundation -public extension VOTask { - func wait(_ id: String, sleepSeconds: UInt32 = 1) async throws -> Entity? { +extension VOTask { + public func wait(_ id: String, sleepSeconds: UInt32 = 1) async throws -> Entity? { var task: Entity? repeat { do { @@ -30,7 +30,7 @@ public extension VOTask { return task } - enum RuntimeError: Error { + public enum RuntimeError: Error { case message(String) } } diff --git a/Sources/Task.swift b/Sources/Task.swift index c08e9f9..2eba0bd 100644 --- a/Sources/Task.swift +++ b/Sources/Task.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif diff --git a/Sources/Token.swift b/Sources/Token.swift index c5ecba0..4499c63 100644 --- a/Sources/Token.swift +++ b/Sources/Token.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif @@ -21,7 +22,8 @@ public struct VOToken { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: url()) request.httpMethod = "POST" - request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") + request.setValue( + "application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") request.httpBody = Data(options.urlEncodedString.utf8) let task = URLSession.shared.dataTask(with: request) { data, response, error in handleJSONResponse( @@ -90,7 +92,8 @@ public struct VOToken { // Explicitly replace spaces with + and encode & characters var percentEncodedQuery = components.percentEncodedQuery ?? "" - percentEncodedQuery = percentEncodedQuery + percentEncodedQuery = + percentEncodedQuery .replacingOccurrences(of: "+", with: "%2B") .replacingOccurrences(of: "%20", with: "+") return percentEncodedQuery diff --git a/Sources/User.swift b/Sources/User.swift index e652db7..5f90586 100644 --- a/Sources/User.swift +++ b/Sources/User.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif @@ -149,7 +150,8 @@ public struct VOUser { items.append(.init(name: "group_id", value: groupID)) } if let excludeGroupMembers { - items.append(.init(name: "exclude_group_members", value: String(excludeGroupMembers))) + items.append( + .init(name: "exclude_group_members", value: String(excludeGroupMembers))) } if let size { items.append(.init(name: "size", value: String(size))) diff --git a/Sources/Workspace.swift b/Sources/Workspace.swift index 20b650b..8bc61f1 100644 --- a/Sources/Workspace.swift +++ b/Sources/Workspace.swift @@ -4,6 +4,7 @@ // included in the file LICENSE in the root of this repository. import Foundation + #if canImport(FoundationNetworking) import FoundationNetworking #endif @@ -111,7 +112,9 @@ public struct VOWorkspace { } } - public func patchStorageCapacity(_ id: String, options: PatchStorageCapacityOptions) async throws -> Entity { + public func patchStorageCapacity(_ id: String, options: PatchStorageCapacityOptions) + async throws -> Entity + { try await withCheckedThrowingContinuation { continuation in var request = URLRequest(url: urlForStorageCapacity(id)) request.httpMethod = "PATCH" @@ -189,7 +192,9 @@ public struct VOWorkspace { public let organizationID: String public let storageCapacity: Int - public init(name: String, image: String? = nil, organizationID: String, storageCapacity: Int) { + public init( + name: String, image: String? = nil, organizationID: String, storageCapacity: Int + ) { self.name = name self.image = image self.organizationID = organizationID diff --git a/Tests/AccountTests.swift b/Tests/AccountTests.swift index b49518d..2d7130a 100644 --- a/Tests/AccountTests.swift +++ b/Tests/AccountTests.swift @@ -3,9 +3,10 @@ // Use of this software is governed by the MIT License // included in the file LICENSE in the root of this repository. -@testable import VoltaserveCore import XCTest +@testable import VoltaserveCore + final class AccountTests: XCTestCase { var factory: DisposableFactory? diff --git a/Tests/Common/TokenFactory.swift b/Tests/Common/TokenFactory.swift index 59a9921..e987438 100644 --- a/Tests/Common/TokenFactory.swift +++ b/Tests/Common/TokenFactory.swift @@ -14,12 +14,13 @@ class TokenFactory { } init(_ credentials: Config.Credentials) async throws { - value = try await VOToken(baseURL: config.idpURL).exchange(.init( - grantType: .password, - username: credentials.username, - password: credentials.password, - refreshToken: nil, - locale: nil - )) + value = try await VOToken(baseURL: config.idpURL).exchange( + .init( + grantType: .password, + username: credentials.username, + password: credentials.password, + refreshToken: nil, + locale: nil + )) } } diff --git a/Tests/Common/XCTestCase+Bundle.swift b/Tests/Common/XCTestCase+Bundle.swift index f0791d0..f15437e 100644 --- a/Tests/Common/XCTestCase+Bundle.swift +++ b/Tests/Common/XCTestCase+Bundle.swift @@ -11,10 +11,11 @@ extension XCTestCase { #if os(Linux) URL(fileURLWithPath: "Tests/Resources/\(resource).\(fileExtension)") #else - Bundle(url: Bundle(for: type(of: self)).url( - forResource: "VoltaserveCore_VoltaserveTests", - withExtension: "bundle" - )!)!.url(forResource: resource, withExtension: fileExtension) + Bundle( + url: Bundle(for: type(of: self)).url( + forResource: "VoltaserveCore_VoltaserveTests", + withExtension: "bundle" + )!)!.url(forResource: resource, withExtension: fileExtension) #endif } } diff --git a/Tests/FileTests.swift b/Tests/FileTests.swift index b7228b1..7a2d5a6 100644 --- a/Tests/FileTests.swift +++ b/Tests/FileTests.swift @@ -3,9 +3,10 @@ // Use of this software is governed by the MIT License // included in the file LICENSE in the root of this repository. -@testable import VoltaserveCore import XCTest +@testable import VoltaserveCore + final class FileTests: XCTestCase { var factory: DisposableFactory? var otherFactory: DisposableFactory? @@ -19,28 +20,30 @@ final class FileTests: XCTestCase { let client = factory.client.file let organization = try await factory.organization(.init(name: "Test Organization")) - let workspace = try await factory.workspace(.init( - name: "Test Workspace", - organizationID: organization.id, - storageCapacity: 100_000_000 - )) + let workspace = try await factory.workspace( + .init( + name: "Test Workspace", + organizationID: organization.id, + storageCapacity: 100_000_000 + )) /* Create files */ var options: [VOFile.CreateFileOptions] = [] - for index in 0 ..< 6 { - options.append(.init( - workspaceID: workspace.id, - name: "Test File \(index).txt", - data: Data("Test Content \(index)".utf8) - )) + for index in 0..<6 { + options.append( + .init( + workspaceID: workspace.id, + name: "Test File \(index).txt", + data: Data("Test Content \(index)".utf8) + )) } var files: [VOFile.Entity] = [] - for index in 0 ..< options.count { + for index in 0..