dexie-cloud-addon 4.0.1-beta.39 → 4.0.1-beta.40

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.
@@ -2140,7 +2140,7 @@ function MessagesFromServerConsumer(db) {
2140
2140
  event.next(null);
2141
2141
  }
2142
2142
  function consumeQueue() {
2143
- var _a, _b, _c;
2143
+ var _a, _b, _c, _d, _e, _f;
2144
2144
  return __awaiter(this, void 0, void 0, function* () {
2145
2145
  while (queue.length > 0) {
2146
2146
  const msg = queue.shift();
@@ -2172,29 +2172,32 @@ function MessagesFromServerConsumer(db) {
2172
2172
  // new token. So we don't need to do anything more here.
2173
2173
  break;
2174
2174
  case 'realm-added':
2175
- //if (!persistedSyncState?.realms?.includes(msg.realm) && !persistedSyncState?.inviteRealms?.includes(msg.realm)) {
2176
- triggerSync(db, 'pull');
2177
- //}
2175
+ if (!((_a = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms) === null || _a === void 0 ? void 0 : _a.includes(msg.realm)) &&
2176
+ !((_b = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.inviteRealms) === null || _b === void 0 ? void 0 : _b.includes(msg.realm))) {
2177
+ yield db.cloud.sync({ purpose: 'pull', wait: true });
2178
+ //triggerSync(db, 'pull');
2179
+ }
2178
2180
  break;
2179
2181
  case 'realm-accepted':
2180
- //if (!persistedSyncState?.realms?.includes(msg.realm)) {
2181
- triggerSync(db, 'pull');
2182
- //}
2182
+ if (!((_c = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms) === null || _c === void 0 ? void 0 : _c.includes(msg.realm))) {
2183
+ yield db.cloud.sync({ purpose: 'pull', wait: true });
2184
+ //triggerSync(db, 'pull');
2185
+ }
2183
2186
  break;
2184
2187
  case 'realm-removed':
2185
- //if (
2186
- ((_a = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms) === null || _a === void 0 ? void 0 : _a.includes(msg.realm)) ||
2187
- ((_b = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.inviteRealms) === null || _b === void 0 ? void 0 : _b.includes(msg.realm));
2188
- //) {
2189
- triggerSync(db, 'pull');
2190
- //}
2188
+ if (((_d = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms) === null || _d === void 0 ? void 0 : _d.includes(msg.realm)) ||
2189
+ ((_e = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.inviteRealms) === null || _e === void 0 ? void 0 : _e.includes(msg.realm))) {
2190
+ yield db.cloud.sync({ purpose: 'pull', wait: true });
2191
+ //triggerSync(db, 'pull');
2192
+ }
2191
2193
  break;
2192
2194
  case 'realms-changed':
2193
- triggerSync(db, 'pull');
2195
+ //triggerSync(db, 'pull');
2196
+ yield db.cloud.sync({ purpose: 'pull', wait: true });
2194
2197
  break;
2195
2198
  case 'changes':
2196
2199
  console.debug('changes');
2197
- if (((_c = db.cloud.syncState.value) === null || _c === void 0 ? void 0 : _c.phase) === 'error') {
2200
+ if (((_f = db.cloud.syncState.value) === null || _f === void 0 ? void 0 : _f.phase) === 'error') {
2198
2201
  triggerSync(db, 'pull');
2199
2202
  break;
2200
2203
  }
@@ -3548,10 +3551,13 @@ function connectWebSocket(db) {
3548
3551
  const messageProducer = db.messageConsumer.readyToServe.pipe(filter((isReady) => isReady), // When consumer is ready for new messages, produce such a message to inform server about it
3549
3552
  switchMap(() => db.getPersistedSyncState()), // We need the info on which server revision we are at:
3550
3553
  filter((syncState) => syncState && syncState.serverRevision), // We wont send anything to server before inital sync has taken place
3551
- map((syncState) => ({
3552
- // Produce the message to trigger server to send us new messages to consume:
3553
- type: 'ready',
3554
- rev: syncState.serverRevision,
3554
+ switchMap((syncState) => __awaiter(this, void 0, void 0, function* () {
3555
+ return ({
3556
+ // Produce the message to trigger server to send us new messages to consume:
3557
+ type: 'ready',
3558
+ rev: syncState.serverRevision,
3559
+ realmSetHash: yield computeRealmSetHash(syncState)
3560
+ });
3555
3561
  })));
3556
3562
  function createObservable() {
3557
3563
  return db.cloud.persistedSyncState.pipe(filter((syncState) => syncState === null || syncState === void 0 ? void 0 : syncState.serverRevision), // Don't connect before there's no initial sync performed.
@@ -4428,7 +4434,7 @@ function dexieCloud(dexie) {
4428
4434
  });
4429
4435
  const syncComplete = new Subject();
4430
4436
  dexie.cloud = {
4431
- version: '4.0.1-beta.39',
4437
+ version: '4.0.1-beta.40',
4432
4438
  options: Object.assign({}, DEFAULT_OPTIONS),
4433
4439
  schema: null,
4434
4440
  get currentUserId() {
@@ -4689,7 +4695,7 @@ function dexieCloud(dexie) {
4689
4695
  });
4690
4696
  }
4691
4697
  }
4692
- dexieCloud.version = '4.0.1-beta.39';
4698
+ dexieCloud.version = '4.0.1-beta.40';
4693
4699
  Dexie.Cloud = dexieCloud;
4694
4700
 
4695
4701
  // In case the SW lives for a while, let it reuse already opened connections: