dexie 4.0.7 → 4.0.8

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.
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 4.0.7, Sun May 26 2024
7
+ * Version 4.0.8, Wed Jul 10 2024
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -1094,7 +1094,7 @@ function tempTransaction(db, mode, storeNames, fn) {
1094
1094
  }
1095
1095
  }
1096
1096
 
1097
- const DEXIE_VERSION = '4.0.7';
1097
+ const DEXIE_VERSION = '4.0.8';
1098
1098
  const maxString = String.fromCharCode(65535);
1099
1099
  const minKey = -Infinity;
1100
1100
  const INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
@@ -3653,6 +3653,10 @@ props(RangeSet.prototype, {
3653
3653
  keys.forEach(key => addRange(this, key, key));
3654
3654
  return this;
3655
3655
  },
3656
+ hasKey(key) {
3657
+ const node = getRangeSetIterator(this).next(key).value;
3658
+ return node && cmp(node.from, key) <= 0 && cmp(node.to, key) >= 0;
3659
+ },
3656
3660
  [iteratorSymbol]() {
3657
3661
  return getRangeSetIterator(this);
3658
3662
  }
@@ -4744,19 +4748,23 @@ function applyOptimisticOps(result, req, ops, table, cacheEntry, immutable) {
4744
4748
  const extractLowLevelIndex = (index.lowLevelIndex || index).extractKey;
4745
4749
  let finalResult = ops.reduce((result, op) => {
4746
4750
  let modifedResult = result;
4747
- const includedValues = op.type === 'add' || op.type === 'put'
4748
- ? op.values.filter((v) => {
4749
- const key = extractIndex(v);
4750
- return multiEntry && isArray(key)
4751
+ const includedValues = [];
4752
+ if (op.type === 'add' || op.type === 'put') {
4753
+ const includedPKs = new RangeSet();
4754
+ for (let i = op.values.length - 1; i >= 0; --i) {
4755
+ const value = op.values[i];
4756
+ const pk = extractPrimKey(value);
4757
+ if (includedPKs.hasKey(pk))
4758
+ continue;
4759
+ const key = extractIndex(value);
4760
+ if (multiEntry && isArray(key)
4751
4761
  ? key.some((k) => isWithinRange(k, queryRange))
4752
- : isWithinRange(key, queryRange);
4753
- }).map(v => {
4754
- v = deepClone(v);
4755
- if (immutable)
4756
- Object.freeze(v);
4757
- return v;
4758
- })
4759
- : [];
4762
+ : isWithinRange(key, queryRange)) {
4763
+ includedPKs.addKey(pk);
4764
+ includedValues.push(value);
4765
+ }
4766
+ }
4767
+ }
4760
4768
  switch (op.type) {
4761
4769
  case 'add':
4762
4770
  modifedResult = result.concat(req.values
@@ -4766,20 +4774,16 @@ function applyOptimisticOps(result, req, ops, table, cacheEntry, immutable) {
4766
4774
  case 'put':
4767
4775
  const keySet = new RangeSet().addKeys(op.values.map((v) => extractPrimKey(v)));
4768
4776
  modifedResult = result
4769
- .filter((item) => {
4770
- const key = req.values ? extractPrimKey(item) : item;
4771
- return !rangesOverlap(new RangeSet(key), keySet);
4772
- })
4773
- .concat(req.values
4777
+ .filter(
4778
+ (item) => !keySet.hasKey(req.values ? extractPrimKey(item) : item))
4779
+ .concat(
4780
+ req.values
4774
4781
  ? includedValues
4775
4782
  : includedValues.map((v) => extractPrimKey(v)));
4776
4783
  break;
4777
4784
  case 'delete':
4778
4785
  const keysToDelete = new RangeSet().addKeys(op.keys);
4779
- modifedResult = result.filter((item) => {
4780
- const key = req.values ? extractPrimKey(item) : item;
4781
- return !rangesOverlap(new RangeSet(key), keysToDelete);
4782
- });
4786
+ modifedResult = result.filter((item) => !keysToDelete.hasKey(req.values ? extractPrimKey(item) : item));
4783
4787
  break;
4784
4788
  case 'deleteRange':
4785
4789
  const range = op.range;