add types for mysql-import (#38762)

This commit is contained in:
Ben Grynhaus 2019-10-02 23:29:05 +03:00 committed by Ryan Cavanaugh
parent 837bb465c9
commit 8501cb5b3e
4 changed files with 81 additions and 0 deletions

40
types/mysql-import/index.d.ts vendored Normal file
View File

@ -0,0 +1,40 @@
// Type definitions for mysql-import 2.0
// Project: https://github.com/pamblam/mysql-import#readme
// Definitions by: Ben Grynhaus <https://github.com/bengry>
// 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<void>;
}
export function config(settings: Settings): Importer;

View File

@ -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<void>

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }