Skip to content

Commit a048a4e

Browse files
committed
Add Version as a public API
1 parent 6ed7746 commit a048a4e

File tree

4 files changed

+14
-61
lines changed

4 files changed

+14
-61
lines changed

Diff for: Sources/Pulse/Helpers/Version.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
//
33
// Copyright (c) 2020-2024 Alexander Grebenyuk (github.com/kean).
44

5-
struct Version: Comparable, LosslessStringConvertible, Codable, Sendable {
6-
let major: Int
7-
let minor: Int
8-
let patch: Int
5+
public struct Version: Comparable, LosslessStringConvertible, Codable, Sendable {
6+
public let major: Int
7+
public let minor: Int
8+
public let patch: Int
99

10-
init(_ major: Int, _ minor: Int, _ patch: Int) {
10+
public init(_ major: Int, _ minor: Int, _ patch: Int) {
1111
precondition(major >= 0 && minor >= 0 && patch >= 0, "Negative versioning is invalid.")
1212
self.major = major
1313
self.minor = minor
@@ -16,15 +16,15 @@ struct Version: Comparable, LosslessStringConvertible, Codable, Sendable {
1616

1717
// MARK: Comparable
1818

19-
static func == (lhs: Version, rhs: Version) -> Bool {
19+
public static func == (lhs: Version, rhs: Version) -> Bool {
2020
!(lhs < rhs) && !(lhs > rhs)
2121
}
2222

23-
static func < (lhs: Version, rhs: Version) -> Bool {
23+
public static func < (lhs: Version, rhs: Version) -> Bool {
2424
(lhs.major, lhs.minor, lhs.patch) < (rhs.major, rhs.minor, rhs.patch)
2525
}
2626

27-
init(string: String) throws {
27+
public init(string: String) throws {
2828
guard let version = Version(string) else {
2929
throw LoggerStore.Error.unknownError // Should never happen
3030
}
@@ -33,7 +33,7 @@ struct Version: Comparable, LosslessStringConvertible, Codable, Sendable {
3333

3434
// MARK: LosslessStringConvertible
3535

36-
init?(_ string: String) {
36+
public init?(_ string: String) {
3737
guard string.allSatisfy(\.isASCII) else { return nil }
3838
let components = string.split(separator: ".", omittingEmptySubsequences: false)
3939
guard components.count == 3,
@@ -47,21 +47,21 @@ struct Version: Comparable, LosslessStringConvertible, Codable, Sendable {
4747
self.patch = patch
4848
}
4949

50-
var description: String {
50+
public var description: String {
5151
"\(major).\(minor).\(patch)"
5252
}
5353

5454
// MARK: Codable
5555

56-
init(from decoder: Decoder) throws {
56+
public init(from decoder: Decoder) throws {
5757
let container = try decoder.singleValueContainer()
5858
guard let version = Version(try container.decode(String.self)) else {
5959
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Invalid version number format")
6060
}
6161
self = version
6262
}
6363

64-
func encode(to encoder: Encoder) throws {
64+
public func encode(to encoder: Encoder) throws {
6565
var container = encoder.singleValueContainer()
6666
try container.encode(self.description)
6767
}

Diff for: Sources/Pulse/LoggerStore/LoggerStore.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public final class LoggerStore: @unchecked Sendable, Identifiable {
3838
public let events = PassthroughSubject<Event, Never>()
3939

4040
/// The store version.
41-
public var version: String { manifest.version.description }
41+
public var version: Version { manifest.version }
4242

4343
private var isSaveScheduled = false
4444
private let queue = DispatchQueue(label: "com.github.kean.pulse.logger-store")

Diff for: Sources/PulseUI/Features/Sessions/SessionsView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct SessionsView: View {
2525
@Environment(\.router) private var router
2626

2727
var body: some View {
28-
if let version = Version(store.version), version < Version(3, 6, 0) {
28+
if store.version < Version(3, 6, 0) {
2929
PlaceholderView(imageName: "questionmark.app", title: "Unsupported", subtitle: "This feature requires a store created by Pulse version 3.6.0 or higher").padding()
3030
} else {
3131
content

Diff for: Sources/PulseUI/Helpers/Version.swift

-47
This file was deleted.

0 commit comments

Comments
 (0)