diff --git a/Package.resolved b/Package.resolved index 2704ea8..9c6d02a 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,8 +6,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/combine-schedulers", "state" : { - "revision" : "5928286acce13def418ec36d05a001a9641086f2", - "version" : "1.0.3" + "revision" : "fd16d76fd8b9a976d88bfb6cacc05ca8d19c91b6", + "version" : "1.1.0" } }, { @@ -24,8 +24,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-concurrency-extras", "state" : { - "revision" : "82a4ae7170d98d8538ec77238b7eb8e7199ef2e8", - "version" : "1.3.1" + "revision" : "5a3825302b1a0d744183200915a47b508c828e6f", + "version" : "1.3.2" } }, { @@ -33,8 +33,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-dependencies", "state" : { - "revision" : "fee6aa29908a75437506ddcbe7434c460605b7e6", - "version" : "1.9.1" + "revision" : "706feb7858a7f6c242879d137b8ee30926aa5b26", + "version" : "1.12.0" } }, { @@ -42,8 +42,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/swiftlang/swift-syntax", "state" : { - "revision" : "f99ae8aa18f0cf0d53481901f88a0991dc3bd4a2", - "version" : "601.0.1" + "revision" : "2b59c0c741e9184ab057fd22950b491076d42e91", + "version" : "603.0.0" } }, { @@ -51,8 +51,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/square/Valet", "state" : { - "revision" : "05c9e514fbd352a6866877ca31326b4e0b7d6d01", - "version" : "5.0.0" + "revision" : "246baf6be3f9e3ff116dc05251a08f69dd7c7b9d", + "version" : "5.1.0" } }, { @@ -60,8 +60,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", "state" : { - "revision" : "39de59b2d47f7ef3ca88a039dff3084688fe27f4", - "version" : "1.5.2" + "revision" : "dfd70507def84cb5fb821278448a262c6ff2bbad", + "version" : "1.9.0" } } ], diff --git a/Sources/Keychain/Keychain+Dependencies.swift b/Sources/Keychain/Keychain+Dependencies.swift index a31c75f..4a49191 100644 --- a/Sources/Keychain/Keychain+Dependencies.swift +++ b/Sources/Keychain/Keychain+Dependencies.swift @@ -11,9 +11,6 @@ extension DependencyValues { } public enum KeychainDependencyKey: DependencyKey { - public static let liveValue: any Keychain = ValetKeychain() -} - -extension KeychainDependencyKey: TestDependencyKey { - public static let testValue: any Keychain = InMemoryKeychain() + public static var liveValue: any Keychain { ValetKeychain() } + public static var testValue: any Keychain { InMemoryKeychain() } } diff --git a/Sources/Keychain/Keychain.swift b/Sources/Keychain/Keychain.swift index abf263f..eaca96d 100644 --- a/Sources/Keychain/Keychain.swift +++ b/Sources/Keychain/Keychain.swift @@ -2,10 +2,8 @@ import Foundation public protocol Keychain: Sendable { - @inlinable func load(key: String) throws -> T where T: Decodable - @inlinable func save(key: String, value: T) throws where T: Encodable func delete(key: String) throws diff --git a/Sources/Keychain/KeychainConfiguration+Dependencies.swift b/Sources/Keychain/KeychainConfiguration+Dependencies.swift index 451cfa9..dbfb7a8 100644 --- a/Sources/Keychain/KeychainConfiguration+Dependencies.swift +++ b/Sources/Keychain/KeychainConfiguration+Dependencies.swift @@ -1,6 +1,5 @@ import Dependencies import Foundation -import XCTestDynamicOverlay extension DependencyValues { diff --git a/Sources/Keychain/Keychains/InMemoryKeychain.swift b/Sources/Keychain/Keychains/InMemoryKeychain.swift index 1f6fe75..89ee937 100644 --- a/Sources/Keychain/Keychains/InMemoryKeychain.swift +++ b/Sources/Keychain/Keychains/InMemoryKeychain.swift @@ -1,19 +1,15 @@ -import Dependencies import Foundation import os import Valet public final class InMemoryKeychain { - @usableFromInline - static let data = OSAllocatedUnfairLock(initialState: [String: Data]()) + let data = OSAllocatedUnfairLock(initialState: [String: Data]()) init() {} - @usableFromInline let encoder = JSONEncoder() - @usableFromInline let decoder = JSONDecoder() } @@ -22,26 +18,24 @@ public final class InMemoryKeychain { extension InMemoryKeychain: Keychain { - @inlinable public func load(key: String) throws -> T where T: Decodable { - guard let data = InMemoryKeychain.data.withLock({ $0[key] }) else { + guard let data = data.withLock({ $0[key] }) else { throw KeychainError.itemNotFound } return try decoder.decode(T.self, from: data) } - @inlinable public func save(key: String, value: T) throws where T: Encodable { - let data = try encoder.encode(value) - InMemoryKeychain.data.withLock { $0[key] = data } + let encoded = try encoder.encode(value) + data.withLock { $0[key] = encoded } } public func delete(key: String) throws { - _ = InMemoryKeychain.data.withLock { $0.removeValue(forKey: key) } + _ = data.withLock { $0.removeValue(forKey: key) } } public func allKeys() throws -> Set { - InMemoryKeychain.data.withLock { Set($0.keys) } + data.withLock { Set($0.keys) } } } diff --git a/Sources/Keychain/Keychains/ValetKeychain.swift b/Sources/Keychain/Keychains/ValetKeychain.swift index 121a4b4..65f5abb 100644 --- a/Sources/Keychain/Keychains/ValetKeychain.swift +++ b/Sources/Keychain/Keychains/ValetKeychain.swift @@ -65,13 +65,11 @@ struct ValetKeychain { extension ValetKeychain: Keychain { - @inlinable func load(key: String) throws -> T where T: Decodable { let data = try valet().object(forKey: key) return try decoder.decode(T.self, from: data) } - @inlinable func save(key: String, value: T) throws where T: Encodable { let data = try encoder.encode(value) try valet().setObject(data, forKey: key)