1// Definitions copied from `@types/websql` as we want
2// to expose a custom version of the API that:
3// - uses primitive `string` instead of `String`
4// - excludes some methods that are not exposed by our API.
5//
6// Original definitions by: TeamworkGuy2 <https://github.com/TeamworkGuy2>
7
8export interface Window {
9  openDatabase?: (
10    name: string,
11    version: string,
12    displayName: string,
13    estimatedSize: number,
14    creationCallback?: DatabaseCallback
15  ) => Database;
16}
17
18export interface DatabaseCallback {
19  (database: Database): void;
20}
21
22export interface Database {
23  version: string;
24
25  transaction(
26    callback: SQLTransactionCallback,
27    errorCallback?: SQLTransactionErrorCallback,
28    successCallback?: SQLVoidCallback
29  ): void;
30
31  readTransaction(
32    callback: SQLTransactionCallback,
33    errorCallback?: SQLTransactionErrorCallback,
34    successCallback?: SQLVoidCallback
35  ): void;
36}
37
38export interface SQLVoidCallback {
39  (): void;
40}
41
42export interface SQLTransactionCallback {
43  (transaction: SQLTransaction): void;
44}
45
46export interface SQLTransactionErrorCallback {
47  (error: SQLError): void;
48}
49
50export interface SQLTransaction {
51  executeSql(
52    sqlStatement: string,
53    args?: any[],
54    callback?: SQLStatementCallback,
55    errorCallback?: SQLStatementErrorCallback
56  ): void;
57}
58
59export interface SQLStatementCallback {
60  (transaction: SQLTransaction, resultSet: SQLResultSet): void;
61}
62
63export interface SQLStatementErrorCallback {
64  (transaction: SQLTransaction, error: SQLError): boolean;
65}
66
67export interface SQLResultSet {
68  insertId: number;
69  rowsAffected: number;
70  rows: SQLResultSetRowList;
71}
72
73export interface SQLResultSetRowList {
74  length: number;
75  item(index: number): any;
76}
77
78export declare class SQLError {
79  static UNKNOWN_ERR: number;
80  static DATABASE_ERR: number;
81  static VERSION_ERR: number;
82  static TOO_LARGE_ERR: number;
83  static QUOTA_ERR: number;
84  static SYNTAX_ERR: number;
85  static CONSTRAINT_ERR: number;
86  static TIMEOUT_ERR: number;
87
88  code: number;
89  message: string;
90}
91
92export interface WebSQLDatabase extends Database {
93  exec(queries: Query[], readOnly: boolean, callback: SQLiteCallback): void;
94}
95
96export type Query = { sql: string; args: unknown[] };
97
98export interface ResultSetError {
99  error: Error;
100}
101export interface ResultSet {
102  insertId?: number;
103  rowsAffected: number;
104  rows: { [column: string]: any }[];
105}
106
107export type SQLiteCallback = (
108  error?: Error | null,
109  resultSet?: (ResultSetError | ResultSet)[]
110) => void;
111