fake-indexeddb 2.1.1 → 3.1.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/CHANGELOG.md +16 -0
- package/README.md +70 -8
- package/auto.js +4 -5
- package/build/FDBCursor.js +4 -3
- package/build/FDBDatabase.js +5 -4
- package/build/FDBFactory.js +4 -3
- package/build/FDBTransaction.js +7 -12
- package/build/index.js +0 -1
- package/build/lib/FakeEventTarget.js +4 -3
- package/build/lib/Index.js +4 -3
- package/build/lib/ObjectStore.js +12 -11
- package/build/lib/RecordStore.js +15 -19
- package/build/lib/binarySearch.js +82 -0
- package/build/lib/canInjectKey.js +4 -3
- package/build/lib/extractKey.js +4 -3
- package/build/lib/validateKeyPath.js +4 -3
- package/lib/FDBCursor.js +0 -1
- package/lib/FDBCursorWithValue.js +0 -1
- package/lib/FDBDatabase.js +0 -1
- package/lib/FDBFactory.js +0 -1
- package/lib/FDBIndex.js +0 -1
- package/lib/FDBKeyRange.js +0 -1
- package/lib/FDBObjectStore.js +0 -1
- package/lib/FDBOpenDBRequest.js +0 -1
- package/lib/FDBRequest.js +0 -1
- package/lib/FDBTransaction.js +0 -1
- package/lib/FDBVersionChangeEvent.js +0 -1
- package/package.json +15 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# 3.1.0 (2020-07-02)
|
|
2
|
+
|
|
3
|
+
- #52 - Significant performance improvement. 5.5x faster on a real use case. Thank you @nolanlawson for this speed up!
|
|
4
|
+
|
|
5
|
+
# 3.0.2 (2020-06-10)
|
|
6
|
+
|
|
7
|
+
* #45 - Fix synchronous event firing in a transaction, which led to a stack overflow when used with Dexie's waitFor function.
|
|
8
|
+
|
|
9
|
+
# 3.0.1 (2020-05-25)
|
|
10
|
+
|
|
11
|
+
* #41 - Correctly roll back a record added to a store when an index constraint error occurs.
|
|
12
|
+
|
|
13
|
+
# 3.0.0 (2019-11-15)
|
|
14
|
+
|
|
15
|
+
* 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.
|
|
16
|
+
|
|
1
17
|
# 2.1.1 (2019-06-05)
|
|
2
18
|
|
|
3
19
|
* #30 - Fixed typo in the name of the `Event.timeStamp` property.
|
package/README.md
CHANGED
|
@@ -63,19 +63,81 @@ var IDBKeyRange = require("fake-indexeddb/lib/FDBKeyRange");
|
|
|
63
63
|
// The rest is the same as above.
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
When importing individual classes directly (like `var IDBKeyRange =
|
|
66
|
+
When importing individual classes directly (like `var IDBKeyRange =
|
|
67
|
+
require("fake-indexeddb/lib/FDBKeyRange");` above), file names of all the objects are like the
|
|
68
|
+
normal IndexedDB ones except with F replacing I, e.g. `FDBIndex` instead of `IDBIndex`.
|
|
69
|
+
|
|
70
|
+
### With Dexie and other IndexedDB API wrappers
|
|
71
|
+
|
|
72
|
+
If you import `fake-indexeddb/auto` before calling `new Dexie()`, it should work:
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
const Dexie = require("dexie");
|
|
76
|
+
require("fake-indexeddb/auto");
|
|
77
|
+
|
|
78
|
+
const db = new Dexie("MyDatabase");
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The same likely holds true for other IndexedDB API wrappers like idb.
|
|
82
|
+
|
|
83
|
+
Alternatively, if you don't want to modify the global scope, then you need to explicitly pass the objects to Dexie:
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
const Dexie = require("dexie");
|
|
87
|
+
const indexedDB = require("fake-indexeddb");
|
|
88
|
+
const IDBKeyRange = require("fake-indexeddb/lib/FDBKeyRange");
|
|
89
|
+
|
|
90
|
+
const db = new Dexie("MyDatabase", { indexedDB: indexedDB, IDBKeyRange: IDBKeyRange });
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### With Jest
|
|
94
|
+
|
|
95
|
+
To use this on a single Jest test suite, require `fake-indexeddb/auto` at the beginning of the test
|
|
96
|
+
file, as described above.
|
|
97
|
+
|
|
98
|
+
To use it on all Jest tests without having to require it in each file, add the auto setup script to the `setupFiles` in your Jest config:
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
"jest": {
|
|
102
|
+
...
|
|
103
|
+
"setupFiles": [
|
|
104
|
+
"fake-indexeddb/auto"
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Wiping/resetting the indexedDB for a fresh state
|
|
110
|
+
|
|
111
|
+
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 `fakeIndexedDB` instance, which lets you have a totally fresh start.
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
require("fake-indexeddb/auto");
|
|
115
|
+
const FDBFactory = require("fake-indexeddb/lib/FDBFactory");
|
|
116
|
+
|
|
117
|
+
// Whenever you want a fresh indexedDB
|
|
118
|
+
indexedDB = new FDBFactory();
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### With PhantomJS and other really old environments
|
|
122
|
+
|
|
123
|
+
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:
|
|
124
|
+
|
|
125
|
+
```js
|
|
126
|
+
require("core-js/stable");
|
|
127
|
+
var indexedDB = require("fake-indexeddb");
|
|
128
|
+
```
|
|
67
129
|
|
|
68
130
|
## Quality
|
|
69
131
|
|
|
70
132
|
Here's a comparison of fake-indexeddb and real browser IndexedDB implementations on [the W3C IndexedDB test suite](https://github.com/w3c/web-platform-tests/tree/master/IndexedDB) as of March 18, 2019:
|
|
71
133
|
|
|
72
|
-
Implementation
|
|
73
|
-
|
|
74
|
-
Chrome 73
|
|
75
|
-
Firefox 65
|
|
76
|
-
Safari 12
|
|
77
|
-
fake-indexeddb
|
|
78
|
-
Edge 18
|
|
134
|
+
| Implementation | Percentage of files that pass completely |
|
|
135
|
+
| -------------------- | ---------------------------------------- |
|
|
136
|
+
| Chrome 73 | 99% |
|
|
137
|
+
| Firefox 65 | 97% |
|
|
138
|
+
| Safari 12 | 92% |
|
|
139
|
+
| fake-indexeddb 3.0.0 | 87% |
|
|
140
|
+
| Edge 18 | 61% |
|
|
79
141
|
|
|
80
142
|
For browsers, I ran http://w3c-test.org/tools/runner/index.html and counted the passes. For fake-indexeddb, I ran `npm run test-w3c`.
|
|
81
143
|
|
package/auto.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
require("core-js/shim");
|
|
2
1
|
var fakeIndexedDB = require("./build/fakeIndexedDB").default;
|
|
3
2
|
var FDBCursor = require("./build/FDBCursor").default;
|
|
4
3
|
var FDBCursorWithValue = require("./build/FDBCursorWithValue").default;
|
|
@@ -17,10 +16,10 @@ var globalVar =
|
|
|
17
16
|
typeof window !== "undefined"
|
|
18
17
|
? window
|
|
19
18
|
: typeof WorkerGlobalScope !== "undefined"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
? self
|
|
20
|
+
: typeof global !== "undefined"
|
|
21
|
+
? global
|
|
22
|
+
: Function("return this;")();
|
|
24
23
|
|
|
25
24
|
globalVar.indexedDB = fakeIndexedDB;
|
|
26
25
|
globalVar.IDBCursor = FDBCursor;
|
package/build/FDBCursor.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function
|
|
3
|
-
var
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
4
|
if (m) return m.call(o);
|
|
5
|
-
return {
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
6
|
next: function () {
|
|
7
7
|
if (o && i >= o.length) o = void 0;
|
|
8
8
|
return { value: o && o[i++], done: !o };
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
12
|
};
|
|
12
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
14
|
var FDBKeyRange_1 = require("./FDBKeyRange");
|
package/build/FDBDatabase.js
CHANGED
|
@@ -12,15 +12,16 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
12
12
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
13
|
};
|
|
14
14
|
})();
|
|
15
|
-
var __values = (this && this.__values) || function
|
|
16
|
-
var
|
|
15
|
+
var __values = (this && this.__values) || function(o) {
|
|
16
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
17
17
|
if (m) return m.call(o);
|
|
18
|
-
return {
|
|
18
|
+
if (o && typeof o.length === "number") return {
|
|
19
19
|
next: function () {
|
|
20
20
|
if (o && i >= o.length) o = void 0;
|
|
21
21
|
return { value: o && o[i++], done: !o };
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
24
25
|
};
|
|
25
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
27
|
var FDBTransaction_1 = require("./FDBTransaction");
|
|
@@ -145,8 +146,8 @@ var FDBDatabase = /** @class */ (function (_super) {
|
|
|
145
146
|
transaction._objectStoresCache.delete(name);
|
|
146
147
|
};
|
|
147
148
|
FDBDatabase.prototype.transaction = function (storeNames, mode) {
|
|
148
|
-
var _this = this;
|
|
149
149
|
var e_1, _a;
|
|
150
|
+
var _this = this;
|
|
150
151
|
mode = mode !== undefined ? mode : "readonly";
|
|
151
152
|
if (mode !== "readonly" &&
|
|
152
153
|
mode !== "readwrite" &&
|
package/build/FDBFactory.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function
|
|
3
|
-
var
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
4
|
if (m) return m.call(o);
|
|
5
|
-
return {
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
6
|
next: function () {
|
|
7
7
|
if (o && i >= o.length) o = void 0;
|
|
8
8
|
return { value: o && o[i++], done: !o };
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
12
|
};
|
|
12
13
|
var __read = (this && this.__read) || function (o, n) {
|
|
13
14
|
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
package/build/FDBTransaction.js
CHANGED
|
@@ -12,15 +12,16 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
12
12
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
13
|
};
|
|
14
14
|
})();
|
|
15
|
-
var __values = (this && this.__values) || function
|
|
16
|
-
var
|
|
15
|
+
var __values = (this && this.__values) || function(o) {
|
|
16
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
17
17
|
if (m) return m.call(o);
|
|
18
|
-
return {
|
|
18
|
+
if (o && typeof o.length === "number") return {
|
|
19
19
|
next: function () {
|
|
20
20
|
if (o && i >= o.length) o = void 0;
|
|
21
21
|
return { value: o && o[i++], done: !o };
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
24
25
|
};
|
|
25
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
27
|
var FDBObjectStore_1 = require("./FDBObjectStore");
|
|
@@ -51,8 +52,8 @@ var FDBTransaction = /** @class */ (function (_super) {
|
|
|
51
52
|
}
|
|
52
53
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-aborting-a-transaction
|
|
53
54
|
FDBTransaction.prototype._abort = function (errName) {
|
|
54
|
-
var _this = this;
|
|
55
55
|
var e_1, _a, e_2, _b;
|
|
56
|
+
var _this = this;
|
|
56
57
|
try {
|
|
57
58
|
for (var _c = __values(this._rollbackLog.reverse()), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
58
59
|
var f = _d.value;
|
|
@@ -225,14 +226,8 @@ var FDBTransaction = /** @class */ (function (_super) {
|
|
|
225
226
|
}
|
|
226
227
|
}
|
|
227
228
|
}
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
this._start();
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
// Give it another chance for new handlers to be set before finishing
|
|
234
|
-
setImmediate(this._start.bind(this));
|
|
235
|
-
}
|
|
229
|
+
// Give it another chance for new handlers to be set before finishing
|
|
230
|
+
setImmediate(this._start.bind(this));
|
|
236
231
|
return;
|
|
237
232
|
}
|
|
238
233
|
// Check if transaction complete event needs to be fired
|
package/build/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function
|
|
3
|
-
var
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
4
|
if (m) return m.call(o);
|
|
5
|
-
return {
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
6
|
next: function () {
|
|
7
7
|
if (o && i >= o.length) o = void 0;
|
|
8
8
|
return { value: o && o[i++], done: !o };
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
12
|
};
|
|
12
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
14
|
var errors_1 = require("./errors");
|
package/build/lib/Index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function
|
|
3
|
-
var
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
4
|
if (m) return m.call(o);
|
|
5
|
-
return {
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
6
|
next: function () {
|
|
7
7
|
if (o && i >= o.length) o = void 0;
|
|
8
8
|
return { value: o && o[i++], done: !o };
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
12
|
};
|
|
12
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
14
|
var errors_1 = require("./errors");
|
package/build/lib/ObjectStore.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function
|
|
3
|
-
var
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
4
|
if (m) return m.call(o);
|
|
5
|
-
return {
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
6
|
next: function () {
|
|
7
7
|
if (o && i >= o.length) o = void 0;
|
|
8
8
|
return { value: o && o[i++], done: !o };
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
12
|
};
|
|
12
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
14
|
var errors_1 = require("./errors");
|
|
@@ -90,8 +91,8 @@ var ObjectStore = /** @class */ (function () {
|
|
|
90
91
|
};
|
|
91
92
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-storing-a-record-into-an-object-store
|
|
92
93
|
ObjectStore.prototype.storeRecord = function (newRecord, noOverwrite, rollbackLog) {
|
|
93
|
-
var _this = this;
|
|
94
94
|
var e_3, _a;
|
|
95
|
+
var _this = this;
|
|
95
96
|
if (this.keyPath !== null) {
|
|
96
97
|
var key = extractKey_1.default(this.keyPath, newRecord.value);
|
|
97
98
|
if (key !== undefined) {
|
|
@@ -148,6 +149,11 @@ var ObjectStore = /** @class */ (function () {
|
|
|
148
149
|
this.deleteRecord(newRecord.key, rollbackLog);
|
|
149
150
|
}
|
|
150
151
|
this.records.add(newRecord);
|
|
152
|
+
if (rollbackLog) {
|
|
153
|
+
rollbackLog.push(function () {
|
|
154
|
+
_this.deleteRecord(newRecord.key);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
151
157
|
try {
|
|
152
158
|
// Update indexes
|
|
153
159
|
for (var _b = __values(this.rawIndexes.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -164,17 +170,12 @@ var ObjectStore = /** @class */ (function () {
|
|
|
164
170
|
}
|
|
165
171
|
finally { if (e_3) throw e_3.error; }
|
|
166
172
|
}
|
|
167
|
-
if (rollbackLog) {
|
|
168
|
-
rollbackLog.push(function () {
|
|
169
|
-
_this.deleteRecord(newRecord.key);
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
173
|
return newRecord.key;
|
|
173
174
|
};
|
|
174
175
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-deleting-records-from-an-object-store
|
|
175
176
|
ObjectStore.prototype.deleteRecord = function (key, rollbackLog) {
|
|
176
|
-
var _this = this;
|
|
177
177
|
var e_4, _a, e_5, _b;
|
|
178
|
+
var _this = this;
|
|
178
179
|
var deletedRecords = this.records.delete(key);
|
|
179
180
|
if (rollbackLog) {
|
|
180
181
|
var _loop_1 = function (record) {
|
|
@@ -212,8 +213,8 @@ var ObjectStore = /** @class */ (function () {
|
|
|
212
213
|
};
|
|
213
214
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-steps-for-clearing-an-object-store
|
|
214
215
|
ObjectStore.prototype.clear = function (rollbackLog) {
|
|
215
|
-
var _this = this;
|
|
216
216
|
var e_6, _a, e_7, _b;
|
|
217
|
+
var _this = this;
|
|
217
218
|
var deletedRecords = this.records.clear();
|
|
218
219
|
if (rollbackLog) {
|
|
219
220
|
var _loop_2 = function (record) {
|
package/build/lib/RecordStore.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var FDBKeyRange_1 = require("../FDBKeyRange");
|
|
4
|
+
var binarySearch_1 = require("./binarySearch");
|
|
4
5
|
var cmp_1 = require("./cmp");
|
|
5
6
|
var RecordStore = /** @class */ (function () {
|
|
6
7
|
function RecordStore() {
|
|
@@ -8,13 +9,9 @@ var RecordStore = /** @class */ (function () {
|
|
|
8
9
|
}
|
|
9
10
|
RecordStore.prototype.get = function (key) {
|
|
10
11
|
if (key instanceof FDBKeyRange_1.default) {
|
|
11
|
-
return this.records
|
|
12
|
-
return key.includes(record.key);
|
|
13
|
-
});
|
|
12
|
+
return binarySearch_1.getByKeyRange(this.records, key);
|
|
14
13
|
}
|
|
15
|
-
return this.records
|
|
16
|
-
return cmp_1.default(record.key, key) === 0;
|
|
17
|
-
});
|
|
14
|
+
return binarySearch_1.getByKey(this.records, key);
|
|
18
15
|
};
|
|
19
16
|
RecordStore.prototype.add = function (newRecord) {
|
|
20
17
|
// Find where to put it so it's sorted by key
|
|
@@ -23,11 +20,7 @@ var RecordStore = /** @class */ (function () {
|
|
|
23
20
|
i = 0;
|
|
24
21
|
}
|
|
25
22
|
else {
|
|
26
|
-
i = this.records.
|
|
27
|
-
// cmp will only return 0 for an index. For an object store, any matching key has already been deleted,
|
|
28
|
-
// but we still need to look for cmp = 1 to find where to insert.
|
|
29
|
-
return cmp_1.default(record.key, newRecord.key) >= 0;
|
|
30
|
-
});
|
|
23
|
+
i = binarySearch_1.getIndexByKeyGTE(this.records, newRecord.key);
|
|
31
24
|
if (i === -1) {
|
|
32
25
|
// If no matching key, add to end
|
|
33
26
|
i = this.records.length;
|
|
@@ -47,15 +40,18 @@ var RecordStore = /** @class */ (function () {
|
|
|
47
40
|
this.records.splice(i, 0, newRecord);
|
|
48
41
|
};
|
|
49
42
|
RecordStore.prototype.delete = function (key) {
|
|
50
|
-
var range = key instanceof FDBKeyRange_1.default ? key : FDBKeyRange_1.default.only(key);
|
|
51
43
|
var deletedRecords = [];
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
var isRange = key instanceof FDBKeyRange_1.default;
|
|
45
|
+
while (true) {
|
|
46
|
+
var idx = isRange
|
|
47
|
+
? binarySearch_1.getIndexByKeyRange(this.records, key)
|
|
48
|
+
: binarySearch_1.getIndexByKey(this.records, key);
|
|
49
|
+
if (idx === -1) {
|
|
50
|
+
break;
|
|
56
51
|
}
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
deletedRecords.push(this.records[idx]);
|
|
53
|
+
this.records.splice(idx, 1);
|
|
54
|
+
}
|
|
59
55
|
return deletedRecords;
|
|
60
56
|
};
|
|
61
57
|
RecordStore.prototype.deleteByValue = function (key) {
|
|
@@ -76,9 +72,9 @@ var RecordStore = /** @class */ (function () {
|
|
|
76
72
|
return deletedRecords;
|
|
77
73
|
};
|
|
78
74
|
RecordStore.prototype.values = function (range, direction) {
|
|
75
|
+
var _a;
|
|
79
76
|
var _this = this;
|
|
80
77
|
if (direction === void 0) { direction = "next"; }
|
|
81
|
-
var _a;
|
|
82
78
|
return _a = {},
|
|
83
79
|
_a[Symbol.iterator] = function () {
|
|
84
80
|
var i;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var cmp_1 = require("./cmp");
|
|
4
|
+
/**
|
|
5
|
+
* Classic binary search implementation. Returns the index where the key
|
|
6
|
+
* should be inserted, assuming the records list is ordered.
|
|
7
|
+
*/
|
|
8
|
+
function binarySearch(records, key) {
|
|
9
|
+
var low = 0;
|
|
10
|
+
var high = records.length;
|
|
11
|
+
var mid;
|
|
12
|
+
while (low < high) {
|
|
13
|
+
// tslint:disable-next-line:no-bitwise
|
|
14
|
+
mid = (low + high) >>> 1; // like Math.floor((low + high) / 2) but fast
|
|
15
|
+
if (cmp_1.default(records[mid].key, key) < 0) {
|
|
16
|
+
low = mid + 1;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
high = mid;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return low;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Equivalent to `records.findIndex(record => cmp(record.key, key) === 0)`
|
|
26
|
+
*/
|
|
27
|
+
function getIndexByKey(records, key) {
|
|
28
|
+
var idx = binarySearch(records, key);
|
|
29
|
+
var record = records[idx];
|
|
30
|
+
if (record && cmp_1.default(record.key, key) === 0) {
|
|
31
|
+
return idx;
|
|
32
|
+
}
|
|
33
|
+
return -1;
|
|
34
|
+
}
|
|
35
|
+
exports.getIndexByKey = getIndexByKey;
|
|
36
|
+
/**
|
|
37
|
+
* Equivalent to `records.find(record => cmp(record.key, key) === 0)`
|
|
38
|
+
*/
|
|
39
|
+
function getByKey(records, key) {
|
|
40
|
+
var idx = getIndexByKey(records, key);
|
|
41
|
+
return records[idx];
|
|
42
|
+
}
|
|
43
|
+
exports.getByKey = getByKey;
|
|
44
|
+
/**
|
|
45
|
+
* Equivalent to `records.findIndex(record => key.includes(record.key))`
|
|
46
|
+
*/
|
|
47
|
+
function getIndexByKeyRange(records, keyRange) {
|
|
48
|
+
var lowerIdx = typeof keyRange.lower === "undefined"
|
|
49
|
+
? 0
|
|
50
|
+
: binarySearch(records, keyRange.lower);
|
|
51
|
+
var upperIdx = typeof keyRange.upper === "undefined"
|
|
52
|
+
? records.length - 1
|
|
53
|
+
: binarySearch(records, keyRange.upper);
|
|
54
|
+
for (var i = lowerIdx; i <= upperIdx; i++) {
|
|
55
|
+
var record = records[i];
|
|
56
|
+
if (keyRange.includes(record.key)) {
|
|
57
|
+
return i;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return -1;
|
|
61
|
+
}
|
|
62
|
+
exports.getIndexByKeyRange = getIndexByKeyRange;
|
|
63
|
+
/**
|
|
64
|
+
* Equivalent to `records.find(record => key.includes(record.key))`
|
|
65
|
+
*/
|
|
66
|
+
function getByKeyRange(records, keyRange) {
|
|
67
|
+
var idx = getIndexByKeyRange(records, keyRange);
|
|
68
|
+
return records[idx];
|
|
69
|
+
}
|
|
70
|
+
exports.getByKeyRange = getByKeyRange;
|
|
71
|
+
/**
|
|
72
|
+
* Equivalent to `records.findIndex(record => cmp(record.key, key) >= 0)`
|
|
73
|
+
*/
|
|
74
|
+
function getIndexByKeyGTE(records, key) {
|
|
75
|
+
var idx = binarySearch(records, key);
|
|
76
|
+
var record = records[idx];
|
|
77
|
+
if (record && cmp_1.default(record.key, key) >= 0) {
|
|
78
|
+
return idx;
|
|
79
|
+
}
|
|
80
|
+
return -1;
|
|
81
|
+
}
|
|
82
|
+
exports.getIndexByKeyGTE = getIndexByKeyGTE;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function
|
|
3
|
-
var
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
4
|
if (m) return m.call(o);
|
|
5
|
-
return {
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
6
|
next: function () {
|
|
7
7
|
if (o && i >= o.length) o = void 0;
|
|
8
8
|
return { value: o && o[i++], done: !o };
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
12
|
};
|
|
12
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
14
|
// http://w3c.github.io/IndexedDB/#check-that-a-key-could-be-injected-into-a-value
|
package/build/lib/extractKey.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function
|
|
3
|
-
var
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
4
|
if (m) return m.call(o);
|
|
5
|
-
return {
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
6
|
next: function () {
|
|
7
7
|
if (o && i >= o.length) o = void 0;
|
|
8
8
|
return { value: o && o[i++], done: !o };
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
12
|
};
|
|
12
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
14
|
var valueToKey_1 = require("./valueToKey");
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function
|
|
3
|
-
var
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
4
|
if (m) return m.call(o);
|
|
5
|
-
return {
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
6
|
next: function () {
|
|
7
7
|
if (o && i >= o.length) o = void 0;
|
|
8
8
|
return { value: o && o[i++], done: !o };
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
12
|
};
|
|
12
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
14
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#dfn-valid-key-path
|
package/lib/FDBCursor.js
CHANGED
package/lib/FDBDatabase.js
CHANGED
package/lib/FDBFactory.js
CHANGED
package/lib/FDBIndex.js
CHANGED
package/lib/FDBKeyRange.js
CHANGED
package/lib/FDBObjectStore.js
CHANGED
package/lib/FDBOpenDBRequest.js
CHANGED
package/lib/FDBRequest.js
CHANGED
package/lib/FDBTransaction.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fake-indexeddb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
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": {
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
"main": "build/index.js",
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "rm -rf build && tsc",
|
|
26
|
-
"
|
|
26
|
+
"prepublishOnly": "npm run build && rm -rf build/test",
|
|
27
27
|
"lint": "tslint 'src/**/*.ts'",
|
|
28
28
|
"prettier": "prettier --write *.json 'src/**/*.{js,ts}'",
|
|
29
29
|
"test-mocha": "mocha --timeout 10000 build/test/fakeIndexedDB",
|
|
30
30
|
"build-qunit": "browserify build/test/indexedDBmock/exports-qunit-bundle.js -o build/test/indexedDBmock/exports-qunit-bundle.js && cp src/test/indexedDBmock/index.html build/test/indexedDBmock/index.html",
|
|
31
31
|
"test-qunit": "npm run build-qunit && node-qunit-phantomjs build/test/indexedDBmock/index.html",
|
|
32
32
|
"test-w3c": "node src/test/web-platform-tests/run-all.js",
|
|
33
|
-
"test": "npm run lint && npm run build && npm run test-w3c && npm run test-mocha && npm run test-qunit"
|
|
33
|
+
"test": "npm run lint && npm run build && node test/test.js && npm run test-w3c && npm run test-mocha && npm run test-qunit"
|
|
34
34
|
},
|
|
35
35
|
"author": "Jeremy Scheff <jdscheff@gmail.com> (http://dumbmatter.com/)",
|
|
36
36
|
"license": "Apache-2.0",
|
|
@@ -40,25 +40,25 @@
|
|
|
40
40
|
"lib"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"core-js": "^2.4.1",
|
|
44
43
|
"realistic-structured-clone": "^2.0.1",
|
|
45
44
|
"setimmediate": "^1.0.5"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
|
-
"@types/mocha": "^5.2.
|
|
49
|
-
"@types/node": "^
|
|
50
|
-
"browserify": "^16.
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
47
|
+
"@types/mocha": "^5.2.7",
|
|
48
|
+
"@types/node": "^12.12.7",
|
|
49
|
+
"browserify": "^16.5.0",
|
|
50
|
+
"core-js": "^3.4.1",
|
|
51
|
+
"glob": "^7.1.6",
|
|
52
|
+
"husky": "^3.0.9",
|
|
53
|
+
"lint-staged": "^9.4.3",
|
|
54
|
+
"mocha": "^6.2.2",
|
|
55
55
|
"node-qunit-phantomjs": "^1.6.3",
|
|
56
|
-
"prettier": "^1.
|
|
56
|
+
"prettier": "^1.19.1",
|
|
57
57
|
"qunitjs": "^1.23.1",
|
|
58
|
-
"semver": "^
|
|
59
|
-
"tslint": "^5.
|
|
58
|
+
"semver": "^6.3.0",
|
|
59
|
+
"tslint": "^5.20.1",
|
|
60
60
|
"tslint-config-prettier": "^1.15.0",
|
|
61
|
-
"typescript": "3.
|
|
61
|
+
"typescript": "3.7.2"
|
|
62
62
|
},
|
|
63
63
|
"husky": {
|
|
64
64
|
"hooks": {
|