dexie 4.0.8 → 4.0.9

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.8, Wed Jul 10 2024
7
+ * Version 4.0.9, Mon Oct 21 2024
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -720,6 +720,8 @@ if (NativePromise) {
720
720
  }));
721
721
  });
722
722
  });
723
+ if (NativePromise.withResolvers)
724
+ DexiePromise.withResolvers = NativePromise.withResolvers;
723
725
  }
724
726
  function executePromiseTask(promise, fn) {
725
727
  try {
@@ -1094,7 +1096,7 @@ function tempTransaction(db, mode, storeNames, fn) {
1094
1096
  }
1095
1097
  }
1096
1098
 
1097
- const DEXIE_VERSION = '4.0.8';
1099
+ const DEXIE_VERSION = '4.0.9';
1098
1100
  const maxString = String.fromCharCode(65535);
1099
1101
  const minKey = -Infinity;
1100
1102
  const INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
@@ -1284,9 +1286,8 @@ class Table {
1284
1286
  console.warn(`The query ${JSON.stringify(indexOrCrit)} on ${this.name} would benefit from a ` +
1285
1287
  `compound index [${keyPaths.join('+')}]`);
1286
1288
  const { idxByName } = this.schema;
1287
- const idb = this.db._deps.indexedDB;
1288
1289
  function equals(a, b) {
1289
- return idb.cmp(a, b) === 0;
1290
+ return cmp(a, b) === 0;
1290
1291
  }
1291
1292
  const [idx, filterFunction] = keyPaths.reduce(([prevIndex, prevFilterFn], keyPath) => {
1292
1293
  const index = idxByName[keyPath];
@@ -1830,7 +1831,7 @@ class Collection {
1830
1831
  var order = this._ctx.dir === "next" ? 1 : -1;
1831
1832
  function sorter(a, b) {
1832
1833
  var aVal = getval(a, lastIndex), bVal = getval(b, lastIndex);
1833
- return aVal < bVal ? -order : aVal > bVal ? order : 0;
1834
+ return cmp(aVal, bVal) * order;
1834
1835
  }
1835
1836
  return this.toArray(function (a) {
1836
1837
  return a.sort(sorter);
@@ -4542,7 +4543,10 @@ const observabilityMiddleware = {
4542
4543
  }
4543
4544
  }
4544
4545
  else if (keys) {
4545
- const range = { from: keys.lower, to: keys.upper };
4546
+ const range = {
4547
+ from: keys.lower ?? core.MIN_KEY,
4548
+ to: keys.upper ?? core.MAX_KEY
4549
+ };
4546
4550
  delsRangeSet.add(range);
4547
4551
  pkRangeSet.add(range);
4548
4552
  }
@@ -4766,12 +4770,27 @@ function applyOptimisticOps(result, req, ops, table, cacheEntry, immutable) {
4766
4770
  }
4767
4771
  }
4768
4772
  switch (op.type) {
4769
- case 'add':
4773
+ case 'add': {
4774
+ const existingKeys = new RangeSet().addKeys(req.values ? result.map((v) => extractPrimKey(v)) : result);
4770
4775
  modifedResult = result.concat(req.values
4771
- ? includedValues
4772
- : includedValues.map((v) => extractPrimKey(v)));
4776
+ ? includedValues.filter((v) => {
4777
+ const key = extractPrimKey(v);
4778
+ if (existingKeys.hasKey(key))
4779
+ return false;
4780
+ existingKeys.addKey(key);
4781
+ return true;
4782
+ })
4783
+ : includedValues
4784
+ .map((v) => extractPrimKey(v))
4785
+ .filter((k) => {
4786
+ if (existingKeys.hasKey(k))
4787
+ return false;
4788
+ existingKeys.addKey(k);
4789
+ return true;
4790
+ }));
4773
4791
  break;
4774
- case 'put':
4792
+ }
4793
+ case 'put': {
4775
4794
  const keySet = new RangeSet().addKeys(op.values.map((v) => extractPrimKey(v)));
4776
4795
  modifedResult = result
4777
4796
  .filter(
@@ -4781,6 +4800,7 @@ function applyOptimisticOps(result, req, ops, table, cacheEntry, immutable) {
4781
4800
  ? includedValues
4782
4801
  : includedValues.map((v) => extractPrimKey(v)));
4783
4802
  break;
4803
+ }
4784
4804
  case 'delete':
4785
4805
  const keysToDelete = new RangeSet().addKeys(op.keys);
4786
4806
  modifedResult = result.filter((item) => !keysToDelete.hasKey(req.values ? extractPrimKey(item) : item));
@@ -4991,7 +5011,8 @@ const cacheMiddleware = {
4991
5011
  const trans = PSD.trans;
4992
5012
  if (primKey.outbound ||
4993
5013
  trans.db._options.cache === 'disabled' ||
4994
- trans.explicit
5014
+ trans.explicit ||
5015
+ trans.idbtrans.mode !== 'readwrite'
4995
5016
  ) {
4996
5017
  return downTable.mutate(req);
4997
5018
  }
@@ -5004,6 +5025,8 @@ const cacheMiddleware = {
5004
5025
  const reqWithResolvedKeys = {
5005
5026
  ...req,
5006
5027
  values: req.values.map((value, i) => {
5028
+ if (res.failures[i])
5029
+ return value;
5007
5030
  const valueWithKey = primKey.keyPath?.includes('.')
5008
5031
  ? deepClone(value)
5009
5032
  : {