indexeddbshim 17.3.3 → 17.3.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.
@@ -1,4 +1,4 @@
1
- /*! indexeddbshim - v17.3.3 - 8/25/2026 */
1
+ /*! indexeddbshim - v17.3.4 - 8/25/2026 */
2
2
 
3
3
  (function (factory) {
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -3554,6 +3554,32 @@
3554
3554
  }
3555
3555
 
3556
3556
  var _templateObject, _templateObject2;
3557
+ /**
3558
+ * @param {unknown[]} arr
3559
+ * @param {number} index
3560
+ * @param {unknown} val
3561
+ * @returns {void}
3562
+ */
3563
+ var setArrayValue = function setArrayValue(arr, index, val) {
3564
+ if (Reflect.has(Array.prototype, index)) {
3565
+ Object.defineProperty(arr, index, {
3566
+ value: val,
3567
+ enumerable: true,
3568
+ writable: true,
3569
+ configurable: true
3570
+ });
3571
+ } else {
3572
+ arr[index] = val;
3573
+ }
3574
+ };
3575
+ /**
3576
+ * @param {unknown[]} arr
3577
+ * @param {unknown} val
3578
+ * @returns {void}
3579
+ */
3580
+ var safePush = function safePush(arr, val) {
3581
+ return setArrayValue(arr, arr.length, val);
3582
+ };
3557
3583
 
3558
3584
  /**
3559
3585
  * @typedef {NodeJS.TypedArray|DataView} ArrayBufferView
@@ -3817,6 +3843,7 @@
3817
3843
  * @returns {string}
3818
3844
  */
3819
3845
  encode: function encode(key) {
3846
+ /** @type {(string|null)[]} */
3820
3847
  var encoded = [];
3821
3848
  var _iterator = _createForOfIteratorHelper(key.entries()),
3822
3849
  _step;
@@ -3826,14 +3853,14 @@
3826
3853
  i = _step$value[0],
3827
3854
  item = _step$value[1];
3828
3855
  var encodedItem = _encode(item, true); // encode the array item
3829
- encoded[i] = encodedItem;
3856
+ setArrayValue(encoded, i, encodedItem);
3830
3857
  }
3831
3858
  } catch (err) {
3832
3859
  _iterator.e(err);
3833
3860
  } finally {
3834
3861
  _iterator.f();
3835
3862
  }
3836
- encoded.push(keyTypeToEncodedChar.invalid + '-'); // append an extra item, so empty arrays sort correctly
3863
+ safePush(encoded, keyTypeToEncodedChar.invalid + '-'); // append an extra item, so empty arrays sort correctly
3837
3864
  var encodedKey = JSON.stringify(encoded);
3838
3865
  if (CFG.escapeNULForSQLiteStatements === false) {
3839
3866
  encodedKey = encodedKey.replaceAll(String.raw(_templateObject || (_templateObject = _taggedTemplateLiteral(["\0"], ["\\u0000"]))), '\0');
@@ -3854,7 +3881,7 @@
3854
3881
  for (var i = 0; i < decoded.length; i++) {
3855
3882
  var item = decoded[i];
3856
3883
  var decodedItem = _decode(item, true); // decode the item
3857
- decoded[i] = decodedItem;
3884
+ setArrayValue(decoded, i, decodedItem);
3858
3885
  }
3859
3886
  return decoded;
3860
3887
  }
@@ -4152,7 +4179,7 @@
4152
4179
  // May throw (from binary)
4153
4180
  var arr = /** @type {Array<any>} */input;
4154
4181
  var len = arr.length;
4155
- seen.push(input);
4182
+ safePush(seen, input);
4156
4183
 
4157
4184
  /** @type {(KeyValueObject|Value)[]} */
4158
4185
  var keys = [];
@@ -4187,7 +4214,7 @@
4187
4214
  }) || fullKeys && keys.every(function (k) {
4188
4215
  return cmp(k, key) !== 0;
4189
4216
  })) {
4190
- keys.push(fullKeys ? key : key.value);
4217
+ safePush(keys, fullKeys ? key : key.value);
4191
4218
  }
