indexeddbshim 12.0.0 → 13.0.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/README.md +1 -1
- package/badges/licenses-badge-dev.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 +288 -0
- package/dist/IDBCursor.d.ts.map +1 -0
- package/dist/IDBDatabase.d.ts +143 -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 +88 -0
- package/dist/IDBRequest.d.ts.map +1 -0
- package/dist/IDBTransaction.d.ts +270 -0
- package/dist/IDBTransaction.d.ts.map +1 -0
- package/dist/IDBVersionChangeEvent.d.ts +22 -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 +553 -252
- 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 +17560 -1302
- package/dist/indexeddbshim-UnicodeIdentifiers-node.cjs.map +1 -1
- package/dist/indexeddbshim-UnicodeIdentifiers.js +4367 -1604
- 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 +17556 -1302
- package/dist/indexeddbshim-node.cjs.map +1 -1
- package/dist/indexeddbshim-noninvasive.js +4362 -1604
- 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 +4362 -1604
- 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/index.html +1 -1
- package/package.json +51 -37
- package/src/CFG.js +89 -11
- package/src/DOMException.js +117 -31
- package/src/DOMStringList.js +93 -3
- package/src/Event.js +19 -4
- package/src/IDBCursor.js +350 -76
- package/src/IDBDatabase.js +88 -10
- package/src/IDBFactory.js +331 -61
- package/src/IDBIndex.js +393 -110
- package/src/IDBKeyRange.js +90 -17
- package/src/IDBObjectStore.js +347 -86
- package/src/IDBRequest.js +59 -1
- package/src/IDBTransaction.js +254 -46
- package/src/IDBVersionChangeEvent.js +28 -3
- package/src/Key.d.ts +1 -0
- package/src/Key.js +272 -162
- 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 +159 -22
- package/src/unicode-regex.js +2 -0
- package/src/util.js +229 -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,22 +134,36 @@ 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({
|
|
144
|
+
// eslint-disable-next-line n/no-sync -- API
|
|
62
145
|
defaultSync: true,
|
|
63
146
|
// Ensure EventTarget preserves our properties
|
|
64
147
|
extraProperties: ['complete']
|
|
65
148
|
});
|
|
66
149
|
|
|
150
|
+
/**
|
|
151
|
+
*
|
|
152
|
+
* @param {boolean} err
|
|
153
|
+
* @param {(bool: boolean) => void} cb
|
|
154
|
+
* @returns {void}
|
|
155
|
+
*/
|
|
67
156
|
IDBTransaction.prototype.__transFinishedCb = function (err, cb) {
|
|
68
157
|
cb(Boolean(err));
|
|
69
158
|
};
|
|
159
|
+
/**
|
|
160
|
+
* @this {IDBTransactionFull}
|
|
161
|
+
* @returns {void}
|
|
162
|
+
*/
|
|
70
163
|
IDBTransaction.prototype.__executeRequests = function () {
|
|
71
164
|
const me = this;
|
|
72
165
|
if (me.__running) {
|
|
73
|
-
CFG.DEBUG
|
|
166
|
+
if (CFG.DEBUG) { console.log('Looks like the request set is already running', me.mode); }
|
|
74
167
|
return;
|
|
75
168
|
}
|
|
76
169
|
|
|
@@ -79,8 +172,19 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
79
172
|
me.db.__db[me.mode === 'readonly' ? 'readTransaction' : 'transaction']( // `readTransaction` is optimized, at least in `node-websql`
|
|
80
173
|
function executeRequests (tx) {
|
|
81
174
|
me.__tx = tx;
|
|
82
|
-
|
|
83
|
-
|
|
175
|
+
/** @type {RequestInfo} */
|
|
176
|
+
let q,
|
|
177
|
+
i = -1;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @typedef {any} IDBRequestResult
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @param {IDBRequestResult} [result]
|
|
185
|
+
* @param {import('./IDBRequest.js').IDBRequestFull} [req]
|
|
186
|
+
* @returns {void}
|
|
187
|
+
*/
|
|
84
188
|
function success (result, req) {
|
|
85
189
|
if (me.__errored || me.__requestsFinished) {
|
|
86
190
|
// We've already called "onerror", "onabort", or thrown within the transaction, so don't do it again.
|
|
@@ -89,6 +193,9 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
89
193
|
if (req) {
|
|
90
194
|
q.req = req; // Need to do this in case of cursors
|
|
91
195
|
}
|
|
196
|
+
if (!q.req) { // TS guard
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
92
199
|
if (q.req.__done) { // Avoid continuing with aborted requests
|
|
93
200
|
return;
|
|
94
201
|
}
|
|
@@ -109,6 +216,10 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
109
216
|
executeNextRequest();
|
|
110
217
|
}
|
|
111
218
|
|
|
219
|
+
/**
|
|
220
|
+
* @param {[tx: SQLTransaction|DOMException|Error|SQLError, err?: SQLError]} args
|
|
221
|
+
* @returns {void}
|
|
222
|
+
*/
|
|
112
223
|
function error (...args /* tx, err */) {
|
|
113
224
|
if (me.__errored || me.__requestsFinished) {
|
|
114
225
|
// We've already called "onerror", "onabort", or thrown within
|
|
@@ -118,7 +229,7 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
118
229
|
if (q.req && q.req.__done) { // Avoid continuing with aborted requests
|
|
119
230
|
return;
|
|
120
231
|
}
|
|
121
|
-
const err = findError(args);
|
|
232
|
+
const err = /** @type {Error|DOMException} */ (findError(args));
|
|
122
233
|
if (!q.req) {
|
|
123
234
|
me.__abortTransaction(err);
|
|
124
235
|
return;
|
|
@@ -134,6 +245,9 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
134
245
|
}
|
|
135
246
|
});
|
|
136
247
|
q.req.addDefaultEventListener('error', function () {
|
|
248
|
+
if (!q.req) { // TS guard
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
137
251
|
me.__abortTransaction(q.req.__error);
|
|
138
252
|
});
|
|
139
253
|
|
|
@@ -148,6 +262,9 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
148
262
|
}
|
|
149
263
|
}
|
|
150
264
|
|
|
265
|
+
/**
|
|
266
|
+
* @returns {void}
|
|
267
|
+
*/
|
|
151
268
|
function executeNextRequest () {
|
|
152
269
|
if (me.__errored || me.__requestsFinished) {
|
|
153
270
|
// We've already called "onerror", "onabort", or thrown within the transaction, so don't do it again.
|
|
@@ -172,7 +289,7 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
172
289
|
}
|
|
173
290
|
q.op(tx, q.args, success, error, executeNextRequest);
|
|
174
291
|
} catch (e) {
|
|
175
|
-
error(e);
|
|
292
|
+
error(/** @type {Error} */ (e));
|
|
176
293
|
}
|
|
177
294
|
}
|
|
178
295
|
}
|
|
@@ -180,10 +297,11 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
180
297
|
executeNextRequest();
|
|
181
298
|
},
|
|
182
299
|
function webSQLError (webSQLErr) {
|
|
300
|
+
// @ts-expect-error It's ok
|
|
183
301
|
if (webSQLErr === true) { // Not a genuine SQL error
|
|
184
302
|
return;
|
|
185
303
|
}
|
|
186
|
-
const err = webSQLErrback(webSQLErr);
|
|
304
|
+
const err = webSQLErrback(/** @type {SQLError} */ (webSQLErr));
|
|
187
305
|
me.__abortTransaction(err);
|
|
188
306
|
},
|
|
189
307
|
function () {
|
|
@@ -219,13 +337,20 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
219
337
|
}
|
|
220
338
|
);
|
|
221
339
|
|
|
340
|
+
/**
|
|
341
|
+
* @returns {void}
|
|
342
|
+
*/
|
|
222
343
|
function requestsFinished () {
|
|
223
344
|
me.__active = false;
|
|
224
345
|
me.__requestsFinished = true;
|
|
225
346
|
|
|
347
|
+
/**
|
|
348
|
+
* @throws {Error}
|
|
349
|
+
* @returns {void}
|
|
350
|
+
*/
|
|
226
351
|
function complete () {
|
|
227
352
|
me.__completed = true;
|
|
228
|
-
CFG.DEBUG
|
|
353
|
+
if (CFG.DEBUG) { console.log('Transaction completed'); }
|
|
229
354
|
const evt = createEvent('complete');
|
|
230
355
|
try {
|
|
231
356
|
me.__internal = true;
|
|
@@ -255,7 +380,9 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
255
380
|
complete();
|
|
256
381
|
return;
|
|
257
382
|
}
|
|
258
|
-
const ev =
|
|
383
|
+
const ev = /** @type {Event & {complete: () => void}} */ (
|
|
384
|
+
createEvent('__beforecomplete')
|
|
385
|
+
);
|
|
259
386
|
ev.complete = complete;
|
|
260
387
|
me.dispatchEvent(ev);
|
|
261
388
|
}
|
|
@@ -264,9 +391,9 @@ IDBTransaction.prototype.__executeRequests = function () {
|
|
|
264
391
|
/**
|
|
265
392
|
* Creates a new IDBRequest for the transaction.
|
|
266
393
|
* NOTE: The transaction is not queued until you call {@link IDBTransaction#__pushToQueue}.
|
|
267
|
-
* @param {IDBDatabase} source
|
|
394
|
+
* @param {import('./IDBDatabase.js').IDBDatabaseFull} source
|
|
395
|
+
* @this {IDBTransactionFull}
|
|
268
396
|
* @returns {IDBRequest}
|
|
269
|
-
* @protected
|
|
270
397
|
*/
|
|
271
398
|
IDBTransaction.prototype.__createRequest = function (source) {
|
|
272
399
|
const me = this;
|
|
@@ -276,13 +403,25 @@ IDBTransaction.prototype.__createRequest = function (source) {
|
|
|
276
403
|
return request;
|
|
277
404
|
};
|
|
278
405
|
|
|
406
|
+
/**
|
|
407
|
+
* @typedef {(
|
|
408
|
+
* tx: SQLTransaction,
|
|
409
|
+
* args: ObjectArray,
|
|
410
|
+
* success: (result?: any, req?: import('./IDBRequest.js').IDBRequestFull) => void,
|
|
411
|
+
* error: (tx: SQLTransaction|Error|DOMException|SQLError, err?: SQLError) => void,
|
|
412
|
+
* executeNextRequest?: () => void
|
|
413
|
+
* ) => void} SQLCallback
|
|
414
|
+
*/
|
|
415
|
+
|
|
279
416
|
/**
|
|
280
417
|
* Adds a callback function to the transaction queue.
|
|
281
|
-
* @param {
|
|
282
|
-
* @param {
|
|
283
|
-
* @param {IDBDatabase
|
|
284
|
-
*
|
|
285
|
-
*
|
|
418
|
+
* @param {SQLCallback} callback
|
|
419
|
+
* @param {ObjectArray} args
|
|
420
|
+
* @param {import('./IDBDatabase.js').IDBDatabaseFull|
|
|
421
|
+
* import('./IDBObjectStore.js').IDBObjectStoreFull|
|
|
422
|
+
* import('./IDBIndex.js').IDBIndexFull} source
|
|
423
|
+
* @this {IDBTransactionFull}
|
|
424
|
+
* @returns {import('./IDBRequest.js').IDBRequestFull}
|
|
286
425
|
*/
|
|
287
426
|
IDBTransaction.prototype.__addToTransactionQueue = function (callback, args, source) {
|
|
288
427
|
const request = this.__createRequest(source);
|
|
@@ -293,22 +432,21 @@ IDBTransaction.prototype.__addToTransactionQueue = function (callback, args, sou
|
|
|
293
432
|
/**
|
|
294
433
|
* Adds a callback function to the transaction queue without generating a
|
|
295
434
|
* request.
|
|
296
|
-
* @param {
|
|
297
|
-
* @param {
|
|
298
|
-
* @
|
|
435
|
+
* @param {SQLCallback} callback
|
|
436
|
+
* @param {ObjectArray} args
|
|
437
|
+
* @this {IDBTransactionFull}
|
|
299
438
|
* @returns {void}
|
|
300
|
-
* @protected
|
|
301
439
|
*/
|
|
302
|
-
IDBTransaction.prototype.__addNonRequestToTransactionQueue = function (callback, args
|
|
440
|
+
IDBTransaction.prototype.__addNonRequestToTransactionQueue = function (callback, args) {
|
|
303
441
|
this.__pushToQueue(null, callback, args);
|
|
304
442
|
};
|
|
305
443
|
|
|
306
444
|
/**
|
|
307
445
|
* Adds an IDBRequest to the transaction queue.
|
|
308
|
-
* @param {IDBRequest} request
|
|
309
|
-
* @param {
|
|
310
|
-
* @param {
|
|
311
|
-
* @
|
|
446
|
+
* @param {import('./IDBRequest.js').IDBRequestFull|null} request
|
|
447
|
+
* @param {SQLCallback} callback
|
|
448
|
+
* @param {ObjectArray} args
|
|
449
|
+
* @this {IDBTransactionFull}
|
|
312
450
|
* @returns {void}
|
|
313
451
|
*/
|
|
314
452
|
IDBTransaction.prototype.__pushToQueue = function (request, callback, args) {
|
|
@@ -320,18 +458,31 @@ IDBTransaction.prototype.__pushToQueue = function (request, callback, args) {
|
|
|
320
458
|
});
|
|
321
459
|
};
|
|
322
460
|
|
|
461
|
+
/**
|
|
462
|
+
* @throws {DOMException}
|
|
463
|
+
* @returns {void}
|
|
464
|
+
*/
|
|
323
465
|
IDBTransaction.prototype.__assertActive = function () {
|
|
324
466
|
if (!this.__active) {
|
|
325
467
|
throw createDOMException('TransactionInactiveError', 'A request was placed against a transaction which is currently not active, or which is finished');
|
|
326
468
|
}
|
|
327
469
|
};
|
|
328
470
|
|
|
471
|
+
/**
|
|
472
|
+
* @throws {DOMException}
|
|
473
|
+
* @this {IDBTransactionFull}
|
|
474
|
+
* @returns {void}
|
|
475
|
+
*/
|
|
329
476
|
IDBTransaction.prototype.__assertWritable = function () {
|
|
330
477
|
if (this.mode === 'readonly') {
|
|
331
478
|
throw createDOMException('ReadOnlyError', 'The transaction is read only');
|
|
332
479
|
}
|
|
333
480
|
};
|
|
334
481
|
|
|
482
|
+
/**
|
|
483
|
+
* @this {IDBTransactionFull}
|
|
484
|
+
* @returns {void}
|
|
485
|
+
*/
|
|
335
486
|
IDBTransaction.prototype.__assertVersionChange = function () {
|
|
336
487
|
IDBTransaction.__assertVersionChange(this);
|
|
337
488
|
};
|
|
@@ -339,6 +490,7 @@ IDBTransaction.prototype.__assertVersionChange = function () {
|
|
|
339
490
|
/**
|
|
340
491
|
* Returns the specified object store.
|
|
341
492
|
* @param {string} objectStoreName
|
|
493
|
+
* @this {IDBTransactionFull}
|
|
342
494
|
* @returns {IDBObjectStore}
|
|
343
495
|
*/
|
|
344
496
|
IDBTransaction.prototype.objectStore = function (objectStoreName) {
|
|
@@ -368,6 +520,12 @@ IDBTransaction.prototype.objectStore = function (objectStoreName) {
|
|
|
368
520
|
return me.__storeHandles[objectStoreName];
|
|
369
521
|
};
|
|
370
522
|
|
|
523
|
+
/**
|
|
524
|
+
*
|
|
525
|
+
* @param {Error|DOMException|null} err
|
|
526
|
+
* @this {IDBTransactionFull}
|
|
527
|
+
* @returns {void}
|
|
528
|
+
*/
|
|
371
529
|
IDBTransaction.prototype.__abortTransaction = function (err) {
|
|
372
530
|
const me = this;
|
|
373
531
|
logError('Error', 'An error occurred in a transaction', err);
|
|
@@ -419,14 +577,17 @@ IDBTransaction.prototype.__abortTransaction = function (err) {
|
|
|
419
577
|
}, 0);
|
|
420
578
|
}
|
|
421
579
|
|
|
580
|
+
/**
|
|
581
|
+
* @param {SQLTransaction|null} [tx]
|
|
582
|
+
* @param {SQLResultSet|SQLError|{code: 0}} [errOrResult]
|
|
583
|
+
* @returns {void}
|
|
584
|
+
*/
|
|
422
585
|
function abort (tx, errOrResult) {
|
|
423
586
|
if (!tx) {
|
|
424
|
-
CFG.DEBUG
|
|
425
|
-
} else if (errOrResult && typeof errOrResult.code === 'number') {
|
|
426
|
-
CFG.DEBUG
|
|
427
|
-
} else {
|
|
428
|
-
CFG.DEBUG && console.log('Rollback succeeded', me);
|
|
429
|
-
}
|
|
587
|
+
if (CFG.DEBUG) { console.log('Rollback not possible due to missing transaction', me); }
|
|
588
|
+
} else if (errOrResult && 'code' in errOrResult && typeof errOrResult.code === 'number') {
|
|
589
|
+
if (CFG.DEBUG) { console.log('Rollback erred; feature is probably not supported as per WebSQL', me); }
|
|
590
|
+
} else if (CFG.DEBUG) { console.log('Rollback succeeded', me); }
|
|
430
591
|
|
|
431
592
|
me.dispatchEvent(createEvent('__preabort'));
|
|
432
593
|
me.__requests.filter(function (q, i, arr) { // eslint-disable-line promise/no-promise-in-callback
|
|
@@ -439,18 +600,27 @@ IDBTransaction.prototype.__abortTransaction = function (err) {
|
|
|
439
600
|
// behaves first-in-first-out with the same timeout so we could
|
|
440
601
|
// just use a `forEach`.
|
|
441
602
|
return promises.then(function () {
|
|
603
|
+
if (!q.req) { // TS guard
|
|
604
|
+
throw new Error('Missing request');
|
|
605
|
+
}
|
|
442
606
|
q.req.__done = true;
|
|
443
607
|
q.req.__result = undefined;
|
|
444
608
|
q.req.__error = createDOMException('AbortError', 'A request was aborted (an unfinished request).');
|
|
445
609
|
const reqEvt = createEvent('error', q.req.__error, {bubbles: true, cancelable: true});
|
|
446
|
-
return new SyncPromise(
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
610
|
+
return new SyncPromise(
|
|
611
|
+
/** @type {() => void} */
|
|
612
|
+
(resolve) => {
|
|
613
|
+
setTimeout(() => {
|
|
614
|
+
if (!q.req) { // TS guard
|
|
615
|
+
throw new Error('Missing request');
|
|
616
|
+
}
|
|
617
|
+
q.req.dispatchEvent(reqEvt); // No need to catch errors
|
|
618
|
+
resolve();
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
);
|
|
452
622
|
});
|
|
453
|
-
}, SyncPromise.resolve()).then(function () { // Also works when there are no pending requests
|
|
623
|
+
}, SyncPromise.resolve(undefined)).then(function () { // Also works when there are no pending requests
|
|
454
624
|
const evt = createEvent('abort', err, {bubbles: true, cancelable: false});
|
|
455
625
|
setTimeout(() => {
|
|
456
626
|
me.__abortFinished = true;
|
|
@@ -478,7 +648,12 @@ IDBTransaction.prototype.__abortTransaction = function (err) {
|
|
|
478
648
|
return;
|
|
479
649
|
}
|
|
480
650
|
try {
|
|
481
|
-
me.__tx.executeSql(
|
|
651
|
+
me.__tx.executeSql(
|
|
652
|
+
'ROLLBACK',
|
|
653
|
+
[],
|
|
654
|
+
abort,
|
|
655
|
+
/** @type {SQLStatementErrorCallback} */ (abort)
|
|
656
|
+
); // Not working in some circumstances, even in Node
|
|
482
657
|
} catch (err) {
|
|
483
658
|
// Browser errs when transaction has ended and since it most likely already erred here,
|
|
484
659
|
// we call to abort
|
|
@@ -490,29 +665,50 @@ IDBTransaction.prototype.__abortTransaction = function (err) {
|
|
|
490
665
|
});
|
|
491
666
|
};
|
|
492
667
|
|
|
668
|
+
/**
|
|
669
|
+
* @this {IDBTransactionFull}
|
|
670
|
+
* @returns {void}
|
|
671
|
+
*/
|
|
493
672
|
IDBTransaction.prototype.abort = function () {
|
|
494
673
|
const me = this;
|
|
495
674
|
if (!(me instanceof IDBTransaction)) {
|
|
496
675
|
throw new TypeError('Illegal invocation');
|
|
497
676
|
}
|
|
498
|
-
CFG.DEBUG
|
|
677
|
+
if (CFG.DEBUG) { console.log('The transaction was aborted', me); }
|
|
499
678
|
IDBTransaction.__assertNotFinished(me);
|
|
500
679
|
me.__abortTransaction(null);
|
|
501
680
|
};
|
|
502
681
|
|
|
503
682
|
IDBTransaction.prototype[Symbol.toStringTag] = 'IDBTransactionPrototype';
|
|
504
683
|
|
|
684
|
+
/**
|
|
685
|
+
*
|
|
686
|
+
* @param {IDBTransactionFull|undefined} tx
|
|
687
|
+
* @returns {void}
|
|
688
|
+
*/
|
|
505
689
|
IDBTransaction.__assertVersionChange = function (tx) {
|
|
506
690
|
if (!tx || tx.mode !== 'versionchange') {
|
|
507
691
|
throw createDOMException('InvalidStateError', 'Not a version transaction');
|
|
508
692
|
}
|
|
509
693
|
};
|
|
694
|
+
/**
|
|
695
|
+
*
|
|
696
|
+
* @param {IDBTransactionFull} tx
|
|
697
|
+
* @throws {DOMException}
|
|
698
|
+
* @returns {void}
|
|
699
|
+
*/
|
|
510
700
|
IDBTransaction.__assertNotVersionChange = function (tx) {
|
|
511
701
|
if (tx && tx.mode === 'versionchange') {
|
|
512
702
|
throw createDOMException('InvalidStateError', 'Cannot be called during a version transaction');
|
|
513
703
|
}
|
|
514
704
|
};
|
|
515
705
|
|
|
706
|
+
/**
|
|
707
|
+
*
|
|
708
|
+
* @param {IDBTransactionFull|undefined} tx
|
|
709
|
+
* @throws {DOMException}
|
|
710
|
+
* @returns {void}
|
|
711
|
+
*/
|
|
516
712
|
IDBTransaction.__assertNotFinished = function (tx) {
|
|
517
713
|
if (!tx || tx.__completed || tx.__abortFinished || tx.__errored) {
|
|
518
714
|
throw createDOMException('InvalidStateError', 'Transaction finished by commit or abort');
|
|
@@ -520,6 +716,11 @@ IDBTransaction.__assertNotFinished = function (tx) {
|
|
|
520
716
|
};
|
|
521
717
|
|
|
522
718
|
// object store methods behave differently: see https://github.com/w3c/IndexedDB/issues/192
|
|
719
|
+
/**
|
|
720
|
+
*
|
|
721
|
+
* @param {IDBTransactionFull} tx
|
|
722
|
+
* @returns {void}
|
|
723
|
+
*/
|
|
523
724
|
IDBTransaction.__assertNotFinishedObjectStoreMethod = function (tx) {
|
|
524
725
|
try {
|
|
525
726
|
IDBTransaction.__assertNotFinished(tx);
|
|
@@ -531,6 +732,12 @@ IDBTransaction.__assertNotFinishedObjectStoreMethod = function (tx) {
|
|
|
531
732
|
}
|
|
532
733
|
};
|
|
533
734
|
|
|
735
|
+
/**
|
|
736
|
+
*
|
|
737
|
+
* @param {IDBTransactionFull|undefined} tx
|
|
738
|
+
* @throws {DOMException}
|
|
739
|
+
* @returns {void}
|
|
740
|
+
*/
|
|
534
741
|
IDBTransaction.__assertActive = function (tx) {
|
|
535
742
|
if (!tx || !tx.__active) {
|
|
536
743
|
throw createDOMException('TransactionInactiveError', 'A request was placed against a transaction which is currently not active, or which is finished');
|
|
@@ -539,7 +746,8 @@ IDBTransaction.__assertActive = function (tx) {
|
|
|
539
746
|
|
|
540
747
|
/**
|
|
541
748
|
* Used by our `EventTarget.prototype` library to implement bubbling/capturing.
|
|
542
|
-
* @
|
|
749
|
+
* @this {IDBTransactionFull}
|
|
750
|
+
* @returns {import('./IDBDatabase.js').IDBDatabaseFull}
|
|
543
751
|
*/
|
|
544
752
|
IDBTransaction.prototype.__getParent = function () {
|
|
545
753
|
return this.db;
|