cry-synced-db-client 0.1.117 → 0.1.118

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
@@ -4484,6 +4484,31 @@ var SyncedDb = class _SyncedDb {
4484
4484
  this.syncMetaCache.clear();
4485
4485
  this._clearLastFullSync();
4486
4486
  }
4487
+ /**
4488
+ * Clear all collection data and sync metadata, then re-download
4489
+ * from server. Dirty changes (pending local writes) are preserved
4490
+ * so unsynchronized edits are NOT lost.
4491
+ *
4492
+ * Flow:
4493
+ * 1. Flush pending in-memory changes to Dexie dirty table
4494
+ * 2. Clear collection data tables in Dexie (NOT dirty changes)
4495
+ * 3. Clear in-memory collections
4496
+ * 4. Reset sync timestamps (so next sync downloads everything)
4497
+ *
4498
+ * After this method returns, call sync() to re-download all data.
4499
+ * The sync will also upload any remaining dirty items.
4500
+ */
4501
+ async refreshDatabaseFromServer() {
4502
+ await this.pendingChanges.flushAll();
4503
+ const collectionNames = Array.from(this.collections.keys());
4504
+ for (const collectionName of collectionNames) {
4505
+ await this.dexieDb.deleteCollection(collectionName);
4506
+ this.inMemManager.clearCollection(collectionName);
4507
+ await this.dexieDb.deleteSyncMeta(collectionName);
4508
+ }
4509
+ this.syncMetaCache.clear();
4510
+ this._clearLastFullSync();
4511
+ }
4487
4512
  // ==================== Object Metadata ====================
4488
4513
  getObjectMetadata(collection, _id) {
4489
4514
  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.118",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",