fake-indexeddb 4.0.2 → 5.0.1

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.
Files changed (64) hide show
  1. package/README.md +42 -6
  2. package/build/cjs/FDBCursor.js +39 -159
  3. package/build/cjs/FDBCursorWithValue.js +1 -9
  4. package/build/cjs/FDBDatabase.js +9 -72
  5. package/build/cjs/FDBFactory.js +23 -66
  6. package/build/cjs/FDBIndex.js +17 -73
  7. package/build/cjs/FDBKeyRange.js +3 -28
  8. package/build/cjs/FDBObjectStore.js +25 -145
  9. package/build/cjs/FDBOpenDBRequest.js +1 -8
  10. package/build/cjs/FDBRequest.js +1 -15
  11. package/build/cjs/FDBTransaction.js +26 -64
  12. package/build/cjs/FDBVersionChangeEvent.js +1 -8
  13. package/build/cjs/fakeIndexedDB.js +1 -5
  14. package/build/cjs/index.js +1 -16
  15. package/build/cjs/lib/Database.js +1 -11
  16. package/build/cjs/lib/FakeDOMStringList.js +5 -13
  17. package/build/cjs/lib/FakeEvent.js +3 -10
  18. package/build/cjs/lib/FakeEventTarget.js +15 -32
  19. package/build/cjs/lib/Index.js +14 -46
  20. package/build/cjs/lib/KeyGenerator.js +3 -12
  21. package/build/cjs/lib/ObjectStore.js +24 -63
  22. package/build/cjs/lib/RecordStore.js +4 -42
  23. package/build/cjs/lib/binarySearch.js +5 -24
  24. package/build/cjs/lib/canInjectKey.js +2 -14
  25. package/build/cjs/lib/cmp.js +3 -29
  26. package/build/cjs/lib/enforceRange.js +2 -6
  27. package/build/cjs/lib/errors.js +0 -32
  28. package/build/cjs/lib/extractKey.js +2 -17
  29. package/build/cjs/lib/scheduling.js +4 -7
  30. package/build/cjs/lib/validateKeyPath.js +4 -16
  31. package/build/cjs/lib/valueToKey.js +18 -20
  32. package/build/cjs/lib/valueToKeyRange.js +1 -11
  33. package/build/esm/FDBCursor.js +33 -144
  34. package/build/esm/FDBCursorWithValue.js +0 -5
  35. package/build/esm/FDBDatabase.js +8 -62
  36. package/build/esm/FDBFactory.js +22 -54
  37. package/build/esm/FDBIndex.js +16 -61
  38. package/build/esm/FDBKeyRange.js +4 -22
  39. package/build/esm/FDBObjectStore.js +23 -126
  40. package/build/esm/FDBOpenDBRequest.js +0 -4
  41. package/build/esm/FDBRequest.js +0 -10
  42. package/build/esm/FDBTransaction.js +25 -54
  43. package/build/esm/FDBVersionChangeEvent.js +0 -4
  44. package/build/esm/lib/Database.js +2 -8
  45. package/build/esm/lib/FakeDOMStringList.js +4 -9
  46. package/build/esm/lib/FakeEvent.js +2 -7
  47. package/build/esm/lib/FakeEventTarget.js +14 -29
  48. package/build/esm/lib/Index.js +14 -37
  49. package/build/esm/lib/KeyGenerator.js +2 -8
  50. package/build/esm/lib/ObjectStore.js +19 -51
  51. package/build/esm/lib/RecordStore.js +3 -36
  52. package/build/esm/lib/binarySearch.js +5 -18
  53. package/build/esm/lib/canInjectKey.js +1 -11
  54. package/build/esm/lib/cmp.js +2 -24
  55. package/build/esm/lib/enforceRange.js +1 -3
  56. package/build/esm/lib/errors.js +0 -11
  57. package/build/esm/lib/extractKey.js +3 -13
  58. package/build/esm/lib/scheduling.js +3 -3
  59. package/build/esm/lib/validateKeyPath.js +3 -13
  60. package/build/esm/lib/valueToKey.js +17 -17
  61. package/build/esm/lib/valueToKeyRange.js +2 -5
  62. package/package.json +30 -28
  63. package/build/cjs/lib/structuredClone.js +0 -30
  64. package/build/esm/lib/structuredClone.js +0 -18
