indexeddbshim 13.0.0-pre.1 → 13.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 +1 -1
- package/badges/licenses-badge-dev.svg +1 -1
- package/dist/indexeddbshim-Key.js +90 -82
- 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 +824 -487
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +947 -774
- package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js +2 -2
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
- package/dist/indexeddbshim-node.cjs +824 -487
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +947 -774
- package/dist/indexeddbshim-noninvasive.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.min.js +2 -2
- package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
- package/dist/indexeddbshim.js +947 -774
- package/dist/indexeddbshim.js.map +1 -1
- package/dist/indexeddbshim.min.js +2 -2
- package/dist/indexeddbshim.min.js.map +1 -1
- package/index.html +1 -1
- package/package.json +35 -34
- package/src/DOMException.js +3 -4
- package/src/DOMStringList.js +1 -1
- package/src/IDBCursor.js +19 -17
- package/src/IDBDatabase.js +1 -0
- package/src/IDBFactory.js +23 -16
- package/src/IDBIndex.js +17 -23
- package/src/IDBKeyRange.js +4 -4
- package/src/IDBObjectStore.js +29 -26
- package/src/IDBTransaction.js +7 -8
- package/src/Key.d.ts +1 -0
- package/src/Key.js +11 -12
- package/src/setGlobalVars.js +3 -1
- package/src/util.js +1 -0
package/src/IDBObjectStore.js
CHANGED
|
@@ -151,21 +151,21 @@ IDBObjectStore.__createInstance = function (storeProperties, transaction) {
|
|
|
151
151
|
|
|
152
152
|
const sql = 'UPDATE __sys__ SET "name" = ? WHERE "name" = ?';
|
|
153
153
|
const sqlValues = [util.escapeSQLiteStatement(name), util.escapeSQLiteStatement(oldName)];
|
|
154
|
-
CFG.DEBUG
|
|
154
|
+
if (CFG.DEBUG) { console.log(sql, sqlValues); }
|
|
155
155
|
/** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
156
156
|
me.transaction
|
|
157
157
|
).__addNonRequestToTransactionQueue(function objectStoreClear (tx, args, success, error) {
|
|
158
|
-
tx.executeSql(sql, sqlValues, function (tx
|
|
158
|
+
tx.executeSql(sql, sqlValues, function (tx) {
|
|
159
159
|
// This SQL preserves indexes per https://www.sqlite.org/lang_altertable.html
|
|
160
160
|
const sql = 'ALTER TABLE ' + util.escapeStoreNameForSQL(oldName) + ' RENAME TO ' + util.escapeStoreNameForSQL(name);
|
|
161
|
-
CFG.DEBUG
|
|
162
|
-
tx.executeSql(sql, [], function (
|
|
161
|
+
if (CFG.DEBUG) { console.log(sql); }
|
|
162
|
+
tx.executeSql(sql, [], function () {
|
|
163
163
|
delete me.__pendingName;
|
|
164
164
|
success();
|
|
165
165
|
});
|
|
166
166
|
}, function (tx, err) {
|
|
167
167
|
error(err);
|
|
168
|
-
return
|
|
168
|
+
return false;
|
|
169
169
|
});
|
|
170
170
|
});
|
|
171
171
|
}
|
|
@@ -254,16 +254,16 @@ IDBObjectStore.__createObjectStore = function (db, store) {
|
|
|
254
254
|
* @returns {boolean}
|
|
255
255
|
*/
|
|
256
256
|
function error (tx, err) {
|
|
257
|
-
CFG.DEBUG
|
|
257
|
+
if (CFG.DEBUG) { console.log(err); }
|
|
258
258
|
failure(createDOMException('UnknownError', 'Could not create object store "' + storeName + '"', err));
|
|
259
|
-
return
|
|
259
|
+
return false;
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
const escapedStoreNameSQL = util.escapeStoreNameForSQL(storeName);
|
|
263
263
|
// key INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE
|
|
264
264
|
const sql = ['CREATE TABLE', escapedStoreNameSQL, '(key BLOB', store.autoIncrement ? 'UNIQUE, inc INTEGER PRIMARY KEY AUTOINCREMENT' : 'PRIMARY KEY', ', value BLOB)'].join(' ');
|
|
265
|
-
CFG.DEBUG
|
|
266
|
-
tx.executeSql(sql, [], function (tx
|
|
265
|
+
if (CFG.DEBUG) { console.log(sql); }
|
|
266
|
+
tx.executeSql(sql, [], function (tx) {
|
|
267
267
|
/**
|
|
268
268
|
* @returns {void}
|
|
269
269
|
*/
|
|
@@ -327,9 +327,9 @@ IDBObjectStore.__deleteObjectStore = function (db, store) {
|
|
|
327
327
|
* @returns {boolean}
|
|
328
328
|
*/
|
|
329
329
|
function error (tx, err) {
|
|
330
|
-
CFG.DEBUG
|
|
330
|
+
if (CFG.DEBUG) { console.log(err); }
|
|
331
331
|
failure(createDOMException('UnknownError', 'Could not delete ObjectStore', err));
|
|
332
|
-
return
|
|
332
|
+
return false;
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
tx.executeSql('SELECT "name" FROM __sys__ WHERE "name" = ?', [util.escapeSQLiteStatement(store.__currentName)], function (tx, data) {
|
|
@@ -447,6 +447,7 @@ IDBObjectStore.prototype.__deriveKey = function (tx, value, key, success, failCb
|
|
|
447
447
|
if (me.autoIncrement) {
|
|
448
448
|
// If auto-increment and no valid primaryKey found on the keyPath, get and set the new value, and use
|
|
449
449
|
if (key === undefined) {
|
|
450
|
+
// @ts-expect-error Due to re-exporting `Key.d.ts` file (needed for `node_modules` imports)
|
|
450
451
|
Key.generateKeyForStore(tx, me, function (failure, key, oldCn) {
|
|
451
452
|
if (failure) {
|
|
452
453
|
failCb(createDOMException('ConstraintError', 'The key generator\'s current number has reached the maximum safe integer limit'));
|
|
@@ -462,6 +463,7 @@ IDBObjectStore.prototype.__deriveKey = function (tx, value, key, success, failCb
|
|
|
462
463
|
success(key, oldCn);
|
|
463
464
|
}, failCb);
|
|
464
465
|
} else {
|
|
466
|
+
// @ts-expect-error Due to re-exporting `Key.d.ts` file (needed for `node_modules` imports)
|
|
465
467
|
Key.possiblyUpdateKeyGenerator(tx, me, key, keyCloneThenSuccess, failCb);
|
|
466
468
|
}
|
|
467
469
|
// Not auto-increment
|
|
@@ -597,16 +599,16 @@ IDBObjectStore.prototype.__insertData = function (tx, encoded, value, clonedKeyO
|
|
|
597
599
|
insertSqlValues.push(util.escapeSQLiteStatement(encoded));
|
|
598
600
|
|
|
599
601
|
const insertSql = sqlStart.join(' ') + sqlEnd.join(' ');
|
|
600
|
-
CFG.DEBUG
|
|
602
|
+
if (CFG.DEBUG) { console.log('SQL for adding', insertSql, insertSqlValues); }
|
|
601
603
|
|
|
602
|
-
tx.executeSql(insertSql, insertSqlValues, function (
|
|
604
|
+
tx.executeSql(insertSql, insertSqlValues, function () {
|
|
603
605
|
success(clonedKeyOrCurrentNumber);
|
|
604
606
|
}, function (tx, err) {
|
|
605
607
|
// Should occur for `add` operation
|
|
606
608
|
error(createDOMException(
|
|
607
609
|
'ConstraintError', /** @type {string} */ (err.message), err
|
|
608
610
|
));
|
|
609
|
-
return
|
|
611
|
+
return false;
|
|
610
612
|
});
|
|
611
613
|
return undefined;
|
|
612
614
|
}).catch(function (err) {
|
|
@@ -619,6 +621,7 @@ IDBObjectStore.prototype.__insertData = function (tx, encoded, value, clonedKeyO
|
|
|
619
621
|
error(err);
|
|
620
622
|
}
|
|
621
623
|
if (typeof oldCn === 'number') {
|
|
624
|
+
// @ts-expect-error Due to re-exporting `Key.d.ts` file (needed for `node_modules` imports)
|
|
622
625
|
Key.assignCurrentNumber(tx, me, oldCn, fail, fail);
|
|
623
626
|
return null;
|
|
624
627
|
}
|
|
@@ -664,7 +667,7 @@ IDBObjectStore.prototype.add = function (value /* , key */) {
|
|
|
664
667
|
* @this {IDBObjectStoreFull}
|
|
665
668
|
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
666
669
|
*/
|
|
667
|
-
IDBObjectStore.prototype.put = function (value
|
|
670
|
+
IDBObjectStore.prototype.put = function (value /* , key */) {
|
|
668
671
|
const me = this;
|
|
669
672
|
// eslint-disable-next-line prefer-rest-params
|
|
670
673
|
const key = arguments[1];
|
|
@@ -704,11 +707,11 @@ IDBObjectStore.prototype.__overwrite = function (tx, key, cb, error) {
|
|
|
704
707
|
const sql = 'DELETE FROM ' + util.escapeStoreNameForSQL(me.__currentName) + ' WHERE "key" = ?';
|
|
705
708
|
const encodedKey = /** @type {string} */ (Key.encode(key));
|
|
706
709
|
tx.executeSql(sql, [util.escapeSQLiteStatement(encodedKey)], function (tx, data) {
|
|
707
|
-
CFG.DEBUG
|
|
710
|
+
if (CFG.DEBUG) { console.log('Did the row with the', key, 'exist?', data.rowsAffected); }
|
|
708
711
|
cb(tx);
|
|
709
712
|
}, function (tx, err) {
|
|
710
713
|
error(err);
|
|
711
|
-
return
|
|
714
|
+
return false;
|
|
712
715
|
});
|
|
713
716
|
};
|
|
714
717
|
|
|
@@ -793,9 +796,9 @@ IDBObjectStore.prototype.__get = function (query, getKey, getAll, count) {
|
|
|
793
796
|
return /** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
794
797
|
me.transaction
|
|
795
798
|
).__addToTransactionQueue(function objectStoreGet (tx, args, success, error) {
|
|
796
|
-
CFG.DEBUG
|
|
799
|
+
if (CFG.DEBUG) { console.log('Fetching', me.__currentName, sqlValues); }
|
|
797
800
|
tx.executeSql(sqlStr, sqlValues, function (tx, data) {
|
|
798
|
-
CFG.DEBUG
|
|
801
|
+
if (CFG.DEBUG) { console.log('Fetched data', data); }
|
|
799
802
|
let ret;
|
|
800
803
|
try {
|
|
801
804
|
// Opera can't deal with the try-catch here.
|
|
@@ -827,12 +830,12 @@ IDBObjectStore.prototype.__get = function (query, getKey, getAll, count) {
|
|
|
827
830
|
}
|
|
828
831
|
} catch (e) {
|
|
829
832
|
// If no result is returned, or error occurs when parsing JSON
|
|
830
|
-
CFG.DEBUG
|
|
833
|
+
if (CFG.DEBUG) { console.log(e); }
|
|
831
834
|
}
|
|
832
835
|
success(ret);
|
|
833
836
|
}, function (tx, err) {
|
|
834
837
|
error(err);
|
|
835
|
-
return
|
|
838
|
+
return false;
|
|
836
839
|
});
|
|
837
840
|
}, undefined, me);
|
|
838
841
|
};
|
|
@@ -917,16 +920,16 @@ IDBObjectStore.prototype.delete = function (query) {
|
|
|
917
920
|
return /** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
918
921
|
me.transaction
|
|
919
922
|
).__addToTransactionQueue(function objectStoreDelete (tx, args, success, error) {
|
|
920
|
-
CFG.DEBUG
|
|
923
|
+
if (CFG.DEBUG) { console.log('Deleting', me.__currentName, sqlValues); }
|
|
921
924
|
tx.executeSql(sql, sqlValues, function (tx, data) {
|
|
922
|
-
CFG.DEBUG
|
|
925
|
+
if (CFG.DEBUG) { console.log('Deleted from database', data.rowsAffected); }
|
|
923
926
|
me.__cursors.forEach((cursor) => {
|
|
924
927
|
cursor.__invalidateCache(); // Delete
|
|
925
928
|
});
|
|
926
929
|
success();
|
|
927
930
|
}, function (tx, err) {
|
|
928
931
|
error(err);
|
|
929
|
-
return
|
|
932
|
+
return false;
|
|
930
933
|
});
|
|
931
934
|
}, undefined, me);
|
|
932
935
|
};
|
|
@@ -950,14 +953,14 @@ IDBObjectStore.prototype.clear = function () {
|
|
|
950
953
|
me.transaction
|
|
951
954
|
).__addToTransactionQueue(function objectStoreClear (tx, args, success, error) {
|
|
952
955
|
tx.executeSql('DELETE FROM ' + util.escapeStoreNameForSQL(me.__currentName), [], function (tx, data) {
|
|
953
|
-
CFG.DEBUG
|
|
956
|
+
if (CFG.DEBUG) { console.log('Cleared all records from database', data.rowsAffected); }
|
|
954
957
|
me.__cursors.forEach((cursor) => {
|
|
955
958
|
cursor.__invalidateCache(); // Clear
|
|
956
959
|
});
|
|
957
960
|
success();
|
|
958
961
|
}, function (tx, err) {
|
|
959
962
|
error(err);
|
|
960
|
-
return
|
|
963
|
+
return false;
|
|
961
964
|
});
|
|
962
965
|
}, undefined, me);
|
|
963
966
|
};
|
package/src/IDBTransaction.js
CHANGED
|
@@ -141,6 +141,7 @@ IDBTransaction.__createInstance = function (db, storeNames, mode) {
|
|
|
141
141
|
|
|
142
142
|
// @ts-expect-error It's ok
|
|
143
143
|
IDBTransaction.prototype = EventTargetFactory.createInstance({
|
|
144
|
+
// eslint-disable-next-line n/no-sync -- API
|
|
144
145
|
defaultSync: true,
|
|
145
146
|
// Ensure EventTarget preserves our properties
|
|
146
147
|
extraProperties: ['complete']
|
|
@@ -162,7 +163,7 @@ IDBTransaction.prototype.__transFinishedCb = function (err, cb) {
|
|
|
162
163
|
IDBTransaction.prototype.__executeRequests = function () {
|
|
163
164
|
const me = this;
|
|
164
165
|
if (me.__running) {
|
|
165
|
-
CFG.DEBUG
|
|
166
|
+
if (CFG.DEBUG) { console.log('Looks like the request set is already running', me.mode); }
|
|
166
167
|
return;
|
|
167
168
|
}
|
|
168
169
|
|
|
@@ -349,7 +350,7 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
349
350
|
*/
|
|
350
351
|
function complete () {
|
|
351
352
|
me.__completed = true;
|
|
352
|
-
CFG.DEBUG
|
|
353
|
+
if (CFG.DEBUG) { console.log('Transaction completed'); }
|
|
353
354
|
const evt = createEvent('complete');
|
|
354
355
|
try {
|
|
355
356
|
me.__internal = true;
|
|
@@ -583,12 +584,10 @@ IDBTransaction.prototype.__abortTransaction = function (err) {
|
|
|
583
584
|
*/
|
|
584
585
|
function abort (tx, errOrResult) {
|
|
585
586
|
if (!tx) {
|
|
586
|
-
CFG.DEBUG
|
|
587
|
+
if (CFG.DEBUG) { console.log('Rollback not possible due to missing transaction', me); }
|
|
587
588
|
} else if (errOrResult && 'code' in errOrResult && typeof errOrResult.code === 'number') {
|
|
588
|
-
CFG.DEBUG
|
|
589
|
-
} else {
|
|
590
|
-
CFG.DEBUG && console.log('Rollback succeeded', me);
|
|
591
|
-
}
|
|
589
|
+
if (CFG.DEBUG) { console.log('Rollback erred; feature is probably not supported as per WebSQL', me); }
|
|
590
|
+
} else if (CFG.DEBUG) { console.log('Rollback succeeded', me); }
|
|
592
591
|
|
|
593
592
|
me.dispatchEvent(createEvent('__preabort'));
|
|
594
593
|
me.__requests.filter(function (q, i, arr) { // eslint-disable-line promise/no-promise-in-callback
|
|
@@ -675,7 +674,7 @@ IDBTransaction.prototype.abort = function () {
|
|
|
675
674
|
if (!(me instanceof IDBTransaction)) {
|
|
676
675
|
throw new TypeError('Illegal invocation');
|
|
677
676
|
}
|
|
678
|
-
CFG.DEBUG
|
|
677
|
+
if (CFG.DEBUG) { console.log('The transaction was aborted', me); }
|
|
679
678
|
IDBTransaction.__assertNotFinished(me);
|
|
680
679
|
me.__abortTransaction(null);
|
|
681
680
|
};
|
package/src/Key.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/Key.js';
|
package/src/Key.js
CHANGED
|
@@ -94,17 +94,15 @@ const signValues = ['negativeInfinity', 'bigNegative', 'smallNegative', 'smallPo
|
|
|
94
94
|
const types = {
|
|
95
95
|
invalid: {
|
|
96
96
|
/**
|
|
97
|
-
* @param {AnyValue} _key
|
|
98
97
|
* @returns {string}
|
|
99
98
|
*/
|
|
100
|
-
encode (
|
|
99
|
+
encode () {
|
|
101
100
|
return keyTypeToEncodedChar.invalid + '-';
|
|
102
101
|
},
|
|
103
102
|
/**
|
|
104
|
-
* @param {string} _key
|
|
105
103
|
* @returns {undefined}
|
|
106
104
|
*/
|
|
107
|
-
decode (
|
|
105
|
+
decode () {
|
|
108
106
|
return undefined;
|
|
109
107
|
}
|
|
110
108
|
},
|
|
@@ -437,9 +435,9 @@ function negate (s) {
|
|
|
437
435
|
* @returns {KeyType|"invalid"}
|
|
438
436
|
*/
|
|
439
437
|
function getKeyType (key) {
|
|
440
|
-
if (Array.isArray(key)) return 'array';
|
|
441
|
-
if (util.isDate(key)) return 'date';
|
|
442
|
-
if (util.isBinary(key)) return 'binary';
|
|
438
|
+
if (Array.isArray(key)) { return 'array'; }
|
|
439
|
+
if (util.isDate(key)) { return 'date'; }
|
|
440
|
+
if (util.isBinary(key)) { return 'binary'; }
|
|
443
441
|
const keyType = typeof key;
|
|
444
442
|
return ['string', 'number'].includes(keyType)
|
|
445
443
|
? /** @type {"string"|"number"} */ (keyType)
|
|
@@ -712,7 +710,7 @@ function evaluateKeyPathOnValueToDecodedValue (value, keyPath, multiEntry, fullK
|
|
|
712
710
|
return {value};
|
|
713
711
|
}
|
|
714
712
|
const identifiers = keyPath.split('.');
|
|
715
|
-
return identifiers.some((idntfr
|
|
713
|
+
return identifiers.some((idntfr) => {
|
|
716
714
|
if (idntfr === 'length' && (
|
|
717
715
|
typeof value === 'string' || Array.isArray(value)
|
|
718
716
|
)) {
|
|
@@ -925,6 +923,7 @@ function encode (key, inArray) {
|
|
|
925
923
|
return null;
|
|
926
924
|
}
|
|
927
925
|
// array, date, number, string, binary (should already have detected "invalid")
|
|
926
|
+
// @ts-expect-error Argument may be ignored
|
|
928
927
|
return types[getKeyType(key)].encode(key, inArray);
|
|
929
928
|
}
|
|
930
929
|
|
|
@@ -993,7 +992,7 @@ function getCurrentNumber (tx, store, func, sqlFailCb) {
|
|
|
993
992
|
'Could not get the auto increment value for key',
|
|
994
993
|
error
|
|
995
994
|
));
|
|
996
|
-
return
|
|
995
|
+
return false;
|
|
997
996
|
});
|
|
998
997
|
}
|
|
999
998
|
|
|
@@ -1009,12 +1008,12 @@ function getCurrentNumber (tx, store, func, sqlFailCb) {
|
|
|
1009
1008
|
function assignCurrentNumber (tx, store, num, successCb, failCb) {
|
|
1010
1009
|
const sql = 'UPDATE __sys__ SET "currNum" = ? WHERE "name" = ?';
|
|
1011
1010
|
const sqlValues = [num, util.escapeSQLiteStatement(store.__currentName)];
|
|
1012
|
-
CFG.DEBUG
|
|
1013
|
-
tx.executeSql(sql, sqlValues, function (
|
|
1011
|
+
if (CFG.DEBUG) { console.log(sql, sqlValues); }
|
|
1012
|
+
tx.executeSql(sql, sqlValues, function () {
|
|
1014
1013
|
successCb(num);
|
|
1015
1014
|
}, function (tx, err) {
|
|
1016
1015
|
failCb(createDOMException('UnknownError', 'Could not set the auto increment value for key', err));
|
|
1017
|
-
return
|
|
1016
|
+
return false;
|
|
1018
1017
|
});
|
|
1019
1018
|
}
|
|
1020
1019
|
|
package/src/setGlobalVars.js
CHANGED
|
@@ -181,7 +181,9 @@ function setGlobalVars (idb, initialConfig) {
|
|
|
181
181
|
|
|
182
182
|
// @ts-expect-error It's ok
|
|
183
183
|
if (IDB[name] !== value) {
|
|
184
|
-
typeof console !== 'undefined' && console.warn
|
|
184
|
+
if (typeof console !== 'undefined' && console.warn) {
|
|
185
|
+
console.warn('Unable to shim ' + name);
|
|
186
|
+
}
|
|
185
187
|
}
|
|
186
188
|
}
|
|
187
189
|
if (CFG.win.openDatabase !== undefined) {
|
package/src/util.js
CHANGED