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

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.40, Mon May 08 2023
11
+ * Version 4.0.1-beta.42, Sat Jul 01 2023
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -2750,7 +2750,10 @@ function listClientChanges(mutationTables, db, { since = {}, limit = Infinity }
2750
2750
  }));
2751
2751
  })));
2752
2752
  // Sort by time to get a true order of the operations (between tables)
2753
- const sorted = flatten(allMutsOnTables).sort((a, b) => a.mut.ts - b.mut.ts);
2753
+ const sorted = flatten(allMutsOnTables).sort((a, b) => a.mut.txid === b.mut.txid
2754
+ ? a.mut.opNo - b.mut.opNo // Within same transaction, sort by opNo
2755
+ : a.mut.ts - b.mut.ts // Different transactions - sort by timestamp when mutation resolved
2756
+ );
2754
2757
  const result = [];
2755
2758
  let currentEntry = null;
2756
2759
  let currentTxid = null;
@@ -4637,6 +4640,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
4637
4640
  if (mode === 'readwrite') {
4638
4641
  // Give each transaction a globally unique id.
4639
4642
  tx.txid = randomString(16);
4643
+ tx.opCount = 0;
4640
4644
  // Introduce the concept of current user that lasts through the entire transaction.
4641
4645
  // This is important because the tracked mutations must be connected to the user.
4642
4646
  tx.currentUser = currentUserObservable.value;
@@ -4743,6 +4747,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
4743
4747
  trans.mutationsAdded = true;
4744
4748
  const { txid, currentUser: { userId } } = trans;
4745
4749
  const { type } = req;
4750
+ const opNo = ++trans.opCount;
4746
4751
  return table.mutate(req).then((res) => {
4747
4752
  const { numFailures: hasFailures, failures } = res;
4748
4753
  let keys = type === 'delete' ? req.keys : res.results;
@@ -4757,6 +4762,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
4757
4762
  ? {
4758
4763
  type: 'delete',
4759
4764
  ts,
4765
+ opNo,
4760
4766
  keys,
4761
4767
  criteria: req.criteria,
4762
4768
  txid,
@@ -6079,7 +6085,7 @@ function dexieCloud(dexie) {
6079
6085
  });
6080
6086
  const syncComplete = new Subject();
6081
6087
  dexie.cloud = {
6082
- version: '4.0.1-beta.40',
6088
+ version: '4.0.1-beta.42',
6083
6089
  options: Object.assign({}, DEFAULT_OPTIONS),
6084
6090
  schema: null,
6085
6091
  get currentUserId() {
@@ -6340,7 +6346,7 @@ function dexieCloud(dexie) {
6340
6346
  });
6341
6347
  }
6342
6348
  }
6343
- dexieCloud.version = '4.0.1-beta.40';
6349
+ dexieCloud.version = '4.0.1-beta.42';
6344
6350
  Dexie.Cloud = dexieCloud;
6345
6351
 
6346
6352
  export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId };