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.
@@ -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
  *
@@ -98,7 +98,7 @@ function tryCatch(fn, onerror, args) {
98
98
  }
99
99
  }
100
100
  function getByKeyPath(obj, keyPath) {
101
- if (hasOwn(obj, keyPath))
101
+ if (typeof keyPath === 'string' && hasOwn(obj, keyPath))
102
102
  return obj[keyPath];
103
103
  if (!keyPath)
104
104
  return obj;
@@ -181,7 +181,7 @@ const concat = [].concat;
181
181
  function flatten(a) {
182
182
  return concat.apply([], a);
183
183
  }
184
- const intrinsicTypeNames = "Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey"
184
+ const intrinsicTypeNames = "BigUint64Array,BigInt64Array,Array,Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,FileSystemDirectoryHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey"
185
185
  .split(',').concat(flatten([8, 16, 32, 64].map(num => ["Int", "Uint", "Float"].map(t => t + num + "Array")))).filter(t => _global[t]);
186
186
  const intrinsicTypes = intrinsicTypeNames.map(t => _global[t]);
187
187
  arrayToObject(intrinsicTypeNames, x => [x, true]);
@@ -1242,7 +1242,7 @@ function tempTransaction(db, mode, storeNames, fn) {
1242
1242
  }
1243
1243
  }
1244
1244
 
1245
- const DEXIE_VERSION = '3.2.4';
1245
+ const DEXIE_VERSION = '3.2.5';
1246
1246
  const maxString = String.fromCharCode(65535);
1247
1247
  const minKey = -Infinity;
1248
1248
  const INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