package/README.md CHANGED
@@ -8,12 +8,6 @@ This is a pure JS in-memory implementation of [the IndexedDB API](https://w3c.gi
8
8
  npm install --save-dev fake-indexeddb
9
9
  ```
10
10
 
11
- or
12
-
13
- ```sh
14
- yarn add --dev fake-indexeddb
15
- ```
16
-
17
11
  ## Use
18
12
 
19
13
  Functionally, it works exactly like IndexedDB except data is not persisted to disk.
@@ -124,6 +118,48 @@ To use it on all Jest tests without having to include it in each file, add the a
124
118
  }
125
119
  ```
126
120
 
121
+ ### jsdom (often used with Jest)
122
+
123
+ As of version 5, fake-indexeddb no longer includes a `structuredClone` polyfill. This mostly affects old environments like unsupported versions of Node.js, but [it also affects jsdom](https://github.com/dumbmatter/fakeIndexedDB/issues/88), which is often used with Jest and other testing frameworks.
124
+
125
+ There are a few ways you could work around this. You could include your own `structuredClone` polyfill by installing core-js and importing its polyfill before you use fake-indexeddb:
126
+
127
+ ```js
128
+ import "core-js/stable/structured-clone";
129
+ import "fake-indexeddb/auto";
130
+ ```
131
+
132
+ Or, [you could manually include the Node.js `structuredClone` implementation in a jsdom environment](https://github.com/jsdom/jsdom/issues/3363#issuecomment-1467894943):
133
+
134
+ ```js
135
+ // FixJSDOMEnvironment.ts
136
+
137
+ import JSDOMEnvironment from 'jest-environment-jsdom';
138
+
139
+ // https://github.com/facebook/jest/blob/v29.4.3/website/versioned_docs/version-29.4/Configuration.md#testenvironment-string
140
+ export default class FixJSDOMEnvironment extends JSDOMEnvironment {
141
+ constructor(...args: ConstructorParameters<typeof JSDOMEnvironment>) {
142
+ super(...args);
143
+
144
+ // FIXME https://github.com/jsdom/jsdom/issues/3363
145
+ this.global.structuredClone = structuredClone;
146
+ }
147
+ }
148
+ ```
149
+
150
+ ```js
151
+ // jest.config.js
152
+
153
+ /** @type {import('jest').Config} */
154
+ const config = {
155
+ testEnvironment: './FixJSDOMEnvironment.ts',
156
+ };
157
+
158
+ module.exports = config;
159
+ ```
160
+
161
+ Hopefully a future version of jsdom will no longer require these workarounds.
162
+
127
163
  ### Wiping/resetting the indexedDB for a fresh state
128
164
 
129
165
  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.
@@ -4,186 +4,149 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _FDBKeyRange = _interopRequireDefault(require("./FDBKeyRange.js"));
9
-
10
8
  var _FDBObjectStore = _interopRequireDefault(require("./FDBObjectStore.js"));
11
-
12
9
  var _cmp = _interopRequireDefault(require("./lib/cmp.js"));
13
-
14
10
  var _errors = require("./lib/errors.js");
15
-
16
11
  var _extractKey = _interopRequireDefault(require("./lib/extractKey.js"));
17
-
18
- var _structuredClone = _interopRequireDefault(require("./lib/structuredClone.js"));
19
-
20
12
  var _valueToKey = _interopRequireDefault(require("./lib/valueToKey.js"));
21
-
22
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
14
  const getEffectiveObjectStore = cursor => {
25
15
  if (cursor.source instanceof _FDBObjectStore.default) {
26
16
  return cursor.source;
27
17
  }
28
-
29
18
  return cursor.source.objectStore;
30
- }; // This takes a key range, a list of lower bounds, and a list of upper bounds and combines them all into a single key
19
+ };
20
+
21
+ // This takes a key range, a list of lower bounds, and a list of upper bounds and combines them all into a single key
31
22
  // range. It does not handle gt/gte distinctions, because it doesn't really matter much anyway, since for next/prev
32
23
  // cursor iteration it'd also have to look at values to be precise, which would be complicated. This should get us 99%
33
24
  // of the way there.
34
-
35
-
36
25
  const makeKeyRange = (range, lowers, uppers) => {
37
26
  // Start with bounds from range
38
27
  let lower = range !== undefined ? range.lower : undefined;
39
- let upper = range !== undefined ? range.upper : undefined; // Augment with values from lowers and uppers
28
+ let upper = range !== undefined ? range.upper : undefined;
40
29
 
30
+ // Augment with values from lowers and uppers
41
31
  for (const lowerTemp of lowers) {
42
32
  if (lowerTemp === undefined) {
43
33
  continue;
44
34
  }
45
-
46
35
  if (lower === undefined || (0, _cmp.default)(lower, lowerTemp) === 1) {
47
36
  lower = lowerTemp;
48
37
  }
49
38
  }
50
-
51
39
  for (const upperTemp of uppers) {
52
40
  if (upperTemp === undefined) {
53
41
  continue;
54
42
  }
55
-
56
43
  if (upper === undefined || (0, _cmp.default)(upper, upperTemp) === -1) {
57
44
  upper = upperTemp;
58
45
  }
59
46
  }
60
-
61
47
  if (lower !== undefined && upper !== undefined) {
62
48
  return _FDBKeyRange.default.bound(lower, upper);
63
49
  }
64
-
65
50
  if (lower !== undefined) {
66
51
  return _FDBKeyRange.default.lowerBound(lower);
67
52
  }
68
-
69
53
  if (upper !== undefined) {
70
54
  return _FDBKeyRange.default.upperBound(upper);
71
55
  }
72
- }; // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#cursor
73
-
56
+ };
74
57
 
58
+ // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#cursor
75
59
  class FDBCursor {
76
60
  _gotValue = false;
77
61
  _position = undefined; // Key of previously returned record
78
-
79
62
  _objectStorePosition = undefined;
80
63
  _keyOnly = false;
81
64
  _key = undefined;
82
65
  _primaryKey = undefined;
83
-
84
66
  constructor(source, range, direction = "next", request, keyOnly = false) {
85
67
  this._range = range;
86
68
  this._source = source;
87
69
  this._direction = direction;
88
70
  this._request = request;
89
71
  this._keyOnly = keyOnly;
90
- } // Read only properties
91
-
72
+ }
92
73
 
74
+ // Read only properties
93
75
  get source() {
94
76
  return this._source;
95
77
  }
96
-
97
78
  set source(val) {
98
79
  /* For babel */
99
80
  }
100
-
101
81
  get request() {
102
82
  return this._request;
103
83
  }
104
-
105
84
  set request(val) {
106
85
  /* For babel */
107
86
  }
108
-
109
87
  get direction() {
110
88
  return this._direction;
111
89
  }
112
-
113
90
  set direction(val) {
114
91
  /* For babel */
115
92
  }
116
-
117
93
  get key() {
118
94
  return this._key;
119
95
  }
120
-
121
96
  set key(val) {
122
97
  /* For babel */
123
98
  }
124
-
125
99
  get primaryKey() {
126
100
  return this._primaryKey;
127
101
  }
128
-
129
102
  set primaryKey(val) {
130
103
  /* For babel */
131
- } // https://w3c.github.io/IndexedDB/#iterate-a-cursor
132
-
104
+ }
133
105
 