4192
4219
  } catch (err) {
4193
4220
  if (!multiEntry) {
@@ -4347,7 +4374,7 @@
4347
4374
  if (key.failure) {
4348
4375
  return true;
4349
4376
  }
4350
- result.push(key.value);
4377
+ safePush(result, key.value);
4351
4378
  return false;
4352
4379
  }) ? {
4353
4380
  failure: true
@@ -4408,11 +4435,21 @@
4408
4435
  identifiers.forEach(function (identifier) {
4409
4436
  var hop = Object.hasOwn(value, identifier);
4410
4437
  if (!hop) {
4411
- value[identifier] = {};
4438
+ Object.defineProperty(value, identifier, {
4439
+ value: {},
4440
+ enumerable: true,
4441
+ writable: true,
4442
+ configurable: true
4443
+ });
4412
4444
  }
4413
4445
  value = value[identifier];
4414
4446
  });
4415
- value[(/** @type {string} */last)] = key; // key is already a `keyValue` in our processing so no need to convert
4447
+ Object.defineProperty(value, /** @type {string} */last, {
4448
+ value: key,
4449
+ enumerable: true,
4450
+ writable: true,
4451
+ configurable: true
4452
+ }); // key is already a `keyValue` in our processing so no need to convert
4416
4453
  }
4417
4454
 
4418
4455
  /**
@@ -4490,6 +4527,7 @@
4490
4527
  * @returns {Key[]}
4491
4528
  */
4492
4529
  function findMultiEntryMatches(keyEntry, range) {
4530
+ /** @type {unknown[]} */
4493
4531
  var matches = [];
4494
4532
  if (Array.isArray(keyEntry)) {
4495
4533
  var _iterator4 = _createForOfIteratorHelper(keyEntry),
@@ -4506,13 +4544,13 @@
4506
4544
  } else {
4507
4545
  var nested = findMultiEntryMatches(key, range);
4508
4546
  if (nested.length > 0) {
4509
- matches.push(key);
4547
+ safePush(matches, key);
4510
4548
  }
4511
4549
  continue;
4512
4550
  }
4513
4551
  }
4514
4552
  if (isNullish(range) || isKeyInRange(key, range, true)) {
4515
- matches.push(key);
4553
+ safePush(matches, key);
4516
4554
  }
4517
4555
  }
4518
4556
  } catch (err) {
@@ -4521,7 +4559,7 @@
4521
4559
  _iterator4.f();
4522
4560
  }
4523
4561
  } else if (isNullish(range) || isKeyInRange(keyEntry, range, true)) {
4524
- matches.push(keyEntry);
4562
+ safePush(matches, keyEntry);
4525
4563
  }
4526
4564
  return matches;
4527
4565
  }
@@ -4543,12 +4581,13 @@
4543
4581
  }
4544
4582
  case 'array':
4545
4583
  {
4584
+ /** @type {ValueType[]} */
4546
4585
  var array = [];
4547
4586
  var len = value.length;
4548
4587
  var index = 0;
4549
4588
  while (index < len) {
4550
4589
  var entry = convertKeyToValue(value[index]);
4551
- array[index] = entry;
4590
+ setArrayValue(array, index, entry);
4552
4591
  index++;
4553
4592
  }
4554
4593
  return array;
@@ -5308,6 +5347,7 @@
5308
5347
  }
5309
5348
 
5310
5349
  var uniqueID = 0;
5350
+ var activeTransactions = new Set();
5311
5351
  var listeners$1 = ['onabort', 'oncomplete', 'onerror'];
5312
5352
  var readonlyProperties$4 = ['objectStoreNames', 'mode', 'durability', 'db', 'error'];
5313
5353
 
@@ -5439,6 +5479,7 @@
5439
5479
  me.__mode = mode;
5440
5480
  me.__durability = durability;
5441
5481
  me.__db = db;
5482
+ activeTransactions.add(me);
5442
5483
  me.__error = null;
5443
5484
  // @ts-expect-error Part of `ShimEventTarget`
5444
5485
  me.__setOptions({
@@ -5951,6 +5992,7 @@
5951
5992
  me.__errored = true;
5952
5993
  throw e;
5953
5994
  } finally {
5995
+ activeTransactions.delete(me);
5954
5996
  me.__storeHandles = {};
5955
5997
  }
5956
5998
  }
@@ -6157,7 +6199,7 @@
6157
6199
  });
6158
6200
  }
6159
6201
  me.__active = false; // Setting here and in requestsFinished for https://github.com/w3c/IndexedDB/issues/87
6160
-
6202
+ activeTransactions.delete(me);
6161
6203
  if (err !== null) {
6162
6204
  me.__error = err;
6163
6205
  }
@@ -6378,7 +6420,7 @@
6378
6420
  * @returns {void}
6379
6421
  */
