Skip to content

Commit

Permalink
apply deno fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
erfanium committed Oct 9, 2024
1 parent a816284 commit 6f6cfd6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 56 deletions.
13 changes: 7 additions & 6 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 @@ -43,8 +43,9 @@ export class MongoClient {
*/
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 @@ -58,7 +59,7 @@ export class MongoClient {
});
} catch (e: unknown) {
throw new MongoDriverError(
`Connection failed: ${e instanceof Error ? e.message : "unknown"}`
`Connection failed: ${e instanceof Error ? e.message : "unknown"}`,
);
}
return this.database((options as ConnectOptions).db);
Expand All @@ -76,14 +77,14 @@ export class MongoClient {
nameOnly?: boolean;
authorizedCollections?: boolean;
comment?: Document;
} = {}
} = {},
): Promise<ListDatabaseInfo[]> {
const { databases } = await this.getCluster().protocol.commandSingle(
"admin",
{
listDatabases: 1,
...options,
}
},
);
return databases;
}
Expand Down
56 changes: 28 additions & 28 deletions tests/cases/03_crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe("crud operations", () => {
date: new Date(dateNow),
},
},
{ upsert: true }
{ upsert: true },
);

assert(upsertedId);
Expand Down Expand Up @@ -135,7 +135,7 @@ describe("crud operations", () => {
username: "user1",
}),
MongoServerError,
"E11000"
"E11000",
);
});

Expand All @@ -154,12 +154,12 @@ describe("crud operations", () => {
assertEquals(findNull, undefined);
const projectionUser = await users.findOne(
{},
{ projection: { _id: 0, username: 1 } }
{ projection: { _id: 0, username: 1 } },
);
assertEquals(Object.keys(projectionUser!), ["username"]);
const projectionUserWithId = await users.findOne(
{},
{ projection: { username: 1 } }
{ projection: { username: 1 } },
);
assertEquals(Object.keys(projectionUserWithId!), ["_id", "username"]);
});
Expand Down Expand Up @@ -237,7 +237,7 @@ describe("crud operations", () => {

it("testFindAndModify-notfound", async () => {
const users = database.collection<{ username: string; counter: number }>(
"mongo_test_users"
"mongo_test_users",
);

const find = await users.findAndModify(
Expand All @@ -248,7 +248,7 @@ describe("crud operations", () => {
{
update: { $inc: { counter: 1 } },
new: false,
}
},
);

assert(find === null);
Expand All @@ -257,15 +257,15 @@ describe("crud operations", () => {

it("testFindAndModify-update", async () => {
const users = database.collection<{ username: string; counter: number }>(
"mongo_test_users"
"mongo_test_users",
);
await users.insertOne({ username: "counter", counter: 5 });
const updated = await users.findAndModify(
{ username: "counter" },
{
update: { $inc: { counter: 1 } },
new: true,
}
},
);

assert(updated !== null);
Expand All @@ -275,14 +275,14 @@ describe("crud operations", () => {

it("testFindAndModify-delete", async () => {
const users = database.collection<{ username: string; counter: number }>(
"mongo_test_users"
"mongo_test_users",
);
await users.insertOne({ username: "delete", counter: 10 });
const updated = await users.findAndModify(
{ username: "delete" },
{
remove: true,
}
},
);

assert(updated !== null);
Expand Down Expand Up @@ -341,7 +341,7 @@ describe("crud operations", () => {
{},
{
$push: { friends: { $each: ["Carol"] } },
}
},
);
assertEquals(result, {
matchedCount: 1,
Expand All @@ -364,7 +364,7 @@ describe("crud operations", () => {
{},
{
$pull: { friends: "Bob" },
}
},
);
assertEquals(result, {
matchedCount: 1,
Expand All @@ -387,7 +387,7 @@ describe("crud operations", () => {
{},
{
$push: { "likes.hobbies.indoor": "board games" },
}
},
);
assertEquals(result, {
matchedCount: 1,
Expand All @@ -410,7 +410,7 @@ describe("crud operations", () => {
{},
{
$pullAll: { "likes.hobbies.indoor": ["board games", "cooking"] },
}
},
);
assertEquals(result, {
matchedCount: 1,
Expand All @@ -433,7 +433,7 @@ describe("crud operations", () => {
{},
{
$pull: { "likes.hobbies.indoor": "board games" },
}
},
);
assertEquals(result, {
matchedCount: 1,
Expand Down Expand Up @@ -467,7 +467,7 @@ describe("crud operations", () => {
const result = await users.updateOne(
{ username: "user2" },
{ $set: { username: "USER2" } },
{ upsert: true }
{ upsert: true },
);
assertEquals(result.matchedCount, 1);
assertEquals(result.modifiedCount, 0);
Expand All @@ -484,7 +484,7 @@ describe("crud operations", () => {
{ username: "user1" },
{
username: "user2",
}
},
);

assertEquals(result, {
Expand Down Expand Up @@ -698,7 +698,7 @@ describe("crud operations", () => {
]);
const result = await users.updateMany(
{ username: "many" },
{ $set: { username: "MANY" } }
{ $set: { username: "MANY" } },
);
assertEquals(result, {
matchedCount: 2,
Expand Down Expand Up @@ -794,13 +794,13 @@ describe("crud operations", () => {
acceding,
all.sort((lhs, rhs) => {
return lhs.uid! - rhs.uid!;
})
}),
);
assertEquals(
descending,
all.sort((lhs, rhs) => {
return -lhs.uid! - rhs.uid!;
})
}),
);

await database.collection("mongo_test_users").drop();
Expand Down Expand Up @@ -828,7 +828,7 @@ describe("crud operations", () => {
it("testFindWithMaxTimeMS", async () => {
const supportsMaxTimeMSInFindOne = greaterOrEqual(
parse(client.buildInfo!.version),
{ major: 4, minor: 2, patch: 0 }
{ major: 4, minor: 2, patch: 0 },
);

const users = database.collection<User>("mongo_test_users");
Expand All @@ -844,7 +844,7 @@ describe("crud operations", () => {
{
uid: 0,
},
{ maxTimeMS: 100 }
{ maxTimeMS: 100 },
)
.toArray();

Expand All @@ -854,7 +854,7 @@ describe("crud operations", () => {
{
uid: 0,
},
{ maxTimeMS: 100 }
{ maxTimeMS: 100 },
);

assertEquals(user1!.uid, 0);
Expand All @@ -866,7 +866,7 @@ describe("crud operations", () => {
uid: 0,
$where: "sleep(10) || true",
},
{ maxTimeMS: 1 }
{ maxTimeMS: 1 },
)
.toArray();
assert(false);
Expand All @@ -884,7 +884,7 @@ describe("crud operations", () => {
uid: 0,
$where: "sleep(10) || true",
},
{ maxTimeMS: 1 }
{ maxTimeMS: 1 },
);
assert(false);
} catch (e) {
Expand Down Expand Up @@ -969,7 +969,7 @@ describe("crud operations", () => {

const createdCollection = await database.createCollection<IStudents>(
testCollectionName,
options
options,
);

assert(createdCollection);
Expand Down Expand Up @@ -1004,10 +1004,10 @@ describe("crud operations", () => {
() =>
database.createCollection<{ _id: string; name: string }>(
testCollectionName,
invalidOptions
invalidOptions,
),
// error with the message "the 'size' field is required when 'capped' is true"
MongoServerError
MongoServerError,
);
});
});
Loading

0 comments on commit 6f6cfd6

Please sign in to comment.