@@ -29,7 +29,7 @@ export class MongoClient {
29
29
getCluster ( ) : Cluster {
30
30
if ( ! this . #cluster) {
31
31
throw new MongoDriverError (
32
- "MongoClient is not connected to the Database" ,
32
+ "MongoClient is not connected to the Database"
33
33
) ;
34
34
}
35
35
@@ -41,13 +41,10 @@ export class MongoClient {
41
41
*
42
42
* @param options Connection options or a MongoDB URI
43
43
*/
44
- async connect (
45
- options : ConnectOptions | string ,
46
- ) : Promise < Database > {
44
+ async connect ( options : ConnectOptions | string ) : Promise < Database > {
47
45
try {
48
- const parsedOptions = typeof options === "string"
49
- ? await parse ( options )
50
- : options ;
46
+ const parsedOptions =
47
+ typeof options === "string" ? await parse ( options ) : options ;
51
48
52
49
this . #defaultDbName = parsedOptions . db ;
53
50
const cluster = new Cluster ( parsedOptions ) ;
@@ -59,8 +56,10 @@ export class MongoClient {
59
56
this . #buildInfo = await this . runCommand ( this . #defaultDbName, {
60
57
buildInfo : 1 ,
61
58
} ) ;
62
- } catch ( e ) {
63
- throw new MongoDriverError ( `Connection failed: ${ e . message || e } ` ) ;
59
+ } catch ( e : unknown ) {
60
+ throw new MongoDriverError (
61
+ `Connection failed: ${ e instanceof Error ? e . message : "unknown" } `
62
+ ) ;
64
63
}
65
64
return this . database ( ( options as ConnectOptions ) . db ) ;
66
65
}
@@ -71,18 +70,20 @@ export class MongoClient {
71
70
* @param options Options to pass to the `listDatabases` command
72
71
* @returns A list of databases including their name, size on disk, and whether they are empty
73
72
*/
74
- async listDatabases ( options : {
75
- filter ?: Document ;
76
- nameOnly ?: boolean ;
77
- authorizedCollections ?: boolean ;
78
- comment ?: Document ;
79
- } = { } ) : Promise < ListDatabaseInfo [ ] > {
73
+ async listDatabases (
74
+ options : {
75
+ filter ?: Document ;
76
+ nameOnly ?: boolean ;
77
+ authorizedCollections ?: boolean ;
78
+ comment ?: Document ;
79
+ } = { }
80
+ ) : Promise < ListDatabaseInfo [ ] > {
80
81
const { databases } = await this . getCluster ( ) . protocol . commandSingle (
81
82
"admin" ,
82
83
{
83
84
listDatabases : 1 ,
84
85
...options ,
85
- } ,
86
+ }
86
87
) ;
87
88
return databases ;
88
89
}
0 commit comments