From 6f6cfd6d475c45ff8f5ed06e2d61321191f8e0a4 Mon Sep 17 00:00:00 2001 From: Erfanium Date: Wed, 9 Oct 2024 21:13:41 +0330 Subject: [PATCH] apply deno fmt --- src/client.ts | 13 +++++----- tests/cases/03_crud.ts | 56 +++++++++++++++++++++--------------------- tests/cases/05_srv.ts | 47 ++++++++++++++++++----------------- 3 files changed, 60 insertions(+), 56 deletions(-) diff --git a/src/client.ts b/src/client.ts index 1853a82..bdf35fc 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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", ); } @@ -43,8 +43,9 @@ export class MongoClient { */ async connect(options: ConnectOptions | string): Promise { 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); @@ -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); @@ -76,14 +77,14 @@ export class MongoClient { nameOnly?: boolean; authorizedCollections?: boolean; comment?: Document; - } = {} + } = {}, ): Promise { const { databases } = await this.getCluster().protocol.commandSingle( "admin", { listDatabases: 1, ...options, - } + }, ); return databases; } diff --git a/tests/cases/03_crud.ts b/tests/cases/03_crud.ts index 26fbf76..3979c6d 100644 --- a/tests/cases/03_crud.ts +++ b/tests/cases/03_crud.ts @@ -104,7 +104,7 @@ describe("crud operations", () => { date: new Date(dateNow), }, }, - { upsert: true } + { upsert: true }, ); assert(upsertedId); @@ -135,7 +135,7 @@ describe("crud operations", () => { username: "user1", }), MongoServerError, - "E11000" + "E11000", ); }); @@ -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"]); }); @@ -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( @@ -248,7 +248,7 @@ describe("crud operations", () => { { update: { $inc: { counter: 1 } }, new: false, - } + }, ); assert(find === null); @@ -257,7 +257,7 @@ 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( @@ -265,7 +265,7 @@ describe("crud operations", () => { { update: { $inc: { counter: 1 } }, new: true, - } + }, ); assert(updated !== null); @@ -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); @@ -341,7 +341,7 @@ describe("crud operations", () => { {}, { $push: { friends: { $each: ["Carol"] } }, - } + }, ); assertEquals(result, { matchedCount: 1, @@ -364,7 +364,7 @@ describe("crud operations", () => { {}, { $pull: { friends: "Bob" }, - } + }, ); assertEquals(result, { matchedCount: 1, @@ -387,7 +387,7 @@ describe("crud operations", () => { {}, { $push: { "likes.hobbies.indoor": "board games" }, - } + }, ); assertEquals(result, { matchedCount: 1, @@ -410,7 +410,7 @@ describe("crud operations", () => { {}, { $pullAll: { "likes.hobbies.indoor": ["board games", "cooking"] }, - } + }, ); assertEquals(result, { matchedCount: 1, @@ -433,7 +433,7 @@ describe("crud operations", () => { {}, { $pull: { "likes.hobbies.indoor": "board games" }, - } + }, ); assertEquals(result, { matchedCount: 1, @@ -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); @@ -484,7 +484,7 @@ describe("crud operations", () => { { username: "user1" }, { username: "user2", - } + }, ); assertEquals(result, { @@ -698,7 +698,7 @@ describe("crud operations", () => { ]); const result = await users.updateMany( { username: "many" }, - { $set: { username: "MANY" } } + { $set: { username: "MANY" } }, ); assertEquals(result, { matchedCount: 2, @@ -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(); @@ -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("mongo_test_users"); @@ -844,7 +844,7 @@ describe("crud operations", () => { { uid: 0, }, - { maxTimeMS: 100 } + { maxTimeMS: 100 }, ) .toArray(); @@ -854,7 +854,7 @@ describe("crud operations", () => { { uid: 0, }, - { maxTimeMS: 100 } + { maxTimeMS: 100 }, ); assertEquals(user1!.uid, 0); @@ -866,7 +866,7 @@ describe("crud operations", () => { uid: 0, $where: "sleep(10) || true", }, - { maxTimeMS: 1 } + { maxTimeMS: 1 }, ) .toArray(); assert(false); @@ -884,7 +884,7 @@ describe("crud operations", () => { uid: 0, $where: "sleep(10) || true", }, - { maxTimeMS: 1 } + { maxTimeMS: 1 }, ); assert(false); } catch (e) { @@ -969,7 +969,7 @@ describe("crud operations", () => { const createdCollection = await database.createCollection( testCollectionName, - options + options, ); assert(createdCollection); @@ -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, ); }); }); diff --git a/tests/cases/05_srv.ts b/tests/cases/05_srv.ts index bee2eea..09f1421 100644 --- a/tests/cases/05_srv.ts +++ b/tests/cases/05_srv.ts @@ -3,7 +3,7 @@ import { assertEquals, assertRejects, describe, it } from "../deps.ts"; function mockResolver( srvRecords: Partial[] = [], - txtRecords: string[][] = [] + txtRecords: string[][] = [], ) { return { resolveDns: (_url: string, type: Deno.RecordType) => { @@ -21,18 +21,19 @@ describe("SRV", () => { assertRejects( () => new Srv().resolve("foo.bar"), Error, - "Expected url in format 'host.domain.tld', received foo.bar" + "Expected url in format 'host.domain.tld', received foo.bar", ); }, }); it({ - name: "SRV: it throws an error if SRV resolution doesn't return any SRV records", + name: + "SRV: it throws an error if SRV resolution doesn't return any SRV records", fn() { assertRejects( () => new Srv(mockResolver()).resolve("mongohost.mongodomain.com"), Error, - "Expected at least one SRV record, received 0 for url mongohost.mongodomain.com" + "Expected at least one SRV record, received 0 for url mongohost.mongodomain.com", ); }, }); @@ -43,27 +44,28 @@ describe("SRV", () => { assertRejects( () => new Srv( - mockResolver([{ target: "mongohost1.mongodomain.com" }]) + mockResolver([{ target: "mongohost1.mongodomain.com" }]), ).resolve("mongohost.mongodomain.com"), Error, - "Expected exactly one TXT record, received 0 for url mongohost.mongodomain.com" + "Expected exactly one TXT record, received 0 for url mongohost.mongodomain.com", ); }, }); it({ - name: "SRV: it throws an error if TXT resolution returns more than one record", + name: + "SRV: it throws an error if TXT resolution returns more than one record", fn() { assertRejects( () => new Srv( mockResolver( [{ target: "mongohost1.mongodomain.com" }], - [["replicaSet=rs-0"], ["authSource=admin"]] - ) + [["replicaSet=rs-0"], ["authSource=admin"]], + ), ).resolve("mongohost.mongodomain.com"), Error, - "Expected exactly one TXT record, received 2 for url mongohost.mongodomain.com" + "Expected exactly one TXT record, received 2 for url mongohost.mongodomain.com", ); }, }); @@ -76,11 +78,11 @@ describe("SRV", () => { new Srv( mockResolver( [{ target: "mongohost1.mongodomain.com" }], - [["replicaSet=rs-0&authSource=admin&ssl=true"]] - ) + [["replicaSet=rs-0&authSource=admin&ssl=true"]], + ), ).resolve("mongohost.mongodomain.com"), Error, - "Illegal uri options: ssl=true" + "Illegal uri options: ssl=true", ); }, }); @@ -100,15 +102,15 @@ describe("SRV", () => { port: 27017, }, ], - [["replicaSet=rs-0&authSource=admin"]] - ) + [["replicaSet=rs-0&authSource=admin"]], + ), ).resolve("mongohost.mongodomain.com"); assertEquals(result.servers.length, 2); const server1 = result.servers.find( - (server) => server.host === "mongohost1.mongodomain.com" + (server) => server.host === "mongohost1.mongodomain.com", ); const server2 = result.servers.find( - (server) => server.host === "mongohost2.mongodomain.com" + (server) => server.host === "mongohost2.mongodomain.com", ); assertEquals(server1!.port, 27015); assertEquals(server2!.port, 27017); @@ -119,7 +121,8 @@ describe("SRV", () => { }); it({ - name: "SRV: it correctly parses seedlist and options for options split in two strings", + name: + "SRV: it correctly parses seedlist and options for options split in two strings", async fn() { const result = await new Srv( mockResolver( @@ -133,15 +136,15 @@ describe("SRV", () => { port: 27017, }, ], - [["replicaS", "et=rs-0&authSource=admin"]] - ) + [["replicaS", "et=rs-0&authSource=admin"]], + ), ).resolve("mongohost.mongodomain.com"); assertEquals(result.servers.length, 2); const server1 = result.servers.find( - (server) => server.host === "mongohost1.mongodomain.com" + (server) => server.host === "mongohost1.mongodomain.com", ); const server2 = result.servers.find( - (server) => server.host === "mongohost2.mongodomain.com" + (server) => server.host === "mongohost2.mongodomain.com", ); assertEquals(server1!.port, 27015); assertEquals(server2!.port, 27017);