fake-indexeddb 6.2.0 → 6.2.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/auto/index.js CHANGED
@@ -22,27 +22,21 @@ var globalVar =
22
22
  ? global
23
23
  : Function("return this;")();
24
24
 
25
- // Match the native behavior for `globalThis.indexedDB`, `globlThis.IDBCursor`, etc.
26
- // Per the IDL, `indexedDB` is readonly but the others are readwrite
25
+ // Partly match the native behavior for `globalThis.indexedDB`, `globalThis.IDBCursor`, etc.
26
+ // Per the IDL, `indexedDB` is readonly but the others are readwrite. For us, though, we want it to still
27
+ // be overwritable with `globalThis.<global> = ...`, so we make them all readwrite.
27
28
  // https://w3c.github.io/IndexedDB/#idl-index
28
- const createPropertyDescriptor = (value, readOnly = false) => {
29
+ const createPropertyDescriptor = (value) => {
29
30
  return {
30
- ...(readOnly
31
- ? {
32
- set: undefined,
33
- get: () => value,
34
- }
35
- : {
36
- value,
37
- writable: true,
38
- }),
31
+ value,
39
32
  enumerable: true,
40
33
  configurable: true,
34
+ writable: true,
41
35
  };
42
36
  };
43
37
 
44
38
  Object.defineProperties(globalVar, {
45
- indexedDB: createPropertyDescriptor(fakeIndexedDB, true),
39
+ indexedDB: createPropertyDescriptor(fakeIndexedDB),
46
40
  IDBCursor: createPropertyDescriptor(FDBCursor),
47
41
  IDBCursorWithValue: createPropertyDescriptor(FDBCursorWithValue),
48
42
  IDBDatabase: createPropertyDescriptor(FDBDatabase),
package/auto/index.mjs CHANGED
@@ -22,27 +22,21 @@ var globalVar =
22
22
  ? global
23
23
  : Function("return this;")();
24
24
 
25
- // Match the native behavior for `globalThis.indexedDB`, `globlThis.IDBCursor`, etc.
26
- // Per the IDL, `indexedDB` is readonly but the others are readwrite
25
+ // Partly match the native behavior for `globalThis.indexedDB`, `globalThis.IDBCursor`, etc.
26
+ // Per the IDL, `indexedDB` is readonly but the others are readwrite. For us, though, we want it to still
27
+ // be overwritable with `globalThis.<global> = ...`, so we make them all readwrite.
27
28
  // https://w3c.github.io/IndexedDB/#idl-index
28
- const createPropertyDescriptor = (value, readOnly = false) => {
29
+ const createPropertyDescriptor = (value) => {
29
30
  return {
30
- ...(readOnly
31
- ? {
32
- set: undefined,
33
- get: () => value,
34
- }
35
- : {
36
- value,
37
- writable: true,
38
- }),
31
+ value,
39
32
  enumerable: true,
40
33
  configurable: true,
34
+ writable: true,
41
35
  };
42
36
  };
43
37
 
44
38
  Object.defineProperties(globalVar, {
45
- indexedDB: createPropertyDescriptor(fakeIndexedDB, true),
39
+ indexedDB: createPropertyDescriptor(fakeIndexedDB),
46
40
  IDBCursor: createPropertyDescriptor(FDBCursor),
47
41
  IDBCursorWithValue: createPropertyDescriptor(FDBCursorWithValue),
48
42
  IDBDatabase: createPropertyDescriptor(FDBDatabase),
@@ -3,15 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.closeConnection = void 0;
6
+ exports.default = void 0;
7
7
  var _FDBTransaction = _interopRequireDefault(require("./FDBTransaction.js"));
8
8
  var _errors = require("./lib/errors.js");
9
9
  var _FakeDOMStringList = _interopRequireDefault(require("./lib/FakeDOMStringList.js"));
10
10
  var _FakeEventTarget = _interopRequireDefault(require("./lib/FakeEventTarget.js"));
11
11
  var _ObjectStore = _interopRequireDefault(require("./lib/ObjectStore.js"));
12
- var _scheduling = require("./lib/scheduling.js");
13
12
  var _validateKeyPath = _interopRequireDefault(require("./lib/validateKeyPath.js"));
14
- var _FakeEvent = _interopRequireDefault(require("./lib/FakeEvent.js"));
13
+ var _closeConnection = _interopRequireDefault(require("./lib/closeConnection.js"));
15
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
15
  const confirmActiveVersionchangeTransaction = database => {
17
16
  if (!database._runningVersionchangeTransaction) {
@@ -32,34 +31,7 @@ const confirmActiveVersionchangeTransaction = database => {
32
31
  return transaction;
33
32
  };
34
33
 
35
- // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#database-closing-steps
36
- const closeConnection = (connection, forced = false) => {
37
- connection._closePending = true;
38
- const transactionsComplete = connection._rawDatabase.transactions.every(transaction => {
39
- return transaction._state === "finished";
40
- });
41
- if (transactionsComplete) {
42
- connection._closed = true;
43
- connection._rawDatabase.connections = connection._rawDatabase.connections.filter(otherConnection => {
44
- return connection !== otherConnection;
45
- });
46
- if (forced) {
47
- const event = new _FakeEvent.default("close", {
48
- bubbles: false,
49
- cancelable: false
50
- });
51
- event.eventPath = [];
52
- connection.dispatchEvent(event);
53
- }
54
- } else {
55
- (0, _scheduling.queueTask)(() => {
56
- closeConnection(connection, forced);
57
- });
58
- }
59
- };
60
-
61
34
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#database-interface
62
- exports.closeConnection = closeConnection;
63
35
  class FDBDatabase extends _FakeEventTarget.default {
64
36
  _closePending = false;
65
37
  _closed = false;
@@ -172,10 +144,11 @@ class FDBDatabase extends _FakeEventTarget.default {
172
144
  return tx;
173
145
  }
174
146
  close() {
175
- closeConnection(this);
147
+ (0, _closeConnection.default)(this);
176
148
  }
177
149
  get [Symbol.toStringTag]() {
178
150
  return "IDBDatabase";
179
151
  }
180
152
  }
181
- var _default = exports.default = FDBDatabase;
153
+ var _default = exports.default = FDBDatabase;
154
+ module.exports = exports.default;
@@ -4,7 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = forceCloseDatabase;
7
- var _FDBDatabase = require("./FDBDatabase.js");
7
+ var _closeConnection = _interopRequireDefault(require("./lib/closeConnection.js"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
9
  /**
9
10
  * Forcibly closes a database. This simulates a database being closed due to abnormal reasons, such as
10
11
  * using DevTools to clear data while a database is open. Spec-wise, this is equivalent to
@@ -23,6 +24,6 @@ var _FDBDatabase = require("./FDBDatabase.js");
23
24
  * @param db
24
25
  */
25
26
  function forceCloseDatabase(db) {
26
- (0, _FDBDatabase.closeConnection)(db, true);
27
+ (0, _closeConnection.default)(db, true);
27
28
  }
28
29
  module.exports = exports.default;
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _FDBRecord = _interopRequireDefault(require("../FDBRecord.js"));
7
8
  var _errors = require("./errors.js");
8
9
  var _extractKey = _interopRequireDefault(require("./extractKey.js"));
9
10
  var _RecordStore = _interopRequireDefault(require("./RecordStore.js"));
10
11
  var _valueToKey = _interopRequireDefault(require("./valueToKey.js"));
11
- var _FDBRecord = _interopRequireDefault(require("../FDBRecord.js"));
12
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
13
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-index
14
14
  class Index {
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _FDBRecord = _interopRequireDefault(require("../FDBRecord.js"));
7
8
  var _errors = require("./errors.js");
8
9
  var _extractKey = _interopRequireDefault(require("./extractKey.js"));
9
10
  var _KeyGenerator = _interopRequireDefault(require("./KeyGenerator.js"));
10
11
  var _RecordStore = _interopRequireDefault(require("./RecordStore.js"));
11
- var _FDBRecord = _interopRequireDefault(require("../FDBRecord.js"));
12
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
13
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-object-store
14
14
  class ObjectStore {
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _cmp = _interopRequireDefault(require("./cmp.js"));
8
7
  var _FDBKeyRange = _interopRequireDefault(require("../FDBKeyRange.js"));
8
+ var _cmp = _interopRequireDefault(require("./cmp.js"));
9
9
  var _errors = require("./errors.js");
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  // what fraction of the total number of nodes are allowed to be deleted tombstones?
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _FakeEvent = _interopRequireDefault(require("./FakeEvent.js"));
8
+ var _scheduling = require("./scheduling.js");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#database-closing-steps
11
+ const closeConnection = (connection, forced = false) => {
12
+ connection._closePending = true;
13
+ const transactionsComplete = connection._rawDatabase.transactions.every(transaction => {
14
+ return transaction._state === "finished";
15
+ });
16
+ if (transactionsComplete) {
17
+ connection._closed = true;
18
+ connection._rawDatabase.connections = connection._rawDatabase.connections.filter(otherConnection => {
19
+ return connection !== otherConnection;
20
+ });
21
+ if (forced) {
22
+ const event = new _FakeEvent.default("close", {
23
+ bubbles: false,
24
+ cancelable: false
25
+ });
26
+ event.eventPath = [];
27
+ connection.dispatchEvent(event);
28
+ }
29
+ } else {
30
+ (0, _scheduling.queueTask)(() => {
31
+ closeConnection(connection, forced);
32
+ });
33
+ }
34
+ };
35
+ var _default = exports.default = closeConnection;
36
+ module.exports = exports.default;
@@ -3,9 +3,8 @@ import { ConstraintError, InvalidAccessError, InvalidStateError, NotFoundError,
3
3
  import FakeDOMStringList from "./lib/FakeDOMStringList.js";
4
4
  import FakeEventTarget from "./lib/FakeEventTarget.js";
5
5
  import ObjectStore from "./lib/ObjectStore.js";
6
- import { queueTask } from "./lib/scheduling.js";
7
6
  import validateKeyPath from "./lib/validateKeyPath.js";
8
- import FakeEvent from "./lib/FakeEvent.js";
7
+ import closeConnection from "./lib/closeConnection.js";
9
8
  const confirmActiveVersionchangeTransaction = database => {
10
9
  if (!database._runningVersionchangeTransaction) {
11
10
  throw new InvalidStateError();
@@ -25,32 +24,6 @@ const confirmActiveVersionchangeTransaction = database => {
25
24
  return transaction;
26
25
  };
27
26
 
28
- // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#database-closing-steps
29
- export const closeConnection = (connection, forced = false) => {
30
- connection._closePending = true;
31
- const transactionsComplete = connection._rawDatabase.transactions.every(transaction => {
32
- return transaction._state === "finished";
33
- });
34
- if (transactionsComplete) {
35
- connection._closed = true;
36
- connection._rawDatabase.connections = connection._rawDatabase.connections.filter(otherConnection => {
37
- return connection !== otherConnection;
38
- });
39
- if (forced) {
40
- const event = new FakeEvent("close", {
41
- bubbles: false,
42
- cancelable: false
43
- });
44
- event.eventPath = [];
45
- connection.dispatchEvent(event);
46
- }
47
- } else {
48
- queueTask(() => {
49
- closeConnection(connection, forced);
50
- });
51
- }
52
- };
53
-
54
27
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#database-interface
55
28
  class FDBDatabase extends FakeEventTarget {
56
29
  _closePending = false;
@@ -1,7 +1,6 @@
1
1
  import cmp from "./lib/cmp.js";
2
2
  import { DataError } from "./lib/errors.js";
3
3
  import valueToKey from "./lib/valueToKey.js";
4
-
5
4
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#range-concept
6
5
  class FDBKeyRange {
7
6
  static only(value) {
@@ -1,5 +1,4 @@
1
- import { closeConnection } from "./FDBDatabase.js";
2
-
1
+ import closeConnection from "./lib/closeConnection.js";
3
2
  /**
4
3
  * Forcibly closes a database. This simulates a database being closed due to abnormal reasons, such as
5
4
  * using DevTools to clear data while a database is open. Spec-wise, this is equivalent to
@@ -1,5 +1,4 @@
1
1
  import { queueTask } from "./scheduling.js";
2
-
3
2
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-database
4
3
  class Database {
5
4
  deletePending = false;
@@ -1,9 +1,8 @@
1
+ import FDBRecord from "../FDBRecord.js";
1
2
  import { ConstraintError } from "./errors.js";
2
3
  import extractKey from "./extractKey.js";
3
4
  import RecordStore from "./RecordStore.js";
4
5
  import valueToKey from "./valueToKey.js";
5
- import FDBRecord from "../FDBRecord.js";
6
-
7
6
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-index
8
7
  class Index {
9
8
  deleted = false;
@@ -1,9 +1,8 @@
1
+ import FDBRecord from "../FDBRecord.js";
1
2
  import { DataError } from "./errors.js";
2
3
  import extractKey from "./extractKey.js";
3
4
  import KeyGenerator from "./KeyGenerator.js";
4
5
  import RecordStore from "./RecordStore.js";
5
- import FDBRecord from "../FDBRecord.js";
6
-
7
6
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-object-store
8
7
  class ObjectStore {
9
8
  deleted = false;
@@ -1,7 +1,6 @@
1
- import cmp from "./cmp.js";
2
1
  import FDBKeyRange from "../FDBKeyRange.js";
2
+ import cmp from "./cmp.js";
3
3
  import { ConstraintError } from "./errors.js";
4
-
5
4
  // what fraction of the total number of nodes are allowed to be deleted tombstones?
6
5
  const MAX_TOMBSTONE_FACTOR = 2 / 3;
7
6
  const EVERYTHING_KEY_RANGE = new FDBKeyRange(undefined, undefined, false, false);
@@ -0,0 +1,28 @@
1
+ import FakeEvent from "./FakeEvent.js";
2
+ import { queueTask } from "./scheduling.js";
3
+ // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#database-closing-steps
4
+ const closeConnection = (connection, forced = false) => {
5
+ connection._closePending = true;
6
+ const transactionsComplete = connection._rawDatabase.transactions.every(transaction => {
7
+ return transaction._state === "finished";
8
+ });
9
+ if (transactionsComplete) {
10
+ connection._closed = true;
11
+ connection._rawDatabase.connections = connection._rawDatabase.connections.filter(otherConnection => {
12
+ return connection !== otherConnection;
13
+ });
14
+ if (forced) {
15
+ const event = new FakeEvent("close", {
16
+ bubbles: false,
17
+ cancelable: false
18
+ });
19
+ event.eventPath = [];
20
+ connection.dispatchEvent(event);
21
+ }
22
+ } else {
23
+ queueTask(() => {
24
+ closeConnection(connection, forced);
25
+ });
26
+ }
27
+ };
28
+ export default closeConnection;
@@ -1,6 +1,5 @@
1
1
  import isPotentiallyValidKeyRange from "./isPotentiallyValidKeyRange.js";
2
2
  import enforceRange from "./enforceRange.js";
3
-
4
3
  // https://www.w3.org/TR/IndexedDB/#create-request-to-retrieve-multiple-items
5
4
  const extractGetAllOptions = (queryOrOptions, count, numArguments) => {
6
5
  let query;
@@ -1,5 +1,4 @@
1
1
  import valueToKey from "./valueToKey.js";
2
-
3
2
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-extracting-a-key-from-a-value-using-a-key-path
4
3
  const extractKey = (keyPath, value) => {
5
4
  if (Array.isArray(keyPath)) {
@@ -1,5 +1,4 @@
1
1
  import { SyntaxError } from "./errors.js";
2
-
3
2
  // http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-valid-key-path
4
3
  const validateKeyPath = (keyPath, parent) => {
5
4
  // This doesn't make sense to me based on the spec, but it is needed to pass the W3C KeyPath tests (see same
@@ -1,6 +1,5 @@
1
1
  import { DataError } from "./errors.js";
2
2
  import isSharedArrayBuffer from "./isSharedArrayBuffer.js";
3
-
4
3
  // https://w3c.github.io/IndexedDB/#convert-value-to-key
5
4
  const valueToKey = (input, seen) => {
6
5
  if (typeof input === "number") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fake-indexeddb",
3
- "version": "6.2.0",
3
+ "version": "6.2.2",
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": {
@@ -131,6 +131,7 @@
131
131
  "dexie": "^4.0.11",
132
132
  "eslint": "^8.57.1",
133
133
  "eslint-config-prettier": "^9.1.0",
134
+ "eslint-plugin-import": "^2.32.0",
134
135
  "glob": "^11.0.2",
135
136
  "husky": "^9.1.7",
136
137
  "jest": "^30.0.0",