cry-synced-db-client 0.1.216 → 0.1.217

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
@@ -7684,17 +7684,30 @@ var _SyncedDb = class _SyncedDb {
7684
7684
  }
7685
7685
  }
7686
7686
  }
7687
- /** Stringify an Id parameter (ObjectId → hex string). */
7687
+ /**
7688
+ * Stringify an Id parameter (ObjectId → hex string).
7689
+ *
7690
+ * Throws when `id` is falsy (null, undefined, 0, "", false) or is a
7691
+ * stringified-falsy value ("undefined", "null", "0", "false", "").
7692
+ * Passing a garbage _id creates a stuck dirty item that can never be
7693
+ * uploaded (server rejects it) and can never be auto-healed (library
7694
+ * doesn't know the correct _id). Fail-fast prevents silent data loss.
7695
+ */
7688
7696
  normalizeId(id, method, collection) {
7689
7697
  if (!id && id !== void 0) {
7690
- console.error(
7691
- `[SyncedDb] SyncedDb.${method != null ? method : "?"}("${collection != null ? collection : "?"}"): id parameter is falsy (${JSON.stringify(id)}). This is a bug \u2014 the caller must provide a valid _id.`
7692
- );
7698
+ const msg = `[SyncedDb] SyncedDb.${method != null ? method : "?"}("${collection != null ? collection : "?"}"): id parameter is falsy (${JSON.stringify(id)}). This is a bug \u2014 the caller must provide a valid _id.`;
7699
+ console.error(msg);
7700
+ throw new Error(msg);
7693
7701
  }
7694
7702
  if (typeof id === "string" && _SyncedDb.STRINGIFIED_FALSY.has(id)) {
7695
- console.error(
7696
- `[SyncedDb] SyncedDb.${method != null ? method : "?"}("${collection != null ? collection : "?"}"): id is a stringified falsy value ("${id}"). This is a bug \u2014 a falsy value was coerced to string before being passed as _id.`
7697
- );
7703
+ const msg = `[SyncedDb] SyncedDb.${method != null ? method : "?"}("${collection != null ? collection : "?"}"): id is a stringified falsy value ("${id}"). This is a bug \u2014 a falsy value was coerced to string before being passed as _id.`;
7704
+ console.error(msg);
7705
+ throw new Error(msg);
7706
+ }
7707
+ if (id === void 0) {
7708
+ const msg = `[SyncedDb] SyncedDb.${method != null ? method : "?"}("${collection != null ? collection : "?"}"): id parameter is undefined. This is a bug \u2014 the caller must provide a valid _id.`;
7709
+ console.error(msg);
7710
+ throw new Error(msg);
7698
7711
  }
7699
7712
  return typeof id === "object" && id !== null ? String(id) : id;
7700
7713
  }
@@ -7976,7 +7989,27 @@ var DexieDb = class extends Dexie {
7976
7989
  }
7977
7990
  return table;
7978
7991
  }
7992
+ /**
7993
+ * Convert an Id to its string representation for IndexedDB key storage.
7994
+ * Throws on falsy values to prevent stuck-dirty items with garbage
7995
+ * _id values like "undefined" / "null" that can never be uploaded.
7996
+ */
7979
7997
  idToString(id) {
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.`
8001
+ );
8002
+ }
8003
+ if (id === void 0) {
8004
+ throw new Error(
8005
+ `[DexieDb.idToString] id is undefined. This is a bug \u2014 a valid _id is required.`
8006
+ );
8007
+ }
8008
+ 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
+ );
8012
+ }
7980
8013
  return String(id);
7981
8014
  }
7982
8015
  /** Ensure _id is a primitive string. IndexedDB rejects ObjectId objects as keys. */
@@ -15,6 +15,11 @@ export declare class DexieDb extends Dexie implements I_DexieDb {
15
15
  private _isNewDatabase;
16
16
  constructor(tenant: string, collectionConfigs: CollectionConfig<any>[]);
17
17
  private getTable;
18
+ /**
19
+ * Convert an Id to its string representation for IndexedDB key storage.
20
+ * Throws on falsy values to prevent stuck-dirty items with garbage
21
+ * _id values like "undefined" / "null" that can never be uploaded.
22
+ */
18
23
  private idToString;
19
24
  /** Ensure _id is a primitive string. IndexedDB rejects ObjectId objects as keys. */
20
25
  private ensureStringId;
@@ -617,7 +617,15 @@ export declare class SyncedDb implements I_SyncedDb {
617
617
  */
618
618
  private _autoRegisterTemporaryForFind;
619
619
  private static readonly STRINGIFIED_FALSY;
620
- /** Stringify an Id parameter (ObjectId → hex string). */
620
+ /**
621
+ * Stringify an Id parameter (ObjectId → hex string).
622
+ *
623
+ * Throws when `id` is falsy (null, undefined, 0, "", false) or is a
624
+ * stringified-falsy value ("undefined", "null", "0", "false", "").
625
+ * Passing a garbage _id creates a stuck dirty item that can never be
626
+ * uploaded (server rejects it) and can never be auto-healed (library
627
+ * doesn't know the correct _id). Fail-fast prevents silent data loss.
628
+ */
621
629
  private normalizeId;
622
630
  /**
623
631
  * Warn if a query/data object has `_id` present but falsy.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.216",
3
+ "version": "0.1.217",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",