cry-synced-db-client 0.1.217 → 0.1.219

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 +24 -21
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -7994,20 +7994,23 @@ var DexieDb = class extends Dexie {
7994
7994
  * Throws on falsy values to prevent stuck-dirty items with garbage
7995
7995
  * _id values like "undefined" / "null" that can never be uploaded.
7996
7996
  */
7997
- idToString(id) {
7997
+ idToString(id, debugContext) {
7998
7998
  if (!id && id !== void 0) {
7999
- throw new Error(
8000
- `[DexieDb.idToString] id is falsy (${JSON.stringify(id)}). This is a bug \u2014 a valid _id is required.`
7999
+ console.error(
8000
+ `[DexieDb.idToString] id is falsy (${JSON.stringify(id)}, type ${typeof id}). `,
8001
+ debugContext
8001
8002
  );
8002
8003
  }
8003
8004
  if (id === void 0) {
8004
- throw new Error(
8005
- `[DexieDb.idToString] id is undefined. This is a bug \u2014 a valid _id is required.`
8005
+ console.error(
8006
+ `[DexieDb.idToString] id is undefined. `,
8007
+ debugContext
8006
8008
  );
8007
8009
  }
8008
8010
  if (typeof id === "string" && (id === "undefined" || id === "null" || id === "0" || id === "false" || id === "")) {
8009
- throw new Error(
8010
- `[DexieDb.idToString] id is a stringified falsy value ("${id}"). This is a bug \u2014 a falsy value was coerced to string before being passed as _id.`
8011
+ console.error(
8012
+ `[DexieDb.idToString] id is a stringified falsy value ("${id}"). `,
8013
+ debugContext
8011
8014
  );
8012
8015
  }
8013
8016
  return String(id);
@@ -8020,7 +8023,7 @@ var DexieDb = class extends Dexie {
8020
8023
  }
8021
8024
  async save(collection, id, data) {
8022
8025
  const table = this.getTable(collection);
8023
- const key = this.idToString(id);
8026
+ const key = this.idToString(id, { collection, id, data, calledFrom: "DexieDb/save" });
8024
8027
  const existing = await table.get(key);
8025
8028
  if (existing) {
8026
8029
  await table.update(key, data);
@@ -8065,14 +8068,14 @@ var DexieDb = class extends Dexie {
8065
8068
  }
8066
8069
  async deleteOne(collection, id) {
8067
8070
  const table = this.getTable(collection);
8068
- const key = this.idToString(id);
8071
+ const key = this.idToString(id, { collection, id, calledFrom: "DexieDb/deleteOne" });
8069
8072
  await table.delete(key);
8070
8073
  }
8071
8074
  async deleteMany(collection, ids) {
8072
8075
  if (ids.length === 0) return;
8073
8076
  const table = this.getTable(collection);
8074
8077
  const keys = [];
8075
- for (const id of ids) keys.push(this.idToString(id));
8078
+ for (const id of ids) keys.push(this.idToString(id, { collection, id, ids, calledFrom: "DexieDb/deleteMany" }));
8076
8079
  await table.bulkDelete(keys);
8077
8080
  }
8078
8081
  async saveCollection(collection, data) {
@@ -8089,14 +8092,14 @@ var DexieDb = class extends Dexie {
8089
8092
  }
8090
8093
  async getById(collection, id) {
8091
8094
  const table = this.getTable(collection);
8092
- const key = this.idToString(id);
8095
+ const key = this.idToString(id, { collection, id, calledFrom: "DexieDb/getById" });
8093
8096
  return await table.get(key);
8094
8097
  }
8095
8098
  async getByIds(collection, ids) {
8096
8099
  if (ids.length === 0) return [];
8097
8100
  const table = this.getTable(collection);
8098
8101
  const keys = [];
8099
- for (const id of ids) keys.push(this.idToString(id));
8102
+ for (const id of ids) keys.push(this.idToString(id, { collection, ids, calledFrom: "DexieDb/getByIds" }));
8100
8103
  return await table.bulkGet(keys);
8101
8104
  }
8102
8105
  async getAll(collection) {
@@ -8149,7 +8152,7 @@ var DexieDb = class extends Dexie {
8149
8152
  }
8150
8153
  async addDirtyChange(collection, id, changes, baseMeta) {
8151
8154
  if (isMetaOnlyChanges(changes)) return;
8152
- const stringId = this.idToString(id);
8155
+ const stringId = this.idToString(id, { collection, id, changes, baseMeta, calledFrom: "DexieDb/addDirtyChange" });
8153
8156
  const existing = await this.dirtyChanges.get([collection, stringId]);
8154
8157
  const now = Date.now();
8155
8158
  if (existing) {
@@ -8176,12 +8179,12 @@ var DexieDb = class extends Dexie {
8176
8179
  if (filtered.length === 0) return;
8177
8180
  const now = Date.now();
8178
8181
  const keys = [];
8179
- for (const c of filtered) keys.push([collection, this.idToString(c.id)]);
8182
+ for (const c of filtered) keys.push([collection, this.idToString(c.id, { collection, changesList, c, calledFrom: "DexieDb/addDirtyChangesBatch" })]);
8180
8183
  const existingEntries = await this.dirtyChanges.bulkGet(keys);
8181
8184
  const toWrite = [];
8182
8185
  for (let i = 0; i < filtered.length; i++) {
8183
8186
  const changeItem = filtered[i];
8184
- const stringId = this.idToString(changeItem.id);
8187
+ const stringId = this.idToString(changeItem.id, { collection, changesList, changeItem, calledFrom: "DexieDb/addDirtyChangesBatch" });
8185
8188
  const existing = existingEntries[i];
8186
8189
  if (existing) {
8187
8190
  rebaseDirtyOnServerAdvance(existing, changeItem.changes, changeItem.baseMeta);
@@ -8203,19 +8206,19 @@ var DexieDb = class extends Dexie {
8203
8206
  await this.dirtyChanges.bulkPut(toWrite);
8204
8207
  }
8205
8208
  async getDirtyChange(collection, id) {
8206
- const stringId = this.idToString(id);
8209
+ const stringId = this.idToString(id, { collection, id, calledFrom: "DexieDb/getDirtyChange" });
8207
8210
  return this.dirtyChanges.get([collection, stringId]);
8208
8211
  }
8209
8212
  async getDirtyChangesBatch(collection, ids) {
8210
8213
  const result = /* @__PURE__ */ new Map();
8211
8214
  if (ids.length === 0) return result;
8212
8215
  const keys = [];
8213
- for (const id of ids) keys.push([collection, this.idToString(id)]);
8216
+ for (const id of ids) keys.push([collection, this.idToString(id, { collection, ids, id, calledFrom: "DexieDb/getDirtyChangesBatch" })]);
8214
8217
  const entries = await this.dirtyChanges.bulkGet(keys);
8215
8218
  for (let i = 0; i < ids.length; i++) {
8216
8219
  const entry = entries[i];
8217
8220
  if (entry) {
8218
- result.set(this.idToString(ids[i]), entry);
8221
+ result.set(this.idToString(ids[i], { collection, ids, entry, calledFrom: "DexieDb/getDirtyChangesBatch" }), entry);
8219
8222
  }
8220
8223
  }
8221
8224
  return result;
@@ -8224,7 +8227,7 @@ var DexieDb = class extends Dexie {
8224
8227
  var _a;
8225
8228
  if (ids.length === 0) return [];
8226
8229
  const keys = [];
8227
- for (const id of ids) keys.push([collection, this.idToString(id)]);
8230
+ for (const id of ids) keys.push([collection, this.idToString(id, { collection, id, ids, calledFrom: "DexieDb/incrementDirtyUploadAttempts" })]);
8228
8231
  const entries = await this.dirtyChanges.bulkGet(keys);
8229
8232
  const now = Date.now();
8230
8233
  const toUpdate = [];
@@ -8260,7 +8263,7 @@ var DexieDb = class extends Dexie {
8260
8263
  return newlyStuck;
8261
8264
  }
8262
8265
  async clearDirtyChange(collection, id) {
8263
- const stringId = this.idToString(id);
8266
+ const stringId = this.idToString(id, { collection, id, calledFrom: "DexieDb/clearDirtyChange" });
8264
8267
  await this.dirtyChanges.delete([collection, stringId]);
8265
8268
  }
8266
8269
  async clearDirtyChangesBatch(collection, ids) {
@@ -8268,7 +8271,7 @@ var DexieDb = class extends Dexie {
8268
8271
  const promises = [];
8269
8272
  for (const id of ids) {
8270
8273
  promises.push(
8271
- this.dirtyChanges.delete([collection, this.idToString(id)])
8274
+ this.dirtyChanges.delete([collection, this.idToString(id, { collection, id, ids, calledFrom: "DexieDb/clearDirtyChangesBatch" })])
8272
8275
  );
8273
8276
  }
8274
8277
  await Promise.all(promises);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.217",
3
+ "version": "0.1.219",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -33,12 +33,12 @@
33
33
  "dexie": "^4.4.4",
34
34
  "esbuild": "^0.28.1",
35
35
  "fake-indexeddb": "^6.2.5",
36
- "typescript": "^6",
37
- "vitest": "^4.1.9"
36
+ "typescript": "^7",
37
+ "vitest": "^4.1.10"
38
38
  },
39
39
  "dependencies": {
40
- "cry-db": "^2.5.6",
41
- "cry-helpers": "^2.1.206",
40
+ "cry-db": "^2.6.2",
41
+ "cry-helpers": "^2.1.207",
42
42
  "msgpackr": "^2.0.4",
43
43
  "superjson": "^2.2.6"
44
44
  },