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.
@@ -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
  *
@@ -4007,7 +4007,7 @@ function MessagesFromServerConsumer(db) {
4007
4007
  event.next(null);
4008
4008
  }
4009
4009
  function consumeQueue() {
4010
- var _a, _b, _c;
4010
+ var _a, _b, _c, _d, _e, _f;
4011
4011
  return __awaiter(this, void 0, void 0, function* () {
4012
4012
  while (queue.length > 0) {
4013
4013
  const msg = queue.shift();
@@ -4039,29 +4039,32 @@ function MessagesFromServerConsumer(db) {
4039
4039
  // new token. So we don't need to do anything more here.
4040
4040
  break;
4041
4041
  case 'realm-added':
4042
- //if (!persistedSyncState?.realms?.includes(msg.realm) && !persistedSyncState?.inviteRealms?.includes(msg.realm)) {
4043
- triggerSync(db, 'pull');
4044
- //}
4042
+ if (!((_a = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms) === null || _a === void 0 ? void 0 : _a.includes(msg.realm)) &&
4043
+ !((_b = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.inviteRealms) === null || _b === void 0 ? void 0 : _b.includes(msg.realm))) {
4044
+ yield db.cloud.sync({ purpose: 'pull', wait: true });
4045
+ //triggerSync(db, 'pull');
4046
+ }
4045
4047
  break;
4046
4048
  case 'realm-accepted':
4047
- //if (!persistedSyncState?.realms?.includes(msg.realm)) {
4048
- triggerSync(db, 'pull');
4049
- //}
4049
+ if (!((_c = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms) === null || _c === void 0 ? void 0 : _c.includes(msg.realm))) {
4050
+ yield db.cloud.sync({ purpose: 'pull', wait: true });
4051
+ //triggerSync(db, 'pull');
4052
+ }
4050
4053
  break;
4051
4054
  case 'realm-removed':
4052
- //if (
4053
- ((_a = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms) === null || _a === void 0 ? void 0 : _a.includes(msg.realm)) ||
4054
- ((_b = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.inviteRealms) === null || _b === void 0 ? void 0 : _b.includes(msg.realm));
4055
- //) {
4056
- triggerSync(db, 'pull');
4057
- //}
4055
+ if (((_d = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms) === null || _d === void 0 ? void 0 : _d.includes(msg.realm)) ||
4056
+ ((_e = persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.inviteRealms) === null || _e === void 0 ? void 0 : _e.includes(msg.realm))) {
4057
+ yield db.cloud.sync({ purpose: 'pull', wait: true });
4058
+ //triggerSync(db, 'pull');
4059
+ }
4058
4060
  break;
4059
4061
  case 'realms-changed':
4060
- triggerSync(db, 'pull');
4062
+ //triggerSync(db, 'pull');
4063
+ yield db.cloud.sync({ purpose: 'pull', wait: true });
4061
4064
  break;
4062
4065
  case 'changes':
4063
4066
  console.debug('changes');
4064
- if (((_c = db.cloud.syncState.value) === null || _c === void 0 ? void 0 : _c.phase) === 'error') {
4067
+ if (((_f = db.cloud.syncState.value) === null || _f === void 0 ? void 0 : _f.phase) === 'error') {
4065
4068
  triggerSync(db, 'pull');
4066
4069
  break;
4067
4070
  }
@@ -4634,6 +4637,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
4634
4637
  if (mode === 'readwrite') {
4635
4638
  // Give each transaction a globally unique id.
4636
4639
  tx.txid = randomString(16);
4640
+ tx.opCount = 0;
4637
4641
  // Introduce the concept of current user that lasts through the entire transaction.
4638
4642
  // This is important because the tracked mutations must be connected to the user.
4639
4643
  tx.currentUser = currentUserObservable.value;
@@ -4740,6 +4744,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
4740
4744
  trans.mutationsAdded = true;
4741
4745
  const { txid, currentUser: { userId } } = trans;
4742
4746
  const { type } = req;
4747
+ const opNo = ++trans.opCount;
4743
4748
  return table.mutate(req).then((res) => {
4744
4749
  const { numFailures: hasFailures, failures } = res;
4745
4750
  let keys = type === 'delete' ? req.keys : res.results;
@@ -4754,6 +4759,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
4754
4759
  ? {
4755
4760
  type: 'delete',
4756
4761
  ts,
4762
+ opNo,
4757
4763
  keys,
4758
4764
  criteria: req.criteria,
4759
4765
  txid,
@@ -5186,10 +5192,13 @@ function connectWebSocket(db) {
5186
5192
  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
5187
5193
  switchMap(() => db.getPersistedSyncState()), // We need the info on which server revision we are at:
5188
5194
  filter((syncState) => syncState && syncState.serverRevision), // We wont send anything to server before inital sync has taken place
5189
- map((syncState) => ({
5190
- // Produce the message to trigger server to send us new messages to consume:
5191
- type: 'ready',
5192
- rev: syncState.serverRevision,
5195
+ switchMap((syncState) => __awaiter(this, void 0, void 0, function* () {
5196
+ return ({
5197
+ // Produce the message to trigger server to send us new messages to consume:
5198
+ type: 'ready',
5199
+ rev: syncState.serverRevision,
5200
+ realmSetHash: yield computeRealmSetHash(syncState)
5201
+ });
5193
5202
  })));
5194
5203
  function createObservable() {
5195
5204
  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.
@@ -6073,7 +6082,7 @@ function dexieCloud(dexie) {
6073
6082
  });
6074
6083
  const syncComplete = new Subject();
6075
6084
  dexie.cloud = {
6076
- version: '4.0.1-beta.39',
6085
+ version: '4.0.1-beta.41',
6077
6086
  options: Object.assign({}, DEFAULT_OPTIONS),
6078
6087
  schema: null,
6079
6088
  get currentUserId() {
@@ -6334,7 +6343,7 @@ function dexieCloud(dexie) {
6334
6343
  });
6335
6344
  }
6336
6345
  }
6337
- dexieCloud.version = '4.0.1-beta.39';
6346
+ dexieCloud.version = '4.0.1-beta.41';
6338
6347
  Dexie.Cloud = dexieCloud;
6339
6348
 
6340
6349
  export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId };