indexeddbshim 16.1.0 → 17.1.0

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 (82) hide show
  1. package/README.md +65 -3
  2. package/badges/licenses-badge-dev.svg +1 -1
  3. package/badges/licenses-badge.svg +1 -1
  4. package/dist/CFG.d.ts +1 -0
  5. package/dist/CFG.d.ts.map +1 -1
  6. package/dist/DOMException.d.ts.map +1 -1
  7. package/dist/DOMStringList.d.ts.map +1 -1
  8. package/dist/IDBCursor.d.ts +12 -3
  9. package/dist/IDBCursor.d.ts.map +1 -1
  10. package/dist/IDBDatabase.d.ts +2 -1
  11. package/dist/IDBDatabase.d.ts.map +1 -1
  12. package/dist/IDBFactory.d.ts +2 -1
  13. package/dist/IDBFactory.d.ts.map +1 -1
  14. package/dist/IDBIndex.d.ts +2 -1
  15. package/dist/IDBIndex.d.ts.map +1 -1
  16. package/dist/IDBKeyRange.d.ts +1 -1
  17. package/dist/IDBKeyRange.d.ts.map +1 -1
  18. package/dist/IDBObjectStore.d.ts +2 -1
  19. package/dist/IDBObjectStore.d.ts.map +1 -1
  20. package/dist/IDBRequest.d.ts +5 -3
  21. package/dist/IDBRequest.d.ts.map +1 -1
  22. package/dist/IDBTransaction.d.ts +23 -1
  23. package/dist/IDBTransaction.d.ts.map +1 -1
  24. package/dist/Key.d.ts.map +1 -1
  25. package/dist/Sca.d.ts.map +1 -1
  26. package/dist/UnicodeIdentifiers.d.ts.map +1 -1
  27. package/dist/browser-noninvasive.d.ts.map +1 -1
  28. package/dist/indexeddbshim-Key.js +1863 -1669
  29. package/dist/indexeddbshim-Key.js.map +1 -1
  30. package/dist/indexeddbshim-Key.min.js +2 -2
  31. package/dist/indexeddbshim-Key.min.js.map +1 -1
  32. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs +2373 -1893
  33. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
  34. package/dist/indexeddbshim-UnicodeIdentifiers.js +3124 -2285
  35. package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
  36. package/dist/indexeddbshim-UnicodeIdentifiers.min.js +9 -2
  37. package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
  38. package/dist/indexeddbshim-node.cjs +2373 -1893
  39. package/dist/indexeddbshim-node.cjs.map +1 -1
  40. package/dist/indexeddbshim-noninvasive.js +3123 -2284
  41. package/dist/indexeddbshim-noninvasive.js.map +1 -1
  42. package/dist/indexeddbshim-noninvasive.min.js +9 -2
  43. package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
  44. package/dist/indexeddbshim.js +3120 -2282
  45. package/dist/indexeddbshim.js.map +1 -1
  46. package/dist/indexeddbshim.min.js +9 -2
  47. package/dist/indexeddbshim.min.js.map +1 -1
  48. package/dist/node-UnicodeIdentifiers.d.ts +2 -2
  49. package/dist/node-UnicodeIdentifiers.d.ts.map +1 -1
  50. package/dist/node.d.ts +2 -2
  51. package/dist/node.d.ts.map +1 -1
  52. package/dist/nodeSQLiteDatabase.d.ts +65 -0
  53. package/dist/nodeSQLiteDatabase.d.ts.map +1 -0
  54. package/dist/nodeWebSQL.d.ts.map +1 -1
  55. package/dist/util.d.ts +5 -0
  56. package/dist/util.d.ts.map +1 -1
  57. package/package.json +118 -106
  58. package/src/CFG.js +5 -3
  59. package/src/DOMException.js +11 -9
  60. package/src/DOMStringList.js +8 -3
  61. package/src/Event.js +2 -0
  62. package/src/IDBCursor.js +152 -95
  63. package/src/IDBDatabase.js +9 -6
  64. package/src/IDBFactory.js +31 -20
  65. package/src/IDBIndex.js +83 -79
  66. package/src/IDBKeyRange.js +42 -35
  67. package/src/IDBObjectStore.js +83 -77
  68. package/src/IDBRequest.js +28 -15
  69. package/src/IDBTransaction.js +40 -6
  70. package/src/IDBVersionChangeEvent.js +2 -0
  71. package/src/Key.js +28 -14
  72. package/src/Sca.js +2 -1
  73. package/src/UnicodeIdentifiers.js +2 -2
  74. package/src/browser-UnicodeIdentifiers.js +0 -1
  75. package/src/browser-noninvasive.js +0 -1
  76. package/src/browser.js +0 -1
  77. package/src/node-UnicodeIdentifiers.js +6 -2
  78. package/src/node.js +6 -2
  79. package/src/nodeSQLiteDatabase.js +174 -0
  80. package/src/nodeWebSQL.js +1 -3
  81. package/src/setGlobalVars.js +13 -13
  82. package/src/util.js +75 -15
