dexie 3.2.4 → 3.2.5

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.mjs CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 3.2.4, Tue May 30 2023
7
+ * Version 3.2.5, Thu Feb 08 2024
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -130,7 +130,7 @@ function tryCatch(fn, onerror, args) {
130
130
  }
131
131
  }
132
132
  function getByKeyPath(obj, keyPath) {
133
- if (hasOwn(obj, keyPath))
133
+ if (typeof keyPath === 'string' && hasOwn(obj, keyPath))
134
134
  return obj[keyPath];
135
135
  if (!keyPath)
136
136
  return obj;
@@ -213,7 +213,7 @@ var concat = [].concat;
213
213
  function flatten(a) {
214
214
  return concat.apply([], a);
215
215
  }
216
- var intrinsicTypeNames = "Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey"
216
+ var intrinsicTypeNames = "BigUint64Array,BigInt64Array,Array,Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,FileSystemDirectoryHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey"
217
217
  .split(',').concat(flatten([8, 16, 32, 64].map(function (num) { return ["Int", "Uint", "Float"].map(function (t) { return t + num + "Array"; }); }))).filter(function (t) { return _global[t]; });
218
218
  var intrinsicTypes = intrinsicTypeNames.map(function (t) { return _global[t]; });
219
219
  arrayToObject(intrinsicTypeNames, function (x) { return [x, true]; });
@@ -1281,7 +1281,7 @@ function tempTransaction(db, mode, storeNames, fn) {
1281
1281
  }
1282
1282
  }
1283
1283
 
1284
- var DEXIE_VERSION = '3.2.4';
1284
+ var DEXIE_VERSION = '3.2.5';
1285
1285
  var maxString = String.fromCharCode(65535);
1286
1286
  var minKey = -Infinity;
1287
1287
  var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
@@ -1367,14 +1367,22 @@ var Table = (function () {
1367
1367
  .where(keyPaths[0])
1368
1368
  .equals(indexOrCrit[keyPaths[0]]);
1369
1369
  var compoundIndex = this.schema.indexes.concat(this.schema.primKey).filter(function (ix) {
1370
- return ix.compound &&
1371
- keyPaths.every(function (keyPath) { return ix.keyPath.indexOf(keyPath) >= 0; }) &&
1372
- ix.keyPath.every(function (keyPath) { return keyPaths.indexOf(keyPath) >= 0; });
1373
- })[0];
1374
- if (compoundIndex && this.db._maxKey !== maxString)
1370
+ if (ix.compound &&
1371
+ keyPaths.every(function (keyPath) { return ix.keyPath.indexOf(keyPath) >= 0; })) {
1372
+ for (var i = 0; i < keyPaths.length; ++i) {
1373
+ if (keyPaths.indexOf(ix.keyPath[i]) === -1)
1374
+ return false;
1375
+ }
1376
+ return true;
1377
+ }
1378
+ return false;
1379
+ }).sort(function (a, b) { return a.keyPath.length - b.keyPath.length; })[0];
1380
+ if (compoundIndex && this.db._maxKey !== maxString) {
1381
+ var keyPathsInValidOrder = compoundIndex.keyPath.slice(0, keyPaths.length);
1375
1382
  return this
1376
- .where(compoundIndex.name)
1377
- .equals(compoundIndex.keyPath.map(function (kp) { return indexOrCrit[kp]; }));
1383
+ .where(keyPathsInValidOrder)
1384
+ .equals(keyPathsInValidOrder.map(function (kp) { return indexOrCrit[kp]; }));
1385
+ }
1378
1386
  if (!compoundIndex && debug)
1379
1387
  console.warn("The query " + JSON.stringify(indexOrCrit) + " on " + this.name + " would benefit of a " +
1380
1388
  ("compound index [" + keyPaths.join('+') + "]"));
@@ -3727,69 +3735,82 @@ function dexieOpen(db) {
3727
3735
  }
3728
3736
  var resolveDbReady = state.dbReadyResolve,
3729
3737
  upgradeTransaction = null, wasCreated = false;
