Feat/issue 69 offline first data layer#1273
Open
strngecloud wants to merge 8 commits into
Open
Conversation
… data layer - Add Message, Thread, Contact, SenderPolicyRecord, ProofRecord, SyncCursor types - Define repository interfaces for message, thread, contact, policy, proof, and sync cursor data - Include IdempotentMutation type for replay-safe mutations - Support loading, stale, offline, and error states Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Semantic version tracking with storage key - Forward migrations with up() function - Migration registry with compareVersions logic - Safe fallback to older schema on downgrade Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Deterministic adapter: - In-memory storage seeded with mock emails - Predictable for UI testing - reset() and snapshot() methods for test fixtures Offline-first adapter: - localStorage persistence layer - In-memory cache for performance - Migrations applied on load - Graceful failure on quota limits Both support idempotent mutations and all repository interfaces. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Singleton factory pattern - switchAdapter() for testing - resetAdapter() for test cleanup - getCurrentAdapterType() and getCurrentAdapterName() for inspection - Default to offline-first adapter Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Barrel file for all data layer modules: - Type exports (Message, Thread, Contact, etc) - Repository interfaces - Adapters (DeterministicAdapter, OfflineFirstAdapter) - Factory functions (getAdapterInstance, switchAdapter, resetAdapter) - Migration functions (runMigrations, getSchemaVersion) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Exposes mailbox data and mutations through React hooks: - useMailbox() returns messages, loadingState, error, isOffline - updateMessage() for single-message updates - bulkUpdateMessages() for batch operations - deleteMessage() for removal - retry() for error recovery Handles loading states, offline detection, error management. Automatically syncs adapter messages to local state. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Import useMailbox from mailbox feature - Initialize mailbox on component mount - Sync loaded messages into local component state - Maintains backward compatibility with existing email handling Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
DeterministicAdapter tests: - Message CRUD operations and bulk updates - Get messages by folder - Contact management with email lookup - Sender policies with filtering by type - Proof records with valid/pending filtering - Sync cursor state management - Idempotent upsert operations - Reset and snapshot functionality All tests pass against the deterministic adapter for reproducible UI testing. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #69: Client Replace Mock Mailbox State with Typed Offline-First Data Layer
Summary
Implemented a complete offline-first data layer replacing hardcoded mock state. Components now depend on repository interfaces instead of seed data, supporting deterministic (test) and persistent (production) adapters.
Acceptance Criteria
✅ Components depend on interfaces, not seed data
✅ Loading, stale, offline, and error states modeled
✅ Mutations are idempotent
✅ Migration strategy exists for local schema changes
✅ UI test suite passes against deterministic adapter
Changes
src/services/data/types.tssrc/services/data/repositories.tssrc/services/data/migrations.tssrc/services/data/adapters/deterministic.tssrc/services/data/adapters/offline-first.tssrc/services/data/factory.tssrc/features/mailbox/useMailbox.tssrc/routes/index.tsxtests/unit/mailbox/adapters.test.tsBackward Compatibility
All changes are additive. Existing Email type and component APIs unchanged. Migration is opt-in via useMailbox hook.
Test Results
Closes #69