fake-indexeddb 6.2.2 → 6.2.4
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 +23 -15
- package/auto/index.js +1 -1
- package/auto/index.mjs +1 -1
- package/build/cjs/FDBCursor.js +2 -1
- package/build/cjs/FDBDatabase.js +45 -20
- package/build/cjs/FDBFactory.js +285 -137
- package/build/cjs/FDBIndex.js +13 -9
- package/build/cjs/FDBObjectStore.js +26 -22
- package/build/cjs/FDBTransaction.js +51 -11
- package/build/cjs/lib/Database.js +25 -12
- package/build/cjs/lib/FakeEventTarget.js +17 -5
- package/build/cjs/lib/ObjectStore.js +60 -20
- package/build/cjs/lib/cloneValueForInsertion.js +30 -0
- package/build/cjs/lib/extractGetAllOptions.js +2 -2
- package/build/cjs/lib/intersection.js +18 -0
- package/build/cjs/lib/isPotentiallyValidKeyRange.js +13 -20
- package/build/cjs/lib/scheduling.js +4 -4
- package/build/cjs/lib/validateRequiredArguments.js +13 -0
- package/build/cjs/lib/valueToKey.js +8 -53
- package/build/cjs/lib/valueToKeyWithoutThrowing.js +102 -0
- package/build/esm/FDBCursor.js +2 -1
- package/build/esm/FDBDatabase.js +45 -20
- package/build/esm/FDBFactory.js +285 -137
- package/build/esm/FDBIndex.js +13 -9
- package/build/esm/FDBObjectStore.js +26 -22
- package/build/esm/FDBTransaction.js +51 -11
- package/build/esm/lib/Database.js +25 -12
- package/build/esm/lib/FakeEventTarget.js +17 -5
- package/build/esm/lib/ObjectStore.js +60 -20
- package/build/esm/lib/cloneValueForInsertion.js +24 -0
- package/build/esm/lib/extractGetAllOptions.js +2 -2
- package/build/esm/lib/intersection.js +12 -0
- package/build/esm/lib/isPotentiallyValidKeyRange.js +12 -20
- package/build/esm/lib/scheduling.js +4 -4
- package/build/esm/lib/validateRequiredArguments.js +7 -0
- package/build/esm/lib/valueToKey.js +7 -52
- package/build/esm/lib/valueToKeyWithoutThrowing.js +95 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# fake-indexeddb
|
|
2
2
|
|
|
3
|
-

|
|
4
|
-

|
|
5
|
-

|
|
6
|
-

|
|
7
|
-

