This commit is contained in:
Max Goedjen 2022-01-01 18:08:59 -08:00
parent 776b4a0b97
commit 8dbca4635e
No known key found for this signature in database
GPG Key ID: E58C21DD77B9B8E8
2 changed files with 7 additions and 4 deletions

View File

@ -2,10 +2,6 @@
SecretKit is a collection of protocols describing secrets and stores. SecretKit is a collection of protocols describing secrets and stores.
## Overview
Overview
## Topics ## Topics
### Base Protocols ### Base Protocols

View File

@ -1,25 +1,32 @@
import Foundation import Foundation
import Combine import Combine
/// A "Store Store," which holds a list of type-erased stores.
public class SecretStoreList: ObservableObject { public class SecretStoreList: ObservableObject {
/// The Stores managed by the SecretStoreList.
@Published public var stores: [AnySecretStore] = [] @Published public var stores: [AnySecretStore] = []
/// A modifiable store, if one is available.
@Published public var modifiableStore: AnySecretStoreModifiable? @Published public var modifiableStore: AnySecretStoreModifiable?
private var sinks: [AnyCancellable] = [] private var sinks: [AnyCancellable] = []
/// Initializes a SecretStoreList.
public init() { public init() {
} }
/// Adds a non-type-erased SecretStore to the list.
public func add<SecretStoreType: SecretStore>(store: SecretStoreType) { public func add<SecretStoreType: SecretStore>(store: SecretStoreType) {
addInternal(store: AnySecretStore(store)) addInternal(store: AnySecretStore(store))
} }
/// Adds a non-type-erased modifiable SecretStore.
public func add<SecretStoreType: SecretStoreModifiable>(store: SecretStoreType) { public func add<SecretStoreType: SecretStoreModifiable>(store: SecretStoreType) {
let modifiable = AnySecretStoreModifiable(modifiable: store) let modifiable = AnySecretStoreModifiable(modifiable: store)
modifiableStore = modifiable modifiableStore = modifiable
addInternal(store: modifiable) addInternal(store: modifiable)
} }
/// A boolean describing whether there are any Stores available.
public var anyAvailable: Bool { public var anyAvailable: Bool {
stores.reduce(false, { $0 || $1.isAvailable }) stores.reduce(false, { $0 || $1.isAvailable })
} }