Commit 9e58c31
authored
docs: fix and add jsdocs to promise.js for tsc inference (#205)
We noticed that many of the types in the tsc-generated `promise.d.ts`
definitions were either missing or incorrect. This attempts to address
some of those issues through updating JSDocs. In particular, correcting
the Database constructor to type the parameter as NativeDb allows tsc to
correctly infer more method return types.
Here is `promise.d.ts` after a local run of tsc with these changes
applied:
```ts
import Authorization = require("./auth");
/**
* Database represents a connection that can prepare and execute SQL statements.
*/
export class Database {
/**
* Creates a new database connection. If the database file pointed to by `path` does not exists, it will be created.
*
* @constructor
* @param {NativeDb} db - Database object
*/
constructor(db: NativeDb);
db: NativeDb;
memory: boolean;
sync(): Promise<import("./index.js").SyncResult>;
syncUntil(replicationIndex: any): void;
/**
* Prepares a SQL statement for execution.
*
* @param {string} sql - The SQL statement string to prepare.
*/
prepare(sql: string): Promise<Statement>;
/**
* Returns a function that executes the given function in a transaction.
*
* @param {function} fn - The function to wrap in a transaction.
*/
transaction(fn: Function): (...bindParameters: any[]) => Promise<any>;
/**
* Execute a pragma statement
* @param {string} source - The pragma statement to execute, without the `PRAGMA` prefix.
* @param {object} [options] - Options object.
* @param {boolean} [options.simple] - If true, return a single value for single-column results.
*/
pragma(source: string, options?: {
simple?: boolean | undefined;
}): Promise<object>;
backup(filename: any, options: any): void;
serialize(options: any): void;
function(name: any, options: any, fn: any): void;
aggregate(name: any, options: any): void;
table(name: any, factory: any): void;
authorizer(rules: any): void;
authorizer(hook: any): this;
/**
* Loads an extension into the database
* @param {Parameters<NativeDb['loadExtension']>} args - Arguments to pass to the underlying loadExtension method
*/
loadExtension(path: string, entryPoint?: string | null | undefined): void;
maxWriteReplicationIndex(): number;
/**
* Executes a SQL statement.
*
* @param {string} sql - The SQL statement string to execute.
*/
exec(sql: string): Promise<void>;
/**
* Interrupts the database connection.
*/
interrupt(): void;
/**
* Closes the database connection.
*/
close(): void;
/**
* Toggle 64-bit integer support.
* @param {boolean} [toggle] - Whether to use safe integers by default.
*/
defaultSafeIntegers(toggle?: boolean): this;
unsafeMode(...args: any[]): void;
}
import SqliteError = require("./sqlite-error.js");
/**
* Statement represents a prepared SQL statement that can be executed.
*/
export class Statement {
/**
* @param {NativeStatement} stmt
*/
constructor(stmt: NativeStatement);
stmt: NativeStatement;
/**
* Toggle raw mode.
*
* @param {boolean} [raw] - Enable or disable raw mode. If you don't pass the parameter, raw mode is enabled.
*/
raw(raw?: boolean): this;
/**
* Toggle pluck mode.
*
* @param {boolean} [pluckMode] - Enable or disable pluck mode. If you don't pass the parameter, pluck mode is enabled.
*/
pluck(pluckMode?: boolean): this;
/**
* Toggle query timing.
*
* @param {boolean} [timingMode] - Enable or disable query timing. If you don't pass the parameter, query timing is enabled.
*/
timing(timingMode?: boolean): this;
get reader(): void;
/**
* Executes the SQL statement and returns an info object.
*/
run(...bindParameters: any[]): Promise<object>;
/**
* Executes the SQL statement and returns the first row.
*
* @param bindParameters - The bind parameters for executing the statement.
*/
get(...bindParameters: any[]): Promise<object>;
/**
* Executes the SQL statement and returns an iterator to the resulting rows.
*
* @param bindParameters - The bind parameters for executing the statement.
*/
iterate(...bindParameters: any[]): Promise<{
next(): any;
[Symbol.asyncIterator](): {
next(): any;
};
}>;
/**
* Executes the SQL statement and returns an array of the resulting rows.
*
* @param bindParameters - The bind parameters for executing the statement.
*/
all(...bindParameters: any[]): Promise<any[]>;
/**
* Interrupts the statement.
*/
interrupt(): this;
/**
* Returns the columns in the result set returned by this prepared statement.
*/
columns(): unknown[];
/**
* Toggle 64-bit integer support.
*/
safeIntegers(toggle: any): this;
}
/**
* Creates a new database connection.
*
* @param {string} path - Path to the database file.
* @param {NativeOptions} opts - Options.
*/
export function connect(path: string, opts: NativeOptions): Promise<Database>;
import { Database as NativeDb } from "./index.js";
import type { Statement as NativeStatement } from './index.js';
import type { Options as NativeOptions } from './index.js';
export { Authorization, SqliteError };
```1 file changed
+23
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
| |||
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
35 | | - | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
| |||
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
50 | | - | |
| 54 | + | |
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
| |||
124 | 128 | | |
125 | 129 | | |
126 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
127 | 137 | | |
128 | 138 | | |
129 | 139 | | |
| |||
161 | 171 | | |
162 | 172 | | |
163 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
164 | 178 | | |
165 | 179 | | |
166 | 180 | | |
| |||
211 | 225 | | |
212 | 226 | | |
213 | 227 | | |
| 228 | + | |
214 | 229 | | |
215 | 230 | | |
216 | 231 | | |
| |||
226 | 241 | | |
227 | 242 | | |
228 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
229 | 247 | | |
230 | 248 | | |
231 | 249 | | |
232 | 250 | | |
233 | 251 | | |
234 | 252 | | |
235 | 253 | | |
236 | | - | |
| 254 | + | |
237 | 255 | | |
238 | 256 | | |
239 | 257 | | |
| |||
243 | 261 | | |
244 | 262 | | |
245 | 263 | | |
246 | | - | |
| 264 | + | |
247 | 265 | | |
248 | 266 | | |
249 | 267 | | |
| |||
253 | 271 | | |
254 | 272 | | |
255 | 273 | | |
256 | | - | |
| 274 | + | |
257 | 275 | | |
258 | 276 | | |
259 | 277 | | |
| |||
0 commit comments