indexeddbshim 17.2.0 → 17.2.2

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.
@@ -1,4 +1,4 @@
1
- /*! indexeddbshim - v17.2.0 - 8/18/2026 */
1
+ /*! indexeddbshim - v17.2.2 - 8/18/2026 */
2
2
 
3
3
  (function (factory) {
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -4930,6 +4930,17 @@
4930
4930
  IDBTransaction.prototype.__callTransFinishedCb = function (err, cb) {
4931
4931
  var me = this;
4932
4932
  if (me.__transFinishedCb === IDBTransaction.prototype.__transFinishedCb) {
4933
+ // Standard (3-argument) `transaction()` implementations (browser WebSQL,
4934
+ // `cordova-plugin-sqlite-2`, etc.) never invoke the non-standard 4th
4935
+ // callback that installs the real `__transFinishedCb`, so waiting for
4936
+ // it here would defer forever. Detect that via arity and, if it's not
4937
+ // supported, just call the default (the driver auto-commits on its own).
4938
+ var dbConn = me.db && me.db.__db;
4939
+ var supportsNonstandardTransCb = Boolean(dbConn && typeof dbConn.transaction === 'function' && dbConn.transaction.length >= 4);
4940
+ if (!supportsNonstandardTransCb) {
4941
+ me.__transFinishedCb(err, cb);
4942
+ return;
4943
+ }
4933
4944
  setTimeout(function () {
4934
4945
  me.__callTransFinishedCb(err, cb);
4935
4946
  }, 0);
@@ -9871,6 +9882,56 @@
9871
9882
  return websqlDBCache[name] && websqlDBCache[name][getLatestCachedWebSQLVersion(name)];
9872
9883
  }
9873
9884
 
9885
+ /**
9886
+ * A cached WebSQL connection (e.g., from a prior `open()`) can keep the
9887
+ * underlying SQLite file handle open even after `IDBDatabase#close()`
9888
+ * (which only flags the connection for closing without releasing the
9889
+ * handle, to allow instance reuse). On Windows, deleting a file while a
9890
+ * handle to it is still open fails with `EBUSY`, so any cached connections
9891
+ * for `name` must be actually closed (and evicted, since they're no longer
9892
+ * usable) before attempting to remove the file.
9893
+ * @param {string} name
9894
+ * @param {() => void} cb
9895
+ * @returns {void}
9896
+ */
9897
+ function closeCachedWebSQLConnections(name, cb) {
9898
+ if (!Object.hasOwn(websqlDBCache, name)) {
9899
+ cb();
9900
+ return;
9901
+ }
9902
+ var dbs = Object.values(websqlDBCache[name]);
9903
+ delete websqlDBCache[name];
9904
+ var remaining = dbs.length;
9905
+ if (remaining === 0) {
9906
+ cb();
9907
+ return;
9908
+ }
9909
+ dbs.forEach(function (db) {
9910
+ var sqliteDB = db._db && db._db._db;
9911
+ if (!sqliteDB || !sqliteDB.close) {
9912
+ remaining--;
9913
+ if (remaining === 0) {
9914
+ cb();
9915
+ }
9916
+ return;
9917
+ }
9918
+ sqliteDB.close(
9919
+ /**
9920
+ * @param {Error} err
9921
+ * @returns {void}
9922
+ */
9923
+ function (err) {
9924
+ if (err) {
9925
+ console.warn('Error closing database connection prior to file removal: ' + err);
9926
+ }
9927
+ remaining--;
9928
+ if (remaining === 0) {
9929
+ cb();
9930
+ }
9931
+ });
9932
+ });
9933
+ }
9934
+
9874
9935
  /**
9875
9936
  * @param {OpenDatabase} __openDatabase
9876
9937
  * @param {string} name
@@ -9908,16 +9969,18 @@
9908
9969
  return;
9909
9970
  }
9910
9971
  if (fs && CFG.deleteDatabaseFiles !== false) {
9911
- fs.unlink(path.join(CFG.databaseBasePath || '', escapedDatabaseName), function (err) {
9912
- if (err && err.code !== 'ENOENT') {
9913
- // Ignore if file is already deleted
9914
- dbError({
9915
- code: 0,
9916
- message: 'Error removing database file: ' + escapedDatabaseName + ' ' + err
9917
- });
9918
- return;
9919
- }
9920
- databaseDeleted();
9972
+ closeCachedWebSQLConnections(name, function () {
9973
+ fs.unlink(path.join(CFG.databaseBasePath || '', escapedDatabaseName), function (err) {
9974
+ if (err && err.code !== 'ENOENT') {
9975
+ // Ignore if file is already deleted
9976
+ dbError({
9977
+ code: 0,
9978
+ message: 'Error removing database file: ' + escapedDatabaseName + ' ' + err
9979
+ });
9980
+ return;
9981
+ }
9982
+ databaseDeleted();
9983
+ });
9921
9984
  });
9922
9985
  return;
9923
9986
  }
@@ -10446,9 +10509,17 @@
10446
10509
  * @returns {boolean}
10447
10510
  */
10448
10511
  function dbError(tx, err) {
10449
- if (calledDBError || err === true) {
10512
+ if (calledDBError) {
10450
10513
  return false;
10451
10514
  }
10515
+ // Must be set synchronously (not inside the `sysdbFinishedCbDelete` callback below) to
10516
+ // guard against reentrancy: `sysdbFinishedCbDelete` -> `rollback`/`commit` -> websql-configurable's
10517
+ // `done()` -> `currentTask.errorCallback(er)`, which is this very `dbError`, calling back into
10518
+ // us before the first invocation has finished. Without this, a second rollback/commit gets
10519
+ // issued on the shared `sysdb` connection after it has already moved on to the next queued
10520
+ // transaction, corrupting that connection's task queue (see issue with unrelated `open()` calls
10521
+ // failing/crashing after a `deleteDatabase` file-removal error).
10522
+ calledDBError = true;
10452
10523
  var er = webSQLErrback(/** @type {SQLError} */err || tx);
10453
10524
  sysdbFinishedCbDelete(true, function () {
10454
10525
  req.__done = true;
@@ -10460,7 +10531,6 @@
10460
10531
  cancelable: true
10461
10532
  });
10462
10533
  req.dispatchEvent(e);
10463
- calledDBError = true;
10464
10534
  });
10465
10535
  return false;
10466
10536
  }