package/src/IDBFactory.js CHANGED
@@ -31,6 +31,7 @@ let fs;
31
31
  * @returns {void}
32
32
  */
33
33
  const setFS = (_fs) => {
34
+ // eslint-disable-next-line unicorn/no-top-level-assignment-in-function -- Necessary?
34
35
  fs = _fs;
35
36
  };
36
37
 
@@ -93,7 +94,7 @@ function processNextInConnectionQueue (name, origin = getOrigin()) {
93
94
  */
94
95
  function addRequestToConnectionQueue (req, name, origin = getOrigin(), cb) {
95
96
  /* eslint-enable default-param-last -- Keep cb at end */
96
- if (!connectionQueue[origin][name]) {
97
+ if (!Object.hasOwn(connectionQueue[origin], name)) {
97
98
  connectionQueue[origin][name] = [];
98
99
  }
99
100
  connectionQueue[origin][name].push({req, cb});
@@ -139,7 +140,7 @@ function triggerAnyVersionChangeAndBlockedEvents (openConnections, req, oldVersi
139
140
  setTimeout(() => {
140
141
  entry.dispatchEvent(e); // No need to catch errors
141
142
  resolve(undefined);
142
- });
143
+ }, 0);
143
144
  });
144
145
  });
145
146
  }, SyncPromise.resolve(undefined)).then(function () {
@@ -168,7 +169,7 @@ function triggerAnyVersionChangeAndBlockedEvents (openConnections, req, oldVersi
168
169
  } else {
169
170
  resolve(undefined);
170
171
  }
171
- });
172
+ }, 0);
172
173
  });
173
174
  });
174
175
  }
