diff --git a/Package.swift b/Package.swift index c681a0f..941adc1 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,7 @@ let package = Package( ), ], dependencies: [ - .package(url: "https://github.com/mochidev/AsyncSequenceReader.git", .upToNextMinor(from: "0.2.1")), + .package(url: "https://github.com/mochidev/AsyncSequenceReader.git", .upToNextMinor(from: "0.3.0")), .package(url: "https://github.com/mochidev/Bytes.git", .upToNextMinor(from: "0.3.0")), ], targets: [ @@ -29,14 +29,14 @@ let package = Package( "Bytes" ], swiftSettings: [ - .enableExperimentalFeature("StrictConcurrency") + .enableExperimentalFeature("StrictConcurrency"), ] ), .testTarget( name: "CodableDatastoreTests", dependencies: ["CodableDatastore"], swiftSettings: [ - .enableExperimentalFeature("StrictConcurrency") + .enableExperimentalFeature("StrictConcurrency"), ] ), ] diff --git a/Package@swift-6.0.swift b/Package@swift-6.0.swift new file mode 100644 index 0000000..bac5a58 --- /dev/null +++ b/Package@swift-6.0.swift @@ -0,0 +1,43 @@ +// swift-tools-version: 6.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "CodableDatastore", + platforms: [ + .macOS(.v10_15), + .iOS(.v13), + .tvOS(.v13), + .watchOS(.v6), + ], + products: [ + .library( + name: "CodableDatastore", + targets: ["CodableDatastore"] + ), + ], + dependencies: [ + .package(url: "https://github.com/mochidev/AsyncSequenceReader.git", .upToNextMinor(from: "0.3.0")), + .package(url: "https://github.com/mochidev/Bytes.git", .upToNextMinor(from: "0.3.0")), + ], + targets: [ + .target( + name: "CodableDatastore", + dependencies: [ + "AsyncSequenceReader", + "Bytes" + ], + swiftSettings: [ + .swiftLanguageVersion(.v6), + ] + ), + .testTarget( + name: "CodableDatastoreTests", + dependencies: ["CodableDatastore"], + swiftSettings: [ + .swiftLanguageVersion(.v6), + ] + ), + ] +) diff --git a/README.md b/README.md index 53c2ea6..ef04185 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Please check the [releases](https://github.com/mochidev/CodableDatastore/release dependencies: [ .package( url: "https://github.com/mochidev/CodableDatastore.git", - .upToNextMinor(from: "0.3.1") + .upToNextMinor(from: "0.3.2") ), ], ... diff --git a/Sources/CodableDatastore/Indexes/IndexRepresentation.swift b/Sources/CodableDatastore/Indexes/IndexRepresentation.swift index cbac3ef..d5a66e7 100644 --- a/Sources/CodableDatastore/Indexes/IndexRepresentation.swift +++ b/Sources/CodableDatastore/Indexes/IndexRepresentation.swift @@ -276,4 +276,8 @@ public struct AnyIndexRepresentation: Hashable, Sendable { } /// Forced KeyPath conformance since Swift 5.10 doesn't support it out of the box. +#if compiler(>=6) +extension KeyPath: @unchecked @retroactive Sendable where Root: Sendable, Value: Sendable {} +#else extension KeyPath: @unchecked Sendable where Root: Sendable, Value: Sendable {} +#endif diff --git a/Sources/CodableDatastore/Indexes/Indexable.swift b/Sources/CodableDatastore/Indexes/Indexable.swift index bc8c038..52b2810 100644 --- a/Sources/CodableDatastore/Indexes/Indexable.swift +++ b/Sources/CodableDatastore/Indexes/Indexable.swift @@ -77,12 +77,21 @@ extension UInt16: DiscreteIndexable, RangedIndexable {} extension UInt32: DiscreteIndexable, RangedIndexable {} extension UInt64: DiscreteIndexable, RangedIndexable {} +#if compiler(>=6) +extension Optional: @retroactive Comparable where Wrapped: Comparable { + public static func < (lhs: Self, rhs: Self) -> Bool { + if let lhs, let rhs { return lhs < rhs } + return lhs == nil && rhs != nil + } +} +#else extension Optional: Comparable where Wrapped: Comparable { public static func < (lhs: Self, rhs: Self) -> Bool { if let lhs, let rhs { return lhs < rhs } return lhs == nil && rhs != nil } } +#endif extension Optional: DiscreteIndexable where Wrapped: DiscreteIndexable {} extension Optional: RangedIndexable where Wrapped: RangedIndexable {} diff --git a/Sources/CodableDatastore/Indexes/UUID+Comparable.swift b/Sources/CodableDatastore/Indexes/UUID+Comparable.swift index d86dea3..4b98cf5 100644 --- a/Sources/CodableDatastore/Indexes/UUID+Comparable.swift +++ b/Sources/CodableDatastore/Indexes/UUID+Comparable.swift @@ -10,12 +10,30 @@ import Foundation #if swift(<5.9) || os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(Linux) || os(Windows) /// Make UUIDs comparable, so that they can be used transparently as an index. -/// -/// - SeeAlso: https://github.com/apple/swift-foundation/blob/5388acf1d929865d4df97d3c50e4d08bc4c6bdf0/Sources/FoundationEssentials/UUID.swift#L135-L156 +#if compiler(>=6) +extension UUID: @retroactive Comparable { + @inlinable + public static func < (lhs: UUID, rhs: UUID) -> Bool { + lhs.isLessThan(rhs: rhs) + } +} +#else extension UUID: Comparable { @inlinable public static func < (lhs: UUID, rhs: UUID) -> Bool { - var leftUUID = lhs.uuid + lhs.isLessThan(rhs: rhs) + } +} +#endif +#endif + +extension UUID { + /// Make UUIDs comparable, so that they can be used transparently as an index. + /// + /// - SeeAlso: https://github.com/apple/swift-foundation/blob/5388acf1d929865d4df97d3c50e4d08bc4c6bdf0/Sources/FoundationEssentials/UUID.swift#L135-L156 + @usableFromInline + func isLessThan(rhs: UUID) -> Bool { + var leftUUID = self.uuid var rightUUID = rhs.uuid var result: Int = 0 var diff: Int = 0 @@ -36,4 +54,3 @@ extension UUID: Comparable { return result < 0 } } -#endif diff --git a/Sources/CodableDatastore/Persistence/Disk Persistence/ISO8601DateFormatter+Milliseconds.swift b/Sources/CodableDatastore/Persistence/Disk Persistence/ISO8601DateFormatter+Milliseconds.swift index d898905..1f79ddc 100644 --- a/Sources/CodableDatastore/Persistence/Disk Persistence/ISO8601DateFormatter+Milliseconds.swift +++ b/Sources/CodableDatastore/Persistence/Disk Persistence/ISO8601DateFormatter+Milliseconds.swift @@ -9,6 +9,8 @@ import Foundation extension ISO8601DateFormatter { + #if compiler(>=6) + nonisolated(unsafe) static let withMilliseconds: ISO8601DateFormatter = { let formatter = ISO8601DateFormatter() formatter.timeZone = TimeZone(secondsFromGMT: 0) @@ -21,6 +23,20 @@ extension ISO8601DateFormatter { ] return formatter }() + #else + static let withMilliseconds: ISO8601DateFormatter = { + let formatter = ISO8601DateFormatter() + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.formatOptions = [ + .withInternetDateTime, + .withDashSeparatorInDate, + .withColonSeparatorInTime, + .withTimeZone, + .withFractionalSeconds + ] + return formatter + }() + #endif } extension JSONDecoder.DateDecodingStrategy {