@@ -1324,13 +1324,23 @@ class Table {
1324
1324
  return this
1325
1325
  .where(keyPaths[0])
1326
1326
  .equals(indexOrCrit[keyPaths[0]]);
1327
- const compoundIndex = this.schema.indexes.concat(this.schema.primKey).filter(ix => ix.compound &&
1328
- keyPaths.every(keyPath => ix.keyPath.indexOf(keyPath) >= 0) &&
1329
- ix.keyPath.every(keyPath => keyPaths.indexOf(keyPath) >= 0))[0];
1330
- if (compoundIndex && this.db._maxKey !== maxString)
1327
+ const compoundIndex = this.schema.indexes.concat(this.schema.primKey).filter(ix => {
1328
+ if (ix.compound &&
1329
+ keyPaths.every(keyPath => ix.keyPath.indexOf(keyPath) >= 0)) {
1330
+ for (let i = 0; i < keyPaths.length; ++i) {
1331
+ if (keyPaths.indexOf(ix.keyPath[i]) === -1)
1332
+ return false;
1333
+ }
1334
+ return true;
1335
+ }
1336
+ return false;
1337
+ }).sort((a, b) => a.keyPath.length - b.keyPath.length)[0];
1338
+ if (compoundIndex && this.db._maxKey !== maxString) {
1339
+ const keyPathsInValidOrder = compoundIndex.keyPath.slice(0, keyPaths.length);
1331
1340
  return this
1332
- .where(compoundIndex.name)
1333
- .equals(compoundIndex.keyPath.map(kp => indexOrCrit[kp]));
1341
+ .where(keyPathsInValidOrder)
1342
+ .equals(keyPathsInValidOrder.map(kp => indexOrCrit[kp]));
1343
+ }
1334
1344
  if (!compoundIndex && debug)
1335
1345
  console.warn(`The query ${JSON.stringify(indexOrCrit)} on ${this.name} would benefit of a ` +
1336
1346
  `compound index [${keyPaths.join('+')}]`);
@@ -3613,69 +3623,82 @@ function dexieOpen(db) {
3613
3623
  }
3614
3624
  let resolveDbReady = state.dbReadyResolve,
3615
3625
  upgradeTransaction = null, wasCreated = false;
3616
- return DexiePromise.race([openCanceller, (typeof navigator === 'undefined' ? DexiePromise.resolve() : idbReady()).then(() => new DexiePromise((resolve, reject) => {
3617
- throwIfCancelled();
3618
- if (!indexedDB)
3619
- throw new exceptions.MissingAPI();
3620
- const dbName = db.name;
3621
- const req = state.autoSchema ?
3622
- indexedDB.open(dbName) :
3623
- indexedDB.open(dbName, Math.round(db.verno * 10));
3624
- if (!req)
3625
- throw new exceptions.MissingAPI();
3626
- req.onerror = eventRejectHandler(reject);
3627
- req.onblocked = wrap(db._fireOnBlocked);
3628
- req.onupgradeneeded = wrap(e => {
3629
- upgradeTransaction = req.transaction;
3630
- if (state.autoSchema && !db._options.allowEmptyDB) {
3631
- req.onerror = preventDefault;
3632
- upgradeTransaction.abort();
3633
- req.result.close();
3634
- const delreq = indexedDB.deleteDatabase(dbName);
3635
- delreq.onsuccess = delreq.onerror = wrap(() => {
3636
- reject(new exceptions.NoSuchDatabase(`Database ${dbName} doesnt exist`));
3637
- });
3638
- }
3639
- else {
3640
- upgradeTransaction.onerror = eventRejectHandler(reject);
3641
- var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
3642
- wasCreated = oldVer < 1;
3643
- db._novip.idbdb = req.result;
3644
- runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
3645
- }
3646
- }, reject);
3647
- req.onsuccess = wrap(() => {
3648
- upgradeTransaction = null;
3649
- const idbdb = db._novip.idbdb = req.result;
3650
- const objectStoreNames = slice(idbdb.objectStoreNames);
3651
- if (objectStoreNames.length > 0)
3652
- try {
3653
- const tmpTrans = idbdb.transaction(safariMultiStoreFix(objectStoreNames), 'readonly');
3654
- if (state.autoSchema)
3655
- readGlobalSchema(db, idbdb, tmpTrans);
3656
- else {
3657
- adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
3658
- if (!verifyInstalledSchema(db, tmpTrans)) {
3659
- console.warn(`Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Some queries may fail.`);
3660
- }
3626
+ const tryOpenDB = () => new DexiePromise((resolve, reject) => {
3627
+ throwIfCancelled();
3628
+ if (!indexedDB)
3629
+ throw new exceptions.MissingAPI();
3630
+ const dbName = db.name;
3631
+ const req = state.autoSchema ?
3632
+ indexedDB.open(dbName) :
3633
+ indexedDB.open(dbName, Math.round(db.verno * 10));
3634
+ if (!req)
3635
+ throw new exceptions.MissingAPI();
3636
+ req.onerror = eventRejectHandler(reject);
3637
+ req.onblocked = wrap(db._fireOnBlocked);
3638
+ req.onupgradeneeded = wrap(e => {
3639
+ upgradeTransaction = req.transaction;
3640
+ if (state.autoSchema && !db._options.allowEmptyDB) {
3641
+ req.onerror = preventDefault;
3642
+ upgradeTransaction.abort();
3643
+ req.result.close();
3644
+ const delreq = indexedDB.deleteDatabase(dbName);
3645
+ delreq.onsuccess = delreq.onerror = wrap(() => {
3646
+ reject(new exceptions.NoSuchDatabase(`Database ${dbName} doesnt exist`));
3647
+ });
3648
+ }
3649
+ else {
3650
+ upgradeTransaction.onerror = eventRejectHandler(reject);
3651
+ var oldVer = e.oldVersion > Math.pow(2, 62) ? 0 : e.oldVersion;
3652
+ wasCreated = oldVer < 1;
3653
+ db._novip.idbdb = req.result;
3654
+ runUpgraders(db, oldVer / 10, upgradeTransaction, reject);
3655
+ }
3656
+ }, reject);
3657
+ req.onsuccess = wrap(() => {
3658
+ upgradeTransaction = null;
3659
+ const idbdb = db._novip.idbdb = req.result;
3660
+ const objectStoreNames = slice(idbdb.objectStoreNames);
3661
+ if (objectStoreNames.length > 0)
3662
+ try {
3663
+ const tmpTrans = idbdb.transaction(safariMultiStoreFix(objectStoreNames), 'readonly');
3664
+ if (state.autoSchema)
3665
+ readGlobalSchema(db, idbdb, tmpTrans);
3666
+ else {
3667
+ adjustToExistingIndexNames(db, db._dbSchema, tmpTrans);
3668
+ if (!verifyInstalledSchema(db, tmpTrans)) {
3669
+ console.warn(`Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Some queries may fail.`);
3661
3670
  }
3662
- generateMiddlewareStacks(db, tmpTrans);
3663
3671
  }
3664
- catch (e) {
3665
- }
3666
- connections.push(db);
3667
- idbdb.onversionchange = wrap(ev => {
3668
- state.vcFired = true;
3669
- db.on("versionchange").fire(ev);
3670
- });
3671
- idbdb.onclose = wrap(ev => {
3672
- db.on("close").fire(ev);
3673
- });
3674
- if (wasCreated)
3675
- _onDatabaseCreated(db._deps, dbName);
3676
- resolve();
3677
- }, reject);
3678
- }))]).then(() => {
3672
+ generateMiddlewareStacks(db, tmpTrans);
3673
+ }
3674
+ catch (e) {
3675
+ }
3676
+ connections.push(db);
3677
+ idbdb.onversionchange = wrap(ev => {
3678
+ state.vcFired = true;
3679
+ db.on("versionchange").fire(ev);
3680
+ });
3681
+ idbdb.onclose = wrap(ev => {
3682
+ db.on("close").fire(ev);
3683
+ });
3684
+ if (wasCreated)
3685
+ _onDatabaseCreated(db._deps, dbName);
3686
+ resolve();
3687
+ }, reject);
3688
+ }).catch(err => {
3689
+ if (err && err.name === 'UnknownError' && state.PR1398_maxLoop > 0) {
3690
+ state.PR1398_maxLoop--;
3691
+ console.warn('Dexie: Workaround for Chrome UnknownError on open()');
3692
+ return tryOpenDB();
3693
+ }
3694
+ else {
3695
+ return DexiePromise.reject(err);
3696
+ }
3697
+ });
3698
+ return DexiePromise.race([
3699
+ openCanceller,
3700
+ (typeof navigator === 'undefined' ? DexiePromise.resolve() : idbReady()).then(tryOpenDB)
3701
+ ]).then(() => {
3679
3702
  throwIfCancelled();
3680
3703
  state.onReadyBeingFired = [];
3681
3704
  return DexiePromise.resolve(vip(() => db.on.ready.fire(db.vip))).then(function fireRemainders() {