fake-indexeddb 6.0.1 → 6.2.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 +23 -2
- package/auto/index.js +39 -16
- package/auto/index.mjs +39 -16
- package/build/cjs/FDBCursor.js +2 -2
- package/build/cjs/FDBCursorWithValue.js +2 -2
- package/build/cjs/FDBDatabase.js +27 -9
- package/build/cjs/FDBFactory.js +3 -3
- package/build/cjs/FDBIndex.js +37 -15
- package/build/cjs/FDBKeyRange.js +2 -2
- package/build/cjs/FDBObjectStore.js +37 -15
- package/build/cjs/FDBOpenDBRequest.js +2 -2
- package/build/cjs/FDBRecord.js +36 -0
- package/build/cjs/FDBRequest.js +2 -2
- package/build/cjs/FDBTransaction.js +4 -3
- package/build/cjs/FDBVersionChangeEvent.js +2 -2
- package/build/cjs/forceCloseDatabase.js +28 -0
- package/build/cjs/index.js +14 -0
- package/build/cjs/lib/FakeDOMStringList.js +27 -57
- package/build/cjs/lib/FakeEventTarget.js +1 -0
- package/build/cjs/lib/Index.js +23 -7
- package/build/cjs/lib/ObjectStore.js +40 -14
- package/build/cjs/lib/RecordStore.js +68 -97
- package/build/cjs/lib/binarySearchTree.js +308 -0
- package/build/cjs/lib/errors.js +23 -1
- package/build/cjs/lib/extractGetAllOptions.js +40 -0
- package/build/cjs/lib/extractKey.js +4 -1
- package/build/cjs/lib/getKeyPath.js +16 -0
- package/build/cjs/lib/isPotentiallyValidKeyRange.js +33 -0
- package/build/cjs/lib/isSharedArrayBuffer.js +10 -0
- package/build/cjs/lib/scheduling.js +11 -1
- package/build/cjs/lib/validateKeyPath.js +5 -4
- package/build/cjs/lib/valueToKey.js +10 -5
- package/build/esm/FDBCursor.js +2 -2
- package/build/esm/FDBCursorWithValue.js +2 -2
- package/build/esm/FDBDatabase.js +24 -6
- package/build/esm/FDBFactory.js +3 -3
- package/build/esm/FDBIndex.js +37 -15
- package/build/esm/FDBKeyRange.js +2 -2
- package/build/esm/FDBObjectStore.js +37 -15
- package/build/esm/FDBOpenDBRequest.js +2 -2
- package/build/esm/FDBRecord.js +29 -0
- package/build/esm/FDBRequest.js +2 -2
- package/build/esm/FDBTransaction.js +4 -3
- package/build/esm/FDBVersionChangeEvent.js +2 -2
- package/build/esm/forceCloseDatabase.js +22 -0
- package/build/esm/index.js +3 -1
- package/build/esm/lib/FakeDOMStringList.js +27 -58
- package/build/esm/lib/FakeEventTarget.js +1 -0
- package/build/esm/lib/Index.js +23 -7
- package/build/esm/lib/ObjectStore.js +42 -15
- package/build/esm/lib/RecordStore.js +68 -97
- package/build/esm/lib/binarySearchTree.js +300 -0
- package/build/esm/lib/errors.js +21 -0
- package/build/esm/lib/extractGetAllOptions.js +33 -0
- package/build/esm/lib/extractKey.js +4 -1
- package/build/esm/lib/getKeyPath.js +10 -0
- package/build/esm/lib/isPotentiallyValidKeyRange.js +26 -0
- package/build/esm/lib/isSharedArrayBuffer.js +3 -0
- package/build/esm/lib/scheduling.js +11 -1
- package/build/esm/lib/validateKeyPath.js +2 -0
- package/build/esm/lib/valueToKey.js +10 -5
- package/package.json +15 -10
- package/types.d.ts +4 -0
- package/build/cjs/lib/binarySearch.js +0 -85
- package/build/esm/lib/binarySearch.js +0 -74
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
# fake-indexeddb
|
|
1
|
+
# fake-indexeddb
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
A pure JS in-memory implementation of [the IndexedDB API](https://w3c.github.io/IndexedDB/). Its main use is testing IndexedDB-dependent code in Node.js.
|
|
4
10
|
|
|
5
11
|
## Installation
|
|
6
12
|
|
|
@@ -172,6 +178,21 @@ import { IDBFactory } from "fake-indexeddb";
|
|
|
172
178
|
indexedDB = new IDBFactory();
|
|
173
179
|
```
|
|
174
180
|
|
|
181
|
+
### Triggering the `"close"` event
|
|
182
|
+
|
|
183
|
+
An `IDBDatabase` will fire a `"close"` event when closed for [abnormal reasons](https://www.w3.org/TR/IndexedDB/#closing-connection), such as the user manually deleting databases in DevTools. If you want to simulate this event for test coverage, you can use `forceCloseDatabase()`:
|
|
184
|
+
|
|
185
|
+
```js
|
|
186
|
+
import { forceCloseDatabase } from "fake-indexeddb";
|
|
187
|
+
|
|
188
|
+
db.addEventListener("close", () => {
|
|
189
|
+
console.log("Forcibly closed!");
|
|
190
|
+
});
|
|
191
|
+
forceCloseDatabase(db); // invokes the event listener
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Note that `forceCloseDatabase()` is not a standard IndexedDB API and is unique to fake-indexeddb.
|
|
195
|
+
|
|
175
196
|
### With PhantomJS and other really old environments
|
|
176
197
|
|
|
177
198
|
PhantomJS (and other really old environments) are missing tons of modern JavaScript features. In fact, that may be why you use fake-indexeddb in such an environment! Prior to v3.0.0, fake-indexeddb imported core-js and automatically applied its polyfills. However, since most fake-indexeddb users are not using really old environments, I got rid of that runtime dependency in v3.0.0. To work around that, you can import core-js yourself before you import fake-indexeddb, like:
|
package/auto/index.js
CHANGED
|
@@ -6,6 +6,7 @@ const FDBFactory = require("../build/cjs/FDBFactory.js");
|
|
|
6
6
|
const FDBIndex = require("../build/cjs/FDBIndex.js");
|
|
7
7
|
const FDBKeyRange = require("../build/cjs/FDBKeyRange.js");
|
|
8
8
|
const FDBObjectStore = require("../build/cjs/FDBObjectStore.js");
|
|
9
|
+
const FDBRecord = require("../build/cjs/FDBRecord.js");
|
|
9
10
|
const FDBOpenDBRequest = require("../build/cjs/FDBOpenDBRequest.js");
|
|
10
11
|
const FDBRequest = require("../build/cjs/FDBRequest.js");
|
|
11
12
|
const FDBTransaction = require("../build/cjs/FDBTransaction.js");
|
|
@@ -16,20 +17,42 @@ var globalVar =
|
|
|
16
17
|
typeof window !== "undefined"
|
|
17
18
|
? window
|
|
18
19
|
: typeof WorkerGlobalScope !== "undefined"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
? self
|
|
21
|
+
: typeof global !== "undefined"
|
|
22
|
+
? global
|
|
23
|
+
: Function("return this;")();
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
// Match the native behavior for `globalThis.indexedDB`, `globlThis.IDBCursor`, etc.
|
|
26
|
+
// Per the IDL, `indexedDB` is readonly but the others are readwrite
|
|
27
|
+
// https://w3c.github.io/IndexedDB/#idl-index
|
|
28
|
+
const createPropertyDescriptor = (value, readOnly = false) => {
|
|
29
|
+
return {
|
|
30
|
+
...(readOnly
|
|
31
|
+
? {
|
|
32
|
+
set: undefined,
|
|
33
|
+
get: () => value,
|
|
34
|
+
}
|
|
35
|
+
: {
|
|
36
|
+
value,
|
|
37
|
+
writable: true,
|
|
38
|
+
}),
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
Object.defineProperties(globalVar, {
|
|
45
|
+
indexedDB: createPropertyDescriptor(fakeIndexedDB, true),
|
|
46
|
+
IDBCursor: createPropertyDescriptor(FDBCursor),
|
|
47
|
+
IDBCursorWithValue: createPropertyDescriptor(FDBCursorWithValue),
|
|
48
|
+
IDBDatabase: createPropertyDescriptor(FDBDatabase),
|
|
49
|
+
IDBFactory: createPropertyDescriptor(FDBFactory),
|
|
50
|
+
IDBIndex: createPropertyDescriptor(FDBIndex),
|
|
51
|
+
IDBKeyRange: createPropertyDescriptor(FDBKeyRange),
|
|
52
|
+
IDBObjectStore: createPropertyDescriptor(FDBObjectStore),
|
|
53
|
+
IDBOpenDBRequest: createPropertyDescriptor(FDBOpenDBRequest),
|
|
54
|
+
IDBRecord: createPropertyDescriptor(FDBRecord),
|
|
55
|
+
IDBRequest: createPropertyDescriptor(FDBRequest),
|
|
56
|
+
IDBTransaction: createPropertyDescriptor(FDBTransaction),
|
|
57
|
+
IDBVersionChangeEvent: createPropertyDescriptor(FDBVersionChangeEvent),
|
|
58
|
+
});
|
package/auto/index.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import FDBIndex from "../build/esm/FDBIndex.js";
|
|
|
7
7
|
import FDBKeyRange from "../build/esm/FDBKeyRange.js";
|
|
8
8
|
import FDBObjectStore from "../build/esm/FDBObjectStore.js";
|
|
9
9
|
import FDBOpenDBRequest from "../build/esm/FDBOpenDBRequest.js";
|
|
10
|
+
import FDBRecord from "../build/esm/FDBRecord.js";
|
|
10
11
|
import FDBRequest from "../build/esm/FDBRequest.js";
|
|
11
12
|
import FDBTransaction from "../build/esm/FDBTransaction.js";
|
|
12
13
|
import FDBVersionChangeEvent from "../build/esm/FDBVersionChangeEvent.js";
|
|
@@ -16,20 +17,42 @@ var globalVar =
|
|
|
16
17
|
typeof window !== "undefined"
|
|
17
18
|
? window
|
|
18
19
|
: typeof WorkerGlobalScope !== "undefined"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
? self
|
|
21
|
+
: typeof global !== "undefined"
|
|
22
|
+
? global
|
|
23
|
+
: Function("return this;")();
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
// Match the native behavior for `globalThis.indexedDB`, `globlThis.IDBCursor`, etc.
|
|
26
|
+
// Per the IDL, `indexedDB` is readonly but the others are readwrite
|
|
27
|
+
// https://w3c.github.io/IndexedDB/#idl-index
|
|
28
|
+
const createPropertyDescriptor = (value, readOnly = false) => {
|
|
29
|
+
return {
|
|
30
|
+
...(readOnly
|
|
31
|
+
? {
|
|
32
|
+
set: undefined,
|
|
33
|
+
get: () => value,
|
|
34
|
+
}
|
|
35
|
+
: {
|
|
36
|
+
value,
|
|
37
|
+
writable: true,
|
|
38
|
+
}),
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
Object.defineProperties(globalVar, {
|
|
45
|
+
indexedDB: createPropertyDescriptor(fakeIndexedDB, true),
|
|
46
|
+
IDBCursor: createPropertyDescriptor(FDBCursor),
|
|
47
|
+
IDBCursorWithValue: createPropertyDescriptor(FDBCursorWithValue),
|
|
48
|
+
IDBDatabase: createPropertyDescriptor(FDBDatabase),
|
|
49
|
+
IDBFactory: createPropertyDescriptor(FDBFactory),
|
|
50
|
+
IDBIndex: createPropertyDescriptor(FDBIndex),
|
|
51
|
+
IDBKeyRange: createPropertyDescriptor(FDBKeyRange),
|
|
52
|
+
IDBObjectStore: createPropertyDescriptor(FDBObjectStore),
|
|
53
|
+
IDBOpenDBRequest: createPropertyDescriptor(FDBOpenDBRequest),
|
|
54
|
+
IDBRecord: createPropertyDescriptor(FDBRecord),
|
|
55
|
+
IDBRequest: createPropertyDescriptor(FDBRequest),
|
|
56
|
+
IDBTransaction: createPropertyDescriptor(FDBTransaction),
|
|
57
|
+
IDBVersionChangeEvent: createPropertyDescriptor(FDBVersionChangeEvent),
|
|
58
|
+
});
|
package/build/cjs/FDBCursor.js
CHANGED
|
@@ -11,8 +11,8 @@ class FDBCursorWithValue extends _FDBCursor.default {
|
|
|
11
11
|
constructor(source, range, direction, request) {
|
|
12
12
|
super(source, range, direction, request);
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
return "
|
|
14
|
+
get [Symbol.toStringTag]() {
|
|
15
|
+
return "IDBCursorWithValue";
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
var _default = exports.default = FDBCursorWithValue;
|
package/build/cjs/FDBDatabase.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.closeConnection = 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"));
|
|
@@ -11,6 +11,7 @@ var _FakeEventTarget = _interopRequireDefault(require("./lib/FakeEventTarget.js"
|
|
|
11
11
|
var _ObjectStore = _interopRequireDefault(require("./lib/ObjectStore.js"));
|
|
12
12
|
var _scheduling = require("./lib/scheduling.js");
|
|
13
13
|
var _validateKeyPath = _interopRequireDefault(require("./lib/validateKeyPath.js"));
|
|
14
|
+
var _FakeEvent = _interopRequireDefault(require("./lib/FakeEvent.js"));
|
|
14
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
16
|
const confirmActiveVersionchangeTransaction = database => {
|
|
16
17
|
if (!database._runningVersionchangeTransaction) {
|
|
@@ -32,7 +33,7 @@ const confirmActiveVersionchangeTransaction = database => {
|
|
|
32
33
|
};
|
|
33
34
|
|
|
34
35
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#database-closing-steps
|
|
35
|
-
const closeConnection = connection => {
|
|
36
|
+
const closeConnection = (connection, forced = false) => {
|
|
36
37
|
connection._closePending = true;
|
|
37
38
|
const transactionsComplete = connection._rawDatabase.transactions.every(transaction => {
|
|
38
39
|
return transaction._state === "finished";
|
|
@@ -42,14 +43,23 @@ const closeConnection = connection => {
|
|
|
42
43
|
connection._rawDatabase.connections = connection._rawDatabase.connections.filter(otherConnection => {
|
|
43
44
|
return connection !== otherConnection;
|
|
44
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
|
+
}
|
|
45
54
|
} else {
|
|
46
55
|
(0, _scheduling.queueTask)(() => {
|
|
47
|
-
closeConnection(connection);
|
|
56
|
+
closeConnection(connection, forced);
|
|
48
57
|
});
|
|
49
58
|
}
|
|
50
59
|
};
|
|
51
60
|
|
|
52
61
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#database-interface
|
|
62
|
+
exports.closeConnection = closeConnection;
|
|
53
63
|
class FDBDatabase extends _FakeEventTarget.default {
|
|
54
64
|
_closePending = false;
|
|
55
65
|
_closed = false;
|
|
@@ -121,7 +131,7 @@ class FDBDatabase extends _FakeEventTarget.default {
|
|
|
121
131
|
this._rawDatabase.rawObjectStores.delete(name);
|
|
122
132
|
transaction._objectStoresCache.delete(name);
|
|
123
133
|
}
|
|
124
|
-
transaction(storeNames, mode) {
|
|
134
|
+
transaction(storeNames, mode, options) {
|
|
125
135
|
mode = mode !== undefined ? mode : "readonly";
|
|
126
136
|
if (mode !== "readonly" && mode !== "readwrite" && mode !== "versionchange") {
|
|
127
137
|
throw new TypeError("Invalid mode: " + mode);
|
|
@@ -146,7 +156,16 @@ class FDBDatabase extends _FakeEventTarget.default {
|
|
|
146
156
|
throw new _errors.NotFoundError("No objectStore named " + storeName + " in this database");
|
|
147
157
|
}
|
|
148
158
|
}
|
|
149
|
-
|
|
159
|
+
|
|
160
|
+
// the actual algo is more complex but this passes the IDB tests: https://webidl.spec.whatwg.org/#es-dictionary
|
|
161
|
+
const durability = options?.durability ?? "default";
|
|
162
|
+
// invalid enums throw a TypeError: https://webidl.spec.whatwg.org/#es-enumeration
|
|
163
|
+
if (durability !== "default" && durability !== "strict" && durability !== "relaxed") {
|
|
164
|
+
throw new TypeError(
|
|
165
|
+
// based on Firefox's error message
|
|
166
|
+
`'${durability}' (value of 'durability' member of IDBTransactionOptions) ` + `is not a valid value for enumeration IDBTransactionDurability`);
|
|
167
|
+
}
|
|
168
|
+
const tx = new _FDBTransaction.default(storeNames, mode, durability, this);
|
|
150
169
|
this._rawDatabase.transactions.push(tx);
|
|
151
170
|
this._rawDatabase.processTransactions(); // See if can start right away (async)
|
|
152
171
|
|
|
@@ -155,9 +174,8 @@ class FDBDatabase extends _FakeEventTarget.default {
|
|
|
155
174
|
close() {
|
|
156
175
|
closeConnection(this);
|
|
157
176
|
}
|
|
158
|
-
|
|
159
|
-
return "
|
|
177
|
+
get [Symbol.toStringTag]() {
|
|
178
|
+
return "IDBDatabase";
|
|
160
179
|
}
|
|
161
180
|
}
|
|
162
|
-
var _default = exports.default = FDBDatabase;
|
|
163
|
-
module.exports = exports.default;
|
|
181
|
+
var _default = exports.default = FDBDatabase;
|
package/build/cjs/FDBFactory.js
CHANGED
|
@@ -104,7 +104,7 @@ const runVersionchangeTransaction = (connection, version, request, cb) => {
|
|
|
104
104
|
connection.version = version;
|
|
105
105
|
|
|
106
106
|
// Get rid of this setImmediate?
|
|
107
|
-
const transaction = connection.transaction(connection.objectStoreNames, "versionchange");
|
|
107
|
+
const transaction = connection.transaction(Array.from(connection.objectStoreNames), "versionchange");
|
|
108
108
|
request.result = connection;
|
|
109
109
|
request.readyState = "done";
|
|
110
110
|
request.transaction = transaction;
|
|
@@ -256,8 +256,8 @@ class FDBFactory {
|
|
|
256
256
|
resolve(result);
|
|
257
257
|
});
|
|
258
258
|
}
|
|
259
|
-
|
|
260
|
-
return "
|
|
259
|
+
get [Symbol.toStringTag]() {
|
|
260
|
+
return "IDBFactory";
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
var _default = exports.default = FDBFactory;
|
package/build/cjs/FDBIndex.js
CHANGED
|
@@ -8,11 +8,13 @@ var _FDBCursor = _interopRequireDefault(require("./FDBCursor.js"));
|
|
|
8
8
|
var _FDBCursorWithValue = _interopRequireDefault(require("./FDBCursorWithValue.js"));
|
|
9
9
|
var _FDBKeyRange = _interopRequireDefault(require("./FDBKeyRange.js"));
|
|
10
10
|
var _FDBRequest = _interopRequireDefault(require("./FDBRequest.js"));
|
|
11
|
-
var _enforceRange = _interopRequireDefault(require("./lib/enforceRange.js"));
|
|
12
11
|
var _errors = require("./lib/errors.js");
|
|
13
12
|
var _FakeDOMStringList = _interopRequireDefault(require("./lib/FakeDOMStringList.js"));
|
|
14
13
|
var _valueToKey = _interopRequireDefault(require("./lib/valueToKey.js"));
|
|
15
14
|
var _valueToKeyRange = _interopRequireDefault(require("./lib/valueToKeyRange.js"));
|
|
15
|
+
var _getKeyPath = require("./lib/getKeyPath.js");
|
|
16
|
+
var _extractGetAllOptions = _interopRequireDefault(require("./lib/extractGetAllOptions.js"));
|
|
17
|
+
var _enforceRange = _interopRequireDefault(require("./lib/enforceRange.js"));
|
|
16
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
19
|
const confirmActiveTransaction = index => {
|
|
18
20
|
if (index._rawIndex.deleted || index.objectStore._rawObjectStore.deleted) {
|
|
@@ -29,7 +31,7 @@ class FDBIndex {
|
|
|
29
31
|
this._rawIndex = rawIndex;
|
|
30
32
|
this._name = rawIndex.name;
|
|
31
33
|
this.objectStore = objectStore;
|
|
32
|
-
this.keyPath = rawIndex.keyPath;
|
|
34
|
+
this.keyPath = (0, _getKeyPath.getKeyPath)(rawIndex.keyPath);
|
|
33
35
|
this.multiEntry = rawIndex.multiEntry;
|
|
34
36
|
this.unique = rawIndex.unique;
|
|
35
37
|
}
|
|
@@ -41,7 +43,7 @@ class FDBIndex {
|
|
|
41
43
|
set name(name) {
|
|
42
44
|
const transaction = this.objectStore.transaction;
|
|
43
45
|
if (!transaction.db._runningVersionchangeTransaction) {
|
|
44
|
-
throw new _errors.InvalidStateError();
|
|
46
|
+
throw transaction._state === "active" ? new _errors.InvalidStateError() : new _errors.TransactionInactiveError();
|
|
45
47
|
}
|
|
46
48
|
if (transaction._state !== "active") {
|
|
47
49
|
throw new _errors.TransactionInactiveError();
|
|
@@ -130,14 +132,12 @@ class FDBIndex {
|
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
// http://w3c.github.io/IndexedDB/#dom-idbindex-getall
|
|
133
|
-
getAll(
|
|
134
|
-
|
|
135
|
-
count = (0, _enforceRange.default)(count, "unsigned long");
|
|
136
|
-
}
|
|
135
|
+
getAll(queryOrOptions, count) {
|
|
136
|
+
const options = (0, _extractGetAllOptions.default)(queryOrOptions, count, arguments.length);
|
|
137
137
|
confirmActiveTransaction(this);
|
|
138
|
-
const range = (0, _valueToKeyRange.default)(query);
|
|
138
|
+
const range = (0, _valueToKeyRange.default)(options.query);
|
|
139
139
|
return this.objectStore.transaction._execRequestAsync({
|
|
140
|
-
operation: this._rawIndex.getAllValues.bind(this._rawIndex, range, count),
|
|
140
|
+
operation: this._rawIndex.getAllValues.bind(this._rawIndex, range, options.count, options.direction),
|
|
141
141
|
source: this
|
|
142
142
|
});
|
|
143
143
|
}
|
|
@@ -155,14 +155,36 @@ class FDBIndex {
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
// http://w3c.github.io/IndexedDB/#dom-idbindex-getallkeys
|
|
158
|
-
getAllKeys(
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
getAllKeys(queryOrOptions, count) {
|
|
159
|
+
const options = (0, _extractGetAllOptions.default)(queryOrOptions, count, arguments.length);
|
|
160
|
+
confirmActiveTransaction(this);
|
|
161
|
+
const range = (0, _valueToKeyRange.default)(options.query);
|
|
162
|
+
return this.objectStore.transaction._execRequestAsync({
|
|
163
|
+
operation: this._rawIndex.getAllKeys.bind(this._rawIndex, range, options.count, options.direction),
|
|
164
|
+
source: this
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// https://www.w3.org/TR/IndexedDB/#dom-idbobjectstore-getallrecords
|
|
169
|
+
getAllRecords(options) {
|
|
170
|
+
let query;
|
|
171
|
+
let count;
|
|
172
|
+
let direction;
|
|
173
|
+
if (options !== undefined) {
|
|
174
|
+
if (options.query !== undefined) {
|
|
175
|
+
query = options.query;
|
|
176
|
+
}
|
|
177
|
+
if (options.count !== undefined) {
|
|
178
|
+
count = (0, _enforceRange.default)(options.count, "unsigned long");
|
|
179
|
+
}
|
|
180
|
+
if (options.direction !== undefined) {
|
|
181
|
+
direction = options.direction;
|
|
182
|
+
}
|
|
161
183
|
}
|
|
162
184
|
confirmActiveTransaction(this);
|
|
163
185
|
const range = (0, _valueToKeyRange.default)(query);
|
|
164
186
|
return this.objectStore.transaction._execRequestAsync({
|
|
165
|
-
operation: this._rawIndex.
|
|
187
|
+
operation: this._rawIndex.getAllRecords.bind(this._rawIndex, range, count, direction),
|
|
166
188
|
source: this
|
|
167
189
|
});
|
|
168
190
|
}
|
|
@@ -183,8 +205,8 @@ class FDBIndex {
|
|
|
183
205
|
source: this
|
|
184
206
|
});
|
|
185
207
|
}
|
|
186
|
-
|
|
187
|
-
return "
|
|
208
|
+
get [Symbol.toStringTag]() {
|
|
209
|
+
return "IDBIndex";
|
|
188
210
|
}
|
|
189
211
|
}
|
|
190
212
|
var _default = exports.default = FDBIndex;
|
package/build/cjs/FDBKeyRange.js
CHANGED
|
@@ -10,7 +10,6 @@ var _FDBIndex = _interopRequireDefault(require("./FDBIndex.js"));
|
|
|
10
10
|
var _FDBKeyRange = _interopRequireDefault(require("./FDBKeyRange.js"));
|
|
11
11
|
var _FDBRequest = _interopRequireDefault(require("./FDBRequest.js"));
|
|
12
12
|
var _canInjectKey = _interopRequireDefault(require("./lib/canInjectKey.js"));
|
|
13
|
-
var _enforceRange = _interopRequireDefault(require("./lib/enforceRange.js"));
|
|
14
13
|
var _errors = require("./lib/errors.js");
|
|
15
14
|
var _extractKey = _interopRequireDefault(require("./lib/extractKey.js"));
|
|
16
15
|
var _FakeDOMStringList = _interopRequireDefault(require("./lib/FakeDOMStringList.js"));
|
|
@@ -18,6 +17,9 @@ var _Index = _interopRequireDefault(require("./lib/Index.js"));
|
|
|
18
17
|
var _validateKeyPath = _interopRequireDefault(require("./lib/validateKeyPath.js"));
|
|
19
18
|
var _valueToKey = _interopRequireDefault(require("./lib/valueToKey.js"));
|
|
20
19
|
var _valueToKeyRange = _interopRequireDefault(require("./lib/valueToKeyRange.js"));
|
|
20
|
+
var _getKeyPath = require("./lib/getKeyPath.js");
|
|
21
|
+
var _extractGetAllOptions = _interopRequireDefault(require("./lib/extractGetAllOptions.js"));
|
|
22
|
+
var _enforceRange = _interopRequireDefault(require("./lib/enforceRange.js"));
|
|
21
23
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
24
|
const confirmActiveTransaction = objectStore => {
|
|
23
25
|
if (objectStore._rawObjectStore.deleted) {
|
|
@@ -68,7 +70,7 @@ class FDBObjectStore {
|
|
|
68
70
|
constructor(transaction, rawObjectStore) {
|
|
69
71
|
this._rawObjectStore = rawObjectStore;
|
|
70
72
|
this._name = rawObjectStore.name;
|
|
71
|
-
this.keyPath = rawObjectStore.keyPath;
|
|
73
|
+
this.keyPath = (0, _getKeyPath.getKeyPath)(rawObjectStore.keyPath);
|
|
72
74
|
this.autoIncrement = rawObjectStore.autoIncrement;
|
|
73
75
|
this.transaction = transaction;
|
|
74
76
|
this.indexNames = new _FakeDOMStringList.default(...Array.from(rawObjectStore.rawIndexes.keys()).sort());
|
|
@@ -81,7 +83,7 @@ class FDBObjectStore {
|
|
|
81
83
|
set name(name) {
|
|
82
84
|
const transaction = this.transaction;
|
|
83
85
|
if (!transaction.db._runningVersionchangeTransaction) {
|
|
84
|
-
throw new _errors.InvalidStateError();
|
|
86
|
+
throw transaction._state === "active" ? new _errors.InvalidStateError() : new _errors.TransactionInactiveError();
|
|
85
87
|
}
|
|
86
88
|
confirmActiveTransaction(this);
|
|
87
89
|
name = String(name);
|
|
@@ -171,14 +173,12 @@ class FDBObjectStore {
|
|
|
171
173
|
}
|
|
172
174
|
|
|
173
175
|
// http://w3c.github.io/IndexedDB/#dom-idbobjectstore-getall
|
|
174
|
-
getAll(
|
|
175
|
-
|
|
176
|
-
count = (0, _enforceRange.default)(count, "unsigned long");
|
|
177
|
-
}
|
|
176
|
+
getAll(queryOrOptions, count) {
|
|
177
|
+
const options = (0, _extractGetAllOptions.default)(queryOrOptions, count, arguments.length);
|
|
178
178
|
confirmActiveTransaction(this);
|
|
179
|
-
const range = (0, _valueToKeyRange.default)(query);
|
|
179
|
+
const range = (0, _valueToKeyRange.default)(options.query);
|
|
180
180
|
return this.transaction._execRequestAsync({
|
|
181
|
-
operation: this._rawObjectStore.getAllValues.bind(this._rawObjectStore, range, count),
|
|
181
|
+
operation: this._rawObjectStore.getAllValues.bind(this._rawObjectStore, range, options.count, options.direction),
|
|
182
182
|
source: this
|
|
183
183
|
});
|
|
184
184
|
}
|
|
@@ -199,14 +199,36 @@ class FDBObjectStore {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
// http://w3c.github.io/IndexedDB/#dom-idbobjectstore-getallkeys
|
|
202
|
-
getAllKeys(
|
|
203
|
-
|
|
204
|
-
|
|
202
|
+
getAllKeys(queryOrOptions, count) {
|
|
203
|
+
const options = (0, _extractGetAllOptions.default)(queryOrOptions, count, arguments.length);
|
|
204
|
+
confirmActiveTransaction(this);
|
|
205
|
+
const range = (0, _valueToKeyRange.default)(options.query);
|
|
206
|
+
return this.transaction._execRequestAsync({
|
|
207
|
+
operation: this._rawObjectStore.getAllKeys.bind(this._rawObjectStore, range, options.count, options.direction),
|
|
208
|
+
source: this
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// https://www.w3.org/TR/IndexedDB/#dom-idbobjectstore-getallrecords
|
|
213
|
+
getAllRecords(options) {
|
|
214
|
+
let query;
|
|
215
|
+
let count;
|
|
216
|
+
let direction;
|
|
217
|
+
if (options !== undefined) {
|
|
218
|
+
if (options.query !== undefined) {
|
|
219
|
+
query = options.query;
|
|
220
|
+
}
|
|
221
|
+
if (options.count !== undefined) {
|
|
222
|
+
count = (0, _enforceRange.default)(options.count, "unsigned long");
|
|
223
|
+
}
|
|
224
|
+
if (options.direction !== undefined) {
|
|
225
|
+
direction = options.direction;
|
|
226
|
+
}
|
|
205
227
|
}
|
|
206
228
|
confirmActiveTransaction(this);
|
|
207
229
|
const range = (0, _valueToKeyRange.default)(query);
|
|
208
230
|
return this.transaction._execRequestAsync({
|
|
209
|
-
operation: this._rawObjectStore.
|
|
231
|
+
operation: this._rawObjectStore.getAllRecords.bind(this._rawObjectStore, range, count, direction),
|
|
210
232
|
source: this
|
|
211
233
|
});
|
|
212
234
|
}
|
|
@@ -375,8 +397,8 @@ class FDBObjectStore {
|
|
|
375
397
|
source: this
|
|
376
398
|
});
|
|
377
399
|
}
|
|
378
|
-
|
|
379
|
-
return "
|
|
400
|
+
get [Symbol.toStringTag]() {
|
|
401
|
+
return "IDBObjectStore";
|
|
380
402
|
}
|
|
381
403
|
}
|
|
382
404
|
var _default = exports.default = FDBObjectStore;
|
|
@@ -9,8 +9,8 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
9
9
|
class FDBOpenDBRequest extends _FDBRequest.default {
|
|
10
10
|
onupgradeneeded = null;
|
|
11
11
|
onblocked = null;
|
|
12
|
-
|
|
13
|
-
return "
|
|
12
|
+
get [Symbol.toStringTag]() {
|
|
13
|
+
return "IDBOpenDBRequest";
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
var _default = exports.default = FDBOpenDBRequest;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
class FDBRecord {
|
|
8
|
+
constructor(key, primaryKey, value) {
|
|
9
|
+
this._key = key;
|
|
10
|
+
this._primaryKey = primaryKey;
|
|
11
|
+
this._value = value;
|
|
12
|
+
}
|
|
13
|
+
get key() {
|
|
14
|
+
return this._key;
|
|
15
|
+
}
|
|
16
|
+
set key(_) {
|
|
17
|
+
/* for babel */
|
|
18
|
+
}
|
|
19
|
+
get primaryKey() {
|
|
20
|
+
return this._primaryKey;
|
|
21
|
+
}
|
|
22
|
+
set primaryKey(_) {
|
|
23
|
+
/* for babel */
|
|
24
|
+
}
|
|
25
|
+
get value() {
|
|
26
|
+
return this._value;
|
|
27
|
+
}
|
|
28
|
+
set value(_) {
|
|
29
|
+
/* for babel */
|
|
30
|
+
}
|
|
31
|
+
get [Symbol.toStringTag]() {
|
|
32
|
+
return "IDBRecord";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
var _default = exports.default = FDBRecord;
|
|
36
|
+
module.exports = exports.default;
|
package/build/cjs/FDBRequest.js
CHANGED
|
@@ -33,8 +33,8 @@ class FDBRequest extends _FakeEventTarget.default {
|
|
|
33
33
|
set result(value) {
|
|
34
34
|
this._result = value;
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
return "
|
|
36
|
+
get [Symbol.toStringTag]() {
|
|
37
|
+
return "IDBRequest";
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
var _default = exports.default = FDBRequest;
|
|
@@ -23,10 +23,11 @@ class FDBTransaction extends _FakeEventTarget.default {
|
|
|
23
23
|
oncomplete = null;
|
|
24
24
|
onerror = null;
|
|
25
25
|
_requests = [];
|
|
26
|
-
constructor(storeNames, mode, db) {
|
|
26
|
+
constructor(storeNames, mode, durability, db) {
|
|
27
27
|
super();
|
|
28
28
|
this._scope = new Set(storeNames);
|
|
29
29
|
this.mode = mode;
|
|
30
|
+
this.durability = durability;
|
|
30
31
|
this.db = db;
|
|
31
32
|
this.objectStoreNames = new _FakeDOMStringList.default(...Array.from(this._scope).sort());
|
|
32
33
|
}
|
|
@@ -213,8 +214,8 @@ class FDBTransaction extends _FakeEventTarget.default {
|
|
|
213
214
|
}
|
|
214
215
|
this._state = "committing";
|
|
215
216
|
}
|
|
216
|
-
|
|
217
|
-
return "
|
|
217
|
+
get [Symbol.toStringTag]() {
|
|
218
|
+
return "IDBTransaction";
|
|
218
219
|
}
|
|
219
220
|
}
|
|
220
221
|
var _default = exports.default = FDBTransaction;
|
|
@@ -12,8 +12,8 @@ class FDBVersionChangeEvent extends _FakeEvent.default {
|
|
|
12
12
|
this.newVersion = parameters.newVersion !== undefined ? parameters.newVersion : null;
|
|
13
13
|
this.oldVersion = parameters.oldVersion !== undefined ? parameters.oldVersion : 0;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
return "
|
|
15
|
+
get [Symbol.toStringTag]() {
|
|
16
|
+
return "IDBVersionChangeEvent";
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
var _default = exports.default = FDBVersionChangeEvent;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = forceCloseDatabase;
|
|
7
|
+
var _FDBDatabase = require("./FDBDatabase.js");
|
|
8
|
+
/**
|
|
9
|
+
* Forcibly closes a database. This simulates a database being closed due to abnormal reasons, such as
|
|
10
|
+
* using DevTools to clear data while a database is open. Spec-wise, this is equivalent to
|
|
11
|
+
* [closing a database connection](https://www.w3.org/TR/IndexedDB/#closing-connection) with the `forced flag`
|
|
12
|
+
* set to true.
|
|
13
|
+
*
|
|
14
|
+
* Use this API if you want to have more test coverage for unusual IndexedDB events, such as a database firing
|
|
15
|
+
* the "close" event:
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* db.addEventListener("close", () => {
|
|
19
|
+
* console.log("Forcibly closed!");
|
|
20
|
+
* });
|
|
21
|
+
* forceCloseDatabase(db); // invokes the event listener
|
|
22
|
+
* ```
|
|
23
|
+
* @param db
|
|
24
|
+
*/
|
|
25
|
+
function forceCloseDatabase(db) {
|
|
26
|
+
(0, _FDBDatabase.closeConnection)(db, true);
|
|
27
|
+
}
|
|
28
|
+
module.exports = exports.default;
|