From 84d3784827726284961e7d3cf0c1db3e38c03986 Mon Sep 17 00:00:00 2001 From: Alpha Date: Wed, 6 Feb 2019 17:24:37 -0500 Subject: [PATCH 1/2] Add flow typings --- src/main.js.flow | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/main.js.flow diff --git a/src/main.js.flow b/src/main.js.flow new file mode 100644 index 0000000..a28154c --- /dev/null +++ b/src/main.js.flow @@ -0,0 +1,82 @@ +// @flow strict + +export type DataType = number | string; + +export type MigrateOptions = {| + force?: 'last', + migrationsPath?: string, + table?: string +|}; + +export type Params = DataType[] | { [param: string]: DataType }; + +export type RowCallback = (err: ?Error, row: T) => void; + +export type SqliteOpenFlag = {| + OPEN_READONLY: 0x01, + OPEN_READWRITE: 0x02, + OPEN_READWRITE_CREATE: 0x06 // 0x02 | 0x04 +|}; + +export type OpenOptions = {| + cached?: boolean, + mode?: $Values, + promise?: typeof Promise, + verbose?: boolean +|}; + +declare class Statement { + +sql: string; + +lastID: number; + +changes: number; + + all(params?: Params): Promise; + all(...params: DataType[]): Promise; + + bind(params: Params): Promise; + bind(...params: DataType[]): Promise; + + each(callback: RowCallback): Promise; + each(params: Params | DataType, callback: RowCallback): Promise; + each(param1: DataType, param2: DataType, ...params: Array>): Promise; + + get(params?: Params): Promise; + get(...params: DataType[]): Promise; + + finalize(): Promise; + + reset(): Promise; + + run(params: Params): Promise; + run(...params: DataType[]): Promise; +}; + +declare class Database { + all(sql: string, params?: Params): Promise; + all(sql: string, ...params: DataType[]): Promise; + + close(): Promise; + + configure(option: 'busyTimeout', value: number): void; + configure(option: 'profile', value: (sql: string) => void): void; + configure(option: 'trace', value: (sql: string, nsecs: number) => void): void; + + each(sql: string, callback: RowCallback): Promise; + each(sql: string, params: Params | DataType, callback: RowCallback): Promise; + each(sql: string, param1: DataType, param2: DataType, ...params: Array>): Promise; + + exec(sql: string): Promise; + + get(sql: string, params?: Params): Promise; + get(sql: string, ...params: DataType[]): Promise; + + migrate(options?: MigrateOptions): Promise; + + prepare(sql: string, params?: Params): Promise; + prepare(sql: string, ...params: DataType[]): Promise; + + run(sql: string, params?: Params): Promise; + run(sql: string, ...params: DataType[]): Promise; +}; + +declare export function open(filename: string, options?: OpenOptions): Promise; From 44e91af673dcd7ee5e6be651063c30c0482758c1 Mon Sep 17 00:00:00 2001 From: Alpha Date: Wed, 6 Feb 2019 17:27:10 -0500 Subject: [PATCH 2/2] Install flow typings during build --- tools/build.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/build.js b/tools/build.js index 7a595d9..8046bb1 100644 --- a/tools/build.js +++ b/tools/build.js @@ -57,6 +57,7 @@ promise = promise.then(() => { delete pkg.babel; fs.writeFileSync('build/package.json', JSON.stringify(pkg, null, ' '), 'utf-8'); fs.writeFileSync('build/main.d.ts', fs.readFileSync('src/main.d.ts', 'utf-8'), 'utf-8'); + fs.writeFileSync('build/main.js.flow', fs.readFileSync('src/main.js.flow', 'utf-8'), 'utf-8'); fs.writeFileSync('build/LICENSE.txt', fs.readFileSync('LICENSE.txt', 'utf-8'), 'utf-8'); fs.writeFileSync('build/README.md', fs.readFileSync('README.md', 'utf-8'), 'utf-8'); });