From bc5f1254b8d19353025e7ae4375a57b971424daf Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 14 Jan 2026 13:39:50 -0600 Subject: [PATCH] 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(-) --- README.md | 10 ++++++++++ Sources/LocalData/Models/SyncConfiguration.swift | 13 +++++++++++++ Sources/LocalData/Services/StorageRouter.swift | 5 +++++ Sources/LocalData/Services/SyncHelper.swift | 14 ++++++++++---- 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 Sources/LocalData/Models/SyncConfiguration.swift diff --git a/README.md b/README.md index b84eda7..76e643b 100644 --- a/README.md +++ b/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 { diff --git a/Sources/LocalData/Models/SyncConfiguration.swift b/Sources/LocalData/Models/SyncConfiguration.swift new file mode 100644 index 0000000..0350d72 --- /dev/null +++ b/Sources/LocalData/Models/SyncConfiguration.swift @@ -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() +} diff --git a/Sources/LocalData/Services/StorageRouter.swift b/Sources/LocalData/Services/StorageRouter.swift index b6e559e..4cbae3a 100644 --- a/Sources/LocalData/Services/StorageRouter.swift +++ b/Sources/LocalData/Services/StorageRouter.swift @@ -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. diff --git a/Sources/LocalData/Services/SyncHelper.swift b/Sources/LocalData/Services/SyncHelper.swift index 2230f27..4917a94 100644 --- a/Sources/LocalData/Services/SyncHelper.swift +++ b/Sources/LocalData/Services/SyncHelper.swift @@ -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)