3730
- return DexiePromise.race([openCanceller, (typeof navigator === 'undefined' ? DexiePromise.resolve() : idbReady()).then(function () { return new DexiePromise(function (resolve, reject) {
3731
- throwIfCancelled();
3732
- if (!indexedDB)
3733
- throw new exceptions.MissingAPI();
3734
- var dbName = db.name;
3735
- var req = state.autoSchema ?
3736
- indexedDB.open(dbName) :
3737
- indexedDB.open(dbName, Math.round(db.verno * 10));
3738
- if (!req)
3739
- throw new exceptions.MissingAPI();
3740
- req.onerror = eventRejectHandler(reject);
3741
- req.onblocked = wrap(db._fireOnBlocked);
3742
- req.onupgradeneeded = wrap(function (e) {
3743
- upgradeTransaction = req.transaction;
3744
- if (state.autoSchema && !db._options.allowEmptyDB) {
3745
- req.onerror = preventDefault;
3746
- upgradeTransaction.abort();
3747
- req.result.close();
3748
- var delreq = indexedDB.deleteDatabase(dbName);
3749
- delreq.onsuccess = delreq.onerror = wrap(function () {
3750
- reject(new exceptions.NoSuchDatabase("Database " + dbName + " doesnt exist"));
3751
- });
3752
- }
3753
- else {
3754
- upgradeTransaction.onerror = eventRejectHandler(reject);
3755
- var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
3756
- wasCreated = oldVer < 1;
3757
- db._novip.idbdb = req.result;
3758
- runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
3759
- }
3760
- }, reject);
3761
- req.onsuccess = wrap(function () {
3762
- upgradeTransaction = null;
3763
- var idbdb = db._novip.idbdb = req.result;
3764
- var objectStoreNames = slice(idbdb.objectStoreNames);
3765
- if (objectStoreNames.length > 0)
3766
- try {
3767
- var tmpTrans = idbdb.transaction(safariMultiStoreFix(objectStoreNames), 'readonly');
3768
- if (state.autoSchema)
3769
- readGlobalSchema(db, idbdb, tmpTrans);
3770
- else {
3771
- adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
3772
- if (!verifyInstalledSchema(db, tmpTrans)) {
3773
- console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Some queries may fail.");
3774
- }
3738
+ var tryOpenDB = function () { return new DexiePromise(function (resolve, reject) {
3739
+ throwIfCancelled();
3740
+ if (!indexedDB)
3741
+ throw new exceptions.MissingAPI();
3742
+ var dbName = db.name;
3743
+ var req = state.autoSchema ?
3744
+ indexedDB.open(dbName) :
3745
+ indexedDB.open(dbName, Math.round(db.verno * 10));
3746
+ if (!req)
3747
+ throw new exceptions.MissingAPI();
3748
+ req.onerror = eventRejectHandler(reject);
3749
+ req.onblocked = wrap(db._fireOnBlocked);
3750
+ req.onupgradeneeded = wrap(function (e) {
3751
+ upgradeTransaction = req.transaction;
3752
+ if (state.autoSchema && !db._options.allowEmptyDB) {
3753
+ req.onerror = preventDefault;
3754
+ upgradeTransaction.abort();
3755
+ req.result.close();
3756
+ var delreq = indexedDB.deleteDatabase(dbName);
3757
+ delreq.onsuccess = delreq.onerror = wrap(function () {
3758
+ reject(new exceptions.NoSuchDatabase("Database " + dbName + " doesnt exist"));
3759
+ });
3760
+ }
3761
+ else {
3762
+ upgradeTransaction.onerror = eventRejectHandler(reject);
3763
+ var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
3764
+ wasCreated = oldVer < 1;
3765
+ db._novip.idbdb = req.result;
3766
+ runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
3767
+ }
3768
+ }, reject);
3769
+ req.onsuccess = wrap(function () {
3770
+ upgradeTransaction = null;
3771
+ var idbdb = db._novip.idbdb = req.result;
3772
+ var objectStoreNames = slice(idbdb.objectStoreNames);
3773
+ if (objectStoreNames.length > 0)
3774
+ try {
3775
+ var tmpTrans = idbdb.transaction(safariMultiStoreFix(objectStoreNames), 'readonly');
3776
+ if (state.autoSchema)
3777
+ readGlobalSchema(db, idbdb, tmpTrans);
3778
+ else {
3779
+ adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
3780
+ if (!verifyInstalledSchema(db, tmpTrans)) {
3781
+ console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Some queries may fail.");
3775
3782
  }
3776
- generateMiddlewareStacks(db, tmpTrans);
3777
- }
3778
- catch (e) {
3779
3783
  }
3780
- connections.push(db);
3781
- idbdb.onversionchange = wrap(function (ev) {
3782
- state.vcFired = true;
3783
- db.on("versionchange").fire(ev);
3784
- });
3785
- idbdb.onclose = wrap(function (ev) {
3786
- db.on("close").fire(ev);
3787
- });
3788
- if (wasCreated)
3789
- _onDatabaseCreated(db._deps, dbName);
3790
- resolve();
3791
- }, reject);
3792
- }); })]).then(function () {
3784
+ generateMiddlewareStacks(db, tmpTrans);
3785
+ }
3786
+ catch (e) {
3787
+ }
3788
+ connections.push(db);
3789
+ idbdb.onversionchange = wrap(function (ev) {
3790
+ state.vcFired = true;
3791
+ db.on("versionchange").fire(ev);
3792
+ });
3793
+ idbdb.onclose = wrap(function (ev) {
3794
+ db.on("close").fire(ev);
3795
+ });
3796
+ if (wasCreated)
3797
+ _onDatabaseCreated(db._deps, dbName);
3798
+ resolve();
3799
+ }, reject);
3800
+ }).catch(function (err) {
3801
+ if (err && err.name === 'UnknownError' && state.PR1398_maxLoop > 0) {
3802
+ state.PR1398_maxLoop--;
3803
+ console.warn('Dexie: Workaround for Chrome UnknownError on open()');
3804
+ return tryOpenDB();
3805
+ }
3806
+ else {
3807
+ return DexiePromise.reject(err);
3808
+ }
3809
+ }); };
3810
+ return DexiePromise.race([
3811
+ openCanceller,
3812
+ (typeof navigator === 'undefined' ? DexiePromise.resolve() : idbReady()).then(tryOpenDB)
3813
+ ]).then(function () {
3793
3814
  throwIfCancelled();
3794
3815
  state.onReadyBeingFired = [];
3795
3816
  return DexiePromise.resolve(vip(function () { return db.on.ready.fire(db.vip); })).then(function fireRemainders() {