indexeddbshim 19.0.5 → 19.0.7

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 (62) hide show
  1. package/README.md +2 -0
  2. package/badges/coverage-badge.svg +1 -1
  3. package/badges/tests-badge.svg +1 -1
  4. package/dist/CFG.d.ts +1 -1
  5. package/dist/CFG.d.ts.map +1 -1
  6. package/dist/DOMException.d.ts.map +1 -1
  7. package/dist/IDBCursor.d.ts.map +1 -1
  8. package/dist/IDBDatabase.d.ts.map +1 -1
  9. package/dist/IDBFactory.d.ts +1 -2
  10. package/dist/IDBFactory.d.ts.map +1 -1
  11. package/dist/IDBIndex.d.ts +2 -6
  12. package/dist/IDBIndex.d.ts.map +1 -1
  13. package/dist/IDBKeyRange.d.ts.map +1 -1
  14. package/dist/IDBObjectStore.d.ts.map +1 -1
  15. package/dist/IDBRecord.d.ts.map +1 -1
  16. package/dist/IDBRequest.d.ts.map +1 -1
  17. package/dist/IDBTransaction.d.ts.map +1 -1
  18. package/dist/Key.d.ts.map +1 -1
  19. package/dist/Sca.d.ts.map +1 -1
  20. package/dist/indexeddbshim-Key.js +73 -33
  21. package/dist/indexeddbshim-Key.js.map +1 -1
  22. package/dist/indexeddbshim-Key.min.js +2 -2
  23. package/dist/indexeddbshim-Key.min.js.map +1 -1
  24. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs +543 -221
  25. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
  26. package/dist/indexeddbshim-UnicodeIdentifiers.js +572 -249
  27. package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
  28. package/dist/indexeddbshim-UnicodeIdentifiers.min.js +3 -3
  29. package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
  30. package/dist/indexeddbshim-node.cjs +543 -221
  31. package/dist/indexeddbshim-node.cjs.map +1 -1
  32. package/dist/indexeddbshim-noninvasive.js +572 -249
  33. package/dist/indexeddbshim-noninvasive.js.map +1 -1
  34. package/dist/indexeddbshim-noninvasive.min.js +3 -3
  35. package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
  36. package/dist/indexeddbshim.js +572 -249
  37. package/dist/indexeddbshim.js.map +1 -1
  38. package/dist/indexeddbshim.min.js +3 -3
  39. package/dist/indexeddbshim.min.js.map +1 -1
  40. package/dist/nodeWebSQL.d.ts.map +1 -1
  41. package/dist/setGlobalVars.d.ts +1 -1
  42. package/dist/setGlobalVars.d.ts.map +1 -1
  43. package/dist/util.d.ts.map +1 -1
  44. package/licenseInfo.json +8 -0
  45. package/package.json +106 -102
  46. package/src/CFG.js +18 -4
  47. package/src/DOMException.js +6 -0
  48. package/src/DOMStringList.js +3 -0
  49. package/src/IDBCursor.js +36 -3
  50. package/src/IDBDatabase.js +26 -10
  51. package/src/IDBFactory.js +105 -5
  52. package/src/IDBIndex.js +49 -32
  53. package/src/IDBKeyRange.js +8 -7
  54. package/src/IDBObjectStore.js +25 -2
  55. package/src/IDBRecord.js +2 -0
  56. package/src/IDBRequest.js +7 -4
  57. package/src/IDBTransaction.js +97 -26
  58. package/src/Key.js +53 -22
  59. package/src/Sca.js +9 -4
  60. package/src/nodeWebSQL.js +1 -0
  61. package/src/setGlobalVars.js +86 -77
  62. package/src/util.js +5 -6
@@ -205,14 +205,17 @@ IDBObjectStore.__createInstance = function (storeProperties, transaction) {
205
205
  tx.executeSql(sql, sqlValues, function (tx) {
206
206
  // This SQL preserves indexes per https://www.sqlite.org/lang_altertable.html
207
207
  const sql = 'ALTER TABLE ' + util.escapeStoreNameForSQL(oldName) + ' RENAME TO ' + util.escapeStoreNameForSQL(name);
208
+ /* c8 ignore next -- Debug-only log; no test sets `CFG.DEBUG` while renaming a store. */
208
209
  if (CFG.DEBUG) { console.log(sql); }
209
210
  tx.executeSql(sql, [], function () {
210
211
  delete me.__pendingName;
211
212
  success();
212
213
  });
213
214
  }, function (tx, err) {
215
+ /* c8 ignore start -- Defensive: SQL execution error, not reliably reproducible without mocking the SQL layer. */
214
216
  error(err);
215
217
  return false;
218
+ /* c8 ignore stop -- see comment above */
216
219
  });
217
220
  });
218
221
  }
@@ -296,6 +299,7 @@ IDBObjectStore.__createObjectStore = function (db, store) {
296
299
  }
297
300
 
298
301
  transaction.__addNonRequestToTransactionQueue(function createObjectStore (tx, args, success, failure) {
302
+ /* c8 ignore start -- Defensive: SQL execution error, not reliably reproducible without mocking the SQL layer. */
299
303
  /**
300
304
  * @param {WebSQLTransaction} tx
301
305
  * @param {(Error & {code?: number})} [err]
@@ -306,6 +310,7 @@ IDBObjectStore.__createObjectStore = function (db, store) {
306
310
  failure(createDOMException('UnknownError', 'Could not create object store "' + storeName + '"', err));
307
311
  return false;
308
312
  }
313
+ /* c8 ignore stop -- see comment above */
309
314
 
310
315
  const escapedStoreNameSQL = util.escapeStoreNameForSQL(storeName);
311
316
  // key INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE
@@ -369,6 +374,7 @@ IDBObjectStore.__deleteObjectStore = function (db, store) {
369
374
 
370
375
  // Remove the object store from WebSQL
371
376
  transaction.__addNonRequestToTransactionQueue(function deleteObjectStore (tx, args, success, failure) {
377
+ /* c8 ignore start -- Defensive: SQL execution error, not reliably reproducible without mocking the SQL layer. */
372
378
  /**
373
379
  * @param {WebSQLTransaction} tx
374
380
  * @param {(Error & {code?: number})} [err]
@@ -379,6 +385,7 @@ IDBObjectStore.__deleteObjectStore = function (db, store) {
379
385
  failure(createDOMException('UnknownError', 'Could not delete ObjectStore', err));
380
386
  return false;
381
387
  }
388
+ /* c8 ignore stop -- see comment above */
382
389
 
383
390
  tx.executeSql('SELECT "name" FROM __sys__ WHERE "name" = ?', [util.escapeSQLiteStatement(store.__currentName)], function (tx, data) {
384
391
  if (data.rows.length > 0) {
@@ -572,13 +579,15 @@ IDBObjectStore.prototype.__checkIndexConstraints = function (tx, value, excludeK
572
579
  return;
573
580
  }
574
581
  const indexKeyValue = indexKey.value;
582
+ /* c8 ignore start -- Defensive: unreachable given the current `Key.js` implementation, where a keyPath evaluation that would resolve to `undefined` always instead reports `invalid`/`failure` (caught above, causing an earlier `return`) rather than succeeding with an `undefined` value. */
575
583
  if (indexKeyValue === undefined) {
576
584
  resolve(undefined);
577
585
  return;
578
586
  }
587
+ /* c8 ignore stop -- see comment above */
579
588
  const multiCheck = index.multiEntry && Array.isArray(indexKeyValue);
580
589
  const fetchArgs = buildFetchIndexDataSQL(true, index, indexKeyValue, 'key', multiCheck);
581
- executeFetchIndexData(null, ...fetchArgs, tx, null, function success (key) {
590
+ executeFetchIndexData(...fetchArgs, tx, null, function success (key) {
582
591
  if (key === undefined || (excludeKey !== undefined && cmp(
583
592
  /** @type {import('./Key.js').Key} */ (key), excludeKey
584
593
  ) === 0)) {
@@ -670,9 +679,11 @@ IDBObjectStore.prototype.__insertData = function (tx, encoded, value, clonedKeyO
670
679
  * @returns {void}
671
680
  */
672
681
  function setIndexInfo (index) {
682
+ /* c8 ignore start -- Defensive: unreachable given the current `Key.js` implementation, where a keyPath evaluation that would resolve to `undefined` always instead reports `invalid`/`failure` (caught above, causing an earlier `return`) rather than succeeding with an `undefined` value. */
673
683
  if (indexKeyValue === undefined) {
674
684
  return;
675
685
  }
686
+ /* c8 ignore stop -- see comment above */
676
687
  paramMap[index.__currentName] = /** @type {string} */ (
677
688
  Key.encode(indexKeyValue, index.multiEntry)
678
689
  );
@@ -680,7 +691,7 @@ IDBObjectStore.prototype.__insertData = function (tx, encoded, value, clonedKeyO
680
691
  if (index.unique) {
681
692
  const multiCheck = index.multiEntry && Array.isArray(indexKeyValue);
682
693
  const fetchArgs = buildFetchIndexDataSQL(true, index, indexKeyValue, 'key', multiCheck);
683
- executeFetchIndexData(null, ...fetchArgs, tx, null, function success (key) {
694
+ executeFetchIndexData(...fetchArgs, tx, null, function success (key) {
684
695
  if (key === undefined) {
685
696
  setIndexInfo(index);
686
697
  resolve(undefined);
@@ -780,6 +791,7 @@ IDBObjectStore.prototype.add = function (value /* , key */) {
780
791
  me.transaction
781
792
  ).__createRequest(me);
782
793
  const [ky, clonedValue] = me.__validateKeyAndValueAndCloneValue(value, key, false);
794
+ // eslint-disable-next-line jsdoc/ts-ban-ts-comment -- TS 6/7
783
795
  // @ts-ignore -- Private API
784
796
  IDBObjectStore.__storingRecordObjectStore(request, me, true, clonedValue, true, ky);
785
797
  return request;
@@ -812,6 +824,7 @@ IDBObjectStore.prototype.put = function (value /* , key */) {
812
824
  me.transaction
813
825
  ).__createRequest(me);
814
826
  const [ky, clonedValue] = me.__validateKeyAndValueAndCloneValue(value, key, false);
827
+ // eslint-disable-next-line jsdoc/ts-ban-ts-comment -- TS 6/7
815
828
  // @ts-ignore -- Private API
816
829
  IDBObjectStore.__storingRecordObjectStore(request, me, true, clonedValue, false, ky);
817
830
  return request;
@@ -836,8 +849,10 @@ IDBObjectStore.prototype.__overwrite = function (tx, key, cb, error) {
836
849
  if (CFG.DEBUG) { console.log('Did the row with the', key, 'exist?', data.rowsAffected); }
837
850
  cb(tx);
838
851
  }, function (tx, err) {
852
+ /* c8 ignore start -- Defensive: SQL execution error, not reliably reproducible without mocking the SQL layer. */
839
853
  error(err);
840
854
  return false;
855
+ /* c8 ignore stop -- see comment above */
841
856
  });
842
857
  };
843
858
 
@@ -950,14 +965,18 @@ IDBObjectStore.prototype.__get = function (query, getKey) {
950
965
  ret = getKey
951
966
  ? Key.decode(util.unescapeSQLiteResponse(/** @type {{key: string}} */ (data.rows.item(0)).key), false)
952
967
  : Sca.decode(util.unescapeSQLiteResponse(/** @type {{value: string}} */ (data.rows.item(0)).value));
968
+ /* c8 ignore start -- Defensive: catches unexpected decode failures (e.g. corrupted stored data); not reliably reproducible via the public API since encode/decode are always paired and never write undecodable data. */
953
969
  } catch (e) {
954
970
  // If no result is returned, or error occurs when parsing JSON
955
971
  if (CFG.DEBUG) { console.log(e); }
956
972
  }
973
+ /* c8 ignore stop -- see comment above */
957
974
  success(ret);
958
975
  }, function (tx, err) {
976
+ /* c8 ignore start -- Defensive: SQL execution error, not reliably reproducible without mocking the SQL layer. */
959
977
  error(err);
960
978
  return false;
979
+ /* c8 ignore stop -- see comment above */
961
980
  });
962
981
  }, undefined, me);
963
982
  };
@@ -1060,8 +1079,10 @@ IDBObjectStore.prototype.delete = function (query) {
1060
1079
  });
1061
1080
  success();
1062
1081
  }, function (tx, err) {
1082
+ /* c8 ignore start -- Defensive: SQL execution error, not reliably reproducible without mocking the SQL layer. */
1063
1083
  error(err);
1064
1084
  return false;
1085
+ /* c8 ignore stop -- see comment above */
1065
1086
  });
1066
1087
  }, undefined, me);
1067
1088
  };
@@ -1091,8 +1112,10 @@ IDBObjectStore.prototype.clear = function () {
1091
1112
  });
1092
1113
  success();
1093
1114
  }, function (tx, err) {
1115
+ /* c8 ignore start -- Defensive: SQL execution error, not reliably reproducible without mocking the SQL layer. */
1094
1116
  error(err);
1095
1117
  return false;
1118
+ /* c8 ignore stop -- see comment above */
1096
1119
  });
1097
1120
  }, undefined, me);
1098
1121
  };
package/src/IDBRecord.js CHANGED
@@ -43,6 +43,7 @@ IDBRecord.__createInstance = function (key, primaryKey, value) {
43
43
  * @this {IDBRecordFull}
44
44
  */
45
45
  function IDBRecord () {
46
+ // eslint-disable-next-line jsdoc/ts-ban-ts-comment -- TS 6/7
46
47
  // @ts-ignore Should be ok
47
48
  this[Symbol.toStringTag] = 'IDBRecord';
48
49
  this.__key = key;
@@ -84,6 +85,7 @@ readonlyProperties.forEach((prop) => {
84
85
  if (!(this instanceof IDBRecordAlias)) {
85
86
  throw new TypeError('Illegal invocation');
86
87
  }
88
+ // eslint-disable-next-line jsdoc/ts-ban-ts-comment -- TS 6/7
87
89
  // @ts-ignore `this` is a real instance past the check above (not an issue in TS7)
88
90
  return this['__' + prop];
89
91
  }
package/src/IDBRequest.js CHANGED
@@ -42,8 +42,10 @@ function IDBRequest () {
42
42
  * @this {IDBRequestFull}
43
43
  */
44
44
  IDBRequest.__super = function IDBRequest () {
45
+ // eslint-disable-next-line jsdoc/ts-ban-ts-comment -- TS 6/7
45
46
  // @ts-ignore It's ok
46
47
  this[Symbol.toStringTag] = 'IDBRequest';
48
+ // eslint-disable-next-line jsdoc/ts-ban-ts-comment -- TS 6/7
47
49
  // @ts-ignore Part of `ShimEventTarget`
48
50
  this.__setOptions({
49
51
  legacyOutputDidListenersThrowFlag: true // Event hook for IndexedB
@@ -106,10 +108,9 @@ IDBRequest.prototype[Symbol.toStringTag] = 'IDBRequestPrototype';
106
108
  * @returns {import('./IDBTransaction.js').IDBTransactionFull|null|undefined}
107
109
  */
108
110
  IDBRequest.prototype.__getParent = function () {
109
- if (this.toString() === '[object IDBOpenDBRequest]') {
110
- return null;
111
- }
112
- return this.__transaction;
111
+ return this.toString() === '[object IDBOpenDBRequest]'
112
+ ? null
113
+ : this.__transaction;
113
114
  };
114
115
 
115
116
  /* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
@@ -171,8 +172,10 @@ IDBOpenDBRequest.__createInstance = function () {
171
172
  function IDBOpenDBRequest () {
172
173
  IDBRequest.__super.call(this);
173
174
 
175
+ // eslint-disable-next-line jsdoc/ts-ban-ts-comment -- TS 6/7
174
176
  // @ts-ignore It's ok
175
177
  this[Symbol.toStringTag] = 'IDBOpenDBRequest';
178
+ // eslint-disable-next-line jsdoc/ts-ban-ts-comment -- TS 6/7
176
179
  // @ts-ignore It's ok
177
180
  this.__setOptions({
178
181
  legacyOutputDidListenersThrowFlag: true, // Event hook for IndexedB