fake-indexeddb 3.1.2 → 3.1.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 CHANGED
@@ -1,4 +1,4 @@
1
- # fake-indexeddb [![Build Status](https://travis-ci.org/dumbmatter/fakeIndexedDB.svg?branch=master)](https://travis-ci.org/dumbmatter/fakeIndexedDB)
1
+ # fake-indexeddb ![Build Status](https://github.com/dumbmatter/fakeIndexedDB/actions/workflows/test.yml/badge.svg)
2
2
 
3
3
  This is a pure JS in-memory implementation of [the IndexedDB API](https://w3c.github.io/IndexedDB/). Its main utility is for testing IndexedDB-dependent code in Node.js.
4
4
 
@@ -335,7 +335,7 @@ var FDBCursor = /** @class */ (function () {
335
335
  // "this instanceof FDBCursorWithValue" would be better and not require (this as any), but causes runtime
336
336
  // error due to circular dependency.
337
337
  if (!this._keyOnly &&
338
- this.constructor.name === "FDBCursorWithValue") {
338
+ this.toString() === "[object IDBCursorWithValue]") {
339
339
  this.value = undefined;
340
340
  }
341
341
  result = null;
@@ -349,14 +349,14 @@ var FDBCursor = /** @class */ (function () {
349
349
  if (sourceIsObjectStore) {
350
350
  this._primaryKey = structuredClone_1.default(foundRecord.key);
351
351
  if (!this._keyOnly &&
352
- this.constructor.name === "FDBCursorWithValue") {
352
+ this.toString() === "[object IDBCursorWithValue]") {
353
353
  this.value = structuredClone_1.default(foundRecord.value);
354
354
  }
355
355
  }
356
356
  else {
357
357
  this._primaryKey = structuredClone_1.default(foundRecord.value);
358
358
  if (!this._keyOnly &&
359
- this.constructor.name === "FDBCursorWithValue") {
359
+ this.toString() === "[object IDBCursorWithValue]") {
360
360
  if (this.source instanceof FDBObjectStore_1.default) {
361
361
  // Can't use sourceIsObjectStore because TypeScript
362
362
  throw new Error("This should never happen");
@@ -29,6 +29,7 @@ var errors_1 = require("./lib/errors");
29
29
  var fakeDOMStringList_1 = require("./lib/fakeDOMStringList");
30
30
  var FakeEventTarget_1 = require("./lib/FakeEventTarget");
31
31
  var ObjectStore_1 = require("./lib/ObjectStore");
32
+ var scheduling_1 = require("./lib/scheduling");
32
33
  var validateKeyPath_1 = require("./lib/validateKeyPath");
33
34
  var confirmActiveVersionchangeTransaction = function (database) {
34
35
  if (!database._runningVersionchangeTransaction) {
@@ -60,7 +61,7 @@ var closeConnection = function (connection) {
60
61
  });
61
62
  }
62
63
  else {
63
- setImmediate(function () {
64
+ scheduling_1.queueTask(function () {
64
65
  closeConnection(connection);
65
66
  });
66
67
  }
@@ -27,7 +27,6 @@ var __read = (this && this.__read) || function (o, n) {
27
27
  return ar;
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- require("setimmediate");
31
30
  var FDBDatabase_1 = require("./FDBDatabase");
32
31
  var FDBOpenDBRequest_1 = require("./FDBOpenDBRequest");
33
32
  var FDBVersionChangeEvent_1 = require("./FDBVersionChangeEvent");
@@ -36,12 +35,13 @@ var Database_1 = require("./lib/Database");
36
35
  var enforceRange_1 = require("./lib/enforceRange");
37
36
  var errors_1 = require("./lib/errors");
38
37
  var FakeEvent_1 = require("./lib/FakeEvent");
38
+ var scheduling_1 = require("./lib/scheduling");
39
39
  var waitForOthersClosedDelete = function (databases, name, openDatabases, cb) {
40
40
  var anyOpen = openDatabases.some(function (openDatabase2) {
41
41
  return !openDatabase2._closed && !openDatabase2._closePending;
42
42
  });
43
43
  if (anyOpen) {
44
- setImmediate(function () {
44
+ scheduling_1.queueTask(function () {
45
45
  return waitForOthersClosedDelete(databases, name, openDatabases, cb);
46
46
  });
47
47
  return;
@@ -139,7 +139,7 @@ var runVersionchangeTransaction = function (connection, version, request, cb) {
139
139
  return !openDatabase2._closed && !openDatabase2._closePending;
140
140
  });
141
141
  if (anyOpen2) {
142
- setImmediate(waitForOthersClosed);
142
+ scheduling_1.queueTask(waitForOthersClosed);
143
143
  return;
144
144
  }
145
145
  // Set the version of database to version. This change is considered part of the transaction, and so if the
@@ -168,7 +168,7 @@ var runVersionchangeTransaction = function (connection, version, request, cb) {
168
168
  transaction.addEventListener("abort", function () {
169
169
  connection._runningVersionchangeTransaction = false;
170
170
  request.transaction = null;
171
- setImmediate(function () {
171
+ scheduling_1.queueTask(function () {
172
172
  cb(new errors_1.AbortError());
173
173
  });
174
174
  });
@@ -176,7 +176,7 @@ var runVersionchangeTransaction = function (connection, version, request, cb) {
176
176
  connection._runningVersionchangeTransaction = false;
177
177
  request.transaction = null;
178
178
  // Let other complete event handlers run before continuing
179
- setImmediate(function () {
179
+ scheduling_1.queueTask(function () {
180
180
  if (connection._closePending) {
181
181
  cb(new errors_1.AbortError());
182
182
  }
@@ -226,7 +226,7 @@ var FDBFactory = /** @class */ (function () {
226
226
  var _this = this;
227
227
  var request = new FDBOpenDBRequest_1.default();
228
228
  request.source = null;
229
- setImmediate(function () {
229
+ scheduling_1.queueTask(function () {
230
230
  var db = _this._databases.get(name);
231
231
  var oldVersion = db !== undefined ? db.version : 0;
232
232
  deleteDatabase(_this._databases, name, request, function (err) {
@@ -267,7 +267,7 @@ var FDBFactory = /** @class */ (function () {
267
267
  }
268
268
  var request = new FDBOpenDBRequest_1.default();
269
269
  request.source = null;
270
- setImmediate(function () {
270
+ scheduling_1.queueTask(function () {
271
271
  openDatabase(_this._databases, name, version, request, function (err, connection) {
272
272
  if (err) {
273
273
  request.result = undefined;
@@ -30,6 +30,7 @@ var errors_1 = require("./lib/errors");
30
30
  var fakeDOMStringList_1 = require("./lib/fakeDOMStringList");
31
31
  var FakeEvent_1 = require("./lib/FakeEvent");
32
32
  var FakeEventTarget_1 = require("./lib/FakeEventTarget");
33
+ var scheduling_1 = require("./lib/scheduling");
33
34
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#transaction
34
35
  var FDBTransaction = /** @class */ (function (_super) {
35
36
  __extends(FDBTransaction, _super);
@@ -98,7 +99,7 @@ var FDBTransaction = /** @class */ (function (_super) {
98
99
  }
99
100
  finally { if (e_2) throw e_2.error; }
100
101
  }
101
- setImmediate(function () {
102
+ scheduling_1.queueTask(function () {
102
103
  var event = new FakeEvent_1.default("abort", {
103
104
  bubbles: true,
104
105
  cancelable: false,
@@ -227,12 +228,11 @@ var FDBTransaction = /** @class */ (function (_super) {
227
228
  }
228
229
  }
229
230
  // Give it another chance for new handlers to be set before finishing
230
- setImmediate(this._start.bind(this));
231
+ scheduling_1.queueTask(this._start.bind(this));
231
232
  return;
232
233
  }
233
234
  // Check if transaction complete event needs to be fired
234
235
  if (this._state !== "finished") {
235
- // Either aborted or committed already
236
236
  this._state = "finished";
237
237
  if (!this.error) {
238
238
  var event_3 = new FakeEvent_1.default("complete");
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ var scheduling_1 = require("./scheduling");
3
4
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-database
4
5
  var Database = /** @class */ (function () {
5
6
  function Database(name, version) {
@@ -13,7 +14,7 @@ var Database = /** @class */ (function () {
13
14
  }
14
15
  Database.prototype.processTransactions = function () {
15
16
  var _this = this;
16
- setImmediate(function () {
17
+ scheduling_1.queueTask(function () {
17
18
  var anyRunning = _this.transactions.some(function (transaction) {
18
19
  return (transaction._started && transaction._state !== "finished");
19
20
  });
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // When running within Node.js (including jsdom), we want to use setImmediate
4
+ // (which runs immediately) rather than setTimeout (which enforces a minimum
5
+ // delay of 1ms, and on Windows only has a resolution of 15ms or so). jsdom
6
+ // doesn't provide setImmediate (to better match the browser environment) and
7
+ // sandboxes scripts, but its sandbox is by necessity imperfect, so we can break
8
+ // out of it:
9
+ //
10
+ // - https://github.com/jsdom/jsdom#executing-scripts
11
+ // - https://github.com/jsdom/jsdom/issues/2729
12
+ // - https://github.com/scala-js/scala-js-macrotask-executor/pull/17
13
+ function getSetImmediateFromJsdom() {
14
+ if (typeof navigator !== "undefined" && /jsdom/.test(navigator.userAgent)) {
15
+ var outerRealmFunctionConstructor = Node.constructor;
16
+ return new outerRealmFunctionConstructor("return setImmediate")();
17
+ }
18
+ else {
19
+ return undefined;
20
+ }
21
+ }
22
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
23
+ // Remove this after dropping Node 8 support
24
+ // tslint:disable-next-line
25
+ var getGlobal = function () {
26
+ if (typeof globalThis !== 'undefined') {
27
+ return globalThis;
28
+ }
29
+ if (typeof global !== 'undefined') {
30
+ return global;
31
+ }
32
+ if (typeof self !== 'undefined') {
33
+ return self;
34
+ }
35
+ if (typeof window !== 'undefined') {
36
+ return window;
37
+ }
38
+ throw new Error('unable to locate global object');
39
+ };
40
+ var globals = getGlobal();
41
+ // Schedules a task to run later. Use Node.js's setImmediate if available and
42
+ // setTimeout otherwise. Note that options like process.nextTick or
43
+ // queueMicrotask will likely not work: IndexedDB semantics require that
44
+ // transactions are marked as not active when the event loop runs. The next
45
+ // tick queue and microtask queue run within the current event loop macrotask,
46
+ // so they'd process database operations too quickly.
47
+ exports.queueTask = globals.setImmediate ||
48
+ getSetImmediateFromJsdom() ||
49
+ (function (fn) { return setTimeout(fn, 0); });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fake-indexeddb",
3
- "version": "3.1.2",
3
+ "version": "3.1.7",
4
4
  "description": "Fake IndexedDB: a pure JS in-memory implementation of the IndexedDB API",
5
5
  "homepage": "https://github.com/dumbmatter/fakeIndexedDB",
6
6
  "repository": {
@@ -40,8 +40,7 @@
40
40
  "lib"
41
41
  ],
42
42
  "dependencies": {
43
- "realistic-structured-clone": "^2.0.1",
44
- "setimmediate": "^1.0.5"
43
+ "realistic-structured-clone": "^2.0.1"
45
44
  },
46
45
  "devDependencies": {
47
46
  "@types/mocha": "^5.2.7",
package/CHANGELOG.md DELETED
@@ -1,63 +0,0 @@
1
- # 3.1.1 (2020-07-15)
2
-
3
- - #54 - Fixed a bug where multiple transactions started at the same time could result in a transaction never resolving, if one of the transactions had no database operations inside it. Thank you @medmunds for both finding and fixing this bug!
4
-
5
- # 3.1.1 (2020-07-15)
6
-
7
- - #53 - Fixed a bug introduced in v3.1.0 where `FDBObjectStore.delete` resulted in an error when given a key range. Possibly a couple other situations with key ranges produced similar errors too.
8
-
9
- # 3.1.0 (2020-07-02)
10
-
11
- - #52 - Significant performance improvement. 5.5x faster on a real use case. Thank you @nolanlawson for this speed up!
12
-
13
- # 3.0.2 (2020-06-10)
14
-
15
- * #45 - Fix synchronous event firing in a transaction, which led to a stack overflow when used with Dexie's waitFor function.
16
-
17
- # 3.0.1 (2020-05-25)
18
-
19
- * #41 - Correctly roll back a record added to a store when an index constraint error occurs.
20
-
21
- # 3.0.0 (2019-11-15)
22
-
23
- * Stopped importing core-js by default. This means that, for people using fake-indexeddb in really old environments like PhantomJS, they will now need to import core-js like `require("core-js/stable");` (or something similar) before importing fake-indexeddb.
24
-
25
- # 2.1.1 (2019-06-05)
26
-
27
- * #30 - Fixed typo in the name of the `Event.timeStamp` property.
28
-
29
- # 2.1.0 (2019-03-18)
30
-
31
- * Added the ability to include `fake-indexeddb/auto` and have it populate all the global variables.
32
- * Added support for `IDBTransaction.commit()` and `IDBFactory.databases()`.
33
- * Fixed a couple minor edge cases to improve performance on the web platform tests from 85% to 87%.
34
-
35
- # 2.0.6 (2019-03-14)
36
-
37
- * Fixed issue #26, where event handlers were inappropriately not being called if they added or removed other handlers to the invoking listener in their callbacks.
38
-
39
- # 2.0.5 (2019-02-07)
40
-
41
- * Fixed issue #25 by importing core-js/shim rather than all of core-js.
42
-
43
- # 2.0.4 (2018-02-22)
44
-
45
- * Improved structured cloning, which fixes bugs when used with strange objects like https://github.com/dumbmatter/realistic-structured-clone/issues/5
46
-
47
- # 2.0.3 (2017-05-09)
48
-
49
- * Fixed issue #20 related to iterating over cursors with non-unique keys
50
-
51
- # 2.0.2 (2017-05-01)
52
-
53
- * Include core-js by default to make it work more easily in old environments like PhantomJS
54
-
55
- # 2.0.1 (2017-04-29)
56
-
57
- * Minor updates to README
58
-
59
- # 2.0.0 (2017-04-29)
60
-
61
- * Fully implements the [IndexedDB 2.0 API](https://hacks.mozilla.org/2016/10/whats-new-in-indexeddb-2-0/) (which technically still is a draft, but is probably not going to substantially change).
62
- * Ported to TypeScript, which hopefully means less bugs.
63
- * Dynamically runs [the W3C web-platform-tests](https://github.com/w3c/web-platform-tests/tree/master/IndexedDB) rather than using manually ported tests. This means it's easy to run new tests, and the tests written since the original release of fake-indexeddb turned up several minor bugs which have now been fixed. See `npm run test-w3c`.