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
  *
@@ -2757,13 +2757,17 @@
2757
2757
  function encodeYMessage(msg) {
2758
2758
  const encoder = new Encoder();
2759
2759
  writeVarString(encoder, msg.type);
2760
- writeVarString(encoder, msg.table);
2761
- writeVarString(encoder, msg.prop);
2760
+ if ('table' in msg)
2761
+ writeVarString(encoder, msg.table);
2762
+ if ('prop' in msg)
2763
+ writeVarString(encoder, msg.prop);
2762
2764
  switch (msg.type) {
2763
2765
  case 'u-ack':
2764
2766
  case 'u-reject':
2765
2767
  writeBigUint64(encoder, BigInt(msg.i));
2766
2768
  break;
2769
+ case 'outdated-server-rev':
2770
+ break;
2767
2771
  default:
2768
2772
  writeAny(encoder, msg.k);
2769
2773
  switch (msg.type) {
@@ -3107,6 +3111,9 @@
3107
3111
  function decodeYMessage(a) {
3108
3112
  const decoder = new Decoder(a);
3109
3113
  const type = readVarString(decoder);
3114
+ if (type === 'outdated-server-rev') {
3115
+ return { type };
3116
+ }
3110
3117
  const table = readVarString(decoder);
3111
3118
  const prop = readVarString(decoder);
3112
3119
  switch (type) {
@@ -4757,12 +4764,13 @@
4757
4764
  function applyYServerMessages(yMessages, db) {
4758
4765
  return __awaiter(this, void 0, void 0, function* () {
4759
4766
  var _a;
4760
- const result = {};
4767
+ const receivedUntils = {};
4768
+ let resyncNeeded = false;
4761
4769
  for (const m of yMessages) {
4762
4770
  switch (m.type) {
4763
4771
  case 'u-s': {
4764
4772
  const utbl = getUpdatesTable(db, m.table, m.prop);
4765
- result[utbl.name] = yield utbl.add({
4773
+ receivedUntils[utbl.name] = yield utbl.add({
4766
4774
  k: m.k,
4767
4775
  u: m.u,
4768
4776
  });
@@ -4791,13 +4799,13 @@
4791
4799
  // and destroy it's open document if there is one.
4792
4800
  const primaryKey = (_a = (yield utbl.get(m.i))) === null || _a === void 0 ? void 0 : _a.k;
4793
4801
  if (primaryKey != null) {
4794
- yield db.transaction('rw', utbl, tx => {
4802
+ yield db.transaction('rw', utbl, (tx) => {
4795
4803
  // @ts-ignore
4796
4804
  tx.idbtrans._rejecting_y_ypdate = true; // Inform ydoc triggers that we delete because of a rejection and not GC
4797
4805
  return utbl
4798
4806
  .where('i')
4799
4807
  .aboveOrEqual(m.i)
4800
- .filter(u => Dexie.cmp(u.k, primaryKey) === 0 && ((u.f || 0) & 1) === 1)
4808
+ .filter((u) => Dexie.cmp(u.k, primaryKey) === 0 && ((u.f || 0) & 1) === 1)
4801
4809
  .delete();
4802
4810
  });
4803
4811
  // Destroy active doc
@@ -4814,9 +4822,15 @@
4814
4822
  }
4815
4823
  break;
4816
4824
  }
4825
+ case 'outdated-server-rev':
4826
+ resyncNeeded = true;
4827
+ break;
4817
4828
  }
4818
4829
  }
4819
- return result;
4830
+ return {
4831
+ receivedUntils,
4832
+ resyncNeeded,
4833
+ };
4820
4834
  });
4821
4835
  }
4822
4836
 
@@ -5223,11 +5237,14 @@
5223
5237
  //
5224
5238
  // apply yMessages
5225
5239
  //
5226
- const receivedUntils = yield applyYServerMessages(res.yMessages, db);
5240
+ const { receivedUntils, resyncNeeded } = yield applyYServerMessages(res.yMessages, db);
5227
5241
  //
5228
5242
  // update Y SyncStates
5229
5243
  //
5230
5244
  yield updateYSyncStates(lastUpdateIds, receivedUntils, db, res.serverRevision);
5245
+ if (resyncNeeded) {
5246
+ newSyncState.yDownloadedRealms = {}; // Will trigger a full download of Y-documents below...
5247
+ }
5231
5248
  }
5232
5249
  //
5233
5250
  // Update regular syncState
@@ -6982,6 +6999,10 @@
6982
6999
  else if (msg.type === 'u-ack' || msg.type === 'u-reject' || msg.type === 'u-s' || msg.type === 'in-sync') {
6983
7000
  applyYServerMessages([msg], this.db);
6984
7001
  }
7002
+ else if (msg.type === 'outdated-server-rev') {
7003
+ // Won't happen but need this for typing.
7004
+ throw new Error('Outdated server revision not expected over WebSocket - only in sync using fetch()');
7005
+ }
6985
7006
  else if (msg.type !== 'pong') {
6986
7007
  this.subscriber.next(msg);
6987
7008
  }
@@ -7024,12 +7045,19 @@
7024
7045
  else {
7025
7046
  // If it's not a "ready" message, it's an YMessage.
7026
7047
  // YMessages can be sent binary encoded.
7048
+ if (msg.type === 'u-c') {
7049
+ console.log("u-c:B", ++gotClientUpdateB);
7050
+ }
7027
7051
  (_b = this.ws) === null || _b === void 0 ? void 0 : _b.send(encodeYMessage(msg));
7028
7052
  }
7029
7053
  }
7030
7054
  }));
7031
7055
  if (this.user.isLoggedIn && !isEagerSyncDisabled(this.db)) {
7032
- this.subscriptions.add(createYClientUpdateObservable(this.db).subscribe(this.db.messageProducer));
7056
+ this.subscriptions.add(createYClientUpdateObservable(this.db).pipe(rxjs.tap((msg) => {
7057
+ if (msg.type === 'u-c') {
7058
+ console.log("u-c:A", ++gotClientUpdateA, msg.i);
7059
+ }
7060
+ })).subscribe(this.db.messageProducer));
7033
7061
  }
7034
7062
  }
7035
7063
  catch (error) {
@@ -7038,6 +7066,8 @@
7038
7066
  });
7039
7067
  }
7040
7068
  }
7069
+ let gotClientUpdateA = 0;
7070
+ let gotClientUpdateB = 0;
7041
7071
 
7042
7072
  class InvalidLicenseError extends Error {
7043
7073
  constructor(license) {
@@ -8093,7 +8123,7 @@
8093
8123
  const syncComplete = new rxjs.Subject();
8094
8124
  dexie.cloud = {
8095
8125
  // @ts-ignore
8096
- version: "4.1.0-alpha.20",
8126
+ version: "4.1.0-alpha.21",
8097
8127
  options: Object.assign({}, DEFAULT_OPTIONS),
8098
8128
  schema: null,
8099
8129
  get currentUserId() {
@@ -8395,7 +8425,7 @@
8395
8425
  }
8396
8426
  }
8397
8427
  // @ts-ignore
8398
- dexieCloud.version = "4.1.0-alpha.20";
8428
+ dexieCloud.version = "4.1.0-alpha.21";
8399
8429
  Dexie.Cloud = dexieCloud;
8400
8430
 
8401
8431
  // In case the SW lives for a while, let it reuse already opened connections: