Update Models, Services + docs
Summary: - Sources: Models, Services - Docs: README - Added symbols: struct SyncConfiguration, func updateSyncConfiguration, func updateConfiguration Stats: - 4 files changed, 38 insertions(+), 4 deletions(-)
This commit is contained in:
parent
32de45f7ad
commit
bc5f1254b8
10
README.md
10
README.md
@ -47,6 +47,7 @@ These helpers are internal implementation details used by `StorageRouter`. They
|
|||||||
- **StorageError** - Comprehensive error types
|
- **StorageError** - Comprehensive error types
|
||||||
- **StorageKeyDescriptor** - Audit snapshot of a key’s storage metadata
|
- **StorageKeyDescriptor** - Audit snapshot of a key’s storage metadata
|
||||||
- **EncryptionConfiguration** - Global encryption settings (Keychain identifiers, key length)
|
- **EncryptionConfiguration** - Global encryption settings (Keychain identifiers, key length)
|
||||||
|
- **SyncConfiguration** - Global sync settings (Max automatic sync size)
|
||||||
- **AnyStorageKey** - Type-erased storage key for catalogs
|
- **AnyStorageKey** - Type-erased storage key for catalogs
|
||||||
- **AnyCodable** - Type-erased Codable for mixed-type payloads
|
- **AnyCodable** - Type-erased Codable for mixed-type payloads
|
||||||
|
|
||||||
@ -152,6 +153,15 @@ await StorageRouter.shared.updateEncryptionConfiguration(config)
|
|||||||
> [!WARNING]
|
> [!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.
|
> 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
|
```swift
|
||||||
struct RemoteKeyProvider: KeyMaterialProviding {
|
struct RemoteKeyProvider: KeyMaterialProviding {
|
||||||
func keyMaterial(for keyName: String) async throws -> Data {
|
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)
|
await EncryptionHelper.shared.updateConfiguration(configuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Updates the sync configuration.
|
||||||
|
public func updateSyncConfiguration(_ configuration: SyncConfiguration) async {
|
||||||
|
await SyncHelper.shared.updateConfiguration(configuration)
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Key Material Providers
|
// MARK: - Key Material Providers
|
||||||
|
|
||||||
/// Registers a key material provider for external encryption policies.
|
/// Registers a key material provider for external encryption policies.
|
||||||
|
|||||||
@ -9,10 +9,16 @@ actor SyncHelper {
|
|||||||
|
|
||||||
public static let shared = SyncHelper()
|
public static let shared = SyncHelper()
|
||||||
|
|
||||||
/// Maximum data size for automatic sync (100KB).
|
private var configuration: SyncConfiguration
|
||||||
public static let maxAutoSyncSize = 100_000
|
|
||||||
|
|
||||||
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
|
// MARK: - Public Interface
|
||||||
|
|
||||||
@ -40,7 +46,7 @@ actor SyncHelper {
|
|||||||
return
|
return
|
||||||
|
|
||||||
case .automaticSmall:
|
case .automaticSmall:
|
||||||
guard data.count <= Self.maxAutoSyncSize else {
|
guard data.count <= configuration.maxAutoSyncSize else {
|
||||||
throw StorageError.dataTooLargeForSync
|
throw StorageError.dataTooLargeForSync
|
||||||
}
|
}
|
||||||
try performSync(data: data, keyName: keyName)
|
try performSync(data: data, keyName: keyName)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user