dexie 4.0.5 → 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.5, Sat May 25 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.5';
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>.";
@@ -2054,6 +2054,12 @@ class Collection {
2054
2054
  }
2055
2055
  };
2056
2056
  return this.clone().primaryKeys().then(keys => {
2057
+ const criteria = isPlainKeyRange(ctx) &&
2058
+ ctx.limit === Infinity &&
2059
+ (typeof changes !== 'function' || changes === deleteCallback) && {
2060
+ index: ctx.index,
2061
+ range: ctx.range
2062
+ };
2057
2063
  const nextChunk = (offset) => {
2058
2064
  const count = Math.min(limit, keys.length - offset);
2059
2065
  return coreTable.getMany({
@@ -2086,12 +2092,6 @@ class Collection {
2086
2092
  }
2087
2093
  }
2088
2094
  }
2089
- const criteria = isPlainKeyRange(ctx) &&
2090
- ctx.limit === Infinity &&
2091
- (typeof changes !== 'function' || changes === deleteCallback) && {
2092
- index: ctx.index,
2093
- range: ctx.range
2094
- };
2095
2095
  return Promise.resolve(addValues.length > 0 &&
2096
2096
  coreTable.mutate({ trans, type: 'add', values: addValues })
2097
2097
  .then(res => {
@@ -2107,13 +2107,15 @@ class Collection {
2107
2107
  values: putValues,
2108
2108
  criteria,
2109
2109
  changeSpec: typeof changes !== 'function'
2110
- && changes
2110
+ && changes,
2111
+ isAdditionalChunk: offset > 0
2111
2112
  }).then(res => applyMutateResult(putValues.length, res))).then(() => (deleteKeys.length > 0 || (criteria && changes === deleteCallback)) &&
2112
2113
  coreTable.mutate({
2113
2114
  trans,
2114
2115
  type: 'delete',
2115
2116
  keys: deleteKeys,
2116
- criteria
2117
+ criteria,
2118
+ isAdditionalChunk: offset > 0
2117
2119
  }).then(res => applyMutateResult(deleteKeys.length, res))).then(() => {
2118
2120
  return keys.length > offset + count && nextChunk(offset + limit);
2119
2121
  });
@@ -3651,6 +3653,10 @@ props(RangeSet.prototype, {
3651
3653
  keys.forEach(key => addRange(this, key, key));
3652
3654
  return this;
3653
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
+ },
3654
3660
  [iteratorSymbol]() {
3655
3661
  return getRangeSetIterator(this);
3656
3662
  }
@@ -4742,19 +4748,23 @@ function applyOptimisticOps(result, req, ops, table, cacheEntry, immutable) {
4742
4748
  const extractLowLevelIndex = (index.lowLevelIndex || index).extractKey;
4743
4749
  let finalResult = ops.reduce((result, op) => {
4744
4750
  let modifedResult = result;
4745
- const includedValues = op.type === 'add' || op.type === 'put'
4746
- ? op.values.filter((v) => {
4747
- const key = extractIndex(v);
4748
- 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)
4749
4761
  ? key.some((k) => isWithinRange(k, queryRange))
4750
- : isWithinRange(key, queryRange);
4751
- }).map(v => {
4752
- v = deepClone(v);
4753
- if (immutable)
4754
- Object.freeze(v);
4755
- return v;
4756
- })
4757
- : [];
4762
+ : isWithinRange(key, queryRange)) {
4763
+ includedPKs.addKey(pk);
4764
+ includedValues.push(value);
4765
+ }
4766
+ }
4767
+ }
4758
4768
  switch (op.type) {
4759
4769
  case 'add':
4760
4770
  modifedResult = result.concat(req.values
@@ -4764,20 +4774,16 @@ function applyOptimisticOps(result, req, ops, table, cacheEntry, immutable) {
4764
4774
  case 'put':
4765
4775
  const keySet = new RangeSet().addKeys(op.values.map((v) => extractPrimKey(v)));
4766
4776
  modifedResult = result
4767
- .filter((item) => {
4768
- const key = req.values ? extractPrimKey(item) : item;
4769
- return !rangesOverlap(new RangeSet(key), keySet);
4770
- })
4771
- .concat(req.values
4777
+ .filter(
4778
+ (item) => !keySet.hasKey(req.values ? extractPrimKey(item) : item))
4779
+ .concat(
4780
+ req.values
4772
4781
  ? includedValues
4773
4782
  : includedValues.map((v) => extractPrimKey(v)));
4774
4783
  break;
4775
4784
  case 'delete':
4776
4785
  const keysToDelete = new RangeSet().addKeys(op.keys);
4777
- modifedResult = result.filter((item) => {
4778
- const key = req.values ? extractPrimKey(item) : item;
4779
- return !rangesOverlap(new RangeSet(key), keysToDelete);
4780
- });
4786
+ modifedResult = result.filter((item) => !keysToDelete.hasKey(req.values ? extractPrimKey(item) : item));
4781
4787
  break;
4782
4788
  case 'deleteRange':
4783
4789
  const range = op.range;