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.
@@ -1,5 +1,8 @@
1
1
  import { DexieCloudDB } from '../db/DexieCloudDB';
2
2
  import { YServerMessage } from 'dexie-cloud-common';
3
3
  export declare function applyYServerMessages(yMessages: YServerMessage[], db: DexieCloudDB): Promise<{
4
- [yTable: string]: number;
4
+ receivedUntils: {
5
+ [yTable: string]: number;
6
+ };
7
+ resyncNeeded: boolean;
5
8
  }>;
@@ -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
  *
@@ -982,13 +982,17 @@
982
982
  function encodeYMessage(msg) {
983
983
  const encoder = new Encoder();
984
984
  writeVarString(encoder, msg.type);
985
- writeVarString(encoder, msg.table);
986
- writeVarString(encoder, msg.prop);
985
+ if ('table' in msg)
986
+ writeVarString(encoder, msg.table);
987
+ if ('prop' in msg)
988
+ writeVarString(encoder, msg.prop);
987
989
  switch (msg.type) {
988
990
  case 'u-ack':
989
991
  case 'u-reject':
990
992
  writeBigUint64(encoder, BigInt(msg.i));
991
993
  break;
994
+ case 'outdated-server-rev':
995
+ break;
992
996
  default:
993
997
  writeAny(encoder, msg.k);
994
998
  switch (msg.type) {
@@ -1332,6 +1336,9 @@
1332
1336
  function decodeYMessage(a) {
1333
1337
  const decoder = new Decoder(a);
1334
1338
  const type = readVarString(decoder);
1339
+ if (type === 'outdated-server-rev') {
1340
+ return { type };
1341
+ }
1335
1342
  const table = readVarString(decoder);
1336
1343
  const prop = readVarString(decoder);
1337
1344
  switch (type) {
@@ -5063,12 +5070,13 @@
5063
5070
  function applyYServerMessages(yMessages, db) {
5064
5071
  return __awaiter(this, void 0, void 0, function* () {
5065
5072
  var _a;
5066
- const result = {};
5073
+ const receivedUntils = {};
5074
+ let resyncNeeded = false;
5067
5075
  for (const m of yMessages) {
5068
5076
  switch (m.type) {
5069
5077
  case 'u-s': {
5070
5078
  const utbl = getUpdatesTable(db, m.table, m.prop);
5071
- result[utbl.name] = yield utbl.add({
5079
+ receivedUntils[utbl.name] = yield utbl.add({
5072
5080
  k: m.k,
5073
5081
  u: m.u,
5074
5082
  });
@@ -5097,13 +5105,13 @@
5097
5105
  // and destroy it's open document if there is one.
5098
5106
  const primaryKey = (_a = (yield utbl.get(m.i))) === null || _a === void 0 ? void 0 : _a.k;
5099
5107
  if (primaryKey != null) {
5100
- yield db.transaction('rw', utbl, tx => {
5108
+ yield db.transaction('rw', utbl, (tx) => {
5101
5109
  // @ts-ignore
5102
5110
  tx.idbtrans._rejecting_y_ypdate = true; // Inform ydoc triggers that we delete because of a rejection and not GC
5103
5111
  return utbl
5104
5112
  .where('i')
5105
5113
  .aboveOrEqual(m.i)
5106
- .filter(u => Dexie.cmp(u.k, primaryKey) === 0 && ((u.f || 0) & 1) === 1)
5114
+ .filter((u) => Dexie.cmp(u.k, primaryKey) === 0 && ((u.f || 0) & 1) === 1)
5107
5115
  .delete();
5108
5116
  });
5109
5117
  // Destroy active doc
@@ -5120,9 +5128,15 @@
5120
5128
  }
5121
5129
  break;
5122
5130
  }
5131
+ case 'outdated-server-rev':
5132
+ resyncNeeded = true;
5133
+ break;
5123
5134
  }
5124
5135
  }
5125
- return result;
5136
+ return {
5137
+ receivedUntils,
5138
+ resyncNeeded,
5139
+ };
5126
5140
  });
5127
5141
  }
5128
5142
 
@@ -5529,11 +5543,14 @@
5529
5543
  //
5530
5544
  // apply yMessages
5531
5545
  //
5532
- const receivedUntils = yield applyYServerMessages(res.yMessages, db);
5546
+ const { receivedUntils, resyncNeeded } = yield applyYServerMessages(res.yMessages, db);
5533
5547
  //
5534
5548
  // update Y SyncStates
5535
5549
  //
5536
5550
  yield updateYSyncStates(lastUpdateIds, receivedUntils, db, res.serverRevision);
5551
+ if (resyncNeeded) {
5552
+ newSyncState.yDownloadedRealms = {}; // Will trigger a full download of Y-documents below...
5553
+ }
5537
5554
  }
5538
5555
  //
5539
5556
  // 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) {
@@ -8100,7 +8130,7 @@
8100
8130
  const syncComplete = new rxjs.Subject();
8101
8131
  dexie.cloud = {
8102
8132
  // @ts-ignore
8103
- version: "4.1.0-alpha.20",
8133
+ version: "4.1.0-alpha.21",
8104
8134
  options: Object.assign({}, DEFAULT_OPTIONS),
8105
8135
  schema: null,
8106
8136
  get currentUserId() {
@@ -8402,7 +8432,7 @@
8402
8432
  }
8403
8433
  }
8404
8434
  // @ts-ignore
8405
- dexieCloud.version = "4.1.0-alpha.20";
8435
+ dexieCloud.version = "4.1.0-alpha.21";
8406
8436
  Dexie.Cloud = dexieCloud;
8407
8437
 
8408
8438
  const ydocTriggers = {};