diff --git a/dashboards/tracker-web/package.json b/dashboards/tracker-web/package.json index 4bab08c4..65224094 100644 --- a/dashboards/tracker-web/package.json +++ b/dashboards/tracker-web/package.json @@ -6,6 +6,7 @@ "node": "20.x" }, "scripts": { + "pretest": "corepack pnpm --dir ../.. --filter @bytelyst/api-client --filter @bytelyst/config --filter @bytelyst/errors --filter @bytelyst/logger --filter @bytelyst/telemetry-client build", "dev": "next dev --port 3003", "build": "next build --webpack", "start": "next start --port 3003", diff --git a/packages/blob/package.json b/packages/blob/package.json index 48713cda..21bf2ef8 100644 --- a/packages/blob/package.json +++ b/packages/blob/package.json @@ -14,6 +14,7 @@ "dist" ], "scripts": { + "pretest": "corepack pnpm --dir ../.. --filter @bytelyst/storage build", "build": "tsc", "test": "vitest run" }, diff --git a/packages/sync/src/engine.ts b/packages/sync/src/engine.ts index 142a6e08..d3f6f4e9 100644 --- a/packages/sync/src/engine.ts +++ b/packages/sync/src/engine.ts @@ -33,6 +33,8 @@ const LAST_SYNC_KEY = 'lastSync'; export class SyncEngineImpl implements SyncEngine { private config: SyncEngineConfig; private status: SyncStatus = 'idle'; + private queueLength = 0; + private lastSyncAt?: string; private statusListeners: Set = new Set(); private connectivityListeners: (() => void)[] = []; @@ -78,12 +80,8 @@ export class SyncEngineImpl implements SyncEngine { } await this.saveQueue(existingQueue); + this.queueLength = existingQueue.length; this.updateStatus('idle'); - - // Auto-flush if online - if (this.isOnline()) { - await this.flush(); - } } async delete(entity: EntityName, id: string): Promise { @@ -115,6 +113,7 @@ export class SyncEngineImpl implements SyncEngine { } await this.setLastSyncTime(result.timestamp); + this.lastSyncAt = result.timestamp; } catch (error) { result.success = false; this.updateStatus('error', error instanceof Error ? error.message : 'Unknown error'); @@ -152,6 +151,7 @@ export class SyncEngineImpl implements SyncEngine { private async saveQueue(queue: SyncItem[]): Promise { await this.config.storage.setItem(QUEUE_KEY, queue); + this.queueLength = queue.length; } private async pushQueue(): Promise { @@ -279,7 +279,7 @@ export class SyncEngineImpl implements SyncEngine { private setupConnectivityDetection(): void { if (typeof window !== 'undefined' && window.addEventListener) { const handleOnline = () => { - this.flush(); + void this.flush(); this.connectivityListeners.forEach(cb => cb()); }; @@ -296,7 +296,10 @@ export class SyncEngineImpl implements SyncEngine { async flush(): Promise { if (this.status === 'syncing') return; - await this.pushQueue(); + const result = await this.pushQueue(); + if (result.success && result.errors === 0) { + this.updateStatus('idle'); + } } // ─────────────────────────────────────────────────────────────────────────── @@ -304,14 +307,14 @@ export class SyncEngineImpl implements SyncEngine { // ─────────────────────────────────────────────────────────────────────────── getQueueLength(): number { - // Async getQueue but we need sync return - use cached value or 0 - return 0; // Consumer should use getStatus() for accurate count + return this.queueLength; } getStatus(): SyncStatusInfo { return { status: this.status, - queueLength: 0, // Will be populated async + queueLength: this.queueLength, + lastSyncAt: this.lastSyncAt, }; } @@ -324,7 +327,8 @@ export class SyncEngineImpl implements SyncEngine { this.status = status; const info: SyncStatusInfo = { status, - queueLength: 0, + queueLength: this.queueLength, + lastSyncAt: this.lastSyncAt, lastError: error, }; this.statusListeners.forEach(cb => cb(info)); diff --git a/packages/testing/package.json b/packages/testing/package.json index 0f48c92c..7bcb8738 100644 --- a/packages/testing/package.json +++ b/packages/testing/package.json @@ -14,6 +14,7 @@ "dist" ], "scripts": { + "pretest": "corepack pnpm --dir ../.. --filter @bytelyst/fastify-core build", "build": "tsc", "test": "vitest run" },