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

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.
@@ -7,4 +7,5 @@ export interface TXExpandos {
7
7
  disableChangeTracking?: boolean;
8
8
  disableAccessControl?: boolean;
9
9
  mutationsAdded?: boolean;
10
+ opCount: number;
10
11
  }
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * ==========================================================================
10
10
  *
11
- * Version 4.0.1-beta.39, Wed Apr 26 2023
11
+ * Version 4.0.1-beta.41, Sat Jul 01 2023
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -4014,7 +4014,7 @@
4014
4014
  event.next(null);
4015
4015
  }
4016
4016
  function consumeQueue() {
4017
- var _a, _b, _c;
4017
+ var _a, _b, _c, _d, _e, _f;
4018
4018
  return __awaiter(this, void 0, void 0, function* () {
4019
4019
  while (queue.length > 0) {
4020
4020
  const msg = queue.shift();
@@ -4046,29 +4046,32 @@
4046
4046
  // new token. So we don't need to do anything more here.
4047
4047
  break;
4048
4048
  case 'realm-added':
4049
- //if (!persistedSyncState?.realms?.includes(msg.realm) && !persistedSyncState?.inviteRealms?.includes(msg.realm)) {
4050
- triggerSync(db, 'pull');
4051
- //}
4049
+ if (!((_a = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms) === null || _a === void 0 ? void 0 : _a.includes(msg.realm)) &&
4050
+ !((_b = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.inviteRealms) === null || _b === void 0 ? void 0 : _b.includes(msg.realm))) {
4051
+ yield db.cloud.sync({ purpose: 'pull', wait: true });
4052
+ //triggerSync(db, 'pull');
4053
+ }
4052
4054
  break;
4053
4055
  case 'realm-accepted':
4054
- //if (!persistedSyncState?.realms?.includes(msg.realm)) {
4055
- triggerSync(db, 'pull');
4056
- //}
4056
+ if (!((_c = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms) === null || _c === void 0 ? void 0 : _c.includes(msg.realm))) {
4057
+ yield db.cloud.sync({ purpose: 'pull', wait: true });
4058
+ //triggerSync(db, 'pull');
4059
+ }
4057
4060
  break;
4058
4061
  case 'realm-removed':
4059
- //if (
4060
- ((_a = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms) === null || _a === void 0 ? void 0 : _a.includes(msg.realm)) ||
4061
- ((_b = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.inviteRealms) === null || _b === void 0 ? void 0 : _b.includes(msg.realm));
4062
- //) {
4063
- triggerSync(db, 'pull');
4064
- //}
4062
+ if (((_d = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms) === null || _d === void 0 ? void 0 : _d.includes(msg.realm)) ||
4063
+ ((_e = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.inviteRealms) === null || _e === void 0 ? void 0 : _e.includes(msg.realm))) {
4064
+ yield db.cloud.sync({ purpose: 'pull', wait: true });
4065
+ //triggerSync(db, 'pull');
4066
+ }
4065
4067
  break;
4066
4068
  case 'realms-changed':
4067
- triggerSync(db, 'pull');
4069
+ //triggerSync(db, 'pull');
4070
+ yield db.cloud.sync({ purpose: 'pull', wait: true });
4068
4071
  break;
4069
4072
  case 'changes':
4070
4073
  console.debug('changes');
4071
- if (((_c = db.cloud.syncState.value) === null || _c === void 0 ? void 0 : _c.phase) === 'error') {
4074
+ if (((_f = db.cloud.syncState.value) === null || _f === void 0 ? void 0 : _f.phase) === 'error') {
4072
4075
  triggerSync(db, 'pull');
4073
4076
  break;
4074
4077
  }
@@ -4641,6 +4644,7 @@
4641
4644
  if (mode === 'readwrite') {
4642
4645
  // Give each transaction a globally unique id.
4643
4646
  tx.txid = randomString(16);
4647
+ tx.opCount = 0;
4644
4648
  // Introduce the concept of current user that lasts through the entire transaction.
4645
4649
  // This is important because the tracked mutations must be connected to the user.
4646
4650
  tx.currentUser = currentUserObservable.value;
@@ -4747,6 +4751,7 @@
4747
4751
  trans.mutationsAdded = true;
4748
4752
  const { txid, currentUser: { userId } } = trans;
4749
4753
  const { type } = req;
4754
+ const opNo = ++trans.opCount;
4750
4755
  return table.mutate(req).then((res) => {
4751
4756
  const { numFailures: hasFailures, failures } = res;
4752
4757
  let keys = type === 'delete' ? req.keys : res.results;
@@ -4761,6 +4766,7 @@
4761
4766
  ? {
4762
4767
  type: 'delete',
4763
4768
  ts,
4769
+ opNo,
4764
4770
  keys,
4765
4771
  criteria: req.criteria,
4766
4772
  txid,
@@ -5193,10 +5199,13 @@
5193
5199
  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
5194
5200
  switchMap(() => db.getPersistedSyncState()), // We need the info on which server revision we are at:
5195
5201
  filter((syncState) => syncState && syncState.serverRevision), // We wont send anything to server before inital sync has taken place
5196
- map((syncState) => ({
5197
- // Produce the message to trigger server to send us new messages to consume:
5198
- type: 'ready',
5199
- rev: syncState.serverRevision,
5202
+ switchMap((syncState) => __awaiter(this, void 0, void 0, function* () {
5203
+ return ({
5204
+ // Produce the message to trigger server to send us new messages to consume:
5205
+ type: 'ready',
5206
+ rev: syncState.serverRevision,
5207
+ realmSetHash: yield computeRealmSetHash(syncState)
5208
+ });
5200
5209
  })));
5201
5210
  function createObservable() {
5202
5211
  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.
@@ -6080,7 +6089,7 @@
6080
6089
  });
6081
6090
  const syncComplete = new rxjs.Subject();
6082
6091
  dexie.cloud = {
6083
- version: '4.0.1-beta.39',
6092
+ version: '4.0.1-beta.41',
6084
6093
  options: Object.assign({}, DEFAULT_OPTIONS),
6085
6094
  schema: null,
6086
6095
  get currentUserId() {
@@ -6341,7 +6350,7 @@
6341
6350
  });
6342
6351
  }
6343
6352
  }
6344
- dexieCloud.version = '4.0.1-beta.39';
6353
+ dexieCloud.version = '4.0.1-beta.41';
6345
6354
  Dexie__default["default"].Cloud = dexieCloud;
6346
6355
 
6347
6356
  exports["default"] = dexieCloud;