@@ -8,6 +8,15 @@ const Authorization = require("./auth");
88 * @import {Options as NativeOptions, Statement as NativeStatement} from './index.js'
99 */
1010
11+ /**
12+ * better-sqlite3-compatible types for db.transaction()
13+ * @typedef {(...params: any[]) => unknown } VariableArgFunction
14+ */
15+ /**
16+ * @template {VariableArgFunction} F
17+ * @typedef {F extends (...args: infer A) => unknown ? A : never } ArgumentTypes
18+ */
19+
1120function convertError ( err ) {
1221 // Handle errors from Rust with JSON-encoded message
1322 if ( typeof err . message === 'string' ) {
@@ -56,6 +65,10 @@ class Database {
5665 constructor ( db ) {
5766 this . db = db ;
5867 this . memory = this . db . memory
68+
69+ /** @type boolean */
70+ this . inTransaction ;
71+
5972 Object . defineProperties ( this , {
6073 inTransaction : {
6174 get ( ) {
@@ -94,7 +107,15 @@ class Database {
94107 /**
95108 * Returns a function that executes the given function in a transaction.
96109 *
97- * @param {function } fn - The function to wrap in a transaction.
110+ * @template {VariableArgFunction} F
111+ * @param {F } fn - The function to wrap in a transaction.
112+ * @returns {{
113+ * (...bindParameters: ArgumentTypes<F>): Promise<ReturnType<F>>;
114+ * default(...bindParameters: ArgumentTypes<F>): Promise<ReturnType<F>>;
115+ * deferred(...bindParameters: ArgumentTypes<F>): Promise<ReturnType<F>>;
116+ * immediate(...bindParameters: ArgumentTypes<F>): Promise<ReturnType<F>>;
117+ * exclusive(...bindParameters: ArgumentTypes<F>): Promise<ReturnType<F>>;
118+ * }}
98119 */
99120 transaction ( fn ) {
100121 if ( typeof fn !== "function" )
0 commit comments