|
|
3
|
+
[](https://github.com/dumbmatter/fakeIndexedDB/actions/workflows/test.yml)
|
|
4
|
+
[](https://github.com/dumbmatter/fakeIndexedDB)
|
|
5
|
+
[](https://github.com/dumbmatter/fakeIndexedDB)
|
|
6
|
+
[](https://www.npmjs.com/package/fake-indexeddb)
|
|
7
|
+
[](https://www.npmjs.com/package/fake-indexeddb)
|
|
8
8
|
|
|
9
9
|
A pure JS in-memory implementation of [the IndexedDB API](https://w3c.github.io/IndexedDB/). Its main use is testing IndexedDB-dependent code in Node.js.
|
|
10
10
|
|
|
@@ -204,19 +204,27 @@ import "fake-indexeddb/auto";
|
|
|
204
204
|
|
|
205
205
|
## Quality
|
|
206
206
|
|
|
207
|
-
Here's a comparison of fake-indexeddb and real browser IndexedDB implementations on [the
|
|
207
|
+
Here's a comparison of fake-indexeddb and real browser IndexedDB implementations on [the Web Platform Tests IndexedDB suite](https://wpt.fyi/results/IndexedDB) as of <!-- last_updated_date_start -->October 16, 2025<!-- last_updated_date_end -->:
|
|
208
208
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
|
214
|
-
|
|
|
215
|
-
|
|
|
209
|
+
<!-- DO NOT MANUALLY OVERWRITE THE TABLE BELOW! -->
|
|
210
|
+
<!-- To update the results, run `pnpm run update-wpt-results` -->
|
|
211
|
+
<!-- wpt_results_start -->
|
|
212
|
+
<!-- wpt_results_total=1651 -->
|
|
213
|
+
| Implementation | Version | Passed | % |
|
|
214
|
+
| --- | --- | --- | --- |
|
|
215
|
+
| Chrome | 143.0.7476.0 | 1651 | 100% |
|
|
216
|
+
| Firefox | 146.0a1 | 1498 | 90.7% |
|
|
217
|
+
| Safari | 230 preview | 1498 | 90.7% |
|
|
218
|
+
| Ladybird | 1.0-62c00712fa | 772 | 46.8% |
|
|
219
|
+
| fake-indexeddb | 6.2.4 | 1368 | 82.9% |
|
|
220
|
+
<!-- wpt_results_end -->
|
|
216
221
|
|
|
217
|
-
|
|
222
|
+
Keep in mind that these tests include a lot of edge cases (such as rare error conditions), so even hitting ~40% likely means that the core IndexedDB functionality is covered. Your app will probably work fine.
|
|
218
223
|
|
|
219
|
-
|
|
224
|
+
Also note that, for a fair comparison with browsers, these results omit some tests that aren't relevant to Node.js such as web workers and cross-origin isolation. When testing fake-indexeddb, some polyfills are used to simulate a browser environment, such as `File` and `location`.
|
|
225
|
+
|
|
226
|
+
> [!NOTE]
|
|
227
|
+
> To see how these test results are generated, see [`update-browser-wpt-results.js`](./bin/update-browser-wpt-results.js) and [`run-all.js`](./src/test/web-platform-tests/run-all.js).
|
|
220
228
|
|
|
221
229
|
## Potential applications:
|
|
222
230
|
|
package/auto/index.js
CHANGED
package/auto/index.mjs
CHANGED
package/build/cjs/FDBCursor.js
CHANGED
|
@@ -10,6 +10,7 @@ var _cmp = _interopRequireDefault(require("./lib/cmp.js"));
|
|
|
10
10
|
var _errors = require("./lib/errors.js");
|
|
11
11
|
var _extractKey = _interopRequireDefault(require("./lib/extractKey.js"));
|
|
12
12
|
var _valueToKey = _interopRequireDefault(require("./lib/valueToKey.js"));
|
|
13
|
+
var _cloneValueForInsertion = require("./lib/cloneValueForInsertion.js");
|
|
13
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
15
|
const getEffectiveObjectStore = cursor => {
|
|
15
16
|
if (cursor.source instanceof _FDBObjectStore.default) {
|
|
@@ -305,7 +306,7 @@ class FDBCursor {
|
|
|
305
306
|
if (!this._gotValue || !Object.hasOwn(this, "value")) {
|
|
306
307
|
throw new _errors.InvalidStateError();
|
|
307
308
|
}
|
|
308
|
-
const clone =
|
|
309
|
+
const clone = (0, _cloneValueForInsertion.cloneValueForInsertion)(value, transaction);
|
|
309
310
|
if (effectiveObjectStore.keyPath !== null) {
|
|
310
311
|
let tempKey;
|
|
311
312
|
try {
|
package/build/cjs/FDBDatabase.js
CHANGED
|
@@ -12,19 +12,21 @@ var _ObjectStore = _interopRequireDefault(require("./lib/ObjectStore.js"));
|
|
|
12
12
|
var _validateKeyPath = _interopRequireDefault(require("./lib/validateKeyPath.js"));
|
|
13
13
|
var _closeConnection = _interopRequireDefault(require("./lib/closeConnection.js"));
|
|
14
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
// Common first 3 steps of https://www.w3.org/TR/IndexedDB/#dom-idbdatabase-createobjectstore and https://www.w3.org/TR/IndexedDB/#dom-idbdatabase-deleteobjectstore
|
|
15
16
|
const confirmActiveVersionchangeTransaction = database => {
|
|
16
|
-
if
|
|
17
|
-
|
|
17
|
+
// Let transaction be database’s upgrade transaction if it is not null, or throw an "InvalidStateError" DOMException otherwise.
|
|
18
|
+
let transaction;
|
|
19
|
+
if (database._runningVersionchangeTransaction) {
|
|
20
|
+
// Find the latest versionchange transaction
|
|
21
|
+
transaction = database._rawDatabase.transactions.findLast(tx => {
|
|
22
|
+
return tx.mode === "versionchange";
|
|
23
|
+
});
|
|
18
24
|
}
|
|
19
|
-
|
|
20
|
-
// Find the latest versionchange transaction
|
|
21
|
-
const transactions = database._rawDatabase.transactions.filter(tx => {
|
|
22
|
-
return tx.mode === "versionchange";
|
|
23
|
-
});
|
|
24
|
-
const transaction = transactions[transactions.length - 1];
|
|
25
|
-
if (!transaction || transaction._state === "finished") {
|
|
25
|
+
if (!transaction) {
|
|
26
26
|
throw new _errors.InvalidStateError();
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
// If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException.
|
|
28
30
|
if (transaction._state !== "active") {
|
|
29
31
|
throw new _errors.TransactionInactiveError();
|
|
30
32
|
}
|
|
@@ -62,43 +64,66 @@ class FDBDatabase extends _FakeEventTarget.default {
|
|
|
62
64
|
if (autoIncrement && (keyPath === "" || Array.isArray(keyPath))) {
|
|
63
65
|
throw new _errors.InvalidAccessError();
|
|
64
66
|
}
|
|
67
|
+
|
|
68
|
+
// Save for rollbackLog
|
|
65
69
|
const objectStoreNames = [...this.objectStoreNames];
|
|
66
|
-
transaction.
|
|
67
|
-
const objectStore = this._rawDatabase.rawObjectStores.get(name);
|
|
68
|
-
if (objectStore) {
|
|
69
|
-
objectStore.deleted = true;
|
|
70
|
-
}
|
|
71
|
-
this.objectStoreNames = new _FakeDOMStringList.default(...objectStoreNames);
|
|
72
|
-
transaction._scope.delete(name);
|
|
73
|
-
this._rawDatabase.rawObjectStores.delete(name);
|
|
74
|
-
});
|
|
70
|
+
const transactionObjectStoreNames = [...transaction.objectStoreNames];
|
|
75
71
|
const rawObjectStore = new _ObjectStore.default(this._rawDatabase, name, keyPath, autoIncrement);
|
|
76
72
|
this.objectStoreNames._push(name);
|
|
77
73
|
this.objectStoreNames._sort();
|
|
78
74
|
transaction._scope.add(name);
|
|
75
|
+
transaction._createdObjectStores.add(rawObjectStore);
|
|
79
76
|
this._rawDatabase.rawObjectStores.set(name, rawObjectStore);
|
|
80
77
|
transaction.objectStoreNames = new _FakeDOMStringList.default(...this.objectStoreNames);
|
|
78
|
+
transaction._rollbackLog.push(() => {
|
|
79
|
+
rawObjectStore.deleted = true;
|
|
80
|
+
this.objectStoreNames = new _FakeDOMStringList.default(...objectStoreNames);
|
|
81
|
+
transaction.objectStoreNames = new _FakeDOMStringList.default(...transactionObjectStoreNames);
|
|
82
|
+
transaction._scope.delete(rawObjectStore.name);
|
|
83
|
+
this._rawDatabase.rawObjectStores.delete(rawObjectStore.name);
|
|
84
|
+
});
|
|
81
85
|
return transaction.objectStore(name);
|
|
82
86
|
}
|
|
87
|
+
|
|
88
|
+
// https://www.w3.org/TR/IndexedDB/#dom-idbdatabase-deleteobjectstore
|
|
83
89
|
deleteObjectStore(name) {
|
|
84
90
|
if (name === undefined) {
|
|
85
91
|
throw new TypeError();
|
|
86
92
|
}
|
|
87
93
|
const transaction = confirmActiveVersionchangeTransaction(this);
|
|
94
|
+
|
|
95
|
+
// Let store be the object store named name in database, or throw a "NotFoundError" DOMException if none.
|
|
88
96
|
const store = this._rawDatabase.rawObjectStores.get(name);
|
|
89
97
|
if (store === undefined) {
|
|
90
98
|
throw new _errors.NotFoundError();
|
|
91
99
|
}
|
|
100
|
+
|
|
101
|
+
// Remove store from this’s object store set.
|
|
102
|
+
// This method synchronously modifies the objectStoreNames property on the IDBDatabase instance on which it was called.
|
|
92
103
|
this.objectStoreNames = new _FakeDOMStringList.default(...Array.from(this.objectStoreNames).filter(objectStoreName => {
|
|
93
104
|
return objectStoreName !== name;
|
|
94
105
|
}));
|
|
95
106
|
transaction.objectStoreNames = new _FakeDOMStringList.default(...this.objectStoreNames);
|
|
107
|
+
|
|
108
|
+
// If there is an object store handle associated with store and transaction, remove all entries from its index set.
|
|
109
|
+
const objectStore = transaction._objectStoresCache.get(name);
|
|
110
|
+
let prevIndexNames;
|
|
111
|
+
if (objectStore) {
|
|
112
|
+
prevIndexNames = [...objectStore.indexNames];
|
|
113
|
+
objectStore.indexNames = new _FakeDOMStringList.default();
|
|
114
|
+
}
|
|
96
115
|
transaction._rollbackLog.push(() => {
|
|
97
116
|
store.deleted = false;
|
|
98
|
-
this._rawDatabase.rawObjectStores.set(name, store);
|
|
99
|
-
this.objectStoreNames._push(name);
|
|
117
|
+
this._rawDatabase.rawObjectStores.set(store.name, store);
|
|
118
|
+
this.objectStoreNames._push(store.name);
|
|
119
|
+
transaction.objectStoreNames._push(store.name);
|
|
100
120
|
this.objectStoreNames._sort();
|
|
121
|
+
if (objectStore && prevIndexNames) {
|
|
122
|
+
objectStore.indexNames = new _FakeDOMStringList.default(...prevIndexNames);
|
|
123
|
+
}
|
|
101
124
|
});
|
|
125
|
+
|
|
126
|
+
// Destroy store.
|
|
102
127
|
store.deleted = true;
|
|
103
128
|
this._rawDatabase.rawObjectStores.delete(name);
|
|
104
129
|
transaction._objectStoresCache.delete(name);
|