cry-synced-db-client 0.1.173 → 0.1.174

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.
Files changed (2) hide show
  1. package/dist/index.js +38 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6262,6 +6262,44 @@ var _SyncedDb = class _SyncedDb {
6262
6262
  }
6263
6263
  }
6264
6264
  });
6265
+ const dirty = await this.dexieDb.getDirty(name);
6266
+ if (dirty.length > 0) {
6267
+ const itemById = /* @__PURE__ */ new Map();
6268
+ for (let i = 0; i < allItems.length; i++) {
6269
+ itemById.set(String(allItems[i]._id), allItems[i]);
6270
+ }
6271
+ let orphanCount = 0;
6272
+ for (const dirtyItem of dirty) {
6273
+ const id = dirtyItem._id;
6274
+ if (id == null) continue;
6275
+ const idStr = String(id);
6276
+ const existing = itemById.get(idStr);
6277
+ const diff = {};
6278
+ for (const key of Object.keys(dirtyItem)) {
6279
+ if (key === "_id" || key === "_ts" || key === "_rev") continue;
6280
+ diff[key] = dirtyItem[key];
6281
+ }
6282
+ const merged = _SyncedDb.applyDiffLocally(
6283
+ existing != null ? existing : null,
6284
+ diff,
6285
+ id,
6286
+ name
6287
+ );
6288
+ if (merged._deleted || merged._archived) {
6289
+ itemById.delete(idStr);
6290
+ continue;
6291
+ }
6292
+ if (!existing) orphanCount++;
6293
+ itemById.set(idStr, merged);
6294
+ }
6295
+ if (orphanCount > 0) {
6296
+ console.warn(
6297
+ `[SyncedDb] init(${name}): ${orphanCount} dirty record(s) had no matching Dexie main row \u2014 included in in-mem pending next sync.`
6298
+ );
6299
+ }
6300
+ allItems.length = 0;
6301
+ for (const item of itemById.values()) allItems.push(item);
6302
+ }
6265
6303
  this.inMemManager.initCollection(name, allItems);
6266
6304
  const meta = await this.dexieDb.getSyncMeta(name);
6267
6305
  if (meta) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.173",
3
+ "version": "0.1.174",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",