fake-indexeddb 4.0.0-beta.1 → 4.0.0-beta.2
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 +2 -2
- package/build/FDBCursor.js +183 -276
- package/build/FDBCursorWithValue.js +7 -25
- package/build/FDBDatabase.js +57 -100
- package/build/FDBFactory.js +82 -148
- package/build/FDBIndex.js +79 -84
- package/build/FDBKeyRange.js +18 -23
- package/build/FDBObjectStore.js +127 -134
- package/build/FDBOpenDBRequest.js +8 -26
- package/build/FDBRequest.js +31 -57
- package/build/FDBTransaction.js +75 -125
- package/build/FDBVersionChangeEvent.js +8 -27
- package/build/fakeIndexedDB.js +1 -1
- package/build/lib/Database.js +11 -12
- package/build/lib/FakeDOMStringList.js +66 -0
- package/build/lib/FakeEvent.js +9 -11
- package/build/lib/FakeEventTarget.js +35 -81
- package/build/lib/Index.js +51 -128
- package/build/lib/KeyGenerator.js +9 -10
- package/build/lib/ObjectStore.js +57 -153
- package/build/lib/RecordStore.js +43 -47
- package/build/lib/binarySearch.js +13 -13
- package/build/lib/canInjectKey.js +9 -31
- package/build/lib/cmp.js +7 -7
- package/build/lib/enforceRange.js +3 -3
- package/build/lib/errors.js +61 -126
- package/build/lib/extractKey.js +15 -37
- package/build/lib/scheduling.js +28 -0
- package/build/lib/structuredClone.js +8 -2
- package/build/lib/validateKeyPath.js +6 -38
- package/build/lib/valueToKey.js +7 -7
- package/build/lib/valueToKeyRange.js +2 -3
- package/package.json +4 -5
- package/build/lib/fakeDOMStringList.js +0 -14
package/README.md
CHANGED
|
@@ -115,7 +115,7 @@ const db = new Dexie("MyDatabase", { indexedDB: indexedDB, IDBKeyRange: IDBKeyRa
|
|
|
115
115
|
|
|
116
116
|
### Jest
|
|
117
117
|
|
|
118
|
-
Out of the box, Jest v27 only supports CommonJS, not ES modules, so
|
|
118
|
+
Out of the box, Jest v27 only supports CommonJS, not ES modules, so you'll have to do a little extra work to opt in to ES modules, either [for all your test files](https://jestjs.io/docs/ecmascript-modules) or by configuring Jest to [transpile fake-indexeddb](https://stackoverflow.com/a/43197503/786644). If you can't do that, you should use fake-indexeddb v3, see the above "ECMAScript modules" section for more info.
|
|
119
119
|
|
|
120
120
|
To use fake-indexeddb in a single Jest test suite, require `fake-indexeddb/auto` at the beginning of the test
|
|
121
121
|
file, as described above.
|
|
@@ -133,7 +133,7 @@ To use it on all Jest tests without having to require it in each file, add the a
|
|
|
133
133
|
|
|
134
134
|
### Wiping/resetting the indexedDB for a fresh state
|
|
135
135
|
|
|
136
|
-
If you are keeping your tests completely isolated you might want to "reset" the state of the mocked indexedDB. You can do this by creating a new `
|
|
136
|
+
If you are keeping your tests completely isolated you might want to "reset" the state of the mocked indexedDB. You can do this by creating a new instance of `IDBFactory`, which lets you have a totally fresh start.
|
|
137
137
|
|
|
138
138
|
```
|
|
139
139
|
import "fake-indexeddb/auto";
|
package/build/FDBCursor.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
var __values = (this && this.__values) || function(o) {
|
|
2
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
3
|
-
if (m) return m.call(o);
|
|
4
|
-
if (o && typeof o.length === "number") return {
|
|
5
|
-
next: function () {
|
|
6
|
-
if (o && i >= o.length) o = void 0;
|
|
7
|
-
return { value: o && o[i++], done: !o };
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
|
-
};
|
|
12
1
|
import FDBKeyRange from "./FDBKeyRange.js";
|
|
13
2
|
import FDBObjectStore from "./FDBObjectStore.js";
|
|
14
3
|
import cmp from "./lib/cmp.js";
|
|
@@ -16,7 +5,7 @@ import { DataError, InvalidAccessError, InvalidStateError, ReadOnlyError, Transa
|
|
|
16
5
|
import extractKey from "./lib/extractKey.js";
|
|
17
6
|
import structuredClone from "./lib/structuredClone.js";
|
|
18
7
|
import valueToKey from "./lib/valueToKey.js";
|
|
19
|
-
|
|
8
|
+
const getEffectiveObjectStore = (cursor) => {
|
|
20
9
|
if (cursor.source instanceof FDBObjectStore) {
|
|
21
10
|
return cursor.source;
|
|
22
11
|
}
|
|
@@ -26,47 +15,26 @@ var getEffectiveObjectStore = function (cursor) {
|
|
|
26
15
|
// range. It does not handle gt/gte distinctions, because it doesn't really matter much anyway, since for next/prev
|
|
27
16
|
// cursor iteration it'd also have to look at values to be precise, which would be complicated. This should get us 99%
|
|
28
17
|
// of the way there.
|
|
29
|
-
|
|
30
|
-
var e_1, _a, e_2, _b;
|
|
18
|
+
const makeKeyRange = (range, lowers, uppers) => {
|
|
31
19
|
// Start with bounds from range
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (lowerTemp === undefined) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
if (lower === undefined || cmp(lower, lowerTemp) === 1) {
|
|
42
|
-
lower = lowerTemp;
|
|
43
|
-
}
|
|
20
|
+
let lower = range !== undefined ? range.lower : undefined;
|
|
21
|
+
let upper = range !== undefined ? range.upper : undefined;
|
|
22
|
+
// Augment with values from lowers and uppers
|
|
23
|
+
for (const lowerTemp of lowers) {
|
|
24
|
+
if (lowerTemp === undefined) {
|
|
25
|
+
continue;
|
|
44
26
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
finally {
|
|
48
|
-
try {
|
|
49
|
-
if (lowers_1_1 && !lowers_1_1.done && (_a = lowers_1.return)) _a.call(lowers_1);
|
|
27
|
+
if (lower === undefined || cmp(lower, lowerTemp) === 1) {
|
|
28
|
+
lower = lowerTemp;
|
|
50
29
|
}
|
|
51
|
-
finally { if (e_1) throw e_1.error; }
|
|
52
30
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (upperTemp === undefined) {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if (upper === undefined || cmp(upper, upperTemp) === -1) {
|
|
60
|
-
upper = upperTemp;
|
|
61
|
-
}
|
|
31
|
+
for (const upperTemp of uppers) {
|
|
32
|
+
if (upperTemp === undefined) {
|
|
33
|
+
continue;
|
|
62
34
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
finally {
|
|
66
|
-
try {
|
|
67
|
-
if (uppers_1_1 && !uppers_1_1.done && (_b = uppers_1.return)) _b.call(uppers_1);
|
|
35
|
+
if (upper === undefined || cmp(upper, upperTemp) === -1) {
|
|
36
|
+
upper = upperTemp;
|
|
68
37
|
}
|
|
69
|
-
finally { if (e_2) throw e_2.error; }
|
|
70
38
|
}
|
|
71
39
|
if (lower !== undefined && upper !== undefined) {
|
|
72
40
|
return FDBKeyRange.bound(lower, upper);
|
|
@@ -79,10 +47,8 @@ var makeKeyRange = function (range, lowers, uppers) {
|
|
|
79
47
|
}
|
|
80
48
|
};
|
|
81
49
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#cursor
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (direction === void 0) { direction = "next"; }
|
|
85
|
-
if (keyOnly === void 0) { keyOnly = false; }
|
|
50
|
+
class FDBCursor {
|
|
51
|
+
constructor(source, range, direction = "next", request, keyOnly = false) {
|
|
86
52
|
this._gotValue = false;
|
|
87
53
|
this._position = undefined; // Key of previously returned record
|
|
88
54
|
this._objectStorePosition = undefined;
|
|
@@ -95,236 +61,179 @@ var FDBCursor = /** @class */ (function () {
|
|
|
95
61
|
this._request = request;
|
|
96
62
|
this._keyOnly = keyOnly;
|
|
97
63
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
set: function (val) {
|
|
124
|
-
/* For babel */
|
|
125
|
-
},
|
|
126
|
-
enumerable: false,
|
|
127
|
-
configurable: true
|
|
128
|
-
});
|
|
129
|
-
Object.defineProperty(FDBCursor.prototype, "primaryKey", {
|
|
130
|
-
get: function () {
|
|
131
|
-
return this._primaryKey;
|
|
132
|
-
},
|
|
133
|
-
set: function (val) {
|
|
134
|
-
/* For babel */
|
|
135
|
-
},
|
|
136
|
-
enumerable: false,
|
|
137
|
-
configurable: true
|
|
138
|
-
});
|
|
64
|
+
// Read only properties
|
|
65
|
+
get source() {
|
|
66
|
+
return this._source;
|
|
67
|
+
}
|
|
68
|
+
set source(val) {
|
|
69
|
+
/* For babel */
|
|
70
|
+
}
|
|
71
|
+
get direction() {
|
|
72
|
+
return this._direction;
|
|
73
|
+
}
|
|
74
|
+
set direction(val) {
|
|
75
|
+
/* For babel */
|
|
76
|
+
}
|
|
77
|
+
get key() {
|
|
78
|
+
return this._key;
|
|
79
|
+
}
|
|
80
|
+
set key(val) {
|
|
81
|
+
/* For babel */
|
|
82
|
+
}
|
|
83
|
+
get primaryKey() {
|
|
84
|
+
return this._primaryKey;
|
|
85
|
+
}
|
|
86
|
+
set primaryKey(val) {
|
|
87
|
+
/* For babel */
|
|
88
|
+
}
|
|
139
89
|
// https://w3c.github.io/IndexedDB/#iterate-a-cursor
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
var sourceIsObjectStore = this.source instanceof FDBObjectStore;
|
|
90
|
+
_iterate(key, primaryKey) {
|
|
91
|
+
const sourceIsObjectStore = this.source instanceof FDBObjectStore;
|
|
143
92
|
// Can't use sourceIsObjectStore because TypeScript
|
|
144
|
-
|
|
93
|
+
const records = this.source instanceof FDBObjectStore
|
|
145
94
|
? this.source._rawObjectStore.records
|
|
146
95
|
: this.source._rawIndex.records;
|
|
147
|
-
|
|
96
|
+
let foundRecord;
|
|
148
97
|
if (this.direction === "next") {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (cmpResultKey === -1) {
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
98
|
+
const range = makeKeyRange(this._range, [key, this._position], []);
|
|
99
|
+
for (const record of records.values(range)) {
|
|
100
|
+
const cmpResultKey = key !== undefined ? cmp(record.key, key) : undefined;
|
|
101
|
+
const cmpResultPosition = this._position !== undefined
|
|
102
|
+
? cmp(record.key, this._position)
|
|
103
|
+
: undefined;
|
|
104
|
+
if (key !== undefined) {
|
|
105
|
+
if (cmpResultKey === -1) {
|
|
106
|
+
continue;
|
|
161
107
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
var cmpResultPrimaryKey = cmp(record.value, primaryKey);
|
|
167
|
-
if (cmpResultKey === 0 && cmpResultPrimaryKey === -1) {
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
108
|
+
}
|
|
109
|
+
if (primaryKey !== undefined) {
|
|
110
|
+
if (cmpResultKey === -1) {
|
|
111
|
+
continue;
|
|
170
112
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
113
|
+
const cmpResultPrimaryKey = cmp(record.value, primaryKey);
|
|
114
|
+
if (cmpResultKey === 0 && cmpResultPrimaryKey === -1) {
|
|
115
|
+
continue;
|
|
175
116
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (cmpResultPosition === 0 &&
|
|
181
|
-
cmp(record.value, this._objectStorePosition) !== 1) {
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
117
|
+
}
|
|
118
|
+
if (this._position !== undefined && sourceIsObjectStore) {
|
|
119
|
+
if (cmpResultPosition !== 1) {
|
|
120
|
+
continue;
|
|
184
121
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
122
|
+
}
|
|
123
|
+
if (this._position !== undefined && !sourceIsObjectStore) {
|
|
124
|
+
if (cmpResultPosition === -1) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (cmpResultPosition === 0 &&
|
|
128
|
+
cmp(record.value, this._objectStorePosition) !== 1) {
|
|
129
|
+
continue;
|
|
189
130
|
}
|
|
190
|
-
foundRecord = record;
|
|
191
|
-
break;
|
|
192
131
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
132
|
+
if (this._range !== undefined) {
|
|
133
|
+
if (!this._range.includes(record.key)) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
198
136
|
}
|
|
199
|
-
|
|
137
|
+
foundRecord = record;
|
|
138
|
+
break;
|
|
200
139
|
}
|
|
201
140
|
}
|
|
202
141
|
else if (this.direction === "nextunique") {
|
|
203
142
|
// This could be done without iterating, if the range was defined slightly better (to handle gt/gte cases).
|
|
204
143
|
// But the performance difference should be small, and that wouldn't work anyway for directions where the
|
|
205
144
|
// value needs to be used (like next and prev).
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
if (cmp(record.key, key) === -1) {
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
145
|
+
const range = makeKeyRange(this._range, [key, this._position], []);
|
|
146
|
+
for (const record of records.values(range)) {
|
|
147
|
+
if (key !== undefined) {
|
|
148
|
+
if (cmp(record.key, key) === -1) {
|
|
149
|
+
continue;
|
|
214
150
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
if (this._range !== undefined) {
|
|
221
|
-
if (!this._range.includes(record.key)) {
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
151
|
+
}
|
|
152
|
+
if (this._position !== undefined) {
|
|
153
|
+
if (cmp(record.key, this._position) !== 1) {
|
|
154
|
+
continue;
|
|
224
155
|
}
|
|
225
|
-
foundRecord = record;
|
|
226
|
-
break;
|
|
227
156
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
157
|
+
if (this._range !== undefined) {
|
|
158
|
+
if (!this._range.includes(record.key)) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
233
161
|
}
|
|
234
|
-
|
|
162
|
+
foundRecord = record;
|
|
163
|
+
break;
|
|
235
164
|
}
|
|
236
165
|
}
|
|
237
166
|
else if (this.direction === "prev") {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
167
|
+
const range = makeKeyRange(this._range, [], [key, this._position]);
|
|
168
|
+
for (const record of records.values(range, "prev")) {
|
|
169
|
+
const cmpResultKey = key !== undefined ? cmp(record.key, key) : undefined;
|
|
170
|
+
const cmpResultPosition = this._position !== undefined
|
|
171
|
+
? cmp(record.key, this._position)
|
|
172
|
+
: undefined;
|
|
173
|
+
if (key !== undefined) {
|
|
174
|
+
if (cmpResultKey === 1) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (primaryKey !== undefined) {
|
|
179
|
+
if (cmpResultKey === 1) {
|
|
180
|
+
continue;
|
|
250
181
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
var cmpResultPrimaryKey = cmp(record.value, primaryKey);
|
|
256
|
-
if (cmpResultKey === 0 && cmpResultPrimaryKey === 1) {
|
|
257
|
-
continue;
|
|
258
|
-
}
|
|
182
|
+
const cmpResultPrimaryKey = cmp(record.value, primaryKey);
|
|
183
|
+
if (cmpResultKey === 0 && cmpResultPrimaryKey === 1) {
|
|
184
|
+
continue;
|
|
259
185
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
186
|
+
}
|
|
187
|
+
if (this._position !== undefined && sourceIsObjectStore) {
|
|
188
|
+
if (cmpResultPosition !== -1) {
|
|
189
|
+
continue;
|
|
264
190
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (cmpResultPosition === 0 &&
|
|
270
|
-
cmp(record.value, this._objectStorePosition) !== -1) {
|
|
271
|
-
continue;
|
|
272
|
-
}
|
|
191
|
+
}
|
|
192
|
+
if (this._position !== undefined && !sourceIsObjectStore) {
|
|
193
|
+
if (cmpResultPosition === 1) {
|
|
194
|
+
continue;
|
|
273
195
|
}
|
|
274
|
-
if (
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
196
|
+
if (cmpResultPosition === 0 &&
|
|
197
|
+
cmp(record.value, this._objectStorePosition) !== -1) {
|
|
198
|
+
continue;
|
|
278
199
|
}
|
|
279
|
-
foundRecord = record;
|
|
280
|
-
break;
|
|
281
200
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
201
|
+
if (this._range !== undefined) {
|
|
202
|
+
if (!this._range.includes(record.key)) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
287
205
|
}
|
|
288
|
-
|
|
206
|
+
foundRecord = record;
|
|
207
|
+
break;
|
|
289
208
|
}
|
|
290
209
|
}
|
|
291
210
|
else if (this.direction === "prevunique") {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (cmp(record.key, key) === 1) {
|
|
299
|
-
continue;
|
|
300
|
-
}
|
|
211
|
+
let tempRecord;
|
|
212
|
+
const range = makeKeyRange(this._range, [], [key, this._position]);
|
|
213
|
+
for (const record of records.values(range, "prev")) {
|
|
214
|
+
if (key !== undefined) {
|
|
215
|
+
if (cmp(record.key, key) === 1) {
|
|
216
|
+
continue;
|
|
301
217
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
if (this._range !== undefined) {
|
|
308
|
-
if (!this._range.includes(record.key)) {
|
|
309
|
-
continue;
|
|
310
|
-
}
|
|
218
|
+
}
|
|
219
|
+
if (this._position !== undefined) {
|
|
220
|
+
if (cmp(record.key, this._position) !== -1) {
|
|
221
|
+
continue;
|
|
311
222
|
}
|
|
312
|
-
tempRecord = record;
|
|
313
|
-
break;
|
|
314
223
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
if (_m && !_m.done && (_d = _l.return)) _d.call(_l);
|
|
224
|
+
if (this._range !== undefined) {
|
|
225
|
+
if (!this._range.includes(record.key)) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
320
228
|
}
|
|
321
|
-
|
|
229
|
+
tempRecord = record;
|
|
230
|
+
break;
|
|
322
231
|
}
|
|
323
232
|
if (tempRecord) {
|
|
324
233
|
foundRecord = records.get(tempRecord.key);
|
|
325
234
|
}
|
|
326
235
|
}
|
|
327
|
-
|
|
236
|
+
let result;
|
|
328
237
|
if (!foundRecord) {
|
|
329
238
|
this._key = undefined;
|
|
330
239
|
if (!sourceIsObjectStore) {
|
|
@@ -359,7 +268,7 @@ var FDBCursor = /** @class */ (function () {
|
|
|
359
268
|
// Can't use sourceIsObjectStore because TypeScript
|
|
360
269
|
throw new Error("This should never happen");
|
|
361
270
|
}
|
|
362
|
-
|
|
271
|
+
const value = this.source.objectStore._rawObjectStore.getValue(foundRecord.value);
|
|
363
272
|
this.value = structuredClone(value);
|
|
364
273
|
}
|
|
365
274
|
}
|
|
@@ -367,17 +276,17 @@ var FDBCursor = /** @class */ (function () {
|
|
|
367
276
|
result = this;
|
|
368
277
|
}
|
|
369
278
|
return result;
|
|
370
|
-
}
|
|
279
|
+
}
|
|
371
280
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBCursor-update-IDBRequest-any-value
|
|
372
|
-
|
|
281
|
+
update(value) {
|
|
373
282
|
if (value === undefined) {
|
|
374
283
|
throw new TypeError();
|
|
375
284
|
}
|
|
376
|
-
|
|
377
|
-
|
|
285
|
+
const effectiveObjectStore = getEffectiveObjectStore(this);
|
|
286
|
+
const effectiveKey = this.source.hasOwnProperty("_rawIndex")
|
|
378
287
|
? this.primaryKey
|
|
379
288
|
: this._position;
|
|
380
|
-
|
|
289
|
+
const transaction = effectiveObjectStore.transaction;
|
|
381
290
|
if (transaction._state !== "active") {
|
|
382
291
|
throw new TransactionInactiveError();
|
|
383
292
|
}
|
|
@@ -394,9 +303,9 @@ var FDBCursor = /** @class */ (function () {
|
|
|
394
303
|
if (!this._gotValue || !this.hasOwnProperty("value")) {
|
|
395
304
|
throw new InvalidStateError();
|
|
396
305
|
}
|
|
397
|
-
|
|
306
|
+
const clone = structuredClone(value);
|
|
398
307
|
if (effectiveObjectStore.keyPath !== null) {
|
|
399
|
-
|
|
308
|
+
let tempKey;
|
|
400
309
|
try {
|
|
401
310
|
tempKey = extractKey(effectiveObjectStore.keyPath, clone);
|
|
402
311
|
}
|
|
@@ -407,7 +316,7 @@ var FDBCursor = /** @class */ (function () {
|
|
|
407
316
|
throw new DataError();
|
|
408
317
|
}
|
|
409
318
|
}
|
|
410
|
-
|
|
319
|
+
const record = {
|
|
411
320
|
key: effectiveKey,
|
|
412
321
|
value: clone,
|
|
413
322
|
};
|
|
@@ -415,15 +324,14 @@ var FDBCursor = /** @class */ (function () {
|
|
|
415
324
|
operation: effectiveObjectStore._rawObjectStore.storeRecord.bind(effectiveObjectStore._rawObjectStore, record, false, transaction._rollbackLog),
|
|
416
325
|
source: this,
|
|
417
326
|
});
|
|
418
|
-
}
|
|
327
|
+
}
|
|
419
328
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBCursor-advance-void-unsigned-long-count
|
|
420
|
-
|
|
421
|
-
var _this = this;
|
|
329
|
+
advance(count) {
|
|
422
330
|
if (!Number.isInteger(count) || count <= 0) {
|
|
423
331
|
throw new TypeError();
|
|
424
332
|
}
|
|
425
|
-
|
|
426
|
-
|
|
333
|
+
const effectiveObjectStore = getEffectiveObjectStore(this);
|
|
334
|
+
const transaction = effectiveObjectStore.transaction;
|
|
427
335
|
if (transaction._state !== "active") {
|
|
428
336
|
throw new TransactionInactiveError();
|
|
429
337
|
}
|
|
@@ -441,10 +349,10 @@ var FDBCursor = /** @class */ (function () {
|
|
|
441
349
|
this._request.readyState = "pending";
|
|
442
350
|
}
|
|
443
351
|
transaction._execRequestAsync({
|
|
444
|
-
operation:
|
|
445
|
-
|
|
446
|
-
for (
|
|
447
|
-
result =
|
|
352
|
+
operation: () => {
|
|
353
|
+
let result;
|
|
354
|
+
for (let i = 0; i < count; i++) {
|
|
355
|
+
result = this._iterate();
|
|
448
356
|
// Not sure why this is needed
|
|
449
357
|
if (!result) {
|
|
450
358
|
break;
|
|
@@ -456,11 +364,11 @@ var FDBCursor = /** @class */ (function () {
|
|
|
456
364
|
source: this.source,
|
|
457
365
|
});
|
|
458
366
|
this._gotValue = false;
|
|
459
|
-
}
|
|
367
|
+
}
|
|
460
368
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBCursor-continue-void-any-key
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
369
|
+
continue(key) {
|
|
370
|
+
const effectiveObjectStore = getEffectiveObjectStore(this);
|
|
371
|
+
const transaction = effectiveObjectStore.transaction;
|
|
464
372
|
if (transaction._state !== "active") {
|
|
465
373
|
throw new TransactionInactiveError();
|
|
466
374
|
}
|
|
@@ -476,7 +384,7 @@ var FDBCursor = /** @class */ (function () {
|
|
|
476
384
|
}
|
|
477
385
|
if (key !== undefined) {
|
|
478
386
|
key = valueToKey(key);
|
|
479
|
-
|
|
387
|
+
const cmpResult = cmp(key, this._position);
|
|
480
388
|
if ((cmpResult <= 0 &&
|
|
481
389
|
(this.direction === "next" ||
|
|
482
390
|
this.direction === "nextunique")) ||
|
|
@@ -495,11 +403,11 @@ var FDBCursor = /** @class */ (function () {
|
|
|
495
403
|
source: this.source,
|
|
496
404
|
});
|
|
497
405
|
this._gotValue = false;
|
|
498
|
-
}
|
|
406
|
+
}
|
|
499
407
|
// hthttps://w3c.github.io/IndexedDB/#dom-idbcursor-continueprimarykey
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
408
|
+
continuePrimaryKey(key, primaryKey) {
|
|
409
|
+
const effectiveObjectStore = getEffectiveObjectStore(this);
|
|
410
|
+
const transaction = effectiveObjectStore.transaction;
|
|
503
411
|
if (transaction._state !== "active") {
|
|
504
412
|
throw new TransactionInactiveError();
|
|
505
413
|
}
|
|
@@ -522,12 +430,12 @@ var FDBCursor = /** @class */ (function () {
|
|
|
522
430
|
throw new DataError();
|
|
523
431
|
}
|
|
524
432
|
key = valueToKey(key);
|
|
525
|
-
|
|
433
|
+
const cmpResult = cmp(key, this._position);
|
|
526
434
|
if ((cmpResult === -1 && this.direction === "next") ||
|
|
527
435
|
(cmpResult === 1 && this.direction === "prev")) {
|
|
528
436
|
throw new DataError();
|
|
529
437
|
}
|
|
530
|
-
|
|
438
|
+
const cmpResult2 = cmp(primaryKey, this._objectStorePosition);
|
|
531
439
|
if (cmpResult === 0) {
|
|
532
440
|
if ((cmpResult2 <= 0 && this.direction === "next") ||
|
|
533
441
|
(cmpResult2 >= 0 && this.direction === "prev")) {
|
|
@@ -543,13 +451,13 @@ var FDBCursor = /** @class */ (function () {
|
|
|
543
451
|
source: this.source,
|
|
544
452
|
});
|
|
545
453
|
this._gotValue = false;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
454
|
+
}
|
|
455
|
+
delete() {
|
|
456
|
+
const effectiveObjectStore = getEffectiveObjectStore(this);
|
|
457
|
+
const effectiveKey = this.source.hasOwnProperty("_rawIndex")
|
|
550
458
|
? this.primaryKey
|
|
551
459
|
: this._position;
|
|
552
|
-
|
|
460
|
+
const transaction = effectiveObjectStore.transaction;
|
|
553
461
|
if (transaction._state !== "active") {
|
|
554
462
|
throw new TransactionInactiveError();
|
|
555
463
|
}
|
|
@@ -570,10 +478,9 @@ var FDBCursor = /** @class */ (function () {
|
|
|
570
478
|
operation: effectiveObjectStore._rawObjectStore.deleteRecord.bind(effectiveObjectStore._rawObjectStore, effectiveKey, transaction._rollbackLog),
|
|
571
479
|
source: this,
|
|
572
480
|
});
|
|
573
|
-
}
|
|
574
|
-
|
|
481
|
+
}
|
|
482
|
+
toString() {
|
|
575
483
|
return "[object IDBCursor]";
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
}());
|
|
484
|
+
}
|
|
485
|
+
}
|
|
579
486
|
export default FDBCursor;
|