Skip to content

feat(sync-engine): define and inject pluggable StorageProvider interface for SyncQueue#43

Open
rohansaini-02 wants to merge 1 commit into
theapprenticeproject:mainfrom
rohansaini-02:feature/sync-engine-storage-standalone
Open

feat(sync-engine): define and inject pluggable StorageProvider interface for SyncQueue#43
rohansaini-02 wants to merge 1 commit into
theapprenticeproject:mainfrom
rohansaini-02:feature/sync-engine-storage-standalone

Conversation

@rohansaini-02

Copy link
Copy Markdown

Summary

Implementation of a decoupled StorageProvider interface for the SyncQueue. This enables SyncQueue to be used across both web (via localStorage) and mobile/React Native (via AsyncStorage/MMKV) without tightly coupling it to any specific environment.

Related Issue

Resolves #35

Problem Statement

Previously, persistToStorage() and loadFromStorage() inside SyncQueue.ts were empty placeholders. To make the sync queue modular and reusable across platforms, we needed to decouple storage operations from the queue implementation while safely handling the asynchronous initialization lifecycle.

Changes Made

  • IStorageProvider Interface: Defined a generic storage interface with getItem and setItem.
  • Dependency Injection: Refactored SyncQueue to accept an IStorageProvider instance upon initialization.
  • Robust Parsing: Added safe serialization and JSON parsing to handle malformed or corrupted queued payloads gracefully.
  • Concurrency Safety: Ensured queue writes to the storage engine are sequenced to prevent race conditions during rapid enqueue/dequeue operations.

Technical Decisions

  • Pluggable Architecture: Allowing storage overrides ensures we can seamlessly swap localStorage for AsyncStorage when porting to React Native without rewriting queue logic.
  • Promise-Based Interface: Designed IStorageProvider to return Promises to natively support asynchronous storage systems.

Testing Performed

  • Validated queue hydration logic against mock asynchronous storage providers.
  • Verified that corrupted storage payloads fallback to an empty queue without crashing.
  • Simulated concurrent queue mutations to ensure storage consistency.

Checklist

  • Code follows project conventions
  • Storage operations are decoupled
  • Changes are scoped to one problem

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.

feat(sync-engine): define and inject pluggable StorageProvider interface for SyncQueue

1 participant