indexeddbshim 16.1.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 +3 -3
- 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 +3 -1
- 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 +1844 -1669
- 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 +972 -1076
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +2704 -2034
- package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js +9 -2
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
- package/dist/indexeddbshim-node.cjs +972 -1076
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +2703 -2033
- package/dist/indexeddbshim-noninvasive.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.min.js +9 -2
- package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
- package/dist/indexeddbshim.js +2676 -2014
- package/dist/indexeddbshim.js.map +1 -1
- package/dist/indexeddbshim.min.js +9 -2
- 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/util.d.ts.map +1 -1
- package/package.json +111 -103
- 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 +16 -9
- package/src/IDBDatabase.js +9 -6
- package/src/IDBFactory.js +21 -14
- 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 +18 -12
- package/src/Sca.js +2 -1
- package/src/UnicodeIdentifiers.js +2 -2
- package/src/browser-UnicodeIdentifiers.js +0 -1
- 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 -13
- package/src/util.js +13 -12
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
|
|
|
@@ -93,7 +94,7 @@ function processNextInConnectionQueue (name, origin = getOrigin()) {
|
|
|
93
94
|
*/
|
|
94
95
|
function addRequestToConnectionQueue (req, name, origin = getOrigin(), cb) {
|
|
95
96
|
/* eslint-enable default-param-last -- Keep cb at end */
|
|
96
|
-
if (!connectionQueue[origin]
|
|
97
|
+
if (!Object.hasOwn(connectionQueue[origin], name)) {
|
|
97
98
|
connectionQueue[origin][name] = [];
|
|
98
99
|
}
|
|
99
100
|
connectionQueue[origin][name].push({req, cb});
|
|
@@ -139,7 +140,7 @@ function triggerAnyVersionChangeAndBlockedEvents (openConnections, req, oldVersi
|
|
|
139
140
|
setTimeout(() => {
|
|
140
141
|
entry.dispatchEvent(e); // No need to catch errors
|
|
141
142
|
resolve(undefined);
|
|
142
|
-
});
|
|
143
|
+
}, 0);
|
|
143
144
|
});
|
|
144
145
|
});
|
|
145
146
|
}, SyncPromise.resolve(undefined)).then(function () {
|
|
@@ -168,7 +169,7 @@ function triggerAnyVersionChangeAndBlockedEvents (openConnections, req, oldVersi
|
|
|
168
169
|
} else {
|
|
169
170
|
resolve(undefined);
|
|
170
171
|
}
|
|
171
|
-
});
|
|
172
|
+
}, 0);
|
|
172
173
|
});
|
|
173
174
|
});
|
|
174
175
|
}
|
|
@@ -229,7 +230,7 @@ function getLatestCachedWebSQLDB (name) {
|
|
|
229
230
|
function cleanupDatabaseResources (__openDatabase, name, escapedDatabaseName, databaseDeleted, dbError) {
|
|
230
231
|
const useMemoryDatabase = typeof CFG.memoryDatabase === 'string';
|
|
231
232
|
if (useMemoryDatabase) {
|
|
232
|
-
const latestSQLiteDBCached = websqlDBCache
|
|
233
|
+
const latestSQLiteDBCached = Object.hasOwn(websqlDBCache, name) ? getLatestCachedWebSQLDB(name) : null;
|
|
233
234
|
if (!latestSQLiteDBCached) {
|
|
234
235
|
console.warn('Could not find a memory database instance to delete.');
|
|
235
236
|
databaseDeleted();
|
|
@@ -334,6 +335,7 @@ function createSysDB (__openDatabase, success, failure) {
|
|
|
334
335
|
if (sysdb) {
|
|
335
336
|
success();
|
|
336
337
|
} else {
|
|
338
|
+
// eslint-disable-next-line unicorn/no-top-level-assignment-in-function -- Necessary?
|
|
337
339
|
sysdb = __openDatabase(
|
|
338
340
|
typeof CFG.memoryDatabase === 'string'
|
|
339
341
|
? CFG.memoryDatabase
|
|
@@ -367,6 +369,7 @@ function createSysDB (__openDatabase, success, failure) {
|
|
|
367
369
|
/**
|
|
368
370
|
* IDBFactory Class.
|
|
369
371
|
* @see https://w3c.github.io/IndexedDB/#idl-def-IDBFactory
|
|
372
|
+
* @throws {TypeError}
|
|
370
373
|
* @class
|
|
371
374
|
*/
|
|
372
375
|
function IDBFactory () {
|
|
@@ -438,6 +441,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
438
441
|
let calledDbCreateError = false;
|
|
439
442
|
|
|
440
443
|
if (CFG.autoName && name === '') {
|
|
444
|
+
// eslint-disable-next-line unicorn/no-top-level-assignment-in-function -- Necessary?
|
|
441
445
|
name = 'autoNamedDatabase_' + nameCounter++;
|
|
442
446
|
}
|
|
443
447
|
name = String(name); // cast to a string
|
|
@@ -494,7 +498,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
494
498
|
req.__done = true;
|
|
495
499
|
}
|
|
496
500
|
const connection = IDBDatabase.__createInstance(db, name, oldVersion, version, data);
|
|
497
|
-
if (!me.__connections
|
|
501
|
+
if (!Object.hasOwn(me.__connections, name)) {
|
|
498
502
|
me.__connections[name] = [];
|
|
499
503
|
}
|
|
500
504
|
me.__connections[name].push(connection);
|
|
@@ -602,7 +606,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
602
606
|
connection.__upgradeTransaction = null;
|
|
603
607
|
// We ensure any cache is deleted before any request error events fire and try to reopen
|
|
604
608
|
if (useDatabaseCache) {
|
|
605
|
-
if (name
|
|
609
|
+
if (Object.hasOwn(websqlDBCache, name)) {
|
|
606
610
|
delete websqlDBCache[name][version];
|
|
607
611
|
}
|
|
608
612
|
}
|
|
@@ -633,7 +637,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
633
637
|
dbCreateError(err);
|
|
634
638
|
return false;
|
|
635
639
|
});
|
|
636
|
-
});
|
|
640
|
+
}, 0);
|
|
637
641
|
};
|
|
638
642
|
|
|
639
643
|
// eslint-disable-next-line camelcase -- Clear API
|
|
@@ -712,7 +716,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
712
716
|
function openDB (oldVersion) {
|
|
713
717
|
/** @type {DatabaseFull} */
|
|
714
718
|
let db;
|
|
715
|
-
if ((useMemoryDatabase || useDatabaseCache) && name
|
|
719
|
+
if ((useMemoryDatabase || useDatabaseCache) && Object.hasOwn(websqlDBCache, name) && Object.hasOwn(websqlDBCache[name], version)) {
|
|
716
720
|
db = websqlDBCache[name][version];
|
|
717
721
|
} else {
|
|
718
722
|
db = me.__openDatabase(
|
|
@@ -722,7 +726,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
722
726
|
CFG.DEFAULT_DB_SIZE
|
|
723
727
|
);
|
|
724
728
|
if (useDatabaseCache) {
|
|
725
|
-
if (!(name
|
|
729
|
+
if (!(Object.hasOwn(websqlDBCache, name))) {
|
|
726
730
|
websqlDBCache[name] = {};
|
|
727
731
|
}
|
|
728
732
|
websqlDBCache[name][version] = db;
|
|
@@ -737,7 +741,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
737
741
|
if (useDatabaseCache) {
|
|
738
742
|
setTimeout(() => {
|
|
739
743
|
dbCreateError(err);
|
|
740
|
-
});
|
|
744
|
+
}, 0);
|
|
741
745
|
} else {
|
|
742
746
|
dbCreateError(err);
|
|
743
747
|
}
|
|
@@ -764,7 +768,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
764
768
|
addRequestToConnectionQueue(req, name, /* origin */ undefined, function () {
|
|
765
769
|
let latestCachedVersion;
|
|
766
770
|
if (useDatabaseCache) {
|
|
767
|
-
if (!(name
|
|
771
|
+
if (!Object.hasOwn(websqlDBCache, name)) {
|
|
768
772
|
websqlDBCache[name] = {};
|
|
769
773
|
}
|
|
770
774
|
latestCachedVersion = getLatestCachedWebSQLVersion(name);
|
|
@@ -884,7 +888,7 @@ IDBFactory.prototype.deleteDatabase = function (name) {
|
|
|
884
888
|
/** @type {DatabaseDeleted} */
|
|
885
889
|
function databaseDeleted () {
|
|
886
890
|
sysdbFinishedCbDelete(false, function () {
|
|
887
|
-
if (useDatabaseCache && name
|
|
891
|
+
if (useDatabaseCache && Object.hasOwn(websqlDBCache, name)) {
|
|
888
892
|
delete websqlDBCache[name]; // New calls will treat as though never existed
|
|
889
893
|
}
|
|
890
894
|
delete me.__connections[name];
|
|
@@ -1017,7 +1021,7 @@ IDBFactory.prototype.databases = function () {
|
|
|
1017
1021
|
* @todo forceClose: Test
|
|
1018
1022
|
* This is provided to facilitate unit-testing of the
|
|
1019
1023
|
* closing of a database connection with a forced flag:
|
|
1020
|
-
* <
|
|
1024
|
+
* <https://w3c.github.io/IndexedDB/#steps-for-closing-a-database-connection>
|
|
1021
1025
|
* @param {string} dbName
|
|
1022
1026
|
* @param {Integer} connIdx
|
|
1023
1027
|
* @param {string} msg
|
|
@@ -1041,12 +1045,13 @@ IDBFactory.prototype.__forceClose = function (dbName, connIdx, msg) {
|
|
|
1041
1045
|
forceClose(connection);
|
|
1042
1046
|
});
|
|
1043
1047
|
});
|
|
1044
|
-
} else if (!me.__connections
|
|
1048
|
+
} else if (!Object.hasOwn(me.__connections, dbName)) {
|
|
1045
1049
|
console.log('No database connections with that name to force close');
|
|
1046
1050
|
} else if (util.isNullish(connIdx)) {
|
|
1047
1051
|
me.__connections[dbName].forEach((conn) => {
|
|
1048
1052
|
forceClose(conn);
|
|
1049
1053
|
});
|
|
1054
|
+
// eslint-disable-next-line unicorn/prefer-number-is-safe-integer -- Ok
|
|
1050
1055
|
} else if (!Number.isInteger(connIdx) || connIdx < 0 || connIdx > me.__connections[dbName].length - 1) {
|
|
1051
1056
|
throw new TypeError(
|
|
1052
1057
|
'If providing an argument, __forceClose must be called with a ' +
|
|
@@ -1068,9 +1073,11 @@ IDBFactory.prototype.__setConnectionQueueOrigin = function (origin = getOrigin()
|
|
|
1068
1073
|
|
|
1069
1074
|
IDBFactory.prototype[Symbol.toStringTag] = 'IDBFactoryPrototype';
|
|
1070
1075
|
|
|
1076
|
+
/* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
|
|
1071
1077
|
Object.defineProperty(IDBFactory, 'prototype', {
|
|
1072
1078
|
writable: false
|
|
1073
1079
|
});
|
|
1080
|
+
/* eslint-enable unicorn/no-top-level-side-effects -- Would be good */
|
|
1074
1081
|
|
|
1075
1082
|
const shimIndexedDB = IDBFactory.__createInstance();
|
|
1076
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
|
|