fake-indexeddb 4.0.2 → 5.0.1
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 +42 -6
- package/build/cjs/FDBCursor.js +39 -159
- package/build/cjs/FDBCursorWithValue.js +1 -9
- package/build/cjs/FDBDatabase.js +9 -72
- package/build/cjs/FDBFactory.js +23 -66
- package/build/cjs/FDBIndex.js +17 -73
- package/build/cjs/FDBKeyRange.js +3 -28
- package/build/cjs/FDBObjectStore.js +25 -145
- package/build/cjs/FDBOpenDBRequest.js +1 -8
- package/build/cjs/FDBRequest.js +1 -15
- package/build/cjs/FDBTransaction.js +26 -64
- package/build/cjs/FDBVersionChangeEvent.js +1 -8
- package/build/cjs/fakeIndexedDB.js +1 -5
- package/build/cjs/index.js +1 -16
- package/build/cjs/lib/Database.js +1 -11
- package/build/cjs/lib/FakeDOMStringList.js +5 -13
- package/build/cjs/lib/FakeEvent.js +3 -10
- package/build/cjs/lib/FakeEventTarget.js +15 -32
- package/build/cjs/lib/Index.js +14 -46
- package/build/cjs/lib/KeyGenerator.js +3 -12
- package/build/cjs/lib/ObjectStore.js +24 -63
- package/build/cjs/lib/RecordStore.js +4 -42
- package/build/cjs/lib/binarySearch.js +5 -24
- package/build/cjs/lib/canInjectKey.js +2 -14
- package/build/cjs/lib/cmp.js +3 -29
- package/build/cjs/lib/enforceRange.js +2 -6
- package/build/cjs/lib/errors.js +0 -32
- package/build/cjs/lib/extractKey.js +2 -17
- package/build/cjs/lib/scheduling.js +4 -7
- package/build/cjs/lib/validateKeyPath.js +4 -16
- package/build/cjs/lib/valueToKey.js +18 -20
- package/build/cjs/lib/valueToKeyRange.js +1 -11
- package/build/esm/FDBCursor.js +33 -144
- package/build/esm/FDBCursorWithValue.js +0 -5
- package/build/esm/FDBDatabase.js +8 -62
- package/build/esm/FDBFactory.js +22 -54
- package/build/esm/FDBIndex.js +16 -61
- package/build/esm/FDBKeyRange.js +4 -22
- package/build/esm/FDBObjectStore.js +23 -126
- package/build/esm/FDBOpenDBRequest.js +0 -4
- package/build/esm/FDBRequest.js +0 -10
- package/build/esm/FDBTransaction.js +25 -54
- package/build/esm/FDBVersionChangeEvent.js +0 -4
- package/build/esm/lib/Database.js +2 -8
- package/build/esm/lib/FakeDOMStringList.js +4 -9
- package/build/esm/lib/FakeEvent.js +2 -7
- package/build/esm/lib/FakeEventTarget.js +14 -29
- package/build/esm/lib/Index.js +14 -37
- package/build/esm/lib/KeyGenerator.js +2 -8
- package/build/esm/lib/ObjectStore.js +19 -51
- package/build/esm/lib/RecordStore.js +3 -36
- package/build/esm/lib/binarySearch.js +5 -18
- package/build/esm/lib/canInjectKey.js +1 -11
- package/build/esm/lib/cmp.js +2 -24
- package/build/esm/lib/enforceRange.js +1 -3
- package/build/esm/lib/errors.js +0 -11
- package/build/esm/lib/extractKey.js +3 -13
- package/build/esm/lib/scheduling.js +3 -3
- package/build/esm/lib/validateKeyPath.js +3 -13
- package/build/esm/lib/valueToKey.js +17 -17
- package/build/esm/lib/valueToKeyRange.js +2 -5
- package/package.json +30 -28
- package/build/cjs/lib/structuredClone.js +0 -30
- package/build/esm/lib/structuredClone.js +0 -18
|
@@ -4,67 +4,42 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _FDBCursor = _interopRequireDefault(require("./FDBCursor.js"));
|
|
9
|
-
|
|
10
8
|
var _FDBCursorWithValue = _interopRequireDefault(require("./FDBCursorWithValue.js"));
|
|
11
|
-
|
|
12
9
|
var _FDBIndex = _interopRequireDefault(require("./FDBIndex.js"));
|
|
13
|
-
|
|
14
10
|
var _FDBKeyRange = _interopRequireDefault(require("./FDBKeyRange.js"));
|
|
15
|
-
|
|
16
11
|
var _FDBRequest = _interopRequireDefault(require("./FDBRequest.js"));
|
|
17
|
-
|
|
18
12
|
var _canInjectKey = _interopRequireDefault(require("./lib/canInjectKey.js"));
|
|
19
|
-
|
|
20
13
|
var _enforceRange = _interopRequireDefault(require("./lib/enforceRange.js"));
|
|
21
|
-
|
|
22
14
|
var _errors = require("./lib/errors.js");
|
|
23
|
-
|
|
24
15
|
var _extractKey = _interopRequireDefault(require("./lib/extractKey.js"));
|
|
25
|
-
|
|
26
16
|
var _FakeDOMStringList = _interopRequireDefault(require("./lib/FakeDOMStringList.js"));
|
|
27
|
-
|
|
28
17
|
var _Index = _interopRequireDefault(require("./lib/Index.js"));
|
|
29
|
-
|
|
30
|
-
var _structuredClone = _interopRequireDefault(require("./lib/structuredClone.js"));
|
|
31
|
-
|
|
32
18
|
var _validateKeyPath = _interopRequireDefault(require("./lib/validateKeyPath.js"));
|
|
33
|
-
|
|
34
19
|
var _valueToKey = _interopRequireDefault(require("./lib/valueToKey.js"));
|
|
35
|
-
|
|
36
20
|
var _valueToKeyRange = _interopRequireDefault(require("./lib/valueToKeyRange.js"));
|
|
37
|
-
|
|
38
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
|
-
|
|
40
22
|
const confirmActiveTransaction = objectStore => {
|
|
41
23
|
if (objectStore._rawObjectStore.deleted) {
|
|
42
24
|
throw new _errors.InvalidStateError();
|
|
43
25
|
}
|
|
44
|
-
|
|
45
26
|
if (objectStore.transaction._state !== "active") {
|
|
46
27
|
throw new _errors.TransactionInactiveError();
|
|
47
28
|
}
|
|
48
29
|
};
|
|
49
|
-
|
|
50
30
|
const buildRecordAddPut = (objectStore, value, key) => {
|
|
51
31
|
confirmActiveTransaction(objectStore);
|
|
52
|
-
|
|
53
32
|
if (objectStore.transaction.mode === "readonly") {
|
|
54
33
|
throw new _errors.ReadOnlyError();
|
|
55
34
|
}
|
|
56
|
-
|
|
57
35
|
if (objectStore.keyPath !== null) {
|
|
58
36
|
if (key !== undefined) {
|
|
59
37
|
throw new _errors.DataError();
|
|
60
38
|
}
|
|
61
39
|
}
|
|
62
|
-
|
|
63
|
-
const clone = (0, _structuredClone.default)(value);
|
|
64
|
-
|
|
40
|
+
const clone = structuredClone(value);
|
|
65
41
|
if (objectStore.keyPath !== null) {
|
|
66
42
|
const tempKey = (0, _extractKey.default)(objectStore.keyPath, clone);
|
|
67
|
-
|
|
68
43
|
if (tempKey !== undefined) {
|
|
69
44
|
(0, _valueToKey.default)(tempKey);
|
|
70
45
|
} else {
|
|
@@ -75,25 +50,21 @@ const buildRecordAddPut = (objectStore, value, key) => {
|
|
|
75
50
|
}
|
|
76
51
|
}
|
|
77
52
|
}
|
|
78
|
-
|
|
79
53
|
if (objectStore.keyPath === null && objectStore._rawObjectStore.keyGenerator === null && key === undefined) {
|
|
80
54
|
throw new _errors.DataError();
|
|
81
55
|
}
|
|
82
|
-
|
|
83
56
|
if (key !== undefined) {
|
|
84
57
|
key = (0, _valueToKey.default)(key);
|
|
85
58
|
}
|
|
86
|
-
|
|
87
59
|
return {
|
|
88
60
|
key,
|
|
89
61
|
value: clone
|
|
90
62
|
};
|
|
91
|
-
};
|
|
92
|
-
|
|
63
|
+
};
|
|
93
64
|
|
|
65
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#object-store
|
|
94
66
|
class FDBObjectStore {
|
|
95
67
|
_indexesCache = new Map();
|
|
96
|
-
|
|
97
68
|
constructor(transaction, rawObjectStore) {
|
|
98
69
|
this._rawObjectStore = rawObjectStore;
|
|
99
70
|
this._name = rawObjectStore.name;
|
|
@@ -102,175 +73,136 @@ class FDBObjectStore {
|
|
|
102
73
|
this.transaction = transaction;
|
|
103
74
|
this.indexNames = new _FakeDOMStringList.default(...Array.from(rawObjectStore.rawIndexes.keys()).sort());
|
|
104
75
|
}
|
|
105
|
-
|
|
106
76
|
get name() {
|
|
107
77
|
return this._name;
|
|
108
|
-
}
|
|
109
|
-
|
|
78
|
+
}
|
|
110
79
|
|
|
80
|
+
// http://w3c.github.io/IndexedDB/#dom-idbobjectstore-name
|
|
111
81
|
set name(name) {
|
|
112
82
|
const transaction = this.transaction;
|
|
113
|
-
|
|
114
83
|
if (!transaction.db._runningVersionchangeTransaction) {
|
|
115
84
|
throw new _errors.InvalidStateError();
|
|
116
85
|
}
|
|
117
|
-
|
|
118
86
|
confirmActiveTransaction(this);
|
|
119
87
|
name = String(name);
|
|
120
|
-
|
|
121
88
|
if (name === this._name) {
|
|
122
89
|
return;
|
|
123
90
|
}
|
|
124
|
-
|
|
125
91
|
if (this._rawObjectStore.rawDatabase.rawObjectStores.has(name)) {
|
|
126
92
|
throw new _errors.ConstraintError();
|
|
127
93
|
}
|
|
128
|
-
|
|
129
94
|
const oldName = this._name;
|
|
130
95
|
const oldObjectStoreNames = [...transaction.db.objectStoreNames];
|
|
131
96
|
this._name = name;
|
|
132
97
|
this._rawObjectStore.name = name;
|
|
133
|
-
|
|
134
98
|
this.transaction._objectStoresCache.delete(oldName);
|
|
135
|
-
|
|
136
99
|
this.transaction._objectStoresCache.set(name, this);
|
|
137
|
-
|
|
138
100
|
this._rawObjectStore.rawDatabase.rawObjectStores.delete(oldName);
|
|
139
|
-
|
|
140
101
|
this._rawObjectStore.rawDatabase.rawObjectStores.set(name, this._rawObjectStore);
|
|
141
|
-
|
|
142
102
|
transaction.db.objectStoreNames = new _FakeDOMStringList.default(...Array.from(this._rawObjectStore.rawDatabase.rawObjectStores.keys()).filter(objectStoreName => {
|
|
143
103
|
const objectStore = this._rawObjectStore.rawDatabase.rawObjectStores.get(objectStoreName);
|
|
144
|
-
|
|
145
104
|
return objectStore && !objectStore.deleted;
|
|
146
105
|
}).sort());
|
|
147
106
|
const oldScope = new Set(transaction._scope);
|
|
148
107
|
const oldTransactionObjectStoreNames = [...transaction.objectStoreNames];
|
|
149
|
-
|
|
150
108
|
this.transaction._scope.delete(oldName);
|
|
151
|
-
|
|
152
109
|
transaction._scope.add(name);
|
|
153
|
-
|
|
154
110
|
transaction.objectStoreNames = new _FakeDOMStringList.default(...Array.from(transaction._scope).sort());
|
|
155
|
-
|
|
156
111
|
transaction._rollbackLog.push(() => {
|
|
157
112
|
this._name = oldName;
|
|
158
113
|
this._rawObjectStore.name = oldName;
|
|
159
|
-
|
|
160
114
|
this.transaction._objectStoresCache.delete(name);
|
|
161
|
-
|
|
162
115
|
this.transaction._objectStoresCache.set(oldName, this);
|
|
163
|
-
|
|
164
116
|
this._rawObjectStore.rawDatabase.rawObjectStores.delete(name);
|
|
165
|
-
|
|
166
117
|
this._rawObjectStore.rawDatabase.rawObjectStores.set(oldName, this._rawObjectStore);
|
|
167
|
-
|
|
168
118
|
transaction.db.objectStoreNames = new _FakeDOMStringList.default(...oldObjectStoreNames);
|
|
169
119
|
transaction._scope = oldScope;
|
|
170
120
|
transaction.objectStoreNames = new _FakeDOMStringList.default(...oldTransactionObjectStoreNames);
|
|
171
121
|
});
|
|
172
122
|
}
|
|
173
|
-
|
|
174
123
|
put(value, key) {
|
|
175
124
|
if (arguments.length === 0) {
|
|
176
125
|
throw new TypeError();
|
|
177
126
|
}
|
|
178
|
-
|
|
179
127
|
const record = buildRecordAddPut(this, value, key);
|
|
180
128
|
return this.transaction._execRequestAsync({
|
|
181
129
|
operation: this._rawObjectStore.storeRecord.bind(this._rawObjectStore, record, false, this.transaction._rollbackLog),
|
|
182
130
|
source: this
|
|
183
131
|
});
|
|
184
132
|
}
|
|
185
|
-
|
|
186
133
|
add(value, key) {
|
|
187
134
|
if (arguments.length === 0) {
|
|
188
135
|
throw new TypeError();
|
|
189
136
|
}
|
|
190
|
-
|
|
191
137
|
const record = buildRecordAddPut(this, value, key);
|
|
192
138
|
return this.transaction._execRequestAsync({
|
|
193
139
|
operation: this._rawObjectStore.storeRecord.bind(this._rawObjectStore, record, true, this.transaction._rollbackLog),
|
|
194
140
|
source: this
|
|
195
141
|
});
|
|
196
142
|
}
|
|
197
|
-
|
|
198
143
|
delete(key) {
|
|
199
144
|
if (arguments.length === 0) {
|
|
200
145
|
throw new TypeError();
|
|
201
146
|
}
|
|
202
|
-
|
|
203
147
|
confirmActiveTransaction(this);
|
|
204
|
-
|
|
205
148
|
if (this.transaction.mode === "readonly") {
|
|
206
149
|
throw new _errors.ReadOnlyError();
|
|
207
150
|
}
|
|
208
|
-
|
|
209
151
|
if (!(key instanceof _FDBKeyRange.default)) {
|
|
210
152
|
key = (0, _valueToKey.default)(key);
|
|
211
153
|
}
|
|
212
|
-
|
|
213
154
|
return this.transaction._execRequestAsync({
|
|
214
155
|
operation: this._rawObjectStore.deleteRecord.bind(this._rawObjectStore, key, this.transaction._rollbackLog),
|
|
215
156
|
source: this
|
|
216
157
|
});
|
|
217
158
|
}
|
|
218
|
-
|
|
219
159
|
get(key) {
|
|
220
160
|
if (arguments.length === 0) {
|
|
221
161
|
throw new TypeError();
|
|
222
162
|
}
|
|
223
|
-
|
|
224
163
|
confirmActiveTransaction(this);
|
|
225
|
-
|
|
226
164
|
if (!(key instanceof _FDBKeyRange.default)) {
|
|
227
165
|
key = (0, _valueToKey.default)(key);
|
|
228
166
|
}
|
|
229
|
-
|
|
230
167
|
return this.transaction._execRequestAsync({
|
|
231
168
|
operation: this._rawObjectStore.getValue.bind(this._rawObjectStore, key),
|
|
232
169
|
source: this
|
|
233
170
|
});
|
|
234
|
-
}
|
|
235
|
-
|
|
171
|
+
}
|
|
236
172
|
|
|
173
|
+
// http://w3c.github.io/IndexedDB/#dom-idbobjectstore-getall
|
|
237
174
|
getAll(query, count) {
|
|
238
175
|
if (arguments.length > 1 && count !== undefined) {
|
|
239
176
|
count = (0, _enforceRange.default)(count, "unsigned long");
|
|
240
177
|
}
|
|
241
|
-
|
|
242
178
|
confirmActiveTransaction(this);
|
|
243
179
|
const range = (0, _valueToKeyRange.default)(query);
|
|
244
180
|
return this.transaction._execRequestAsync({
|
|
245
181
|
operation: this._rawObjectStore.getAllValues.bind(this._rawObjectStore, range, count),
|
|
246
182
|
source: this
|
|
247
183
|
});
|
|
248
|
-
}
|
|
249
|
-
|
|
184
|
+
}
|
|
250
185
|
|
|
186
|
+
// http://w3c.github.io/IndexedDB/#dom-idbobjectstore-getkey
|
|
251
187
|
getKey(key) {
|
|
252
188
|
if (arguments.length === 0) {
|
|
253
189
|
throw new TypeError();
|
|
254
190
|
}
|
|
255
|
-
|
|
256
191
|
confirmActiveTransaction(this);
|
|
257
|
-
|
|
258
192
|
if (!(key instanceof _FDBKeyRange.default)) {
|
|
259
193
|
key = (0, _valueToKey.default)(key);
|
|
260
194
|
}
|
|
261
|
-
|
|
262
195
|
return this.transaction._execRequestAsync({
|
|
263
196
|
operation: this._rawObjectStore.getKey.bind(this._rawObjectStore, key),
|
|
264
197
|
source: this
|
|
265
198
|
});
|
|
266
|
-
}
|
|
267
|
-
|
|
199
|
+
}
|
|
268
200
|
|
|
201
|
+
// http://w3c.github.io/IndexedDB/#dom-idbobjectstore-getallkeys
|
|
269
202
|
getAllKeys(query, count) {
|
|
270
203
|
if (arguments.length > 1 && count !== undefined) {
|
|
271
204
|
count = (0, _enforceRange.default)(count, "unsigned long");
|
|
272
205
|
}
|
|
273
|
-
|
|
274
206
|
confirmActiveTransaction(this);
|
|
275
207
|
const range = (0, _valueToKeyRange.default)(query);
|
|
276
208
|
return this.transaction._execRequestAsync({
|
|
@@ -278,31 +210,24 @@ class FDBObjectStore {
|
|
|
278
210
|
source: this
|
|
279
211
|
});
|
|
280
212
|
}
|
|
281
|
-
|
|
282
213
|
clear() {
|
|
283
214
|
confirmActiveTransaction(this);
|
|
284
|
-
|
|
285
215
|
if (this.transaction.mode === "readonly") {
|
|
286
216
|
throw new _errors.ReadOnlyError();
|
|
287
217
|
}
|
|
288
|
-
|
|
289
218
|
return this.transaction._execRequestAsync({
|
|
290
219
|
operation: this._rawObjectStore.clear.bind(this._rawObjectStore, this.transaction._rollbackLog),
|
|
291
220
|
source: this
|
|
292
221
|
});
|
|
293
222
|
}
|
|
294
|
-
|
|
295
223
|
openCursor(range, direction) {
|
|
296
224
|
confirmActiveTransaction(this);
|
|
297
|
-
|
|
298
225
|
if (range === null) {
|
|
299
226
|
range = undefined;
|
|
300
227
|
}
|
|
301
|
-
|
|
302
228
|
if (range !== undefined && !(range instanceof _FDBKeyRange.default)) {
|
|
303
229
|
range = _FDBKeyRange.default.only((0, _valueToKey.default)(range));
|
|
304
230
|
}
|
|
305
|
-
|
|
306
231
|
const request = new _FDBRequest.default();
|
|
307
232
|
request.source = this;
|
|
308
233
|
request.transaction = this.transaction;
|
|
@@ -313,18 +238,14 @@ class FDBObjectStore {
|
|
|
313
238
|
source: this
|
|
314
239
|
});
|
|
315
240
|
}
|
|
316
|
-
|
|
317
241
|
openKeyCursor(range, direction) {
|
|
318
242
|
confirmActiveTransaction(this);
|
|
319
|
-
|
|
320
243
|
if (range === null) {
|
|
321
244
|
range = undefined;
|
|
322
245
|
}
|
|
323
|
-
|
|
324
246
|
if (range !== undefined && !(range instanceof _FDBKeyRange.default)) {
|
|
325
247
|
range = _FDBKeyRange.default.only((0, _valueToKey.default)(range));
|
|
326
248
|
}
|
|
327
|
-
|
|
328
249
|
const request = new _FDBRequest.default();
|
|
329
250
|
request.source = this;
|
|
330
251
|
request.transaction = this.transaction;
|
|
@@ -334,123 +255,91 @@ class FDBObjectStore {
|
|
|
334
255
|
request,
|
|
335
256
|
source: this
|
|
336
257
|
});
|
|
337
|
-
}
|
|
338
|
-
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBObjectStore-createIndex-IDBIndex-DOMString-name-DOMString-sequence-DOMString--keyPath-IDBIndexParameters-optionalParameters
|
|
339
|
-
|
|
258
|
+
}
|
|
340
259
|
|
|
260
|
+
// tslint:-next-line max-line-length
|
|
261
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBObjectStore-createIndex-IDBIndex-DOMString-name-DOMString-sequence-DOMString--keyPath-IDBIndexParameters-optionalParameters
|
|
341
262
|
createIndex(name, keyPath, optionalParameters = {}) {
|
|
342
263
|
if (arguments.length < 2) {
|
|
343
264
|
throw new TypeError();
|
|
344
265
|
}
|
|
345
|
-
|
|
346
266
|
const multiEntry = optionalParameters.multiEntry !== undefined ? optionalParameters.multiEntry : false;
|
|
347
267
|
const unique = optionalParameters.unique !== undefined ? optionalParameters.unique : false;
|
|
348
|
-
|
|
349
268
|
if (this.transaction.mode !== "versionchange") {
|
|
350
269
|
throw new _errors.InvalidStateError();
|
|
351
270
|
}
|
|
352
|
-
|
|
353
271
|
confirmActiveTransaction(this);
|
|
354
|
-
|
|
355
272
|
if (this.indexNames.contains(name)) {
|
|
356
273
|
throw new _errors.ConstraintError();
|
|
357
274
|
}
|
|
358
|
-
|
|
359
275
|
(0, _validateKeyPath.default)(keyPath);
|
|
360
|
-
|
|
361
276
|
if (Array.isArray(keyPath) && multiEntry) {
|
|
362
277
|
throw new _errors.InvalidAccessError();
|
|
363
|
-
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// The index that is requested to be created can contain constraints on the data allowed in the index's
|
|
364
281
|
// referenced object store, such as requiring uniqueness of the values referenced by the index's keyPath. If the
|
|
365
282
|
// referenced object store already contains data which violates these constraints, this MUST NOT cause the
|
|
366
283
|
// implementation of createIndex to throw an exception or affect what it returns. The implementation MUST still
|
|
367
284
|
// create and return an IDBIndex object. Instead the implementation must queue up an operation to abort the
|
|
368
285
|
// "versionchange" transaction which was used for the createIndex call.
|
|
369
286
|
|
|
370
|
-
|
|
371
287
|
const indexNames = [...this.indexNames];
|
|
372
|
-
|
|
373
288
|
this.transaction._rollbackLog.push(() => {
|
|
374
289
|
const index2 = this._rawObjectStore.rawIndexes.get(name);
|
|
375
|
-
|
|
376
290
|
if (index2) {
|
|
377
291
|
index2.deleted = true;
|
|
378
292
|
}
|
|
379
|
-
|
|
380
293
|
this.indexNames = new _FakeDOMStringList.default(...indexNames);
|
|
381
|
-
|
|
382
294
|
this._rawObjectStore.rawIndexes.delete(name);
|
|
383
295
|
});
|
|
384
|
-
|
|
385
296
|
const index = new _Index.default(this._rawObjectStore, name, keyPath, multiEntry, unique);
|
|
386
|
-
|
|
387
297
|
this.indexNames._push(name);
|
|
388
|
-
|
|
389
298
|
this.indexNames._sort();
|
|
390
|
-
|
|
391
299
|
this._rawObjectStore.rawIndexes.set(name, index);
|
|
392
|
-
|
|
393
300
|
index.initialize(this.transaction); // This is async by design
|
|
394
301
|
|
|
395
302
|
return new _FDBIndex.default(this, index);
|
|
396
|
-
}
|
|
397
|
-
|
|
303
|
+
}
|
|
398
304
|
|
|
305
|
+
// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-index
|
|
399
306
|
index(name) {
|
|
400
307
|
if (arguments.length === 0) {
|
|
401
308
|
throw new TypeError();
|
|
402
309
|
}
|
|
403
|
-
|
|
404
310
|
if (this._rawObjectStore.deleted || this.transaction._state === "finished") {
|
|
405
311
|
throw new _errors.InvalidStateError();
|
|
406
312
|
}
|
|
407
|
-
|
|
408
313
|
const index = this._indexesCache.get(name);
|
|
409
|
-
|
|
410
314
|
if (index !== undefined) {
|
|
411
315
|
return index;
|
|
412
316
|
}
|
|
413
|
-
|
|
414
317
|
const rawIndex = this._rawObjectStore.rawIndexes.get(name);
|
|
415
|
-
|
|
416
318
|
if (!this.indexNames.contains(name) || rawIndex === undefined) {
|
|
417
319
|
throw new _errors.NotFoundError();
|
|
418
320
|
}
|
|
419
|
-
|
|
420
321
|
const index2 = new _FDBIndex.default(this, rawIndex);
|
|
421
|
-
|
|
422
322
|
this._indexesCache.set(name, index2);
|
|
423
|
-
|
|
424
323
|
return index2;
|
|
425
324
|
}
|
|
426
|
-
|
|
427
325
|
deleteIndex(name) {
|
|
428
326
|
if (arguments.length === 0) {
|
|
429
327
|
throw new TypeError();
|
|
430
328
|
}
|
|
431
|
-
|
|
432
329
|
if (this.transaction.mode !== "versionchange") {
|
|
433
330
|
throw new _errors.InvalidStateError();
|
|
434
331
|
}
|
|
435
|
-
|
|
436
332
|
confirmActiveTransaction(this);
|
|
437
|
-
|
|
438
333
|
const rawIndex = this._rawObjectStore.rawIndexes.get(name);
|
|
439
|
-
|
|
440
334
|
if (rawIndex === undefined) {
|
|
441
335
|
throw new _errors.NotFoundError();
|
|
442
336
|
}
|
|
443
|
-
|
|
444
337
|
this.transaction._rollbackLog.push(() => {
|
|
445
338
|
rawIndex.deleted = false;
|
|
446
|
-
|
|
447
339
|
this._rawObjectStore.rawIndexes.set(name, rawIndex);
|
|
448
|
-
|
|
449
340
|
this.indexNames._push(name);
|
|
450
|
-
|
|
451
341
|
this.indexNames._sort();
|
|
452
342
|
});
|
|
453
|
-
|
|
454
343
|
this.indexNames = new _FakeDOMStringList.default(...Array.from(this.indexNames).filter(indexName => {
|
|
455
344
|
return indexName !== name;
|
|
456
345
|
}));
|
|
@@ -458,51 +347,42 @@ class FDBObjectStore {
|
|
|
458
347
|
|
|
459
348
|
this.transaction._execRequestAsync({
|
|
460
349
|
operation: () => {
|
|
461
|
-
const rawIndex2 = this._rawObjectStore.rawIndexes.get(name);
|
|
462
|
-
// to have a real unique ID for each index.
|
|
463
|
-
|
|
350
|
+
const rawIndex2 = this._rawObjectStore.rawIndexes.get(name);
|
|
464
351
|
|
|
352
|
+
// Hack in case another index is given this name before this async request is processed. It'd be better
|
|
353
|
+
// to have a real unique ID for each index.
|
|
465
354
|
if (rawIndex === rawIndex2) {
|
|
466
355
|
this._rawObjectStore.rawIndexes.delete(name);
|
|
467
356
|
}
|
|
468
357
|
},
|
|
469
358
|
source: this
|
|
470
359
|
});
|
|
471
|
-
}
|
|
472
|
-
|
|
360
|
+
}
|
|
473
361
|
|
|
362
|
+
// http://www.w3.org/TR/2015/REC-IndexedDB-20150108/#widl-IDBObjectStore-count-IDBRequest-any-key
|
|
474
363
|
count(key) {
|
|
475
364
|
confirmActiveTransaction(this);
|
|
476
|
-
|
|
477
365
|
if (key === null) {
|
|
478
366
|
key = undefined;
|
|
479
367
|
}
|
|
480
|
-
|
|
481
368
|
if (key !== undefined && !(key instanceof _FDBKeyRange.default)) {
|
|
482
369
|
key = _FDBKeyRange.default.only((0, _valueToKey.default)(key));
|
|
483
370
|
}
|
|
484
|
-
|
|
485
371
|
return this.transaction._execRequestAsync({
|
|
486
372
|
operation: () => {
|
|
487
373
|
let count = 0;
|
|
488
374
|
const cursor = new _FDBCursor.default(this, key);
|
|
489
|
-
|
|
490
375
|
while (cursor._iterate() !== null) {
|
|
491
376
|
count += 1;
|
|
492
377
|
}
|
|
493
|
-
|
|
494
378
|
return count;
|
|
495
379
|
},
|
|
496
380
|
source: this
|
|
497
381
|
});
|
|
498
382
|
}
|
|
499
|
-
|
|
500
383
|
toString() {
|
|
501
384
|
return "[object IDBObjectStore]";
|
|
502
385
|
}
|
|
503
|
-
|
|
504
386
|
}
|
|
505
|
-
|
|
506
|
-
var _default = FDBObjectStore;
|
|
507
|
-
exports.default = _default;
|
|
387
|
+
var _default = exports.default = FDBObjectStore;
|
|
508
388
|
module.exports = exports.default;
|
|
@@ -4,21 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _FDBRequest = _interopRequireDefault(require("./FDBRequest.js"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
class FDBOpenDBRequest extends _FDBRequest.default {
|
|
13
10
|
onupgradeneeded = null;
|
|
14
11
|
onblocked = null;
|
|
15
|
-
|
|
16
12
|
toString() {
|
|
17
13
|
return "[object IDBOpenDBRequest]";
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
}
|
|
21
|
-
|
|
22
|
-
var _default = FDBOpenDBRequest;
|
|
23
|
-
exports.default = _default;
|
|
16
|
+
var _default = exports.default = FDBOpenDBRequest;
|
|
24
17
|
module.exports = exports.default;
|
package/build/cjs/FDBRequest.js
CHANGED
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _errors = require("./lib/errors.js");
|
|
9
|
-
|
|
10
8
|
var _FakeEventTarget = _interopRequireDefault(require("./lib/FakeEventTarget.js"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
class FDBRequest extends _FakeEventTarget.default {
|
|
15
11
|
_result = null;
|
|
16
12
|
_error = null;
|
|
@@ -19,37 +15,27 @@ class FDBRequest extends _FakeEventTarget.default {
|
|
|
19
15
|
readyState = "pending";
|
|
20
16
|
onsuccess = null;
|
|
21
17
|
onerror = null;
|
|
22
|
-
|
|
23
18
|
get error() {
|
|
24
19
|
if (this.readyState === "pending") {
|
|
25
20
|
throw new _errors.InvalidStateError();
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
return this._error;
|
|
29
23
|
}
|
|
30
|
-
|
|
31
24
|
set error(value) {
|
|
32
25
|
this._error = value;
|
|
33
26
|
}
|
|
34
|
-
|
|
35
27
|
get result() {
|
|
36
28
|
if (this.readyState === "pending") {
|
|
37
29
|
throw new _errors.InvalidStateError();
|
|
38
30
|
}
|
|
39
|
-
|
|
40
31
|
return this._result;
|
|
41
32
|
}
|
|
42
|
-
|
|
43
33
|
set result(value) {
|
|
44
34
|
this._result = value;
|
|
45
35
|
}
|
|
46
|
-
|
|
47
36
|
toString() {
|
|
48
37
|
return "[object IDBRequest]";
|
|
49
38
|
}
|
|
50
|
-
|
|
51
39
|
}
|
|
52
|
-
|
|
53
|
-
var _default = FDBRequest;
|
|
54
|
-
exports.default = _default;
|
|
40
|
+
var _default = exports.default = FDBRequest;
|
|
55
41
|
module.exports = exports.default;
|