cry-synced-db-client 0.1.106 → 0.1.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -2385,6 +2385,7 @@ var _SyncEngine = class _SyncEngine {
|
|
|
2385
2385
|
});
|
|
2386
2386
|
}
|
|
2387
2387
|
try {
|
|
2388
|
+
const completedCollections = /* @__PURE__ */ new Set();
|
|
2388
2389
|
await this.deps.withSyncTimeout(
|
|
2389
2390
|
this.restInterface.findNewerManyStream(
|
|
2390
2391
|
syncSpecs,
|
|
@@ -2403,6 +2404,15 @@ var _SyncEngine = class _SyncEngine {
|
|
|
2403
2404
|
if (stats.updatedIds.length > 0) {
|
|
2404
2405
|
this.deps.broadcastUpdates({ [collection]: stats.updatedIds });
|
|
2405
2406
|
}
|
|
2407
|
+
if (!completedCollections.has(collection)) {
|
|
2408
|
+
completedCollections.add(collection);
|
|
2409
|
+
this.callbackSafe(this.callbacks.onSyncProgress, {
|
|
2410
|
+
collection,
|
|
2411
|
+
loaded: completedCollections.size,
|
|
2412
|
+
total: syncSpecs.length,
|
|
2413
|
+
items: items.length
|
|
2414
|
+
});
|
|
2415
|
+
}
|
|
2406
2416
|
}
|
|
2407
2417
|
),
|
|
2408
2418
|
"findNewerManyStream"
|
|
@@ -2489,14 +2499,24 @@ var _SyncEngine = class _SyncEngine {
|
|
|
2489
2499
|
const deletes = [];
|
|
2490
2500
|
const ids = dirtyChanges.map((dc) => dc._id);
|
|
2491
2501
|
const fullItems = await this.dexieDb.getByIds(collectionName, ids);
|
|
2492
|
-
for (
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2502
|
+
for (let i = 0; i < fullItems.length; i++) {
|
|
2503
|
+
const fullItem = fullItems[i];
|
|
2504
|
+
const id = ids[i];
|
|
2505
|
+
if (fullItem) {
|
|
2506
|
+
if (fullItem._deleted) {
|
|
2507
|
+
deletes.push(fullItem);
|
|
2508
|
+
} else {
|
|
2509
|
+
const delta = dirtyChangesMap.get(String(fullItem._id));
|
|
2510
|
+
if (delta) {
|
|
2511
|
+
updates.push({ _id: fullItem._id, delta });
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
} else if (id != null) {
|
|
2515
|
+
const delta = dirtyChangesMap.get(String(id));
|
|
2498
2516
|
if (delta) {
|
|
2499
|
-
|
|
2517
|
+
const reconstructed = __spreadProps(__spreadValues({}, delta), { _id: id });
|
|
2518
|
+
await this.dexieDb.save(collectionName, id, reconstructed);
|
|
2519
|
+
updates.push({ _id: id, delta });
|
|
2500
2520
|
}
|
|
2501
2521
|
}
|
|
2502
2522
|
}
|
|
@@ -3478,6 +3498,7 @@ var SyncedDb = class _SyncedDb {
|
|
|
3478
3498
|
callbacks: {
|
|
3479
3499
|
onSyncStart: config.onSyncStart ? (info) => config.onSyncStart(__spreadProps(__spreadValues({}, info), { initialSync: !this._lastFullSyncDate })) : void 0,
|
|
3480
3500
|
onSyncEnd: config.onSyncEnd,
|
|
3501
|
+
onSyncProgress: config.onSyncProgress,
|
|
3481
3502
|
onServerSyncStart: config.onServerSyncStart,
|
|
3482
3503
|
onServerSyncEnd: config.onServerSyncEnd,
|
|
3483
3504
|
onConflictResolved: config.onConflictResolved,
|
|
@@ -213,6 +213,12 @@ export interface SyncEngineCallbacks {
|
|
|
213
213
|
initialSync: boolean;
|
|
214
214
|
}) => void;
|
|
215
215
|
onSyncEnd?: (info: SyncInfo) => void;
|
|
216
|
+
onSyncProgress?: (info: {
|
|
217
|
+
collection: string;
|
|
218
|
+
loaded: number;
|
|
219
|
+
total: number;
|
|
220
|
+
items: number;
|
|
221
|
+
}) => void;
|
|
216
222
|
onServerSyncStart?: (info: {
|
|
217
223
|
calledFrom?: string;
|
|
218
224
|
collectionCount: number;
|
|
@@ -475,6 +475,20 @@ export interface I_SyncedDb {
|
|
|
475
475
|
init(): Promise<void>;
|
|
476
476
|
/** Zapre bazo in počisti resurse */
|
|
477
477
|
close(): Promise<void>;
|
|
478
|
+
/**
|
|
479
|
+
* Flush all debounced pending writes to Dexie.
|
|
480
|
+
* Resolves when all data is persisted to IndexedDB.
|
|
481
|
+
* Does NOT upload to server — call sync() for that.
|
|
482
|
+
*/
|
|
483
|
+
flush(): Promise<void>;
|
|
484
|
+
/**
|
|
485
|
+
* Returns when all collections were last successfully synced
|
|
486
|
+
* from the server, or undefined if never synced.
|
|
487
|
+
* Persisted in Dexie via syncMeta key `__lastFullSync`.
|
|
488
|
+
* Only set when syncOnlyCollections is null (all collections active).
|
|
489
|
+
* Cleared on dropDatabase().
|
|
490
|
+
*/
|
|
491
|
+
lastSuccessfulServerSync(): Date | undefined;
|
|
478
492
|
/** Ali je povezan na server */
|
|
479
493
|
isOnline(): boolean;
|
|
480
494
|
/** Nastavi online/offline status. Returns a promise when going online. */
|