indexeddbshim 11.0.0 → 12.0.0-pre.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/badges/licenses-badge.svg +1 -1
- package/dist/CFG.d.ts +80 -0
- package/dist/CFG.d.ts.map +1 -0
- package/dist/DOMException.d.ts +71 -0
- package/dist/DOMException.d.ts.map +1 -0
- package/dist/DOMStringList.d.ts +20 -0
- package/dist/DOMStringList.d.ts.map +1 -0
- package/dist/Event.d.ts +21 -0
- package/dist/Event.d.ts.map +1 -0
- package/dist/IDBCursor.d.ts +289 -0
- package/dist/IDBCursor.d.ts.map +1 -0
- package/dist/IDBDatabase.d.ts +144 -0
- package/dist/IDBDatabase.d.ts.map +1 -0
- package/dist/IDBFactory.d.ts +96 -0
- package/dist/IDBFactory.d.ts.map +1 -0
- package/dist/IDBIndex.d.ts +243 -0
- package/dist/IDBIndex.d.ts.map +1 -0
- package/dist/IDBKeyRange.d.ts +79 -0
- package/dist/IDBKeyRange.d.ts.map +1 -0
- package/dist/IDBObjectStore.d.ts +273 -0
- package/dist/IDBObjectStore.d.ts.map +1 -0
- package/dist/IDBRequest.d.ts +90 -0
- package/dist/IDBRequest.d.ts.map +1 -0
- package/dist/IDBTransaction.d.ts +271 -0
- package/dist/IDBTransaction.d.ts.map +1 -0
- package/dist/IDBVersionChangeEvent.d.ts +23 -0
- package/dist/IDBVersionChangeEvent.d.ts.map +1 -0
- package/dist/Key.d.ts +214 -0
- package/dist/Key.d.ts.map +1 -0
- package/dist/Sca.d.ts +31 -0
- package/dist/Sca.d.ts.map +1 -0
- package/dist/UnicodeIdentifiers.d.ts +3 -0
- package/dist/UnicodeIdentifiers.d.ts.map +1 -0
- package/dist/browser-UnicodeIdentifiers.d.ts +2 -0
- package/dist/browser-UnicodeIdentifiers.d.ts.map +1 -0
- package/dist/browser-noninvasive.d.ts +3 -0
- package/dist/browser-noninvasive.d.ts.map +1 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/cmp.d.ts +9 -0
- package/dist/cmp.d.ts.map +1 -0
- package/dist/indexeddbshim-Key.js +491 -189
- package/dist/indexeddbshim-Key.js.map +1 -1
- package/dist/indexeddbshim-Key.min.js +2 -2
- package/dist/indexeddbshim-Key.min.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs +17263 -1396
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +3892 -1271
- package/dist/indexeddbshim-UnicodeIdentifiers.js.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js +2 -2
- package/dist/indexeddbshim-UnicodeIdentifiers.min.js.map +1 -1
- package/dist/indexeddbshim-node.cjs +17259 -1396
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +3887 -1271
- package/dist/indexeddbshim-noninvasive.js.map +1 -1
- package/dist/indexeddbshim-noninvasive.min.js +2 -2
- package/dist/indexeddbshim-noninvasive.min.js.map +1 -1
- package/dist/indexeddbshim.js +3887 -1271
- package/dist/indexeddbshim.js.map +1 -1
- package/dist/indexeddbshim.min.js +2 -2
- package/dist/indexeddbshim.min.js.map +1 -1
- package/dist/node-UnicodeIdentifiers.d.ts +8 -0
- package/dist/node-UnicodeIdentifiers.d.ts.map +1 -0
- package/dist/node.d.ts +8 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/nodeWebSQL.d.ts +3 -0
- package/dist/nodeWebSQL.d.ts.map +1 -0
- package/dist/setGlobalVars.d.ts +79 -0
- package/dist/setGlobalVars.d.ts.map +1 -0
- package/dist/unicode-regex.d.ts +3 -0
- package/dist/unicode-regex.d.ts.map +1 -0
- package/dist/util.d.ts +174 -0
- package/dist/util.d.ts.map +1 -0
- package/package.json +40 -27
- package/src/CFG.js +89 -11
- package/src/DOMException.js +116 -29
- package/src/DOMStringList.js +92 -2
- package/src/Event.js +19 -4
- package/src/IDBCursor.js +339 -67
- package/src/IDBDatabase.js +87 -10
- package/src/IDBFactory.js +319 -56
- package/src/IDBIndex.js +385 -96
- package/src/IDBKeyRange.js +86 -13
- package/src/IDBObjectStore.js +326 -68
- package/src/IDBRequest.js +59 -1
- package/src/IDBTransaction.js +247 -38
- package/src/IDBVersionChangeEvent.js +28 -3
- package/src/Key.js +273 -156
- package/src/Sca.js +29 -4
- package/src/browser-UnicodeIdentifiers.js +5 -1
- package/src/cmp.js +5 -5
- package/src/node-UnicodeIdentifiers.js +9 -0
- package/src/node.js +5 -0
- package/src/nodeWebSQL.js +11 -5
- package/src/setGlobalVars.js +156 -21
- package/src/unicode-regex.js +9 -1
- package/src/util.js +228 -40
- package/typings/shimIndexedDB.d.ts +9 -0
package/src/IDBObjectStore.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import SyncPromise from 'sync-promise';
|
|
1
|
+
import SyncPromise from 'sync-promise-expanded';
|
|
2
2
|
import {createDOMException} from './DOMException.js';
|
|
3
3
|
import {IDBCursor, IDBCursorWithValue} from './IDBCursor.js';
|
|
4
4
|
import {setSQLForKeyRange, convertValueToKeyRange} from './IDBKeyRange.js';
|
|
@@ -12,22 +12,63 @@ import CFG from './CFG.js';
|
|
|
12
12
|
|
|
13
13
|
const readonlyProperties = ['keyPath', 'indexNames', 'transaction', 'autoIncrement'];
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {number} Integer
|
|
17
|
+
*/
|
|
18
|
+
|
|
16
19
|
/**
|
|
17
20
|
* IndexedDB Object Store.
|
|
18
21
|
* @see http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBObjectStore
|
|
19
|
-
* @param {IDBObjectStoreProperties} storeProperties
|
|
20
|
-
* @param {IDBTransaction} transaction
|
|
21
22
|
* @class
|
|
22
23
|
*/
|
|
23
24
|
function IDBObjectStore () {
|
|
24
|
-
/* eslint-enable jsdoc/check-param-names */
|
|
25
25
|
throw new TypeError('Illegal constructor');
|
|
26
26
|
}
|
|
27
27
|
const IDBObjectStoreAlias = IDBObjectStore;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {IDBObjectStore & {
|
|
31
|
+
* name: string,
|
|
32
|
+
* keyPath: import('./Key.js').KeyPath,
|
|
33
|
+
* transaction?: import('./IDBTransaction.js').IDBTransactionFull,
|
|
34
|
+
* indexNames: import('./DOMStringList.js').DOMStringListFull,
|
|
35
|
+
* autoIncrement: boolean,
|
|
36
|
+
* __autoIncrement: boolean,
|
|
37
|
+
* __indexes: {[key: string]: import('./IDBIndex.js').IDBIndexFull},
|
|
38
|
+
* __indexHandles: {[key: string]: import('./IDBIndex.js').IDBIndexFull},
|
|
39
|
+
* __indexNames: import('./DOMStringList.js').DOMStringListFull,
|
|
40
|
+
* __oldIndexNames: import('./DOMStringList.js').DOMStringListFull,
|
|
41
|
+
* __transaction?: import('./IDBTransaction.js').IDBTransactionFull,
|
|
42
|
+
* __name: string,
|
|
43
|
+
* __keyPath: import('./Key.js').KeyPath,
|
|
44
|
+
* __originalName: string,
|
|
45
|
+
* __currentName: string,
|
|
46
|
+
* __pendingName?: string,
|
|
47
|
+
* __pendingDelete?: boolean,
|
|
48
|
+
* __pendingCreate?: boolean,
|
|
49
|
+
* __deleted?: boolean,
|
|
50
|
+
* __cursors: (
|
|
51
|
+
* import('./IDBCursor.js').IDBCursorFull|
|
|
52
|
+
* import('./IDBCursor.js').IDBCursorWithValueFull
|
|
53
|
+
* )[],
|
|
54
|
+
* __idbdb: import('./IDBDatabase.js').IDBDatabaseFull,
|
|
55
|
+
* }} IDBObjectStoreFull
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @param {import('./IDBDatabase.js').IDBObjectStoreProperties} storeProperties
|
|
61
|
+
* @param {import('./IDBTransaction.js').IDBTransactionFull} [transaction]
|
|
62
|
+
* @returns {IDBObjectStoreFull}
|
|
63
|
+
*/
|
|
28
64
|
IDBObjectStore.__createInstance = function (storeProperties, transaction) {
|
|
65
|
+
/**
|
|
66
|
+
* @class
|
|
67
|
+
* @this {IDBObjectStoreFull}
|
|
68
|
+
*/
|
|
29
69
|
function IDBObjectStore () {
|
|
30
70
|
const me = this;
|
|
71
|
+
// @ts-expect-error It's ok
|
|
31
72
|
me[Symbol.toStringTag] = 'IDBObjectStore';
|
|
32
73
|
util.defineReadonlyProperties(this, readonlyProperties);
|
|
33
74
|
me.__name = me.__originalName = storeProperties.name;
|
|
@@ -44,7 +85,7 @@ IDBObjectStore.__createInstance = function (storeProperties, transaction) {
|
|
|
44
85
|
me.__indexNames = DOMStringList.__createInstance();
|
|
45
86
|
const {indexList} = storeProperties;
|
|
46
87
|
for (const indexName in indexList) {
|
|
47
|
-
if (
|
|
88
|
+
if (Object.hasOwn(indexList, indexName)) {
|
|
48
89
|
const index = IDBIndex.__createInstance(me, indexList[indexName]);
|
|
49
90
|
me.__indexes[index.name] = index;
|
|
50
91
|
if (!index.__deleted) {
|
|
@@ -61,9 +102,18 @@ IDBObjectStore.__createInstance = function (storeProperties, transaction) {
|
|
|
61
102
|
Object.defineProperty(this, 'name', {
|
|
62
103
|
enumerable: false,
|
|
63
104
|
configurable: false,
|
|
105
|
+
/**
|
|
106
|
+
* @this {IDBObjectStoreFull}
|
|
107
|
+
* @returns {string}
|
|
108
|
+
*/
|
|
64
109
|
get () {
|
|
65
110
|
return this.__name;
|
|
66
111
|
},
|
|
112
|
+
/**
|
|
113
|
+
* @param {string} name
|
|
114
|
+
* @this {IDBObjectStoreFull}
|
|
115
|
+
* @returns {void}
|
|
116
|
+
*/
|
|
67
117
|
set (name) {
|
|
68
118
|
const me = this;
|
|
69
119
|
name = util.convertToDOMString(name);
|
|
@@ -87,16 +137,24 @@ IDBObjectStore.__createInstance = function (storeProperties, transaction) {
|
|
|
87
137
|
|
|
88
138
|
me.__idbdb.objectStoreNames.splice(me.__idbdb.objectStoreNames.indexOf(oldName), 1, name);
|
|
89
139
|
|
|
90
|
-
const oldHandle =
|
|
140
|
+
const oldHandle = /** @type {IDBObjectStoreFull} */ (
|
|
141
|
+
/** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
142
|
+
me.transaction
|
|
143
|
+
).__storeHandles[oldName]
|
|
144
|
+
);
|
|
91
145
|
oldHandle.__name = name; // Fix old references
|
|
92
|
-
|
|
146
|
+
/** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
147
|
+
me.transaction
|
|
148
|
+
).__storeHandles[name] = oldHandle; // Ensure new reference accessible
|
|
93
149
|
|
|
94
150
|
me.__pendingName = oldName;
|
|
95
151
|
|
|
96
152
|
const sql = 'UPDATE __sys__ SET "name" = ? WHERE "name" = ?';
|
|
97
153
|
const sqlValues = [util.escapeSQLiteStatement(name), util.escapeSQLiteStatement(oldName)];
|
|
98
154
|
CFG.DEBUG && console.log(sql, sqlValues);
|
|
99
|
-
|
|
155
|
+
/** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
156
|
+
me.transaction
|
|
157
|
+
).__addNonRequestToTransactionQueue(function objectStoreClear (tx, args, success, error) {
|
|
100
158
|
tx.executeSql(sql, sqlValues, function (tx, data) {
|
|
101
159
|
// This SQL preserves indexes per https://www.sqlite.org/lang_altertable.html
|
|
102
160
|
const sql = 'ALTER TABLE ' + util.escapeStoreNameForSQL(oldName) + ' RENAME TO ' + util.escapeStoreNameForSQL(name);
|
|
@@ -107,21 +165,23 @@ IDBObjectStore.__createInstance = function (storeProperties, transaction) {
|
|
|
107
165
|
});
|
|
108
166
|
}, function (tx, err) {
|
|
109
167
|
error(err);
|
|
168
|
+
return true;
|
|
110
169
|
});
|
|
111
170
|
});
|
|
112
171
|
}
|
|
113
172
|
});
|
|
114
173
|
}
|
|
115
174
|
IDBObjectStore.prototype = IDBObjectStoreAlias.prototype;
|
|
175
|
+
|
|
176
|
+
// @ts-expect-error It's ok
|
|
116
177
|
return new IDBObjectStore();
|
|
117
178
|
};
|
|
118
179
|
|
|
119
180
|
/**
|
|
120
181
|
* Clones an IDBObjectStore instance for a different IDBTransaction instance.
|
|
121
|
-
* @param {
|
|
122
|
-
* @param {IDBTransaction} transaction
|
|
123
|
-
* @
|
|
124
|
-
* @returns {IDBObjectStore}
|
|
182
|
+
* @param {IDBObjectStoreFull} store
|
|
183
|
+
* @param {import('./IDBTransaction.js').IDBTransactionFull} transaction
|
|
184
|
+
* @returns {IDBObjectStoreFull}
|
|
125
185
|
*/
|
|
126
186
|
IDBObjectStore.__clone = function (store, transaction) {
|
|
127
187
|
const newStore = IDBObjectStore.__createInstance({
|
|
@@ -133,23 +193,37 @@ IDBObjectStore.__clone = function (store, transaction) {
|
|
|
133
193
|
cursors: store.__cursors
|
|
134
194
|
}, transaction);
|
|
135
195
|
|
|
136
|
-
|
|
196
|
+
/** @type {const} */ ([
|
|
197
|
+
'__indexes', '__indexNames', '__oldIndexNames',
|
|
198
|
+
'__deleted', '__pendingDelete', '__pendingCreate', '__originalName'
|
|
199
|
+
]).forEach((p) => {
|
|
200
|
+
// @ts-expect-error It's ok
|
|
137
201
|
newStore[p] = store[p];
|
|
138
202
|
});
|
|
139
203
|
return newStore;
|
|
140
204
|
};
|
|
141
205
|
|
|
206
|
+
/**
|
|
207
|
+
*
|
|
208
|
+
* @param {IDBObjectStoreFull|import('./IDBIndex.js').IDBIndexFull} store
|
|
209
|
+
* @param {string} [msg]
|
|
210
|
+
* @throws {DOMException}
|
|
211
|
+
* @returns {void}
|
|
212
|
+
*/
|
|
142
213
|
IDBObjectStore.__invalidStateIfDeleted = function (store, msg) {
|
|
143
|
-
if (
|
|
214
|
+
if (
|
|
215
|
+
store.__deleted || store.__pendingDelete || (store.__pendingCreate && (
|
|
216
|
+
'transaction' in store && store.transaction && store.transaction.__errored
|
|
217
|
+
))
|
|
218
|
+
) {
|
|
144
219
|
throw createDOMException('InvalidStateError', msg || 'This store has been deleted');
|
|
145
220
|
}
|
|
146
221
|
};
|
|
147
222
|
|
|
148
223
|
/**
|
|
149
224
|
* Creates a new object store in the database.
|
|
150
|
-
* @param {IDBDatabase} db
|
|
151
|
-
* @param {
|
|
152
|
-
* @protected
|
|
225
|
+
* @param {import('./IDBDatabase.js').IDBDatabaseFull} db
|
|
226
|
+
* @param {IDBObjectStoreFull} store
|
|
153
227
|
* @returns {IDBObjectStore}
|
|
154
228
|
*/
|
|
155
229
|
IDBObjectStore.__createObjectStore = function (db, store) {
|
|
@@ -160,7 +234,9 @@ IDBObjectStore.__createObjectStore = function (db, store) {
|
|
|
160
234
|
db.objectStoreNames.push(storeName);
|
|
161
235
|
|
|
162
236
|
// Add the object store to WebSQL
|
|
163
|
-
const transaction
|
|
237
|
+
const transaction =/** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
238
|
+
db.__versionTransaction
|
|
239
|
+
);
|
|
164
240
|
|
|
165
241
|
const storeHandles = transaction.__storeHandles;
|
|
166
242
|
if (!storeHandles[storeName] ||
|
|
@@ -172,9 +248,15 @@ IDBObjectStore.__createObjectStore = function (db, store) {
|
|
|
172
248
|
}
|
|
173
249
|
|
|
174
250
|
transaction.__addNonRequestToTransactionQueue(function createObjectStore (tx, args, success, failure) {
|
|
251
|
+
/**
|
|
252
|
+
* @param {SQLTransaction} tx
|
|
253
|
+
* @param {SQLError} [err]
|
|
254
|
+
* @returns {boolean}
|
|
255
|
+
*/
|
|
175
256
|
function error (tx, err) {
|
|
176
257
|
CFG.DEBUG && console.log(err);
|
|
177
258
|
failure(createDOMException('UnknownError', 'Could not create object store "' + storeName + '"', err));
|
|
259
|
+
return true;
|
|
178
260
|
}
|
|
179
261
|
|
|
180
262
|
const escapedStoreNameSQL = util.escapeStoreNameForSQL(storeName);
|
|
@@ -182,6 +264,9 @@ IDBObjectStore.__createObjectStore = function (db, store) {
|
|
|
182
264
|
const sql = ['CREATE TABLE', escapedStoreNameSQL, '(key BLOB', store.autoIncrement ? 'UNIQUE, inc INTEGER PRIMARY KEY AUTOINCREMENT' : 'PRIMARY KEY', ', value BLOB)'].join(' ');
|
|
183
265
|
CFG.DEBUG && console.log(sql);
|
|
184
266
|
tx.executeSql(sql, [], function (tx, data) {
|
|
267
|
+
/**
|
|
268
|
+
* @returns {void}
|
|
269
|
+
*/
|
|
185
270
|
function insertStoreInfo () {
|
|
186
271
|
const encodedKeyPath = JSON.stringify(store.keyPath);
|
|
187
272
|
tx.executeSql('INSERT INTO __sys__ VALUES (?,?,?,?,?)', [
|
|
@@ -213,9 +298,8 @@ IDBObjectStore.__createObjectStore = function (db, store) {
|
|
|
213
298
|
|
|
214
299
|
/**
|
|
215
300
|
* Deletes an object store from the database.
|
|
216
|
-
* @param {IDBDatabase} db
|
|
217
|
-
* @param {IDBObjectStore} store
|
|
218
|
-
* @protected
|
|
301
|
+
* @param {import('./IDBDatabase.js').IDBDatabaseFull} db
|
|
302
|
+
* @param {import('./IDBObjectStore.js').IDBObjectStoreFull} store
|
|
219
303
|
* @returns {void}
|
|
220
304
|
*/
|
|
221
305
|
IDBObjectStore.__deleteObjectStore = function (db, store) {
|
|
@@ -233,11 +317,19 @@ IDBObjectStore.__deleteObjectStore = function (db, store) {
|
|
|
233
317
|
}
|
|
234
318
|
|
|
235
319
|
// Remove the object store from WebSQL
|
|
236
|
-
const transaction =
|
|
320
|
+
const transaction = /** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
321
|
+
db.__versionTransaction
|
|
322
|
+
);
|
|
237
323
|
transaction.__addNonRequestToTransactionQueue(function deleteObjectStore (tx, args, success, failure) {
|
|
324
|
+
/**
|
|
325
|
+
* @param {SQLTransaction} tx
|
|
326
|
+
* @param {SQLError} [err]
|
|
327
|
+
* @returns {boolean}
|
|
328
|
+
*/
|
|
238
329
|
function error (tx, err) {
|
|
239
330
|
CFG.DEBUG && console.log(err);
|
|
240
331
|
failure(createDOMException('UnknownError', 'Could not delete ObjectStore', err));
|
|
332
|
+
return true;
|
|
241
333
|
}
|
|
242
334
|
|
|
243
335
|
tx.executeSql('SELECT "name" FROM __sys__ WHERE "name" = ?', [util.escapeSQLiteStatement(store.__currentName)], function (tx, data) {
|
|
@@ -259,10 +351,8 @@ IDBObjectStore.__deleteObjectStore = function (db, store) {
|
|
|
259
351
|
};
|
|
260
352
|
|
|
261
353
|
/**
|
|
262
|
-
* @typedef {
|
|
263
|
-
|
|
264
|
-
* @property {*} 1
|
|
265
|
-
*/
|
|
354
|
+
* @typedef {[import('./Key.js').Key, import('./Key.js').Value]} KeyValueArray
|
|
355
|
+
*/
|
|
266
356
|
|
|
267
357
|
// Todo: Although we may end up needing to do cloning genuinely asynchronously (for Blobs and FileLists),
|
|
268
358
|
// and we'll want to ensure the queue starts up synchronously, we nevertheless do the cloning
|
|
@@ -275,18 +365,18 @@ IDBObjectStore.__deleteObjectStore = function (db, store) {
|
|
|
275
365
|
/**
|
|
276
366
|
* Determines whether the given inline or out-of-line key is valid,
|
|
277
367
|
* according to the object store's schema.
|
|
278
|
-
* @param {
|
|
279
|
-
* @param {
|
|
368
|
+
* @param {import('./Key.js').Value} value Used for inline keys
|
|
369
|
+
* @param {import('./Key.js').Key} key Used for out-of-line keys
|
|
280
370
|
* @param {boolean} cursorUpdate
|
|
281
371
|
* @throws {DOMException}
|
|
372
|
+
* @this {IDBObjectStoreFull}
|
|
282
373
|
* @returns {KeyValueArray}
|
|
283
|
-
* @private
|
|
284
374
|
*/
|
|
285
375
|
IDBObjectStore.prototype.__validateKeyAndValueAndCloneValue = function (value, key, cursorUpdate) {
|
|
286
376
|
const me = this;
|
|
287
377
|
if (me.keyPath !== null) {
|
|
288
378
|
if (key !== undefined) {
|
|
289
|
-
throw createDOMException('DataError', 'The object store uses in-line keys and the key parameter was provided'
|
|
379
|
+
throw createDOMException('DataError', 'The object store uses in-line keys and the key parameter was provided');
|
|
290
380
|
}
|
|
291
381
|
// Todo Binary: Avoid blobs loading async to ensure cloning (and errors therein)
|
|
292
382
|
// occurs sync; then can make cloning and this method without callbacks (except where ok
|
|
@@ -301,7 +391,8 @@ IDBObjectStore.prototype.__validateKeyAndValueAndCloneValue = function (value, k
|
|
|
301
391
|
if (!me.autoIncrement) {
|
|
302
392
|
throw createDOMException('DataError', 'Could not evaluate a key from keyPath and there is no key generator');
|
|
303
393
|
}
|
|
304
|
-
|
|
394
|
+
// Todo: Could the keyPath not be an array?
|
|
395
|
+
if (!Key.checkKeyCouldBeInjectedIntoValue(clonedValue, /** @type {string} */ (me.keyPath))) {
|
|
305
396
|
throw createDOMException('DataError', 'A key could not be injected into a value');
|
|
306
397
|
}
|
|
307
398
|
// A key will be generated
|
|
@@ -314,7 +405,7 @@ IDBObjectStore.prototype.__validateKeyAndValueAndCloneValue = function (value, k
|
|
|
314
405
|
}
|
|
315
406
|
if (key === undefined) {
|
|
316
407
|
if (!me.autoIncrement) {
|
|
317
|
-
throw createDOMException('DataError', 'The object store uses out-of-line keys and has no key generator and the key parameter was not provided.'
|
|
408
|
+
throw createDOMException('DataError', 'The object store uses out-of-line keys and has no key generator and the key parameter was not provided.');
|
|
318
409
|
}
|
|
319
410
|
// A key will be generated
|
|
320
411
|
key = undefined;
|
|
@@ -330,17 +421,22 @@ IDBObjectStore.prototype.__validateKeyAndValueAndCloneValue = function (value, k
|
|
|
330
421
|
* the object store
|
|
331
422
|
* If the table has auto increment, get the current number (unless it has
|
|
332
423
|
* a keyPath leading to a valid but non-numeric or < 1 key).
|
|
333
|
-
* @param {
|
|
334
|
-
* @param {
|
|
335
|
-
* @param {
|
|
336
|
-
* @param {
|
|
337
|
-
* @param {
|
|
424
|
+
* @param {SQLTransaction} tx
|
|
425
|
+
* @param {import('./Key.js').Value} value
|
|
426
|
+
* @param {import('./Key.js').Key} key
|
|
427
|
+
* @param {(key: import('./Key.js').Key, cn?: Integer) => void} success
|
|
428
|
+
* @param {import('./Key.js').SQLFailureCallback} failCb
|
|
429
|
+
* @this {IDBObjectStoreFull}
|
|
338
430
|
* @returns {void}
|
|
339
431
|
*/
|
|
340
432
|
IDBObjectStore.prototype.__deriveKey = function (tx, value, key, success, failCb) {
|
|
341
433
|
const me = this;
|
|
342
434
|
|
|
343
435
|
// Only run if cloning is needed
|
|
436
|
+
/**
|
|
437
|
+
* @param {Integer} [oldCn]
|
|
438
|
+
* @returns {void}
|
|
439
|
+
*/
|
|
344
440
|
function keyCloneThenSuccess (oldCn) { // We want to return the original key, so we don't need to accept an argument here
|
|
345
441
|
Sca.encode(key, function (key) {
|
|
346
442
|
key = Sca.decode(key);
|
|
@@ -358,7 +454,10 @@ IDBObjectStore.prototype.__deriveKey = function (tx, value, key, success, failCb
|
|
|
358
454
|
}
|
|
359
455
|
if (me.keyPath !== null) {
|
|
360
456
|
// Should not throw now as checked earlier
|
|
361
|
-
|
|
457
|
+
// Todo: Could this not be an array here?
|
|
458
|
+
Key.injectKeyIntoValueUsingKeyPath(
|
|
459
|
+
value, key, /** @type {string} */ (me.keyPath)
|
|
460
|
+
);
|
|
362
461
|
}
|
|
363
462
|
success(key, oldCn);
|
|
364
463
|
}, failCb);
|
|
@@ -371,10 +470,25 @@ IDBObjectStore.prototype.__deriveKey = function (tx, value, key, success, failCb
|
|
|
371
470
|
}
|
|
372
471
|
};
|
|
373
472
|
|
|
473
|
+
/**
|
|
474
|
+
*
|
|
475
|
+
* @param {SQLTransaction} tx
|
|
476
|
+
* @param {string} encoded
|
|
477
|
+
* @param {import('./Key.js').Value} value
|
|
478
|
+
* @param {import('./Key.js').Key|Integer} clonedKeyOrCurrentNumber
|
|
479
|
+
* @param {Integer|undefined} oldCn
|
|
480
|
+
* @param {(
|
|
481
|
+
* clonedKeyOrCurrentNumber: import('./Key.js').Key|Integer
|
|
482
|
+
* ) => void} success
|
|
483
|
+
* @param {(err: Error|DOMException) => void} error
|
|
484
|
+
* @this {IDBObjectStoreFull}
|
|
485
|
+
* @returns {SyncPromise}
|
|
486
|
+
*/
|
|
374
487
|
IDBObjectStore.prototype.__insertData = function (tx, encoded, value, clonedKeyOrCurrentNumber, oldCn, success, error) {
|
|
375
488
|
const me = this;
|
|
376
489
|
// The `ConstraintError` to occur for `add` upon a duplicate will occur naturally in attempting an insert
|
|
377
490
|
// We process the index information first as it will stored in the same table as the store
|
|
491
|
+
/** @type {{[key: string]: string}} */
|
|
378
492
|
const paramMap = {};
|
|
379
493
|
const indexPromises = Object.keys(
|
|
380
494
|
// We do not iterate `indexNames` as those can be modified synchronously (e.g.,
|
|
@@ -403,25 +517,38 @@ IDBObjectStore.prototype.__insertData = function (tx, encoded, value, clonedKeyO
|
|
|
403
517
|
// after this add), we avoid checks
|
|
404
518
|
index.__deleted
|
|
405
519
|
) {
|
|
406
|
-
resolve();
|
|
520
|
+
resolve(undefined);
|
|
407
521
|
return;
|
|
408
522
|
}
|
|
523
|
+
/**
|
|
524
|
+
* @type {import('./Key.js').KeyValueObject|
|
|
525
|
+
* import('./Key.js').KeyPathEvaluateValue}
|
|
526
|
+
*/
|
|
409
527
|
let indexKey;
|
|
410
528
|
try {
|
|
411
529
|
indexKey = Key.extractKeyValueDecodedFromValueUsingKeyPath(value, index.keyPath, index.multiEntry); // Add as necessary to this and skip past this index if exceptions here)
|
|
412
|
-
if (
|
|
530
|
+
if (
|
|
531
|
+
('invalid' in indexKey && indexKey.invalid) ||
|
|
532
|
+
('failure' in indexKey && indexKey.failure)
|
|
533
|
+
) {
|
|
413
534
|
throw new Error('Go to catch');
|
|
414
535
|
}
|
|
415
536
|
} catch (err) {
|
|
416
|
-
resolve();
|
|
537
|
+
resolve(undefined);
|
|
417
538
|
return;
|
|
418
539
|
}
|
|
419
540
|
indexKey = indexKey.value;
|
|
541
|
+
/**
|
|
542
|
+
* @param {import('./IDBIndex.js').IDBIndexFull} index
|
|
543
|
+
* @returns {void}
|
|
544
|
+
*/
|
|
420
545
|
function setIndexInfo (index) {
|
|
421
546
|
if (indexKey === undefined) {
|
|
422
547
|
return;
|
|
423
548
|
}
|
|
424
|
-
paramMap[index.__currentName] =
|
|
549
|
+
paramMap[index.__currentName] = /** @type {string} */ (
|
|
550
|
+
Key.encode(indexKey, index.multiEntry)
|
|
551
|
+
);
|
|
425
552
|
}
|
|
426
553
|
if (index.unique) {
|
|
427
554
|
const multiCheck = index.multiEntry && Array.isArray(indexKey);
|
|
@@ -429,7 +556,7 @@ IDBObjectStore.prototype.__insertData = function (tx, encoded, value, clonedKeyO
|
|
|
429
556
|
executeFetchIndexData(null, ...fetchArgs, tx, null, function success (key) {
|
|
430
557
|
if (key === undefined) {
|
|
431
558
|
setIndexInfo(index);
|
|
432
|
-
resolve();
|
|
559
|
+
resolve(undefined);
|
|
433
560
|
return;
|
|
434
561
|
}
|
|
435
562
|
reject(createDOMException(
|
|
@@ -441,7 +568,7 @@ IDBObjectStore.prototype.__insertData = function (tx, encoded, value, clonedKeyO
|
|
|
441
568
|
}, reject);
|
|
442
569
|
} else {
|
|
443
570
|
setIndexInfo(index);
|
|
444
|
-
resolve();
|
|
571
|
+
resolve(undefined);
|
|
445
572
|
}
|
|
446
573
|
});
|
|
447
574
|
});
|
|
@@ -455,7 +582,7 @@ IDBObjectStore.prototype.__insertData = function (tx, encoded, value, clonedKeyO
|
|
|
455
582
|
sqlEnd.push('?,');
|
|
456
583
|
insertSqlValues.push(
|
|
457
584
|
util.escapeSQLiteStatement(
|
|
458
|
-
Key.encode(clonedKeyOrCurrentNumber)
|
|
585
|
+
/** @type {string} */ (Key.encode(clonedKeyOrCurrentNumber))
|
|
459
586
|
)
|
|
460
587
|
);
|
|
461
588
|
}
|
|
@@ -476,10 +603,16 @@ IDBObjectStore.prototype.__insertData = function (tx, encoded, value, clonedKeyO
|
|
|
476
603
|
success(clonedKeyOrCurrentNumber);
|
|
477
604
|
}, function (tx, err) {
|
|
478
605
|
// Should occur for `add` operation
|
|
479
|
-
error(createDOMException(
|
|
606
|
+
error(createDOMException(
|
|
607
|
+
'ConstraintError', /** @type {string} */ (err.message), err
|
|
608
|
+
));
|
|
609
|
+
return true;
|
|
480
610
|
});
|
|
481
611
|
return undefined;
|
|
482
612
|
}).catch(function (err) {
|
|
613
|
+
/**
|
|
614
|
+
* @returns {void}
|
|
615
|
+
*/
|
|
483
616
|
function fail () {
|
|
484
617
|
// Todo: Add a different error object here if `assignCurrentNumber`
|
|
485
618
|
// fails in reverting?
|
|
@@ -487,12 +620,19 @@ IDBObjectStore.prototype.__insertData = function (tx, encoded, value, clonedKeyO
|
|
|
487
620
|
}
|
|
488
621
|
if (typeof oldCn === 'number') {
|
|
489
622
|
Key.assignCurrentNumber(tx, me, oldCn, fail, fail);
|
|
490
|
-
return;
|
|
623
|
+
return null;
|
|
491
624
|
}
|
|
492
625
|
fail();
|
|
626
|
+
return null;
|
|
493
627
|
});
|
|
494
628
|
};
|
|
495
629
|
|
|
630
|
+
/**
|
|
631
|
+
*
|
|
632
|
+
* @param {import('./Key.js').Value} value
|
|
633
|
+
* @this {IDBObjectStoreFull}
|
|
634
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
635
|
+
*/
|
|
496
636
|
IDBObjectStore.prototype.add = function (value /* , key */) {
|
|
497
637
|
const me = this;
|
|
498
638
|
// eslint-disable-next-line prefer-rest-params
|
|
@@ -505,14 +645,25 @@ IDBObjectStore.prototype.add = function (value /* , key */) {
|
|
|
505
645
|
}
|
|
506
646
|
IDBObjectStore.__invalidStateIfDeleted(me);
|
|
507
647
|
IDBTransaction.__assertActive(me.transaction);
|
|
508
|
-
|
|
648
|
+
/** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
649
|
+
me.transaction
|
|
650
|
+
).__assertWritable();
|
|
509
651
|
|
|
510
|
-
const request =
|
|
652
|
+
const request = /** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
653
|
+
me.transaction
|
|
654
|
+
).__createRequest(me);
|
|
511
655
|
const [ky, clonedValue] = me.__validateKeyAndValueAndCloneValue(value, key, false);
|
|
512
656
|
IDBObjectStore.__storingRecordObjectStore(request, me, true, clonedValue, true, ky);
|
|
513
657
|
return request;
|
|
514
658
|
};
|
|
515
659
|
|
|
660
|
+
/**
|
|
661
|
+
*
|
|
662
|
+
* @param {import('./Key.js').Value} value
|
|
663
|
+
* @throws {TypeError}
|
|
664
|
+
* @this {IDBObjectStoreFull}
|
|
665
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
666
|
+
*/
|
|
516
667
|
IDBObjectStore.prototype.put = function (value /*, key */) {
|
|
517
668
|
const me = this;
|
|
518
669
|
// eslint-disable-next-line prefer-rest-params
|
|
@@ -525,34 +676,63 @@ IDBObjectStore.prototype.put = function (value /*, key */) {
|
|
|
525
676
|
}
|
|
526
677
|
IDBObjectStore.__invalidStateIfDeleted(me);
|
|
527
678
|
IDBTransaction.__assertActive(me.transaction);
|
|
528
|
-
|
|
679
|
+
/** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
680
|
+
me.transaction
|
|
681
|
+
).__assertWritable();
|
|
529
682
|
|
|
530
|
-
const request =
|
|
683
|
+
const request = /** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
684
|
+
me.transaction
|
|
685
|
+
).__createRequest(me);
|
|
531
686
|
const [ky, clonedValue] = me.__validateKeyAndValueAndCloneValue(value, key, false);
|
|
532
687
|
IDBObjectStore.__storingRecordObjectStore(request, me, true, clonedValue, false, ky);
|
|
533
688
|
return request;
|
|
534
689
|
};
|
|
535
690
|
|
|
691
|
+
/**
|
|
692
|
+
*
|
|
693
|
+
* @param {SQLTransaction} tx
|
|
694
|
+
* @param {import('./Key.js').Key} key
|
|
695
|
+
* @param {(tx: SQLTransaction) => void} cb
|
|
696
|
+
* @param {(err: SQLError) => void} error
|
|
697
|
+
* @this {IDBObjectStoreFull}
|
|
698
|
+
* @returns {void}
|
|
699
|
+
*/
|
|
536
700
|
IDBObjectStore.prototype.__overwrite = function (tx, key, cb, error) {
|
|
537
701
|
const me = this;
|
|
538
702
|
// First try to delete if the record exists
|
|
539
703
|
// Key.convertValueToKey(key); // Already run
|
|
540
704
|
const sql = 'DELETE FROM ' + util.escapeStoreNameForSQL(me.__currentName) + ' WHERE "key" = ?';
|
|
541
|
-
const encodedKey = Key.encode(key);
|
|
705
|
+
const encodedKey = /** @type {string} */ (Key.encode(key));
|
|
542
706
|
tx.executeSql(sql, [util.escapeSQLiteStatement(encodedKey)], function (tx, data) {
|
|
543
707
|
CFG.DEBUG && console.log('Did the row with the', key, 'exist?', data.rowsAffected);
|
|
544
708
|
cb(tx);
|
|
545
709
|
}, function (tx, err) {
|
|
546
710
|
error(err);
|
|
711
|
+
return true;
|
|
547
712
|
});
|
|
548
713
|
};
|
|
549
714
|
|
|
715
|
+
/**
|
|
716
|
+
*
|
|
717
|
+
* @param {import('./IDBRequest.js').IDBRequestFull} request
|
|
718
|
+
* @param {IDBObjectStoreFull} store
|
|
719
|
+
* @param {boolean} invalidateCache
|
|
720
|
+
* @param {import('./Key.js').Value} value
|
|
721
|
+
* @param {boolean} noOverwrite
|
|
722
|
+
* @returns {void}
|
|
723
|
+
*/
|
|
550
724
|
IDBObjectStore.__storingRecordObjectStore = function (request, store, invalidateCache, value, noOverwrite /* , key */) {
|
|
551
725
|
// eslint-disable-next-line prefer-rest-params
|
|
552
726
|
const key = arguments[5];
|
|
553
|
-
|
|
727
|
+
/** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
728
|
+
store.transaction
|
|
729
|
+
).__pushToQueue(request, function (tx, args, success, error) {
|
|
554
730
|
store.__deriveKey(tx, value, key, function (clonedKeyOrCurrentNumber, oldCn) {
|
|
555
731
|
Sca.encode(value, function (encoded) {
|
|
732
|
+
/**
|
|
733
|
+
* @param {SQLTransaction} tx
|
|
734
|
+
* @returns {void}
|
|
735
|
+
*/
|
|
556
736
|
function insert (tx) {
|
|
557
737
|
store.__insertData(tx, encoded, value, clonedKeyOrCurrentNumber, oldCn, function (...args) {
|
|
558
738
|
if (invalidateCache) {
|
|
@@ -573,6 +753,15 @@ IDBObjectStore.__storingRecordObjectStore = function (request, store, invalidate
|
|
|
573
753
|
});
|
|
574
754
|
};
|
|
575
755
|
|
|
756
|
+
/**
|
|
757
|
+
*
|
|
758
|
+
* @param {import('./Key.js').Value} query
|
|
759
|
+
* @param {boolean} [getKey]
|
|
760
|
+
* @param {boolean} [getAll]
|
|
761
|
+
* @param {Integer} [count]
|
|
762
|
+
* @this {IDBObjectStoreFull}
|
|
763
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
764
|
+
*/
|
|
576
765
|
IDBObjectStore.prototype.__get = function (query, getKey, getAll, count) {
|
|
577
766
|
const me = this;
|
|
578
767
|
if (count !== undefined) {
|
|
@@ -584,7 +773,8 @@ IDBObjectStore.prototype.__get = function (query, getKey, getAll, count) {
|
|
|
584
773
|
const range = convertValueToKeyRange(query, !getAll);
|
|
585
774
|
|
|
586
775
|
const col = getKey ? 'key' : 'value';
|
|
587
|
-
|
|
776
|
+
const sql = ['SELECT', util.sqlQuote(col), 'FROM', util.escapeStoreNameForSQL(me.__currentName)];
|
|
777
|
+
/** @type {string[]} */
|
|
588
778
|
const sqlValues = [];
|
|
589
779
|
if (range !== undefined) {
|
|
590
780
|
sql.push('WHERE');
|
|
@@ -597,12 +787,14 @@ IDBObjectStore.prototype.__get = function (query, getKey, getAll, count) {
|
|
|
597
787
|
if (!Number.isFinite(count)) {
|
|
598
788
|
throw new TypeError('The count parameter must be a finite number');
|
|
599
789
|
}
|
|
600
|
-
sql.push('LIMIT', count);
|
|
790
|
+
sql.push('LIMIT', String(count));
|
|
601
791
|
}
|
|
602
|
-
|
|
603
|
-
return
|
|
792
|
+
const sqlStr = sql.join(' ');
|
|
793
|
+
return /** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
794
|
+
me.transaction
|
|
795
|
+
).__addToTransactionQueue(function objectStoreGet (tx, args, success, error) {
|
|
604
796
|
CFG.DEBUG && console.log('Fetching', me.__currentName, sqlValues);
|
|
605
|
-
tx.executeSql(
|
|
797
|
+
tx.executeSql(sqlStr, sqlValues, function (tx, data) {
|
|
606
798
|
CFG.DEBUG && console.log('Fetched data', data);
|
|
607
799
|
let ret;
|
|
608
800
|
try {
|
|
@@ -640,10 +832,18 @@ IDBObjectStore.prototype.__get = function (query, getKey, getAll, count) {
|
|
|
640
832
|
success(ret);
|
|
641
833
|
}, function (tx, err) {
|
|
642
834
|
error(err);
|
|
835
|
+
return true;
|
|
643
836
|
});
|
|
644
837
|
}, undefined, me);
|
|
645
838
|
};
|
|
646
839
|
|
|
840
|
+
/**
|
|
841
|
+
*
|
|
842
|
+
* @param {import('./Key.js').Value} query
|
|
843
|
+
* @throws {TypeError}
|
|
844
|
+
* @this {IDBObjectStoreFull}
|
|
845
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
846
|
+
*/
|
|
647
847
|
IDBObjectStore.prototype.get = function (query) {
|
|
648
848
|
if (!arguments.length) {
|
|
649
849
|
throw new TypeError('A parameter was missing for `IDBObjectStore.get`.');
|
|
@@ -651,6 +851,12 @@ IDBObjectStore.prototype.get = function (query) {
|
|
|
651
851
|
return this.__get(query);
|
|
652
852
|
};
|
|
653
853
|
|
|
854
|
+
/**
|
|
855
|
+
*
|
|
856
|
+
* @param {import('./Key.js').Value} query
|
|
857
|
+
* @this {IDBObjectStoreFull}
|
|
858
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
859
|
+
*/
|
|
654
860
|
IDBObjectStore.prototype.getKey = function (query) {
|
|
655
861
|
if (!arguments.length) {
|
|
656
862
|
throw new TypeError('A parameter was missing for `IDBObjectStore.getKey`.');
|
|
@@ -658,18 +864,33 @@ IDBObjectStore.prototype.getKey = function (query) {
|
|
|
658
864
|
return this.__get(query, true);
|
|
659
865
|
};
|
|
660
866
|
|
|
867
|
+
/**
|
|
868
|
+
* @this {IDBObjectStoreFull}
|
|
869
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
870
|
+
*/
|
|
661
871
|
IDBObjectStore.prototype.getAll = function (/* query, count */) {
|
|
662
872
|
// eslint-disable-next-line prefer-rest-params
|
|
663
873
|
const [query, count] = arguments;
|
|
664
874
|
return this.__get(query, false, true, count);
|
|
665
875
|
};
|
|
666
876
|
|
|
877
|
+
/**
|
|
878
|
+
* @this {IDBObjectStoreFull}
|
|
879
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
880
|
+
*/
|
|
667
881
|
IDBObjectStore.prototype.getAllKeys = function (/* query, count */) {
|
|
668
882
|
// eslint-disable-next-line prefer-rest-params
|
|
669
883
|
const [query, count] = arguments;
|
|
670
884
|
return this.__get(query, true, true, count);
|
|
671
885
|
};
|
|
672
886
|
|
|
887
|
+
/**
|
|
888
|
+
*
|
|
889
|
+
* @param {import('./Key.js').Value} query
|
|
890
|
+
* @throws {TypeError}
|
|
891
|
+
* @this {IDBObjectStoreFull}
|
|
892
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
893
|
+
*/
|
|
673
894
|
IDBObjectStore.prototype.delete = function (query) {
|
|
674
895
|
const me = this;
|
|
675
896
|
if (!(this instanceof IDBObjectStore)) {
|
|
@@ -681,16 +902,21 @@ IDBObjectStore.prototype.delete = function (query) {
|
|
|
681
902
|
|
|
682
903
|
IDBObjectStore.__invalidStateIfDeleted(me);
|
|
683
904
|
IDBTransaction.__assertActive(me.transaction);
|
|
684
|
-
|
|
905
|
+
/** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
906
|
+
me.transaction
|
|
907
|
+
).__assertWritable();
|
|
685
908
|
|
|
686
909
|
const range = convertValueToKeyRange(query, true);
|
|
687
910
|
|
|
688
911
|
const sqlArr = ['DELETE FROM', util.escapeStoreNameForSQL(me.__currentName), 'WHERE'];
|
|
912
|
+
/** @type {string[]} */
|
|
689
913
|
const sqlValues = [];
|
|
690
914
|
setSQLForKeyRange(range, util.sqlQuote('key'), sqlArr, sqlValues);
|
|
691
915
|
const sql = sqlArr.join(' ');
|
|
692
916
|
|
|
693
|
-
return
|
|
917
|
+
return /** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
918
|
+
me.transaction
|
|
919
|
+
).__addToTransactionQueue(function objectStoreDelete (tx, args, success, error) {
|
|
694
920
|
CFG.DEBUG && console.log('Deleting', me.__currentName, sqlValues);
|
|
695
921
|
tx.executeSql(sql, sqlValues, function (tx, data) {
|
|
696
922
|
CFG.DEBUG && console.log('Deleted from database', data.rowsAffected);
|
|
@@ -700,10 +926,15 @@ IDBObjectStore.prototype.delete = function (query) {
|
|
|
700
926
|
success();
|
|
701
927
|
}, function (tx, err) {
|
|
702
928
|
error(err);
|
|
929
|
+
return true;
|
|
703
930
|
});
|
|
704
931
|
}, undefined, me);
|
|
705
932
|
};
|
|
706
933
|
|
|
934
|
+
/**
|
|
935
|
+
* @this {IDBObjectStoreFull}
|
|
936
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
937
|
+
*/
|
|
707
938
|
IDBObjectStore.prototype.clear = function () {
|
|
708
939
|
const me = this;
|
|
709
940
|
if (!(this instanceof IDBObjectStore)) {
|
|
@@ -711,9 +942,13 @@ IDBObjectStore.prototype.clear = function () {
|
|
|
711
942
|
}
|
|
712
943
|
IDBObjectStore.__invalidStateIfDeleted(me);
|
|
713
944
|
IDBTransaction.__assertActive(me.transaction);
|
|
714
|
-
|
|
945
|
+
/** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
946
|
+
me.transaction
|
|
947
|
+
).__assertWritable();
|
|
715
948
|
|
|
716
|
-
return
|
|
949
|
+
return /** @type {import('./IDBTransaction.js').IDBTransactionFull} */ (
|
|
950
|
+
me.transaction
|
|
951
|
+
).__addToTransactionQueue(function objectStoreClear (tx, args, success, error) {
|
|
717
952
|
tx.executeSql('DELETE FROM ' + util.escapeStoreNameForSQL(me.__currentName), [], function (tx, data) {
|
|
718
953
|
CFG.DEBUG && console.log('Cleared all records from database', data.rowsAffected);
|
|
719
954
|
me.__cursors.forEach((cursor) => {
|
|
@@ -722,10 +957,15 @@ IDBObjectStore.prototype.clear = function () {
|
|
|
722
957
|
success();
|
|
723
958
|
}, function (tx, err) {
|
|
724
959
|
error(err);
|
|
960
|
+
return true;
|
|
725
961
|
});
|
|
726
962
|
}, undefined, me);
|
|
727
963
|
};
|
|
728
964
|
|
|
965
|
+
/**
|
|
966
|
+
* @this {IDBObjectStoreFull}
|
|
967
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
968
|
+
*/
|
|
729
969
|
IDBObjectStore.prototype.count = function (/* query */) {
|
|
730
970
|
const me = this;
|
|
731
971
|
// eslint-disable-next-line prefer-rest-params
|
|
@@ -740,6 +980,10 @@ IDBObjectStore.prototype.count = function (/* query */) {
|
|
|
740
980
|
return IDBCursorWithValue.__createInstance(query, 'next', me, me, 'key', 'value', true).__request;
|
|
741
981
|
};
|
|
742
982
|
|
|
983
|
+
/**
|
|
984
|
+
* @this {IDBObjectStoreFull}
|
|
985
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
986
|
+
*/
|
|
743
987
|
IDBObjectStore.prototype.openCursor = function (/* query, direction */) {
|
|
744
988
|
const me = this;
|
|
745
989
|
// eslint-disable-next-line prefer-rest-params
|
|
@@ -753,6 +997,10 @@ IDBObjectStore.prototype.openCursor = function (/* query, direction */) {
|
|
|
753
997
|
return cursor.__request;
|
|
754
998
|
};
|
|
755
999
|
|
|
1000
|
+
/**
|
|
1001
|
+
* @this {IDBObjectStoreFull}
|
|
1002
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
1003
|
+
*/
|
|
756
1004
|
IDBObjectStore.prototype.openKeyCursor = function (/* query, direction */) {
|
|
757
1005
|
const me = this;
|
|
758
1006
|
if (!(me instanceof IDBObjectStore)) {
|
|
@@ -766,6 +1014,12 @@ IDBObjectStore.prototype.openKeyCursor = function (/* query, direction */) {
|
|
|
766
1014
|
return cursor.__request;
|
|
767
1015
|
};
|
|
768
1016
|
|
|
1017
|
+
/**
|
|
1018
|
+
*
|
|
1019
|
+
* @param {string} indexName
|
|
1020
|
+
* @this {IDBObjectStoreFull}
|
|
1021
|
+
* @returns {import('./IDBIndex.js').IDBIndexFull}
|
|
1022
|
+
*/
|
|
769
1023
|
IDBObjectStore.prototype.index = function (indexName) {
|
|
770
1024
|
const me = this;
|
|
771
1025
|
if (!(me instanceof IDBObjectStore)) {
|
|
@@ -790,16 +1044,14 @@ IDBObjectStore.prototype.index = function (indexName) {
|
|
|
790
1044
|
return me.__indexHandles[indexName];
|
|
791
1045
|
};
|
|
792
1046
|
|
|
793
|
-
/* eslint-disable jsdoc/check-param-names */
|
|
794
1047
|
/**
|
|
795
1048
|
* Creates a new index on the object store.
|
|
796
1049
|
* @param {string} indexName
|
|
797
|
-
* @param {string} keyPath
|
|
798
|
-
* @
|
|
1050
|
+
* @param {string|string[]} keyPath
|
|
1051
|
+
* @this {IDBObjectStoreFull}
|
|
799
1052
|
* @returns {IDBIndex}
|
|
800
1053
|
*/
|
|
801
1054
|
IDBObjectStore.prototype.createIndex = function (indexName, keyPath /* , optionalParameters */) {
|
|
802
|
-
/* eslint-enable jsdoc/check-param-names */
|
|
803
1055
|
const me = this;
|
|
804
1056
|
// eslint-disable-next-line prefer-rest-params
|
|
805
1057
|
let optionalParameters = arguments[2];
|
|
@@ -829,7 +1081,7 @@ IDBObjectStore.prototype.createIndex = function (indexName, keyPath /* , optiona
|
|
|
829
1081
|
}
|
|
830
1082
|
|
|
831
1083
|
optionalParameters = optionalParameters || {};
|
|
832
|
-
/** @
|
|
1084
|
+
/** @type {import('./IDBIndex.js').IDBIndexProperties} */
|
|
833
1085
|
const indexProperties = {
|
|
834
1086
|
columnName: indexName,
|
|
835
1087
|
keyPath,
|
|
@@ -843,6 +1095,12 @@ IDBObjectStore.prototype.createIndex = function (indexName, keyPath /* , optiona
|
|
|
843
1095
|
return index;
|
|
844
1096
|
};
|
|
845
1097
|
|
|
1098
|
+
/**
|
|
1099
|
+
*
|
|
1100
|
+
* @param {string} name
|
|
1101
|
+
* @this {IDBObjectStoreFull}
|
|
1102
|
+
* @returns {void}
|
|
1103
|
+
*/
|
|
846
1104
|
IDBObjectStore.prototype.deleteIndex = function (name) {
|
|
847
1105
|
const me = this;
|
|
848
1106
|
if (!(me instanceof IDBObjectStore)) {
|