cry-synced-db-client 0.1.107 → 0.1.110
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 +47 -7
- package/dist/src/db/SyncedDb.d.ts +11 -0
- package/dist/src/types/I_SyncedDb.d.ts +20 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2499,14 +2499,24 @@ var _SyncEngine = class _SyncEngine {
|
|
|
2499
2499
|
const deletes = [];
|
|
2500
2500
|
const ids = dirtyChanges.map((dc) => dc._id);
|
|
2501
2501
|
const fullItems = await this.dexieDb.getByIds(collectionName, ids);
|
|
2502
|
-
for (
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
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));
|
|
2508
2516
|
if (delta) {
|
|
2509
|
-
|
|
2517
|
+
const reconstructed = __spreadProps(__spreadValues({}, delta), { _id: id });
|
|
2518
|
+
await this.dexieDb.save(collectionName, id, reconstructed);
|
|
2519
|
+
updates.push({ _id: id, delta });
|
|
2510
2520
|
}
|
|
2511
2521
|
}
|
|
2512
2522
|
}
|
|
@@ -3640,6 +3650,7 @@ var SyncedDb = class _SyncedDb {
|
|
|
3640
3650
|
);
|
|
3641
3651
|
}
|
|
3642
3652
|
await this._loadLastFullSync();
|
|
3653
|
+
await this._loadLastInitialSync();
|
|
3643
3654
|
await this.pendingChanges.recoverPendingWrites();
|
|
3644
3655
|
const allowedColls = [...this.collections.keys()].filter((n) => this.isSyncAllowed(n));
|
|
3645
3656
|
const dexieStart = Date.now();
|
|
@@ -3729,6 +3740,30 @@ var SyncedDb = class _SyncedDb {
|
|
|
3729
3740
|
/** @internal Clear on dropDatabase */
|
|
3730
3741
|
_clearLastFullSync() {
|
|
3731
3742
|
this._lastFullSyncDate = void 0;
|
|
3743
|
+
this._lastInitialSyncDate = void 0;
|
|
3744
|
+
}
|
|
3745
|
+
/**
|
|
3746
|
+
* Returns when the initial sync (first full sync after login)
|
|
3747
|
+
* last completed, or undefined if never.
|
|
3748
|
+
* Persisted in Dexie via syncMeta key `__lastInitialSync`.
|
|
3749
|
+
*/
|
|
3750
|
+
lastInitialSync() {
|
|
3751
|
+
return this._lastInitialSyncDate;
|
|
3752
|
+
}
|
|
3753
|
+
/** @internal Update after initial sync completes */
|
|
3754
|
+
async _setLastInitialSync(date) {
|
|
3755
|
+
this._lastInitialSyncDate = date;
|
|
3756
|
+
await this.dexieDb.setSyncMeta(
|
|
3757
|
+
"__lastInitialSync",
|
|
3758
|
+
date.toISOString()
|
|
3759
|
+
);
|
|
3760
|
+
}
|
|
3761
|
+
/** @internal Load cached value from Dexie */
|
|
3762
|
+
async _loadLastInitialSync() {
|
|
3763
|
+
const meta = await this.dexieDb.getSyncMeta("__lastInitialSync");
|
|
3764
|
+
if (meta == null ? void 0 : meta.lastSyncTs) {
|
|
3765
|
+
this._lastInitialSyncDate = new Date(meta.lastSyncTs);
|
|
3766
|
+
}
|
|
3732
3767
|
}
|
|
3733
3768
|
async close() {
|
|
3734
3769
|
var _a, _b;
|
|
@@ -4233,6 +4268,11 @@ var SyncedDb = class _SyncedDb {
|
|
|
4233
4268
|
await this.syncEngine.sync(calledFrom);
|
|
4234
4269
|
if (!this.syncOnlyCollections) {
|
|
4235
4270
|
const now = /* @__PURE__ */ new Date();
|
|
4271
|
+
if (!this._lastFullSyncDate) {
|
|
4272
|
+
this._setLastInitialSync(now).catch((err) => {
|
|
4273
|
+
console.error("Failed to persist lastInitialSync:", err);
|
|
4274
|
+
});
|
|
4275
|
+
}
|
|
4236
4276
|
this._setLastFullSync(now).catch((err) => {
|
|
4237
4277
|
console.error("Failed to persist lastFullSync:", err);
|
|
4238
4278
|
});
|
|
@@ -78,6 +78,7 @@ export declare class SyncedDb implements I_SyncedDb {
|
|
|
78
78
|
*/
|
|
79
79
|
flush(): Promise<void>;
|
|
80
80
|
private _lastFullSyncDate?;
|
|
81
|
+
private _lastInitialSyncDate?;
|
|
81
82
|
/**
|
|
82
83
|
* Returns when all collections were last successfully synced
|
|
83
84
|
* from the server, or undefined if never.
|
|
@@ -92,6 +93,16 @@ export declare class SyncedDb implements I_SyncedDb {
|
|
|
92
93
|
private _loadLastFullSync;
|
|
93
94
|
/** @internal Clear on dropDatabase */
|
|
94
95
|
private _clearLastFullSync;
|
|
96
|
+
/**
|
|
97
|
+
* Returns when the initial sync (first full sync after login)
|
|
98
|
+
* last completed, or undefined if never.
|
|
99
|
+
* Persisted in Dexie via syncMeta key `__lastInitialSync`.
|
|
100
|
+
*/
|
|
101
|
+
lastInitialSync(): Date | undefined;
|
|
102
|
+
/** @internal Update after initial sync completes */
|
|
103
|
+
_setLastInitialSync(date: Date): Promise<void>;
|
|
104
|
+
/** @internal Load cached value from Dexie */
|
|
105
|
+
private _loadLastInitialSync;
|
|
95
106
|
close(): Promise<void>;
|
|
96
107
|
isOnline(): boolean;
|
|
97
108
|
forceOffline(forced: boolean): void;
|
|
@@ -475,6 +475,26 @@ 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;
|
|
492
|
+
/**
|
|
493
|
+
* Returns when the initial sync (first full sync after login/reload)
|
|
494
|
+
* last completed, or undefined if never.
|
|
495
|
+
* Persisted in Dexie via syncMeta key `__lastInitialSync`.
|
|
496
|
+
*/
|
|
497
|
+
lastInitialSync(): Date | undefined;
|
|
478
498
|
/** Ali je povezan na server */
|
|
479
499
|
isOnline(): boolean;
|
|
480
500
|
/** Nastavi online/offline status. Returns a promise when going online. */
|