mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
add (optional) logging for idb requests
This commit is contained in:
parent
93a7f9959e
commit
3c7125bb88
@ -17,6 +17,14 @@ limitations under the License.
|
|||||||
import {QueryTarget} from "./QueryTarget.js";
|
import {QueryTarget} from "./QueryTarget.js";
|
||||||
import {IDBRequestAttemptError} from "./error.js";
|
import {IDBRequestAttemptError} from "./error.js";
|
||||||
|
|
||||||
|
const LOG_REQUESTS = false;
|
||||||
|
|
||||||
|
function logRequest(method, params, source) {
|
||||||
|
const storeName = source?.name;
|
||||||
|
const databaseName = source?.transaction?.db?.name;
|
||||||
|
console.info(`${databaseName}.${storeName}.${method}(${params.map(p => JSON.stringify(p)).join(", ")})`);
|
||||||
|
}
|
||||||
|
|
||||||
class QueryTargetWrapper {
|
class QueryTargetWrapper {
|
||||||
constructor(qt) {
|
constructor(qt) {
|
||||||
this._qt = qt;
|
this._qt = qt;
|
||||||
@ -38,8 +46,10 @@ class QueryTargetWrapper {
|
|||||||
try {
|
try {
|
||||||
// not supported on Edge 15
|
// not supported on Edge 15
|
||||||
if (!this._qt.openKeyCursor) {
|
if (!this._qt.openKeyCursor) {
|
||||||
|
LOG_REQUESTS && logRequest("openCursor", params, this._qt);
|
||||||
return this.openCursor(...params);
|
return this.openCursor(...params);
|
||||||
}
|
}
|
||||||
|
LOG_REQUESTS && logRequest("openKeyCursor", params, this._qt);
|
||||||
return this._qt.openKeyCursor(...params);
|
return this._qt.openKeyCursor(...params);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
throw new IDBRequestAttemptError("openKeyCursor", this._qt, err, params);
|
throw new IDBRequestAttemptError("openKeyCursor", this._qt, err, params);
|
||||||
@ -48,6 +58,7 @@ class QueryTargetWrapper {
|
|||||||
|
|
||||||
openCursor(...params) {
|
openCursor(...params) {
|
||||||
try {
|
try {
|
||||||
|
LOG_REQUESTS && logRequest("openCursor", params, this._qt);
|
||||||
return this._qt.openCursor(...params);
|
return this._qt.openCursor(...params);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
throw new IDBRequestAttemptError("openCursor", this._qt, err, params);
|
throw new IDBRequestAttemptError("openCursor", this._qt, err, params);
|
||||||
@ -56,6 +67,7 @@ class QueryTargetWrapper {
|
|||||||
|
|
||||||
put(...params) {
|
put(...params) {
|
||||||
try {
|
try {
|
||||||
|
LOG_REQUESTS && logRequest("put", params, this._qt);
|
||||||
return this._qt.put(...params);
|
return this._qt.put(...params);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
throw new IDBRequestAttemptError("put", this._qt, err, params);
|
throw new IDBRequestAttemptError("put", this._qt, err, params);
|
||||||
@ -64,6 +76,7 @@ class QueryTargetWrapper {
|
|||||||
|
|
||||||
add(...params) {
|
add(...params) {
|
||||||
try {
|
try {
|
||||||
|
LOG_REQUESTS && logRequest("add", params, this._qt);
|
||||||
return this._qt.add(...params);
|
return this._qt.add(...params);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
throw new IDBRequestAttemptError("add", this._qt, err, params);
|
throw new IDBRequestAttemptError("add", this._qt, err, params);
|
||||||
@ -72,6 +85,7 @@ class QueryTargetWrapper {
|
|||||||
|
|
||||||
get(...params) {
|
get(...params) {
|
||||||
try {
|
try {
|
||||||
|
LOG_REQUESTS && logRequest("get", params, this._qt);
|
||||||
return this._qt.get(...params);
|
return this._qt.get(...params);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
throw new IDBRequestAttemptError("get", this._qt, err, params);
|
throw new IDBRequestAttemptError("get", this._qt, err, params);
|
||||||
@ -80,6 +94,7 @@ class QueryTargetWrapper {
|
|||||||
|
|
||||||
getKey(...params) {
|
getKey(...params) {
|
||||||
try {
|
try {
|
||||||
|
LOG_REQUESTS && logRequest("getKey", params, this._qt);
|
||||||
return this._qt.getKey(...params);
|
return this._qt.getKey(...params);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
throw new IDBRequestAttemptError("getKey", this._qt, err, params);
|
throw new IDBRequestAttemptError("getKey", this._qt, err, params);
|
||||||
@ -88,6 +103,7 @@ class QueryTargetWrapper {
|
|||||||
|
|
||||||
delete(...params) {
|
delete(...params) {
|
||||||
try {
|
try {
|
||||||
|
LOG_REQUESTS && logRequest("delete", params, this._qt);
|
||||||
return this._qt.delete(...params);
|
return this._qt.delete(...params);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
throw new IDBRequestAttemptError("delete", this._qt, err, params);
|
throw new IDBRequestAttemptError("delete", this._qt, err, params);
|
||||||
|
Loading…
Reference in New Issue
Block a user