6380
6422
  IDBTransaction.__assertActive = function (tx) {
6381
- if (!tx || !tx.__active || tx.__committed) {
6423
+ if (!tx || !tx.__active || !tx.__handlerActive || tx.__committed) {
6382
6424
  throw createDOMException('TransactionInactiveError', 'A request was placed against a transaction which is currently not active, or which is finished');
6383
6425
  }
6384
6426
  };
@@ -6405,6 +6447,9 @@
6405
6447
  Object.defineProperty(IDBTransaction, 'prototype', {
6406
6448
  writable: false
6407
6449
  });
6450
+ /* eslint-enable unicorn/no-top-level-side-effects -- Would be good */
6451
+
6452
+ IDBTransaction.activeTransactions = activeTransactions;
6408
6453
 
6409
6454
  var TypesonPromise = /*#__PURE__*/_createClass(function TypesonPromise(e) {
6410
6455
  _classCallCheck(this, TypesonPromise);
@@ -7791,7 +7836,7 @@
7791
7836
  }
7792
7837
  }
7793
7838
  },
7794
- k = {
7839
+ D = {
7795
7840
  map: {
7796
7841
  test: function test(e) {
7797
7842
  return "Map" === toStringTag(e);
@@ -7804,7 +7849,7 @@
7804
7849
  }
7805
7850
  }
7806
7851
  },
7807
- D = {
7852
+ R = {
7808
7853
  nan: {
7809
7854
  test: function test(e) {
7810
7855
  return Number.isNaN(e);
@@ -8153,8 +8198,8 @@
8153
8198
  revive: function revive() {}
8154
8199
  }
8155
8200
  }],
8156
- ne = [D, M, L, F],
8157
- ce = [Z, Y, re, K, ne, O, z, U, _, B, I, h, N, C].concat("function" == typeof Map ? k : [], "function" == typeof Set ? H : [], "function" == typeof ArrayBuffer ? p : [], "function" == typeof Uint8Array ? X : [], "function" == typeof DataView ? w : [], "undefined" != typeof crypto ? v : [], "undefined" != typeof BigInt ? [m, d] : [], "undefined" != typeof DOMException ? A : [], "undefined" != typeof QuotaExceededError ? W : [], "undefined" != typeof WebTransportError ? te : [], "undefined" != typeof DOMRect ? x : [], "undefined" != typeof DOMPoint ? S : [], "undefined" != typeof DOMQuad ? P : [], "undefined" != typeof DOMMatrix ? T : [], "undefined" != typeof AudioData ? f : [], "undefined" != typeof EncodedAudioChunk ? E : [], "undefined" != typeof EncodedVideoChunk ? j : [], "undefined" != typeof VideoFrame ? ee : []);
8201
+ ne = [R, M, L, F],
8202
+ ce = [Z, Y, re, K, ne, O, z, U, _, B, I, h, N, C].concat("function" == typeof Map ? D : [], "function" == typeof Set ? H : [], "function" == typeof ArrayBuffer ? p : [], "function" == typeof Uint8Array ? X : [], "function" == typeof DataView ? w : [], "undefined" != typeof crypto ? v : [], "undefined" != typeof BigInt ? [m, d] : [], "undefined" != typeof DOMException ? A : [], "undefined" != typeof QuotaExceededError ? W : [], "undefined" != typeof WebTransportError ? te : [], "undefined" != typeof DOMRect ? x : [], "undefined" != typeof DOMPoint ? S : [], "undefined" != typeof DOMQuad ? P : [], "undefined" != typeof DOMMatrix ? T : [], "undefined" != typeof AudioData ? f : [], "undefined" != typeof EncodedAudioChunk ? E : [], "undefined" != typeof EncodedVideoChunk ? j : [], "undefined" != typeof VideoFrame ? ee : []);
8158
8203
  var ue = ce.concat({
8159
8204
  checkDataCloneException: {
8160
8205
  test: function test(e) {
@@ -8171,11 +8216,56 @@
8171
8216
  return false;
8172
8217
  }
8173
8218
  }
8219
+ }),
8220
+ ye = ue.concat({
8221
+ checkSharedArrayBufferException: {
8222
+ test: function test(e) {
8223
+ if ("SharedArrayBuffer" === {}.toString.call(e).slice(8, -1)) throw new DOMException("The object cannot be cloned.", "DataCloneError");
8224
+ return false;
8225
+ }
8226
+ }
8174
8227
  });
8175
8228
 
8176
8229
  // See: https://stackoverflow.com/questions/42170826/categories-for-rejection-by-the-structured-cloning-algorithm
8177
8230
 
8178
- var typeson = new Typeson().register(ue);
8231
+ // Although typeson-registry already has a FileList type in its structured cloning presets,
8232
+ // we need to override it so it works with our tests
8233
+
8234
+ var specSet = ye.flatMap(function (preset) {
8235
+ return Array.isArray(preset) ? preset : [preset];
8236
+ }).find(function (preset) {
8237
+ return preset && !Array.isArray(preset) && 'filelist' in preset;
8238
+ });
8239
+ var origFileList = specSet && !Array.isArray(specSet) && 'filelist' in specSet ? specSet.filelist : undefined;
8240
+ var origTest = origFileList && _typeof(origFileList) === 'object' && 'test' in origFileList && typeof origFileList.test === 'function' ? origFileList.test : undefined;
8241
+ var origRevive = origFileList && _typeof(origFileList) === 'object' && 'revive' in origFileList && typeof origFileList.revive === 'function' ? origFileList.revive : undefined;
8242
+ var customFileList = origFileList ? _objectSpread2(_objectSpread2({}, origFileList), {}, {
8243
+ /**
8244
+ * @param {unknown} x
8245
+ * @param {import('typeson').StateObject} state
8246
+ * @returns {boolean}
8247
+ */
8248
+ test: function test(x, state) {
8249
+ if (typeof FileList !== 'undefined') {
8250
+ return x instanceof FileList;
8251
+ }
8252
+ return typeof origTest === 'function' ? origTest(x, state) : false;
8253
+ },
8254
+ /**
8255
+ * @param {unknown} x
8256
+ * @param {import('typeson').StateObject} state
8257
+ * @returns {unknown}
8258
+ */
8259
+ revive: function revive(x, state) {
8260
+ if (typeof FileList !== 'undefined') {
8261
+ return Reflect.construct(FileList, [x]);
8262
+ }
8263
+ return typeof origRevive === 'function' ? origRevive(x, state) : undefined;
8264
+ }
8265
+ }) : undefined;
8266
+ var typeson = new Typeson().register([ye, customFileList ? {
8267
+ filelist: customFileList
8268
+ } : {}]);
8179
8269
 
8180
8270
  /**
8181
8271
  * @param {(preset: import('typeson-registry').Preset) =>
@@ -8184,7 +8274,7 @@
8184
8274
  */
8185
8275
  function register(func) {
8186
8276
  // eslint-disable-next-line unicorn/no-top-level-assignment-in-function -- Should be one-time cache
8187
- typeson = new Typeson().register(func(ue));
8277
+ typeson = new Typeson().register(func(ye));
8188
8278
  }
8189
8279
 
8190
8280
  /**
@@ -11483,6 +11573,7 @@
11483
11573
  }
11484
11574
  var req = IDBOpenDBRequest.__createInstance();
11485
11575
  var calledDbCreateError = false;
11576
+ var isRevertingSysdb = false;
11486
11577
  if (CFG.autoName && name === '') {
11487
11578
  // eslint-disable-next-line unicorn/no-top-level-assignment-in-function -- Necessary?
11488
11579
  name = 'autoNamedDatabase_' + nameCounter++;
@@ -11509,7 +11600,7 @@
11509
11600
  * @returns {boolean}
11510
11601
  */
11511
11602
  function dbCreateError(tx, err) {
11512
- if (calledDbCreateError) {
11603
+ if (calledDbCreateError || isRevertingSysdb) {
11513
11604
  return false;
11514
11605
  }
11515
11606
  // Defensive cleanup: `pendingVersionChanges.set(name, ...)` (see
@@ -11573,36 +11664,46 @@
11573
11664
  */
11574
11665
  var sysdbFinishedCb = function sysdbFinishedCb(systx, err, cb) {
11575
11666
  if (err) {
11576
- try {
11577
- systx.executeSql('ROLLBACK', [], cb, cb);
11578
- } catch (err) {
11579
- // Browser may fail with expired transaction above so
11580
- // no choice but to manually revert
11667
+ /**
11668
+ * @param {any} [errorToShow]
11669
+ * @returns {void}
11670
+ */
11671
+ var manualRevert = function manualRevert(errorToShow) {
11672
+ /**
11673
+ * @param {string} [msg]
11674
+ * @throws {Error}
11675
+ * @returns {never}
11676
+ */
11677
+ function reportError(msg) {
11678
+ throw new Error('Unable to roll back upgrade transaction!' + (msg || ''));
11679
+ }
11581
11680
  sysdb.transaction(function (systx) {
11582
- /**
11583
- *
11584
- * @param {string} msg
11585
- * @throws {Error}
11586
- * @returns {never}
11587
- */
11588
- function reportError(msg) {
11589
- throw new Error('Unable to roll back upgrade transaction!' + (msg || ''));
11590
- }
11591
-
11592
11681
  // Attempt to revert
11593
11682
  if (oldVersion === 0) {
11594
- systx.executeSql('DELETE FROM dbVersions WHERE "name" = ?', [sqlSafeName], function () {
11595
- // @ts-expect-error Force to work
11596
- cb(reportError); // eslint-disable-line promise/no-callback-in-promise -- Convenient
11597
- },
11598
- // @ts-expect-error Force to work
11599
- reportError);
11683
+ systx.executeSql('DELETE FROM dbVersions WHERE "name" = ?', [sqlSafeName]);
11600
11684
  } else {
11601
- systx.executeSql('UPDATE dbVersions SET "version" = ? WHERE "name" = ?', [oldVersion, sqlSafeName], cb,
11602
- // @ts-expect-error Force to work
11603
- reportError);
11685
+ systx.executeSql('UPDATE dbVersions SET "version" = ? WHERE "name" = ?', [oldVersion, sqlSafeName]);
11604
11686
  }
11687
+ }, function (sqlErr) {
11688
+ isRevertingSysdb = false;
11689
+ cb(sqlErr); // eslint-disable-line promise/no-callback-in-promise -- Convenient
11690
+ }, function () {
11691
+ isRevertingSysdb = false;
11692
+ cb(errorToShow || reportError); // eslint-disable-line promise/no-callback-in-promise -- Convenient
11693
+ });
11694
+ };
11695
+ try {
11696
+ systx.executeSql('ROLLBACK', [], function () {
11697
+ cb(); // eslint-disable-line promise/no-callback-in-promise -- Convenient
11698
+ }, function (tx, sqlErr) {
11699
+ // Browser/Node may fail with expired transaction, so manually revert
11700
+ manualRevert(sqlErr);
11701
+ return false;
11605
11702
  });
11703
+ } catch (e) {
11704
+ // Browser may fail with expired transaction above so
11705
+ // no choice but to manually revert
11706
+ manualRevert(e);
11606
11707
  }
11607
11708
  return;
11608
11709
  }
@@ -11703,6 +11804,7 @@
11703
11804
 
11704
11805
  // eslint-disable-next-line camelcase -- Clear API
11705
11806
  req.transaction.on__preabort = function () {
11807
+ isRevertingSysdb = true;
11706
11808
  pendingVersionChanges.delete(name);
11707
11809
  connection.__upgradeTransaction = null;
11708
11810
  // We ensure any cache is deleted before any request error events fire and try to reopen
@@ -11720,6 +11822,7 @@
11720
11822
  req.__result = undefined;
11721
11823
  req.__done = false;
11722
11824
  connection.close();
11825
+ isRevertingSysdb = true;
11723
11826
  setTimeout(function () {
11724
11827
  var err = createDOMException('AbortError', 'The upgrade transaction was aborted.');
11725
11828
  sysdbFinishedCb(systx, err, function (reportError) {
@@ -11781,7 +11884,26 @@
11781
11884
  }
11782
11885
  sysdbFinishedCb = function sysdbFinishedCb(systx, err, cb) {
11783
11886
  if (err) {
11784
- rollback(err, cb);
11887
+ rollback(err,
11888
+ /**
11889
+ * @param {Error} [reportError]
11890
+ * @returns {void}
11891
+ */
11892
+ function (reportError) {
11893
+ sysdb.transaction(function (systx) {
11894
+ if (oldVersion === 0) {
11895
+ systx.executeSql('DELETE FROM dbVersions WHERE "name" = ?', [sqlSafeName]);
11896
+ } else {
11897
+ systx.executeSql('UPDATE dbVersions SET "version" = ? WHERE "name" = ?', [oldVersion, sqlSafeName]);
11898
+ }
11899
+ }, function (sqlErr) {
11900
+ isRevertingSysdb = false;
11901
+ cb(sqlErr); // eslint-disable-line promise/no-callback-in-promise -- Convenient
11902
+ }, function () {
11903
+ isRevertingSysdb = false;
11904
+ cb(reportError); // eslint-disable-line promise/no-callback-in-promise -- Convenient
11905
+ });
11906
+ });
11785
11907
  } else {
11786
11908
  commit(cb);
11787
11909
  }