Skip to content

Commit

Permalink
feat: support Deno 2 (#416)
Browse files Browse the repository at this point in the history
* Update ci.yml

* chore: some minor changes to make deno2 happy

* apply deno fmt
  • Loading branch information
erfanium authored Oct 9, 2024
1 parent 1ade65f commit b60fcca
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 202 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install Deno
uses: denolib/setup-deno@master
with:
deno-version: 1.x.x
deno-version: 2.x.x

- name: Log versions
run: |
Expand Down
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";
24 changes: 13 additions & 11 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ 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)
Expand All @@ -59,8 +57,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,12 +71,14 @@ 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",
{
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 b60fcca

Please sign in to comment.