indexeddbshim 19.0.3 → 19.0.4

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.
Files changed (35) hide show
  1. package/README.md +1 -6
  2. package/badges/coverage-badge.svg +1 -1
  3. package/badges/tests-badge.svg +1 -1
  4. package/dist/IDBTransaction.d.ts +15 -0
  5. package/dist/IDBTransaction.d.ts.map +1 -1
  6. package/dist/indexeddbshim-Key.js +2 -2
  7. package/dist/indexeddbshim-Key.js.map +1 -1
  8. package/dist/indexeddbshim-Key.min.js +1 -1
  9. package/dist/indexeddbshim-Key.min.js.map +1 -1
  10. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs +80 -20
  11. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
  12. package/dist/indexeddbshim-UnicodeIdentifiers.js +78 -19
  13. package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
  14. package/dist/indexeddbshim-UnicodeIdentifiers.min.js +3 -3
  15. package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
  16. package/dist/indexeddbshim-node.cjs +78 -19
  17. package/dist/indexeddbshim-node.cjs.map +1 -1
  18. package/dist/indexeddbshim-noninvasive.js +78 -19
  19. package/dist/indexeddbshim-noninvasive.js.map +1 -1
  20. package/dist/indexeddbshim-noninvasive.min.js +2 -2
  21. package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
  22. package/dist/indexeddbshim.js +78 -19
  23. package/dist/indexeddbshim.js.map +1 -1
  24. package/dist/indexeddbshim.min.js +2 -2
  25. package/dist/indexeddbshim.min.js.map +1 -1
  26. package/dist/node-UnicodeIdentifiers.d.ts.map +1 -1
  27. package/dist/setGlobalVars.d.ts.map +1 -1
  28. package/dist/util.d.ts +0 -6
  29. package/dist/util.d.ts.map +1 -1
  30. package/package.json +22 -18
  31. package/src/CFG.js +1 -1
  32. package/src/IDBTransaction.js +76 -18
  33. package/src/node-UnicodeIdentifiers.js +2 -1
  34. package/src/setGlobalVars.js +2 -1
  35. package/src/util.js +1 -11
@@ -1,4 +1,4 @@
1
- /*! indexeddbshim - v19.0.3 - 9/15/2026 */
1
+ /*! indexeddbshim - v19.0.4 - 9/17/2026 */
2
2
 
