We need to implement the persistence layer of the new Event Platform Client library. Some general thoughts are:
- Setup a new Core Data database, like how EventLoggingService works.
- Add ability for StorageManager to hold and manipulate a buffer of Events in memory. These are events coming from the library before the library has downloaded a stream configuration, so there's no where to post these to yet.
- Add ability for StorageManager to persist, delete, and restore stored items of any type according to a key. Our queue of events in part 2 leans on this when the app closes and the user has not yet downloaded a stream configuration.
- Add ability for StorageManager to save post items (these will contain event data and meta data with stream information), update post items, purge stale post items, and pull a batch of events for the network manager to post. NetworkManager use these periodically to pull data to fetch.
- Ensure StorageManager's deviceID matches and is in sync with EventLoggingService's appInstallID.
Interface thoughts:
StorageManager func persistBuffer() func restoreBuffer() func deleteBuffer() var buffer: [Event] func appendEventToBuffer(event: Event) func removeBufferAtIndex(index: Int) //----------- func savePostItem(with body: String) //body could be a more structured object func updatePostItem(success: Bool) func deleteStalePostItems() func fetchPostItemsToPost() -> [PostItem] //-------- class Event: NSManagedObject { let stream: String let schema: String let data: [String: Any] let domain: String? } class PostItem: NSManagedObject { let body: String //again this could be a more structured set of data let recorded: Date let posted: Date let failed: Bool }