indexeddbshim 19.0.5 → 19.0.6

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 (60) hide show
  1. package/badges/coverage-badge.svg +1 -1
  2. package/badges/tests-badge.svg +1 -1
  3. package/dist/CFG.d.ts +1 -1
  4. package/dist/CFG.d.ts.map +1 -1
  5. package/dist/DOMException.d.ts.map +1 -1
  6. package/dist/IDBCursor.d.ts.map +1 -1
  7. package/dist/IDBDatabase.d.ts.map +1 -1
  8. package/dist/IDBFactory.d.ts +1 -2
  9. package/dist/IDBFactory.d.ts.map +1 -1
  10. package/dist/IDBIndex.d.ts +2 -6
  11. package/dist/IDBIndex.d.ts.map +1 -1
  12. package/dist/IDBKeyRange.d.ts.map +1 -1
  13. package/dist/IDBObjectStore.d.ts.map +1 -1
  14. package/dist/IDBRecord.d.ts.map +1 -1
  15. package/dist/IDBRequest.d.ts.map +1 -1
  16. package/dist/IDBTransaction.d.ts.map +1 -1
  17. package/dist/Key.d.ts.map +1 -1
  18. package/dist/Sca.d.ts.map +1 -1
  19. package/dist/indexeddbshim-Key.js +40 -28
  20. package/dist/indexeddbshim-Key.js.map +1 -1
  21. package/dist/indexeddbshim-Key.min.js +2 -2
  22. package/dist/indexeddbshim-Key.min.js.map +1 -1
  23. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs +511 -217
  24. package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
  25. package/dist/indexeddbshim-UnicodeIdentifiers.js +539 -244
  26. package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
  27. package/dist/indexeddbshim-UnicodeIdentifiers.min.js +3 -3
  28. package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
  29. package/dist/indexeddbshim-node.cjs +511 -217
  30. package/dist/indexeddbshim-node.cjs.map +1 -1
  31. package/dist/indexeddbshim-noninvasive.js +539 -244
  32. package/dist/indexeddbshim-noninvasive.js.map +1 -1
  33. package/dist/indexeddbshim-noninvasive.min.js +3 -3
  34. package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
  35. package/dist/indexeddbshim.js +539 -244
  36. package/dist/indexeddbshim.js.map +1 -1
  37. package/dist/indexeddbshim.min.js +3 -3
  38. package/dist/indexeddbshim.min.js.map +1 -1
  39. package/dist/nodeWebSQL.d.ts.map +1 -1
  40. package/dist/setGlobalVars.d.ts +1 -1
  41. package/dist/setGlobalVars.d.ts.map +1 -1
  42. package/dist/util.d.ts.map +1 -1
  43. package/package.json +22 -17
  44. package/src/CFG.js +18 -4
  45. package/src/DOMException.js +6 -0
  46. package/src/DOMStringList.js +3 -0
  47. package/src/IDBCursor.js +36 -3
  48. package/src/IDBDatabase.js +26 -10
  49. package/src/IDBFactory.js +105 -5
  50. package/src/IDBIndex.js +49 -32
  51. package/src/IDBKeyRange.js +8 -7
  52. package/src/IDBObjectStore.js +25 -2
  53. package/src/IDBRecord.js +2 -0
  54. package/src/IDBRequest.js +7 -4
  55. package/src/IDBTransaction.js +97 -26
  56. package/src/Key.js +17 -16
  57. package/src/Sca.js +9 -4
  58. package/src/nodeWebSQL.js +1 -0
  59. package/src/setGlobalVars.js +86 -77
  60. package/src/util.js +5 -6
@@ -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
  }