Skip to content

Commit

Permalink
1.0.0-beta.3 (#13)
Browse files Browse the repository at this point in the history
* Bump github.com/apple/swift-openapi-generator from 1.1.0 to 1.2.1

Bumps [github.com/apple/swift-openapi-generator](https://github.com/apple/swift-openapi-generator) from 1.1.0 to 1.2.1.
- [Release notes](https://github.com/apple/swift-openapi-generator/releases)
- [Commits](apple/swift-openapi-generator@1.1.0...1.2.1)

---
updated-dependencies:
- dependency-name: github.com/apple/swift-openapi-generator
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* adding concurrency checks:

* working on OperatingSystemVersion.swift extensions and Sendable

* Updating on github workflow

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
leogdion and dependabot[bot] authored Mar 9, 2024
1 parent 72e2805 commit 9a500e1
Show file tree
Hide file tree
Showing 18 changed files with 422 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/IPSWDownloads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
runs-on: [ubuntu-20.04, ubuntu-22.04]
swift-version: [5.9]
swift-version: [5.9, "5.10"]
steps:
- uses: actions/checkout@v4
- name: Cache swift package modules
Expand Down
2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--indent 2
--header "\n .*?\.swift\n IPSWDownloads\n\n Created by {file}\n Copyright © {year} BrightDigit.\n\n Permission is hereby granted, free of charge, to any person\n obtaining a copy of this software and associated documentation\n files (the “Software”), to deal in the Software without\n restriction, including without limitation the rights to use,\n copy, modify, merge, publish, distribute, sublicense, and/or\n sell copies of the Software, and to permit persons to whom the\n Software is furnished to do so, subject to the following\n conditions:\n \n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,\n EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n OTHER DEALINGS IN THE SOFTWARE.\n"
--header "\n {file}.swift\n IPSWDownloads\n\n Created by Leo Dion.\n Copyright © {year} BrightDigit.\n\n Permission is hereby granted, free of charge, to any person\n obtaining a copy of this software and associated documentation\n files (the “Software”), to deal in the Software without\n restriction, including without limitation the rights to use,\n copy, modify, merge, publish, distribute, sublicense, and/or\n sell copies of the Software, and to permit persons to whom the\n Software is furnished to do so, subject to the following\n conditions:\n \n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,\n EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n OTHER DEALINGS IN THE SOFTWARE.\n"
--commas inline
--disable wrapMultilineStatementBraces, redundantInternal
--extensionacl on-declarations
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-openapi-generator",
"state" : {
"revision" : "76994bfc77061c6cfa3b82415613a9dfbfb47f28",
"version" : "1.1.0"
"revision" : "7992d77065f2787e7651cf6d9be9b99ad38f5166",
"version" : "1.2.1"
}
},
{
Expand Down
10 changes: 10 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ let package = Package(
dependencies: [
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"),
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession")
],
swiftSettings: [
.enableUpcomingFeature("BareSlashRegexLiterals"),
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("ImplicitOpenExistentials"),
.enableUpcomingFeature("StrictConcurrency"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableExperimentalFeature("StrictConcurrency")
]
),
.testTarget(
Expand Down
3 changes: 1 addition & 2 deletions Scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ $MINT_CMD bootstrap -m Mintfile

if [ -z "$CI" ]; then
$MINT_RUN swiftformat .
$MINT_RUN swiftlint autocorrect
$MINT_RUN swiftlint --autocorrect
fi

if [ -z "$FORMAT_ONLY"]; then
$MINT_RUN periphery scan
$MINT_RUN swiftformat --lint $SWIFTFORMAT_OPTIONS .
$MINT_RUN swiftlint lint $SWIFTLINT_OPTIONS
fi
Expand Down
4 changes: 2 additions & 2 deletions Sources/IPSWDownloads/Board.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Board.swift
// IPSWDownloads
//
// Created by Board.swift
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -30,7 +30,7 @@
import Foundation

/// A struct representing a board with configuration details.
public struct Board {
public struct Board: Sendable, Codable, Hashable, Equatable {
/// The configuration of the board.
public let boardconfig: String

Expand Down
2 changes: 1 addition & 1 deletion Sources/IPSWDownloads/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Data.swift
// IPSWDownloads
//
// Created by Data.swift
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
Expand Down
4 changes: 2 additions & 2 deletions Sources/IPSWDownloads/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Device.swift
// IPSWDownloads
//
// Created by Device.swift
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -30,7 +30,7 @@
import Foundation

/// A struct representing an Apple device along with its firmware and supported boards.
public struct Device {
public struct Device: Sendable, Codable, Hashable, Equatable {
/// The name of the Apple device.
public let name: String

Expand Down
4 changes: 2 additions & 2 deletions Sources/IPSWDownloads/Firmware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Firmware.swift
// IPSWDownloads
//
// Created by Firmware.swift
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -30,7 +30,7 @@
import Foundation

/// A struct representing firmware details of a device.
public struct Firmware {
public struct Firmware: Sendable, Codable, Hashable, Equatable {
/// The unique identifier of the firmware.
public let identifier: String

Expand Down
4 changes: 2 additions & 2 deletions Sources/IPSWDownloads/FirmwareType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// FirmwareType.swift
// IPSWDownloads
//
// Created by FirmwareType.swift
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -30,7 +30,7 @@
import Foundation

/// Type of Firmware file.
public enum FirmwareType: String {
public enum FirmwareType: String, Sendable, Codable, Hashable, Equatable {
/// IPSW File
case ipsw
/// OTA Firmware
Expand Down
4 changes: 2 additions & 2 deletions Sources/IPSWDownloads/IPSWDownloads.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// IPSWDownloads.swift
// IPSWDownloads
//
// Created by IPSWDownloads.swift
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -32,7 +32,7 @@ import OpenAPIRuntime

/// Client for downloading current and previous versions
/// of Apple's iOS Firmware, iTunes and OTA updates.
public struct IPSWDownloads {
public struct IPSWDownloads: Sendable {
// swiftlint:disable:next force_try
private static let serverURL = try! Servers.server1()

Expand Down
175 changes: 175 additions & 0 deletions Sources/IPSWDownloads/OperatingSystemVersion+Codable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
//
// OperatingSystemVersion+Codable.swift
// IPSWDownloads
//
// 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 Foundation

extension OperatingSystemVersion:
Codable,
CustomDebugStringConvertible,
CustomStringConvertible {
public enum CodingKeys: String, CodingKey {
case majorVersion
case minorVersion
case patchVersion
}

public enum Error: Swift.Error, Equatable {
case invalidFormatString(String)
case invalidComponentsCount(Int)
}

public var debugDescription: String {
// swiftlint:disable:next line_length
"OperatingSystemVersion(majorVersion: \(majorVersion), minorVersion: \(minorVersion), patchVersion: \(patchVersion))"
}

public var description: String {
string()
}

public init(string: String) throws {
let components = Self.componentsFrom(string)

guard components.count == 2 || components.count == 3 else {
throw RuntimeError.invalidVersion(string)
}

self.init(
majorVersion: components[0],
minorVersion: components[1],
patchVersion: components.count == 3 ? components[2] : 0
)
}

private init(container: any SingleValueDecodingContainer) throws {
let intArrayResult = Result {
try container.decode(String.self)
}
.map(Self.componentsFrom(_:))
.flatMapError { _ in
Result {
try container.decode([Int].self)
}
}
try self.init(components: intArrayResult.get())
}

private init(compositeFrom decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let majorVersion: Int = try container.decode(Int.self, forKey: .majorVersion)
let minorVersion: Int = try container.decode(Int.self, forKey: .minorVersion)
let patchVersion: Int = try container.decode(Int.self, forKey: .patchVersion)
self.init(
majorVersion: majorVersion,
minorVersion: minorVersion,
patchVersion: patchVersion
)
}

public init(components: [Int]) throws {
guard components.count == 2 || components.count == 3 else {
throw Self.Error.invalidComponentsCount(components.count)
}

self.init(
majorVersion: components[0],
minorVersion: components[1],
patchVersion: components.count == 3 ? components[2] : 0
)
}

// swiftlint:disable:next function_body_length
public init(from decoder: any Decoder) throws {
let throwingError: (any Swift.Error)?
if let container = Self.singleStringDecodingContainer(from: decoder) {
do {
try self.init(container: container)
return
} catch {
throwingError = error
}
} else {
throwingError = nil
}
do {
try self.init(compositeFrom: decoder)
} catch {
throw throwingError ?? error
}
}

private static func singleStringDecodingContainer(
from decoder: any Decoder
) -> (any SingleValueDecodingContainer)? {
try? decoder.singleValueContainer()
}

private static func componentsFrom(_ string: String) -> [Int] {
string.components(separatedBy: ".").compactMap(Int.init)
}

public func encode(to encoder: any Encoder) throws {
let throwingError: any Swift.Error
do {
try encodeAsString(to: encoder)
return
} catch {
throwingError = error
}
do {
try encodeAsComposite(to: encoder)
} catch {
throw throwingError
}
}

internal func string(trimZeroPatch: Bool = false) -> String {
let values: [Int?] = [
majorVersion,
minorVersion,
(!trimZeroPatch || patchVersion > 0) ? patchVersion : nil
]
return values.compactMap {
$0?.description
}
.joined(separator: ".")
}

private func encodeAsString(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(description)
}

private func encodeAsComposite(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: Self.CodingKeys.self)
try container.encode(majorVersion, forKey: .majorVersion)
try container.encode(minorVersion, forKey: .minorVersion)
try container.encode(patchVersion, forKey: .patchVersion)
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//
// OperatingSystemVersion.swift
// OperatingSystemVersion+Hashable.swift
// IPSWDownloads
//
// Created by OperatingSystemVersion.swift
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
Expand All @@ -29,18 +29,35 @@

import Foundation

extension OperatingSystemVersion {
internal init(string: String) throws {
let components = string.components(separatedBy: ".").compactMap(Int.init)
extension OperatingSystemVersion:
Hashable,
Equatable,
Comparable {
public static func == (
lhs: OperatingSystemVersion,
rhs: OperatingSystemVersion
) -> Bool {
lhs.majorVersion == rhs.majorVersion &&
lhs.minorVersion == rhs.minorVersion &&
lhs.patchVersion == rhs.patchVersion
}

guard components.count == 2 || components.count == 3 else {
throw RuntimeError.invalidVersion(string)
public static func < (
lhs: OperatingSystemVersion,
rhs: OperatingSystemVersion
) -> Bool {
guard lhs.majorVersion == rhs.majorVersion else {
return lhs.majorVersion < rhs.majorVersion
}
guard lhs.minorVersion == rhs.minorVersion else {
return lhs.minorVersion < rhs.minorVersion
}
return lhs.patchVersion < rhs.patchVersion
}

self.init(
majorVersion: components[0],
minorVersion: components[1],
patchVersion: components.count == 3 ? components[2] : 0
)
public func hash(into hasher: inout Hasher) {
majorVersion.hash(into: &hasher)
minorVersion.hash(into: &hasher)
patchVersion.hash(into: &hasher)
}
}
Loading

0 comments on commit 9a500e1

Please sign in to comment.