3
3
  (function (factory) {
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -1806,7 +1806,7 @@
1806
1806
  'UnicodeIDStart',
1807
1807
  // In the non-Unicode builds, defaults to /[$0-9A-Z_a-z]/
1808
1808
  'UnicodeIDContinue',
1809
- // Used by SCA.js for optional restructuring of typeson-registry
1809
+ // Used by Sca.js for optional restructuring of typeson-registry
1810
1810
  // Structured Cloning Algorithm; should only be needed for ensuring data
1811
1811
  // created in 3.* versions of IndexedDBShim continue to work; see the
1812
1812
  // library `typeson-registry-sca-reverter` to get a function to do this
@@ -5370,6 +5370,7 @@
5370
5370
  * __requestsFinished: boolean,
5371
5371
  * __transFinishedCb: (err: boolean, cb: ((bool?: boolean) => void)) => void,
5372
5372
  * __callTransFinishedCb: (err: boolean, cb: ((bool?: boolean) => void)) => void,
5373
+ * __usesStandardDriver: () => boolean,
5373
5374
  * __transactionEndCallback: (() => void)|undefined,
5374
5375
  * __transactionFinished: boolean,
5375
5376
  * __completed: boolean,
@@ -5509,6 +5510,27 @@
5509
5510
  cb(Boolean(err));
5510
5511
  };
5511
5512
 
5513
+ /**
5514
+ * A standard (3-argument) `transaction()`/`readTransaction()` implementation
5515
+ * (browser WebSQL, `cordova-plugin-sqlite-2`, etc.) never invokes the
5516
+ * non-standard 4th callback that installs the real `__transFinishedCb`,
5517
+ * and finalizes its own underlying SQL transaction synchronously, as soon
5518
+ * as it sees no further `executeSql` call already in flight or queued --
5519
+ * with no way for it to know a JS-level continuation (e.g. an
5520
+ * `await`-deferred follow-up request) is still coming. Detected via
5521
+ * arity, checking whichever of the two methods this transaction's own
5522
+ * mode actually uses.
5523
+ * @this {IDBTransactionFull}
5524
+ * @returns {boolean}
5525
+ */
5526
+ IDBTransaction.prototype.__usesStandardDriver = function () {
5527
+ var me = this;
5528
+ var dbConn = me.db && me.db.__db;
5529
+ var dbMethodName = me.mode === 'readonly' ? 'readTransaction' : 'transaction';
5530
+ var supportsNonstandardTransCb = Boolean(dbConn && typeof dbConn[dbMethodName] === 'function' && dbConn[dbMethodName].length >= 4);
5531
+ return !supportsNonstandardTransCb;
5532
+ };
5533
+
5512
5534
  /**
5513
5535
  * In Node, the real (SQL-commit-capable) `__transFinishedCb` is only
5514
5536
  * installed once the underlying WebSQL driver's own SQL-queue-idle check
@@ -5543,17 +5565,11 @@
5543
5565
  return;
5544
5566
  }
5545
5567
  if (me.__transFinishedCb === IDBTransaction.prototype.__transFinishedCb) {
5546
- // Standard (3-argument) `transaction()`/`readTransaction()` implementations
5547
- // (browser WebSQL, `cordova-plugin-sqlite-2`, etc.) never invoke the
5548
- // non-standard 4th callback that installs the real `__transFinishedCb`,
5549
- // so waiting for it here would defer forever. Detect that via arity
5550
- // (checking whichever of the two methods this transaction's own mode
5551
- // actually uses -- see `__executeRequests`) and, if it's not supported,
5552
- // just call the default (the driver auto-commits on its own).
5553
- var dbConn = me.db && me.db.__db;
5554
- var dbMethodName = me.mode === 'readonly' ? 'readTransaction' : 'transaction';
5555
- var supportsNonstandardTransCb = Boolean(dbConn && typeof dbConn[dbMethodName] === 'function' && dbConn[dbMethodName].length >= 4);
5556
- if (!supportsNonstandardTransCb) {
5568
+ // Waiting here for the non-standard 4th callback to install the real
5569
+ // `__transFinishedCb` would defer forever on a standard driver, which
5570
+ // never invokes it -- call the default instead (the driver auto-commits
5571
+ // on its own).
5572
+ if (me.__usesStandardDriver()) {
5557
5573
  me.__transFinishedCbFired = true;
5558
5574
  me.__transFinishedCb(err, cb);
5559
5575
  return;
@@ -5592,10 +5608,52 @@
5592
5608
  // `readTransaction` is optimized, at least in `node-websql`
5593
5609
  function executeRequests(tx) {
5594
5610
  me.__tx = tx;
5611
+ var isStandardDriver = me.__usesStandardDriver();
5595
5612
  /** @type {RequestInfo} */
5596
5613
  var q,
5597
5614
  i = -1;
5598
5615
 
5616
+ /**
5617
+ * A continuation that must still be able to observe the
5618
+ * transaction as safe to extend (e.g., re-checking whether an
5619
+ * `await`-based follow-up request has arrived yet, or giving a
5620
+ * same-tick microtask scheduled from a handler a chance to run
5621
+ * first) can normally just be deferred via `queueMicrotask`.
5622
+ * That alone isn't safe on a standard (3-argument) driver,
5623
+ * though: it finalizes its own underlying SQL transaction
5624
+ * synchronously, as soon as it sees no further `executeSql`
5625
+ * call already in flight or queued, and a microtask hop by
5626
+ * itself never issues one -- so the driver already considers
5627
+ * the transaction done by the time the deferred continuation
5628
+ * runs, silently dropping whatever it tries to do next. Issuing
5629
+ * a harmless `SELECT 1` instead keeps the driver's own queue
5630
+ * non-empty across that same gap, at the cost of a real SQL
5631
+ * round trip; Node's driver doesn't need this since its real
5632
+ * commit/rollback is already deferred separately, via
5633
+ * `nonstandardTransCb`.
5634
+ * @param {() => void} cb
5635
+ * @returns {void}
5636
+ */
5637
+ function keepAliveAndWait(cb) {
5638
+ if (!isStandardDriver) {
5639
+ queueMicrotask(cb);
5640
+ return;
5641
+ }
5642
+ try {
5643
+ tx.executeSql('SELECT 1', [], function () {
5644
+ cb();
5645
+ }, function () {
5646
+ cb();
5647
+ return false; // Don't roll back the transaction over a keep-alive no-op
5648
+ });
5649
+ } catch (err) {
5650
+ // The driver has already finalized the transaction (or otherwise
5651
+ // rejected the call) -- nothing left to hold open, so fall back
5652
+ // to a plain microtask hop for the continuation itself.
5653
+ queueMicrotask(cb);
5654
+ }
5655
+ }
5656
+
5599
5657
  /**
5600
5658
  * @typedef {unknown} IDBRequestResult
5601
5659
  */
@@ -5789,9 +5847,9 @@
5789
5847
  * from a microtask -- so if the JS-level queue is merely found
5790
5848
  * empty here, that doesn't yet mean no more work is coming, only
5791
5849
  * that none has been queued *yet*. Re-check across a small, bounded
5792
- * number of further microtask turns (letting a typical `await`
5793
- * chain like `await store.put(...); await store.get(...)` catch
5794
- * up) before finally concluding the transaction is genuinely done.
5850
+ * number of further turns (see `keepAliveAndWait`, letting a typical
5851
+ * `await` chain like `await store.put(...); await store.get(...)`
5852
+ * catch up) before finally concluding the transaction is genuinely done.
5795
5853
  * Applies to `readonly` transactions too, not just `readwrite`/
5796
5854
  * `versionchange`: a `readonly` transaction's `complete` event
5797
5855
  * can otherwise fire synchronously, immediately after its last
@@ -5821,7 +5879,7 @@
5821
5879
  }
5822
5880
  return;
5823
5881
  }
5824
- queueMicrotask(function () {
5882
+ keepAliveAndWait(function () {
5825
5883
  checkQueueEntry(attemptsLeft - 1);
5826
5884
  });
5827
5885
  }
@@ -5876,7 +5934,7 @@
5876
5934
  checkQueueEntry(10);
5877
5935
  return;
5878
5936
  }
5879
- queueMicrotask(function () {
5937
+ keepAliveAndWait(function () {
5880
5938
  if (me.__errored || me.__requestsFinished) {
5881
5939
  return;
5882
5940
  }
@@ -13879,10 +13937,11 @@
13879
13937
  setNonIDBGlobals();
13880
13938
  }
13881
13939
  }
13882
- /* istanbul ignore next -- TS guard */
13940
+ /* c8 ignore start -- TS guard */
13883
13941
  if (!IDB.shimIndexedDB) {
13884
13942
  return;
13885
13943
  }
13944
+ /* c8 ignore stop -- TS guard */
13886
13945
  IDB.shimIndexedDB.__setConnectionQueueOrigin();
13887
13946
  }
13888
13947
  };