106
+ // https://w3c.github.io/IndexedDB/#iterate-a-cursor
134
107
  _iterate(key, primaryKey) {
135
- const sourceIsObjectStore = this.source instanceof _FDBObjectStore.default; // Can't use sourceIsObjectStore because TypeScript
108
+ const sourceIsObjectStore = this.source instanceof _FDBObjectStore.default;
136
109
 
110
+ // Can't use sourceIsObjectStore because TypeScript
137
111
  const records = this.source instanceof _FDBObjectStore.default ? this.source._rawObjectStore.records : this.source._rawIndex.records;
138
112
  let foundRecord;
139
-
140
113
  if (this.direction === "next") {
141
114
  const range = makeKeyRange(this._range, [key, this._position], []);
142
-
143
115
  for (const record of records.values(range)) {
144
116
  const cmpResultKey = key !== undefined ? (0, _cmp.default)(record.key, key) : undefined;
145
117
  const cmpResultPosition = this._position !== undefined ? (0, _cmp.default)(record.key, this._position) : undefined;
146
-
147
118
  if (key !== undefined) {
148
119
  if (cmpResultKey === -1) {
149
120
  continue;
150
121
  }
151
122
  }
152
-
153
123
  if (primaryKey !== undefined) {
154
124
  if (cmpResultKey === -1) {
155
125
  continue;
156
126
  }
157
-
158
127
  const cmpResultPrimaryKey = (0, _cmp.default)(record.value, primaryKey);
159
-
160
128
  if (cmpResultKey === 0 && cmpResultPrimaryKey === -1) {
161
129
  continue;
162
130
  }
163
131
  }
164
-
165
132
  if (this._position !== undefined && sourceIsObjectStore) {
166
133
  if (cmpResultPosition !== 1) {
167
134
  continue;
168
135
  }
169
136
  }
170
-
171
137
  if (this._position !== undefined && !sourceIsObjectStore) {
172
138
  if (cmpResultPosition === -1) {
173
139
  continue;
174
140
  }
175
-
176
141
  if (cmpResultPosition === 0 && (0, _cmp.default)(record.value, this._objectStorePosition) !== 1) {
177
142
  continue;
178
143
  }
179
144
  }
180
-
181
145
  if (this._range !== undefined) {
182
146
  if (!this._range.includes(record.key)) {
183
147
  continue;
184
148
  }
185
149
  }
186
-
187
150
  foundRecord = record;
188
151
  break;
189
152
  }
@@ -192,210 +155,168 @@ class FDBCursor {
192
155
  // But the performance difference should be small, and that wouldn't work anyway for directions where the
193
156
  // value needs to be used (like next and prev).
194
157
  const range = makeKeyRange(this._range, [key, this._position], []);
195
-
196
158
  for (const record of records.values(range)) {
197
159
  if (key !== undefined) {
198
160
  if ((0, _cmp.default)(record.key, key) === -1) {
199
161
  continue;
200
162
  }
201
163
  }
202
-
203
164
  if (this._position !== undefined) {
204
165
  if ((0, _cmp.default)(record.key, this._position) !== 1) {
205
166
  continue;
206
167
  }
207
168
  }
208
-
209
169
  if (this._range !== undefined) {
210
170
  if (!this._range.includes(record.key)) {
211
171
  continue;
212
172
  }
213
173
  }
214
-
215
174
  foundRecord = record;
216
175
  break;
217
176
  }
218
177
  } else if (this.direction === "prev") {
219
178
  const range = makeKeyRange(this._range, [], [key, this._position]);
220
-
221
179
  for (const record of records.values(range, "prev")) {
222
180
  const cmpResultKey = key !== undefined ? (0, _cmp.default)(record.key, key) : undefined;
223
181
  const cmpResultPosition = this._position !== undefined ? (0, _cmp.default)(record.key, this._position) : undefined;
224
-
225
182
  if (key !== undefined) {
226
183
  if (cmpResultKey === 1) {
227
184
  continue;
228
185
  }
229
186
  }
230
-
231
187
  if (primaryKey !== undefined) {
232
188
  if (cmpResultKey === 1) {
233
189
  continue;
234
190
  }
235
-
236
191
  const cmpResultPrimaryKey = (0, _cmp.default)(record.value, primaryKey);
237
-
238
192
  if (cmpResultKey === 0 && cmpResultPrimaryKey === 1) {
239
193
  continue;
240
194
  }
241
195
  }
242
-
243
196
  if (this._position !== undefined && sourceIsObjectStore) {
244
197
  if (cmpResultPosition !== -1) {
245
198
  continue;
246
199
  }
247
200
  }
248
-
249
201
  if (this._position !== undefined && !sourceIsObjectStore) {
250
202
  if (cmpResultPosition === 1) {
251
203
  continue;
252
204
  }
253
-
254
205
  if (cmpResultPosition === 0 && (0, _cmp.default)(record.value, this._objectStorePosition) !== -1) {
255
206
  continue;
256
207
  }
257
208
  }
258
-
259
209
  if (this._range !== undefined) {
260
210
  if (!this._range.includes(record.key)) {
261
211
  continue;
262
212
  }
263
213
  }
264
-
265
214
  foundRecord = record;
266
215
  break;
267
216
  }
268
217
  } else if (this.direction === "prevunique") {
269
218
  let tempRecord;
270
219
  const range = makeKeyRange(this._range, [], [key, this._position]);
271
-
272
220
  for (const record of records.values(range, "prev")) {
273
221
  if (key !== undefined) {
274
222
  if ((0, _cmp.default)(record.key, key) === 1) {
275
223
  continue;
276
224
  }
277
225
  }
278
-
279
226
  if (this._position !== undefined) {
280
227
  if ((0, _cmp.default)(record.key, this._position) !== -1) {
281
228
  continue;
282
229
  }
283
230
  }
284
-
285
231
  if (this._range !== undefined) {
286
232
  if (!this._range.includes(record.key)) {
287
233
  continue;
288
234
  }
289
235
  }
290
-
291
236
  tempRecord = record;
292
237
  break;
293
238
  }
294
-
295
239
  if (tempRecord) {
296
240
  foundRecord = records.get(tempRecord.key);
297
241
  }
298
242
  }
299
-
300
243
  let result;
301
-
302
244
  if (!foundRecord) {
303
245
  this._key = undefined;
304
-
305
246
  if (!sourceIsObjectStore) {
306
247
  this._objectStorePosition = undefined;
307
- } // "this instanceof FDBCursorWithValue" would be better and not require (this as any), but causes runtime
308
- // error due to circular dependency.
309
-
248
+ }
310
249
 
250
+ // "this instanceof FDBCursorWithValue" would be better and not require (this as any), but causes runtime
251
+ // error due to circular dependency.
311
252
  if (!this._keyOnly && this.toString() === "[object IDBCursorWithValue]") {
312
253
  this.value = undefined;
313
254
  }
314
-
315
255
  result = null;
316
256
  } else {
317
257
  this._position = foundRecord.key;
318
-
319
258
  if (!sourceIsObjectStore) {
320
259
  this._objectStorePosition = foundRecord.value;
321
260
  }
322
-
323
261
  this._key = foundRecord.key;
324
-
325
262
  if (sourceIsObjectStore) {
326
- this._primaryKey = (0, _structuredClone.default)(foundRecord.key);
327
-
263
+ this._primaryKey = structuredClone(foundRecord.key);
328
264
  if (!this._keyOnly && this.toString() === "[object IDBCursorWithValue]") {
329
- this.value = (0, _structuredClone.default)(foundRecord.value);
265
+ this.value = structuredClone(foundRecord.value);
330
266
  }
331
267
  } else {
332
- this._primaryKey = (0, _structuredClone.default)(foundRecord.value);
333
-
268
+ this._primaryKey = structuredClone(foundRecord.value);
334
269
  if (!this._keyOnly && this.toString() === "[object IDBCursorWithValue]") {
335
270
  if (this.source instanceof _FDBObjectStore.default) {
336
271
  // Can't use sourceIsObjectStore because TypeScript
337
272
  throw new Error("This should never happen");
338
273
  }
339
-
340
274
  const value = this.source.objectStore._rawObjectStore.getValue(foundRecord.value);
341
-
342
- this.value = (0, _structuredClone.default)(value);
275
+ this.value = structuredClone(value);
343
276
  }
344
277
  }
345
-
346
278
  this._gotValue = true;
279
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
347
280
  result = this;
348
281
  }
349
-
350
282
  return result;
351
- } // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBCursor-update-IDBRequest-any-value
352
-
283
+ }
353
284
 
