fake-indexeddb 4.0.2 → 5.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 +0 -6
- package/build/cjs/FDBCursor.js +39 -159
- package/build/cjs/FDBCursorWithValue.js +1 -9
- package/build/cjs/FDBDatabase.js +9 -72
- package/build/cjs/FDBFactory.js +23 -66
- package/build/cjs/FDBIndex.js +17 -73
- package/build/cjs/FDBKeyRange.js +3 -28
- package/build/cjs/FDBObjectStore.js +25 -145
- package/build/cjs/FDBOpenDBRequest.js +1 -8
- package/build/cjs/FDBRequest.js +1 -15
- package/build/cjs/FDBTransaction.js +26 -64
- package/build/cjs/FDBVersionChangeEvent.js +1 -8
- package/build/cjs/fakeIndexedDB.js +1 -5
- package/build/cjs/index.js +1 -16
- package/build/cjs/lib/Database.js +1 -11
- package/build/cjs/lib/FakeDOMStringList.js +5 -13
- package/build/cjs/lib/FakeEvent.js +3 -10
- package/build/cjs/lib/FakeEventTarget.js +15 -32
- package/build/cjs/lib/Index.js +14 -46
- package/build/cjs/lib/KeyGenerator.js +3 -12
- package/build/cjs/lib/ObjectStore.js +24 -63
- package/build/cjs/lib/RecordStore.js +4 -42
- package/build/cjs/lib/binarySearch.js +5 -24
- package/build/cjs/lib/canInjectKey.js +2 -14
- package/build/cjs/lib/cmp.js +3 -29
- package/build/cjs/lib/enforceRange.js +2 -6
- package/build/cjs/lib/errors.js +0 -32
- package/build/cjs/lib/extractKey.js +2 -17
- package/build/cjs/lib/scheduling.js +4 -7
- package/build/cjs/lib/validateKeyPath.js +4 -16
- package/build/cjs/lib/valueToKey.js +2 -15
- package/build/cjs/lib/valueToKeyRange.js +1 -11
- package/build/esm/FDBCursor.js +33 -144
- package/build/esm/FDBCursorWithValue.js +0 -5
- package/build/esm/FDBDatabase.js +8 -62
- package/build/esm/FDBFactory.js +22 -54
- package/build/esm/FDBIndex.js +16 -61
- package/build/esm/FDBKeyRange.js +4 -22
- package/build/esm/FDBObjectStore.js +23 -126
- package/build/esm/FDBOpenDBRequest.js +0 -4
- package/build/esm/FDBRequest.js +0 -10
- package/build/esm/FDBTransaction.js +25 -54
- package/build/esm/FDBVersionChangeEvent.js +0 -4
- package/build/esm/lib/Database.js +2 -8
- package/build/esm/lib/FakeDOMStringList.js +4 -9
- package/build/esm/lib/FakeEvent.js +2 -7
- package/build/esm/lib/FakeEventTarget.js +14 -29
- package/build/esm/lib/Index.js +14 -37
- package/build/esm/lib/KeyGenerator.js +2 -8
- package/build/esm/lib/ObjectStore.js +19 -51
- package/build/esm/lib/RecordStore.js +3 -36
- package/build/esm/lib/binarySearch.js +5 -18
- package/build/esm/lib/canInjectKey.js +1 -11
- package/build/esm/lib/cmp.js +2 -24
- package/build/esm/lib/enforceRange.js +1 -3
- package/build/esm/lib/errors.js +0 -11
- package/build/esm/lib/extractKey.js +3 -13
- package/build/esm/lib/scheduling.js +3 -3
- package/build/esm/lib/validateKeyPath.js +3 -13
- package/build/esm/lib/valueToKey.js +1 -12
- package/build/esm/lib/valueToKeyRange.js +2 -5
- package/package.json +30 -28
- package/build/cjs/lib/structuredClone.js +0 -30
- package/build/esm/lib/structuredClone.js +0 -18
package/build/esm/FDBIndex.js
CHANGED
|
@@ -7,18 +7,16 @@ import { ConstraintError, InvalidStateError, TransactionInactiveError } from "./
|
|
|
7
7
|
import FakeDOMStringList from "./lib/FakeDOMStringList.js";
|
|
8
8
|
import valueToKey from "./lib/valueToKey.js";
|
|
9
9
|
import valueToKeyRange from "./lib/valueToKeyRange.js";
|
|
10
|
-
|
|
11
10
|
const confirmActiveTransaction = index => {
|
|
12
11
|
if (index._rawIndex.deleted || index.objectStore._rawObjectStore.deleted) {
|
|
13
12
|
throw new InvalidStateError();
|
|
14
13
|
}
|
|
15
|
-
|
|
16
14
|
if (index.objectStore.transaction._state !== "active") {
|
|
17
15
|
throw new TransactionInactiveError();
|
|
18
16
|
}
|
|
19
|
-
};
|
|
20
|
-
|
|
17
|
+
};
|
|
21
18
|
|
|
19
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#idl-def-IDBIndex
|
|
22
20
|
class FDBIndex {
|
|
23
21
|
constructor(objectStore, rawIndex) {
|
|
24
22
|
this._rawIndex = rawIndex;
|
|
@@ -28,85 +26,61 @@ class FDBIndex {
|
|
|
28
26
|
this.multiEntry = rawIndex.multiEntry;
|
|
29
27
|
this.unique = rawIndex.unique;
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
get name() {
|
|
33
30
|
return this._name;
|
|
34
|
-
}
|
|
35
|
-
|
|
31
|
+
}
|
|
36
32
|
|
|
33
|
+
// https://w3c.github.io/IndexedDB/#dom-idbindex-name
|
|
37
34
|
set name(name) {
|
|
38
35
|
const transaction = this.objectStore.transaction;
|
|
39
|
-
|
|
40
36
|
if (!transaction.db._runningVersionchangeTransaction) {
|
|
41
37
|
throw new InvalidStateError();
|
|
42
38
|
}
|
|
43
|
-
|
|
44
39
|
if (transaction._state !== "active") {
|
|
45
40
|
throw new TransactionInactiveError();
|
|
46
41
|
}
|
|
47
|
-
|
|
48
42
|
if (this._rawIndex.deleted || this.objectStore._rawObjectStore.deleted) {
|
|
49
43
|
throw new InvalidStateError();
|
|
50
44
|
}
|
|
51
|
-
|
|
52
45
|
name = String(name);
|
|
53
|
-
|
|
54
46
|
if (name === this._name) {
|
|
55
47
|
return;
|
|
56
48
|
}
|
|
57
|
-
|
|
58
49
|
if (this.objectStore.indexNames.contains(name)) {
|
|
59
50
|
throw new ConstraintError();
|
|
60
51
|
}
|
|
61
|
-
|
|
62
52
|
const oldName = this._name;
|
|
63
53
|
const oldIndexNames = [...this.objectStore.indexNames];
|
|
64
54
|
this._name = name;
|
|
65
55
|
this._rawIndex.name = name;
|
|
66
|
-
|
|
67
56
|
this.objectStore._indexesCache.delete(oldName);
|
|
68
|
-
|
|
69
57
|
this.objectStore._indexesCache.set(name, this);
|
|
70
|
-
|
|
71
58
|
this.objectStore._rawObjectStore.rawIndexes.delete(oldName);
|
|
72
|
-
|
|
73
59
|
this.objectStore._rawObjectStore.rawIndexes.set(name, this._rawIndex);
|
|
74
|
-
|
|
75
60
|
this.objectStore.indexNames = new FakeDOMStringList(...Array.from(this.objectStore._rawObjectStore.rawIndexes.keys()).filter(indexName => {
|
|
76
61
|
const index = this.objectStore._rawObjectStore.rawIndexes.get(indexName);
|
|
77
|
-
|
|
78
62
|
return index && !index.deleted;
|
|
79
63
|
}).sort());
|
|
80
|
-
|
|
81
64
|
transaction._rollbackLog.push(() => {
|
|
82
65
|
this._name = oldName;
|
|
83
66
|
this._rawIndex.name = oldName;
|
|
84
|
-
|
|
85
67
|
this.objectStore._indexesCache.delete(name);
|
|
86
|
-
|
|
87
68
|
this.objectStore._indexesCache.set(oldName, this);
|
|
88
|
-
|
|
89
69
|
this.objectStore._rawObjectStore.rawIndexes.delete(name);
|
|
90
|
-
|
|
91
70
|
this.objectStore._rawObjectStore.rawIndexes.set(oldName, this._rawIndex);
|
|
92
|
-
|
|
93
71
|
this.objectStore.indexNames = new FakeDOMStringList(...oldIndexNames);
|
|
94
72
|
});
|
|
95
|
-
}
|
|
96
|
-
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBIndex-openCursor-IDBRequest-any-range-IDBCursorDirection-direction
|
|
97
|
-
|
|
73
|
+
}
|
|
98
74
|
|
|
75
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBIndex-openCursor-IDBRequest-any-range-IDBCursorDirection-direction
|
|
99
76
|
openCursor(range, direction) {
|
|
100
77
|
confirmActiveTransaction(this);
|
|
101
|
-
|
|
102
78
|
if (range === null) {
|
|
103
79
|
range = undefined;
|
|
104
80
|
}
|
|
105
|
-
|
|
106
81
|
if (range !== undefined && !(range instanceof FDBKeyRange)) {
|
|
107
82
|
range = FDBKeyRange.only(valueToKey(range));
|
|
108
83
|
}
|
|
109
|
-
|
|
110
84
|
const request = new FDBRequest();
|
|
111
85
|
request.source = this;
|
|
112
86
|
request.transaction = this.objectStore.transaction;
|
|
@@ -116,21 +90,17 @@ class FDBIndex {
|
|
|
116
90
|
request,
|
|
117
91
|
source: this
|
|
118
92
|
});
|
|
119
|
-
}
|
|
120
|
-
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBIndex-openKeyCursor-IDBRequest-any-range-IDBCursorDirection-direction
|
|
121
|
-
|
|
93
|
+
}
|
|
122
94
|
|
|
95
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBIndex-openKeyCursor-IDBRequest-any-range-IDBCursorDirection-direction
|
|
123
96
|
openKeyCursor(range, direction) {
|
|
124
97
|
confirmActiveTransaction(this);
|
|
125
|
-
|
|
126
98
|
if (range === null) {
|
|
127
99
|
range = undefined;
|
|
128
100
|
}
|
|
129
|
-
|
|
130
101
|
if (range !== undefined && !(range instanceof FDBKeyRange)) {
|
|
131
102
|
range = FDBKeyRange.only(valueToKey(range));
|
|
132
103
|
}
|
|
133
|
-
|
|
134
104
|
const request = new FDBRequest();
|
|
135
105
|
request.source = this;
|
|
136
106
|
request.transaction = this.objectStore.transaction;
|
|
@@ -141,93 +111,78 @@ class FDBIndex {
|
|
|
141
111
|
source: this
|
|
142
112
|
});
|
|
143
113
|
}
|
|
144
|
-
|
|
145
114
|
get(key) {
|
|
146
115
|
confirmActiveTransaction(this);
|
|
147
|
-
|
|
148
116
|
if (!(key instanceof FDBKeyRange)) {
|
|
149
117
|
key = valueToKey(key);
|
|
150
118
|
}
|
|
151
|
-
|
|
152
119
|
return this.objectStore.transaction._execRequestAsync({
|
|
153
120
|
operation: this._rawIndex.getValue.bind(this._rawIndex, key),
|
|
154
121
|
source: this
|
|
155
122
|
});
|
|
156
|
-
}
|
|
157
|
-
|
|
123
|
+
}
|
|
158
124
|
|
|
125
|
+
// http://w3c.github.io/IndexedDB/#dom-idbindex-getall
|
|
159
126
|
getAll(query, count) {
|
|
160
127
|
if (arguments.length > 1 && count !== undefined) {
|
|
161
128
|
count = enforceRange(count, "unsigned long");
|
|
162
129
|
}
|
|
163
|
-
|
|
164
130
|
confirmActiveTransaction(this);
|
|
165
131
|
const range = valueToKeyRange(query);
|
|
166
132
|
return this.objectStore.transaction._execRequestAsync({
|
|
167
133
|
operation: this._rawIndex.getAllValues.bind(this._rawIndex, range, count),
|
|
168
134
|
source: this
|
|
169
135
|
});
|
|
170
|
-
}
|
|
171
|
-
|
|
136
|
+
}
|
|
172
137
|
|
|
138
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBIndex-getKey-IDBRequest-any-key
|
|
173
139
|
getKey(key) {
|
|
174
140
|
confirmActiveTransaction(this);
|
|
175
|
-
|
|
176
141
|
if (!(key instanceof FDBKeyRange)) {
|
|
177
142
|
key = valueToKey(key);
|
|
178
143
|
}
|
|
179
|
-
|
|
180
144
|
return this.objectStore.transaction._execRequestAsync({
|
|
181
145
|
operation: this._rawIndex.getKey.bind(this._rawIndex, key),
|
|
182
146
|
source: this
|
|
183
147
|
});
|
|
184
|
-
}
|
|
185
|
-
|
|
148
|
+
}
|
|
186
149
|
|
|
150
|
+
// http://w3c.github.io/IndexedDB/#dom-idbindex-getallkeys
|
|
187
151
|
getAllKeys(query, count) {
|
|
188
152
|
if (arguments.length > 1 && count !== undefined) {
|
|
189
153
|
count = enforceRange(count, "unsigned long");
|
|
190
154
|
}
|
|
191
|
-
|
|
192
155
|
confirmActiveTransaction(this);
|
|
193
156
|
const range = valueToKeyRange(query);
|
|
194
157
|
return this.objectStore.transaction._execRequestAsync({
|
|
195
158
|
operation: this._rawIndex.getAllKeys.bind(this._rawIndex, range, count),
|
|
196
159
|
source: this
|
|
197
160
|
});
|
|
198
|
-
}
|
|
199
|
-
|
|
161
|
+
}
|
|
200
162
|
|
|
163
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBIndex-count-IDBRequest-any-key
|
|
201
164
|
count(key) {
|
|
202
165
|
confirmActiveTransaction(this);
|
|
203
|
-
|
|
204
166
|
if (key === null) {
|
|
205
167
|
key = undefined;
|
|
206
168
|
}
|
|
207
|
-
|
|
208
169
|
if (key !== undefined && !(key instanceof FDBKeyRange)) {
|
|
209
170
|
key = FDBKeyRange.only(valueToKey(key));
|
|
210
171
|
}
|
|
211
|
-
|
|
212
172
|
return this.objectStore.transaction._execRequestAsync({
|
|
213
173
|
operation: () => {
|
|
214
174
|
let count = 0;
|
|
215
175
|
const cursor = new FDBCursor(this, key);
|
|
216
|
-
|
|
217
176
|
while (cursor._iterate() !== null) {
|
|
218
177
|
count += 1;
|
|
219
178
|
}
|
|
220
|
-
|
|
221
179
|
return count;
|
|
222
180
|
},
|
|
223
181
|
source: this
|
|
224
182
|
});
|
|
225
183
|
}
|
|
226
|
-
|
|
227
184
|
toString() {
|
|
228
185
|
return "[object IDBIndex]";
|
|
229
186
|
}
|
|
230
|
-
|
|
231
187
|
}
|
|
232
|
-
|
|
233
188
|
export default FDBIndex;
|
package/build/esm/FDBKeyRange.js
CHANGED
|
@@ -1,89 +1,71 @@
|
|
|
1
1
|
import cmp from "./lib/cmp.js";
|
|
2
2
|
import { DataError } from "./lib/errors.js";
|
|
3
|
-
import valueToKey from "./lib/valueToKey.js";
|
|
3
|
+
import valueToKey from "./lib/valueToKey.js";
|
|
4
4
|
|
|
5
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#range-concept
|
|
5
6
|
class FDBKeyRange {
|
|
6
7
|
static only(value) {
|
|
7
8
|
if (arguments.length === 0) {
|
|
8
9
|
throw new TypeError();
|
|
9
10
|
}
|
|
10
|
-
|
|
11
11
|
value = valueToKey(value);
|
|
12
12
|
return new FDBKeyRange(value, value, false, false);
|
|
13
13
|
}
|
|
14
|
-
|
|
15
14
|
static lowerBound(lower, open = false) {
|
|
16
15
|
if (arguments.length === 0) {
|
|
17
16
|
throw new TypeError();
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
lower = valueToKey(lower);
|
|
21
19
|
return new FDBKeyRange(lower, undefined, open, true);
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
static upperBound(upper, open = false) {
|
|
25
22
|
if (arguments.length === 0) {
|
|
26
23
|
throw new TypeError();
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
upper = valueToKey(upper);
|
|
30
26
|
return new FDBKeyRange(undefined, upper, true, open);
|
|
31
27
|
}
|
|
32
|
-
|
|
33
28
|
static bound(lower, upper, lowerOpen = false, upperOpen = false) {
|
|
34
29
|
if (arguments.length < 2) {
|
|
35
30
|
throw new TypeError();
|
|
36
31
|
}
|
|
37
|
-
|
|
38
32
|
const cmpResult = cmp(lower, upper);
|
|
39
|
-
|
|
40
33
|
if (cmpResult === 1 || cmpResult === 0 && (lowerOpen || upperOpen)) {
|
|
41
34
|
throw new DataError();
|
|
42
35
|
}
|
|
43
|
-
|
|
44
36
|
lower = valueToKey(lower);
|
|
45
37
|
upper = valueToKey(upper);
|
|
46
38
|
return new FDBKeyRange(lower, upper, lowerOpen, upperOpen);
|
|
47
39
|
}
|
|
48
|
-
|
|
49
40
|
constructor(lower, upper, lowerOpen, upperOpen) {
|
|
50
41
|
this.lower = lower;
|
|
51
42
|
this.upper = upper;
|
|
52
43
|
this.lowerOpen = lowerOpen;
|
|
53
44
|
this.upperOpen = upperOpen;
|
|
54
|
-
}
|
|
55
|
-
|
|
45
|
+
}
|
|
56
46
|
|
|
47
|
+
// https://w3c.github.io/IndexedDB/#dom-idbkeyrange-includes
|
|
57
48
|
includes(key) {
|
|
58
49
|
if (arguments.length === 0) {
|
|
59
50
|
throw new TypeError();
|
|
60
51
|
}
|
|
61
|
-
|
|
62
52
|
key = valueToKey(key);
|
|
63
|
-
|
|
64
53
|
if (this.lower !== undefined) {
|
|
65
54
|
const cmpResult = cmp(this.lower, key);
|
|
66
|
-
|
|
67
55
|
if (cmpResult === 1 || cmpResult === 0 && this.lowerOpen) {
|
|
68
56
|
return false;
|
|
69
57
|
}
|
|
70
58
|
}
|
|
71
|
-
|
|
72
59
|
if (this.upper !== undefined) {
|
|
73
60
|
const cmpResult = cmp(this.upper, key);
|
|
74
|
-
|
|
75
61
|
if (cmpResult === -1 || cmpResult === 0 && this.upperOpen) {
|
|
76
62
|
return false;
|
|
77
63
|
}
|
|
78
64
|
}
|
|
79
|
-
|
|
80
65
|
return true;
|
|
81
66
|
}
|
|
82
|
-
|
|
83
67
|
toString() {
|
|
84
68
|
return "[object IDBKeyRange]";
|
|
85
69
|
}
|
|
86
|
-
|
|
87
70
|
}
|
|
88
|
-
|
|
89
71
|
export default FDBKeyRange;
|