fake-indexeddb 6.2.2 → 6.2.4
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 -15
- package/auto/index.js +1 -1
- package/auto/index.mjs +1 -1
- package/build/cjs/FDBCursor.js +2 -1
- package/build/cjs/FDBDatabase.js +45 -20
- package/build/cjs/FDBFactory.js +285 -137
- package/build/cjs/FDBIndex.js +13 -9
- package/build/cjs/FDBObjectStore.js +26 -22
- package/build/cjs/FDBTransaction.js +51 -11
- package/build/cjs/lib/Database.js +25 -12
- package/build/cjs/lib/FakeEventTarget.js +17 -5
- package/build/cjs/lib/ObjectStore.js +60 -20
- package/build/cjs/lib/cloneValueForInsertion.js +30 -0
- package/build/cjs/lib/extractGetAllOptions.js +2 -2
- package/build/cjs/lib/intersection.js +18 -0
- package/build/cjs/lib/isPotentiallyValidKeyRange.js +13 -20
- package/build/cjs/lib/scheduling.js +4 -4
- package/build/cjs/lib/validateRequiredArguments.js +13 -0
- package/build/cjs/lib/valueToKey.js +8 -53
- package/build/cjs/lib/valueToKeyWithoutThrowing.js +102 -0
- package/build/esm/FDBCursor.js +2 -1
- package/build/esm/FDBDatabase.js +45 -20
- package/build/esm/FDBFactory.js +285 -137
- package/build/esm/FDBIndex.js +13 -9
- package/build/esm/FDBObjectStore.js +26 -22
- package/build/esm/FDBTransaction.js +51 -11
- package/build/esm/lib/Database.js +25 -12
- package/build/esm/lib/FakeEventTarget.js +17 -5
- package/build/esm/lib/ObjectStore.js +60 -20
- package/build/esm/lib/cloneValueForInsertion.js +24 -0
- package/build/esm/lib/extractGetAllOptions.js +2 -2
- package/build/esm/lib/intersection.js +12 -0
- package/build/esm/lib/isPotentiallyValidKeyRange.js +12 -20
- package/build/esm/lib/scheduling.js +4 -4
- package/build/esm/lib/validateRequiredArguments.js +7 -0
- package/build/esm/lib/valueToKey.js +7 -52
- package/build/esm/lib/valueToKeyWithoutThrowing.js +95 -0
- package/package.json +4 -2
package/build/cjs/FDBFactory.js
CHANGED
|
@@ -13,7 +13,17 @@ var _enforceRange = _interopRequireDefault(require("./lib/enforceRange.js"));
|
|
|
13
13
|
var _errors = require("./lib/errors.js");
|
|
14
14
|
var _FakeEvent = _interopRequireDefault(require("./lib/FakeEvent.js"));
|
|
15
15
|
var _scheduling = require("./lib/scheduling.js");
|
|
16
|
+
var _validateRequiredArguments = require("./lib/validateRequiredArguments.js");
|
|
16
17
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
// https://w3c.github.io/IndexedDB/#connection-queue
|
|
19
|
+
const runTaskInConnectionQueue = (connectionQueues, name, task) => {
|
|
20
|
+
// Let queue be the connection queue for storageKey and name.
|
|
21
|
+
// (note FakeIndexedDB does not support storageKeys currently)
|
|
22
|
+
// Add request to queue.
|
|
23
|
+
// Wait until all previous requests in queue have been processed.
|
|
24
|
+
const queue = connectionQueues.get(name) ?? Promise.resolve();
|
|
25
|
+
connectionQueues.set(name, queue.then(task));
|
|
26
|
+
};
|
|
17
27
|
const waitForOthersClosedDelete = (databases, name, openDatabases, cb) => {
|
|
18
28
|
const anyOpen = openDatabases.some(openDatabase2 => {
|
|
19
29
|
return !openDatabase2._closed && !openDatabase2._closePending;
|
|
@@ -26,164 +36,293 @@ const waitForOthersClosedDelete = (databases, name, openDatabases, cb) => {
|
|
|
26
36
|
cb(null);
|
|
27
37
|
};
|
|
28
38
|
|
|
29
|
-
//
|
|
30
|
-
const deleteDatabase = (databases, name, request, cb) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
// https://w3c.github.io/IndexedDB/#delete-a-database
|
|
40
|
+
const deleteDatabase = (databases, connectionQueues, name, request, cb) => {
|
|
41
|
+
const deleteDBTask = () => {
|
|
42
|
+
return new Promise(resolve => {
|
|
43
|
+
const db = databases.get(name);
|
|
44
|
+
const oldVersion = db !== undefined ? db.version : 0;
|
|
45
|
+
const onComplete = err => {
|
|
46
|
+
try {
|
|
47
|
+
if (err) {
|
|
48
|
+
cb(err);
|
|
49
|
+
} else {
|
|
50
|
+
cb(null, oldVersion);
|
|
51
|
+
}
|
|
52
|
+
} finally {
|
|
53
|
+
resolve();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
try {
|
|
57
|
+
const db = databases.get(name);
|
|
58
|
+
if (db === undefined) {
|
|
59
|
+
onComplete(null);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Let openConnections be the set of all connections associated with db.
|
|
64
|
+
const openConnections = db.connections.filter(connection => {
|
|
65
|
+
return !connection._closed;
|
|
46
66
|
});
|
|
47
|
-
|
|
67
|
+
|
|
68
|
+
// For each entry of openConnections that does not have its close pending flag set to true, queue a
|
|
69
|
+
// database task to fire a version change event named versionchange at entry with db’s version and null.
|
|
70
|
+
for (const openDatabase2 of openConnections) {
|
|
71
|
+
if (!openDatabase2._closePending) {
|
|
72
|
+
(0, _scheduling.queueTask)(() => {
|
|
73
|
+
const event = new _FDBVersionChangeEvent.default("versionchange", {
|
|
74
|
+
newVersion: null,
|
|
75
|
+
oldVersion: db.version
|
|
76
|
+
});
|
|
77
|
+
openDatabase2.dispatchEvent(event);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Wait for all of the events to be fired. (i.e. queue a task)
|
|
83
|
+
(0, _scheduling.queueTask)(() => {
|
|
84
|
+
// If any of the connections in openConnections are still not closed, queue a database task to
|
|
85
|
+
// fire a version change event named blocked at request with db’s version and null.
|
|
86
|
+
|
|
87
|
+
const anyOpen = openConnections.some(openDatabase3 => {
|
|
88
|
+
return !openDatabase3._closed && !openDatabase3._closePending;
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// If any of the connections in openConnections are still not closed, queue a database task to
|
|
92
|
+
// fire a version change event named blocked at request with db’s version and null.
|
|
93
|
+
if (anyOpen) {
|
|
94
|
+
(0, _scheduling.queueTask)(() => {
|
|
95
|
+
const event = new _FDBVersionChangeEvent.default("blocked", {
|
|
96
|
+
newVersion: null,
|
|
97
|
+
oldVersion: db.version
|
|
98
|
+
});
|
|
99
|
+
request.dispatchEvent(event);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Wait until all connections in openConnections are closed.
|
|
104
|
+
waitForOthersClosedDelete(databases, name, openConnections, onComplete);
|
|
105
|
+
});
|
|
106
|
+
} catch (err) {
|
|
107
|
+
onComplete(err);
|
|
48
108
|
}
|
|
49
|
-
}
|
|
50
|
-
const anyOpen = openDatabases.some(openDatabase3 => {
|
|
51
|
-
return !openDatabase3._closed && !openDatabase3._closePending;
|
|
52
109
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
newVersion: null,
|
|
56
|
-
oldVersion: db.version
|
|
57
|
-
});
|
|
58
|
-
request.dispatchEvent(event);
|
|
59
|
-
}
|
|
60
|
-
waitForOthersClosedDelete(databases, name, openDatabases, cb);
|
|
61
|
-
} catch (err) {
|
|
62
|
-
cb(err);
|
|
63
|
-
}
|
|
110
|
+
};
|
|
111
|
+
runTaskInConnectionQueue(connectionQueues, name, deleteDBTask);
|
|
64
112
|
};
|
|
65
113
|
|
|
66
|
-
//
|
|
114
|
+
// https://w3c.github.io/IndexedDB/#ref-for-database-version%E2%91%A0%E2%91%A2
|
|
67
115
|
const runVersionchangeTransaction = (connection, version, request, cb) => {
|
|
68
116
|
connection._runningVersionchangeTransaction = true;
|
|
69
|
-
const oldVersion = connection.version;
|
|
70
|
-
|
|
117
|
+
const oldVersion = connection._oldVersion = connection.version;
|
|
118
|
+
|
|
119
|
+
// Let openConnections be the set of all connections, except connection, associated with db.
|
|
120
|
+
const openConnections = connection._rawDatabase.connections.filter(otherDatabase => {
|
|
71
121
|
return connection !== otherDatabase;
|
|
72
122
|
});
|
|
73
|
-
|
|
123
|
+
|
|
124
|
+
// For each entry of openConnections that does not have its close pending flag set to true, queue a
|
|
125
|
+
// database task to fire a version change event named versionchange at entry with db’s version and version.
|
|
126
|
+
for (const openDatabase2 of openConnections) {
|
|
74
127
|
if (!openDatabase2._closed && !openDatabase2._closePending) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
128
|
+
(0, _scheduling.queueTask)(() => {
|
|
129
|
+
const event = new _FDBVersionChangeEvent.default("versionchange", {
|
|
130
|
+
newVersion: version,
|
|
131
|
+
oldVersion
|
|
132
|
+
});
|
|
133
|
+
openDatabase2.dispatchEvent(event);
|
|
78
134
|
});
|
|
79
|
-
openDatabase2.dispatchEvent(event);
|
|
80
135
|
}
|
|
81
136
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
oldVersion
|
|
89
|
-
});
|
|
90
|
-
request.dispatchEvent(event);
|
|
91
|
-
}
|
|
92
|
-
const waitForOthersClosed = () => {
|
|
93
|
-
const anyOpen2 = openDatabases.some(openDatabase2 => {
|
|
94
|
-
return !openDatabase2._closed && !openDatabase2._closePending;
|
|
137
|
+
|
|
138
|
+
// Wait for all of the events to be fired.
|
|
139
|
+
// (i.e. queue a task)
|
|
140
|
+
(0, _scheduling.queueTask)(() => {
|
|
141
|
+
const anyOpen = openConnections.some(openDatabase3 => {
|
|
142
|
+
return !openDatabase3._closed && !openDatabase3._closePending;
|
|
95
143
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
144
|
+
|
|
145
|
+
// If any of the connections in openConnections are still not closed, queue a database task to fire a version change event named blocked at request with db’s version and version.
|
|
146
|
+
if (anyOpen) {
|
|
147
|
+
(0, _scheduling.queueTask)(() => {
|
|
148
|
+
const event = new _FDBVersionChangeEvent.default("blocked", {
|
|
149
|
+
newVersion: version,
|
|
150
|
+
oldVersion
|
|
151
|
+
});
|
|
152
|
+
request.dispatchEvent(event);
|
|
153
|
+
});
|
|
99
154
|
}
|
|
100
155
|
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
156
|
+
// Wait until all connections in openConnections are closed.
|
|
157
|
+
const waitForOthersClosed = () => {
|
|
158
|
+
const anyOpen2 = openConnections.some(openDatabase2 => {
|
|
159
|
+
return !openDatabase2._closed && !openDatabase2._closePending;
|
|
160
|
+
});
|
|
161
|
+
if (anyOpen2) {
|
|
162
|
+
(0, _scheduling.queueTask)(waitForOthersClosed);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
105
165
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
connection.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
request.transaction = null;
|
|
128
|
-
(0, _scheduling.queueTask)(() => {
|
|
129
|
-
cb(new _errors.AbortError());
|
|
166
|
+
// Set the version of database to version. This change is considered part of the transaction, and so if the
|
|
167
|
+
// transaction is aborted, this change is reverted.
|
|
168
|
+
connection._rawDatabase.version = version;
|
|
169
|
+
connection.version = version;
|
|
170
|
+
|
|
171
|
+
// Get rid of this setImmediate?
|
|
172
|
+
const transaction = connection.transaction(Array.from(connection.objectStoreNames), "versionchange");
|
|
173
|
+
|
|
174
|
+
// associate the transaction with the open request for later lookup
|
|
175
|
+
transaction._openRequest = request;
|
|
176
|
+
|
|
177
|
+
// https://w3c.github.io/IndexedDB/#upgrade-a-database
|
|
178
|
+
// Set request’s result to connection.
|
|
179
|
+
request.result = connection;
|
|
180
|
+
// Set request’s done flag to true.
|
|
181
|
+
request.readyState = "done";
|
|
182
|
+
// Set request’s transaction to transaction.
|
|
183
|
+
request.transaction = transaction;
|
|
184
|
+
transaction._rollbackLog.push(() => {
|
|
185
|
+
connection._rawDatabase.version = oldVersion;
|
|
186
|
+
connection.version = oldVersion;
|
|
130
187
|
});
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// Let
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
188
|
+
|
|
189
|
+
// Set transaction’s state to active.
|
|
190
|
+
transaction._state = "active";
|
|
191
|
+
|
|
192
|
+
// Let didThrow be the result of firing a version change event named upgradeneeded at request with old version and version.
|
|
193
|
+
const event = new _FDBVersionChangeEvent.default("upgradeneeded", {
|
|
194
|
+
newVersion: version,
|
|
195
|
+
oldVersion
|
|
196
|
+
});
|
|
197
|
+
let didThrow = false;
|
|
198
|
+
try {
|
|
199
|
+
request.dispatchEvent(event);
|
|
200
|
+
} catch (_err) {
|
|
201
|
+
didThrow = true;
|
|
202
|
+
}
|
|
203
|
+
const concludeUpgrade = () => {
|
|
204
|
+
// If transaction’s state is active, then:
|
|
205
|
+
if (transaction._state === "active") {
|
|
206
|
+
// Set transaction’s state to inactive.
|
|
207
|
+
transaction._state = "inactive";
|
|
208
|
+
if (didThrow) {
|
|
209
|
+
// If didThrow is true, run abort a transaction with transaction and a newly created "AbortError" DOMException.
|
|
210
|
+
transaction._abort("AbortError");
|
|
211
|
+
}
|
|
141
212
|
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
// The "upgrade a database" steps are supposed to run as a database task on the database access task source
|
|
216
|
+
// (i.e. off the main thread), but since we're actually running on the main thread, we have to be tricky:
|
|
217
|
+
// 1. If any `upgradeneeded` event handlers errored, abort synchronously
|
|
218
|
+
// 2. Else yield to allow any microtasks to run in response to that event
|
|
219
|
+
if (didThrow) {
|
|
220
|
+
concludeUpgrade();
|
|
221
|
+
} else {
|
|
222
|
+
(0, _scheduling.queueTask)(concludeUpgrade);
|
|
223
|
+
}
|
|
224
|
+
transaction.addEventListener("error", () => {
|
|
225
|
+
connection._runningVersionchangeTransaction = false;
|
|
226
|
+
connection._oldVersion = undefined;
|
|
227
|
+
// throw arguments[0].target.error;
|
|
228
|
+
// console.log("error in versionchange transaction - not sure if anything needs to be done here", e.target.error.name);
|
|
142
229
|
});
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
230
|
+
transaction.addEventListener("abort", () => {
|
|
231
|
+
connection._runningVersionchangeTransaction = false;
|
|
232
|
+
connection._oldVersion = undefined;
|
|
233
|
+
request.transaction = null;
|
|
234
|
+
(0, _scheduling.queueTask)(() => {
|
|
235
|
+
cb(new _errors.AbortError());
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
transaction.addEventListener("complete", () => {
|
|
239
|
+
connection._runningVersionchangeTransaction = false;
|
|
240
|
+
connection._oldVersion = undefined;
|
|
241
|
+
request.transaction = null;
|
|
242
|
+
// Let other complete event handlers run before continuing
|
|
243
|
+
(0, _scheduling.queueTask)(() => {
|
|
244
|
+
if (connection._closePending) {
|
|
245
|
+
cb(new _errors.AbortError());
|
|
246
|
+
} else {
|
|
247
|
+
cb(null);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
waitForOthersClosed();
|
|
253
|
+
});
|
|
146
254
|
};
|
|
147
255
|
|
|
148
|
-
//
|
|
149
|
-
const openDatabase = (databases, name, version, request, cb) => {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
256
|
+
// https://w3c.github.io/IndexedDB/#opening
|
|
257
|
+
const openDatabase = (databases, connectionQueues, name, version, request, cb) => {
|
|
258
|
+
const openDBTask = () => {
|
|
259
|
+
return new Promise(resolve => {
|
|
260
|
+
const onComplete = err => {
|
|
261
|
+
try {
|
|
262
|
+
if (err) {
|
|
263
|
+
// DO THIS HERE: ensure that connection is closed by running the steps for closing a database connection before these
|
|
264
|
+
// steps are aborted.
|
|
265
|
+
cb(err);
|
|
266
|
+
} else {
|
|
267
|
+
cb(null, connection);
|
|
268
|
+
}
|
|
269
|
+
} finally {
|
|
270
|
+
resolve();
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
// Let db be the database named name in storageKey, or null otherwise.
|
|
275
|
+
let db = databases.get(name);
|
|
276
|
+
if (db === undefined) {
|
|
277
|
+
// If db is null, let db be a new database with name `name`, version 0 (zero), and with no object stores.
|
|
278
|
+
db = new _Database.default(name, 0);
|
|
279
|
+
databases.set(name, db);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// If version is undefined, let version be 1 if db is null, or db’s version otherwise.
|
|
283
|
+
if (version === undefined) {
|
|
284
|
+
version = db.version !== 0 ? db.version : 1;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// If db’s version is greater than version, return a newly created "VersionError" DOMException and abort these steps.
|
|
288
|
+
if (db.version > version) {
|
|
289
|
+
return onComplete(new _errors.VersionError());
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Let connection be a new connection to db.
|
|
293
|
+
const connection = new _FDBDatabase.default(db);
|
|
294
|
+
|
|
295
|
+
// If db’s version is less than version, then:
|
|
296
|
+
if (db.version < version) {
|
|
297
|
+
// (run a version change transaction and resolve so that the next promise in the queue will execute)
|
|
298
|
+
runVersionchangeTransaction(connection, version, request, err => {
|
|
299
|
+
onComplete(err);
|
|
300
|
+
});
|
|
301
|
+
} else {
|
|
302
|
+
onComplete(null);
|
|
168
303
|
}
|
|
169
|
-
cb(null, connection);
|
|
170
304
|
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
}
|
|
305
|
+
};
|
|
306
|
+
runTaskInConnectionQueue(connectionQueues, name, openDBTask);
|
|
174
307
|
};
|
|
175
308
|
class FDBFactory {
|
|
176
|
-
cmp = _cmp.default;
|
|
177
309
|
_databases = new Map();
|
|
310
|
+
// https://w3c.github.io/IndexedDB/#connection-queue
|
|
311
|
+
_connectionQueues = new Map(); // promise chain as lightweight FIFO task queue
|
|
312
|
+
|
|
313
|
+
// https://w3c.github.io/IndexedDB/#dom-idbfactory-cmp
|
|
314
|
+
cmp(first, second) {
|
|
315
|
+
(0, _validateRequiredArguments.validateRequiredArguments)(arguments.length, 2, "IDBFactory.cmp");
|
|
316
|
+
return (0, _cmp.default)(first, second);
|
|
317
|
+
}
|
|
178
318
|
|
|
179
|
-
//
|
|
319
|
+
// https://w3c.github.io/IndexedDB/#dom-idbfactory-deletedatabase
|
|
180
320
|
deleteDatabase(name) {
|
|
321
|
+
(0, _validateRequiredArguments.validateRequiredArguments)(arguments.length, 1, "IDBFactory.deleteDatabase");
|
|
181
322
|
const request = new _FDBOpenDBRequest.default();
|
|
182
323
|
request.source = null;
|
|
183
324
|
(0, _scheduling.queueTask)(() => {
|
|
184
|
-
|
|
185
|
-
const oldVersion = db !== undefined ? db.version : 0;
|
|
186
|
-
deleteDatabase(this._databases, name, request, err => {
|
|
325
|
+
deleteDatabase(this._databases, this._connectionQueues, name, request, (err, oldVersion) => {
|
|
187
326
|
if (err) {
|
|
188
327
|
request.error = new DOMException(err.message, err.name);
|
|
189
328
|
request.readyState = "done";
|
|
@@ -209,6 +348,7 @@ class FDBFactory {
|
|
|
209
348
|
|
|
210
349
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBFactory-open-IDBOpenDBRequest-DOMString-name-unsigned-long-long-version
|
|
211
350
|
open(name, version) {
|
|
351
|
+
(0, _validateRequiredArguments.validateRequiredArguments)(arguments.length, 1, "IDBFactory.open");
|
|
212
352
|
if (arguments.length > 1 && version !== undefined) {
|
|
213
353
|
// Based on spec, not sure why "MAX_SAFE_INTEGER" instead of "unsigned long long", but it's needed to pass
|
|
214
354
|
// tests
|
|
@@ -220,7 +360,7 @@ class FDBFactory {
|
|
|
220
360
|
const request = new _FDBOpenDBRequest.default();
|
|
221
361
|
request.source = null;
|
|
222
362
|
(0, _scheduling.queueTask)(() => {
|
|
223
|
-
openDatabase(this._databases, name, version, request, (err, connection) => {
|
|
363
|
+
openDatabase(this._databases, this._connectionQueues, name, version, request, (err, connection) => {
|
|
224
364
|
if (err) {
|
|
225
365
|
request.result = undefined;
|
|
226
366
|
request.readyState = "done";
|
|
@@ -245,16 +385,24 @@ class FDBFactory {
|
|
|
245
385
|
|
|
246
386
|
// https://w3c.github.io/IndexedDB/#dom-idbfactory-databases
|
|
247
387
|
databases() {
|
|
248
|
-
return
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
388
|
+
return Promise.resolve(Array.from(this._databases.entries(), ([name, database]) => {
|
|
389
|
+
const activeVersionChangeConnection = database.connections.find(connection => connection._runningVersionchangeTransaction);
|
|
390
|
+
// If a versionchange is in progress, report the old version. See `get-databases.any.js` test:
|
|
391
|
+
// "The result of databases() should contain the versions of databases at the time of calling,
|
|
392
|
+
// regardless of versionchange transactions currently running."
|
|
393
|
+
const version = activeVersionChangeConnection ? activeVersionChangeConnection._oldVersion : database.version;
|
|
394
|
+
return {
|
|
395
|
+
name,
|
|
396
|
+
version
|
|
397
|
+
};
|
|
398
|
+
}).filter(({
|
|
399
|
+
version
|
|
400
|
+
}) => {
|
|
401
|
+
// Ignore newly-created DBs with active versionchange transactions. See `get-databases.any.js` test:
|
|
402
|
+
// "The result of databases() should be only those databases which have been created at the
|
|
403
|
+
// time of calling, regardless of versionchange transactions currently running."
|
|
404
|
+
return version > 0;
|
|
405
|
+
}));
|
|
258
406
|
}
|
|
259
407
|
get [Symbol.toStringTag]() {
|
|
260
408
|
return "IDBFactory";
|
package/build/cjs/FDBIndex.js
CHANGED
|
@@ -70,15 +70,19 @@ class FDBIndex {
|
|
|
70
70
|
const index = this.objectStore._rawObjectStore.rawIndexes.get(indexName);
|
|
71
71
|
return index && !index.deleted;
|
|
72
72
|
}).sort());
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
|
|
74
|
+
// https://www.w3.org/TR/IndexedDB/#abort-an-upgrade-transaction - "If handle’s index was not newly created during transaction, set handle’s name to its index’s name."
|
|
75
|
+
if (!this.objectStore.transaction._createdIndexes.has(this._rawIndex)) {
|
|
76
|
+
transaction._rollbackLog.push(() => {
|
|
77
|
+
this._name = oldName;
|
|
78
|
+
this._rawIndex.name = oldName;
|
|
79
|
+
this.objectStore._indexesCache.delete(name);
|
|
80
|
+
this.objectStore._indexesCache.set(oldName, this);
|
|
81
|
+
this.objectStore._rawObjectStore.rawIndexes.delete(name);
|
|
82
|
+
this.objectStore._rawObjectStore.rawIndexes.set(oldName, this._rawIndex);
|
|
83
|
+
this.objectStore.indexNames = new _FakeDOMStringList.default(...oldIndexNames);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBIndex-openCursor-IDBRequest-any-range-IDBCursorDirection-direction
|
|
@@ -20,6 +20,7 @@ var _valueToKeyRange = _interopRequireDefault(require("./lib/valueToKeyRange.js"
|
|
|
20
20
|
var _getKeyPath = require("./lib/getKeyPath.js");
|
|
21
21
|
var _extractGetAllOptions = _interopRequireDefault(require("./lib/extractGetAllOptions.js"));
|
|
22
22
|
var _enforceRange = _interopRequireDefault(require("./lib/enforceRange.js"));
|
|
23
|
+
var _cloneValueForInsertion = require("./lib/cloneValueForInsertion.js");
|
|
23
24
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
24
25
|
const confirmActiveTransaction = objectStore => {
|
|
25
26
|
if (objectStore._rawObjectStore.deleted) {
|
|
@@ -39,7 +40,7 @@ const buildRecordAddPut = (objectStore, value, key) => {
|
|
|
39
40
|
throw new _errors.DataError();
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
|
-
const clone =
|
|
43
|
+
const clone = (0, _cloneValueForInsertion.cloneValueForInsertion)(value, objectStore.transaction);
|
|
43
44
|
if (objectStore.keyPath !== null) {
|
|
44
45
|
const tempKey = (0, _extractKey.default)(objectStore.keyPath, clone);
|
|
45
46
|
if (tempKey.type === "found") {
|
|
@@ -110,17 +111,21 @@ class FDBObjectStore {
|
|
|
110
111
|
this.transaction._scope.delete(oldName);
|
|
111
112
|
transaction._scope.add(name);
|
|
112
113
|
transaction.objectStoreNames = new _FakeDOMStringList.default(...Array.from(transaction._scope).sort());
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
|
|
115
|
+
// https://www.w3.org/TR/IndexedDB/#abort-an-upgrade-transaction - "If handle’s object store was not newly created during transaction, set handle’s name to its object store’s name."
|
|
116
|
+
if (!this.transaction._createdObjectStores.has(this._rawObjectStore)) {
|
|
117
|
+
transaction._rollbackLog.push(() => {
|
|
118
|
+
this._name = oldName;
|
|
119
|
+
this._rawObjectStore.name = oldName;
|
|
120
|
+
this.transaction._objectStoresCache.delete(name);
|
|
121
|
+
this.transaction._objectStoresCache.set(oldName, this);
|
|
122
|
+
this._rawObjectStore.rawDatabase.rawObjectStores.delete(name);
|
|
123
|
+
this._rawObjectStore.rawDatabase.rawObjectStores.set(oldName, this._rawObjectStore);
|
|
124
|
+
transaction.db.objectStoreNames = new _FakeDOMStringList.default(...oldObjectStoreNames);
|
|
125
|
+
transaction._scope = oldScope;
|
|
126
|
+
transaction.objectStoreNames = new _FakeDOMStringList.default(...oldTransactionObjectStoreNames);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
124
129
|
}
|
|
125
130
|
put(value, key) {
|
|
126
131
|
if (arguments.length === 0) {
|
|
@@ -306,21 +311,20 @@ class FDBObjectStore {
|
|
|
306
311
|
// create and return an IDBIndex object. Instead the implementation must queue up an operation to abort the
|
|
307
312
|
// "versionchange" transaction which was used for the createIndex call.
|
|
308
313
|
|
|
314
|
+
// Save for rollbackLog
|
|
309
315
|
const indexNames = [...this.indexNames];
|
|
310
|
-
this.transaction._rollbackLog.push(() => {
|
|
311
|
-
const index2 = this._rawObjectStore.rawIndexes.get(name);
|
|
312
|
-
if (index2) {
|
|
313
|
-
index2.deleted = true;
|
|
314
|
-
}
|
|
315
|
-
this.indexNames = new _FakeDOMStringList.default(...indexNames);
|
|
316
|
-
this._rawObjectStore.rawIndexes.delete(name);
|
|
317
|
-
});
|
|
318
316
|
const index = new _Index.default(this._rawObjectStore, name, keyPath, multiEntry, unique);
|
|
319
317
|
this.indexNames._push(name);
|
|
320
318
|
this.indexNames._sort();
|
|
319
|
+
this.transaction._createdIndexes.add(index);
|
|
321
320
|
this._rawObjectStore.rawIndexes.set(name, index);
|
|
322
321
|
index.initialize(this.transaction); // This is async by design
|
|
323
322
|
|
|
323
|
+
this.transaction._rollbackLog.push(() => {
|
|
324
|
+
index.deleted = true;
|
|
325
|
+
this.indexNames = new _FakeDOMStringList.default(...indexNames);
|
|
326
|
+
this._rawObjectStore.rawIndexes.delete(index.name);
|
|
327
|
+
});
|
|
324
328
|
return new _FDBIndex.default(this, index);
|
|
325
329
|
}
|
|
326
330
|
|
|
@@ -358,8 +362,8 @@ class FDBObjectStore {
|
|
|
358
362
|
}
|
|
359
363
|
this.transaction._rollbackLog.push(() => {
|
|
360
364
|
rawIndex.deleted = false;
|
|
361
|
-
this._rawObjectStore.rawIndexes.set(name, rawIndex);
|
|
362
|
-
this.indexNames._push(name);
|
|
365
|
+
this._rawObjectStore.rawIndexes.set(rawIndex.name, rawIndex);
|
|
366
|
+
this.indexNames._push(rawIndex.name);
|
|
363
367
|
this.indexNames._sort();
|
|
364
368
|
});
|
|
365
369
|
this.indexNames = new _FakeDOMStringList.default(...Array.from(this.indexNames).filter(indexName => {
|