From 8501cb5b3e4f7ef94a9b9b87dfc06e037d59cb93 Mon Sep 17 00:00:00 2001 From: Ben Grynhaus Date: Wed, 2 Oct 2019 23:29:05 +0300 Subject: [PATCH] add types for mysql-import (#38762) --- types/mysql-import/index.d.ts | 40 ++++++++++++++++++++++++ types/mysql-import/mysql-import-tests.ts | 17 ++++++++++ types/mysql-import/tsconfig.json | 23 ++++++++++++++ types/mysql-import/tslint.json | 1 + 4 files changed, 81 insertions(+) create mode 100644 types/mysql-import/index.d.ts create mode 100644 types/mysql-import/mysql-import-tests.ts create mode 100644 types/mysql-import/tsconfig.json create mode 100644 types/mysql-import/tslint.json diff --git a/types/mysql-import/index.d.ts b/types/mysql-import/index.d.ts new file mode 100644 index 0000000000..d9e06f922f --- /dev/null +++ b/types/mysql-import/index.d.ts @@ -0,0 +1,40 @@ +// Type definitions for mysql-import 2.0 +// Project: https://github.com/pamblam/mysql-import#readme +// Definitions by: Ben Grynhaus +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface Settings { + /** + * The MySQL host to connect to. + */ + host: string; + /** + * The MySQL port to connect to. + */ + port?: number; + /** + * The MySQL user to connect with. + */ + user: string; + /** + * The password for the user. + */ + password: string; + /** + * The database to connect to. + */ + database: string; + /** + * Function to handle errors. The function will receive the Error. If not provided the error will be thrown. + */ + onerror?(error: any): void; +} + +export interface Importer { + /** + * Import an .sql file to the database. + */ + import(filename: string): Promise; +} + +export function config(settings: Settings): Importer; diff --git a/types/mysql-import/mysql-import-tests.ts b/types/mysql-import/mysql-import-tests.ts new file mode 100644 index 0000000000..c5383b5670 --- /dev/null +++ b/types/mysql-import/mysql-import-tests.ts @@ -0,0 +1,17 @@ +import * as mysqlImport from 'mysql-import'; + +mysqlImport.config(); // $ExpectError + +mysqlImport.config({}); // $ExpectError + +// $ExpectType Importer +const importer = mysqlImport.config({ + host: 'localhost', + port: 1234, + user: 'user', + password: 'test', + database: 'database', + onerror: err => {}, +}); + +importer.import('sql-file-path'); // $ExpectType Promise diff --git a/types/mysql-import/tsconfig.json b/types/mysql-import/tsconfig.json new file mode 100644 index 0000000000..5366f0d47c --- /dev/null +++ b/types/mysql-import/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mysql-import-tests.ts" + ] +} diff --git a/types/mysql-import/tslint.json b/types/mysql-import/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/mysql-import/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }