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
package/src/Sca.js CHANGED
@@ -15,14 +15,17 @@ const specSet = structuredCloningForStorage
15
15
 
16
16
  const origFileList = specSet && !Array.isArray(specSet) && 'filelist' in specSet
17
17
  ? specSet.filelist
18
+ /* c8 ignore next -- Defensive fallback if typeson-registry's `filelist` preset entry ever goes missing */
18
19
  : undefined;
19
20
 
20
21
  const origTest = origFileList && typeof origFileList === 'object' && 'test' in origFileList && typeof origFileList.test === 'function'
21
22
  ? origFileList.test
23
+ /* c8 ignore next -- Defensive fallback if typeson-registry's `filelist.test` ever goes missing */
22
24
  : undefined;
23
25
 
24
26
  const origRevive = origFileList && typeof origFileList === 'object' && 'revive' in origFileList && typeof origFileList.revive === 'function'
25
27
  ? origFileList.revive
28
+ /* c8 ignore next -- Defensive fallback if typeson-registry's `filelist.revive` ever goes missing */
26
29
  : undefined;
27
30
 
28
31
  const customFileList = origFileList
@@ -34,10 +37,9 @@ const customFileList = origFileList
34
37
  * @returns {boolean}
35
38
  */
36
39
  test (x, state) {
37
- if (typeof FileList !== 'undefined') {
38
- return x instanceof FileList;
39
- }
40
- return typeof origTest === 'function' ? origTest(x, state) : false;
40
+ return typeof FileList !== 'undefined'
41
+ ? x instanceof FileList
42
+ : ((typeof origTest === 'function') && origTest(x, state));
41
43
  },
42
44
  /**
43
45
  * @param {unknown} x
@@ -48,13 +50,16 @@ const customFileList = origFileList
48
50
  if (typeof FileList !== 'undefined') {
49
51
  return Reflect.construct(FileList, [x]);
50
52
  }
53
+ /* c8 ignore next -- Defensive fallback if typeson-registry's `filelist.revive` ever goes missing */
51
54
  return typeof origRevive === 'function' ? origRevive(x, state) : undefined;
52
55
  }
53
56
  }
57
+ /* c8 ignore next -- Defensive fallback if typeson-registry's `filelist` preset entry ever goes missing */
54
58
  : undefined;
55
59
 
56
60
  let typeson = new Typeson().register([
57
61
  structuredCloningForStorage,
62
+ /* c8 ignore next -- Defensive fallback if typeson-registry's `filelist` preset entry ever goes missing */
58
63
  customFileList ? {filelist: customFileList} : {}
59
64
  ]);
60
65
 
package/src/nodeWebSQL.js CHANGED
@@ -29,6 +29,7 @@ import CFG from './CFG.js';
29
29
  * @returns {SQLiteDatabaseInstance}
30
30
  */
