cry-synced-db-client 0.1.77 → 0.1.79

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
@@ -1869,7 +1869,7 @@ dist_default.registerCustom(
1869
1869
  {
1870
1870
  isApplicable: (v) => v instanceof ObjectId,
1871
1871
  serialize: (v) => v.toHexString(),
1872
- deserialize: (v) => new ObjectId(v)
1872
+ deserialize: (v) => v
1873
1873
  },
1874
1874
  "ObjectId"
1875
1875
  );
@@ -2061,9 +2061,16 @@ var PendingChangesManager = class {
2061
2061
  });
2062
2062
  if (existing) {
2063
2063
  Object.assign(existing, write.data);
2064
+ if (existing._id && typeof existing._id === "object") {
2065
+ existing._id = String(existing._id);
2066
+ }
2064
2067
  saveBatch.push(existing);
2065
2068
  } else {
2066
- insertBatch.push(write.data);
2069
+ const insertData = write.data;
2070
+ if (insertData._id && typeof insertData._id === "object") {
2071
+ insertData._id = String(insertData._id);
2072
+ }
2073
+ insertBatch.push(insertData);
2067
2074
  }
2068
2075
  }
2069
2076
  if (dirtyChangesBatch.length > 0) {
@@ -3925,7 +3932,7 @@ var SyncedDb = class {
3925
3932
  if (existing) {
3926
3933
  return this.save(collection, existing._id, update);
3927
3934
  } else {
3928
- const id = new ObjectId2();
3935
+ const id = new ObjectId2().toHexString();
3929
3936
  const newDoc = __spreadValues({ _id: id }, update);
3930
3937
  return this.insert(collection, newDoc);
3931
3938
  }
@@ -3933,7 +3940,7 @@ var SyncedDb = class {
3933
3940
  async insert(collection, data) {
3934
3941
  var _a;
3935
3942
  this.assertCollection(collection);
3936
- const id = data._id || new ObjectId2();
3943
+ const id = data._id ? String(data._id) : new ObjectId2().toHexString();
3937
3944
  const existing = await this.dexieDb.getById(collection, id);
3938
3945
  if (existing && !existing._deleted && !existing._archived) {
3939
3946
  console.warn(
@@ -4402,6 +4409,12 @@ var DexieDb = class extends Dexie {
4402
4409
  idToString(id) {
4403
4410
  return String(id);
4404
4411
  }
4412
+ /** Ensure _id is a primitive string. IndexedDB rejects ObjectId objects as keys. */
4413
+ ensureStringId(item) {
4414
+ if (item._id && typeof item._id === "object") {
4415
+ item._id = String(item._id);
4416
+ }
4417
+ }
4405
4418
  async save(collection, id, data) {
4406
4419
  const table = this.getTable(collection);
4407
4420
  const key = this.idToString(id);
@@ -4410,17 +4423,19 @@ var DexieDb = class extends Dexie {
4410
4423
  await table.update(key, data);
4411
4424
  } else {
4412
4425
  await table.put(__spreadValues({
4413
- _id: id
4426
+ _id: key
4414
4427
  }, data));
4415
4428
  }
4416
4429
  }
4417
4430
  async insert(collection, data) {
4418
4431
  const table = this.getTable(collection);
4432
+ this.ensureStringId(data);
4419
4433
  await table.put(data);
4420
4434
  }
4421
4435
  async saveMany(collection, items) {
4422
4436
  if (items.length === 0) return;
4423
4437
  const table = this.getTable(collection);
4438
+ for (const item of items) this.ensureStringId(item);
4424
4439
  await table.bulkPut(items);
4425
4440
  }
4426
4441
  async deleteOne(collection, id) {
@@ -4439,6 +4454,7 @@ var DexieDb = class extends Dexie {
4439
4454
  const table = this.getTable(collection);
4440
4455
  await table.clear();
4441
4456
  if (data.length > 0) {
4457
+ for (const item of data) this.ensureStringId(item);
4442
4458
  await table.bulkPut(data);
4443
4459
  }
4444
4460
  }
@@ -15,6 +15,8 @@ export declare class DexieDb extends Dexie implements I_DexieDb {
15
15
  constructor(tenant: string, collectionConfigs: CollectionConfig<any>[]);
16
16
  private getTable;
17
17
  private idToString;
18
+ /** Ensure _id is a primitive string. IndexedDB rejects ObjectId objects as keys. */
19
+ private ensureStringId;
18
20
  save<T extends LocalDbEntity>(collection: string, id: Id, data: Partial<T>): Promise<void>;
19
21
  insert<T extends LocalDbEntity>(collection: string, data: T): Promise<void>;
20
22
  saveMany<T extends LocalDbEntity>(collection: string, items: T[]): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.77",
3
+ "version": "0.1.79",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",