fake-indexeddb 6.2.4 → 6.2.5
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/FDBFactory.js +7 -5
- package/build/cjs/FDBTransaction.js +10 -0
- package/build/cjs/lib/FakeEventTarget.js +6 -3
- package/build/esm/FDBFactory.js +7 -5
- package/build/esm/FDBTransaction.js +10 -0
- package/build/esm/lib/FakeEventTarget.js +6 -3
- 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 -->November 7, 2025<!-- 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=1653 -->
|
|
213
213
|
| Implementation | Version | Passed | % |
|
|
214
214
|
| --- | --- | --- | --- |
|
|
215
|
-
| Chrome |
|
|
216
|
-
| Firefox | 146.0a1 | 1498 | 90.
|
|
217
|
-
| Safari |
|
|
218
|
-
| Ladybird | 1.0-
|
|
219
|
-
| fake-indexeddb | 6.2.
|
|
215
|
+
| Chrome | 144.0.7514.0 | 1651 | 99.9% |
|
|
216
|
+
| Firefox | 146.0a1 | 1498 | 90.6% |
|
|
217
|
+
| Safari | 231 preview | 1497 | 90.6% |
|
|
218
|
+
| Ladybird | 1.0-cde3941d9f | 1426 | 86.3% |
|
|
219
|
+
| fake-indexeddb | 6.2.5 | 1369 | 82.8% |
|
|
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/FDBFactory.js
CHANGED
|
@@ -221,26 +221,28 @@ const runVersionchangeTransaction = (connection, version, request, cb) => {
|
|
|
221
221
|
} else {
|
|
222
222
|
(0, _scheduling.queueTask)(concludeUpgrade);
|
|
223
223
|
}
|
|
224
|
-
transaction.
|
|
224
|
+
transaction._prioritizedListeners.set("error", () => {
|
|
225
225
|
connection._runningVersionchangeTransaction = false;
|
|
226
226
|
connection._oldVersion = undefined;
|
|
227
227
|
// throw arguments[0].target.error;
|
|
228
228
|
// console.log("error in versionchange transaction - not sure if anything needs to be done here", e.target.error.name);
|
|
229
229
|
});
|
|
230
|
-
transaction.
|
|
230
|
+
transaction._prioritizedListeners.set("abort", () => {
|
|
231
231
|
connection._runningVersionchangeTransaction = false;
|
|
232
232
|
connection._oldVersion = undefined;
|
|
233
|
-
request.transaction = null;
|
|
234
233
|
(0, _scheduling.queueTask)(() => {
|
|
234
|
+
// Reset transaction in a tick after onabort (upgrade-transaction-lifecycle-user-aborted.any)
|
|
235
|
+
request.transaction = null;
|
|
235
236
|
cb(new _errors.AbortError());
|
|
236
237
|
});
|
|
237
238
|
});
|
|
238
|
-
transaction.
|
|
239
|
+
transaction._prioritizedListeners.set("complete", () => {
|
|
239
240
|
connection._runningVersionchangeTransaction = false;
|
|
240
241
|
connection._oldVersion = undefined;
|
|
241
|
-
request.transaction = null;
|
|
242
242
|
// Let other complete event handlers run before continuing
|
|
243
243
|
(0, _scheduling.queueTask)(() => {
|
|
244
|
+
// Reset transaction in a tick after oncomplete (upgrade-transaction-lifecycle-committed.any.js)
|
|
245
|
+
request.transaction = null;
|
|
244
246
|
if (connection._closePending) {
|
|
245
247
|
cb(new _errors.AbortError());
|
|
246
248
|
} else {
|
|
@@ -12,6 +12,7 @@ var _FakeEvent = _interopRequireDefault(require("./lib/FakeEvent.js"));
|
|
|
12
12
|
var _FakeEventTarget = _interopRequireDefault(require("./lib/FakeEventTarget.js"));
|
|
13
13
|
var _scheduling = require("./lib/scheduling.js");
|
|
14
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
const prioritizedListenerTypes = ["error", "abort", "complete"];
|
|
15
16
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#transaction
|
|
16
17
|
class FDBTransaction extends _FakeEventTarget.default {
|
|
17
18
|
_state = "active";
|
|
@@ -23,6 +24,7 @@ class FDBTransaction extends _FakeEventTarget.default {
|
|
|
23
24
|
onabort = null;
|
|
24
25
|
oncomplete = null;
|
|
25
26
|
onerror = null;
|
|
27
|
+
_prioritizedListeners = new Map();
|
|
26
28
|
_requests = [];
|
|
27
29
|
_createdIndexes = new Set();
|
|
28
30
|
_createdObjectStores = new Set();
|
|
@@ -33,6 +35,14 @@ class FDBTransaction extends _FakeEventTarget.default {
|
|
|
33
35
|
this.durability = durability;
|
|
34
36
|
this.db = db;
|
|
35
37
|
this.objectStoreNames = new _FakeDOMStringList.default(...Array.from(this._scope).sort());
|
|
38
|
+
for (const type of prioritizedListenerTypes) {
|
|
39
|
+
// Attach prioritized (internal) listeners before any external listeners are attached.
|
|
40
|
+
// This ensures that these listeners run with the same timing regardless of whether
|
|
41
|
+
// the user uses `on*` or `addEventListener` for event listeners.
|
|
42
|
+
this.addEventListener(type, () => {
|
|
43
|
+
this._prioritizedListeners.get(type)?.();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
// https://w3c.github.io/IndexedDB/#abort-transaction
|
|
@@ -13,8 +13,9 @@ const stopped = (event, listener) => {
|
|
|
13
13
|
const invokeEventListeners = (event, obj) => {
|
|
14
14
|
event.currentTarget = obj;
|
|
15
15
|
const errors = [];
|
|
16
|
-
const invoke =
|
|
16
|
+
const invoke = callbackOrObject => {
|
|
17
17
|
try {
|
|
18
|
+
const callback = typeof callbackOrObject === "function" ? callbackOrObject : callbackOrObject.handleEvent;
|
|
18
19
|
// @ts-expect-error EventCallback's types are not quite right here
|
|
19
20
|
callback.call(event.currentTarget, event);
|
|
20
21
|
} catch (err) {
|
|
@@ -68,14 +69,16 @@ class FakeEventTarget {
|
|
|
68
69
|
|
|
69
70
|
// These will be overridden in individual subclasses and made not readonly
|
|
70
71
|
|
|
71
|
-
addEventListener(type, callback,
|
|
72
|
+
addEventListener(type, callback, options) {
|
|
73
|
+
const capture = !!(typeof options === "object" && options ? options.capture : options);
|
|
72
74
|
this.listeners.push({
|
|
73
75
|
callback,
|
|
74
76
|
capture,
|
|
75
77
|
type
|
|
76
78
|
});
|
|
77
79
|
}
|
|
78
|
-
removeEventListener(type, callback,
|
|
80
|
+
removeEventListener(type, callback, options) {
|
|
81
|
+
const capture = !!(typeof options === "object" && options ? options.capture : options);
|
|
79
82
|
const i = this.listeners.findIndex(listener => {
|
|
80
83
|
return listener.type === type && listener.callback === callback && listener.capture === capture;
|
|
81
84
|
});
|
package/build/esm/FDBFactory.js
CHANGED
|
@@ -214,26 +214,28 @@ const runVersionchangeTransaction = (connection, version, request, cb) => {
|
|
|
214
214
|
} else {
|
|
215
215
|
queueTask(concludeUpgrade);
|
|
216
216
|
}
|
|
217
|
-
transaction.
|
|
217
|
+
transaction._prioritizedListeners.set("error", () => {
|
|
218
218
|
connection._runningVersionchangeTransaction = false;
|
|
219
219
|
connection._oldVersion = undefined;
|
|
220
220
|
// throw arguments[0].target.error;
|
|
221
221
|
// console.log("error in versionchange transaction - not sure if anything needs to be done here", e.target.error.name);
|
|
222
222
|
});
|
|
223
|
-
transaction.
|
|
223
|
+
transaction._prioritizedListeners.set("abort", () => {
|
|
224
224
|
connection._runningVersionchangeTransaction = false;
|
|
225
225
|
connection._oldVersion = undefined;
|
|
226
|
-
request.transaction = null;
|
|
227
226
|
queueTask(() => {
|
|
227
|
+
// Reset transaction in a tick after onabort (upgrade-transaction-lifecycle-user-aborted.any)
|
|
228
|
+
request.transaction = null;
|
|
228
229
|
cb(new AbortError());
|
|
229
230
|
});
|
|
230
231
|
});
|
|
231
|
-
transaction.
|
|
232
|
+
transaction._prioritizedListeners.set("complete", () => {
|
|
232
233
|
connection._runningVersionchangeTransaction = false;
|
|
233
234
|
connection._oldVersion = undefined;
|
|
234
|
-
request.transaction = null;
|
|
235
235
|
// Let other complete event handlers run before continuing
|
|
236
236
|
queueTask(() => {
|
|
237
|
+
// Reset transaction in a tick after oncomplete (upgrade-transaction-lifecycle-committed.any.js)
|
|
238
|
+
request.transaction = null;
|
|
237
239
|
if (connection._closePending) {
|
|
238
240
|
cb(new AbortError());
|
|
239
241
|
} else {
|
|
@@ -5,6 +5,7 @@ import FakeDOMStringList from "./lib/FakeDOMStringList.js";
|
|
|
5
5
|
import FakeEvent from "./lib/FakeEvent.js";
|
|
6
6
|
import FakeEventTarget from "./lib/FakeEventTarget.js";
|
|
7
7
|
import { queueTask } from "./lib/scheduling.js";
|
|
8
|
+
const prioritizedListenerTypes = ["error", "abort", "complete"];
|
|
8
9
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#transaction
|
|
9
10
|
class FDBTransaction extends FakeEventTarget {
|
|
10
11
|
_state = "active";
|
|
@@ -16,6 +17,7 @@ class FDBTransaction extends FakeEventTarget {
|
|
|
16
17
|
onabort = null;
|
|
17
18
|
oncomplete = null;
|
|
18
19
|
onerror = null;
|
|
20
|
+
_prioritizedListeners = new Map();
|
|
19
21
|
_requests = [];
|
|
20
22
|
_createdIndexes = new Set();
|
|
21
23
|
_createdObjectStores = new Set();
|
|
@@ -26,6 +28,14 @@ class FDBTransaction extends FakeEventTarget {
|
|
|
26
28
|
this.durability = durability;
|
|
27
29
|
this.db = db;
|
|
28
30
|
this.objectStoreNames = new FakeDOMStringList(...Array.from(this._scope).sort());
|
|
31
|
+
for (const type of prioritizedListenerTypes) {
|
|
32
|
+
// Attach prioritized (internal) listeners before any external listeners are attached.
|
|
33
|
+
// This ensures that these listeners run with the same timing regardless of whether
|
|
34
|
+
// the user uses `on*` or `addEventListener` for event listeners.
|
|
35
|
+
this.addEventListener(type, () => {
|
|
36
|
+
this._prioritizedListeners.get(type)?.();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
// https://w3c.github.io/IndexedDB/#abort-transaction
|
|
@@ -7,8 +7,9 @@ const stopped = (event, listener) => {
|
|
|
7
7
|
const invokeEventListeners = (event, obj) => {
|
|
8
8
|
event.currentTarget = obj;
|
|
9
9
|
const errors = [];
|
|
10
|
-
const invoke =
|
|
10
|
+
const invoke = callbackOrObject => {
|
|
11
11
|
try {
|
|
12
|
+
const callback = typeof callbackOrObject === "function" ? callbackOrObject : callbackOrObject.handleEvent;
|
|
12
13
|
// @ts-expect-error EventCallback's types are not quite right here
|
|
13
14
|
callback.call(event.currentTarget, event);
|
|
14
15
|
} catch (err) {
|
|
@@ -62,14 +63,16 @@ class FakeEventTarget {
|
|
|
62
63
|
|
|
63
64
|
// These will be overridden in individual subclasses and made not readonly
|
|
64
65
|
|
|
65
|
-
addEventListener(type, callback,
|
|
66
|
+
addEventListener(type, callback, options) {
|
|
67
|
+
const capture = !!(typeof options === "object" && options ? options.capture : options);
|
|
66
68
|
this.listeners.push({
|
|
67
69
|
callback,
|
|
68
70
|
capture,
|
|
69
71
|
type
|
|
70
72
|
});
|
|
71
73
|
}
|
|
72
|
-
removeEventListener(type, callback,
|
|
74
|
+
removeEventListener(type, callback, options) {
|
|
75
|
+
const capture = !!(typeof options === "object" && options ? options.capture : options);
|
|
73
76
|
const i = this.listeners.findIndex(listener => {
|
|
74
77
|
return listener.type === type && listener.callback === callback && listener.capture === capture;
|
|
75
78
|
});
|
package/package.json
CHANGED