dexie 4.0.1-alpha.12 → 4.0.1-alpha.14

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.
package/dist/dexie.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 4.0.1-alpha.12, Tue May 30 2023
7
+ * Version 4.0.1-alpha.14, Wed May 31 2023
8
8
  *
9
9
  * https://dexie.org
10
10
  *
package/dist/dexie.js CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 4.0.1-alpha.12, Tue May 30 2023
7
+ * Version 4.0.1-alpha.14, Wed May 31 2023
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -1270,7 +1270,7 @@
1270
1270
  }
1271
1271
  }
1272
1272
 
1273
- var DEXIE_VERSION = '4.0.1-alpha.12';
1273
+ var DEXIE_VERSION = '4.0.1-alpha.14';
1274
1274
  var maxString = String.fromCharCode(65535);
1275
1275
  var minKey = -Infinity;
1276
1276
  var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
@@ -4753,7 +4753,8 @@
4753
4753
  if (finalResult === result)
4754
4754
  return result;
4755
4755
  finalResult.sort(function (a, b) {
4756
- return cmp(sortIndex.extractKey(a), sortIndex.extractKey(b));
4756
+ return cmp(extractIndex(a), extractIndex(b)) ||
4757
+ cmp(extractPrimKey(a), extractPrimKey(b));
4757
4758
  });
4758
4759
  if (req.limit) {
4759
4760
  if (finalResult.length > req.limit) {
@@ -4766,7 +4767,45 @@
4766
4767
  return immutable ? Object.freeze(finalResult) : finalResult;
4767
4768
  }
4768
4769
 
4770
+ function obsSetsOverlap(os1, os2) {
4771
+ return Object.keys(os1).some(function (key) { return os2[key] && rangesOverlap(os2[key], os1[key]); });
4772
+ }
4773
+
4769
4774
  var cache = {};
4775
+ function invalidateCachedQueries(updateParts) {
4776
+ var queriesToSignal = new Set();
4777
+ for (var key in updateParts) {
4778
+ var parts = /^idb\:\/\/(.*)\/(.*)\//.exec(key);
4779
+ if (parts) {
4780
+ var dbName = parts[1], tableName = parts[2];
4781
+ var tblCache = cache["idb://".concat(dbName, "/").concat(tableName)];
4782
+ if (tblCache)
4783
+ invalidateTableQueries(tblCache, updateParts, queriesToSignal);
4784
+ }
4785
+ }
4786
+ queriesToSignal.forEach(function (requery) { return requery(); });
4787
+ }
4788
+ function invalidateTableQueries(tblCache, mutatedParts, queriesToSignal) {
4789
+ var updatedEntryLists = [];
4790
+ for (var _i = 0, _a = Object.entries(tblCache.queries.query); _i < _a.length; _i++) {
4791
+ var _b = _a[_i], indexName = _b[0], entries = _b[1];
4792
+ var filteredEntries = [];
4793
+ for (var _c = 0, entries_1 = entries; _c < entries_1.length; _c++) {
4794
+ var entry = entries_1[_c];
4795
+ if (entry.obsSet && obsSetsOverlap(mutatedParts, entry.obsSet)) {
4796
+ entry.subscribers.forEach(function (requery) { return queriesToSignal.add(requery); });
4797
+ }
4798
+ else {
4799
+ filteredEntries.push(entry);
4800
+ }
4801
+ }
4802
+ updatedEntryLists.push([indexName, filteredEntries]);
4803
+ }
4804
+ for (var _d = 0, updatedEntryLists_1 = updatedEntryLists; _d < updatedEntryLists_1.length; _d++) {
4805
+ var _e = updatedEntryLists_1[_d], indexName = _e[0], newEntries = _e[1];
4806
+ tblCache.queries.query[indexName] = newEntries;
4807
+ }
4808
+ }
4770
4809
 
4771
4810
  function areRangesEqual(r1, r2) {
4772
4811
  return (cmp(r1.lower, r2.lower) === 0 &&
@@ -4852,10 +4891,6 @@
4852
4891
  }
4853
4892
  }
4854
4893
 
4855
- function obsSetsOverlap(os1, os2) {
4856
- return Object.keys(os1).some(function (key) { return os2[key] && rangesOverlap(os2[key], os1[key]); });
4857
- }
4858
-
4859
4894
  function signalSubscribers(tblCache, mutatedParts) {
4860
4895
  extendObservabilitySet(tblCache.unsignaledParts, mutatedParts);
4861
4896
  if (!tblCache.signalTimer) {
@@ -4916,6 +4951,7 @@
4916
4951
  delArrayItem(txs, idbtrans);
4917
4952
  ac_1.abort();
4918
4953
  if (mode === 'readwrite') {
4954
+ var affectedSubscribers_1 = new Set();
4919
4955
  for (var _i = 0, stores_1 = stores; _i < stores_1.length; _i++) {
4920
4956
  var storeName = stores_1[_i];
4921
4957
  var tblCache = cache["idb://".concat(dbName, "/").concat(storeName)];
@@ -4936,7 +4972,7 @@
4936
4972
  var modRes = applyOptimisticOps(entry.res, entry.req, ops, table, entry, freezeResults);
4937
4973
  if (entry.dirty) {
4938
4974
  delArrayItem(entries, entry);
4939
- entry.subscribers.forEach(function (requery) { return requery(); });
4975
+ entry.subscribers.forEach(function (requery) { return affectedSubscribers_1.add(requery); });
4940
4976
  }
4941
4977
  else if (modRes !== entry.res) {
4942
4978
  entry.res = modRes;
@@ -4947,7 +4983,7 @@
4947
4983
  if (entry.dirty) {
4948
4984
  delArrayItem(entries, entry);
4949
4985
  }
4950
- entry.subscribers.forEach(function (requery) { return requery(); });
4986
+ entry.subscribers.forEach(function (requery) { return affectedSubscribers_1.add(requery); });
4951
4987
  }
4952
4988
  }
4953
4989
  }
@@ -4955,6 +4991,7 @@
4955
4991
  }
4956
4992
  }
4957
4993
  }
