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/IDBRequest.js
CHANGED
|
@@ -14,9 +14,36 @@ const doneFlagGetters = ['result', 'error'];
|
|
|
14
14
|
function IDBRequest () {
|
|
15
15
|
throw new TypeError('Illegal constructor');
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {IDBRequest & EventTarget & import('eventtargeter').ShimEventTarget & {
|
|
20
|
+
* transaction: import('./IDBTransaction.js').IDBTransactionFull,
|
|
21
|
+
* __done: boolean,
|
|
22
|
+
* __result: import('./IDBDatabase.js').IDBDatabaseFull|undefined,
|
|
23
|
+
* __error: null|DOMException|Error,
|
|
24
|
+
* __source: null|import('./IDBDatabase.js').IDBDatabaseFull|
|
|
25
|
+
* import('./IDBObjectStore.js').IDBObjectStoreFull|
|
|
26
|
+
* import('./IDBIndex.js').IDBIndexFull,
|
|
27
|
+
* __transaction: undefined|null|
|
|
28
|
+
* import('./IDBTransaction.js').IDBTransactionFull,
|
|
29
|
+
* addLateEventListener: (ev: string, listener: (e: Event & {
|
|
30
|
+
* __legacyOutputDidListenersThrowError: boolean
|
|
31
|
+
* }) => void) => void
|
|
32
|
+
* addDefaultEventListener: (ev: string, listener: (e: Event & {
|
|
33
|
+
* __legacyOutputDidListenersThrowError: boolean
|
|
34
|
+
* }) => void) => void
|
|
35
|
+
* }} IDBRequestFull
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/* eslint-disable func-name-matching -- Polyfill */
|
|
39
|
+
/**
|
|
40
|
+
* @class
|
|
41
|
+
* @this {IDBRequestFull}
|
|
42
|
+
*/
|
|
18
43
|
IDBRequest.__super = function IDBRequest () {
|
|
44
|
+
// @ts-expect-error It's ok
|
|
19
45
|
this[Symbol.toStringTag] = 'IDBRequest';
|
|
46
|
+
// @ts-expect-error Part of `ShimEventTarget`
|
|
20
47
|
this.__setOptions({
|
|
21
48
|
legacyOutputDidListenersThrowFlag: true // Event hook for IndexedB
|
|
22
49
|
});
|
|
@@ -39,6 +66,10 @@ IDBRequest.__super = function IDBRequest () {
|
|
|
39
66
|
});
|
|
40
67
|
util.defineReadonlyProperties(this, readonlyProperties, {
|
|
41
68
|
readyState: {
|
|
69
|
+
/**
|
|
70
|
+
* @this {IDBRequestFull}
|
|
71
|
+
* @returns {"done"|"pending"}
|
|
72
|
+
*/
|
|
42
73
|
get readyState () {
|
|
43
74
|
return this.__done ? 'done' : 'pending';
|
|
44
75
|
}
|
|
@@ -50,14 +81,24 @@ IDBRequest.__super = function IDBRequest () {
|
|
|
50
81
|
this.__error = this.__source = this.__transaction = null;
|
|
51
82
|
this.__done = false;
|
|
52
83
|
};
|
|
84
|
+
/* eslint-enable func-name-matching -- Polyfill */
|
|
53
85
|
|
|
86
|
+
/**
|
|
87
|
+
* @returns {IDBRequestFull}
|
|
88
|
+
*/
|
|
54
89
|
IDBRequest.__createInstance = function () {
|
|
90
|
+
// @ts-expect-error Casting this causes other errors
|
|
55
91
|
return new IDBRequest.__super();
|
|
56
92
|
};
|
|
57
93
|
|
|
94
|
+
// @ts-expect-error It's ok
|
|
58
95
|
IDBRequest.prototype = EventTargetFactory.createInstance({extraProperties: ['debug']});
|
|
59
96
|
IDBRequest.prototype[Symbol.toStringTag] = 'IDBRequestPrototype';
|
|
60
97
|
|
|
98
|
+
/**
|
|
99
|
+
* @this {IDBRequestFull}
|
|
100
|
+
* @returns {import('./IDBTransaction.js').IDBTransactionFull|null|undefined}
|
|
101
|
+
*/
|
|
61
102
|
IDBRequest.prototype.__getParent = function () {
|
|
62
103
|
if (this.toString() === '[object IDBOpenDBRequest]') {
|
|
63
104
|
return null;
|
|
@@ -85,6 +126,10 @@ Object.defineProperty(IDBRequest, 'prototype', {
|
|
|
85
126
|
|
|
86
127
|
const openListeners = ['onblocked', 'onupgradeneeded'];
|
|
87
128
|
|
|
129
|
+
/**
|
|
130
|
+
* @typedef {IDBRequestFull & IDBOpenDBRequest & {}} IDBOpenDBRequestFull
|
|
131
|
+
*/
|
|
132
|
+
|
|
88
133
|
/**
|
|
89
134
|
* The IDBOpenDBRequest called when a database is opened.
|
|
90
135
|
* @class
|
|
@@ -92,6 +137,8 @@ const openListeners = ['onblocked', 'onupgradeneeded'];
|
|
|
92
137
|
function IDBOpenDBRequest () {
|
|
93
138
|
throw new TypeError('Illegal constructor');
|
|
94
139
|
}
|
|
140
|
+
|
|
141
|
+
// @ts-expect-error It's ok
|
|
95
142
|
IDBOpenDBRequest.prototype = Object.create(IDBRequest.prototype);
|
|
96
143
|
|
|
97
144
|
Object.defineProperty(IDBOpenDBRequest.prototype, 'constructor', {
|
|
@@ -102,11 +149,20 @@ Object.defineProperty(IDBOpenDBRequest.prototype, 'constructor', {
|
|
|
102
149
|
});
|
|
103
150
|
|
|
104
151
|
const IDBOpenDBRequestAlias = IDBOpenDBRequest;
|
|
152
|
+
/**
|
|
153
|
+
* @returns {IDBRequestFull & IDBOpenDBRequest}
|
|
154
|
+
*/
|
|
105
155
|
IDBOpenDBRequest.__createInstance = function () {
|
|
156
|
+
/**
|
|
157
|
+
* @class
|
|
158
|
+
* @this {IDBOpenDBRequestFull}
|
|
159
|
+
*/
|
|
106
160
|
function IDBOpenDBRequest () {
|
|
107
161
|
IDBRequest.__super.call(this);
|
|
108
162
|
|
|
163
|
+
// @ts-expect-error It's ok
|
|
109
164
|
this[Symbol.toStringTag] = 'IDBOpenDBRequest';
|
|
165
|
+
// @ts-expect-error It's ok
|
|
110
166
|
this.__setOptions({
|
|
111
167
|
legacyOutputDidListenersThrowFlag: true, // Event hook for IndexedB
|
|
112
168
|
extraProperties: ['oldVersion', 'newVersion', 'debug']
|
|
@@ -114,6 +170,8 @@ IDBOpenDBRequest.__createInstance = function () {
|
|
|
114
170
|
util.defineListenerProperties(this, openListeners);
|
|
115
171
|
}
|
|
116
172
|
IDBOpenDBRequest.prototype = IDBOpenDBRequestAlias.prototype;
|
|
173
|
+
|
|
174
|
+
// @ts-expect-error It's ok
|
|
117
175
|
return new IDBOpenDBRequest();
|
|
118
176
|
};
|
|
119
177
|
|
package/src/IDBTransaction.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {EventTargetFactory} from 'eventtargeter';
|
|
2
|
-
import SyncPromise from 'sync-promise';
|
|
2
|
+
import SyncPromise from 'sync-promise-expanded';
|
|
3
3
|
import {createEvent} from './Event.js';
|
|
4
4
|
import {logError, findError, webSQLErrback, createDOMException} from './DOMException.js';
|
|
5
5
|
import {IDBRequest} from './IDBRequest.js';
|
|
@@ -11,23 +11,101 @@ let uniqueID = 0;
|
|
|
11
11
|
const listeners = ['onabort', 'oncomplete', 'onerror'];
|
|
12
12
|
const readonlyProperties = ['objectStoreNames', 'mode', 'db', 'error'];
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {number} Integer
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {{
|
|
20
|
+
* op: SQLCallback,
|
|
21
|
+
* args: ObjectArray,
|
|
22
|
+
* req: import('./IDBRequest.js').IDBRequestFull|null
|
|
23
|
+
* }} RequestInfo
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {EventTarget & {
|
|
28
|
+
* mode: "readonly"|"readwrite"|"versionchange",
|
|
29
|
+
* db: import('./IDBDatabase.js').IDBDatabaseFull,
|
|
30
|
+
* on__abort: () => void,
|
|
31
|
+
* on__complete: () => void,
|
|
32
|
+
* on__beforecomplete: (ev: Event & {
|
|
33
|
+
* complete: () => void
|
|
34
|
+
* }) => void,
|
|
35
|
+
* on__preabort: () => void,
|
|
36
|
+
* __abortTransaction: (err: Error|DOMException|null) => void,
|
|
37
|
+
* __executeRequests: () => void,
|
|
38
|
+
* __tx: SQLTransaction,
|
|
39
|
+
* __id: Integer,
|
|
40
|
+
* __active: boolean,
|
|
41
|
+
* __running: boolean,
|
|
42
|
+
* __errored: boolean,
|
|
43
|
+
* __requests: RequestInfo[],
|
|
44
|
+
* __db: import('./IDBDatabase.js').IDBDatabaseFull,
|
|
45
|
+
* __mode: string,
|
|
46
|
+
* __error: null|DOMException|Error,
|
|
47
|
+
* __objectStoreNames: import('./DOMStringList.js').DOMStringListFull,
|
|
48
|
+
* __storeHandles: {
|
|
49
|
+
* [key: string]: import('./IDBObjectStore.js').IDBObjectStoreFull
|
|
50
|
+
* },
|
|
51
|
+
* __requestsFinished: boolean,
|
|
52
|
+
* __transFinishedCb: (err: boolean, cb: ((bool?: boolean) => void)) => void,
|
|
53
|
+
* __transactionEndCallback: () => void,
|
|
54
|
+
* __transactionFinished: boolean,
|
|
55
|
+
* __completed: boolean,
|
|
56
|
+
* __internal: boolean,
|
|
57
|
+
* __abortFinished: boolean,
|
|
58
|
+
* __createRequest: (
|
|
59
|
+
* source: import('./IDBDatabase.js').IDBDatabaseFull|
|
|
60
|
+
* import('./IDBObjectStore.js').IDBObjectStoreFull|
|
|
61
|
+
* import('./IDBIndex.js').IDBIndexFull|
|
|
62
|
+
* import('./IDBCursor.js').IDBCursorFull
|
|
63
|
+
* ) => import('./IDBRequest.js').IDBRequestFull,
|
|
64
|
+
* __pushToQueue: (
|
|
65
|
+
* request: import('./IDBRequest.js').IDBRequestFull|null,
|
|
66
|
+
* callback: SQLCallback,
|
|
67
|
+
* args?: ObjectArray
|
|
68
|
+
* ) => void,
|
|
69
|
+
* __assertActive: () => void,
|
|
70
|
+
* __addNonRequestToTransactionQueue: (
|
|
71
|
+
* callback: SQLCallback,
|
|
72
|
+
* args?: ObjectArray
|
|
73
|
+
* ) => void
|
|
74
|
+
* __addToTransactionQueue: (
|
|
75
|
+
* callback: SQLCallback,
|
|
76
|
+
* args: ObjectArray|undefined,
|
|
77
|
+
* source: import('./IDBDatabase.js').IDBDatabaseFull|
|
|
78
|
+
* import('./IDBObjectStore.js').IDBObjectStoreFull|
|
|
79
|
+
* import('./IDBIndex.js').IDBIndexFull|
|
|
80
|
+
* import('./IDBCursor.js').IDBCursorFull
|
|
81
|
+
* ) => import('./IDBRequest.js').IDBRequestFull
|
|
82
|
+
* __assertWritable: () => void,
|
|
83
|
+
* }} IDBTransactionFull
|
|
84
|
+
*/
|
|
85
|
+
|
|
15
86
|
/**
|
|
16
87
|
* The IndexedDB Transaction.
|
|
17
88
|
* @see http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#idl-def-IDBTransaction
|
|
18
|
-
* @param {IDBDatabase} db
|
|
19
|
-
* @param {string[]} storeNames
|
|
20
|
-
* @param {string} mode
|
|
21
89
|
* @class
|
|
22
90
|
*/
|
|
23
91
|
function IDBTransaction () {
|
|
24
|
-
/* eslint-enable jsdoc/check-param-names */
|
|
25
92
|
throw new TypeError('Illegal constructor');
|
|
26
93
|
}
|
|
27
94
|
const IDBTransactionAlias = IDBTransaction;
|
|
95
|
+
/**
|
|
96
|
+
* @param {import('./IDBDatabase.js').IDBDatabaseFull} db
|
|
97
|
+
* @param {import('./DOMStringList.js').DOMStringListFull} storeNames
|
|
98
|
+
* @param {string} mode
|
|
99
|
+
* @returns {IDBTransactionFull}
|
|
100
|
+
*/
|
|
28
101
|
IDBTransaction.__createInstance = function (db, storeNames, mode) {
|
|
102
|
+
/**
|
|
103
|
+
* @class
|
|
104
|
+
* @this {IDBTransactionFull}
|
|
105
|
+
*/
|
|
29
106
|
function IDBTransaction () {
|
|
30
107
|
const me = this;
|
|
108
|
+
// @ts-expect-error It's ok
|
|
31
109
|
me[Symbol.toStringTag] = 'IDBTransaction';
|
|
32
110
|
util.defineReadonlyProperties(me, readonlyProperties);
|
|
33
111
|
me.__id = ++uniqueID; // for debugging simultaneous transactions
|
|
@@ -39,6 +117,7 @@ IDBTransaction.__createInstance = function (db, storeNames, mode) {
|
|
|
39
117
|
me.__mode = mode;
|
|
40
118
|
me.__db = db;
|
|
41
119
|
me.__error = null;
|
|
120
|
+
// @ts-expect-error Part of `ShimEventTarget`
|
|
42
121
|
me.__setOptions({
|
|
43
122
|
legacyOutputDidListenersThrowFlag: true // Event hook for IndexedB
|
|
44
123
|
});
|
|
@@ -55,18 +134,31 @@ IDBTransaction.__createInstance = function (db, storeNames, mode) {
|
|
|
55
134
|
setTimeout(() => { me.__executeRequests(); }, 0);
|
|
56
135
|
}
|
|
57
136
|
IDBTransaction.prototype = IDBTransactionAlias.prototype;
|
|
137
|
+
|
|
138
|
+
// @ts-expect-error It's ok
|
|
58
139
|
return new IDBTransaction();
|
|
59
140
|
};
|
|
60
141
|
|
|
142
|
+
// @ts-expect-error It's ok
|
|
61
143
|
IDBTransaction.prototype = EventTargetFactory.createInstance({
|
|
62
144
|
defaultSync: true,
|
|
63
145
|
// Ensure EventTarget preserves our properties
|
|
64
146
|
extraProperties: ['complete']
|
|
65
147
|
});
|
|
66
148
|
|
|
149
|
+
/**
|
|
150
|
+
*
|
|
151
|
+
* @param {boolean} err
|
|
152
|
+
* @param {(bool: boolean) => void} cb
|
|
153
|
+
* @returns {void}
|
|
154
|
+
*/
|
|
67
155
|
IDBTransaction.prototype.__transFinishedCb = function (err, cb) {
|
|
68
156
|
cb(Boolean(err));
|
|
69
157
|
};
|
|
158
|
+
/**
|
|
159
|
+
* @this {IDBTransactionFull}
|
|
160
|
+
* @returns {void}
|
|
161
|
+
*/
|
|
70
162
|
IDBTransaction.prototype.__executeRequests = function () {
|
|
71
163
|
const me = this;
|
|
72
164
|
if (me.__running) {
|
|
@@ -79,8 +171,19 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
79
171
|
me.db.__db[me.mode === 'readonly' ? 'readTransaction' : 'transaction']( // `readTransaction` is optimized, at least in `node-websql`
|
|
80
172
|
function executeRequests (tx) {
|
|
81
173
|
me.__tx = tx;
|
|
82
|
-
|
|
83
|
-
|
|
174
|
+
/** @type {RequestInfo} */
|
|
175
|
+
let q,
|
|
176
|
+
i = -1;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @typedef {any} IDBRequestResult
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @param {IDBRequestResult} [result]
|
|
184
|
+
* @param {import('./IDBRequest.js').IDBRequestFull} [req]
|
|
185
|
+
* @returns {void}
|
|
186
|
+
*/
|
|
84
187
|
function success (result, req) {
|
|
85
188
|
if (me.__errored || me.__requestsFinished) {
|
|
86
189
|
// We've already called "onerror", "onabort", or thrown within the transaction, so don't do it again.
|
|
@@ -89,6 +192,9 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
89
192
|
if (req) {
|
|
90
193
|
q.req = req; // Need to do this in case of cursors
|
|
91
194
|
}
|
|
195
|
+
if (!q.req) { // TS guard
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
92
198
|
if (q.req.__done) { // Avoid continuing with aborted requests
|
|
93
199
|
return;
|
|
94
200
|
}
|
|
@@ -109,6 +215,10 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
109
215
|
executeNextRequest();
|
|
110
216
|
}
|
|
111
217
|
|
|
218
|
+
/**
|
|
219
|
+
* @param {[tx: SQLTransaction|DOMException|Error|SQLError, err?: SQLError]} args
|
|
220
|
+
* @returns {void}
|
|
221
|
+
*/
|
|
112
222
|
function error (...args /* tx, err */) {
|
|
113
223
|
if (me.__errored || me.__requestsFinished) {
|
|
114
224
|
// We've already called "onerror", "onabort", or thrown within
|
|
@@ -118,7 +228,7 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
118
228
|
if (q.req && q.req.__done) { // Avoid continuing with aborted requests
|
|
119
229
|
return;
|
|
120
230
|
}
|
|
121
|
-
const err = findError(args);
|
|
231
|
+
const err = /** @type {Error|DOMException} */ (findError(args));
|
|
122
232
|
if (!q.req) {
|
|
123
233
|
me.__abortTransaction(err);
|
|
124
234
|
return;
|
|
@@ -134,6 +244,9 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
134
244
|
}
|
|
135
245
|
});
|
|
136
246
|
q.req.addDefaultEventListener('error', function () {
|
|
247
|
+
if (!q.req) { // TS guard
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
137
250
|
me.__abortTransaction(q.req.__error);
|
|
138
251
|
});
|
|
139
252
|
|
|
@@ -148,6 +261,9 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
148
261
|
}
|
|
149
262
|
}
|
|
150
263
|
|
|
264
|
+
/**
|
|
265
|
+
* @returns {void}
|
|
266
|
+
*/
|
|
151
267
|
function executeNextRequest () {
|
|
152
268
|
if (me.__errored || me.__requestsFinished) {
|
|
153
269
|
// We've already called "onerror", "onabort", or thrown within the transaction, so don't do it again.
|
|
@@ -172,7 +288,7 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
172
288
|
}
|
|
173
289
|
q.op(tx, q.args, success, error, executeNextRequest);
|
|
174
290
|
} catch (e) {
|
|
175
|
-
error(e);
|
|
291
|
+
error(/** @type {Error} */ (e));
|
|
176
292
|
}
|
|
177
293
|
}
|
|
178
294
|
}
|
|
@@ -180,10 +296,11 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
180
296
|
executeNextRequest();
|
|
181
297
|
},
|
|
182
298
|
function webSQLError (webSQLErr) {
|
|
299
|
+
// @ts-expect-error It's ok
|
|
183
300
|
if (webSQLErr === true) { // Not a genuine SQL error
|
|
184
301
|
return;
|
|
185
302
|
}
|
|
186
|
-
const err = webSQLErrback(webSQLErr);
|
|
303
|
+
const err = webSQLErrback(/** @type {SQLError} */ (webSQLErr));
|
|
187
304
|
me.__abortTransaction(err);
|
|
188
305
|
},
|
|
189
306
|
function () {
|
|
@@ -219,10 +336,17 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
219
336
|
}
|
|
220
337
|
);
|
|
221
338
|
|
|
339
|
+
/**
|
|
340
|
+
* @returns {void}
|
|
341
|
+
*/
|
|
222
342
|
function requestsFinished () {
|
|
223
343
|
me.__active = false;
|
|
224
344
|
me.__requestsFinished = true;
|
|
225
345
|
|
|
346
|
+
/**
|
|
347
|
+
* @throws {Error}
|
|
348
|
+
* @returns {void}
|
|
349
|
+
*/
|
|
226
350
|
function complete () {
|
|
227
351
|
me.__completed = true;
|
|
228
352
|
CFG.DEBUG && console.log('Transaction completed');
|
|
@@ -255,7 +379,9 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
255
379
|
complete();
|
|
256
380
|
return;
|
|
257
381
|
}
|
|
258
|
-
const ev =
|
|
382
|
+
const ev = /** @type {Event & {complete: () => void}} */ (
|
|
383
|
+
createEvent('__beforecomplete')
|
|
384
|
+
);
|
|
259
385
|
ev.complete = complete;
|
|
260
386
|
me.dispatchEvent(ev);
|
|
261
387
|
}
|
|
@@ -264,9 +390,9 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
264
390
|
/**
|
|
265
391
|
* Creates a new IDBRequest for the transaction.
|
|
266
392
|
* NOTE: The transaction is not queued until you call {@link IDBTransaction#__pushToQueue}.
|
|
267
|
-
* @param {IDBDatabase} source
|
|
393
|
+
* @param {import('./IDBDatabase.js').IDBDatabaseFull} source
|
|
394
|
+
* @this {IDBTransactionFull}
|
|
268
395
|
* @returns {IDBRequest}
|
|
269
|
-
* @protected
|
|
270
396
|
*/
|
|
271
397
|
IDBTransaction.prototype.__createRequest = function (source) {
|
|
272
398
|
const me = this;
|
|
@@ -276,13 +402,25 @@ IDBTransaction.prototype.__createRequest = function (source) {
|
|
|
276
402
|
return request;
|
|
277
403
|
};
|
|
278
404
|
|
|
405
|
+
/**
|
|
406
|
+
* @typedef {(
|
|
407
|
+
* tx: SQLTransaction,
|
|
408
|
+
* args: ObjectArray,
|
|
409
|
+
* success: (result?: any, req?: import('./IDBRequest.js').IDBRequestFull) => void,
|
|
410
|
+
* error: (tx: SQLTransaction|Error|DOMException|SQLError, err?: SQLError) => void,
|
|
411
|
+
* executeNextRequest?: () => void
|
|
412
|
+
* ) => void} SQLCallback
|
|
413
|
+
*/
|
|
414
|
+
|
|
279
415
|
/**
|
|
280
416
|
* Adds a callback function to the transaction queue.
|
|
281
|
-
* @param {
|
|
282
|
-
* @param {
|
|
283
|
-
* @param {IDBDatabase
|
|
284
|
-
*
|
|
285
|
-
*
|
|
417
|
+
* @param {SQLCallback} callback
|
|
418
|
+
* @param {ObjectArray} args
|
|
419
|
+
* @param {import('./IDBDatabase.js').IDBDatabaseFull|
|
|
420
|
+
* import('./IDBObjectStore.js').IDBObjectStoreFull|
|
|
421
|
+
* import('./IDBIndex.js').IDBIndexFull} source
|
|
422
|
+
* @this {IDBTransactionFull}
|
|
423
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
286
424
|
*/
|
|
287
425
|
IDBTransaction.prototype.__addToTransactionQueue = function (callback, args, source) {
|
|
288
426
|
const request = this.__createRequest(source);
|
|
@@ -293,22 +431,21 @@ IDBTransaction.prototype.__addToTransactionQueue = function (callback, args, sou
|
|
|
293
431
|
/**
|
|
294
432
|
* Adds a callback function to the transaction queue without generating a
|
|
295
433
|
* request.
|
|
296
|
-
* @param {
|
|
297
|
-
* @param {
|
|
298
|
-
* @
|
|
434
|
+
* @param {SQLCallback} callback
|
|
435
|
+
* @param {ObjectArray} args
|
|
436
|
+
* @this {IDBTransactionFull}
|
|
299
437
|
* @returns {void}
|
|
300
|
-
* @protected
|
|
301
438
|
*/
|
|
302
|
-
IDBTransaction.prototype.__addNonRequestToTransactionQueue = function (callback, args
|
|
439
|
+
IDBTransaction.prototype.__addNonRequestToTransactionQueue = function (callback, args) {
|
|
303
440
|
this.__pushToQueue(null, callback, args);
|
|
304
441
|
};
|
|
305
442
|
|
|
306
443
|
/**
|
|
307
444
|
* Adds an IDBRequest to the transaction queue.
|
|
308
|
-
* @param {IDBRequest} request
|
|
309
|
-
* @param {
|
|
310
|
-
* @param {
|
|
311
|
-
* @
|
|
445
|
+
* @param {import('./IDBRequest.js').IDBRequestFull|null} request
|
|
446
|
+
* @param {SQLCallback} callback
|
|
447
|
+
* @param {ObjectArray} args
|
|
448
|
+
* @this {IDBTransactionFull}
|
|
312
449
|
* @returns {void}
|
|
313
450
|
*/
|
|
314
451
|
IDBTransaction.prototype.__pushToQueue = function (request, callback, args) {
|
|
@@ -320,18 +457,31 @@ IDBTransaction.prototype.__pushToQueue = function (request, callback, args) {
|
|
|
320
457
|
});
|
|
321
458
|
};
|
|
322
459
|
|
|
460
|
+
/**
|
|
461
|
+
* @throws {DOMException}
|
|
462
|
+
* @returns {void}
|
|
463
|
+
*/
|
|
323
464
|
IDBTransaction.prototype.__assertActive = function () {
|
|
324
465
|
if (!this.__active) {
|
|
325
466
|
throw createDOMException('TransactionInactiveError', 'A request was placed against a transaction which is currently not active, or which is finished');
|
|
326
467
|
}
|
|
327
468
|
};
|
|
328
469
|
|
|
470
|
+
/**
|
|
471
|
+
* @throws {DOMException}
|
|
472
|
+
* @this {IDBTransactionFull}
|
|
473
|
+
* @returns {void}
|
|
474
|
+
*/
|
|
329
475
|
IDBTransaction.prototype.__assertWritable = function () {
|
|
330
476
|
if (this.mode === 'readonly') {
|
|
331
477
|
throw createDOMException('ReadOnlyError', 'The transaction is read only');
|
|
332
478
|
}
|
|
333
479
|
};
|
|
334
480
|
|
|
481
|
+
/**
|
|
482
|
+
* @this {IDBTransactionFull}
|
|
483
|
+
* @returns {void}
|
|
484
|
+
*/
|
|
335
485
|
IDBTransaction.prototype.__assertVersionChange = function () {
|
|
336
486
|
IDBTransaction.__assertVersionChange(this);
|
|
337
487
|
};
|
|
@@ -339,6 +489,7 @@ IDBTransaction.prototype.__assertVersionChange = function () {
|
|
|
339
489
|
/**
|
|
340
490
|
* Returns the specified object store.
|
|
341
491
|
* @param {string} objectStoreName
|
|
492
|
+
* @this {IDBTransactionFull}
|
|
342
493
|
* @returns {IDBObjectStore}
|
|
343
494
|
*/
|
|
344
495
|
IDBTransaction.prototype.objectStore = function (objectStoreName) {
|
|
@@ -368,6 +519,12 @@ IDBTransaction.prototype.objectStore = function (objectStoreName) {
|
|
|
368
519
|
return me.__storeHandles[objectStoreName];
|
|
369
520
|
};
|
|
370
521
|
|
|
522
|
+
/**
|
|
523
|
+
*
|
|
524
|
+
* @param {Error|DOMException|null} err
|
|
525
|
+
* @this {IDBTransactionFull}
|
|
526
|
+
* @returns {void}
|
|
527
|
+
*/
|
|
371
528
|
IDBTransaction.prototype.__abortTransaction = function (err) {
|
|
372
529
|
const me = this;
|
|
373
530
|
logError('Error', 'An error occurred in a transaction', err);
|
|
@@ -419,10 +576,15 @@ IDBTransaction.prototype.__abortTransaction = function (err) {
|
|
|
419
576
|
}, 0);
|
|
420
577
|
}
|
|
421
578
|
|
|
579
|
+
/**
|
|
580
|
+
* @param {SQLTransaction|null} [tx]
|
|
581
|
+
* @param {SQLResultSet|SQLError|{code: 0}} [errOrResult]
|
|
582
|
+
* @returns {void}
|
|
583
|
+
*/
|
|
422
584
|
function abort (tx, errOrResult) {
|
|
423
585
|
if (!tx) {
|
|
424
586
|
CFG.DEBUG && console.log('Rollback not possible due to missing transaction', me);
|
|
425
|
-
} else if (errOrResult && typeof errOrResult.code === 'number') {
|
|
587
|
+
} else if (errOrResult && 'code' in errOrResult && typeof errOrResult.code === 'number') {
|
|
426
588
|
CFG.DEBUG && console.log('Rollback erred; feature is probably not supported as per WebSQL', me);
|
|
427
589
|
} else {
|
|
428
590
|
CFG.DEBUG && console.log('Rollback succeeded', me);
|
|
@@ -439,18 +601,27 @@ IDBTransaction.prototype.__abortTransaction = function (err) {
|
|
|
439
601
|
// behaves first-in-first-out with the same timeout so we could
|
|
440
602
|
// just use a `forEach`.
|
|
441
603
|
return promises.then(function () {
|
|
604
|
+
if (!q.req) { // TS guard
|
|
605
|
+
throw new Error('Missing request');
|
|
606
|
+
}
|
|
442
607
|
q.req.__done = true;
|
|
443
608
|
q.req.__result = undefined;
|
|
444
609
|
q.req.__error = createDOMException('AbortError', 'A request was aborted (an unfinished request).');
|
|
445
610
|
const reqEvt = createEvent('error', q.req.__error, {bubbles: true, cancelable: true});
|
|
446
|
-
return new SyncPromise(
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
611
|
+
return new SyncPromise(
|
|
612
|
+
/** @type {() => void} */
|
|
613
|
+
(resolve) => {
|
|
614
|
+
setTimeout(() => {
|
|
615
|
+
if (!q.req) { // TS guard
|
|
616
|
+
throw new Error('Missing request');
|
|
617
|
+
}
|
|
618
|
+
q.req.dispatchEvent(reqEvt); // No need to catch errors
|
|
619
|
+
resolve();
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
);
|
|
452
623
|
});
|
|
453
|
-
}, SyncPromise.resolve()).then(function () { // Also works when there are no pending requests
|
|
624
|
+
}, SyncPromise.resolve(undefined)).then(function () { // Also works when there are no pending requests
|
|
454
625
|
const evt = createEvent('abort', err, {bubbles: true, cancelable: false});
|
|
455
626
|
setTimeout(() => {
|
|
456
627
|
me.__abortFinished = true;
|
|
@@ -478,7 +649,12 @@ IDBTransaction.prototype.__abortTransaction = function (err) {
|
|
|
478
649
|
return;
|
|
479
650
|
}
|
|
480
651
|
try {
|
|
481
|
-
me.__tx.executeSql(
|
|
652
|
+
me.__tx.executeSql(
|
|
653
|
+
'ROLLBACK',
|
|
654
|
+
[],
|
|
655
|
+
abort,
|
|
656
|
+
/** @type {SQLStatementErrorCallback} */ (abort)
|
|
657
|
+
); // Not working in some circumstances, even in Node
|
|
482
658
|
} catch (err) {
|
|
483
659
|
// Browser errs when transaction has ended and since it most likely already erred here,
|
|
484
660
|
// we call to abort
|
|
@@ -490,6 +666,10 @@ IDBTransaction.prototype.__abortTransaction = function (err) {
|
|
|
490
666
|
});
|
|
491
667
|
};
|
|
492
668
|
|
|
669
|
+
/**
|
|
670
|
+
* @this {IDBTransactionFull}
|
|
671
|
+
* @returns {void}
|
|
672
|
+
*/
|
|
493
673
|
IDBTransaction.prototype.abort = function () {
|
|
494
674
|
const me = this;
|
|
495
675
|
if (!(me instanceof IDBTransaction)) {
|
|
@@ -502,17 +682,34 @@ IDBTransaction.prototype.abort = function () {
|
|
|
502
682
|
|
|
503
683
|
IDBTransaction.prototype[Symbol.toStringTag] = 'IDBTransactionPrototype';
|
|
504
684
|
|
|
685
|
+
/**
|
|
686
|
+
*
|
|
687
|
+
* @param {IDBTransactionFull|undefined} tx
|
|
688
|
+
* @returns {void}
|
|
689
|
+
*/
|
|
505
690
|
IDBTransaction.__assertVersionChange = function (tx) {
|
|
506
691
|
if (!tx || tx.mode !== 'versionchange') {
|
|
507
692
|
throw createDOMException('InvalidStateError', 'Not a version transaction');
|
|
508
693
|
}
|
|
509
694
|
};
|
|
695
|
+
/**
|
|
696
|
+
*
|
|
697
|
+
* @param {IDBTransactionFull} tx
|
|
698
|
+
* @throws {DOMException}
|
|
699
|
+
* @returns {void}
|
|
700
|
+
*/
|
|
510
701
|
IDBTransaction.__assertNotVersionChange = function (tx) {
|
|
511
702
|
if (tx && tx.mode === 'versionchange') {
|
|
512
703
|
throw createDOMException('InvalidStateError', 'Cannot be called during a version transaction');
|
|
513
704
|
}
|
|
514
705
|
};
|
|
515
706
|
|
|
707
|
+
/**
|
|
708
|
+
*
|
|
709
|
+
* @param {IDBTransactionFull|undefined} tx
|
|
710
|
+
* @throws {DOMException}
|
|
711
|
+
* @returns {void}
|
|
712
|
+
*/
|
|
516
713
|
IDBTransaction.__assertNotFinished = function (tx) {
|
|
517
714
|
if (!tx || tx.__completed || tx.__abortFinished || tx.__errored) {
|
|
518
715
|
throw createDOMException('InvalidStateError', 'Transaction finished by commit or abort');
|
|
@@ -520,6 +717,11 @@ IDBTransaction.__assertNotFinished = function (tx) {
|
|
|
520
717
|
};
|
|
521
718
|
|
|
522
719
|
// object store methods behave differently: see https://github.com/w3c/IndexedDB/issues/192
|
|
720
|
+
/**
|
|
721
|
+
*
|
|
722
|
+
* @param {IDBTransactionFull} tx
|
|
723
|
+
* @returns {void}
|
|
724
|
+
*/
|
|
523
725
|
IDBTransaction.__assertNotFinishedObjectStoreMethod = function (tx) {
|
|
524
726
|
try {
|
|
525
727
|
IDBTransaction.__assertNotFinished(tx);
|
|
@@ -531,6 +733,12 @@ IDBTransaction.__assertNotFinishedObjectStoreMethod = function (tx) {
|
|
|
531
733
|
}
|
|
532
734
|
};
|
|
533
735
|
|
|
736
|
+
/**
|
|
737
|
+
*
|
|
738
|
+
* @param {IDBTransactionFull|undefined} tx
|
|
739
|
+
* @throws {DOMException}
|
|
740
|
+
* @returns {void}
|
|
741
|
+
*/
|
|
534
742
|
IDBTransaction.__assertActive = function (tx) {
|
|
535
743
|
if (!tx || !tx.__active) {
|
|
536
744
|
throw createDOMException('TransactionInactiveError', 'A request was placed against a transaction which is currently not active, or which is finished');
|
|
@@ -539,7 +747,8 @@ IDBTransaction.__assertActive = function (tx) {
|
|
|
539
747
|
|
|
540
748
|
/**
|
|
541
749
|
* Used by our `EventTarget.prototype` library to implement bubbling/capturing.
|
|
542
|
-
* @
|
|
750
|
+
* @this {IDBTransactionFull}
|
|
751
|
+
* @returns {import('./IDBDatabase.js').IDBDatabaseFull}
|
|
543
752
|
*/
|
|
544
753
|
IDBTransaction.prototype.__getParent = function () {
|
|
545
754
|
return this.db;
|