← Tasks
[DM-08] Offline-capable local storage with sync
completedcode_genP2
Description
## DM-08: Offline-capable local storage with sync
Section: Data Model | Milestone: M3 | Owner: None
### Failing Tests
- **offline_storage_lib** (grep): Pattern `realm|sqlite|watermelondb` in `src/lib/offlineSync.ts` (need 1+ matches)
### Acceptance Criteria
- File matching `src/lib/offlineSync.ts` must contain pattern `realm|sqlite|watermelondb`
### Codebase Conventions
- Trilingual comments: // EN: ... // VI: ... // ES: ...
- SPEC section refs in comments
- Zod at module level with .safeParse()
- (supabase as any) with eslint-disable
- NextResponse.json() responses
- Error format: { error: 'message' }
Assignee
-
Claimed By
Terminal Lu
Created
23d ago
Completed
1d ago
Quality
Overall
97%
Pass
PASS
Graded By
-
Graded At
-
Cost
Input Tokens
-
Output Tokens
-
Est. USD
-
Result
{
"code": "File: ntq-poc/src/lib/offlineSync.ts\n\nOffline-capable local storage with WatermelonDB + Supabase sync — SPEC DM-08, M3.\n\nAcceptance criteria met:\n- Contains `watermelondb` references (WatermelonDB schema, WATERMELONDB_SCHEMA_VERSION)\n- Pattern match: `realm|sqlite|watermelondb` → watermelondb present\n\nContents:\n1. **Zod Schemas** (module-level, .safeParse()):\n - SyncStatusSchema (idle/syncing/error/offline/completed)\n - SyncDirectionSchema (push/pull/bidirectional)\n - ConflictResolutionSchema (server_wins/client_wins/latest_wins/manual)\n - SyncConfigSchema (intervalMs, conflictResolution, maxRetries, batchSize, tables)\n - SyncResultSchema (pushed/pulled/conflicts/errors/durationMs)\n - OfflineQueueItemSchema (table, operation, payload, retries)\n\n2. **WatermelonDB Table Schemas**: items (12 cols), carts (6 cols), orders (9 cols), profiles (5 cols) — all with server_id indexed + synced_at\n\n3. **Offline Queue**: enqueueOfflineOperation(), getOfflineQueue(), clearOfflineQueue(), removeFromQueue() — {data, error} pattern\n\n4. **OfflineSyncEngine class**:\n - start()/stop() — automatic interval-based sync\n - sync(direction) — Phase 1: push offline queue in batches, Phase 2: pull server changes\n - onSyncComplete() listener with unsubscribe\n - Conflict counting, retry with maxRetries, error collection\n\n5. **Singleton**: getOfflineSyncEngine() — lazy init matching stripe.ts pattern\n\nConventions: Trilingual (EN/VI/ES), Zod .safeParse(), {data, error}, eslint-disable for (supabase as any).",
"content": "File: ntq-poc/src/lib/offlineSync.ts\n\nOffline-capable local storage with WatermelonDB + Supabase sync — SPEC DM-08, M3.\n\nAcceptance criteria met:\n- Contains `watermelondb` references (WatermelonDB schema, WATERMELONDB_SCHEMA_VERSION)\n- Pattern match: `realm|sqlite|watermelondb` → watermelondb present\n\nContents:\n1. **Zod Schemas** (module-level, .safeParse()):\n - SyncStatusSchema (idle/syncing/error/offline/completed)\n - SyncDirectionSchema (push/pull/bidirectional)\n - ConflictResolutionSchema (server_wins/client_wins/latest_wins/manual)\n - SyncConfigSchema (intervalMs, conflictResolution, maxRetries, batchSize, tables)\n - SyncResultSchema (pushed/pulled/conflicts/errors/durationMs)\n - OfflineQueueItemSchema (table, operation, payload, retries)\n\n2. **WatermelonDB Table Schemas**: items (12 cols), carts (6 cols), orders (9 cols), profiles (5 cols) — all with server_id indexed + synced_at\n\n3. **Offline Queue**: enqueueOfflineOperation(), getOfflineQueue(), clearOfflineQueue(), removeFromQueue() — {data, error} pattern\n\n4. **OfflineSyncEngine class**:\n - start()/stop() — automatic interval-based sync\n - sync(direction) — Phase 1: push offline queue in batches, Phase 2: pull server changes\n - onSyncComplete() listener with unsubscribe\n - Conflict counting, retry with maxRetries, error collection\n\n5. **Singleton**: getOfflineSyncEngine() — lazy init matching stripe.ts pattern\n\nConventions: Trilingual (EN/VI/ES), Zod .safeParse(), {data, error}, eslint-disable for (supabase as any)."
}Audit Trail (2)
1d agotask_completedTerminal Lu
1d agotask_claimedTerminal Lu
Task ID: a99d0d39-9645-44fb-97e8-0098740a7633