-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
304741e
commit 576e625
Showing
14 changed files
with
148 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,55 @@ | ||
import Foundation | ||
import Observation | ||
import Synchronization | ||
|
||
/// A "Store Store," which holds a list of type-erased stores. | ||
@Observable public final class SecretStoreList: ObservableObject { | ||
@Observable public final class SecretStoreList: Sendable { | ||
|
||
/// The Stores managed by the SecretStoreList. | ||
public var stores: [AnySecretStore] = [] | ||
public var stores: [AnySecretStore] { | ||
__stores.withLock { $0 } | ||
} | ||
private let __stores: Mutex<[AnySecretStore]> = .init([]) | ||
|
||
/// A modifiable store, if one is available. | ||
public var modifiableStore: AnySecretStoreModifiable? | ||
public var modifiableStore: AnySecretStoreModifiable? { | ||
__modifiableStore.withLock { $0 } | ||
} | ||
private let __modifiableStore: Mutex<AnySecretStoreModifiable?> = .init(nil) | ||
|
||
/// Initializes a SecretStoreList. | ||
public init() { | ||
} | ||
|
||
/// Adds a non-type-erased SecretStore to the list. | ||
public func add<SecretStoreType: SecretStore>(store: SecretStoreType) { | ||
stores.append(AnySecretStore(store)) | ||
__stores.withLock { | ||
$0.append(AnySecretStore(store)) | ||
} | ||
} | ||
|
||
/// Adds a non-type-erased modifiable SecretStore. | ||
public func add<SecretStoreType: SecretStoreModifiable>(store: SecretStoreType) { | ||
let modifiable = AnySecretStoreModifiable(modifiable: store) | ||
modifiableStore = modifiable | ||
stores.append(modifiable) | ||
__modifiableStore.withLock { | ||
$0 = modifiable | ||
} | ||
__stores.withLock { | ||
$0.append(modifiable) | ||
} | ||
} | ||
|
||
/// A boolean describing whether there are any Stores available. | ||
public var anyAvailable: Bool { | ||
stores.reduce(false, { $0 || $1.isAvailable }) | ||
__stores.withLock { | ||
$0.reduce(false, { $0 || $1.isAvailable }) | ||
} | ||
} | ||
|
||
public var allSecrets: [AnySecret] { | ||
stores.flatMap(\.secrets) | ||
__stores.withLock { | ||
$0.flatMap(\.secrets) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.