Skip to content

Commit

Permalink
chore: some minor changes to make deno2 happy
Browse files Browse the repository at this point in the history
  • Loading branch information
erfanium committed Oct 9, 2024
1 parent dfbd1b3 commit a816284
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 237 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/jsr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
- name: Publish to JSR
run: |
deno publish
deno publish
6 changes: 3 additions & 3 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export {
Timestamp,
UUID,
} from "jsr:@lucsoft/web-bson@^0.3.1";
export { crypto as stdCrypto } from "jsr:@std/crypto@^0.224.0/crypto";
export { decodeBase64, encodeBase64 } from "jsr:@std/encoding@^0.224.0/base64";
export { encodeHex } from "jsr:@std/encoding@^0.224.0/hex";
export { crypto as stdCrypto } from "jsr:@std/crypto@^1.0.3/crypto";
export { decodeBase64, encodeBase64 } from "jsr:@std/encoding@^1.0.5/base64";
export { encodeHex } from "jsr:@std/encoding@^1.0.5/hex";
33 changes: 17 additions & 16 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class MongoClient {
getCluster(): Cluster {
if (!this.#cluster) {
throw new MongoDriverError(
"MongoClient is not connected to the Database",
"MongoClient is not connected to the Database"
);
}

Expand All @@ -41,13 +41,10 @@ export class MongoClient {
*
* @param options Connection options or a MongoDB URI
*/
async connect(
options: ConnectOptions | string,
): Promise<Database> {
async connect(options: ConnectOptions | string): Promise<Database> {
try {
const parsedOptions = typeof options === "string"
? await parse(options)
: options;
const parsedOptions =
typeof options === "string" ? await parse(options) : options;

this.#defaultDbName = parsedOptions.db;
const cluster = new Cluster(parsedOptions);
Expand All @@ -59,8 +56,10 @@ export class MongoClient {
this.#buildInfo = await this.runCommand(this.#defaultDbName, {
buildInfo: 1,
});
} catch (e) {
throw new MongoDriverError(`Connection failed: ${e.message || e}`);
} catch (e: unknown) {
throw new MongoDriverError(
`Connection failed: ${e instanceof Error ? e.message : "unknown"}`
);
}
return this.database((options as ConnectOptions).db);
}
Expand All @@ -71,18 +70,20 @@ export class MongoClient {
* @param options Options to pass to the `listDatabases` command
* @returns A list of databases including their name, size on disk, and whether they are empty
*/
async listDatabases(options: {
filter?: Document;
nameOnly?: boolean;
authorizedCollections?: boolean;
comment?: Document;
} = {}): Promise<ListDatabaseInfo[]> {
async listDatabases(
options: {
filter?: Document;
nameOnly?: boolean;
authorizedCollections?: boolean;
comment?: Document;
} = {}
): Promise<ListDatabaseInfo[]> {
const { databases } = await this.getCluster().protocol.commandSingle(
"admin",
{
listDatabases: 1,
...options,
},
}
);
return databases;
}
Expand Down
2 changes: 1 addition & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class MongoRuntimeError extends MongoDriverError {
super(message);
}

get name(): string {
override get name(): string {
return "MongoRuntimeError";
}
}
Loading

0 comments on commit a816284

Please sign in to comment.