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.
- package/README.md +2 -0
- 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 +73 -33
- 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 +543 -221
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +572 -249
- 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 +543 -221
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +572 -249
- 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 +572 -249
- 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/licenseInfo.json +8 -0
- package/package.json +106 -102
- 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 +53 -22
- 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/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
|
-
|
|
38
|
-
|
|
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) {
|
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
|
}
|