cry-synced-db-client 0.1.117 → 0.1.119

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
@@ -4405,7 +4405,9 @@ var SyncedDb = class _SyncedDb {
4405
4405
  const result = {};
4406
4406
  for (const [collectionName] of this.collections) {
4407
4407
  const dirtyItems = await this.dexieDb.getDirty(collectionName);
4408
- result[collectionName] = dirtyItems;
4408
+ if (dirtyItems.length > 0) {
4409
+ result[collectionName] = dirtyItems;
4410
+ }
4409
4411
  }
4410
4412
  return result;
4411
4413
  }
@@ -4484,6 +4486,31 @@ var SyncedDb = class _SyncedDb {
4484
4486
  this.syncMetaCache.clear();
4485
4487
  this._clearLastFullSync();
4486
4488
  }
4489
+ /**
4490
+ * Clear all collection data and sync metadata, then re-download
4491
+ * from server. Dirty changes (pending local writes) are preserved
4492
+ * so unsynchronized edits are NOT lost.
4493
+ *
4494
+ * Flow:
4495
+ * 1. Flush pending in-memory changes to Dexie dirty table
4496
+ * 2. Clear collection data tables in Dexie (NOT dirty changes)
4497
+ * 3. Clear in-memory collections
4498
+ * 4. Reset sync timestamps (so next sync downloads everything)
4499
+ *
4500
+ * After this method returns, call sync() to re-download all data.
4501
+ * The sync will also upload any remaining dirty items.
4502
+ */
4503
+ async refreshDatabaseFromServer() {
4504
+ await this.pendingChanges.flushAll();
4505
+ const collectionNames = Array.from(this.collections.keys());
4506
+ for (const collectionName of collectionNames) {
4507
+ await this.dexieDb.deleteCollection(collectionName);
4508
+ this.inMemManager.clearCollection(collectionName);
4509
+ await this.dexieDb.deleteSyncMeta(collectionName);
4510
+ }
4511
+ this.syncMetaCache.clear();
4512
+ this._clearLastFullSync();
4513
+ }
4487
4514
  // ==================== Object Metadata ====================
4488
4515
  getObjectMetadata(collection, _id) {
4489
4516
  return this.inMemManager.getObjectMetadata(collection, _id);
@@ -152,6 +152,21 @@ export declare class SyncedDb implements I_SyncedDb {
152
152
  getDirty<T extends DbEntity>(): Promise<Readonly<Record<string, readonly T[]>>>;
153
153
  dropCollection(collection: string, force?: boolean): Promise<void>;
154
154
  dropDatabase(force?: boolean): Promise<void>;
155
+ /**
156
+ * Clear all collection data and sync metadata, then re-download
157
+ * from server. Dirty changes (pending local writes) are preserved
158
+ * so unsynchronized edits are NOT lost.
159
+ *
160
+ * Flow:
161
+ * 1. Flush pending in-memory changes to Dexie dirty table
162
+ * 2. Clear collection data tables in Dexie (NOT dirty changes)
163
+ * 3. Clear in-memory collections
164
+ * 4. Reset sync timestamps (so next sync downloads everything)
165
+ *
166
+ * After this method returns, call sync() to re-download all data.
167
+ * The sync will also upload any remaining dirty items.
168
+ */
169
+ refreshDatabaseFromServer(): Promise<void>;
155
170
  getObjectMetadata<M>(collection: string, _id: Id): M | undefined;
156
171
  getObjectsMetadata<M>(collection: string, _ids: Id[]): (M | undefined)[];
157
172
  setObjectMetadata<M>(collection: string, _id: Id, metadata: M): void;
@@ -664,6 +664,12 @@ export interface I_SyncedDb {
664
664
  * @throws Error if offline, forcedOffline, or sync fails (unless force=true)
665
665
  */
666
666
  dropDatabase(force?: boolean): Promise<void>;
667
+ /**
668
+ * Clear all collection data and sync metadata, preserving dirty
669
+ * changes (pending local writes). Call sync() after to re-download.
670
+ * Unlike dropDatabase(), this never discards unsynchronized edits.
671
+ */
672
+ refreshDatabaseFromServer(): Promise<void>;
667
673
  /**
668
674
  * Check if this instance is the leader tab.
669
675
  * Only the leader processes server notifications and writes to Dexie from server updates.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.117",
3
+ "version": "0.1.119",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",