fake-indexeddb 6.2.7 → 6.2.9
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 +7 -7
- package/build/cjs/FDBDatabase.js +17 -7
- package/build/cjs/FDBFactory.js +1 -1
- package/build/cjs/FDBTransaction.js +5 -2
- package/build/cjs/lib/Index.js +4 -2
- package/build/cjs/lib/ObjectStore.js +6 -1
- package/build/esm/FDBDatabase.js +17 -7
- package/build/esm/FDBFactory.js +1 -1
- package/build/esm/FDBTransaction.js +5 -2
- package/build/esm/lib/Index.js +4 -2
- package/build/esm/lib/ObjectStore.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -204,19 +204,19 @@ 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 Web Platform Tests IndexedDB suite](https://wpt.fyi/results/IndexedDB) as of <!-- last_updated_date_start -->
|
|
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 -->December 4, 2026<!-- last_updated_date_end -->:
|
|
208
208
|
|
|
209
209
|
<!-- DO NOT MANUALLY OVERWRITE THE TABLE BELOW! -->
|
|
210
210
|
<!-- To update the results, run `pnpm run update-wpt-results` -->
|
|
211
211
|
<!-- wpt_results_start -->
|
|
212
|
-
<!-- wpt_results_total=
|
|
212
|
+
<!-- wpt_results_total=1686 -->
|
|
213
213
|
| Implementation | Version | Passed | % |
|
|
214
214
|
| --- | --- | --- | --- |
|
|
215
|
-
| Chrome |
|
|
216
|
-
| Firefox |
|
|
217
|
-
| Safari |
|
|
218
|
-
| Ladybird | 1.0-
|
|
219
|
-
| fake-indexeddb | 6.2.
|
|
215
|
+
| Chrome | 158.0.8127.107 | 1680 | 99.6% |
|
|
216
|
+
| Firefox | 164.0a1 | 1679 | 99.6% |
|
|
217
|
+
| Safari | 27.2 (22625.2.8.11.9) | 1513 | 89.7% |
|
|
218
|
+
| Ladybird | 1.0-8bd3606c4c3 | 1678 | 99.5% |
|
|
219
|
+
| fake-indexeddb | 6.2.9 | 1370 | 81.3% |
|
|
220
220
|
<!-- wpt_results_end -->
|
|
221
221
|
|
|
222
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.
|
package/build/cjs/FDBDatabase.js
CHANGED
|
@@ -129,6 +129,9 @@ class FDBDatabase extends _FakeEventTarget.default {
|
|
|
129
129
|
transaction._objectStoresCache.delete(name);
|
|
130
130
|
}
|
|
131
131
|
transaction(storeNames, mode, options) {
|
|
132
|
+
// storeNames is a `(DOMString or sequence<DOMString>)`: any iterable, like `db.objectStoreNames`, is a
|
|
133
|
+
// sequence, and anything else is converted to a string. https://webidl.spec.whatwg.org/#es-union
|
|
134
|
+
const scope = typeof storeNames === "object" && storeNames !== null && storeNames[Symbol.iterator] != null ? Array.from(storeNames, storeName => `${storeName}`) : [`${storeNames}`];
|
|
132
135
|
mode = mode !== undefined ? mode : "readonly";
|
|
133
136
|
if (mode !== "readonly" && mode !== "readwrite" && mode !== "versionchange") {
|
|
134
137
|
throw new TypeError("Invalid mode: " + mode);
|
|
@@ -142,17 +145,19 @@ class FDBDatabase extends _FakeEventTarget.default {
|
|
|
142
145
|
if (this._closePending) {
|
|
143
146
|
throw new _errors.InvalidStateError();
|
|
144
147
|
}
|
|
145
|
-
|
|
146
|
-
storeNames = [storeNames];
|
|
147
|
-
}
|
|
148
|
-
if (storeNames.length === 0 && mode !== "versionchange") {
|
|
149
|
-
throw new _errors.InvalidAccessError();
|
|
150
|
-
}
|
|
151
|
-
for (const storeName of storeNames) {
|
|
148
|
+
for (const storeName of scope) {
|
|
152
149
|
if (!this.objectStoreNames.contains(storeName)) {
|
|
153
150
|
throw new _errors.NotFoundError("No objectStore named " + storeName + " in this database");
|
|
154
151
|
}
|
|
155
152
|
}
|
|
153
|
+
if (scope.length === 0) {
|
|
154
|
+
throw new _errors.InvalidAccessError();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// "versionchange" is a valid IDBTransactionMode, but only an upgrade can create such a transaction
|
|
158
|
+
if (mode !== "readonly" && mode !== "readwrite") {
|
|
159
|
+
throw new TypeError("Invalid mode: " + mode);
|
|
160
|
+
}
|
|
156
161
|
|
|
157
162
|
// the actual algo is more complex but this passes the IDB tests: https://webidl.spec.whatwg.org/#es-dictionary
|
|
158
163
|
const durability = options?.durability ?? "default";
|
|
@@ -162,6 +167,11 @@ class FDBDatabase extends _FakeEventTarget.default {
|
|
|
162
167
|
// based on Firefox's error message
|
|
163
168
|
`'${durability}' (value of 'durability' member of IDBTransactionOptions) ` + `is not a valid value for enumeration IDBTransactionDurability`);
|
|
164
169
|
}
|
|
170
|
+
return this._createTransaction(scope, mode, durability);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Used by `transaction()`, and by `FDBFactory` to create the upgrade transaction
|
|
174
|
+
_createTransaction(storeNames, mode, durability) {
|
|
165
175
|
const tx = new _FDBTransaction.default(storeNames, mode, durability, this);
|
|
166
176
|
this._rawDatabase.transactions.push(tx);
|
|
167
177
|
this._rawDatabase.processTransactions(); // See if can start right away (async)
|
package/build/cjs/FDBFactory.js
CHANGED
|
@@ -169,7 +169,7 @@ const runVersionchangeTransaction = (connection, version, request, cb) => {
|
|
|
169
169
|
connection.version = version;
|
|
170
170
|
|
|
171
171
|
// Get rid of this setImmediate?
|
|
172
|
-
const transaction = connection.
|
|
172
|
+
const transaction = connection._createTransaction(Array.from(connection.objectStoreNames), "versionchange", "default");
|
|
173
173
|
|
|
174
174
|
// associate the transaction with the open request for later lookup
|
|
175
175
|
transaction._openRequest = request;
|
|
@@ -271,9 +271,12 @@ class FDBTransaction extends _FakeEventTarget.default {
|
|
|
271
271
|
const idx = transactions.indexOf(this);
|
|
272
272
|
if (idx !== -1) {
|
|
273
273
|
transactions.splice(idx, 1);
|
|
274
|
-
} else {
|
|
275
|
-
throw new Error("should have been able to remove transaction");
|
|
276
274
|
}
|
|
275
|
+
// Note: it's possible to hit this twice in the same aborted transaction
|
|
276
|
+
// due to an abort inside an `onerror` (issue #173). In that case we hit:
|
|
277
|
+
// 1. once due to the user's `abort()`
|
|
278
|
+
// 2. once again due to the `if (!event.canceled)` above
|
|
279
|
+
// So we can just ignore the fact that the transaction was already removed
|
|
277
280
|
});
|
|
278
281
|
}
|
|
279
282
|
commit() {
|
package/build/cjs/lib/Index.js
CHANGED
|
@@ -99,11 +99,13 @@ class Index {
|
|
|
99
99
|
}
|
|
100
100
|
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
101
101
|
try {
|
|
102
|
-
|
|
102
|
+
// "Convert a value to a key": a single key path returns the
|
|
103
|
+
// value as-is (e.g. a typed array), so store the converted
|
|
104
|
+
// key, not the raw value.
|
|
105
|
+
return (0, _valueToKey.default)(indexKey);
|
|
103
106
|
} catch (e) {
|
|
104
107
|
return;
|
|
105
108
|
}
|
|
106
|
-
return indexKey;
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
// remove any elements from index key that are not valid keys and remove any duplicate elements from index
|
|
@@ -8,6 +8,7 @@ var _FDBRecord = _interopRequireDefault(require("../FDBRecord.js"));
|
|
|
8
8
|
var _errors = require("./errors.js");
|
|
9
9
|
var _extractKey = _interopRequireDefault(require("./extractKey.js"));
|
|
10
10
|
var _KeyGenerator = _interopRequireDefault(require("./KeyGenerator.js"));
|
|
11
|
+
var _valueToKey = _interopRequireDefault(require("./valueToKey.js"));
|
|
11
12
|
var _RecordStore = _interopRequireDefault(require("./RecordStore.js"));
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
14
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-object-store
|
|
@@ -86,7 +87,11 @@ class ObjectStore {
|
|
|
86
87
|
if (this.keyPath !== null) {
|
|
87
88
|
const key = (0, _extractKey.default)(this.keyPath, newRecord.value).key;
|
|
88
89
|
if (key !== undefined) {
|
|
89
|
-
|
|
90
|
+
// "Convert a value to a key": a single key path returns the
|
|
91
|
+
// value as-is (e.g. a typed array), so convert it here. For
|
|
92
|
+
// an array key path, extractKey already converted each part
|
|
93
|
+
// and valueToKey is idempotent on converted keys.
|
|
94
|
+
newRecord.key = (0, _valueToKey.default)(key);
|
|
90
95
|
}
|
|
91
96
|
}
|
|
92
97
|
const rollbackLogForThisOperation = [];
|
package/build/esm/FDBDatabase.js
CHANGED
|
@@ -122,6 +122,9 @@ class FDBDatabase extends FakeEventTarget {
|
|
|
122
122
|
transaction._objectStoresCache.delete(name);
|
|
123
123
|
}
|
|
124
124
|
transaction(storeNames, mode, options) {
|
|
125
|
+
// storeNames is a `(DOMString or sequence<DOMString>)`: any iterable, like `db.objectStoreNames`, is a
|
|
126
|
+
// sequence, and anything else is converted to a string. https://webidl.spec.whatwg.org/#es-union
|
|
127
|
+
const scope = typeof storeNames === "object" && storeNames !== null && storeNames[Symbol.iterator] != null ? Array.from(storeNames, storeName => `${storeName}`) : [`${storeNames}`];
|
|
125
128
|
mode = mode !== undefined ? mode : "readonly";
|
|
126
129
|
if (mode !== "readonly" && mode !== "readwrite" && mode !== "versionchange") {
|
|
127
130
|
throw new TypeError("Invalid mode: " + mode);
|
|
@@ -135,17 +138,19 @@ class FDBDatabase extends FakeEventTarget {
|
|
|
135
138
|
if (this._closePending) {
|
|
136
139
|
throw new InvalidStateError();
|
|
137
140
|
}
|
|
138
|
-
|
|
139
|
-
storeNames = [storeNames];
|
|
140
|
-
}
|
|
141
|
-
if (storeNames.length === 0 && mode !== "versionchange") {
|
|
142
|
-
throw new InvalidAccessError();
|
|
143
|
-
}
|
|
144
|
-
for (const storeName of storeNames) {
|
|
141
|
+
for (const storeName of scope) {
|
|
145
142
|
if (!this.objectStoreNames.contains(storeName)) {
|
|
146
143
|
throw new NotFoundError("No objectStore named " + storeName + " in this database");
|
|
147
144
|
}
|
|
148
145
|
}
|
|
146
|
+
if (scope.length === 0) {
|
|
147
|
+
throw new InvalidAccessError();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// "versionchange" is a valid IDBTransactionMode, but only an upgrade can create such a transaction
|
|
151
|
+
if (mode !== "readonly" && mode !== "readwrite") {
|
|
152
|
+
throw new TypeError("Invalid mode: " + mode);
|
|
153
|
+
}
|
|
149
154
|
|
|
150
155
|
// the actual algo is more complex but this passes the IDB tests: https://webidl.spec.whatwg.org/#es-dictionary
|
|
151
156
|
const durability = options?.durability ?? "default";
|
|
@@ -155,6 +160,11 @@ class FDBDatabase extends FakeEventTarget {
|
|
|
155
160
|
// based on Firefox's error message
|
|
156
161
|
`'${durability}' (value of 'durability' member of IDBTransactionOptions) ` + `is not a valid value for enumeration IDBTransactionDurability`);
|
|
157
162
|
}
|
|
163
|
+
return this._createTransaction(scope, mode, durability);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Used by `transaction()`, and by `FDBFactory` to create the upgrade transaction
|
|
167
|
+
_createTransaction(storeNames, mode, durability) {
|
|
158
168
|
const tx = new FDBTransaction(storeNames, mode, durability, this);
|
|
159
169
|
this._rawDatabase.transactions.push(tx);
|
|
160
170
|
this._rawDatabase.processTransactions(); // See if can start right away (async)
|
package/build/esm/FDBFactory.js
CHANGED
|
@@ -162,7 +162,7 @@ const runVersionchangeTransaction = (connection, version, request, cb) => {
|
|
|
162
162
|
connection.version = version;
|
|
163
163
|
|
|
164
164
|
// Get rid of this setImmediate?
|
|
165
|
-
const transaction = connection.
|
|
165
|
+
const transaction = connection._createTransaction(Array.from(connection.objectStoreNames), "versionchange", "default");
|
|
166
166
|
|
|
167
167
|
// associate the transaction with the open request for later lookup
|
|
168
168
|
transaction._openRequest = request;
|
|
@@ -264,9 +264,12 @@ class FDBTransaction extends FakeEventTarget {
|
|
|
264
264
|
const idx = transactions.indexOf(this);
|
|
265
265
|
if (idx !== -1) {
|
|
266
266
|
transactions.splice(idx, 1);
|
|
267
|
-
} else {
|
|
268
|
-
throw new Error("should have been able to remove transaction");
|
|
269
267
|
}
|
|
268
|
+
// Note: it's possible to hit this twice in the same aborted transaction
|
|
269
|
+
// due to an abort inside an `onerror` (issue #173). In that case we hit:
|
|
270
|
+
// 1. once due to the user's `abort()`
|
|
271
|
+
// 2. once again due to the `if (!event.canceled)` above
|
|
272
|
+
// So we can just ignore the fact that the transaction was already removed
|
|
270
273
|
});
|
|
271
274
|
}
|
|
272
275
|
commit() {
|
package/build/esm/lib/Index.js
CHANGED
|
@@ -92,11 +92,13 @@ class Index {
|
|
|
92
92
|
}
|
|
93
93
|
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
94
94
|
try {
|
|
95
|
-
|
|
95
|
+
// "Convert a value to a key": a single key path returns the
|
|
96
|
+
// value as-is (e.g. a typed array), so store the converted
|
|
97
|
+
// key, not the raw value.
|
|
98
|
+
return valueToKey(indexKey);
|
|
96
99
|
} catch (e) {
|
|
97
100
|
return;
|
|
98
101
|
}
|
|
99
|
-
return indexKey;
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
// remove any elements from index key that are not valid keys and remove any duplicate elements from index
|
|
@@ -2,6 +2,7 @@ import FDBRecord from "../FDBRecord.js";
|
|
|
2
2
|
import { DataError } from "./errors.js";
|
|
3
3
|
import extractKey from "./extractKey.js";
|
|
4
4
|
import KeyGenerator from "./KeyGenerator.js";
|
|
5
|
+
import valueToKey from "./valueToKey.js";
|
|
5
6
|
import RecordStore from "./RecordStore.js";
|
|
6
7
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-object-store
|
|
7
8
|
class ObjectStore {
|
|
@@ -79,7 +80,11 @@ class ObjectStore {
|
|
|
79
80
|
if (this.keyPath !== null) {
|
|
80
81
|
const key = extractKey(this.keyPath, newRecord.value).key;
|
|
81
82
|
if (key !== undefined) {
|
|
82
|
-
|
|
83
|
+
// "Convert a value to a key": a single key path returns the
|
|
84
|
+
// value as-is (e.g. a typed array), so convert it here. For
|
|
85
|
+
// an array key path, extractKey already converted each part
|
|
86
|
+
// and valueToKey is idempotent on converted keys.
|
|
87
|
+
newRecord.key = valueToKey(key);
|
|
83
88
|
}
|
|
84
89
|
}
|
|
85
90
|
const rollbackLogForThisOperation = [];
|
package/package.json
CHANGED