Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
8833fd82eb
commit
8c76769ced
10
README.md
10
README.md
@ -47,6 +47,7 @@ These helpers are internal implementation details used by `StorageRouter`. They
|
||||
- **StorageError** - Comprehensive error types
|
||||
- **StorageKeyDescriptor** - Audit snapshot of a key’s storage metadata
|
||||
- **EncryptionConfiguration** - Global encryption settings (Keychain identifiers, key length)
|
||||
- **SyncConfiguration** - Global sync settings (Max automatic sync size)
|
||||
- **AnyStorageKey** - Type-erased storage key for catalogs
|
||||
- **AnyCodable** - Type-erased Codable for mixed-type payloads
|
||||
|
||||
@ -152,6 +153,15 @@ await StorageRouter.shared.updateEncryptionConfiguration(config)
|
||||
> [!WARNING]
|
||||
> Changing the `masterKeyService` or `masterKeyAccount` in an existing app will cause the app to look for the master key in a new location. Previously encrypted data will be lost.
|
||||
|
||||
#### Global Sync Configuration
|
||||
|
||||
You can customize the maximum size for automatic synchronization:
|
||||
|
||||
```swift
|
||||
let syncConfig = SyncConfiguration(maxAutoSyncSize: 50_000) // 50KB limit
|
||||
await StorageRouter.shared.updateSyncConfiguration(syncConfig)
|
||||
```
|
||||
|
||||
```swift
|
||||
struct RemoteKeyProvider: KeyMaterialProviding {
|
||||
func keyMaterial(for keyName: String) async throws -> Data {
|
||||
|
||||
13
Sources/LocalData/Models/SyncConfiguration.swift
Normal file
13
Sources/LocalData/Models/SyncConfiguration.swift
Normal file
@ -0,0 +1,13 @@
|
||||
import Foundation
|
||||
|
||||
/// Configuration for WatchConnectivity sync operations.
|
||||
public struct SyncConfiguration: Sendable {
|
||||
/// Maximum data size for automatic sync in bytes.
|
||||
public let maxAutoSyncSize: Int
|
||||
|
||||
public init(maxAutoSyncSize: Int = 100_000) {
|
||||
self.maxAutoSyncSize = maxAutoSyncSize
|
||||
}
|
||||
|
||||
public static let `default` = SyncConfiguration()
|
||||
}
|
||||
@ -23,6 +23,11 @@ public actor StorageRouter: StorageProviding {
|
||||
await EncryptionHelper.shared.updateConfiguration(configuration)
|
||||
}
|
||||
|
||||
/// Updates the sync configuration.
|
||||
public func updateSyncConfiguration(_ configuration: SyncConfiguration) async {
|
||||
await SyncHelper.shared.updateConfiguration(configuration)
|
||||
}
|
||||
|
||||
// MARK: - Key Material Providers
|
||||
|
||||
/// Registers a key material provider for external encryption policies.
|
||||
|
||||
@ -9,10 +9,16 @@ actor SyncHelper {
|
||||
|
||||
public static let shared = SyncHelper()
|
||||
|
||||
/// Maximum data size for automatic sync (100KB).
|
||||
public static let maxAutoSyncSize = 100_000
|
||||
private var configuration: SyncConfiguration
|
||||
|
||||
private init() {}
|
||||
private init(configuration: SyncConfiguration = .default) {
|
||||
self.configuration = configuration
|
||||
}
|
||||
|
||||
/// Updates the sync configuration.
|
||||
public func updateConfiguration(_ configuration: SyncConfiguration) {
|
||||
self.configuration = configuration
|
||||
}
|
||||
|
||||
// MARK: - Public Interface
|
||||
|
||||
@ -40,7 +46,7 @@ actor SyncHelper {
|
||||
return
|
||||
|
||||
case .automaticSmall:
|
||||
guard data.count <= Self.maxAutoSyncSize else {
|
||||
guard data.count <= configuration.maxAutoSyncSize else {
|
||||
throw StorageError.dataTooLargeForSync
|
||||
}
|
||||
try performSync(data: data, keyName: keyName)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user