285
+ // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBCursor-update-IDBRequest-any-value
354
286
  update(value) {
355
287
  if (value === undefined) {
356
288
  throw new TypeError();
357
289
  }
358
-
359
290
  const effectiveObjectStore = getEffectiveObjectStore(this);
360
- const effectiveKey = this.source.hasOwnProperty("_rawIndex") ? this.primaryKey : this._position;
291
+ const effectiveKey = Object.hasOwn(this.source, "_rawIndex") ? this.primaryKey : this._position;
361
292
  const transaction = effectiveObjectStore.transaction;
362
-
363
293
  if (transaction._state !== "active") {
364
294
  throw new _errors.TransactionInactiveError();
365
295
  }
366
-
367
296
  if (transaction.mode === "readonly") {
368
297
  throw new _errors.ReadOnlyError();
369
298
  }
370
-
371
299
  if (effectiveObjectStore._rawObjectStore.deleted) {
372
300
  throw new _errors.InvalidStateError();
373
301
  }
374
-
375
302
  if (!(this.source instanceof _FDBObjectStore.default) && this.source._rawIndex.deleted) {
376
303
  throw new _errors.InvalidStateError();
377
304
  }
378
-
379
- if (!this._gotValue || !this.hasOwnProperty("value")) {
305
+ if (!this._gotValue || !Object.hasOwn(this, "value")) {
380
306
  throw new _errors.InvalidStateError();
381
307
  }
382
-
383
- const clone = (0, _structuredClone.default)(value);
384
-
308
+ const clone = structuredClone(value);
385
309
  if (effectiveObjectStore.keyPath !== null) {
386
310
  let tempKey;
387
-
388
311
  try {
389
312
  tempKey = (0, _extractKey.default)(effectiveObjectStore.keyPath, clone);
390
313
  } catch (err) {
391
314
  /* Handled immediately below */
392
315
  }
393
-
394
316
  if ((0, _cmp.default)(tempKey, effectiveKey) !== 0) {
395
317
  throw new _errors.DataError();
396
318
  }
397
319
  }
398
-
399
320
  const record = {
400
321
  key: effectiveKey,
401
322
  value: clone
@@ -404,196 +325,155 @@ class FDBCursor {
404
325
  operation: effectiveObjectStore._rawObjectStore.storeRecord.bind(effectiveObjectStore._rawObjectStore, record, false, transaction._rollbackLog),
405
326
  source: this
406
327
  });
407
- } // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBCursor-advance-void-unsigned-long-count
408
-
328
+ }
409
329
 
