Skip to content

Feat/issue 69 offline first data layer#1273

Open
strngecloud wants to merge 8 commits into
Stellar-Mail:mainfrom
strngecloud:feat/issue-69-offline-first-data-layer
Open

Feat/issue 69 offline first data layer#1273
strngecloud wants to merge 8 commits into
Stellar-Mail:mainfrom
strngecloud:feat/issue-69-offline-first-data-layer

Conversation

@strngecloud

Copy link
Copy Markdown

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.

  • Types & Repositories: Message, Thread, Contact, SenderPolicyRecord, ProofRecord, SyncCursor types with full repository interfaces
  • Adapters: DeterministicAdapter (testing) and OfflineFirstAdapter (localStorage persistence)
  • React Integration: useMailbox hook with loading/error/offline states
  • Migrations: Schema versioning system for future evolution
  • Tests: 19 unit tests covering all adapter operations (all passing)

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

File Purpose
src/services/data/types.ts Domain model types
src/services/data/repositories.ts Repository interfaces
src/services/data/migrations.ts Schema versioning
src/services/data/adapters/deterministic.ts Test adapter (in-memory)
src/services/data/adapters/offline-first.ts Production adapter (localStorage)
src/services/data/factory.ts Adapter lifecycle management
src/features/mailbox/useMailbox.ts React hook for components
src/routes/index.tsx Hook integration
tests/unit/mailbox/adapters.test.ts Comprehensive tests

Backward Compatibility

All changes are additive. Existing Email type and component APIs unchanged. Migration is opt-in via useMailbox hook.

Test Results

✓ 549 tests passed (existing tests unaffected)
✓ 19 new adapter tests (all passing)
✓ Format/lint: clean

Closes #69

strngecloud and others added 8 commits June 26, 2026 00:33
… 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

client: replace mock mailbox state with a typed offline-first data layer

1 participant