fake-indexeddb 6.2.6 → 6.2.7
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/lib/Index.js +47 -22
- package/build/cjs/lib/ObjectStore.js +4 -2
- package/build/cjs/lib/RecordStore.js +14 -9
- package/build/esm/lib/Index.js +47 -22
- package/build/esm/lib/ObjectStore.js +4 -2
- package/build/esm/lib/RecordStore.js +14 -9
- package/package.json +1 -1
- package/build/cjs/test/fakeIndexedDB/auto.js +0 -54
- package/build/cjs/test/fakeIndexedDB/binarySearchTree.js +0 -413
- package/build/cjs/test/fakeIndexedDB/fakeIndexedDB.js +0 -1018
- package/build/cjs/test/fakeIndexedDB/forceCloseDatabase.js +0 -99
- package/build/cjs/test/fakeIndexedDB/getAll.js +0 -707
- package/build/cjs/test/fakeIndexedDB/memoryLeaks.js +0 -42
- package/build/esm/test/fakeIndexedDB/auto.js +0 -52
- package/build/esm/test/fakeIndexedDB/binarySearchTree.js +0 -409
- package/build/esm/test/fakeIndexedDB/fakeIndexedDB.js +0 -1014
- package/build/esm/test/fakeIndexedDB/forceCloseDatabase.js +0 -95
- package/build/esm/test/fakeIndexedDB/getAll.js +0 -703
- package/build/esm/test/fakeIndexedDB/memoryLeaks.js +0 -38
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 -->October 29, 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=1678 -->
|
|
213
213
|
| Implementation | Version | Passed | % |
|
|
214
214
|
| --- | --- | --- | --- |
|
|
215
|
-
| Chrome |
|
|
216
|
-
| Firefox |
|
|
217
|
-
| Safari |
|
|
218
|
-
| Ladybird | 1.0-
|
|
219
|
-
| fake-indexeddb | 6.2.
|
|
215
|
+
| Chrome | 159.0.8130.0 | 1672 | 99.6% |
|
|
216
|
+
| Firefox | 161.0a1 | 1671 | 99.6% |
|
|
217
|
+
| Safari | 255 preview | 1676 | 99.9% |
|
|
218
|
+
| Ladybird | 1.0-28077c350dc | 1668 | 99.4% |
|
|
219
|
+
| fake-indexeddb | 6.2.7 | 1369 | 81.6% |
|
|
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/lib/Index.js
CHANGED
|
@@ -82,11 +82,14 @@ class Index {
|
|
|
82
82
|
return records;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
//
|
|
86
|
-
|
|
85
|
+
// The index key that an object store record with this value is stored under, or undefined if the value does not
|
|
86
|
+
// belong in this index. For a multiEntry index given an array, this is the array of individual index keys (invalid
|
|
87
|
+
// and duplicate elements removed). Shared by storeRecord and deleteRecord so that deletion finds exactly what
|
|
88
|
+
// insertion stored.
|
|
89
|
+
getIndexKey(value) {
|
|
87
90
|
let indexKey;
|
|
88
91
|
try {
|
|
89
|
-
indexKey = (0, _extractKey.default)(this.keyPath,
|
|
92
|
+
indexKey = (0, _extractKey.default)(this.keyPath, value).key;
|
|
90
93
|
} catch (err) {
|
|
91
94
|
if (err.name === "DataError") {
|
|
92
95
|
// Invalid key is not an actual error, just means we do not store an entry in this index
|
|
@@ -100,20 +103,29 @@ class Index {
|
|
|
100
103
|
} catch (e) {
|
|
101
104
|
return;
|
|
102
105
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
106
|
+
return indexKey;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// remove any elements from index key that are not valid keys and remove any duplicate elements from index
|
|
110
|
+
// key such that only one instance of the duplicate value remains.
|
|
111
|
+
const keep = [];
|
|
112
|
+
for (const part of indexKey) {
|
|
113
|
+
if (keep.indexOf(part) < 0) {
|
|
114
|
+
try {
|
|
115
|
+
keep.push((0, _valueToKey.default)(part));
|
|
116
|
+
} catch (err) {
|
|
117
|
+
/* Do nothing */
|
|
114
118
|
}
|
|
115
119
|
}
|
|
116
|
-
|
|
120
|
+
}
|
|
121
|
+
return keep;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-storing-a-record-into-an-object-store (step 7)
|
|
125
|
+
storeRecord(newRecord) {
|
|
126
|
+
const indexKey = this.getIndexKey(newRecord.value);
|
|
127
|
+
if (indexKey === undefined) {
|
|
128
|
+
return;
|
|
117
129
|
}
|
|
118
130
|
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
119
131
|
if (this.unique) {
|
|
@@ -122,6 +134,10 @@ class Index {
|
|
|
122
134
|
throw new _errors.ConstraintError();
|
|
123
135
|
}
|
|
124
136
|
}
|
|
137
|
+
this.records.put({
|
|
138
|
+
key: indexKey,
|
|
139
|
+
value: newRecord.key
|
|
140
|
+
});
|
|
125
141
|
} else {
|
|
126
142
|
if (this.unique) {
|
|
127
143
|
for (const individualIndexKey of indexKey) {
|
|
@@ -131,13 +147,6 @@ class Index {
|
|
|
131
147
|
}
|
|
132
148
|
}
|
|
133
149
|
}
|
|
134
|
-
}
|
|
135
|
-
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
136
|
-
this.records.put({
|
|
137
|
-
key: indexKey,
|
|
138
|
-
value: newRecord.key
|
|
139
|
-
});
|
|
140
|
-
} else {
|
|
141
150
|
for (const individualIndexKey of indexKey) {
|
|
142
151
|
this.records.put({
|
|
143
152
|
key: individualIndexKey,
|
|
@@ -146,6 +155,22 @@ class Index {
|
|
|
146
155
|
}
|
|
147
156
|
}
|
|
148
157
|
}
|
|
158
|
+
|
|
159
|
+
// Remove the index records that storeRecord created for this object store record. Looking them up by index key is
|
|
160
|
+
// O(log n) per index record, where scanning the whole index for records pointing at this primary key is O(n).
|
|
161
|
+
deleteRecord(record) {
|
|
162
|
+
const indexKey = this.getIndexKey(record.value);
|
|
163
|
+
if (indexKey === undefined) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
167
|
+
this.records.deleteByKeyAndValue(indexKey, record.key);
|
|
168
|
+
} else {
|
|
169
|
+
for (const individualIndexKey of indexKey) {
|
|
170
|
+
this.records.deleteByKeyAndValue(individualIndexKey, record.key);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
149
174
|
initialize(transaction) {
|
|
150
175
|
if (this.initialized) {
|
|
151
176
|
throw new Error("Index already initialized");
|
|
@@ -176,7 +176,7 @@ class ObjectStore {
|
|
|
176
176
|
// Delete existing indexes
|
|
177
177
|
if (existingRecord) {
|
|
178
178
|
for (const rawIndex of this.rawIndexes.values()) {
|
|
179
|
-
rawIndex.
|
|
179
|
+
rawIndex.deleteRecord(existingRecord);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
|
|
@@ -210,7 +210,9 @@ class ObjectStore {
|
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
212
|
for (const rawIndex of this.rawIndexes.values()) {
|
|
213
|
-
|
|
213
|
+
for (const record of deletedRecords) {
|
|
214
|
+
rawIndex.deleteRecord(record);
|
|
215
|
+
}
|
|
214
216
|
}
|
|
215
217
|
}
|
|
216
218
|
|
|
@@ -34,16 +34,21 @@ class RecordStore {
|
|
|
34
34
|
}
|
|
35
35
|
return deletedRecords;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Delete the record with this key and this value, if there is one. Used by indexes, where the value is the primary
|
|
40
|
+
* key of the object store record that the index record points to.
|
|
41
|
+
*/
|
|
42
|
+
deleteByKeyAndValue(key, value) {
|
|
43
|
+
// In a non-unique store the value is part of the sort order, so this finds the exact record. In a unique store
|
|
44
|
+
// it finds the only record with this key, which may point at a different primary key.
|
|
45
|
+
const record = this.records.get({
|
|
46
|
+
key,
|
|
47
|
+
value
|
|
48
|
+
});
|
|
49
|
+
if (record !== undefined && (0, _cmp.cmpKeys)(record.value, value) === 0) {
|
|
50
|
+
this.records.delete(record);
|
|
45
51
|
}
|
|
46
|
-
return deletedRecords;
|
|
47
52
|
}
|
|
48
53
|
clear() {
|
|
49
54
|
const deletedRecords = [...this.records.getAllRecords()];
|
package/build/esm/lib/Index.js
CHANGED
|
@@ -75,11 +75,14 @@ class Index {
|
|
|
75
75
|
return records;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
//
|
|
79
|
-
|
|
78
|
+
// The index key that an object store record with this value is stored under, or undefined if the value does not
|
|
79
|
+
// belong in this index. For a multiEntry index given an array, this is the array of individual index keys (invalid
|
|
80
|
+
// and duplicate elements removed). Shared by storeRecord and deleteRecord so that deletion finds exactly what
|
|
81
|
+
// insertion stored.
|
|
82
|
+
getIndexKey(value) {
|
|
80
83
|
let indexKey;
|
|
81
84
|
try {
|
|
82
|
-
indexKey = extractKey(this.keyPath,
|
|
85
|
+
indexKey = extractKey(this.keyPath, value).key;
|
|
83
86
|
} catch (err) {
|
|
84
87
|
if (err.name === "DataError") {
|
|
85
88
|
// Invalid key is not an actual error, just means we do not store an entry in this index
|
|
@@ -93,20 +96,29 @@ class Index {
|
|
|
93
96
|
} catch (e) {
|
|
94
97
|
return;
|
|
95
98
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
return indexKey;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// remove any elements from index key that are not valid keys and remove any duplicate elements from index
|
|
103
|
+
// key such that only one instance of the duplicate value remains.
|
|
104
|
+
const keep = [];
|
|
105
|
+
for (const part of indexKey) {
|
|
106
|
+
if (keep.indexOf(part) < 0) {
|
|
107
|
+
try {
|
|
108
|
+
keep.push(valueToKey(part));
|
|
109
|
+
} catch (err) {
|
|
110
|
+
/* Do nothing */
|
|
107
111
|
}
|
|
108
112
|
}
|
|
109
|
-
|
|
113
|
+
}
|
|
114
|
+
return keep;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-storing-a-record-into-an-object-store (step 7)
|
|
118
|
+
storeRecord(newRecord) {
|
|
119
|
+
const indexKey = this.getIndexKey(newRecord.value);
|
|
120
|
+
if (indexKey === undefined) {
|
|
121
|
+
return;
|
|
110
122
|
}
|
|
111
123
|
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
112
124
|
if (this.unique) {
|
|
@@ -115,6 +127,10 @@ class Index {
|
|
|
115
127
|
throw new ConstraintError();
|
|
116
128
|
}
|
|
117
129
|
}
|
|
130
|
+
this.records.put({
|
|
131
|
+
key: indexKey,
|
|
132
|
+
value: newRecord.key
|
|
133
|
+
});
|
|
118
134
|
} else {
|
|
119
135
|
if (this.unique) {
|
|
120
136
|
for (const individualIndexKey of indexKey) {
|
|
@@ -124,13 +140,6 @@ class Index {
|
|
|
124
140
|
}
|
|
125
141
|
}
|
|
126
142
|
}
|
|
127
|
-
}
|
|
128
|
-
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
129
|
-
this.records.put({
|
|
130
|
-
key: indexKey,
|
|
131
|
-
value: newRecord.key
|
|
132
|
-
});
|
|
133
|
-
} else {
|
|
134
143
|
for (const individualIndexKey of indexKey) {
|
|
135
144
|
this.records.put({
|
|
136
145
|
key: individualIndexKey,
|
|
@@ -139,6 +148,22 @@ class Index {
|
|
|
139
148
|
}
|
|
140
149
|
}
|
|
141
150
|
}
|
|
151
|
+
|
|
152
|
+
// Remove the index records that storeRecord created for this object store record. Looking them up by index key is
|
|
153
|
+
// O(log n) per index record, where scanning the whole index for records pointing at this primary key is O(n).
|
|
154
|
+
deleteRecord(record) {
|
|
155
|
+
const indexKey = this.getIndexKey(record.value);
|
|
156
|
+
if (indexKey === undefined) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (!this.multiEntry || !Array.isArray(indexKey)) {
|
|
160
|
+
this.records.deleteByKeyAndValue(indexKey, record.key);
|
|
161
|
+
} else {
|
|
162
|
+
for (const individualIndexKey of indexKey) {
|
|
163
|
+
this.records.deleteByKeyAndValue(individualIndexKey, record.key);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
142
167
|
initialize(transaction) {
|
|
143
168
|
if (this.initialized) {
|
|
144
169
|
throw new Error("Index already initialized");
|
|
@@ -169,7 +169,7 @@ class ObjectStore {
|
|
|
169
169
|
// Delete existing indexes
|
|
170
170
|
if (existingRecord) {
|
|
171
171
|
for (const rawIndex of this.rawIndexes.values()) {
|
|
172
|
-
rawIndex.
|
|
172
|
+
rawIndex.deleteRecord(existingRecord);
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
|
|
@@ -203,7 +203,9 @@ class ObjectStore {
|
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
for (const rawIndex of this.rawIndexes.values()) {
|
|
206
|
-
|
|
206
|
+
for (const record of deletedRecords) {
|
|
207
|
+
rawIndex.deleteRecord(record);
|
|
208
|
+
}
|
|
207
209
|
}
|
|
208
210
|
}
|
|
209
211
|
|
|
@@ -27,16 +27,21 @@ class RecordStore {
|
|
|
27
27
|
}
|
|
28
28
|
return deletedRecords;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Delete the record with this key and this value, if there is one. Used by indexes, where the value is the primary
|
|
33
|
+
* key of the object store record that the index record points to.
|
|
34
|
+
*/
|
|
35
|
+
deleteByKeyAndValue(key, value) {
|
|
36
|
+
// In a non-unique store the value is part of the sort order, so this finds the exact record. In a unique store
|
|
37
|
+
// it finds the only record with this key, which may point at a different primary key.
|
|
38
|
+
const record = this.records.get({
|
|
39
|
+
key,
|
|
40
|
+
value
|
|
41
|
+
});
|
|
42
|
+
if (record !== undefined && cmpKeys(record.value, value) === 0) {
|
|
43
|
+
this.records.delete(record);
|
|
38
44
|
}
|
|
39
|
-
return deletedRecords;
|
|
40
45
|
}
|
|
41
46
|
clear() {
|
|
42
47
|
const deletedRecords = [...this.records.getAllRecords()];
|
package/package.json
CHANGED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var assert = _interopRequireWildcard(require("assert"));
|
|
4
|
-
var fakeIndexedDB = _interopRequireWildcard(require("../../index.js"));
|
|
5
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
6
|
-
// `indexedDB` is read-only, all others are read-write
|
|
7
|
-
const props = Object.keys(fakeIndexedDB).filter(prop => prop.startsWith("IDB") || prop === "indexedDB");
|
|
8
|
-
describe("auto", () => {
|
|
9
|
-
it("correctly overrides globals in fake-indexeddb/auto", async () => {
|
|
10
|
-
// simulate what the native property descriptors do
|
|
11
|
-
Object.defineProperty(globalThis, "indexedDB", {
|
|
12
|
-
set: undefined,
|
|
13
|
-
get: () => undefined,
|
|
14
|
-
enumerable: false,
|
|
15
|
-
configurable: true
|
|
16
|
-
});
|
|
17
|
-
for (const prop of props) {
|
|
18
|
-
Object.defineProperty(globalThis, prop, {
|
|
19
|
-
value: undefined,
|
|
20
|
-
enumerable: false,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// @ts-expect-error relative to the build/ directory
|
|
27
|
-
await import("../../../../auto/index.mjs");
|
|
28
|
-
|
|
29
|
-
// check our own globals
|
|
30
|
-
for (const prop of props) {
|
|
31
|
-
const descriptor = Object.getOwnPropertyDescriptor(globalThis, prop);
|
|
32
|
-
assert.equal(descriptor.value, fakeIndexedDB[prop]);
|
|
33
|
-
assert.equal(descriptor.enumerable, false);
|
|
34
|
-
assert.equal(descriptor.configurable, true);
|
|
35
|
-
assert.equal(descriptor.writable, true);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// check that we can still overwrite them with `globalThis.<prop> = ...`
|
|
39
|
-
for (const prop of props) {
|
|
40
|
-
const fake = {};
|
|
41
|
-
globalThis[prop] = fake;
|
|
42
|
-
assert.equal(globalThis[prop], fake);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
it("exports as cjs directly, without `default` member - issue #130", async () => {
|
|
46
|
-
// @ts-expect-error relative to the build/ directory
|
|
47
|
-
await import("../../../../auto/index.js");
|
|
48
|
-
|
|
49
|
-
// ensure we directly set the export as `module.exports` rather than `module.exports.default`
|
|
50
|
-
for (const prop of props) {
|
|
51
|
-
assert.ok(!globalThis[prop].default);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
});
|