330
+ // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBCursor-advance-void-unsigned-long-count
410
331
  advance(count) {
411
332
  if (!Number.isInteger(count) || count <= 0) {
412
333
  throw new TypeError();
413
334
  }
414
-
415
335
  const effectiveObjectStore = getEffectiveObjectStore(this);
416
336
  const transaction = effectiveObjectStore.transaction;
417
-
418
337
  if (transaction._state !== "active") {
419
338
  throw new _errors.TransactionInactiveError();
420
339
  }
421
-
422
340
  if (effectiveObjectStore._rawObjectStore.deleted) {
423
341
  throw new _errors.InvalidStateError();
424
342
  }
425
-
426
343
  if (!(this.source instanceof _FDBObjectStore.default) && this.source._rawIndex.deleted) {
427
344
  throw new _errors.InvalidStateError();
428
345
  }
429
-
430
346
  if (!this._gotValue) {
431
347
  throw new _errors.InvalidStateError();
432
348
  }
433
-
434
349
  if (this._request) {
435
350
  this._request.readyState = "pending";
436
351
  }
437
-
438
352
  transaction._execRequestAsync({
439
353
  operation: () => {
440
354
  let result;
441
-
442
355
  for (let i = 0; i < count; i++) {
443
- result = this._iterate(); // Not sure why this is needed
356
+ result = this._iterate();
444
357
 
358
+ // Not sure why this is needed
445
359
  if (!result) {
446
360
  break;
447
361
  }
448
362
  }
449
-
450
363
  return result;
451
364
  },
452
365
  request: this._request,
453
366
  source: this.source
454
367
  });
455
-
456
368
  this._gotValue = false;
457
- } // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBCursor-continue-void-any-key
458
-
369
+ }
459
370
 
