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.
- package/badges/coverage-badge.svg +1 -1
- package/badges/tests-badge.svg +1 -1
- package/dist/CFG.d.ts +1 -1
- package/dist/CFG.d.ts.map +1 -1
- package/dist/DOMException.d.ts.map +1 -1
- package/dist/IDBCursor.d.ts.map +1 -1
- package/dist/IDBDatabase.d.ts.map +1 -1
- package/dist/IDBFactory.d.ts +1 -2
- package/dist/IDBFactory.d.ts.map +1 -1
- package/dist/IDBIndex.d.ts +2 -6
- package/dist/IDBIndex.d.ts.map +1 -1
- package/dist/IDBKeyRange.d.ts.map +1 -1
- package/dist/IDBObjectStore.d.ts.map +1 -1
- package/dist/IDBRecord.d.ts.map +1 -1
- package/dist/IDBRequest.d.ts.map +1 -1
- package/dist/IDBTransaction.d.ts.map +1 -1
- package/dist/Key.d.ts.map +1 -1
- package/dist/Sca.d.ts.map +1 -1
- package/dist/indexeddbshim-Key.js +40 -28
- package/dist/indexeddbshim-Key.js.map +1 -1
- package/dist/indexeddbshim-Key.min.js +2 -2
- package/dist/indexeddbshim-Key.min.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs +511 -217
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +539 -244
- package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js +3 -3
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
- package/dist/indexeddbshim-node.cjs +511 -217
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +539 -244
- package/dist/indexeddbshim-noninvasive.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.min.js +3 -3
- package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
- package/dist/indexeddbshim.js +539 -244
- package/dist/indexeddbshim.js.map +1 -1
- package/dist/indexeddbshim.min.js +3 -3
- package/dist/indexeddbshim.min.js.map +1 -1
- package/dist/nodeWebSQL.d.ts.map +1 -1
- package/dist/setGlobalVars.d.ts +1 -1
- package/dist/setGlobalVars.d.ts.map +1 -1
- package/dist/util.d.ts.map +1 -1
- package/package.json +22 -17
- package/src/CFG.js +18 -4
- package/src/DOMException.js +6 -0
- package/src/DOMStringList.js +3 -0
- package/src/IDBCursor.js +36 -3
- package/src/IDBDatabase.js +26 -10
- package/src/IDBFactory.js +105 -5
- package/src/IDBIndex.js +49 -32
- package/src/IDBKeyRange.js +8 -7
- package/src/IDBObjectStore.js +25 -2
- package/src/IDBRecord.js +2 -0
- package/src/IDBRequest.js +7 -4
- package/src/IDBTransaction.js +97 -26
- package/src/Key.js +17 -16
- package/src/Sca.js +9 -4
- package/src/nodeWebSQL.js +1 -0
- package/src/setGlobalVars.js +86 -77
- package/src/util.js +5 -6
package/src/setGlobalVars.js
CHANGED
|
@@ -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
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
254
|
-
|
|
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
|
-
|
|
257
|
-
|
|
259
|
+
Object.setPrototypeOf(IDB.IDBOpenDBRequest, IDB.IDBRequest);
|
|
260
|
+
Object.setPrototypeOf(IDB.IDBCursorWithValue, IDB.IDBCursor);
|
|
258
261
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
|
|
294
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
.toString(16).padStart(4, '0')
|
|
23
|
-
|
|
24
|
-
|
|
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
|
}
|