indexeddbshim 16.1.0 → 17.1.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 +65 -3
- package/badges/licenses-badge-dev.svg +1 -1
- package/badges/licenses-badge.svg +1 -1
- package/dist/CFG.d.ts +1 -0
- 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 +12 -3
- 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 +23 -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 +1863 -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 +2373 -1893
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +3124 -2285
- 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 +2373 -1893
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +3123 -2284
- 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 +3120 -2282
- 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/nodeSQLiteDatabase.d.ts +65 -0
- package/dist/nodeSQLiteDatabase.d.ts.map +1 -0
- package/dist/nodeWebSQL.d.ts.map +1 -1
- package/dist/util.d.ts +5 -0
- package/dist/util.d.ts.map +1 -1
- package/package.json +118 -106
- package/src/CFG.js +5 -3
- package/src/DOMException.js +11 -9
- package/src/DOMStringList.js +8 -3
- package/src/Event.js +2 -0
- package/src/IDBCursor.js +152 -95
- package/src/IDBDatabase.js +9 -6
- package/src/IDBFactory.js +31 -20
- package/src/IDBIndex.js +83 -79
- package/src/IDBKeyRange.js +42 -35
- package/src/IDBObjectStore.js +83 -77
- package/src/IDBRequest.js +28 -15
- package/src/IDBTransaction.js +40 -6
- package/src/IDBVersionChangeEvent.js +2 -0
- package/src/Key.js +28 -14
- 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 +6 -2
- package/src/node.js +6 -2
- package/src/nodeSQLiteDatabase.js +174 -0
- package/src/nodeWebSQL.js +1 -3
- package/src/setGlobalVars.js +13 -13
- package/src/util.js +75 -15
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);
|
|
@@ -589,7 +593,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
589
593
|
req.__result
|
|
590
594
|
).__versionTransaction = null;
|
|
591
595
|
sysdbFinishedCb(systx, false, function () {
|
|
592
|
-
req.transaction.
|
|
596
|
+
req.transaction.__callTransFinishedCb(false, function () {
|
|
593
597
|
ev.complete();
|
|
594
598
|
req.__transaction = null;
|
|
595
599
|
});
|
|
@@ -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,14 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
712
716
|
function openDB (oldVersion) {
|
|
713
717
|
/** @type {DatabaseFull} */
|
|
714
718
|
let db;
|
|
715
|
-
if (
|
|
719
|
+
if (version === undefined) {
|
|
720
|
+
// Resolve before use as a cache key below, or a `open(name)` call
|
|
721
|
+
// (no explicit version) would cache/look up under `undefined`
|
|
722
|
+
// instead of the actual version, causing a second, separate
|
|
723
|
+
// connection to be opened for the same database on reopen.
|
|
724
|
+
version = oldVersion || 1;
|
|
725
|
+
}
|
|
726
|
+
if ((useMemoryDatabase || useDatabaseCache) && Object.hasOwn(websqlDBCache, name) && Object.hasOwn(websqlDBCache[name], version)) {
|
|
716
727
|
db = websqlDBCache[name][version];
|
|
717
728
|
} else {
|
|
718
729
|
db = me.__openDatabase(
|
|
@@ -722,22 +733,19 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
722
733
|
CFG.DEFAULT_DB_SIZE
|
|
723
734
|
);
|
|
724
735
|
if (useDatabaseCache) {
|
|
725
|
-
if (!(name
|
|
736
|
+
if (!(Object.hasOwn(websqlDBCache, name))) {
|
|
726
737
|
websqlDBCache[name] = {};
|
|
727
738
|
}
|
|
728
739
|
websqlDBCache[name][version] = db;
|
|
729
740
|
}
|
|
730
741
|
}
|
|
731
742
|
|
|
732
|
-
if (version === undefined) {
|
|
733
|
-
version = oldVersion || 1;
|
|
734
|
-
}
|
|
735
743
|
if (oldVersion > version) {
|
|
736
744
|
const err = createDOMException('VersionError', 'An attempt was made to open a database using a lower version than the existing version.', version);
|
|
737
745
|
if (useDatabaseCache) {
|
|
738
746
|
setTimeout(() => {
|
|
739
747
|
dbCreateError(err);
|
|
740
|
-
});
|
|
748
|
+
}, 0);
|
|
741
749
|
} else {
|
|
742
750
|
dbCreateError(err);
|
|
743
751
|
}
|
|
@@ -764,7 +772,7 @@ IDBFactory.prototype.open = function (name /* , version */) {
|
|
|
764
772
|
addRequestToConnectionQueue(req, name, /* origin */ undefined, function () {
|
|
765
773
|
let latestCachedVersion;
|
|
766
774
|
if (useDatabaseCache) {
|
|
767
|
-
if (!(name
|
|
775
|
+
if (!Object.hasOwn(websqlDBCache, name)) {
|
|
768
776
|
websqlDBCache[name] = {};
|
|
769
777
|
}
|
|
770
778
|
latestCachedVersion = getLatestCachedWebSQLVersion(name);
|
|
@@ -884,7 +892,7 @@ IDBFactory.prototype.deleteDatabase = function (name) {
|
|
|
884
892
|
/** @type {DatabaseDeleted} */
|
|
885
893
|
function databaseDeleted () {
|
|
886
894
|
sysdbFinishedCbDelete(false, function () {
|
|
887
|
-
if (useDatabaseCache && name
|
|
895
|
+
if (useDatabaseCache && Object.hasOwn(websqlDBCache, name)) {
|
|
888
896
|
delete websqlDBCache[name]; // New calls will treat as though never existed
|
|
889
897
|
}
|
|
890
898
|
delete me.__connections[name];
|
|
@@ -901,7 +909,7 @@ IDBFactory.prototype.deleteDatabase = function (name) {
|
|
|
901
909
|
({version} = data.rows.item(0));
|
|
902
910
|
|
|
903
911
|
const openConnections = me.__connections[name] || [];
|
|
904
|
-
triggerAnyVersionChangeAndBlockedEvents(openConnections, req, version, null).then(function () {
|
|
912
|
+
triggerAnyVersionChangeAndBlockedEvents(openConnections, req, version, null).then(function () {
|
|
905
913
|
// Since we need two databases which can't be in a single transaction, we
|
|
906
914
|
// do this deleting from `dbVersions` first since the `__sys__` deleting
|
|
907
915
|
// only impacts file memory whereas this one is critical for avoiding it
|
|
@@ -930,7 +938,7 @@ IDBFactory.prototype.deleteDatabase = function (name) {
|
|
|
930
938
|
});
|
|
931
939
|
return undefined;
|
|
932
940
|
// @ts-expect-error It's ok
|
|
933
|
-
}
|
|
941
|
+
}).catch(dbError);
|
|
934
942
|
return undefined;
|
|
935
943
|
}, dbError);
|
|
936
944
|
});
|
|
@@ -1017,7 +1025,7 @@ IDBFactory.prototype.databases = function () {
|
|
|
1017
1025
|
* @todo forceClose: Test
|
|
1018
1026
|
* This is provided to facilitate unit-testing of the
|
|
1019
1027
|
* closing of a database connection with a forced flag:
|
|
1020
|
-
* <
|
|
1028
|
+
* <https://w3c.github.io/IndexedDB/#steps-for-closing-a-database-connection>
|
|
1021
1029
|
* @param {string} dbName
|
|
1022
1030
|
* @param {Integer} connIdx
|
|
1023
1031
|
* @param {string} msg
|
|
@@ -1041,12 +1049,13 @@ IDBFactory.prototype.__forceClose = function (dbName, connIdx, msg) {
|
|
|
1041
1049
|
forceClose(connection);
|
|
1042
1050
|
});
|
|
1043
1051
|
});
|
|
1044
|
-
} else if (!me.__connections
|
|
1052
|
+
} else if (!Object.hasOwn(me.__connections, dbName)) {
|
|
1045
1053
|
console.log('No database connections with that name to force close');
|
|
1046
1054
|
} else if (util.isNullish(connIdx)) {
|
|
1047
1055
|
me.__connections[dbName].forEach((conn) => {
|
|
1048
1056
|
forceClose(conn);
|
|
1049
1057
|
});
|
|
1058
|
+
// eslint-disable-next-line unicorn/prefer-number-is-safe-integer -- Ok
|
|
1050
1059
|
} else if (!Number.isInteger(connIdx) || connIdx < 0 || connIdx > me.__connections[dbName].length - 1) {
|
|
1051
1060
|
throw new TypeError(
|
|
1052
1061
|
'If providing an argument, __forceClose must be called with a ' +
|
|
@@ -1068,9 +1077,11 @@ IDBFactory.prototype.__setConnectionQueueOrigin = function (origin = getOrigin()
|
|
|
1068
1077
|
|
|
1069
1078
|
IDBFactory.prototype[Symbol.toStringTag] = 'IDBFactoryPrototype';
|
|
1070
1079
|
|
|
1080
|
+
/* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
|
|
1071
1081
|
Object.defineProperty(IDBFactory, 'prototype', {
|
|
1072
1082
|
writable: false
|
|
1073
1083
|
});
|
|
1084
|
+
/* eslint-enable unicorn/no-top-level-side-effects -- Would be good */
|
|
1074
1085
|
|
|
1075
1086
|
const shimIndexedDB = IDBFactory.__createInstance();
|
|
1076
1087
|
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
|
|
@@ -730,8 +733,7 @@ IDBIndex.prototype.__renameIndex = function (store, oldName, newName, colInfoToP
|
|
|
730
733
|
);
|
|
731
734
|
})
|
|
732
735
|
);
|
|
733
|
-
SyncPromise.all(indexCreations).then(
|
|
734
|
-
finish,
|
|
736
|
+
SyncPromise.all(indexCreations).then(finish).catch(
|
|
735
737
|
/** @type {(reason: any) => PromiseLike<never>} */
|
|
736
738
|
(error)
|
|
737
739
|
).catch((err) => {
|
|
@@ -749,6 +751,7 @@ IDBIndex.prototype.__renameIndex = function (store, oldName, newName, colInfoToP
|
|
|
749
751
|
* @typedef {any} AnyValue
|
|
750
752
|
*/
|
|
751
753
|
|
|
754
|
+
/* eslint-disable unicorn/no-top-level-side-effects -- Would be good */
|
|
752
755
|
Object.defineProperty(IDBIndex, Symbol.hasInstance, {
|
|
753
756
|
/**
|
|
754
757
|
* @param {AnyValue} obj
|
|
@@ -769,6 +772,7 @@ IDBIndex.prototype[Symbol.toStringTag] = 'IDBIndexPrototype';
|
|
|
769
772
|
Object.defineProperty(IDBIndex, 'prototype', {
|
|
770
773
|
writable: false
|
|
771
774
|
});
|
|
775
|
+
/* eslint-enable unicorn/no-top-level-side-effects -- Would be good */
|
|
772
776
|
|
|
773
777
|
/**
|
|
774
778
|
* @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
|
|