371
+ // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBCursor-continue-void-any-key
460
372
  continue(key) {
461
373
  const effectiveObjectStore = getEffectiveObjectStore(this);
462
374
  const transaction = effectiveObjectStore.transaction;
463
-
464
375
  if (transaction._state !== "active") {
465
376
  throw new _errors.TransactionInactiveError();
466
377
  }
467
-
468
378
  if (effectiveObjectStore._rawObjectStore.deleted) {
469
379
  throw new _errors.InvalidStateError();
470
380
  }
471
-
472
381
  if (!(this.source instanceof _FDBObjectStore.default) && this.source._rawIndex.deleted) {
473
382
  throw new _errors.InvalidStateError();
474
383
  }
475
-
476
384
  if (!this._gotValue) {
477
385
  throw new _errors.InvalidStateError();
478
386
  }
479
-
480
387
  if (key !== undefined) {
481
388
  key = (0, _valueToKey.default)(key);
482
389
  const cmpResult = (0, _cmp.default)(key, this._position);
483
-
484
390
  if (cmpResult <= 0 && (this.direction === "next" || this.direction === "nextunique") || cmpResult >= 0 && (this.direction === "prev" || this.direction === "prevunique")) {
485
391
  throw new _errors.DataError();
486
392
  }
487
393
  }
488
-
489
394
  if (this._request) {
490
395
  this._request.readyState = "pending";
491
396
  }
492
-
493
397
  transaction._execRequestAsync({
494
398
  operation: this._iterate.bind(this, key),
495
399
  request: this._request,
496
400
  source: this.source
497
401
  });
498
-
499
402
  this._gotValue = false;
500
- } // hthttps://w3c.github.io/IndexedDB/#dom-idbcursor-continueprimarykey
501
-
403
+ }
502
404
 