4994
+ affectedSubscribers_1.forEach(function (requery) { return requery(); });
4958
4995
  }
4959
4996
  }; };
4960
4997
  idbtrans.addEventListener('abort', endTransaction(false), {
@@ -5435,10 +5472,13 @@
5435
5472
  return closed;
5436
5473
  },
5437
5474
  unsubscribe: function () {
5475
+ if (closed)
5476
+ return;
5438
5477
  closed = true;
5439
5478
  if (abortController)
5440
5479
  abortController.abort();
5441
- globalEvents.storagemutated.unsubscribe(mutationListener);
5480
+ if (startedListening)
5481
+ globalEvents.storagemutated.unsubscribe(mutationListener);
5442
5482
  txs.forEach(function (idbtrans) {
5443
5483
  idbtrans.aborted = true;
5444
5484
  try {
@@ -5488,10 +5528,6 @@
5488
5528
  trans: null
5489
5529
  };
5490
5530
  var ret = execute(ctx);
5491
- if (!startedListening) {
5492
- globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, mutationListener);
5493
- startedListening = true;
5494
- }
5495
5531
  Promise.resolve(ret).then(function (result) {
5496
5532
  hasValue = true;
5497
5533
  currentValue = result;
@@ -5500,6 +5536,10 @@
5500
5536
  }
5501
5537
  accumMuts = {};
5502
5538
  currentObs = subscr;
5539
+ if (keys(currentObs).length > 0 && !startedListening) {
5540
+ globalEvents(DEXIE_STORAGE_MUTATED_EVENT_NAME, mutationListener);
5541
+ startedListening = true;
5542
+ }
5503
5543
  observer.next && observer.next(result);
5504
5544
  }, function (err) {
5505
5545
  hasValue = false;
@@ -5631,6 +5671,7 @@
5631
5671
  try {
5632
5672
  propagatingLocally = true;
5633
5673
  globalEvents.storagemutated.fire(updateParts);
5674
+ invalidateCachedQueries(updateParts);
5634
5675
  }
5635
5676
  finally {
5636
5677
  propagatingLocally = wasMe;