indexeddbshim 17.2.2 → 17.3.1
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 +8 -5
- package/dist/CFG.d.ts +1 -1
- package/dist/CFG.d.ts.map +1 -1
- package/dist/DOMException.d.ts +21 -7
- package/dist/DOMException.d.ts.map +1 -1
- package/dist/DOMStringList.d.ts.map +1 -1
- package/dist/Event.d.ts +12 -6
- package/dist/Event.d.ts.map +1 -1
- package/dist/IDBCursor.d.ts +125 -7
- package/dist/IDBCursor.d.ts.map +1 -1
- package/dist/IDBDatabase.d.ts +17 -10
- package/dist/IDBDatabase.d.ts.map +1 -1
- package/dist/IDBFactory.d.ts +5 -0
- package/dist/IDBFactory.d.ts.map +1 -1
- package/dist/IDBIndex.d.ts +43 -13
- package/dist/IDBIndex.d.ts.map +1 -1
- package/dist/IDBKeyRange.d.ts +6 -2
- package/dist/IDBKeyRange.d.ts.map +1 -1
- package/dist/IDBObjectStore.d.ts +66 -17
- package/dist/IDBObjectStore.d.ts.map +1 -1
- package/dist/IDBRecord.d.ts +44 -0
- package/dist/IDBRecord.d.ts.map +1 -0
- package/dist/IDBRequest.d.ts +2 -2
- package/dist/IDBRequest.d.ts.map +1 -1
- package/dist/IDBTransaction.d.ts +43 -15
- package/dist/IDBTransaction.d.ts.map +1 -1
- package/dist/IDBVersionChangeEvent.d.ts +23 -12
- package/dist/IDBVersionChangeEvent.d.ts.map +1 -1
- package/dist/Key.d.ts +7 -6
- package/dist/Key.d.ts.map +1 -1
- package/dist/Sca.d.ts +15 -0
- package/dist/Sca.d.ts.map +1 -1
- package/dist/indexeddbshim-Key.js +59 -23
- 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 +3090 -1168
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +2660 -988
- package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js +4 -4
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
- package/dist/indexeddbshim-node.cjs +3090 -1168
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +2660 -988
- package/dist/indexeddbshim-noninvasive.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.min.js +4 -4
- package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
- package/dist/indexeddbshim.js +2660 -988
- package/dist/indexeddbshim.js.map +1 -1
- package/dist/indexeddbshim.min.js +4 -4
- package/dist/indexeddbshim.min.js.map +1 -1
- package/dist/node-UnicodeIdentifiers.d.ts +2 -2
- package/dist/node-UnicodeIdentifiers.d.ts.map +1 -1
- package/dist/node.d.ts +2 -2
- package/dist/node.d.ts.map +1 -1
- package/dist/nodeSQLiteDatabase.d.ts +13 -14
- package/dist/nodeSQLiteDatabase.d.ts.map +1 -1
- package/dist/nodeWebSQL.d.ts +17 -1
- package/dist/nodeWebSQL.d.ts.map +1 -1
- package/dist/setGlobalVars.d.ts +2 -2
- package/dist/setGlobalVars.d.ts.map +1 -1
- package/dist/util.d.ts +15 -0
- package/dist/util.d.ts.map +1 -1
- package/examples/IDBKeyUtils.html +0 -1
- package/package.json +27 -21
- package/src/CFG.js +2 -1
- package/src/DOMException.js +38 -12
- package/src/DOMStringList.js +21 -2
- package/src/Event.js +9 -4
- package/src/IDBCursor.js +346 -18
- package/src/IDBDatabase.js +33 -16
- package/src/IDBFactory.js +118 -56
- package/src/IDBIndex.js +78 -45
- package/src/IDBKeyRange.js +8 -2
- package/src/IDBObjectStore.js +89 -65
- package/src/IDBRecord.js +96 -0
- package/src/IDBRequest.js +7 -7
- package/src/IDBTransaction.js +335 -67
- package/src/IDBVersionChangeEvent.js +37 -30
- package/src/Key.js +36 -18
- package/src/Sca.js +22 -1
- package/src/browser-UnicodeIdentifiers.js +3 -1
- package/src/browser-noninvasive.js +3 -1
- package/src/browser.js +3 -1
- package/src/node-UnicodeIdentifiers.js +1 -1
- package/src/node.js +1 -1
- package/src/nodeSQLiteDatabase.js +67 -2
- package/src/nodeWebSQL.js +22 -2
- package/src/setGlobalVars.js +23 -7
- package/src/util.js +29 -1
- package/typings/shimIndexedDB.d.ts +1 -1
package/src/IDBFactory.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable sonarjs/no-invariant-returns -- Convenient here */
|
|
2
2
|
// eslint-disable-next-line no-restricted-imports -- Can be polyfilled
|
|
3
|
-
import path from 'path';
|
|
3
|
+
import path from 'node:path';
|
|
4
4
|
import SyncPromise from 'sync-promise-expanded';
|
|
5
5
|
|
|
6
6
|
import {createEvent} from './Event.js';
|
|
@@ -18,6 +18,18 @@ import CFG from './CFG.js';
|
|
|
18
18
|
* @typedef {number} Integer
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {import('websql-configurable/lib/websql/WebSQLTransaction.js').default} WebSQLTransaction
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {import('websql-configurable/lib/websql/WebSQLTransaction.js').SqlErrorCallback} SqlErrorCallback
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {import('websql-configurable/lib/websql/WebSQLResultSet.js').default} WebSQLResultSet
|
|
31
|
+
*/
|
|
32
|
+
|
|
21
33
|
/**
|
|
22
34
|
* @callback DatabaseDeleted
|
|
23
35
|
* @returns {void}
|
|
@@ -52,7 +64,7 @@ const hasNullOrigin = () => CFG.checkOrigin !== false && (getOrigin() === 'null'
|
|
|
52
64
|
* [key: string]: {
|
|
53
65
|
* [key: string]: {
|
|
54
66
|
* req: import('./IDBRequest.js').IDBOpenDBRequestFull,
|
|
55
|
-
* cb: (req: import('./IDBRequest.js').
|
|
67
|
+
* cb: (req: import('./IDBRequest.js').IDBOpenDBRequestFull) => void,
|
|
56
68
|
* }[]
|
|
57
69
|
* }
|
|
58
70
|
* }}
|
|
@@ -78,9 +90,13 @@ function processNextInConnectionQueue (name, origin = getOrigin()) {
|
|
|
78
90
|
queueItems.shift();
|
|
79
91
|
processNextInConnectionQueue(name, origin);
|
|
80
92
|
}
|
|
93
|
+
// Only a terminal (`success`/`error`) event advances the queue --
|
|
94
|
+
// `blocked` means this request is still pending (waiting on other
|
|
95
|
+
// connections to close), so later requests for the same database must
|
|
96
|
+
// keep waiting behind it rather than starting concurrently, per
|
|
97
|
+
// https://w3c.github.io/IndexedDB/#request-connection-queue.
|
|
81
98
|
req.addEventListener('success', removeFromQueue);
|
|
82
99
|
req.addEventListener('error', removeFromQueue);
|
|
83
|
-
req.addEventListener('blocked', removeFromQueue);
|
|
84
100
|
cb(req);
|
|
85
101
|
}
|
|
86
102
|
|
|
@@ -117,7 +133,7 @@ function triggerAnyVersionChangeAndBlockedEvents (openConnections, req, oldVersi
|
|
|
117
133
|
// auto-close if unloading
|
|
118
134
|
|
|
119
135
|
/**
|
|
120
|
-
* @param {IDBDatabase} connection
|
|
136
|
+
* @param {import('./IDBDatabase.js').IDBDatabaseFull} connection
|
|
121
137
|
* @returns {boolean|undefined}
|
|
122
138
|
*/
|
|
123
139
|
const connectionIsClosed = (connection) => connection.__closePending;
|
|
@@ -134,6 +150,7 @@ function triggerAnyVersionChangeAndBlockedEvents (openConnections, req, oldVersi
|
|
|
134
150
|
return undefined;
|
|
135
151
|
}
|
|
136
152
|
const e = /** @type {Event & IDBVersionChangeEvent} */ (
|
|
153
|
+
// @ts-ignore It's ok; needed under some TS versions
|
|
137
154
|
new IDBVersionChangeEvent('versionchange', {oldVersion, newVersion})
|
|
138
155
|
);
|
|
139
156
|
return new SyncPromise(function (resolve) {
|
|
@@ -156,6 +173,7 @@ function triggerAnyVersionChangeAndBlockedEvents (openConnections, req, oldVersi
|
|
|
156
173
|
}
|
|
157
174
|
};
|
|
158
175
|
const e = /** @type {Event & IDBVersionChangeEvent} */ (
|
|
176
|
+
// @ts-ignore It's ok; needed under some TS versions
|
|
159
177
|
new IDBVersionChangeEvent('blocked', {oldVersion, newVersion})
|
|
160
178
|
);
|
|
161
179
|
setTimeout(() => {
|
|
@@ -163,7 +181,10 @@ function triggerAnyVersionChangeAndBlockedEvents (openConnections, req, oldVersi
|
|
|
163
181
|
if (!connectionsClosed()) {
|
|
164
182
|
openConnections.forEach((connection) => {
|
|
165
183
|
if (!connectionIsClosed(connection)) {
|
|
166
|
-
|
|
184
|
+
// Several concurrently-blocked requests can each be
|
|
185
|
+
// waiting on this same connection, so append
|
|
186
|
+
// rather than overwrite -- see `IDBDatabase.close`.
|
|
187
|
+
connection.__unblocking.push(unblocking);
|
|
167
188
|
}
|
|
168
189
|
});
|
|
169
190
|
} else {
|
|
@@ -275,7 +296,7 @@ function closeCachedWebSQLConnections (name, cb) {
|
|
|
275
296
|
* @param {string} name
|
|
276
297
|
* @param {string} escapedDatabaseName
|
|
277
298
|
* @param {DatabaseDeleted} databaseDeleted
|
|
278
|
-
* @param {(tx:
|
|
299
|
+
* @param {(tx: WebSQLTransaction|Error|(Error & {code?: number}), err?: (Error & {code?: number})) => boolean} dbError
|
|
279
300
|
* @returns {void}
|
|
280
301
|
*/
|
|
281
302
|
function cleanupDatabaseResources (__openDatabase, name, escapedDatabaseName, databaseDeleted, dbError) {
|
|
@@ -311,10 +332,11 @@ function cleanupDatabaseResources (__openDatabase, name, escapedDatabaseName, da
|
|
|
311
332
|
closeCachedWebSQLConnections(name, () => {
|
|
312
333
|
fs.unlink(path.join(CFG.databaseBasePath || '', escapedDatabaseName), (err) => {
|
|
313
334
|
if (err && err.code !== 'ENOENT') { // Ignore if file is already deleted
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
335
|
+
const removalError = /** @type {Error & {code?: number}} */ (
|
|
336
|
+
new Error('Error removing database file: ' + escapedDatabaseName + ' ' + err)
|
|
337
|
+
);
|
|
338
|
+
removalError.code = 0;
|
|
339
|
+
dbError(removalError);
|
|
318
340
|
return;
|
|
319
341
|
}
|
|
320
342
|
databaseDeleted();
|
|
@@ -342,7 +364,7 @@ function cleanupDatabaseResources (__openDatabase, name, escapedDatabaseName, da
|
|
|
342
364
|
// Delete all tables in this database, maintained in the sys table
|
|
343
365
|
tx.executeSql('DROP TABLE ' + util.escapeStoreNameForSQL(
|
|
344
366
|
util.unescapeSQLiteResponse( // Avoid double-escaping
|
|
345
|
-
tables.item(i).name
|
|
367
|
+
/** @type {{name: string}} */ (tables.item(i)).name
|
|
346
368
|
)
|
|
347
369
|
), [], function () {
|
|
348
370
|
deleteTables(i + 1);
|
|
@@ -369,18 +391,18 @@ function cleanupDatabaseResources (__openDatabase, name, escapedDatabaseName, da
|
|
|
369
391
|
* Creates the sysDB to keep track of version numbers for databases.
|
|
370
392
|
* @param {OpenDatabase} __openDatabase
|
|
371
393
|
* @param {CreateSysDBSuccessCallback} success
|
|
372
|
-
* @param {(tx:
|
|
394
|
+
* @param {(tx: WebSQLTransaction|(Error & {code?: number})|Error, err?: (Error & {code?: number})) => void} failure
|
|
373
395
|
* @returns {void}
|
|
374
396
|
*/
|
|
375
397
|
function createSysDB (__openDatabase, success, failure) {
|
|
376
398
|
/**
|
|
377
399
|
*
|
|
378
|
-
* @param {boolean|
|
|
379
|
-
* @param {
|
|
400
|
+
* @param {boolean|WebSQLTransaction|(Error & {code?: number})} tx
|
|
401
|
+
* @param {(Error & {code?: number})} [err]
|
|
380
402
|
* @returns {void}
|
|
381
403
|
*/
|
|
382
404
|
function sysDbCreateError (tx, err) {
|
|
383
|
-
const er = webSQLErrback(/** @type {
|
|
405
|
+
const er = webSQLErrback(/** @type {(Error & {code?: number})} */ (err) || tx);
|
|
384
406
|
if (CFG.DEBUG) { console.log('Error in sysdb transaction - when creating dbVersions', err); }
|
|
385
407
|
failure(er);
|
|
386
408
|
}
|
|
@@ -412,9 +434,9 @@ function createSysDB (__openDatabase, success, failure) {
|
|
|
412
434
|
'CREATE INDEX IF NOT EXISTS dbvname ON dbVersions(name)',
|
|
413
435
|
[],
|
|
414
436
|
success,
|
|
415
|
-
/** @type {
|
|
437
|
+
/** @type {SqlErrorCallback} */ (sysDbCreateError)
|
|
416
438
|
);
|
|
417
|
-
}, /** @type {
|
|
439
|
+
}, /** @type {SqlErrorCallback} */ (sysDbCreateError));
|
|
418
440
|
}, sysDbCreateError);
|
|
419
441
|
}
|
|
420
442
|
}
|
|
@@ -440,7 +462,9 @@ function IDBFactory () {
|
|
|
440
462
|
* __openDatabase: OpenDatabase,
|
|
441
463
|
* __connections: {
|
|
442
464
|
* [key: string]: import('./IDBDatabase.js').IDBDatabaseFull[]
|
|
443
|
-
* }
|
|
465
|
+
* },
|
|
466
|
+
* __forceClose: (dbName: string, connIdx: Integer, msg: string) => void,
|
|
467
|
+
* __setConnectionQueueOrigin: (origin?: string) => void
|
|
444
468
|
* }} IDBFactoryFull
|
|
445
469
|
*/
|
|
446
470
|
|
|
@@ -451,8 +475,10 @@ const IDBFactoryAlias = IDBFactory;
|
|
|
451
475
|
IDBFactory.__createInstance = function () {
|
|
452
476
|
/**
|
|
453
477
|
* @class
|
|
478
|
+
* @this {IDBFactoryFull}
|
|
454
479
|
*/
|
|
455
480
|
function IDBFactory () {
|
|
481
|
+
// @ts-expect-error It's ok
|
|
456
482
|
this[Symbol.toStringTag] = 'IDBFactory';
|
|
457
483
|
this.__connections = {};
|
|
458
484
|
}
|
|
@@ -515,8 +541,8 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
515
541
|
|
|
516
542
|
/**
|
|
517
543
|
*
|
|
518
|
-
* @param {
|
|
519
|
-
* @param {
|
|
544
|
+
* @param {WebSQLTransaction|Error|(Error & {code?: number})} tx
|
|
545
|
+
* @param {(Error & {code?: number})} [err]
|
|
520
546
|
* @returns {boolean}
|
|
521
547
|
*/
|
|
522
548
|
function dbCreateError (tx, err) {
|
|
@@ -536,7 +562,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
536
562
|
|
|
537
563
|
/**
|
|
538
564
|
*
|
|
539
|
-
* @param {
|
|
565
|
+
* @param {WebSQLTransaction} tx
|
|
540
566
|
* @param {DatabaseFull} db
|
|
541
567
|
* @param {Integer} oldVersion
|
|
542
568
|
* @returns {void}
|
|
@@ -562,9 +588,9 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
562
588
|
// DB Upgrade in progress
|
|
563
589
|
/**
|
|
564
590
|
*
|
|
565
|
-
* @param {
|
|
566
|
-
* @param {boolean|
|
|
567
|
-
* @param {(tx?:
|
|
591
|
+
* @param {WebSQLTransaction} systx
|
|
592
|
+
* @param {boolean|(Error & {code?: number})|DOMException|Error} err
|
|
593
|
+
* @param {(tx?: WebSQLTransaction|(Error & {code?: number}), err?: (Error & {code?: number})|WebSQLResultSet) => boolean} cb
|
|
568
594
|
* @returns {void}
|
|
569
595
|
*/
|
|
570
596
|
let sysdbFinishedCb = function (systx, err, cb) {
|
|
@@ -622,37 +648,71 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
622
648
|
*/
|
|
623
649
|
function versionSet () {
|
|
624
650
|
const e = /** @type {import('eventtargeter').EventWithProps & Event & IDBVersionChangeEvent} */ (
|
|
651
|
+
// @ts-ignore It's ok; needed under some TS versions
|
|
625
652
|
new IDBVersionChangeEvent('upgradeneeded', {oldVersion, newVersion: version})
|
|
626
653
|
);
|
|
627
654
|
req.__result = connection;
|
|
628
655
|
connection.__upgradeTransaction = req.__transaction = req.__result.__versionTransaction = IDBTransaction.__createInstance(req.__result, req.__result.objectStoreNames, 'versionchange');
|
|
629
656
|
req.__done = true;
|
|
630
657
|
|
|
631
|
-
req.transaction.__addNonRequestToTransactionQueue(
|
|
632
|
-
|
|
658
|
+
req.transaction.__addNonRequestToTransactionQueue(
|
|
659
|
+
/**
|
|
660
|
+
* @param {import('websql-configurable/lib/websql/WebSQLTransaction.js').default} tx
|
|
661
|
+
* @param {ObjectArray} args
|
|
662
|
+
* @param {(result?: any, req?: import('./IDBRequest.js').IDBRequestFull) => void} finished
|
|
663
|
+
* @returns {void}
|
|
664
|
+
*/
|
|
665
|
+
function onupgradeneeded (tx, args, finished /* , error */) {
|
|
666
|
+
// Unlike ordinary requests, this dispatch doesn't go through
|
|
667
|
+
// `IDBTransaction`'s own `success`/`error` closures, so it must
|
|
668
|
+
// open/close the transaction's active-handler window itself.
|
|
669
|
+
req.transaction.__handlerActive = true;
|
|
670
|
+
req.dispatchEvent(e);
|
|
671
|
+
// Give any same-tick microtask scheduled from within the
|
|
672
|
+
// `upgradeneeded` handler (e.g. a plain
|
|
673
|
+
// `Promise.resolve().then(...)`) a chance to run -- and still
|
|
674
|
+
// observe the transaction as active -- before we deactivate it
|
|
675
|
+
// again, per https://github.com/w3c/IndexedDB/issues/87. Only
|
|
676
|
+
// the flag reset itself is deferred here -- unlike
|
|
677
|
+
// `IDBTransaction.js`'s `advanceAfterDispatch`, `finished()`
|
|
678
|
+
// (this transaction's own queue-advancement/completion signal)
|
|
679
|
+
// still runs synchronously, at exactly its previous timing: an
|
|
680
|
+
// earlier attempt at deferring `finished()` too raced against
|
|
681
|
+
// unrelated test setup that assumed a freshly deleted/created
|
|
682
|
+
// database's upgrade transaction had already fully completed by
|
|
683
|
+
// the time this function returns.
|
|
684
|
+
queueMicrotask(() => {
|
|
685
|
+
req.transaction.__handlerActive = false;
|
|
686
|
+
});
|
|
633
687
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
688
|
+
if (e.__legacyOutputDidListenersThrowError) {
|
|
689
|
+
logError('Error', 'An error occurred in an upgradeneeded handler attached to request chain', /** @type {Error} */ (e.__legacyOutputDidListenersThrowError)); // We do nothing else with this error as per spec
|
|
690
|
+
req.transaction.__abortTransaction(createDOMException('AbortError', 'A request was aborted.'));
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
finished();
|
|
638
694
|
}
|
|
639
|
-
|
|
640
|
-
});
|
|
695
|
+
);
|
|
641
696
|
|
|
642
697
|
// eslint-disable-next-line camelcase -- Clear API
|
|
643
|
-
req.transaction.on__beforecomplete =
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
req.
|
|
698
|
+
req.transaction.on__beforecomplete =
|
|
699
|
+
/**
|
|
700
|
+
* @param {Event & {complete: () => void}} ev
|
|
701
|
+
* @returns {void}
|
|
702
|
+
*/
|
|
703
|
+
function (ev) {
|
|
704
|
+
connection.__upgradeTransaction = null;
|
|
705
|
+
/** @type {import('./IDBDatabase.js').IDBDatabaseFull} */ (
|
|
706
|
+
req.__result
|
|
707
|
+
).__versionTransaction = null;
|
|
708
|
+
sysdbFinishedCb(systx, false, function () {
|
|
709
|
+
req.transaction.__callTransFinishedCb(false, function () {
|
|
710
|
+
ev.complete();
|
|
711
|
+
req.__transaction = null;
|
|
712
|
+
});
|
|
713
|
+
return false;
|
|
652
714
|
});
|
|
653
|
-
|
|
654
|
-
});
|
|
655
|
-
};
|
|
715
|
+
};
|
|
656
716
|
|
|
657
717
|
// eslint-disable-next-line camelcase -- Clear API
|
|
658
718
|
req.transaction.on__preabort = function () {
|
|
@@ -779,12 +839,12 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
779
839
|
if ((useMemoryDatabase || useDatabaseCache) && Object.hasOwn(websqlDBCache, name) && Object.hasOwn(websqlDBCache[name], version)) {
|
|
780
840
|
db = websqlDBCache[name][version];
|
|
781
841
|
} else {
|
|
782
|
-
db = me.__openDatabase(
|
|
842
|
+
db = /** @type {DatabaseFull} */ (me.__openDatabase(
|
|
783
843
|
useMemoryDatabase ? CFG.memoryDatabase : path.join(CFG.databaseBasePath || '', escapedDatabaseName),
|
|
784
844
|
'1',
|
|
785
845
|
name,
|
|
786
846
|
CFG.DEFAULT_DB_SIZE
|
|
787
|
-
);
|
|
847
|
+
));
|
|
788
848
|
if (useDatabaseCache) {
|
|
789
849
|
if (!(Object.hasOwn(websqlDBCache, name))) {
|
|
790
850
|
websqlDBCache[name] = {};
|
|
@@ -818,7 +878,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
818
878
|
return;
|
|
819
879
|
}
|
|
820
880
|
tx.executeSql('CREATE INDEX IF NOT EXISTS sysname ON __sys__(name)', [], setup, dbCreateError);
|
|
821
|
-
}, /** @type {
|
|
881
|
+
}, /** @type {SqlErrorCallback} */ (dbCreateError));
|
|
822
882
|
}, dbCreateError);
|
|
823
883
|
}
|
|
824
884
|
|
|
@@ -840,7 +900,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
840
900
|
// Database with this name does not exist
|
|
841
901
|
openDB(0);
|
|
842
902
|
} else {
|
|
843
|
-
openDB(data.rows.item(0).version);
|
|
903
|
+
openDB(/** @type {{version: Integer}} */ (data.rows.item(0)).version);
|
|
844
904
|
}
|
|
845
905
|
}, dbCreateError);
|
|
846
906
|
}, dbCreateError);
|
|
@@ -904,8 +964,8 @@ IDBFactory.prototype.deleteDatabase = function (name) {
|
|
|
904
964
|
// `UnknownError` as we may require upon a SQL deletion error
|
|
905
965
|
/**
|
|
906
966
|
*
|
|
907
|
-
* @param {
|
|
908
|
-
* @param {
|
|
967
|
+
* @param {WebSQLTransaction|(Error & {code?: number})|Error} tx
|
|
968
|
+
* @param {(Error & {code?: number})|boolean} [err]
|
|
909
969
|
* @returns {boolean}
|
|
910
970
|
*/
|
|
911
971
|
function dbError (tx, err) {
|
|
@@ -920,7 +980,7 @@ IDBFactory.prototype.deleteDatabase = function (name) {
|
|
|
920
980
|
// transaction, corrupting that connection's task queue (see issue with unrelated `open()` calls
|
|
921
981
|
// failing/crashing after a `deleteDatabase` file-removal error).
|
|
922
982
|
calledDBError = true;
|
|
923
|
-
const er = webSQLErrback(/** @type {
|
|
983
|
+
const er = webSQLErrback(/** @type {(Error & {code?: number})} */ (err || tx));
|
|
924
984
|
sysdbFinishedCbDelete(true, function () {
|
|
925
985
|
req.__done = true;
|
|
926
986
|
req.__error = er;
|
|
@@ -944,6 +1004,7 @@ IDBFactory.prototype.deleteDatabase = function (name) {
|
|
|
944
1004
|
req.__result = undefined;
|
|
945
1005
|
req.__done = true;
|
|
946
1006
|
const e = /** @type {Event & IDBVersionChangeEvent} */ (
|
|
1007
|
+
// @ts-ignore It's ok; needed under some TS versions
|
|
947
1008
|
new IDBVersionChangeEvent('success', {oldVersion: version, newVersion: null})
|
|
948
1009
|
);
|
|
949
1010
|
req.dispatchEvent(e);
|
|
@@ -966,7 +1027,7 @@ IDBFactory.prototype.deleteDatabase = function (name) {
|
|
|
966
1027
|
completeDatabaseDelete();
|
|
967
1028
|
return undefined;
|
|
968
1029
|
}
|
|
969
|
-
({version} = data.rows.item(0));
|
|
1030
|
+
({version} = /** @type {{version: Integer}} */ (data.rows.item(0)));
|
|
970
1031
|
|
|
971
1032
|
const openConnections = me.__connections[name] || [];
|
|
972
1033
|
triggerAnyVersionChangeAndBlockedEvents(openConnections, req, version, null).then(function () {
|
|
@@ -1050,15 +1111,15 @@ IDBFactory.prototype.databases = function () {
|
|
|
1050
1111
|
}
|
|
1051
1112
|
/**
|
|
1052
1113
|
*
|
|
1053
|
-
* @param {true|
|
|
1054
|
-
* @param {
|
|
1114
|
+
* @param {true|WebSQLTransaction|(Error & {code?: number})|DOMException|Error} tx
|
|
1115
|
+
* @param {(Error & {code?: number})|DOMException|Error} [err]
|
|
1055
1116
|
* @returns {boolean}
|
|
1056
1117
|
*/
|
|
1057
1118
|
function dbGetDatabaseNamesError (tx, err) {
|
|
1058
1119
|
if (calledDbCreateError) {
|
|
1059
1120
|
return false;
|
|
1060
1121
|
}
|
|
1061
|
-
const er = err ? webSQLErrback(/** @type {
|
|
1122
|
+
const er = err ? webSQLErrback(/** @type {(Error & {code?: number})} */ (err)) : tx;
|
|
1062
1123
|
calledDbCreateError = true;
|
|
1063
1124
|
reject(er);
|
|
1064
1125
|
return false;
|
|
@@ -1068,7 +1129,7 @@ IDBFactory.prototype.databases = function () {
|
|
|
1068
1129
|
sysReadTx.executeSql('SELECT "name", "version" FROM dbVersions', [], function (sysReadTx, data) {
|
|
1069
1130
|
const dbNames = [];
|
|
1070
1131
|
for (let i = 0; i < data.rows.length; i++) {
|
|
1071
|
-
const {name, version} = data.rows.item(i);
|
|
1132
|
+
const {name, version} = /** @type {{name: string, version: Integer}} */ (data.rows.item(i));
|
|
1072
1133
|
dbNames.push({
|
|
1073
1134
|
name: util.unescapeSQLiteResponse(name),
|
|
1074
1135
|
version
|
|
@@ -1138,6 +1199,7 @@ IDBFactory.prototype.__setConnectionQueueOrigin = function (origin = getOrigin()
|
|
|
1138
1199
|
IDBFactory.prototype[Symbol.toStringTag] = 'IDBFactoryPrototype';
|
|
1139
1200
|
|
|
1140
1201
|
/* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
|
|
1202
|
+
util.setOperationNames(IDBFactory.prototype);
|
|
1141
1203
|
Object.defineProperty(IDBFactory, 'prototype', {
|
|
1142
1204
|
writable: false
|
|
1143
1205
|
});
|