@@ -229,7 +230,7 @@ function getLatestCachedWebSQLDB (name) {
229
230
  function cleanupDatabaseResources (__openDatabase, name, escapedDatabaseName, databaseDeleted, dbError) {
230
231
  const useMemoryDatabase = typeof CFG.memoryDatabase === 'string';
231
232
  if (useMemoryDatabase) {
232
- const latestSQLiteDBCached = websqlDBCache[name] ? getLatestCachedWebSQLDB(name) : null;
233
+ const latestSQLiteDBCached = Object.hasOwn(websqlDBCache, name) ? getLatestCachedWebSQLDB(name) : null;
233
234
  if (!latestSQLiteDBCached) {
234
235
  console.warn('Could not find a memory database instance to delete.');
235
236
  databaseDeleted();
@@ -334,6 +335,7 @@ function createSysDB (__openDatabase, success, failure) {
334
335
  if (sysdb) {
335
336
  success();
336
337
  } else {
338
+ // eslint-disable-next-line unicorn/no-top-level-assignment-in-function -- Necessary?
337
339
  sysdb = __openDatabase(
338
340
  typeof CFG.memoryDatabase === 'string'
339
341
  ? CFG.memoryDatabase
@@ -367,6 +369,7 @@ function createSysDB (__openDatabase, success, failure) {
367
369
  /**
368
370
  * IDBFactory Class.
369
371
  * @see https://w3c.github.io/IndexedDB/#idl-def-IDBFactory
372
+ * @throws {TypeError}
370
373
  * @class
371
374
  */
372
375
  function IDBFactory () {
@@ -438,6 +441,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
438
441
  let calledDbCreateError = false;
439
442
 
440
443
  if (CFG.autoName && name === '') {
444
+ // eslint-disable-next-line unicorn/no-top-level-assignment-in-function -- Necessary?
441
445
  name = 'autoNamedDatabase_' + nameCounter++;
442
446
  }
443
447
  name = String(name); // cast to a string
@@ -494,7 +498,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
494
498
  req.__done = true;
495
499
  }
496
500
  const connection = IDBDatabase.__createInstance(db, name, oldVersion, version, data);
497
- if (!me.__connections[name]) {
501
+ if (!Object.hasOwn(me.__connections, name)) {
498
502
  me.__connections[name] = [];
499
503
  }
500
504
  me.__connections[name].push(connection);
@@ -589,7 +593,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
589
593
  req.__result
590
594
  ).__versionTransaction = null;
591
595
  sysdbFinishedCb(systx, false, function () {
592
- req.transaction.__transFinishedCb(false, function () {
596
+ req.transaction.__callTransFinishedCb(false, function () {
593
597
  ev.complete();
594
598
  req.__transaction = null;
595
599
  });
@@ -602,7 +606,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
602
606
  connection.__upgradeTransaction = null;
603
607
  // We ensure any cache is deleted before any request error events fire and try to reopen
604
608
  if (useDatabaseCache) {
605
- if (name in websqlDBCache) {
609
+ if (Object.hasOwn(websqlDBCache, name)) {
606
610
  delete websqlDBCache[name][version];
607
611
  }
608
612
  }
@@ -633,7 +637,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
633
637
  dbCreateError(err);
634
638
  return false;
635
639
  });
636
- });
640
+ }, 0);
637
641
  };
638
642
 
639
643
  // eslint-disable-next-line camelcase -- Clear API
@@ -712,7 +716,14 @@ IDBFactory.prototype.open = function (name /* , version */) {
712
716
  function openDB (oldVersion) {
713
717
  /** @type {DatabaseFull} */
714
718
  let db;
715
- if ((useMemoryDatabase || useDatabaseCache) && name in websqlDBCache && websqlDBCache[name][version]) {
719
+ if (version === undefined) {
720
+ // Resolve before use as a cache key below, or a `open(name)` call
721
+ // (no explicit version) would cache/look up under `undefined`
722
+ // instead of the actual version, causing a second, separate
723
+ // connection to be opened for the same database on reopen.
724
+ version = oldVersion || 1;
725
+ }
726
+ if ((useMemoryDatabase || useDatabaseCache) && Object.hasOwn(websqlDBCache, name) && Object.hasOwn(websqlDBCache[name], version)) {
716
727
  db = websqlDBCache[name][version];
717
728
  } else {
718
729
  db = me.__openDatabase(
@@ -722,22 +733,19 @@ IDBFactory.prototype.open = function (name /* , version */) {
722
733
  CFG.DEFAULT_DB_SIZE
723
734
  );
724
735
  if (useDatabaseCache) {
725
- if (!(name in websqlDBCache)) {
736
+ if (!(Object.hasOwn(websqlDBCache, name))) {
726
737
  websqlDBCache[name] = {};
727
738
  }
728
739
  websqlDBCache[name][version] = db;
729
740
  }
730
741
  }
731
742
 
732
- if (version === undefined) {
733
- version = oldVersion || 1;
734
- }
735
743
  if (oldVersion > version) {
736
744
  const err = createDOMException('VersionError', 'An attempt was made to open a database using a lower version than the existing version.', version);
737
745
  if (useDatabaseCache) {
738
746
  setTimeout(() => {
739
747
  dbCreateError(err);
740
- });
748
+ }, 0);
741
749
  } else {
742
750
  dbCreateError(err);
743
751
  }
@@ -764,7 +772,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
764
772
  addRequestToConnectionQueue(req, name, /* origin */ undefined, function () {
765
773
  let latestCachedVersion;
766
774
  if (useDatabaseCache) {
767
- if (!(name in websqlDBCache)) {
775
+ if (!Object.hasOwn(websqlDBCache, name)) {
768
776
  websqlDBCache[name] = {};
769
777
  }
770
778
  latestCachedVersion = getLatestCachedWebSQLVersion(name);
@@ -884,7 +892,7 @@ IDBFactory.prototype.deleteDatabase = function (name) {
884
892
  /** @type {DatabaseDeleted} */
885
893
  function databaseDeleted () {
886
894
  sysdbFinishedCbDelete(false, function () {
887
- if (useDatabaseCache && name in websqlDBCache) {
895
+ if (useDatabaseCache && Object.hasOwn(websqlDBCache, name)) {
888
896
  delete websqlDBCache[name]; // New calls will treat as though never existed
889
897
  }
890
898
  delete me.__connections[name];
@@ -901,7 +909,7 @@ IDBFactory.prototype.deleteDatabase = function (name) {
901
909
  ({version} = data.rows.item(0));
902
910
 
903
911
  const openConnections = me.__connections[name] || [];
904
- triggerAnyVersionChangeAndBlockedEvents(openConnections, req, version, null).then(function () { // eslint-disable-line promise/catch-or-return -- Sync promise
912
+ triggerAnyVersionChangeAndBlockedEvents(openConnections, req, version, null).then(function () {
905
913
  // Since we need two databases which can't be in a single transaction, we
906
914
  // do this deleting from `dbVersions` first since the `__sys__` deleting
907
915
  // only impacts file memory whereas this one is critical for avoiding it
@@ -930,7 +938,7 @@ IDBFactory.prototype.deleteDatabase = function (name) {
930
938
  });
931
939
  return undefined;
932
940
  // @ts-expect-error It's ok
933
- }, dbError);
941
+ }).catch(dbError);
934
942
  return undefined;
935
943
  }, dbError);
936
944
  });
@@ -1017,7 +1025,7 @@ IDBFactory.prototype.databases = function () {
1017
1025
  * @todo forceClose: Test
1018
1026
  * This is provided to facilitate unit-testing of the
1019
1027
  * closing of a database connection with a forced flag:
1020
- * <http://w3c.github.io/IndexedDB/#steps-for-closing-a-database-connection>
1028
+ * <https://w3c.github.io/IndexedDB/#steps-for-closing-a-database-connection>
1021
1029
  * @param {string} dbName
1022
1030
  * @param {Integer} connIdx
1023
1031
  * @param {string} msg
@@ -1041,12 +1049,13 @@ IDBFactory.prototype.__forceClose = function (dbName, connIdx, msg) {
1041
1049
  forceClose(connection);
1042
1050
  });
1043
1051
  });
1044
- } else if (!me.__connections[dbName]) {
1052
+ } else if (!Object.hasOwn(me.__connections, dbName)) {
1045
1053
  console.log('No database connections with that name to force close');
1046
1054
  } else if (util.isNullish(connIdx)) {
1047
1055
  me.__connections[dbName].forEach((conn) => {
1048
1056
  forceClose(conn);
1049
1057
  });
1058
+ // eslint-disable-next-line unicorn/prefer-number-is-safe-integer -- Ok
1050
1059
  } else if (!Number.isInteger(connIdx) || connIdx < 0 || connIdx > me.__connections[dbName].length - 1) {
1051
1060
  throw new TypeError(
1052
1061
  'If providing an argument, __forceClose must be called with a ' +
@@ -1068,9 +1077,11 @@ IDBFactory.prototype.__setConnectionQueueOrigin = function (origin = getOrigin()
1068
1077
 
1069
1078
  IDBFactory.prototype[Symbol.toStringTag] = 'IDBFactoryPrototype';
1070
1079
 
1080
+ /* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
1071
1081
  Object.defineProperty(IDBFactory, 'prototype', {
1072
1082
  writable: false
1073
1083
  });
1084
+ /* eslint-enable unicorn/no-top-level-side-effects -- Would be good */
1074
1085
 
1075
1086
  const shimIndexedDB = IDBFactory.__createInstance();
1076
1087
  export {IDBFactory, cmp, shimIndexedDB, setFS};
package/src/IDBIndex.js CHANGED
@@ -31,7 +31,8 @@ const readonlyProperties = ['objectStore', 'keyPath', 'multiEntry', 'unique'];
31
31
 
32
32
  /**
33
33
  * IDB Index.
34
- * @see http://www.w3.org/TR/IndexedDB/#idl-def-IDBIndex
34
+ * @see https://www.w3.org/TR/IndexedDB/#idl-def-IDBIndex
35
+ * @throws {TypeError}
35
36
  * @class
36
37
  */
37
38
  function IDBIndex () {
@@ -85,83 +86,85 @@ IDBIndex.__createInstance = function (store, indexProperties) {
85
86
  me.__unique = Boolean(optionalParams && optionalParams.unique);
86
87
  me.__deleted = Boolean(indexProperties.__deleted);
87
88
  me.__objectStore.__cursors = indexProperties.cursors || [];
88
- Object.defineProperty(me, '__currentName', {
89
- /**
90
- * @this {IDBIndexFull}
91
- * @returns {string}
92
- */
93
- get () {
94
- return '__pendingName' in me
95
- ? /** @type {string} */ (me.__pendingName)
96
- : me.name;
97
- }
98
- });
99
- Object.defineProperty(me, 'name', {
100
- enumerable: false,
101
- configurable: false,
102
- /**
103
- * @this {IDBIndexFull}
104
- * @returns {string}
105
- */
106
- get () {
107
- return this.__name;
108
- },
109
- /**
110
- * @param {string} newName
111
- * @this {IDBIndexFull}
112
- * @returns {void}
113
- */
114
- set (newName) {
115
- const me = this;
116
- newName = util.convertToDOMString(newName);
117
- const oldName = me.name;
118
- IDBTransaction.__assertVersionChange(me.objectStore.transaction);
119
- IDBTransaction.__assertActive(me.objectStore.transaction);
120
- IDBIndexAlias.__invalidStateIfDeleted(me);
121
- IDBObjectStore.__invalidStateIfDeleted(me);
122
- if (newName === oldName) {
123
- return;
124
- }
125
-
126
- if (me.objectStore.__indexes[newName] && !me.objectStore.__indexes[newName].__deleted &&
127
- !me.objectStore.__indexes[newName].__pendingDelete) {
128
- throw createDOMException('ConstraintError', 'Index "' + newName + '" already exists on ' + me.objectStore.__currentName);
89
+ Object.defineProperties(me, {
90
+ __currentName: {
91
+ /**
92
+ * @this {IDBIndexFull}
93
+ * @returns {string}
94
+ */
95
+ get () {
96
+ return '__pendingName' in me
97
+ ? /** @type {string} */ (me.__pendingName)
98
+ : me.name;
129
99
  }
100
+ },
101
+ name: {
102
+ enumerable: false,
103
+ configurable: false,
104
+ /**
105
+ * @this {IDBIndexFull}
106
+ * @returns {string}
107
+ */
108
+ get () {
109
+ return this.__name;
110
+ },
111
+ /**
112
+ * @param {string} newName
113
+ * @this {IDBIndexFull}
114
+ * @returns {void}
115
+ */
116
+ set (newName) {
117
+ const me = this;
118
+ newName = util.convertToDOMString(newName);
119
+ const oldName = me.name;
120
+ IDBTransaction.__assertVersionChange(me.objectStore.transaction);
121
+ IDBTransaction.__assertActive(me.objectStore.transaction);
122
+ IDBIndexAlias.__invalidStateIfDeleted(me);
123
+ IDBObjectStore.__invalidStateIfDeleted(me);
124
+ if (newName === oldName) {
125
+ return;
126
+ }
130
127
 
131
- me.__name = newName;
132
-
133
- const {objectStore} = me;
134
- delete objectStore.__indexes[oldName];
135
- objectStore.__indexes[newName] = me;
136
- objectStore.indexNames.splice(objectStore.indexNames.indexOf(oldName), 1, newName);
137
-
138
- const storeHandle = /** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
139
- objectStore.transaction
140
- ).__storeHandles[objectStore.name];
141
- const oldIndexHandle = storeHandle.__indexHandles[oldName];
142
- oldIndexHandle.__name = newName; // Fix old references
143
- storeHandle.__indexHandles[newName] = oldIndexHandle; // Ensure new reference accessible
144
- me.__pendingName = oldName;
145
-
146
- const colInfoToPreserveArr = [
147
- ['key', 'BLOB ' + (objectStore.autoIncrement ? 'UNIQUE, inc INTEGER PRIMARY KEY AUTOINCREMENT' : 'PRIMARY KEY')],
148
- ['value', 'BLOB']
149
- ].concat(
150
- // @ts-expect-error Has numeric indexes instead of iterator
151
- [...objectStore.indexNames]
152
- .filter((indexName) => indexName !== newName)
153
- .map((indexName) => [util.escapeIndexNameForSQL(indexName), 'BLOB'])
154
- );
155
-
156
- me.__renameIndex(
157
- objectStore, oldName, newName, colInfoToPreserveArr,
158
- function (tx, success) {
159
- IDBIndexAlias.__updateIndexList(store, tx, function (store) {
160
- delete storeHandle.__pendingName;
161
- success(store);
162
- });
128
+ if (Object.hasOwn(me.objectStore.__indexes, newName) && !me.objectStore.__indexes[newName].__deleted &&
129
+ !me.objectStore.__indexes[newName].__pendingDelete) {
130
+ throw createDOMException('ConstraintError', 'Index "' + newName + '" already exists on ' + me.objectStore.__currentName);
163
131
  }
164
- );
132
+
133
+ me.__name = newName;
134
+
135
+ const {objectStore} = me;
136
+ delete objectStore.__indexes[oldName];
137
+ objectStore.__indexes[newName] = me;
138
+ objectStore.indexNames.splice(objectStore.indexNames.indexOf(oldName), 1, newName);
139
+
140
+ const storeHandle = /** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
141
+ objectStore.transaction
142
+ ).__storeHandles[objectStore.name];
143
+ const oldIndexHandle = storeHandle.__indexHandles[oldName];
144
+ oldIndexHandle.__name = newName; // Fix old references
145
+ storeHandle.__indexHandles[newName] = oldIndexHandle; // Ensure new reference accessible
146
+ me.__pendingName = oldName;
147
+
148
+ const colInfoToPreserveArr = [
149
+ ['key', 'BLOB ' + (objectStore.autoIncrement ? 'UNIQUE, inc INTEGER PRIMARY KEY AUTOINCREMENT' : 'PRIMARY KEY')],
150
+ ['value', 'BLOB']
151
+ ].concat(
152
+ // @ts-expect-error Has numeric indexes instead of iterator
153
+ [...objectStore.indexNames]
154
+ .filter((indexName) => indexName !== newName)
155
+ .map((indexName) => [util.escapeIndexNameForSQL(indexName), 'BLOB'])
156
+ );
157
+
158
+ me.__renameIndex(
159
+ objectStore, oldName, newName, colInfoToPreserveArr,
160
+ function (tx, success) {
161
+ IDBIndexAlias.__updateIndexList(store, tx, function (store) {
162
+ delete storeHandle.__pendingName;
163
+ success(store);
164
+ });
165
+ }
166
+ );
167
+ }
165
168
  }
166
169
  });
167
170
  }
@@ -288,7 +291,7 @@ IDBIndex.__createIndex = function (store, index) {
288
291
  Key.encode(indexKey.value, index.multiEntry)
289
292
  );
290
293
  if (index.unique) {
291
- if (indexValues[indexKeyStr]) {
294
+ if (Object.hasOwn(indexValues, indexKeyStr)) {
292
295
  indexValues = {};
293
296
  failure(createDOMException(
294
297
  'ConstraintError',
@@ -634,7 +637,7 @@ IDBIndex.prototype.__renameIndex = function (store, oldName, newName, colInfoToP
634
637
  const listColInfoToPreserve = (colInfoToPreserve.length ? (colInfoToPreserve.join(', ') + ', ') : '');
635
638
  const listColsToPreserve = (colNamesToPreserve.length ? (colNamesToPreserve.join(', ') + ', ') : '');
636
639
 
637
- // We could adapt the approach at http://stackoverflow.com/a/8430746/271577
640
+ // We could adapt the approach at https://stackoverflow.com/a/8430746/271577
638
641
  // to make the approach reusable without passing column names, but it is a bit fragile
639
642
  /** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
640
643
  store.transaction
@@ -730,8 +733,7 @@ IDBIndex.prototype.__renameIndex = function (store, oldName, newName, colInfoToP
730
733
  );
731
734
  })
732
735
  );
733
- SyncPromise.all(indexCreations).then(
734
- finish,
736
+ SyncPromise.all(indexCreations).then(finish).catch(
735
737
  /** @type {(reason: any) => PromiseLike<never>} */
736
738
  (error)
737
739
  ).catch((err) => {
@@ -749,6 +751,7 @@ IDBIndex.prototype.__renameIndex = function (store, oldName, newName, colInfoToP
749
751
  * @typedef {any} AnyValue
750
752
  */
751
753
 
754
+ /* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
752
755
  Object.defineProperty(IDBIndex, Symbol.hasInstance, {
753
756
  /**
754
757
  * @param {AnyValue} obj
@@ -769,6 +772,7 @@ IDBIndex.prototype[Symbol.toStringTag] = 'IDBIndexPrototype';
769
772
  Object.defineProperty(IDBIndex, 'prototype', {
770
773
  writable: false
771
774
  });
775
+ /* eslint-enable unicorn/no-top-level-side-effects -- Would be good */
772
776
 
773
777
  /**
774
778
  * @param {number|null} count
@@ -14,7 +14,7 @@ const readonlyProperties = /** @type {const} */ (['lower', 'upper', 'lowerOpen',
14
14
 
15
15
  /**
16
16
  * The IndexedDB KeyRange object.
17
- * @see http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#dfn-key-range
17
+ * @see https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#dfn-key-range
18
18
  * @throws {TypeError}
19
19
  * @class
20
20
  */
@@ -35,6 +35,7 @@ const IDBKeyRangeAlias = IDBKeyRange;
35
35
  IDBKeyRange.__createInstance = function (lower, upper, lowerOpen, upperOpen) {
36
36
  /**
37
37
  * @class
38
+ * @throws {DOMException|Error}
38
39
  */
39
40
  function IDBKeyRange () {
40
41
  this[Symbol.toStringTag] = 'IDBKeyRange';
@@ -136,6 +137,7 @@ IDBKeyRange.bound = function (lower, upper /* , lowerOpen, upperOpen */) {
136
137
  };
137
138
  IDBKeyRange.prototype[Symbol.toStringTag] = 'IDBKeyRangePrototype';
138
139
 
140
+ /* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
139
141
  readonlyProperties.forEach((prop) => {
140
142
  Object.defineProperty(IDBKeyRange.prototype, '__' + prop, {
141
143
  enumerable: false,
@@ -163,19 +165,22 @@ readonlyProperties.forEach((prop) => {
163
165
  Object.defineProperty(IDBKeyRange.prototype, prop, desc);
164
166
  });
165
167
 
166
- Object.defineProperty(IDBKeyRange, Symbol.hasInstance, {
167
- value:
168
- /**
169
- * @param {object} obj
170
- * @returns {boolean}
171
- */
172
- (obj) => util.isObj(obj) && 'upper' in obj && 'lowerOpen' in obj &&
173
- typeof obj.lowerOpen === 'boolean'
168
+ Object.defineProperties(IDBKeyRange, {
169
+ [Symbol.hasInstance]: {
170
+ value:
171
+ /**
172
+ * @param {object} obj
173
+ * @returns {boolean}
174
+ */
175
+ (obj) => util.isObj(obj) && 'upper' in obj && 'lowerOpen' in obj &&
176
+ typeof obj.lowerOpen === 'boolean'
177
+ },
178
+ prototype: {
179
+ writable: false
180
+ }
174
181
  });
175
182
 
176
- Object.defineProperty(IDBKeyRange, 'prototype', {
177
- writable: false
178
- });
183
+ /* eslint-enable unicorn/no-top-level-side-effects -- Would be good */
179
184
 
180
185
  /**
181
186
  * @param {IDBKeyRangeFull|undefined} range
@@ -189,30 +194,32 @@ Object.defineProperty(IDBKeyRange, 'prototype', {
189
194
  function setSQLForKeyRange (
190
195
  range, quotedKeyColumnName, sql, sqlValues, addAnd, checkCached
191
196
  ) {
192
- if (range && (range.lower !== undefined || range.upper !== undefined)) {
193
- if (addAnd) { sql.push('AND'); }
194
- let encodedLowerKey, encodedUpperKey;
195
- const hasLower = range.lower !== undefined;
196
- const hasUpper = range.upper !== undefined;
197
- if (hasLower) {
198
- encodedLowerKey = checkCached ? range.__lowerCached : Key.encode(range.lower);
199
- }
200
- if (hasUpper) {
201
- encodedUpperKey = checkCached ? range.__upperCached : Key.encode(range.upper);
202
- }
203
- if (hasLower) {
204
- sqlValues.push(util.escapeSQLiteStatement(/** @type {string} */ (encodedLowerKey)));
205
- if (hasUpper && encodedLowerKey === encodedUpperKey && !range.lowerOpen && !range.upperOpen) {
206
- sql.push(quotedKeyColumnName, '=', '?');
207
- return;
208
- }
209
- sql.push(quotedKeyColumnName, (range.lowerOpen ? '>' : '>='), '?');
210
- }
211
- if (hasLower && hasUpper) { sql.push('AND'); }
212
- if (hasUpper) {
213
- sql.push(quotedKeyColumnName, (range.upperOpen ? '<' : '<='), '?');
214
- sqlValues.push(util.escapeSQLiteStatement(/** @type {string} */ (encodedUpperKey)));
197
+ if (!(range && (range.lower !== undefined || range.upper !== undefined))) {
198
+ return;
199
+ }
200
+
201
+ if (addAnd) { sql.push('AND'); }
202
+ let encodedLowerKey, encodedUpperKey;
203
+ const hasLower = range.lower !== undefined;
204
+ const hasUpper = range.upper !== undefined;
205
+ if (hasLower) {
206
+ encodedLowerKey = checkCached ? range.__lowerCached : Key.encode(range.lower);
207
+ }
208
+ if (hasUpper) {
209
+ encodedUpperKey = checkCached ? range.__upperCached : Key.encode(range.upper);
210
+ }
211
+ if (hasLower) {
212
+ sqlValues.push(util.escapeSQLiteStatement(/** @type {string} */ (encodedLowerKey)));
213
+ if (hasUpper && encodedLowerKey === encodedUpperKey && !range.lowerOpen && !range.upperOpen) {
214
+ sql.push(quotedKeyColumnName, '=', '?');
215
+ return;
215
216
  }
217
+ sql.push(quotedKeyColumnName, (range.lowerOpen ? '>' : '>='), '?');
218
+ }
219
+ if (hasLower && hasUpper) { sql.push('AND'); }
220
+ if (hasUpper) {
221
+ sql.push(quotedKeyColumnName, (range.upperOpen ? '<' : '<='), '?');
222
+ sqlValues.push(util.escapeSQLiteStatement(/** @type {string} */ (encodedUpperKey)));
216
223
  }
217
224
  }
218
225