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
  'use strict';
4
4
 
@@ -4515,6 +4515,17 @@ IDBTransaction.prototype.__transFinishedCb = function (err, cb) {
4515
4515
  IDBTransaction.prototype.__callTransFinishedCb = function (err, cb) {
4516
4516
  const me = this;
4517
4517
  if (me.__transFinishedCb === IDBTransaction.prototype.__transFinishedCb) {
4518
+ // Standard (3-argument) `transaction()` implementations (browser WebSQL,
4519
+ // `cordova-plugin-sqlite-2`, etc.) never invoke the non-standard 4th
4520
+ // callback that installs the real `__transFinishedCb`, so waiting for
4521
+ // it here would defer forever. Detect that via arity and, if it's not
4522
+ // supported, just call the default (the driver auto-commits on its own).
4523
+ const dbConn = me.db && me.db.__db;
4524
+ const supportsNonstandardTransCb = Boolean(dbConn && typeof dbConn.transaction === 'function' && dbConn.transaction.length >= 4);
4525
+ if (!supportsNonstandardTransCb) {
4526
+ me.__transFinishedCb(err, cb);
4527
+ return;
4528
+ }
4518
4529
  setTimeout(() => {
4519
4530
  me.__callTransFinishedCb(err, cb);
4520
4531
  }, 0);
@@ -8878,6 +8889,56 @@ function getLatestCachedWebSQLDB(name) {
8878
8889
  return websqlDBCache[name] && websqlDBCache[name][getLatestCachedWebSQLVersion(name)];
8879
8890
  }
8880
8891
 
8892
+ /**
8893
+ * A cached WebSQL connection (e.g., from a prior `open()`) can keep the
8894
+ * underlying SQLite file handle open even after `IDBDatabase#close()`
8895
+ * (which only flags the connection for closing without releasing the
8896
+ * handle, to allow instance reuse). On Windows, deleting a file while a
8897
+ * handle to it is still open fails with `EBUSY`, so any cached connections
8898
+ * for `name` must be actually closed (and evicted, since they're no longer
8899
+ * usable) before attempting to remove the file.
8900
+ * @param {string} name
8901
+ * @param {() => void} cb
8902
+ * @returns {void}
8903
+ */
8904
+ function closeCachedWebSQLConnections(name, cb) {
8905
+ if (!Object.hasOwn(websqlDBCache, name)) {
8906
+ cb();
8907
+ return;
8908
+ }
8909
+ const dbs = Object.values(websqlDBCache[name]);
8910
+ delete websqlDBCache[name];
8911
+ let remaining = dbs.length;
8912
+ if (remaining === 0) {
8913
+ cb();
8914
+ return;
8915
+ }
8916
+ dbs.forEach(db => {
8917
+ const sqliteDB = db._db && db._db._db;
8918
+ if (!sqliteDB || !sqliteDB.close) {
8919
+ remaining--;
8920
+ if (remaining === 0) {
8921
+ cb();
8922
+ }
8923
+ return;
8924
+ }
8925
+ sqliteDB.close(
8926
+ /**
8927
+ * @param {Error} err
8928
+ * @returns {void}
8929
+ */
8930
+ err => {
8931
+ if (err) {
8932
+ console.warn('Error closing database connection prior to file removal: ' + err);
8933
+ }
8934
+ remaining--;
8935
+ if (remaining === 0) {
8936
+ cb();
8937
+ }
8938
+ });
8939
+ });
8940
+ }
8941
+
8881
8942
  /**
8882
8943
  * @param {OpenDatabase} __openDatabase
8883
8944
  * @param {string} name
@@ -8915,16 +8976,18 @@ function cleanupDatabaseResources(__openDatabase, name, escapedDatabaseName, dat
8915
8976
  return;
8916
8977
  }
8917
8978
  if (fs && CFG.deleteDatabaseFiles !== false) {
8918
- fs.unlink(path.join(CFG.databaseBasePath || '', escapedDatabaseName), err => {
8919
- if (err && err.code !== 'ENOENT') {
8920
- // Ignore if file is already deleted
8921
- dbError({
8922
- code: 0,
8923
- message: 'Error removing database file: ' + escapedDatabaseName + ' ' + err
8924
- });
8925
- return;
8926
- }
8927
- databaseDeleted();
8979
+ closeCachedWebSQLConnections(name, () => {
8980
+ fs.unlink(path.join(CFG.databaseBasePath || '', escapedDatabaseName), err => {
8981
+ if (err && err.code !== 'ENOENT') {
8982
+ // Ignore if file is already deleted
8983
+ dbError({
8984
+ code: 0,
8985
+ message: 'Error removing database file: ' + escapedDatabaseName + ' ' + err
8986
+ });
8987
+ return;
8988
+ }
8989
+ databaseDeleted();
8990
+ });
8928
8991
  });
8929
8992
  return;
8930
8993
  }
@@ -9453,9 +9516,17 @@ IDBFactory.prototype.deleteDatabase = function (name) {
9453
9516
  * @returns {boolean}
9454
9517
  */
9455
9518
  function dbError(tx, err) {
9456
- if (calledDBError || err === true) {
9519
+ if (calledDBError) {
9457
9520
  return false;
9458
9521
  }
9522
+ // Must be set synchronously (not inside the `sysdbFinishedCbDelete` callback below) to
9523
+ // guard against reentrancy: `sysdbFinishedCbDelete` -> `rollback`/`commit` -> websql-configurable's
9524
+ // `done()` -> `currentTask.errorCallback(er)`, which is this very `dbError`, calling back into
9525
+ // us before the first invocation has finished. Without this, a second rollback/commit gets
9526
+ // issued on the shared `sysdb` connection after it has already moved on to the next queued
9527
+ // transaction, corrupting that connection's task queue (see issue with unrelated `open()` calls
9528
+ // failing/crashing after a `deleteDatabase` file-removal error).
9529
+ calledDBError = true;
9459
9530
  const er = webSQLErrback(/** @type {SQLError} */err || tx);
9460
9531
  sysdbFinishedCbDelete(true, function () {
9461
9532
  req.__done = true;
@@ -9467,7 +9538,6 @@ IDBFactory.prototype.deleteDatabase = function (name) {
9467
9538
  cancelable: true
9468
9539
  });
9469
9540
  req.dispatchEvent(e);
9470
- calledDBError = true;
9471
9541
  });
9472
9542
  return false;
9473
9543
  }