cry-synced-db-client 0.1.206 → 0.1.208

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 +67 -33
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -3446,13 +3446,12 @@ var _SyncEngine = class _SyncEngine {
3446
3446
  var _a;
3447
3447
  if ((_a = this.collections.get(collection)) == null ? void 0 : _a.writeOnly) return;
3448
3448
  const dexieSave = [];
3449
- const dexieDeleteIds = [];
3450
3449
  const memUpsert = [];
3451
3450
  const memDelete = [];
3452
3451
  const reAddDirty = [];
3453
3452
  for (const record of mustRefresh) {
3454
3453
  if (record._deleted || record._archived) {
3455
- dexieDeleteIds.push(record._id);
3454
+ dexieSave.push(record);
3456
3455
  memDelete.push({ _id: record._id });
3457
3456
  continue;
3458
3457
  }
@@ -3488,9 +3487,6 @@ var _SyncEngine = class _SyncEngine {
3488
3487
  }
3489
3488
  if (dexieSave.length > 0)
3490
3489
  await this.dexieDb.saveMany(collection, dexieSave);
3491
- if (dexieDeleteIds.length > 0) {
3492
- await this.dexieDb.deleteMany(collection, dexieDeleteIds);
3493
- }
3494
3490
  if (memUpsert.length > 0) {
3495
3491
  this.deps.writeToInMemBatch(collection, memUpsert, "upsert", {
3496
3492
  source: "incremental"
@@ -5395,7 +5391,7 @@ var _SyncedDb = class _SyncedDb {
5395
5391
  }
5396
5392
  // ==================== Lifecycle ====================
5397
5393
  async init() {
5398
- var _a, _b, _c, _d;
5394
+ var _a, _b, _c;
5399
5395
  if (this.initialized) return;
5400
5396
  if (typeof localStorage === "undefined") {
5401
5397
  this.connectionManager.reportInfrastructureError(
@@ -5452,10 +5448,8 @@ var _SyncedDb = class _SyncedDb {
5452
5448
  );
5453
5449
  try {
5454
5450
  await this.serverUpdateNotifier.connect();
5455
- const ep = (_c = this.serverUpdateNotifier.endpoint) != null ? _c : "unknown";
5456
- console.log(`[SyncedDb] SyncedDb: ebus-proxy connected to ${ep}`);
5457
5451
  } catch (err) {
5458
- const ep = (_d = this.serverUpdateNotifier.endpoint) != null ? _d : "unknown";
5452
+ const ep = (_c = this.serverUpdateNotifier.endpoint) != null ? _c : "unknown";
5459
5453
  console.warn(
5460
5454
  `[SyncedDb] SyncedDb: ebus-proxy connection to ${ep} failed`
5461
5455
  );
@@ -6718,9 +6712,7 @@ var _SyncedDb = class _SyncedDb {
6718
6712
  const allDirty = await this.dexieDb.getDirty(collectionName);
6719
6713
  const content = stuck.map((m) => {
6720
6714
  const dirtyId = String(m.id);
6721
- const found = allDirty.find(
6722
- (d) => String(d._id) === dirtyId
6723
- );
6715
+ const found = allDirty.find((d) => String(d._id) === dirtyId);
6724
6716
  if (found) {
6725
6717
  const _a = found, { _id, _ts, _rev } = _a, changedFields = __objRest(_a, ["_id", "_ts", "_rev"]);
6726
6718
  return {
@@ -10870,7 +10862,8 @@ function preprocessForPack2(data) {
10870
10862
  if (isTimestamp2(data)) return { t: data.high, i: data.low };
10871
10863
  if (typeof data !== "object") return data;
10872
10864
  if (data instanceof Date) return data;
10873
- if (data instanceof Map || data instanceof Set || data instanceof RegExp) return data;
10865
+ if (data instanceof Map || data instanceof Set || data instanceof RegExp)
10866
+ return data;
10874
10867
  if (Array.isArray(data)) return data.map(preprocessForPack2);
10875
10868
  const result = {};
10876
10869
  for (const key of Object.keys(data)) {
@@ -10920,8 +10913,10 @@ var Ebus2ProxyServerUpdateNotifier = class {
10920
10913
  this.pongTimeoutMs = (_d = config.pongTimeoutMs) != null ? _d : DEFAULT_PONG_TIMEOUT_MS;
10921
10914
  this.currentReconnectDelay = this.reconnectDelayMs;
10922
10915
  if (config.onWsConnect) this.onWsConnectCallbacks.push(config.onWsConnect);
10923
- if (config.onWsDisconnect) this.onWsDisconnectCallbacks.push(config.onWsDisconnect);
10924
- if (config.onWsReconnect) this.onWsReconnectCallbacks.push(config.onWsReconnect);
10916
+ if (config.onWsDisconnect)
10917
+ this.onWsDisconnectCallbacks.push(config.onWsDisconnect);
10918
+ if (config.onWsReconnect)
10919
+ this.onWsReconnectCallbacks.push(config.onWsReconnect);
10925
10920
  this.onWsNotification = config.onWsNotification;
10926
10921
  this.subscribeServices = (_e = config.subscribeServices) != null ? _e : false;
10927
10922
  this.onServicesChange = config.onServicesChange;
@@ -11003,7 +10998,11 @@ var Ebus2ProxyServerUpdateNotifier = class {
11003
10998
  return new Promise((resolve, reject) => {
11004
10999
  const timer = setTimeout(() => {
11005
11000
  this._pendingRttPings.delete(id);
11006
- reject(new Error(`[Ebus2ProxyNotifier] measureWsRtt: timeout after ${timeoutMs}ms`));
11001
+ reject(
11002
+ new Error(
11003
+ `[Ebus2ProxyNotifier] measureWsRtt: timeout after ${timeoutMs}ms`
11004
+ )
11005
+ );
11007
11006
  }, timeoutMs);
11008
11007
  this._pendingRttPings.set(id, () => {
11009
11008
  clearTimeout(timer);
@@ -11084,7 +11083,9 @@ var Ebus2ProxyServerUpdateNotifier = class {
11084
11083
  return new Promise((resolve, reject) => {
11085
11084
  var _a2;
11086
11085
  if ((_a2 = options == null ? void 0 : options.signal) == null ? void 0 : _a2.aborted) {
11087
- reject(new Error(`[Ebus2ProxyNotifier] callWorker(${service}): aborted`));
11086
+ reject(
11087
+ new Error(`[Ebus2ProxyNotifier] callWorker(${service}): aborted`)
11088
+ );
11088
11089
  return;
11089
11090
  }
11090
11091
  const timer = setTimeout(() => {
@@ -11110,7 +11111,9 @@ var Ebus2ProxyServerUpdateNotifier = class {
11110
11111
  );
11111
11112
  } : void 0;
11112
11113
  if (abortListener && options.signal) {
11113
- options.signal.addEventListener("abort", abortListener, { once: true });
11114
+ options.signal.addEventListener("abort", abortListener, {
11115
+ once: true
11116
+ });
11114
11117
  }
11115
11118
  this._pendingRequests.set(id, {
11116
11119
  resolve,
@@ -11168,11 +11171,15 @@ var Ebus2ProxyServerUpdateNotifier = class {
11168
11171
  if (idx !== -1) this.onWsConnectCallbacks.splice(idx, 1);
11169
11172
  }
11170
11173
  if (addedCallbacks.onDisconnect) {
11171
- const idx = this.onWsDisconnectCallbacks.indexOf(addedCallbacks.onDisconnect);
11174
+ const idx = this.onWsDisconnectCallbacks.indexOf(
11175
+ addedCallbacks.onDisconnect
11176
+ );
11172
11177
  if (idx !== -1) this.onWsDisconnectCallbacks.splice(idx, 1);
11173
11178
  }
11174
11179
  if (addedCallbacks.onReconnect) {
11175
- const idx = this.onWsReconnectCallbacks.indexOf(addedCallbacks.onReconnect);
11180
+ const idx = this.onWsReconnectCallbacks.indexOf(
11181
+ addedCallbacks.onReconnect
11182
+ );
11176
11183
  if (idx !== -1) this.onWsReconnectCallbacks.splice(idx, 1);
11177
11184
  }
11178
11185
  };
@@ -11233,9 +11240,6 @@ var Ebus2ProxyServerUpdateNotifier = class {
11233
11240
  this.connected = true;
11234
11241
  this.reconnectAttempt = 0;
11235
11242
  this.currentReconnectDelay = this.reconnectDelayMs;
11236
- console.log(
11237
- `[Ebus2ProxyNotifier] Ebus2Proxy connected to ${this.wsUrl} (db: ${this.dbName})`
11238
- );
11239
11243
  this.sendSubscribe(`db/${this.dbName}`);
11240
11244
  if (this.subscribeServices) {
11241
11245
  this.sendSubscribe("ebus/services");
@@ -11245,7 +11249,10 @@ var Ebus2ProxyServerUpdateNotifier = class {
11245
11249
  try {
11246
11250
  callback();
11247
11251
  } catch (err) {
11248
- console.error(`[Ebus2ProxyNotifier] onWsConnect callback failed: ${err}`, err);
11252
+ console.error(
11253
+ `[Ebus2ProxyNotifier] onWsConnect callback failed: ${err}`,
11254
+ err
11255
+ );
11249
11256
  }
11250
11257
  }
11251
11258
  }
@@ -11274,7 +11281,10 @@ var Ebus2ProxyServerUpdateNotifier = class {
11274
11281
  try {
11275
11282
  callback(reason);
11276
11283
  } catch (err) {
11277
- console.error(`[Ebus2ProxyNotifier] onWsDisconnect callback failed: ${err}`, err);
11284
+ console.error(
11285
+ `[Ebus2ProxyNotifier] onWsDisconnect callback failed: ${err}`,
11286
+ err
11287
+ );
11278
11288
  }
11279
11289
  }
11280
11290
  }
@@ -11318,7 +11328,10 @@ var Ebus2ProxyServerUpdateNotifier = class {
11318
11328
  clearTimeout(pending.timer);
11319
11329
  this._pendingRequests.delete(message.id);
11320
11330
  if (pending.abortListener && pending.signal) {
11321
- pending.signal.removeEventListener("abort", pending.abortListener);
11331
+ pending.signal.removeEventListener(
11332
+ "abort",
11333
+ pending.abortListener
11334
+ );
11322
11335
  }
11323
11336
  pending.resolve(message.data);
11324
11337
  }
@@ -11332,7 +11345,10 @@ var Ebus2ProxyServerUpdateNotifier = class {
11332
11345
  clearTimeout(pending.timer);
11333
11346
  this._pendingRequests.delete(message.id);
11334
11347
  if (pending.abortListener && pending.signal) {
11335
- pending.signal.removeEventListener("abort", pending.abortListener);
11348
+ pending.signal.removeEventListener(
11349
+ "abort",
11350
+ pending.abortListener
11351
+ );
11336
11352
  }
11337
11353
  pending.reject(
11338
11354
  new Error(
@@ -11342,11 +11358,17 @@ var Ebus2ProxyServerUpdateNotifier = class {
11342
11358
  break;
11343
11359
  }
11344
11360
  }
11345
- console.error(`[Ebus2ProxyNotifier] WebSocket server error: ${message.error}`, message.error);
11361
+ console.error(
11362
+ `[Ebus2ProxyNotifier] WebSocket server error: ${message.error}`,
11363
+ message.error
11364
+ );
11346
11365
  break;
11347
11366
  }
11348
11367
  } catch (err) {
11349
- console.error(`[Ebus2ProxyNotifier] Failed to parse WebSocket message: ${err}`, err);
11368
+ console.error(
11369
+ `[Ebus2ProxyNotifier] Failed to parse WebSocket message: ${err}`,
11370
+ err
11371
+ );
11350
11372
  }
11351
11373
  }
11352
11374
  handleChannelMessage(message) {
@@ -11354,7 +11376,10 @@ var Ebus2ProxyServerUpdateNotifier = class {
11354
11376
  try {
11355
11377
  this.onServicesChange(message.data);
11356
11378
  } catch (err) {
11357
- console.error(`[Ebus2ProxyNotifier] onServicesChange callback failed: ${err}`, err);
11379
+ console.error(
11380
+ `[Ebus2ProxyNotifier] onServicesChange callback failed: ${err}`,
11381
+ err
11382
+ );
11358
11383
  }
11359
11384
  return;
11360
11385
  }
@@ -11371,14 +11396,20 @@ var Ebus2ProxyServerUpdateNotifier = class {
11371
11396
  try {
11372
11397
  this.onWsNotification(payload);
11373
11398
  } catch (err) {
11374
- console.error(`[Ebus2ProxyNotifier] onWsNotification callback failed: ${err}`, err);
11399
+ console.error(
11400
+ `[Ebus2ProxyNotifier] onWsNotification callback failed: ${err}`,
11401
+ err
11402
+ );
11375
11403
  }
11376
11404
  }
11377
11405
  for (const callback of this.callbacks) {
11378
11406
  try {
11379
11407
  callback(payload);
11380
11408
  } catch (err) {
11381
- console.error(`[Ebus2ProxyNotifier] ServerUpdateCallback failed: ${err}`, err);
11409
+ console.error(
11410
+ `[Ebus2ProxyNotifier] ServerUpdateCallback failed: ${err}`,
11411
+ err
11412
+ );
11382
11413
  }
11383
11414
  }
11384
11415
  }
@@ -11397,7 +11428,10 @@ var Ebus2ProxyServerUpdateNotifier = class {
11397
11428
  try {
11398
11429
  callback(this.reconnectAttempt);
11399
11430
  } catch (err) {
11400
- console.error(`[Ebus2ProxyNotifier] onWsReconnect callback failed: ${err}`, err);
11431
+ console.error(
11432
+ `[Ebus2ProxyNotifier] onWsReconnect callback failed: ${err}`,
11433
+ err
11434
+ );
11401
11435
  }
11402
11436
  }
11403
11437
  this.reconnectTimer = setTimeout(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.206",
3
+ "version": "0.1.208",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -37,7 +37,7 @@
37
37
  "vitest": "^4.1.8"
38
38
  },
39
39
  "dependencies": {
40
- "cry-db": "^2.5.3",
40
+ "cry-db": "^2.5.5",
41
41
  "cry-helpers": "^2.1.205",
42
42
  "msgpackr": "^2.0.4",
43
43
  "superjson": "^2.2.6"