indexeddbshim 19.0.3 → 19.0.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.
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 +91 -25
  11. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
  12. package/dist/indexeddbshim-UnicodeIdentifiers.js +89 -24
  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 +89 -24
  17. package/dist/indexeddbshim-node.cjs.map +1 -1
  18. package/dist/indexeddbshim-noninvasive.js +89 -24
  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 +89 -24
  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 +87 -23
  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.5 - 9/17/2026 */
2
2
 
3
3
  (function (global, factory) {
4
4
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -1814,7 +1814,7 @@
1814
1814
  'UnicodeIDStart',
1815
1815
  // In the non-Unicode builds, defaults to /[$0-9A-Z_a-z]/
1816
1816
  'UnicodeIDContinue',
1817
- // Used by SCA.js for optional restructuring of typeson-registry
1817
+ // Used by Sca.js for optional restructuring of typeson-registry
1818
1818
  // Structured Cloning Algorithm; should only be needed for ensuring data
1819
1819
  // created in 3.* versions of IndexedDBShim continue to work; see the
1820
1820
  // library `typeson-registry-sca-reverter` to get a function to do this
@@ -5378,6 +5378,7 @@
5378
5378
  * __requestsFinished: boolean,
5379
5379
  * __transFinishedCb: (err: boolean, cb: ((bool?: boolean) => void)) => void,
5380
5380
  * __callTransFinishedCb: (err: boolean, cb: ((bool?: boolean) => void)) => void,
5381
+ * __usesStandardDriver: () => boolean,
5381
5382
  * __transactionEndCallback: (() => void)|undefined,
5382
5383
  * __transactionFinished: boolean,
5383
5384
  * __completed: boolean,
@@ -5517,6 +5518,27 @@
5517
5518
  cb(Boolean(err));
5518
5519
  };
5519
5520
 
5521
+ /**
5522
+ * A standard (3-argument) `transaction()`/`readTransaction()` implementation
5523
+ * (browser WebSQL, `cordova-plugin-sqlite-2`, etc.) never invokes the
5524
+ * non-standard 4th callback that installs the real `__transFinishedCb`,
5525
+ * and finalizes its own underlying SQL transaction synchronously, as soon
5526
+ * as it sees no further `executeSql` call already in flight or queued --
5527
+ * with no way for it to know a JS-level continuation (e.g. an
5528
+ * `await`-deferred follow-up request) is still coming. Detected via
5529
+ * arity, checking whichever of the two methods this transaction's own
5530
+ * mode actually uses.
5531
+ * @this {IDBTransactionFull}
5532
+ * @returns {boolean}
5533
+ */
5534
+ IDBTransaction.prototype.__usesStandardDriver = function () {
5535
+ var me = this;
5536
+ var dbConn = me.db && me.db.__db;
5537
+ var dbMethodName = me.mode === 'readonly' ? 'readTransaction' : 'transaction';
5538
+ var supportsNonstandardTransCb = Boolean(dbConn && typeof dbConn[dbMethodName] === 'function' && dbConn[dbMethodName].length >= 4);
5539
+ return !supportsNonstandardTransCb;
5540
+ };
5541
+
5520
5542
  /**
5521
5543
  * In Node, the real (SQL-commit-capable) `__transFinishedCb` is only
5522
5544
  * installed once the underlying WebSQL driver's own SQL-queue-idle check
@@ -5551,17 +5573,11 @@
5551
5573
  return;
5552
5574
  }
5553
5575
  if (me.__transFinishedCb === IDBTransaction.prototype.__transFinishedCb) {
5554
- // Standard (3-argument) `transaction()`/`readTransaction()` implementations
5555
- // (browser WebSQL, `cordova-plugin-sqlite-2`, etc.) never invoke the
5556
- // non-standard 4th callback that installs the real `__transFinishedCb`,
5557
- // so waiting for it here would defer forever. Detect that via arity
5558
- // (checking whichever of the two methods this transaction's own mode
5559
- // actually uses -- see `__executeRequests`) and, if it's not supported,
5560
- // just call the default (the driver auto-commits on its own).
5561
- var dbConn = me.db && me.db.__db;
5562
- var dbMethodName = me.mode === 'readonly' ? 'readTransaction' : 'transaction';
5563
- var supportsNonstandardTransCb = Boolean(dbConn && typeof dbConn[dbMethodName] === 'function' && dbConn[dbMethodName].length >= 4);
5564
- if (!supportsNonstandardTransCb) {
5576
+ // Waiting here for the non-standard 4th callback to install the real
5577
+ // `__transFinishedCb` would defer forever on a standard driver, which
5578
+ // never invokes it -- call the default instead (the driver auto-commits
5579
+ // on its own).
5580
+ if (me.__usesStandardDriver()) {
5565
5581
  me.__transFinishedCbFired = true;
5566
5582
  me.__transFinishedCb(err, cb);
5567
5583
  return;
@@ -5600,10 +5616,56 @@
5600
5616
  // `readTransaction` is optimized, at least in `node-websql`
5601
5617
  function executeRequests(tx) {
5602
5618
  me.__tx = tx;
5619
+ var isStandardDriver = me.__usesStandardDriver();
5603
5620
  /** @type {RequestInfo} */
5604
5621
  var q,
5605
5622
  i = -1;
5606
5623
 
5624
+ // On a standard driver, `keepAliveAndWait` issues a SQL query, which
5625
+ // is a macrotask. Otherwise it issues ten microtasks.
5626
+ var keepAliveAttempts = isStandardDriver ? 1 : 10;
5627
+
5628
+ /**
5629
+ * A continuation that must still be able to observe the
5630
+ * transaction as safe to extend (e.g., re-checking whether an
5631
+ * `await`-based follow-up request has arrived yet, or giving a
5632
+ * same-tick microtask scheduled from a handler a chance to run
5633
+ * first) can normally just be deferred via `queueMicrotask`.
5634
+ * That alone isn't safe on a standard (3-argument) driver,
5635
+ * though: it finalizes its own underlying SQL transaction
5636
+ * synchronously, as soon as it sees no further `executeSql`
5637
+ * call already in flight or queued, and a microtask hop by
5638
+ * itself never issues one -- so the driver already considers
5639
+ * the transaction done by the time the deferred continuation
5640
+ * runs, silently dropping whatever it tries to do next. Issuing
5641
+ * a harmless `SELECT 1` instead keeps the driver's own queue
5642
+ * non-empty across that same gap, at the cost of a real SQL
5643
+ * round trip; Node's driver doesn't need this since its real
5644
+ * commit/rollback is already deferred separately, via
5645
+ * `nonstandardTransCb`.
5646
+ * @param {() => void} cb
5647
+ * @returns {void}
5648
+ */
5649
+ function keepAliveAndWait(cb) {
5650
+ if (!isStandardDriver) {
5651
+ queueMicrotask(cb);
5652
+ return;
5653
+ }
5654
+ try {
5655
+ tx.executeSql('SELECT 1', [], function () {
5656
+ cb();
5657
+ }, function () {
5658
+ cb();
5659
+ return false; // Don't roll back the transaction over a keep-alive no-op
5660
+ });
5661
+ } catch (err) {
5662
+ // The driver has already finalized the transaction (or otherwise
5663
+ // rejected the call) -- nothing left to hold open. We explicitly
5664
+ // abort the transaction here.
5665
+ me.__abortTransaction(/** @type {Error|DOMException} */err);
5666
+ }
5667
+ }
5668
+
5607
5669
  /**
5608
5670
  * @typedef {unknown} IDBRequestResult
5609
5671
  */
@@ -5797,9 +5859,9 @@
5797
5859
  * from a microtask -- so if the JS-level queue is merely found
5798
5860
  * empty here, that doesn't yet mean no more work is coming, only
5799
5861
  * that none has been queued *yet*. Re-check across a small, bounded
5800
- * number of further microtask turns (letting a typical `await`
5801
- * chain like `await store.put(...); await store.get(...)` catch
5802
- * up) before finally concluding the transaction is genuinely done.
5862
+ * number of further turns (see `keepAliveAndWait`, letting a typical
5863
+ * `await` chain like `await store.put(...); await store.get(...)`
5864
+ * catch up) before finally concluding the transaction is genuinely done.
5803
5865
  * Applies to `readonly` transactions too, not just `readwrite`/
5804
5866
  * `versionchange`: a `readonly` transaction's `complete` event
5805
5867
  * can otherwise fire synchronously, immediately after its last
@@ -5807,9 +5869,11 @@
5807
5869
  * consumer of that same handler (e.g. one that resolves a
5808
5870
  * promise from within `onsuccess` and only attaches `oncomplete`
5809
5871
  * afterward) ever gets a turn to run, so it can miss `complete`
5810
- * entirely. `readonly` requests don't hold a real SQL
5811
- * transaction open, though, so there's no file-lock/connection
5812
- * collision risk in waiting the same bounded amount here.
5872
+ * afterward) ever gets a turn to run, so it can miss `complete`
5873
+ * entirely. On a non-standard driver, `readonly` requests don't hold
5874
+ * a real SQL transaction open, so there's no file-lock/connection
5875
+ * collision risk. On a standard driver, the wait now issues real SQL
5876
+ * inside the read transaction, so this does carry a slight risk.
5813
5877
  * @param {number} attemptsLeft
5814
5878
  * @returns {void}
5815
5879
  */
@@ -5829,7 +5893,7 @@
5829
5893
  }
5830
5894
  return;
5831
5895
  }
5832
- queueMicrotask(function () {
5896
+ keepAliveAndWait(function () {
5833
5897
  checkQueueEntry(attemptsLeft - 1);
5834
5898
  });
5835
5899
  }
@@ -5844,7 +5908,7 @@
5844
5908
  }
5845
5909
  i++;
5846
5910
  if (i >= me.__requests.length) {
5847
- checkQueueEntry(10);
5911
+ checkQueueEntry(keepAliveAttempts);
5848
5912
  return;
5849
5913
  }
5850
5914
  runQueuedRequest();
@@ -5881,10 +5945,10 @@
5881
5945
  }
5882
5946
  i++;
5883
5947
  if (i >= me.__requests.length) {
5884
- checkQueueEntry(10);
5948
+ checkQueueEntry(keepAliveAttempts);
5885
5949
  return;
5886
5950
  }
5887
- queueMicrotask(function () {
5951
+ keepAliveAndWait(function () {
5888
5952
  if (me.__errored || me.__requestsFinished) {
5889
5953
  return;
5890
5954
  }
@@ -13890,10 +13954,11 @@
13890
13954
  setNonIDBGlobals();
13891
13955
  }
13892
13956
  }
13893
- /* istanbul ignore next -- TS guard */
13957
+ /* c8 ignore start -- TS guard */
13894
13958
  if (!IDB.shimIndexedDB) {
13895
13959
  return;
13896
13960
  }
13961
+ /* c8 ignore stop -- TS guard */
13897
13962
  IDB.shimIndexedDB.__setConnectionQueueOrigin();
13898
13963
  }
13899
13964
  };