405
+ // hthttps://w3c.github.io/IndexedDB/#dom-idbcursor-continueprimarykey
503
406
  continuePrimaryKey(key, primaryKey) {
504
407
  const effectiveObjectStore = getEffectiveObjectStore(this);
505
408
  const transaction = effectiveObjectStore.transaction;
506
-
507
409
  if (transaction._state !== "active") {
508
410
  throw new _errors.TransactionInactiveError();
509
411
  }
510
-
511
412
  if (effectiveObjectStore._rawObjectStore.deleted) {
512
413
  throw new _errors.InvalidStateError();
513
414
  }
514
-
515
415
  if (!(this.source instanceof _FDBObjectStore.default) && this.source._rawIndex.deleted) {
516
416
  throw new _errors.InvalidStateError();
517
417
  }
518
-
519
418
  if (this.source instanceof _FDBObjectStore.default || this.direction !== "next" && this.direction !== "prev") {
520
419
  throw new _errors.InvalidAccessError();
521
420
  }
522
-
523
421
  if (!this._gotValue) {
524
422
  throw new _errors.InvalidStateError();
525
- } // Not sure about this
526
-
423
+ }
527
424
 
425
+ // Not sure about this
528
426
  if (key === undefined || primaryKey === undefined) {
529
427
  throw new _errors.DataError();
530
428
  }
531
-
532
429
  key = (0, _valueToKey.default)(key);
533
430
  const cmpResult = (0, _cmp.default)(key, this._position);
534
-
535
431
  if (cmpResult === -1 && this.direction === "next" || cmpResult === 1 && this.direction === "prev") {
536
432
  throw new _errors.DataError();
537
433
  }
538
-
539
434
  const cmpResult2 = (0, _cmp.default)(primaryKey, this._objectStorePosition);
540
-
541
435
  if (cmpResult === 0) {
542
436
  if (cmpResult2 <= 0 && this.direction === "next" || cmpResult2 >= 0 && this.direction === "prev") {
543
437
  throw new _errors.DataError();
544
438
  }
545
439
  }
546
-
547
440
  if (this._request) {
548
441
  this._request.readyState = "pending";
549
442
  }
550
-
551
443
  transaction._execRequestAsync({
552
444
  operation: this._iterate.bind(this, key, primaryKey),
553
445
  request: this._request,
554
446
  source: this.source
555
447
  });
556
-
557
448
  this._gotValue = false;
558
449
  }
559
-
560
450
  delete() {
561
451
  const effectiveObjectStore = getEffectiveObjectStore(this);
562
- const effectiveKey = this.source.hasOwnProperty("_rawIndex") ? this.primaryKey : this._position;
452
+ const effectiveKey = Object.hasOwn(this.source, "_rawIndex") ? this.primaryKey : this._position;
563
453
  const transaction = effectiveObjectStore.transaction;
564
-
565
454
  if (transaction._state !== "active") {
566
455
  throw new _errors.TransactionInactiveError();
567
456
  }
568
-
569
457
  if (transaction.mode === "readonly") {
570
458
  throw new _errors.ReadOnlyError();
571
459
  }
572
-
573
460
  if (effectiveObjectStore._rawObjectStore.deleted) {
574
461
  throw new _errors.InvalidStateError();
575
462
  }
576
-
577
463
  if (!(this.source instanceof _FDBObjectStore.default) && this.source._rawIndex.deleted) {
578
464
  throw new _errors.InvalidStateError();
579
465
  }
580
-
581
- if (!this._gotValue || !this.hasOwnProperty("value")) {
466
+ if (!this._gotValue || !Object.hasOwn(this, "value")) {
582
467
  throw new _errors.InvalidStateError();
583
468
  }
584
-
585
469
  return transaction._execRequestAsync({
586
470
  operation: effectiveObjectStore._rawObjectStore.deleteRecord.bind(effectiveObjectStore._rawObjectStore, effectiveKey, transaction._rollbackLog),
587
471
  source: this
588
472
  });
589
473
  }
590
-
591
474
  toString() {
592
475
  return "[object IDBCursor]";
593
476
  }
594
-
595
477
  }
596
-
597
- var _default = FDBCursor;
598
- exports.default = _default;
478
+ var _default = exports.default = FDBCursor;
599
479
  module.exports = exports.default;