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.
@@ -329,7 +329,10 @@ function listClientChanges(mutationTables, db, { since = {}, limit = Infinity }
329
329
  }));
330
330
  })));
331
331
  // Sort by time to get a true order of the operations (between tables)
332
- const sorted = flatten(allMutsOnTables).sort((a, b) => a.mut.ts - b.mut.ts);
332
+ const sorted = flatten(allMutsOnTables).sort((a, b) => a.mut.txid === b.mut.txid
333
+ ? a.mut.opNo - b.mut.opNo // Within same transaction, sort by opNo
334
+ : a.mut.ts - b.mut.ts // Different transactions - sort by timestamp when mutation resolved
335
+ );
333
336
  const result = [];
334
337
  let currentEntry = null;
335
338
  let currentTxid = null;
@@ -2999,6 +3002,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
2999
3002
  if (mode === 'readwrite') {
3000
3003
  // Give each transaction a globally unique id.
3001
3004
  tx.txid = randomString$1(16);
3005
+ tx.opCount = 0;
3002
3006
  // Introduce the concept of current user that lasts through the entire transaction.
3003
3007
  // This is important because the tracked mutations must be connected to the user.
3004
3008
  tx.currentUser = currentUserObservable.value;
@@ -3105,6 +3109,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
3105
3109
  trans.mutationsAdded = true;
3106
3110
  const { txid, currentUser: { userId } } = trans;
3107
3111
  const { type } = req;
3112
+ const opNo = ++trans.opCount;
3108
3113
  return table.mutate(req).then((res) => {
3109
3114
  const { numFailures: hasFailures, failures } = res;
3110
3115
  let keys = type === 'delete' ? req.keys : res.results;
@@ -3119,6 +3124,7 @@ function createMutationTrackingMiddleware({ currentUserObservable, db }) {
3119
3124
  ? {
3120
3125
  type: 'delete',
3121
3126
  ts,
3127
+ opNo,
3122
3128
  keys,
3123
3129
  criteria: req.criteria,
3124
3130
  txid,
@@ -4434,7 +4440,7 @@ function dexieCloud(dexie) {
4434
4440
  });
4435
4441
  const syncComplete = new Subject();
4436
4442
  dexie.cloud = {
4437
- version: '4.0.1-beta.40',
4443
+ version: '4.0.1-beta.42',
4438
4444
  options: Object.assign({}, DEFAULT_OPTIONS),
4439
4445
  schema: null,
4440
4446
  get currentUserId() {
@@ -4695,7 +4701,7 @@ function dexieCloud(dexie) {
4695
4701
  });
4696
4702
  }
4697
4703
  }
4698
- dexieCloud.version = '4.0.1-beta.40';
4704
+ dexieCloud.version = '4.0.1-beta.42';
4699
4705
  Dexie.Cloud = dexieCloud;
4700
4706
 
4701
4707
  // In case the SW lives for a while, let it reuse already opened connections: