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 (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,56 @@
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
+ // On a standard driver, `keepAliveAndWait` issues a SQL query, which
5617
+ // is a macrotask. Otherwise it issues ten microtasks.
5618
+ var keepAliveAttempts = isStandardDriver ? 1 : 10;
5619
+
5620
+ /**
5621
+ * A continuation that must still be able to observe the
5622
+ * transaction as safe to extend (e.g., re-checking whether an
5623
+ * `await`-based follow-up request has arrived yet, or giving a
5624
+ * same-tick microtask scheduled from a handler a chance to run
5625
+ * first) can normally just be deferred via `queueMicrotask`.
5626
+ * That alone isn't safe on a standard (3-argument) driver,
5627
+ * though: it finalizes its own underlying SQL transaction
5628
+ * synchronously, as soon as it sees no further `executeSql`
5629
+ * call already in flight or queued, and a microtask hop by
5630
+ * itself never issues one -- so the driver already considers
5631
+ * the transaction done by the time the deferred continuation
5632
+ * runs, silently dropping whatever it tries to do next. Issuing
5633
+ * a harmless `SELECT 1` instead keeps the driver's own queue
5634
+ * non-empty across that same gap, at the cost of a real SQL
5635
+ * round trip; Node's driver doesn't need this since its real
5636
+ * commit/rollback is already deferred separately, via
5637
+ * `nonstandardTransCb`.
5638
+ * @param {() => void} cb
5639
+ * @returns {void}
5640
+ */
5641
+ function keepAliveAndWait(cb) {
5642
+ if (!isStandardDriver) {
5643
+ queueMicrotask(cb);
5644
+ return;
5645
+ }
5646
+ try {
5647
+ tx.executeSql('SELECT 1', [], function () {
5648
+ cb();
5649
+ }, function () {
5650
+ cb();
5651
+ return false; // Don't roll back the transaction over a keep-alive no-op
5652
+ });
5653
+ } catch (err) {
5654
+ // The driver has already finalized the transaction (or otherwise
5655
+ // rejected the call) -- nothing left to hold open. We explicitly
5656
+ // abort the transaction here.
5657
+ me.__abortTransaction(/** @type {Error|DOMException} */err);
5658
+ }
5659
+ }
5660
+
5599
5661
  /**
5600
5662
  * @typedef {unknown} IDBRequestResult
5601
5663
  */
@@ -5789,9 +5851,9 @@
5789
5851
  * from a microtask -- so if the JS-level queue is merely found
5790
5852
  * empty here, that doesn't yet mean no more work is coming, only
5791
5853
  * 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.
5854
+ * number of further turns (see `keepAliveAndWait`, letting a typical
5855
+ * `await` chain like `await store.put(...); await store.get(...)`
5856
+ * catch up) before finally concluding the transaction is genuinely done.
5795
5857
  * Applies to `readonly` transactions too, not just `readwrite`/
5796
5858
  * `versionchange`: a `readonly` transaction's `complete` event
5797
5859
  * can otherwise fire synchronously, immediately after its last
@@ -5799,9 +5861,11 @@
5799
5861
  * consumer of that same handler (e.g. one that resolves a
5800
5862
  * promise from within `onsuccess` and only attaches `oncomplete`
5801
5863
  * afterward) ever gets a turn to run, so it can miss `complete`
5802
- * entirely. `readonly` requests don't hold a real SQL
5803
- * transaction open, though, so there's no file-lock/connection
5804
- * collision risk in waiting the same bounded amount here.
5864
+ * afterward) ever gets a turn to run, so it can miss `complete`
5865
+ * entirely. On a non-standard driver, `readonly` requests don't hold
5866
+ * a real SQL transaction open, so there's no file-lock/connection
5867
+ * collision risk. On a standard driver, the wait now issues real SQL
5868
+ * inside the read transaction, so this does carry a slight risk.
5805
5869
  * @param {number} attemptsLeft
5806
5870
  * @returns {void}
5807
5871
  */
@@ -5821,7 +5885,7 @@
5821
5885
  }
5822
5886
  return;
5823
5887
  }
5824
- queueMicrotask(function () {
5888
+ keepAliveAndWait(function () {
5825
5889
  checkQueueEntry(attemptsLeft - 1);
5826
5890
  });
5827
5891
  }
@@ -5836,7 +5900,7 @@
5836
5900
  }
5837
5901
  i++;
5838
5902
  if (i >= me.__requests.length) {
5839
- checkQueueEntry(10);
5903
+ checkQueueEntry(keepAliveAttempts);
5840
5904
  return;
5841
5905
  }
5842
5906
  runQueuedRequest();
@@ -5873,10 +5937,10 @@
5873
5937
  }
5874
5938
  i++;
5875
5939
  if (i >= me.__requests.length) {
5876
- checkQueueEntry(10);
5940
+ checkQueueEntry(keepAliveAttempts);
5877
5941
  return;
5878
5942
  }
5879
- queueMicrotask(function () {
5943
+ keepAliveAndWait(function () {
5880
5944
  if (me.__errored || me.__requestsFinished) {
5881
5945
  return;
5882
5946
  }
@@ -13879,10 +13943,11 @@
13879
13943
  setNonIDBGlobals();
13880
13944
  }
13881
13945
  }
13882
- /* istanbul ignore next -- TS guard */
13946
+ /* c8 ignore start -- TS guard */
13883
13947
  if (!IDB.shimIndexedDB) {
13884
13948
  return;
13885
13949
  }
13950
+ /* c8 ignore stop -- TS guard */
13886
13951
  IDB.shimIndexedDB.__setConnectionQueueOrigin();
13887
13952
  }
13888
13953
  };