Skip to content

Commit 63b9f8d

Browse files
committed
refactor: pattern and remove circular imports
1 parent 283b1f3 commit 63b9f8d

19 files changed

+274
-292
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import * as mysql from './typings/mysql';
12
import {
23
Connection as PromiseConnection,
34
Pool as PromisePool,
45
PoolConnection as PromisePoolConnection,
56
} from './promise';
67

7-
import * as mysql from './typings/mysql';
88
export * from './typings/mysql';
99

1010
export interface Connection extends mysql.Connection {

promise.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { EventEmitter } from 'events';
2+
13
import {
24
RowDataPacket,
35
OkPacket,
@@ -9,7 +11,6 @@ import {
911
Pool as CorePool,
1012
} from './index';
1113

12-
import { EventEmitter } from 'events';
1314
export * from './index';
1415

1516
export interface PreparedStatementInfo {
@@ -246,6 +247,7 @@ export interface Pool extends EventEmitter, Connection {
246247
): Promise<[T, FieldPacket[]]>;
247248

248249
getConnection(): Promise<PoolConnection>;
250+
249251
releaseConnection(connection: PoolConnection): void;
250252

251253
on(event: 'connection', listener: (connection: PoolConnection) => any): this;

typings/mysql/index.d.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
import * as crypto from 'crypto';
2-
import * as BasePool from './lib/Pool';
3-
import * as BaseConnection from './lib/Connection';
1+
import { RsaPublicKey, RsaPrivateKey, KeyLike } from 'crypto';
2+
import { Pool as BasePool, PoolOptions } from './lib/Pool';
3+
import {
4+
Connection as BaseConnection,
5+
ConnectionOptions,
6+
SslOptions,
7+
} from './lib/Connection';
8+
import {
9+
Query as BaseQuery,
10+
QueryOptions,
11+
QueryError,
12+
} from './lib/protocol/sequences/Query';
413
import {
514
PoolCluster as BasePoolCluster,
615
PoolClusterOptions,
716
} from './lib/PoolCluster';
8-
import { ConnectionOptions, SslOptions } from './lib/Connection';
9-
import BasePoolConnection = require('./lib/PoolConnection');
10-
import { PoolOptions } from './lib/Pool';
11-
import BaseQuery = require('./lib/protocol/sequences/Query');
12-
import BasePrepare = require('./lib/protocol/sequences/Prepare');
13-
import { QueryOptions, QueryError } from './lib/protocol/sequences/Query';
14-
import { PrepareStatementInfo } from './lib/protocol/sequences/Prepare';
15-
import Server = require('./lib/Server');
17+
import { PoolConnection as BasePoolConnection } from './lib/PoolConnection';
18+
import {
19+
Prepare as BasePrepare,
20+
PrepareStatementInfo,
21+
} from './lib/protocol/sequences/Prepare';
22+
import { Server } from './lib/Server';
1623
import { Connection as PromiseConnection } from '../../promise';
1724

1825
export {
@@ -28,10 +35,10 @@ export {
2835
export * from './lib/protocol/packets/index';
2936

3037
// Expose class interfaces
31-
export interface Connection extends BaseConnection.Connection {
38+
export interface Connection extends BaseConnection {
3239
promise(promiseImpl?: PromiseConstructor): PromiseConnection;
3340
}
34-
export interface Pool extends BasePool.Pool {}
41+
export interface Pool extends BasePool {}
3542
export interface PoolConnection extends BasePoolConnection {}
3643
export interface PoolCluster extends BasePoolCluster {}
3744
export interface Query extends BaseQuery {}
@@ -49,10 +56,7 @@ type AuthPluginDefinition<T> = (pluginOptions?: T) => AuthPlugin;
4956
export const authPlugins: {
5057
caching_sha2_password: AuthPluginDefinition<{
5158
overrideIsSecure?: boolean;
52-
serverPublicKey?:
53-
| crypto.RsaPublicKey
54-
| crypto.RsaPrivateKey
55-
| crypto.KeyLike;
59+
serverPublicKey?: RsaPublicKey | RsaPrivateKey | KeyLike;
5660
jonServerPublicKey?: (data: Buffer) => void;
5761
}>;
5862
mysql_clear_password: AuthPluginDefinition<{
@@ -63,20 +67,15 @@ export const authPlugins: {
6367
passwordSha1?: string;
6468
}>;
6569
sha256_password: AuthPluginDefinition<{
66-
serverPublicKey?:
67-
| crypto.RsaPublicKey
68-
| crypto.RsaPrivateKey
69-
| crypto.KeyLike;
70+
serverPublicKey?: RsaPublicKey | RsaPrivateKey | KeyLike;
7071
joinServerPublicKey?: (data: Buffer) => void;
7172
}>;
7273
};
7374

7475
export function createConnection(connectionUri: string): Connection;
75-
export function createConnection(
76-
config: BaseConnection.ConnectionOptions
77-
): Connection;
76+
export function createConnection(config: ConnectionOptions): Connection;
7877

79-
export function createPool(config: BasePool.PoolOptions): BasePool.Pool;
78+
export function createPool(config: PoolOptions): BasePool;
8079

8180
export function createPoolCluster(config?: PoolClusterOptions): PoolCluster;
8281

@@ -103,6 +102,4 @@ export function raw(sql: string): {
103102
toSqlString: () => string;
104103
};
105104

106-
export function createServer(
107-
handler: (conn: BaseConnection.Connection) => any
108-
): Server;
105+
export function createServer(handler: (conn: BaseConnection) => any): Server;

0 commit comments

Comments
 (0)