dexie-cloud-addon 4.1.0-alpha.20 → 4.1.0-alpha.21

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.
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * ==========================================================================
10
10
  *
11
- * Version 4.1.0-alpha.20, Wed Oct 23 2024
11
+ * Version 4.1.0-alpha.21, Mon Nov 18 2024
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -979,13 +979,17 @@ const writeAny = (encoder, data) => {
979
979
  function encodeYMessage(msg) {
980
980
  const encoder = new Encoder();
981
981
  writeVarString(encoder, msg.type);
982
- writeVarString(encoder, msg.table);
983
- writeVarString(encoder, msg.prop);
982
+ if ('table' in msg)
983
+ writeVarString(encoder, msg.table);
984
+ if ('prop' in msg)
985
+ writeVarString(encoder, msg.prop);
984
986
  switch (msg.type) {
985
987
  case 'u-ack':
986
988
  case 'u-reject':
987
989
  writeBigUint64(encoder, BigInt(msg.i));
988
990
  break;
991
+ case 'outdated-server-rev':
992
+ break;
989
993
  default:
990
994
  writeAny(encoder, msg.k);
991
995
  switch (msg.type) {
@@ -1329,6 +1333,9 @@ const readAny = decoder => readAnyLookupTable[127 - readUint8(decoder)](decoder)
1329
1333
  function decodeYMessage(a) {
1330
1334
  const decoder = new Decoder(a);
1331
1335
  const type = readVarString(decoder);
1336
+ if (type === 'outdated-server-rev') {
1337
+ return { type };
1338
+ }
1332
1339
  const table = readVarString(decoder);
1333
1340
  const prop = readVarString(decoder);
1334
1341
  switch (type) {
@@ -5060,12 +5067,13 @@ function getUpdatesTable(db, table, ydocProp) {
5060
5067
  function applyYServerMessages(yMessages, db) {
5061
5068
  return __awaiter(this, void 0, void 0, function* () {
5062
5069
  var _a;
5063
- const result = {};
5070
+ const receivedUntils = {};
5071
+ let resyncNeeded = false;
5064
5072
  for (const m of yMessages) {
5065
5073
  switch (m.type) {
5066
5074
  case 'u-s': {
5067
5075
  const utbl = getUpdatesTable(db, m.table, m.prop);
5068
- result[utbl.name] = yield utbl.add({
5076
+ receivedUntils[utbl.name] = yield utbl.add({
5069
5077
  k: m.k,
5070
5078
  u: m.u,
5071
5079
  });
@@ -5094,13 +5102,13 @@ function applyYServerMessages(yMessages, db) {
5094
5102
  // and destroy it's open document if there is one.
5095
5103
  const primaryKey = (_a = (yield utbl.get(m.i))) === null || _a === void 0 ? void 0 : _a.k;
5096
5104
  if (primaryKey != null) {
5097
- yield db.transaction('rw', utbl, tx => {
5105
+ yield db.transaction('rw', utbl, (tx) => {
5098
5106
  // @ts-ignore
5099
5107
  tx.idbtrans._rejecting_y_ypdate = true; // Inform ydoc triggers that we delete because of a rejection and not GC
5100
5108
  return utbl
5101
5109
  .where('i')
5102
5110
  .aboveOrEqual(m.i)
5103
- .filter(u => cmp(u.k, primaryKey) === 0 && ((u.f || 0) & 1) === 1)
5111
+ .filter((u) => cmp(u.k, primaryKey) === 0 && ((u.f || 0) & 1) === 1)
5104
5112
  .delete();
5105
5113
  });
5106
5114
  // Destroy active doc
@@ -5117,9 +5125,15 @@ function applyYServerMessages(yMessages, db) {
5117
5125
  }
5118
5126
  break;
5119
5127
  }
5128
+ case 'outdated-server-rev':
5129
+ resyncNeeded = true;
5130
+ break;
5120
5131
  }
5121
5132
  }
5122
- return result;
5133
+ return {
5134
+ receivedUntils,
5135
+ resyncNeeded,
5136
+ };
5123
5137
  });
5124
5138
  }
5125
5139
 
@@ -5526,11 +5540,14 @@ function _sync(db_1, options_1, schema_1) {
5526
5540
  //
5527
5541
  // apply yMessages
5528
5542
  //
5529
- const receivedUntils = yield applyYServerMessages(res.yMessages, db);
5543
+ const { receivedUntils, resyncNeeded } = yield applyYServerMessages(res.yMessages, db);
5530
5544
  //
5531
5545
  // update Y SyncStates
5532
5546
  //
5533
5547
  yield updateYSyncStates(lastUpdateIds, receivedUntils, db, res.serverRevision);
5548
+ if (resyncNeeded) {
5549
+ newSyncState.yDownloadedRealms = {}; // Will trigger a full download of Y-documents below...
5550
+ }
5534
5551
  }
5535
5552
  //
5536
5553
  // Update regular syncState
@@ -6979,6 +6996,10 @@ class WSConnection extends Subscription$1 {
6979
6996
  else if (msg.type === 'u-ack' || msg.type === 'u-reject' || msg.type === 'u-s' || msg.type === 'in-sync') {
6980
6997
  applyYServerMessages([msg], this.db);
6981
6998
  }
6999
+ else if (msg.type === 'outdated-server-rev') {
7000
+ // Won't happen but need this for typing.
7001
+ throw new Error('Outdated server revision not expected over WebSocket - only in sync using fetch()');
7002
+ }
6982
7003
  else if (msg.type !== 'pong') {
6983
7004
  this.subscriber.next(msg);
6984
7005
  }
@@ -7021,12 +7042,19 @@ class WSConnection extends Subscription$1 {
7021
7042
  else {
7022
7043
  // If it's not a "ready" message, it's an YMessage.
7023
7044
  // YMessages can be sent binary encoded.
7045
+ if (msg.type === 'u-c') {
7046
+ console.log("u-c:B", ++gotClientUpdateB);
7047
+ }
7024
7048
  (_b = this.ws) === null || _b === void 0 ? void 0 : _b.send(encodeYMessage(msg));
7025
7049
  }
7026
7050
  }
7027
7051
  }));
7028
7052
  if (this.user.isLoggedIn && !isEagerSyncDisabled(this.db)) {
7029
- this.subscriptions.add(createYClientUpdateObservable(this.db).subscribe(this.db.messageProducer));
7053
+ this.subscriptions.add(createYClientUpdateObservable(this.db).pipe(tap$1((msg) => {
7054
+ if (msg.type === 'u-c') {
7055
+ console.log("u-c:A", ++gotClientUpdateA, msg.i);
7056
+ }
7057
+ })).subscribe(this.db.messageProducer));
7030
7058
  }
7031
7059
  }
7032
7060
  catch (error) {
@@ -7035,6 +7063,8 @@ class WSConnection extends Subscription$1 {
7035
7063
  });
7036
7064
  }
7037
7065
  }
7066
+ let gotClientUpdateA = 0;
7067
+ let gotClientUpdateB = 0;
7038
7068
 
7039
7069
  class InvalidLicenseError extends Error {
7040
7070
  constructor(license) {
@@ -8097,7 +8127,7 @@ function dexieCloud(dexie) {
8097
8127
  const syncComplete = new Subject();
8098
8128
  dexie.cloud = {
8099
8129
  // @ts-ignore
8100
- version: "4.1.0-alpha.20",
8130
+ version: "4.1.0-alpha.21",
8101
8131
  options: Object.assign({}, DEFAULT_OPTIONS),
8102
8132
  schema: null,
8103
8133
  get currentUserId() {
@@ -8399,7 +8429,7 @@ function dexieCloud(dexie) {
8399
8429
  }
8400
8430
  }
8401
8431
  // @ts-ignore
8402
- dexieCloud.version = "4.1.0-alpha.20";
8432
+ dexieCloud.version = "4.1.0-alpha.21";
8403
8433
  Dexie.Cloud = dexieCloud;
8404
8434
 
8405
8435
  const ydocTriggers = {};