cry-synced-db-client 0.1.121 → 0.1.123

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/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Versions
2
+
3
+ ## 0.1.123 (2026-04-08)
4
+
5
+ - Falsy `_id` guard on all public DB operations with detailed `console.error` messages
6
+ - `insert`/`upsert`: falsy `_id` replaced with new ObjectId before any operation
7
+ - `save`: falsy `_id` stripped from update partial to prevent overwriting valid id
8
+ - `findById`/`findByIds`/`deleteOne`/`hardDeleteOne`: warn on falsy `id` parameter
9
+ - `findOne`/`find`/`deleteMany`/`hardDelete`: warn on falsy `_id` in query object
10
+
11
+ ## 0.1.120 (2026-04-08)
12
+
13
+ - Ping failure message now includes the REST endpoint URL: "Ping to [URL] failed - staying offline"
14
+ - Ebus-proxy WebSocket connect/disconnect status messages logged on startup and reconnect
15
+ - Added `endpoint` property to `I_RestInterface` and `I_ServerUpdateNotifier` interfaces (for diagnostics/logging)
16
+ - Fixed `getDirty()` test assertions that assumed absent collections have `.length === 0`
package/dist/index.js CHANGED
@@ -3877,7 +3877,7 @@ var SyncedDb = class _SyncedDb {
3877
3877
  async findById(collection, id, opts) {
3878
3878
  var _a;
3879
3879
  this.assertCollection(collection);
3880
- id = this.normalizeId(id);
3880
+ id = this.normalizeId(id, "findById", collection);
3881
3881
  opts = this.resolveOpts(opts);
3882
3882
  if ((_a = this.collections.get(collection)) == null ? void 0 : _a.writeOnly) {
3883
3883
  return this.writeOnlyFindById(collection, id);
@@ -3922,7 +3922,7 @@ var SyncedDb = class _SyncedDb {
3922
3922
  async findByIds(collection, ids, opts) {
3923
3923
  var _a;
3924
3924
  this.assertCollection(collection);
3925
- ids = ids.map((id) => this.normalizeId(id));
3925
+ ids = ids.map((id) => this.normalizeId(id, "findByIds", collection));
3926
3926
  opts = this.resolveOpts(opts);
3927
3927
  if ((_a = this.collections.get(collection)) == null ? void 0 : _a.writeOnly) {
3928
3928
  return this.writeOnlyFindByIds(collection, ids);
@@ -3964,6 +3964,7 @@ var SyncedDb = class _SyncedDb {
3964
3964
  async findOne(collection, query, opts) {
3965
3965
  var _a, _b;
3966
3966
  this.assertCollection(collection);
3967
+ if (query) this.warnFalsyQueryId(query, "findOne", collection);
3967
3968
  query = _SyncedDb.stringifyObjectIds(query);
3968
3969
  opts = this.resolveOpts(opts);
3969
3970
  if ((_a = this.collections.get(collection)) == null ? void 0 : _a.writeOnly) {
@@ -4010,6 +4011,7 @@ var SyncedDb = class _SyncedDb {
4010
4011
  async find(collection, query, opts) {
4011
4012
  var _a;
4012
4013
  this.assertCollection(collection);
4014
+ if (query) this.warnFalsyQueryId(query, "find", collection);
4013
4015
  if (query) query = _SyncedDb.stringifyObjectIds(query);
4014
4016
  opts = this.resolveOpts(opts);
4015
4017
  if ((_a = this.collections.get(collection)) == null ? void 0 : _a.writeOnly) {
@@ -4126,8 +4128,11 @@ var SyncedDb = class _SyncedDb {
4126
4128
  async save(collection, id, update) {
4127
4129
  var _a, _b;
4128
4130
  this.assertCollection(collection);
4129
- id = this.normalizeId(id);
4131
+ id = this.normalizeId(id, "save", collection);
4130
4132
  if ("_id" in update && !update._id) {
4133
+ console.error(
4134
+ `SyncedDb.save("${collection}", "${String(id)}"): update._id is present but falsy (${JSON.stringify(update._id)}). Stripped from update to prevent overwriting valid id. This is a bug \u2014 the caller should not pass falsy _id in update. Data keys: [${Object.keys(update).join(", ")}]`
4135
+ );
4131
4136
  delete update._id;
4132
4137
  }
4133
4138
  update = _SyncedDb.stringifyObjectIds(update);
@@ -4157,7 +4162,7 @@ var SyncedDb = class _SyncedDb {
4157
4162
  }
4158
4163
  async upsert(collection, query, update) {
4159
4164
  this.assertCollection(collection);
4160
- this.ensureId(update);
4165
+ this.ensureId(update, "upsert", collection);
4161
4166
  query = _SyncedDb.stringifyObjectIds(query);
4162
4167
  update = _SyncedDb.stringifyObjectIds(update);
4163
4168
  const existing = await this.findOne(collection, query);
@@ -4170,7 +4175,7 @@ var SyncedDb = class _SyncedDb {
4170
4175
  async insert(collection, data) {
4171
4176
  var _a;
4172
4177
  this.assertCollection(collection);
4173
- this.ensureId(data);
4178
+ this.ensureId(data, "insert", collection);
4174
4179
  data = _SyncedDb.stringifyObjectIds(data);
4175
4180
  const id = String(data._id);
4176
4181
  const existing = await this.dexieDb.getById(collection, id);
@@ -4198,7 +4203,7 @@ var SyncedDb = class _SyncedDb {
4198
4203
  async deleteOne(collection, id) {
4199
4204
  var _a;
4200
4205
  this.assertCollection(collection);
4201
- id = this.normalizeId(id);
4206
+ id = this.normalizeId(id, "deleteOne", collection);
4202
4207
  const existing = await this.dexieDb.getById(collection, id);
4203
4208
  if (!existing || existing._deleted) {
4204
4209
  return null;
@@ -4221,6 +4226,7 @@ var SyncedDb = class _SyncedDb {
4221
4226
  }
4222
4227
  async deleteMany(collection, query) {
4223
4228
  this.assertCollection(collection);
4229
+ if (query) this.warnFalsyQueryId(query, "deleteMany", collection);
4224
4230
  const items = await this.find(collection, query);
4225
4231
  if (items.length === 0) return 0;
4226
4232
  const ids = items.map((item) => item._id);
@@ -4259,7 +4265,7 @@ var SyncedDb = class _SyncedDb {
4259
4265
  // ==================== Hard Delete Operations (online only) ====================
4260
4266
  async hardDeleteOne(collection, id) {
4261
4267
  this.assertCollection(collection);
4262
- id = this.normalizeId(id);
4268
+ id = this.normalizeId(id, "hardDeleteOne", collection);
4263
4269
  if (!this.isOnline()) {
4264
4270
  throw new Error("hardDeleteOne requires online connection");
4265
4271
  }
@@ -4277,6 +4283,7 @@ var SyncedDb = class _SyncedDb {
4277
4283
  }
4278
4284
  async hardDelete(collection, query) {
4279
4285
  this.assertCollection(collection);
4286
+ if (query) this.warnFalsyQueryId(query, "hardDelete", collection);
4280
4287
  if (!this.isOnline()) {
4281
4288
  throw new Error("hardDelete requires online connection");
4282
4289
  }
@@ -4656,17 +4663,42 @@ var SyncedDb = class _SyncedDb {
4656
4663
  }
4657
4664
  }
4658
4665
  /** Stringify an Id parameter (ObjectId → hex string). */
4659
- normalizeId(id) {
4666
+ normalizeId(id, method, collection) {
4667
+ if (!id && id !== void 0) {
4668
+ console.error(
4669
+ `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.`
4670
+ );
4671
+ }
4660
4672
  return typeof id === "object" && id !== null ? String(id) : id;
4661
4673
  }
4674
+ /**
4675
+ * Warn if a query/data object has `_id` present but falsy.
4676
+ * Does NOT mutate — only logs.
4677
+ */
4678
+ warnFalsyQueryId(data, method, collection) {
4679
+ if ("_id" in data && !data._id) {
4680
+ console.error(
4681
+ `SyncedDb.${method}("${collection}"): _id is present in query/data but falsy (${JSON.stringify(data._id)}). This is a bug \u2014 _id must be valid when specified. Data keys: [${Object.keys(data).join(", ")}]`
4682
+ );
4683
+ }
4684
+ }
4662
4685
  /**
4663
4686
  * Ensure `_id` on a data object is never falsy.
4664
4687
  * Replaces undefined / null / 0 / "" with a new ObjectId hex string.
4665
4688
  * @mutates — modifies the object in-place and returns it.
4666
4689
  */
4667
- ensureId(data) {
4668
- if (!data._id) {
4669
- data._id = new ObjectId2().toHexString();
4690
+ /**
4691
+ * Ensure `_id` on a data object is never falsy.
4692
+ * Replaces undefined / null / 0 / "" with a new ObjectId hex string.
4693
+ * @mutates — modifies the object in-place and returns it.
4694
+ */
4695
+ ensureId(data, method, collection) {
4696
+ if ("_id" in data && !data._id) {
4697
+ const newId = new ObjectId2().toHexString();
4698
+ console.error(
4699
+ `SyncedDb.${method}("${collection}"): _id is present but falsy (${JSON.stringify(data._id)}). Replaced with "${newId}". This is a bug \u2014 the caller should provide a valid _id. Data keys: [${Object.keys(data).join(", ")}]`
4700
+ );
4701
+ data._id = newId;
4670
4702
  }
4671
4703
  return data;
4672
4704
  }
@@ -210,6 +210,16 @@ export declare class SyncedDb implements I_SyncedDb {
210
210
  private assertCollection;
211
211
  /** Stringify an Id parameter (ObjectId → hex string). */
212
212
  private normalizeId;
213
+ /**
214
+ * Warn if a query/data object has `_id` present but falsy.
215
+ * Does NOT mutate — only logs.
216
+ */
217
+ private warnFalsyQueryId;
218
+ /**
219
+ * Ensure `_id` on a data object is never falsy.
220
+ * Replaces undefined / null / 0 / "" with a new ObjectId hex string.
221
+ * @mutates — modifies the object in-place and returns it.
222
+ */
213
223
  /**
214
224
  * Ensure `_id` on a data object is never falsy.
215
225
  * Replaces undefined / null / 0 / "" with a new ObjectId hex string.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.121",
3
+ "version": "0.1.123",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -12,7 +12,8 @@
12
12
  }
13
13
  },
14
14
  "files": [
15
- "dist"
15
+ "dist",
16
+ "CHANGELOG.md"
16
17
  ],
17
18
  "scripts": {
18
19
  "clean": "rm -rf dist",