31
31
  function wrappedSQLiteDatabase (name) {
32
+ // eslint-disable-next-line jsdoc/ts-ban-ts-comment -- TS 6/7
32
33
  // @ts-ignore It's ok; needed under some TS versions
33
34
  const db = new SQLiteDatabase(name, {});
34
35
  if (CFG.sqlBusyTimeout) {
@@ -108,7 +108,7 @@ function setGlobalVars (idb, initialConfig) {
108
108
  setConfig(initialConfig);
109
109
  }
110
110
  const IDB = /** @type {ShimmedObject & {[key: string]: unknown}} */ (
111
- /** @type {unknown} */ (idb || globalThis || {})
111
+ /** @type {unknown} */ (idb || globalThis)
112
112
  );
113
113
  /**
114
114
  * @param {string} name
@@ -213,90 +213,98 @@ function setGlobalVars (idb, initialConfig) {
213
213
  });
214
214
  }
215
215
  const shimIDBFactory = IDBFactory;
216
- if (CFG.win.openDatabase !== undefined) {
217
- shimIndexedDB.__openDatabase = CFG.win.openDatabase.bind(CFG.win); // We cache here in case the function is overwritten later as by the IndexedDB support promises tests
218
- // Polyfill ALL of IndexedDB, using WebSQL
219
- shim('indexedDB', shimIndexedDB, {
220
- enumerable: true,
221
- configurable: true,
222
- get () {
223
- if (this !== IDB && !isNullish(this) && !this.shimNS) { // Latter is hack for test environment
224
- throw new TypeError('Illegal invocation');
225
- }
226
- return shimIndexedDB;
216
+ if (CFG.win.openDatabase === undefined) {
217
+ return;
218
+ }
219
+
220
+ shimIndexedDB.__openDatabase = CFG.win.openDatabase.bind(CFG.win); // We cache here in case the function is overwritten later as by the IndexedDB support promises tests
221
+ // Polyfill ALL of IndexedDB, using WebSQL
222
+ shim('indexedDB', shimIndexedDB, {
223
+ enumerable: true,
224
+ configurable: true,
225
+ get () {
226
+ if (this !== IDB && !isNullish(this) && !this.shimNS) { // Latter is hack for test environment
227
+ throw new TypeError('Illegal invocation');
227
228
  }
228
- });
229
- /** @type {[string, unknown][]} */
230
- ([
231
- ['IDBFactory', shimIDBFactory],
232
- ['IDBDatabase', shimIDBDatabase],
233
- ['IDBObjectStore', shimIDBObjectStore],
234
- ['IDBIndex', shimIDBIndex],
235
- ['IDBTransaction', shimIDBTransaction],
236
- ['IDBCursor', shimIDBCursor],
237
- ['IDBCursorWithValue', shimIDBCursorWithValue],
238
- ['IDBRecord', shimIDBRecord],
239
- ['IDBKeyRange', shimIDBKeyRange],
240
- ['IDBRequest', shimIDBRequest],
241
- ['IDBOpenDBRequest', shimIDBOpenDBRequest],
242
- ['IDBVersionChangeEvent', shimIDBVersionChangeEvent]
243
- ]).forEach(([prop, obj]) => {
244
- shim(prop, obj, {
245
- enumerable: false,
246
- configurable: true
247
- });
248
- });
249
- // For Node environments
250
- if (CFG.fs) {
251
- setFS(CFG.fs);
229
+ return shimIndexedDB;
252
230
  }
253
- if (CFG.fullIDLSupport) {
254
- // Slow per MDN so off by default! Though apparently needed for WebIDL: https://stackoverflow.com/questions/41927589/rationales-consequences-of-webidl-class-inheritance-requirements
231
+ });
232
+ /** @type {[string, unknown][]} */
233
+ ([
234
+ ['IDBFactory', shimIDBFactory],
235
+ ['IDBDatabase', shimIDBDatabase],
236
+ ['IDBObjectStore', shimIDBObjectStore],
237
+ ['IDBIndex', shimIDBIndex],
238
+ ['IDBTransaction', shimIDBTransaction],
239
+ ['IDBCursor', shimIDBCursor],
240
+ ['IDBCursorWithValue', shimIDBCursorWithValue],
241
+ ['IDBRecord', shimIDBRecord],
242
+ ['IDBKeyRange', shimIDBKeyRange],
243
+ ['IDBRequest', shimIDBRequest],
244
+ ['IDBOpenDBRequest', shimIDBOpenDBRequest],
245
+ ['IDBVersionChangeEvent', shimIDBVersionChangeEvent]
246
+ ]).forEach(([prop, obj]) => {
247
+ shim(prop, obj, {
248
+ enumerable: false,
249
+ configurable: true
250
+ });
251
+ });
252
+ // For Node environments
253
+ if (CFG.fs) {
254
+ setFS(CFG.fs);
255
+ }
256
+ if (CFG.fullIDLSupport) {
257
+ // Slow per MDN so off by default! Though apparently needed for WebIDL: https://stackoverflow.com/questions/41927589/rationales-consequences-of-webidl-class-inheritance-requirements
255
258
 
256
- Object.setPrototypeOf(IDB.IDBOpenDBRequest, IDB.IDBRequest);
257
- Object.setPrototypeOf(IDB.IDBCursorWithValue, IDB.IDBCursor);
259
+ Object.setPrototypeOf(IDB.IDBOpenDBRequest, IDB.IDBRequest);
260
+ Object.setPrototypeOf(IDB.IDBCursorWithValue, IDB.IDBCursor);
258
261
 
259
- Object.setPrototypeOf(shimIDBDatabase, ShimEventTarget);
260
- Object.setPrototypeOf(shimIDBRequest, ShimEventTarget);
261
- Object.setPrototypeOf(shimIDBTransaction, ShimEventTarget);
262
- Object.setPrototypeOf(shimIDBVersionChangeEvent, ShimEvent);
263
- // `ShimDOMException` is the real native `DOMException` when one
264
- // is available (see `DOMException.js`'s `useNativeDOMException`)
265
- // -- which, unlike the shim classes above, is a single,
266
- // process-wide singleton shared by reference across every
267
- // sandbox this library gets installed into (see
268
- // `node-idb-test.js`'s `sandboxObj`). A native `DOMException`
269
- // already has the correct prototype chain out of the box
270
- // (`Object.getPrototypeOf(DOMException) === Function.prototype`,
271
- // not `Error`), so forcing it here isn't just unneeded but
272
- // actively wrong -- and, because it's shared, permanently
273
- // wrong for every later use of `DOMException` in the same
274
- // process (e.g. a later WPT test file's own idlharness-style
275
- // check that `DOMException` does *not* inherit from `Error`
276
- // on the class side), not just this one shim install.
277
- if (typeof DOMException === 'undefined' || ShimDOMException !== DOMException) {
278
- Object.setPrototypeOf(ShimDOMException, Error);
279
- Object.setPrototypeOf(ShimDOMException.prototype, Error.prototype);
280
- }
262
+ Object.setPrototypeOf(shimIDBDatabase, ShimEventTarget);
263
+ Object.setPrototypeOf(shimIDBRequest, ShimEventTarget);
264
+ Object.setPrototypeOf(shimIDBTransaction, ShimEventTarget);
265
+ Object.setPrototypeOf(shimIDBVersionChangeEvent, ShimEvent);
266
+ // `ShimDOMException` is the real native `DOMException` when one
267
+ // is available (see `DOMException.js`'s `useNativeDOMException`)
268
+ // -- which, unlike the shim classes above, is a single,
269
+ // process-wide singleton shared by reference across every
270
+ // sandbox this library gets installed into (see
271
+ // `node-idb-test.js`'s `sandboxObj`). A native `DOMException`
272
+ // already has the correct prototype chain out of the box
273
+ // (`Object.getPrototypeOf(DOMException) === Function.prototype`,
274
+ // not `Error`), so forcing it here isn't just unneeded but
275
+ // actively wrong -- and, because it's shared, permanently
276
+ // wrong for every later use of `DOMException` in the same
277
+ // process (e.g. a later WPT test file's own idlharness-style
278
+ // check that `DOMException` does *not* inherit from `Error`
279
+ // on the class side), not just this one shim install.
280
+ if (typeof DOMException === 'undefined' || ShimDOMException !== DOMException) {
281
+ Object.setPrototypeOf(ShimDOMException, Error);
282
+ Object.setPrototypeOf(ShimDOMException.prototype, Error.prototype);
281
283
  }
282
- if (IDB.indexedDB && !IDB.indexedDB.toString().includes('[native code]')) {
283
- if (CFG.addNonIDBGlobals) {
284
- // As `DOMStringList` exists per IDL (and Chrome) in the global
285
- // thread (but not in workers), we prefix the name to avoid
286
- // shadowing or conflicts
287
- setNonIDBGlobals('Shim');
288
- }
289
- if (CFG.replaceNonIDBGlobals) {
290
- setNonIDBGlobals();
291
- }
284
+ }
285
+ if (IDB.indexedDB && !IDB.indexedDB.toString().includes('[native code]')) {
286
+ if (CFG.addNonIDBGlobals) {
287
+ // As `DOMStringList` exists per IDL (and Chrome) in the global
288
+ // thread (but not in workers), we prefix the name to avoid
289
+ // shadowing or conflicts
290
+ setNonIDBGlobals('Shim');
292
291
  }
293
- /* c8 ignore start -- TS guard */
294
- if (!IDB.shimIndexedDB) {
295
- return;
292
+ if (CFG.replaceNonIDBGlobals) {
293
+ setNonIDBGlobals();
296
294
  }
297
- /* c8 ignore stop -- TS guard */
298
- IDB.shimIndexedDB.__setConnectionQueueOrigin();
299
295
  }
296
+ /* c8 ignore start -- Defensive: `IDB.shimIndexedDB` was already
297
+ confirmed truthy just before this function (`__useShim`) was
298
+ defined and immediately invoked (see the `if ('shimIndexedDB'
299
+ in IDB && IDB.shimIndexedDB)` guard above), and nothing in
300
+ this function's body reassigns or deletes it. Only reachable
301
+ if `IDB` is some unusual object (e.g. a Proxy) whose
302
+ `shimIndexedDB` property value changes between reads. */
303
+ if (!IDB.shimIndexedDB) {
304
+ return;
305
+ }
306
+ /* c8 ignore stop -- see comment above */
307
+ IDB.shimIndexedDB.__setConnectionQueueOrigin();
300
308
  };
301
309
 
302
310
  IDB.shimIndexedDB.__debug = /** @type {(val: boolean) => void} */ (function (val) {
@@ -382,6 +390,7 @@ function setGlobalVars (idb, initialConfig) {
382
390
  : 4
383
391
  ) * 1024 * 1024;
384
392
  }
393
+
385
394
  if (!CFG.avoidAutoShim &&
386
395
  (!IDB.indexedDB || poorIndexedDbSupport) &&
387
396
  CFG.win.openDatabase !== undefined
package/src/util.js CHANGED
@@ -17,12 +17,11 @@ function escapeUnmatchedSurrogates (arg) {
17
17
  function (_, unmatchedHighSurrogate, precedingLow, unmatchedLowSurrogate) {
18
18
  // Could add a corresponding surrogate for compatibility with `node-sqlite3`: https://bugs.python.org/issue12569 and https://stackoverflow.com/a/6701665/271577
19
19
  // but Chrome having problems
20
- if (unmatchedHighSurrogate) {
21
- return '^2' + unmatchedHighSurrogate.codePointAt()
22
- .toString(16).padStart(4, '0');
23
- }
24
- return (precedingLow || '') + '^3' +
25
- unmatchedLowSurrogate.codePointAt().toString(16).padStart(4, '0');
20
+ return unmatchedHighSurrogate
21
+ ? '^2' + unmatchedHighSurrogate.codePointAt()
22
+ .toString(16).padStart(4, '0')
23
+ : (precedingLow || '') + '^3' +
24
+ unmatchedLowSurrogate.codePointAt().toString(16).padStart(4, '0');
26
25
  }
27
26
  );
28
27
  }