1.6 KiB
1.6 KiB
LocalData Package Proposal
Goal
Create a single, typed, discoverable namespace for persisted app data with consistent security guarantees and clear ownership. This makes it obvious what is stored, where it is stored, how it is secured, how it is serialized, who owns it, and which platforms it belongs to or should sync to.
Package Placement
- localPackages/LocalData/
- Sources/LocalData/
- Tests/LocalDataTests/
Dependencies
- Foundation
- Security (Keychain)
- CryptoKit (encryption)
- WatchConnectivity (sync helpers)
Implemented Scope
- StorageKey protocol and StorageKeys namespace for app-defined keys
- StorageRouter actor with async set, get, and remove
- StorageDomain options for user defaults, keychain, file system, and encrypted file system
- SecurityPolicy options for none, keychain, and encrypted data
- Serializer for JSON, property lists, raw Data, or custom encode and decode
- PlatformAvailability and SyncPolicy metadata
- AnyCodable for simple mixed-type payloads
Usage Pattern
Apps extend StorageKeys with their own key types and use StorageRouter.shared. This follows the Notification.Name pattern for discoverable keys.
Sync Behavior
StorageRouter can call WCSession.updateApplicationContext for manual or automaticSmall sync policies when availability allows it. Session activation and receiving data are owned by the app.
Future Ideas (Not Implemented)
- Migration helpers for legacy storage
- Key rotation strategies for encrypted data
- Watch-optimized data representations
Any future changes should keep LocalData documentation in sync with code changes.