indexeddbshim 16.0.0 → 17.0.0
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 +4 -4
- package/badges/licenses-badge-dev.svg +1 -1
- package/badges/licenses-badge.svg +1 -1
- package/dist/CFG.d.ts.map +1 -1
- package/dist/DOMException.d.ts.map +1 -1
- package/dist/DOMStringList.d.ts.map +1 -1
- package/dist/IDBCursor.d.ts +5 -2
- package/dist/IDBCursor.d.ts.map +1 -1
- package/dist/IDBDatabase.d.ts +2 -1
- package/dist/IDBDatabase.d.ts.map +1 -1
- package/dist/IDBFactory.d.ts +2 -1
- package/dist/IDBFactory.d.ts.map +1 -1
- package/dist/IDBIndex.d.ts +2 -1
- package/dist/IDBIndex.d.ts.map +1 -1
- package/dist/IDBKeyRange.d.ts +1 -1
- package/dist/IDBKeyRange.d.ts.map +1 -1
- package/dist/IDBObjectStore.d.ts +2 -1
- package/dist/IDBObjectStore.d.ts.map +1 -1
- package/dist/IDBRequest.d.ts +5 -3
- package/dist/IDBRequest.d.ts.map +1 -1
- package/dist/IDBTransaction.d.ts +2 -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/UnicodeIdentifiers.d.ts.map +1 -1
- package/dist/browser-noninvasive.d.ts.map +1 -1
- package/dist/indexeddbshim-Key.js +32 -27
- 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 +984 -1092
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +1220 -1233
- package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js +8 -3
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
- package/dist/indexeddbshim-node.cjs +984 -1092
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +1219 -1232
- package/dist/indexeddbshim-noninvasive.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.min.js +8 -3
- package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
- package/dist/indexeddbshim.js +1219 -1232
- package/dist/indexeddbshim.js.map +1 -1
- package/dist/indexeddbshim.min.js +8 -3
- 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/setGlobalVars.d.ts.map +1 -1
- package/dist/util.d.ts.map +1 -1
- package/package.json +112 -105
- package/src/CFG.js +2 -3
- package/src/DOMException.js +11 -9
- package/src/DOMStringList.js +8 -3
- package/src/Event.js +2 -0
- package/src/IDBCursor.js +22 -11
- package/src/IDBDatabase.js +9 -6
- package/src/IDBFactory.js +21 -15
- package/src/IDBIndex.js +82 -77
- package/src/IDBKeyRange.js +42 -35
- package/src/IDBObjectStore.js +83 -77
- package/src/IDBRequest.js +28 -15
- package/src/IDBTransaction.js +8 -4
- package/src/IDBVersionChangeEvent.js +2 -0
- package/src/Key.js +22 -12
- package/src/Sca.js +2 -1
- package/src/UnicodeIdentifiers.js +2 -2
- package/src/browser-UnicodeIdentifiers.js +1 -2
- package/src/browser-noninvasive.js +0 -1
- package/src/browser.js +0 -1
- package/src/node-UnicodeIdentifiers.js +1 -1
- package/src/node.js +1 -1
- package/src/setGlobalVars.js +13 -15
- package/src/unicode-regex.js +1 -1
- package/src/util.js +13 -12
package/src/IDBDatabase.js
CHANGED
|
@@ -23,8 +23,9 @@ const readonlyProperties = ['name', 'version', 'objectStoreNames'];
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* IDB Database Object.
|
|
26
|
-
* @see
|
|
26
|
+
* @see https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#database-interface
|
|
27
27
|
* @class
|
|
28
|
+
* @throws {TypeError}
|
|
28
29
|
*/
|
|
29
30
|
function IDBDatabase () {
|
|
30
31
|
this.__versionTransaction = null;
|
|
@@ -165,7 +166,7 @@ IDBDatabase.prototype.createObjectStore = function (storeName /* , createOptions
|
|
|
165
166
|
throw createDOMException('SyntaxError', 'The keyPath argument contains an invalid key path.');
|
|
166
167
|
}
|
|
167
168
|
|
|
168
|
-
if (this.__objectStores
|
|
169
|
+
if (Object.hasOwn(this.__objectStores, storeName) && !this.__objectStores[storeName].__pendingDelete) {
|
|
169
170
|
throw createDOMException('ConstraintError', 'Object store "' + storeName + '" already exists in ' + this.name);
|
|
170
171
|
}
|
|
171
172
|
|
|
@@ -244,7 +245,8 @@ IDBDatabase.prototype.transaction = function (storeNames /* , mode */) {
|
|
|
244
245
|
// Creating new array also ensures sequence is passed by value: https://heycam.github.io/webidl/#idl-sequence
|
|
245
246
|
? [...new Set( // to be unique
|
|
246
247
|
util.convertToSequenceDOMString(storeNames) // iterables have `ToString` applied (and we convert to array for convenience)
|
|
247
|
-
|
|
248
|
+
// eslint-disable-next-line unicorn/require-array-sort-compare -- IndexedDB requires code unit comparison (default behavior)
|
|
249
|
+
)].toSorted() // must be sorted
|
|
248
250
|
: [util.convertToDOMString(storeNames)];
|
|
249
251
|
|
|
250
252
|
/* (function () {
|
|
@@ -258,7 +260,7 @@ IDBDatabase.prototype.transaction = function (storeNames /* , mode */) {
|
|
|
258
260
|
// prioritizing readonly but not starving readwrite).
|
|
259
261
|
// Even for readonly transactions, due to [issue 17](https://github.com/nolanlawson/node-websql/issues/17),
|
|
260
262
|
// we're not currently actually running the SQL requests in parallel.
|
|
261
|
-
mode
|
|
263
|
+
mode ||= 'readonly';
|
|
262
264
|
|
|
263
265
|
IDBTransaction.__assertNotVersionChange(this.__versionTransaction);
|
|
264
266
|
if (this.__closePending) {
|
|
@@ -321,7 +323,7 @@ IDBDatabase.prototype.__forceClose = function (msg) {
|
|
|
321
323
|
const evt = createEvent('close');
|
|
322
324
|
setTimeout(() => {
|
|
323
325
|
me.dispatchEvent(evt);
|
|
324
|
-
});
|
|
326
|
+
}, 0);
|
|
325
327
|
}
|
|
326
328
|
};
|
|
327
329
|
trans.__abortTransaction(createDOMException(
|
|
@@ -331,7 +333,7 @@ IDBDatabase.prototype.__forceClose = function (msg) {
|
|
|
331
333
|
});
|
|
332
334
|
me.__transactions = [];
|
|
333
335
|
};
|
|
334
|
-
|
|
336
|
+
/* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
|
|
335
337
|
util.defineOuterInterface(IDBDatabase.prototype, listeners);
|
|
336
338
|
util.defineReadonlyOuterInterface(IDBDatabase.prototype, readonlyProperties);
|
|
337
339
|
|
|
@@ -345,5 +347,6 @@ Object.defineProperty(IDBDatabase.prototype, 'constructor', {
|
|
|
345
347
|
Object.defineProperty(IDBDatabase, 'prototype', {
|
|
346
348
|
writable: false
|
|
347
349
|
});
|
|
350
|
+
/* eslint-enable unicorn/no-top-level-side-effects -- Would be good */
|
|
348
351
|
|
|
349
352
|
export default IDBDatabase;
|
package/src/IDBFactory.js
CHANGED
|
@@ -31,6 +31,7 @@ let fs;
|
|
|
31
31
|
* @returns {void}
|
|
32
32
|
*/
|
|
33
33
|
const setFS = (_fs) => {
|
|
34
|
+
// eslint-disable-next-line unicorn/no-top-level-assignment-in-function -- Necessary?
|
|
34
35
|
fs = _fs;
|
|
35
36
|
};
|
|
36
37
|
|
|
@@ -38,7 +39,6 @@ const setFS = (_fs) => {
|
|
|
38
39
|
* @returns {string}
|
|
39
40
|
*/
|
|
40
41
|
const getOrigin = () => {
|
|
41
|
-
// eslint-disable-next-line no-undef -- If browser/polyfilled
|
|
42
42
|
return (typeof location !== 'object' || !location) ? 'null' : location.origin;
|
|
43
43
|
};
|
|
44
44
|
const hasNullOrigin = () => CFG.checkOrigin !== false && (getOrigin() === 'null');
|
|
@@ -94,7 +94,7 @@ function processNextInConnectionQueue (name, origin = getOrigin()) {
|
|
|
94
94
|
*/
|
|
95
95
|
function addRequestToConnectionQueue (req, name, origin = getOrigin(), cb) {
|
|
96
96
|
/* eslint-enable default-param-last -- Keep cb at end */
|
|
97
|
-
if (!connectionQueue[origin]
|
|
97
|
+
if (!Object.hasOwn(connectionQueue[origin], name)) {
|
|
98
98
|
connectionQueue[origin][name] = [];
|
|
99
99
|
}
|
|
100
100
|
connectionQueue[origin][name].push({req, cb});
|
|
@@ -140,7 +140,7 @@ function triggerAnyVersionChangeAndBlockedEvents (openConnections, req, oldVersi
|
|
|
140
140
|
setTimeout(() => {
|
|
141
141
|
entry.dispatchEvent(e); // No need to catch errors
|
|
142
142
|
resolve(undefined);
|
|
143
|
-
});
|
|
143
|
+
}, 0);
|
|
144
144
|
});
|
|
145
145
|
});
|
|
146
146
|
}, SyncPromise.resolve(undefined)).then(function () {
|
|
@@ -169,7 +169,7 @@ function triggerAnyVersionChangeAndBlockedEvents (openConnections, req, oldVersi
|
|
|
169
169
|
} else {
|
|
170
170
|
resolve(undefined);
|
|
171
171
|
}
|
|
172
|
-
});
|
|
172
|
+
}, 0);
|
|
173
173
|
});
|
|
174
174
|
});
|
|
175
175
|
}
|
|
@@ -230,7 +230,7 @@ function getLatestCachedWebSQLDB (name) {
|
|
|
230
230
|
function cleanupDatabaseResources (__openDatabase, name, escapedDatabaseName, databaseDeleted, dbError) {
|
|
231
231
|
const useMemoryDatabase = typeof CFG.memoryDatabase === 'string';
|
|
232
232
|
if (useMemoryDatabase) {
|
|
233
|
-
const latestSQLiteDBCached = websqlDBCache
|
|
233
|
+
const latestSQLiteDBCached = Object.hasOwn(websqlDBCache, name) ? getLatestCachedWebSQLDB(name) : null;
|
|
234
234
|
if (!latestSQLiteDBCached) {
|
|
235
235
|
console.warn('Could not find a memory database instance to delete.');
|
|
236
236
|
databaseDeleted();
|
|
@@ -335,6 +335,7 @@ function createSysDB (__openDatabase, success, failure) {
|
|
|
335
335
|
if (sysdb) {
|
|
336
336
|
success();
|
|
337
337
|
} else {
|
|
338
|
+
// eslint-disable-next-line unicorn/no-top-level-assignment-in-function -- Necessary?
|
|
338
339
|
sysdb = __openDatabase(
|
|
339
340
|
typeof CFG.memoryDatabase === 'string'
|
|
340
341
|
? CFG.memoryDatabase
|
|
@@ -368,6 +369,7 @@ function createSysDB (__openDatabase, success, failure) {
|
|
|
368
369
|
/**
|
|
369
370
|
* IDBFactory Class.
|
|
370
371
|
* @see https://w3c.github.io/IndexedDB/#idl-def-IDBFactory
|
|
372
|
+
* @throws {TypeError}
|
|
371
373
|
* @class
|
|
372
374
|
*/
|
|
373
375
|
function IDBFactory () {
|
|
@@ -439,6 +441,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
439
441
|
let calledDbCreateError = false;
|
|
440
442
|
|
|
441
443
|
if (CFG.autoName && name === '') {
|
|
444
|
+
// eslint-disable-next-line unicorn/no-top-level-assignment-in-function -- Necessary?
|
|
442
445
|
name = 'autoNamedDatabase_' + nameCounter++;
|
|
443
446
|
}
|
|
444
447
|
name = String(name); // cast to a string
|
|
@@ -495,7 +498,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
495
498
|
req.__done = true;
|
|
496
499
|
}
|
|
497
500
|
const connection = IDBDatabase.__createInstance(db, name, oldVersion, version, data);
|
|
498
|
-
if (!me.__connections
|
|
501
|
+
if (!Object.hasOwn(me.__connections, name)) {
|
|
499
502
|
me.__connections[name] = [];
|
|
500
503
|
}
|
|
501
504
|
me.__connections[name].push(connection);
|
|
@@ -603,7 +606,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
603
606
|
connection.__upgradeTransaction = null;
|
|
604
607
|
// We ensure any cache is deleted before any request error events fire and try to reopen
|
|
605
608
|
if (useDatabaseCache) {
|
|
606
|
-
if (name
|
|
609
|
+
if (Object.hasOwn(websqlDBCache, name)) {
|
|
607
610
|
delete websqlDBCache[name][version];
|
|
608
611
|
}
|
|
609
612
|
}
|
|
@@ -634,7 +637,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
634
637
|
dbCreateError(err);
|
|
635
638
|
return false;
|
|
636
639
|
});
|
|
637
|
-
});
|
|
640
|
+
}, 0);
|
|
638
641
|
};
|
|
639
642
|
|
|
640
643
|
// eslint-disable-next-line camelcase -- Clear API
|
|
@@ -713,7 +716,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
713
716
|
function openDB (oldVersion) {
|
|
714
717
|
/** @type {DatabaseFull} */
|
|
715
718
|
let db;
|
|
716
|
-
if ((useMemoryDatabase || useDatabaseCache) && name
|
|
719
|
+
if ((useMemoryDatabase || useDatabaseCache) && Object.hasOwn(websqlDBCache, name) && Object.hasOwn(websqlDBCache[name], version)) {
|
|
717
720
|
db = websqlDBCache[name][version];
|
|
718
721
|
} else {
|
|
719
722
|
db = me.__openDatabase(
|
|
@@ -723,7 +726,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
723
726
|
CFG.DEFAULT_DB_SIZE
|
|
724
727
|
);
|
|
725
728
|
if (useDatabaseCache) {
|
|
726
|
-
if (!(name
|
|
729
|
+
if (!(Object.hasOwn(websqlDBCache, name))) {
|
|
727
730
|
websqlDBCache[name] = {};
|
|
728
731
|
}
|
|
729
732
|
websqlDBCache[name][version] = db;
|
|
@@ -738,7 +741,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
738
741
|
if (useDatabaseCache) {
|
|
739
742
|
setTimeout(() => {
|
|
740
743
|
dbCreateError(err);
|
|
741
|
-
});
|
|
744
|
+
}, 0);
|
|
742
745
|
} else {
|
|
743
746
|
dbCreateError(err);
|
|
744
747
|
}
|
|
@@ -765,7 +768,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
765
768
|
addRequestToConnectionQueue(req, name, /* origin */ undefined, function () {
|
|
766
769
|
let latestCachedVersion;
|
|
767
770
|
if (useDatabaseCache) {
|
|
768
|
-
if (!(name
|
|
771
|
+
if (!Object.hasOwn(websqlDBCache, name)) {
|
|
769
772
|
websqlDBCache[name] = {};
|
|
770
773
|
}
|
|
771
774
|
latestCachedVersion = getLatestCachedWebSQLVersion(name);
|
|
@@ -885,7 +888,7 @@ IDBFactory.prototype.deleteDatabase = function (name) {
|
|
|
885
888
|
/** @type {DatabaseDeleted} */
|
|
886
889
|
function databaseDeleted () {
|
|
887
890
|
sysdbFinishedCbDelete(false, function () {
|
|
888
|
-
if (useDatabaseCache && name
|
|
891
|
+
if (useDatabaseCache && Object.hasOwn(websqlDBCache, name)) {
|
|
889
892
|
delete websqlDBCache[name]; // New calls will treat as though never existed
|
|
890
893
|
}
|
|
891
894
|
delete me.__connections[name];
|
|
@@ -1018,7 +1021,7 @@ IDBFactory.prototype.databases = function () {
|
|
|
1018
1021
|
* @todo forceClose: Test
|
|
1019
1022
|
* This is provided to facilitate unit-testing of the
|
|
1020
1023
|
* closing of a database connection with a forced flag:
|
|
1021
|
-
* <
|
|
1024
|
+
* <https://w3c.github.io/IndexedDB/#steps-for-closing-a-database-connection>
|
|
1022
1025
|
* @param {string} dbName
|
|
1023
1026
|
* @param {Integer} connIdx
|
|
1024
1027
|
* @param {string} msg
|
|
@@ -1042,12 +1045,13 @@ IDBFactory.prototype.__forceClose = function (dbName, connIdx, msg) {
|
|
|
1042
1045
|
forceClose(connection);
|
|
1043
1046
|
});
|
|
1044
1047
|
});
|
|
1045
|
-
} else if (!me.__connections
|
|
1048
|
+
} else if (!Object.hasOwn(me.__connections, dbName)) {
|
|
1046
1049
|
console.log('No database connections with that name to force close');
|
|
1047
1050
|
} else if (util.isNullish(connIdx)) {
|
|
1048
1051
|
me.__connections[dbName].forEach((conn) => {
|
|
1049
1052
|
forceClose(conn);
|
|
1050
1053
|
});
|
|
1054
|
+
// eslint-disable-next-line unicorn/prefer-number-is-safe-integer -- Ok
|
|
1051
1055
|
} else if (!Number.isInteger(connIdx) || connIdx < 0 || connIdx > me.__connections[dbName].length - 1) {
|
|
1052
1056
|
throw new TypeError(
|
|
1053
1057
|
'If providing an argument, __forceClose must be called with a ' +
|
|
@@ -1069,9 +1073,11 @@ IDBFactory.prototype.__setConnectionQueueOrigin = function (origin = getOrigin()
|
|
|
1069
1073
|
|
|
1070
1074
|
IDBFactory.prototype[Symbol.toStringTag] = 'IDBFactoryPrototype';
|
|
1071
1075
|
|
|
1076
|
+
/* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
|
|
1072
1077
|
Object.defineProperty(IDBFactory, 'prototype', {
|
|
1073
1078
|
writable: false
|
|
1074
1079
|
});
|
|
1080
|
+
/* eslint-enable unicorn/no-top-level-side-effects -- Would be good */
|
|
1075
1081
|
|
|
1076
1082
|
const shimIndexedDB = IDBFactory.__createInstance();
|
|
1077
1083
|
export {IDBFactory, cmp, shimIndexedDB, setFS};
|
package/src/IDBIndex.js
CHANGED
|
@@ -31,7 +31,8 @@ const readonlyProperties = ['objectStore', 'keyPath', 'multiEntry', 'unique'];
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* IDB Index.
|
|
34
|
-
* @see
|
|
34
|
+
* @see https://www.w3.org/TR/IndexedDB/#idl-def-IDBIndex
|
|
35
|
+
* @throws {TypeError}
|
|
35
36
|
* @class
|
|
36
37
|
*/
|
|
37
38
|
function IDBIndex () {
|
|
@@ -85,83 +86,85 @@ IDBIndex.__createInstance = function (store, indexProperties) {
|
|
|
85
86
|
me.__unique = Boolean(optionalParams && optionalParams.unique);
|
|
86
87
|
me.__deleted = Boolean(indexProperties.__deleted);
|
|
87
88
|
me.__objectStore.__cursors = indexProperties.cursors || [];
|
|
88
|
-
Object.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
Object.defineProperty(me, 'name', {
|
|
100
|
-
enumerable: false,
|
|
101
|
-
configurable: false,
|
|
102
|
-
/**
|
|
103
|
-
* @this {IDBIndexFull}
|
|
104
|
-
* @returns {string}
|
|
105
|
-
*/
|
|
106
|
-
get () {
|
|
107
|
-
return this.__name;
|
|
108
|
-
},
|
|
109
|
-
/**
|
|
110
|
-
* @param {string} newName
|
|
111
|
-
* @this {IDBIndexFull}
|
|
112
|
-
* @returns {void}
|
|
113
|
-
*/
|
|
114
|
-
set (newName) {
|
|
115
|
-
const me = this;
|
|
116
|
-
newName = util.convertToDOMString(newName);
|
|
117
|
-
const oldName = me.name;
|
|
118
|
-
IDBTransaction.__assertVersionChange(me.objectStore.transaction);
|
|
119
|
-
IDBTransaction.__assertActive(me.objectStore.transaction);
|
|
120
|
-
IDBIndexAlias.__invalidStateIfDeleted(me);
|
|
121
|
-
IDBObjectStore.__invalidStateIfDeleted(me);
|
|
122
|
-
if (newName === oldName) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (me.objectStore.__indexes[newName] && !me.objectStore.__indexes[newName].__deleted &&
|
|
127
|
-
!me.objectStore.__indexes[newName].__pendingDelete) {
|
|
128
|
-
throw createDOMException('ConstraintError', 'Index "' + newName + '" already exists on ' + me.objectStore.__currentName);
|
|
89
|
+
Object.defineProperties(me, {
|
|
90
|
+
__currentName: {
|
|
91
|
+
/**
|
|
92
|
+
* @this {IDBIndexFull}
|
|
93
|
+
* @returns {string}
|
|
94
|
+
*/
|
|
95
|
+
get () {
|
|
96
|
+
return '__pendingName' in me
|
|
97
|
+
? /** @type {string} */ (me.__pendingName)
|
|
98
|
+
: me.name;
|
|
129
99
|
}
|
|
100
|
+
},
|
|
101
|
+
name: {
|
|
102
|
+
enumerable: false,
|
|
103
|
+
configurable: false,
|
|
104
|
+
/**
|
|
105
|
+
* @this {IDBIndexFull}
|
|
106
|
+
* @returns {string}
|
|
107
|
+
*/
|
|
108
|
+
get () {
|
|
109
|
+
return this.__name;
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* @param {string} newName
|
|
113
|
+
* @this {IDBIndexFull}
|
|
114
|
+
* @returns {void}
|
|
115
|
+
*/
|
|
116
|
+
set (newName) {
|
|
117
|
+
const me = this;
|
|
118
|
+
newName = util.convertToDOMString(newName);
|
|
119
|
+
const oldName = me.name;
|
|
120
|
+
IDBTransaction.__assertVersionChange(me.objectStore.transaction);
|
|
121
|
+
IDBTransaction.__assertActive(me.objectStore.transaction);
|
|
122
|
+
IDBIndexAlias.__invalidStateIfDeleted(me);
|
|
123
|
+
IDBObjectStore.__invalidStateIfDeleted(me);
|
|
124
|
+
if (newName === oldName) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
130
127
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
delete objectStore.__indexes[oldName];
|
|
135
|
-
objectStore.__indexes[newName] = me;
|
|
136
|
-
objectStore.indexNames.splice(objectStore.indexNames.indexOf(oldName), 1, newName);
|
|
137
|
-
|
|
138
|
-
const storeHandle = /** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
139
|
-
objectStore.transaction
|
|
140
|
-
).__storeHandles[objectStore.name];
|
|
141
|
-
const oldIndexHandle = storeHandle.__indexHandles[oldName];
|
|
142
|
-
oldIndexHandle.__name = newName; // Fix old references
|
|
143
|
-
storeHandle.__indexHandles[newName] = oldIndexHandle; // Ensure new reference accessible
|
|
144
|
-
me.__pendingName = oldName;
|
|
145
|
-
|
|
146
|
-
const colInfoToPreserveArr = [
|
|
147
|
-
['key', 'BLOB ' + (objectStore.autoIncrement ? 'UNIQUE, inc INTEGER PRIMARY KEY AUTOINCREMENT' : 'PRIMARY KEY')],
|
|
148
|
-
['value', 'BLOB']
|
|
149
|
-
].concat(
|
|
150
|
-
// @ts-expect-error Has numeric indexes instead of iterator
|
|
151
|
-
[...objectStore.indexNames]
|
|
152
|
-
.filter((indexName) => indexName !== newName)
|
|
153
|
-
.map((indexName) => [util.escapeIndexNameForSQL(indexName), 'BLOB'])
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
me.__renameIndex(
|
|
157
|
-
objectStore, oldName, newName, colInfoToPreserveArr,
|
|
158
|
-
function (tx, success) {
|
|
159
|
-
IDBIndexAlias.__updateIndexList(store, tx, function (store) {
|
|
160
|
-
delete storeHandle.__pendingName;
|
|
161
|
-
success(store);
|
|
162
|
-
});
|
|
128
|
+
if (Object.hasOwn(me.objectStore.__indexes, newName) && !me.objectStore.__indexes[newName].__deleted &&
|
|
129
|
+
!me.objectStore.__indexes[newName].__pendingDelete) {
|
|
130
|
+
throw createDOMException('ConstraintError', 'Index "' + newName + '" already exists on ' + me.objectStore.__currentName);
|
|
163
131
|
}
|
|
164
|
-
|
|
132
|
+
|
|
133
|
+
me.__name = newName;
|
|
134
|
+
|
|
135
|
+
const {objectStore} = me;
|
|
136
|
+
delete objectStore.__indexes[oldName];
|
|
137
|
+
objectStore.__indexes[newName] = me;
|
|
138
|
+
objectStore.indexNames.splice(objectStore.indexNames.indexOf(oldName), 1, newName);
|
|
139
|
+
|
|
140
|
+
const storeHandle = /** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
141
|
+
objectStore.transaction
|
|
142
|
+
).__storeHandles[objectStore.name];
|
|
143
|
+
const oldIndexHandle = storeHandle.__indexHandles[oldName];
|
|
144
|
+
oldIndexHandle.__name = newName; // Fix old references
|
|
145
|
+
storeHandle.__indexHandles[newName] = oldIndexHandle; // Ensure new reference accessible
|
|
146
|
+
me.__pendingName = oldName;
|
|
147
|
+
|
|
148
|
+
const colInfoToPreserveArr = [
|
|
149
|
+
['key', 'BLOB ' + (objectStore.autoIncrement ? 'UNIQUE, inc INTEGER PRIMARY KEY AUTOINCREMENT' : 'PRIMARY KEY')],
|
|
150
|
+
['value', 'BLOB']
|
|
151
|
+
].concat(
|
|
152
|
+
// @ts-expect-error Has numeric indexes instead of iterator
|
|
153
|
+
[...objectStore.indexNames]
|
|
154
|
+
.filter((indexName) => indexName !== newName)
|
|
155
|
+
.map((indexName) => [util.escapeIndexNameForSQL(indexName), 'BLOB'])
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
me.__renameIndex(
|
|
159
|
+
objectStore, oldName, newName, colInfoToPreserveArr,
|
|
160
|
+
function (tx, success) {
|
|
161
|
+
IDBIndexAlias.__updateIndexList(store, tx, function (store) {
|
|
162
|
+
delete storeHandle.__pendingName;
|
|
163
|
+
success(store);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
}
|
|
165
168
|
}
|
|
166
169
|
});
|
|
167
170
|
}
|
|
@@ -288,7 +291,7 @@ IDBIndex.__createIndex = function (store, index) {
|
|
|
288
291
|
Key.encode(indexKey.value, index.multiEntry)
|
|
289
292
|
);
|
|
290
293
|
if (index.unique) {
|
|
291
|
-
if (indexValues
|
|
294
|
+
if (Object.hasOwn(indexValues, indexKeyStr)) {
|
|
292
295
|
indexValues = {};
|
|
293
296
|
failure(createDOMException(
|
|
294
297
|
'ConstraintError',
|
|
@@ -634,7 +637,7 @@ IDBIndex.prototype.__renameIndex = function (store, oldName, newName, colInfoToP
|
|
|
634
637
|
const listColInfoToPreserve = (colInfoToPreserve.length ? (colInfoToPreserve.join(', ') + ', ') : '');
|
|
635
638
|
const listColsToPreserve = (colNamesToPreserve.length ? (colNamesToPreserve.join(', ') + ', ') : '');
|
|
636
639
|
|
|
637
|
-
// We could adapt the approach at
|
|
640
|
+
// We could adapt the approach at https://stackoverflow.com/a/8430746/271577
|
|
638
641
|
// to make the approach reusable without passing column names, but it is a bit fragile
|
|
639
642
|
/** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
640
643
|
store.transaction
|
|
@@ -749,6 +752,7 @@ IDBIndex.prototype.__renameIndex = function (store, oldName, newName, colInfoToP
|
|
|
749
752
|
* @typedef {any} AnyValue
|
|
750
753
|
*/
|
|
751
754
|
|
|
755
|
+
/* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
|
|
752
756
|
Object.defineProperty(IDBIndex, Symbol.hasInstance, {
|
|
753
757
|
/**
|
|
754
758
|
* @param {AnyValue} obj
|
|
@@ -769,6 +773,7 @@ IDBIndex.prototype[Symbol.toStringTag] = 'IDBIndexPrototype';
|
|
|
769
773
|
Object.defineProperty(IDBIndex, 'prototype', {
|
|
770
774
|
writable: false
|
|
771
775
|
});
|
|
776
|
+
/* eslint-enable unicorn/no-top-level-side-effects -- Would be good */
|
|
772
777
|
|
|
773
778
|
/**
|
|
774
779
|
* @param {number|null} count
|
package/src/IDBKeyRange.js
CHANGED
|
@@ -14,7 +14,7 @@ const readonlyProperties = /** @type {const} */ (['lower', 'upper', 'lowerOpen',
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The IndexedDB KeyRange object.
|
|
17
|
-
* @see
|
|
17
|
+
* @see https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#dfn-key-range
|
|
18
18
|
* @throws {TypeError}
|
|
19
19
|
* @class
|
|
20
20
|
*/
|
|
@@ -35,6 +35,7 @@ const IDBKeyRangeAlias = IDBKeyRange;
|
|
|
35
35
|
IDBKeyRange.__createInstance = function (lower, upper, lowerOpen, upperOpen) {
|
|
36
36
|
/**
|
|
37
37
|
* @class
|
|
38
|
+
* @throws {DOMException|Error}
|
|
38
39
|
*/
|
|
39
40
|
function IDBKeyRange () {
|
|
40
41
|
this[Symbol.toStringTag] = 'IDBKeyRange';
|
|
@@ -136,6 +137,7 @@ IDBKeyRange.bound = function (lower, upper /* , lowerOpen, upperOpen */) {
|
|
|
136
137
|
};
|
|
137
138
|
IDBKeyRange.prototype[Symbol.toStringTag] = 'IDBKeyRangePrototype';
|
|
138
139
|
|
|
140
|
+
/* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
|
|
139
141
|
readonlyProperties.forEach((prop) => {
|
|
140
142
|
Object.defineProperty(IDBKeyRange.prototype, '__' + prop, {
|
|
141
143
|
enumerable: false,
|
|
@@ -163,19 +165,22 @@ readonlyProperties.forEach((prop) => {
|
|
|
163
165
|
Object.defineProperty(IDBKeyRange.prototype, prop, desc);
|
|
164
166
|
});
|
|
165
167
|
|
|
166
|
-
Object.
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
168
|
+
Object.defineProperties(IDBKeyRange, {
|
|
169
|
+
[Symbol.hasInstance]: {
|
|
170
|
+
value:
|
|
171
|
+
/**
|
|
172
|
+
* @param {object} obj
|
|
173
|
+
* @returns {boolean}
|
|
174
|
+
*/
|
|
175
|
+
(obj) => util.isObj(obj) && 'upper' in obj && 'lowerOpen' in obj &&
|
|
176
|
+
typeof obj.lowerOpen === 'boolean'
|
|
177
|
+
},
|
|
178
|
+
prototype: {
|
|
179
|
+
writable: false
|
|
180
|
+
}
|
|
174
181
|
});
|
|
175
182
|
|
|
176
|
-
|
|
177
|
-
writable: false
|
|
178
|
-
});
|
|
183
|
+
/* eslint-enable unicorn/no-top-level-side-effects -- Would be good */
|
|
179
184
|
|
|
180
185
|
/**
|
|
181
186
|
* @param {IDBKeyRangeFull|undefined} range
|
|
@@ -189,30 +194,32 @@ Object.defineProperty(IDBKeyRange, 'prototype', {
|
|
|
189
194
|
function setSQLForKeyRange (
|
|
190
195
|
range, quotedKeyColumnName, sql, sqlValues, addAnd, checkCached
|
|
191
196
|
) {
|
|
192
|
-
if (range && (range.lower !== undefined || range.upper !== undefined)) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
sql.push(quotedKeyColumnName,
|
|
210
|
-
|
|
211
|
-
if (hasLower && hasUpper) { sql.push('AND'); }
|
|
212
|
-
if (hasUpper) {
|
|
213
|
-
sql.push(quotedKeyColumnName, (range.upperOpen ? '<' : '<='), '?');
|
|
214
|
-
sqlValues.push(util.escapeSQLiteStatement(/** @type {string} */ (encodedUpperKey)));
|
|
197
|
+
if (!(range && (range.lower !== undefined || range.upper !== undefined))) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (addAnd) { sql.push('AND'); }
|
|
202
|
+
let encodedLowerKey, encodedUpperKey;
|
|
203
|
+
const hasLower = range.lower !== undefined;
|
|
204
|
+
const hasUpper = range.upper !== undefined;
|
|
205
|
+
if (hasLower) {
|
|
206
|
+
encodedLowerKey = checkCached ? range.__lowerCached : Key.encode(range.lower);
|
|
207
|
+
}
|
|
208
|
+
if (hasUpper) {
|
|
209
|
+
encodedUpperKey = checkCached ? range.__upperCached : Key.encode(range.upper);
|
|
210
|
+
}
|
|
211
|
+
if (hasLower) {
|
|
212
|
+
sqlValues.push(util.escapeSQLiteStatement(/** @type {string} */ (encodedLowerKey)));
|
|
213
|
+
if (hasUpper && encodedLowerKey === encodedUpperKey && !range.lowerOpen && !range.upperOpen) {
|
|
214
|
+
sql.push(quotedKeyColumnName, '=', '?');
|
|
215
|
+
return;
|
|
215
216
|
}
|
|
217
|
+
sql.push(quotedKeyColumnName, (range.lowerOpen ? '>' : '>='), '?');
|
|
218
|
+
}
|
|
219
|
+
if (hasLower && hasUpper) { sql.push('AND'); }
|
|
220
|
+
if (hasUpper) {
|
|
221
|
+
sql.push(quotedKeyColumnName, (range.upperOpen ? '<' : '<='), '?');
|
|
222
|
+
sqlValues.push(util.escapeSQLiteStatement(/** @type {string} */ (encodedUpperKey)));
|
|
216
223
|
}
|
|
217
224
|
}
|
|
218
225
|
|