Skip to content

Commit

Permalink
Chore: remove instances of return-await pattern (#266)
Browse files Browse the repository at this point in the history
* Chore: remove redundant `return await` pattern

* Deps: update to `std@v0.110.0`
  • Loading branch information
BastiDood authored Oct 8, 2021
1 parent a152fb5 commit 4aa168d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 30 deletions.
19 changes: 9 additions & 10 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
export * as Bson from "./bson/mod.ts";
export * from "./bson/mod.ts";
export type { Document } from "./bson/mod.ts";
export { createHash } from "https://deno.land/std@0.107.0/hash/mod.ts";
// Switch back to std when std@0.107 lands
export { pbkdf2Sync } from "https://raw.githubusercontent.com/denoland/deno_std/b7c61a2/node/_crypto/pbkdf2.ts";
export { HmacSha1 } from "https://deno.land/std@0.107.0/hash/sha1.ts";
export { HmacSha256 } from "https://deno.land/std@0.107.0/hash/sha256.ts";
export { createHash } from "https://deno.land/std@0.110.0/hash/mod.ts";
export { pbkdf2Sync } from "https://deno.land/std@0.110.0/node/_crypto/pbkdf2.ts";
export { HmacSha1 } from "https://deno.land/std@0.110.0/hash/sha1.ts";
export { HmacSha256 } from "https://deno.land/std@0.110.0/hash/sha256.ts";
export * from "https://deno.land/x/bytes_formater@v1.4.0/mod.ts";
export { BufReader, writeAll } from "https://deno.land/std@0.107.0/io/mod.ts";
export { deferred } from "https://deno.land/std@0.107.0/async/deferred.ts";
export type { Deferred } from "https://deno.land/std@0.107.0/async/deferred.ts";
export * as b64 from "https://deno.land/std@0.107.0/encoding/base64.ts";
export { BufReader, writeAll } from "https://deno.land/std@0.110.0/io/mod.ts";
export { deferred } from "https://deno.land/std@0.110.0/async/deferred.ts";
export type { Deferred } from "https://deno.land/std@0.110.0/async/deferred.ts";
export * as b64 from "https://deno.land/std@0.110.0/encoding/base64.ts";
export {
assert,
assertEquals,
} from "https://deno.land/std@0.107.0/testing/asserts.ts";
} from "https://deno.land/std@0.110.0/testing/asserts.ts";
10 changes: 5 additions & 5 deletions src/auth/scram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ export class ScramAuthPlugin extends AuthPlugin {
return request;
}

async auth(authContext: AuthContext): Promise<Document> {
auth(authContext: AuthContext): Promise<Document> {
const response = authContext.response;
if (response && response.speculativeAuthenticate) {
return await continueScramConversation(
return continueScramConversation(
this.cryptoMethod,
response.speculativeAuthenticate,
authContext,
);
}
return await executeScram(this.cryptoMethod, authContext);
return executeScram(this.cryptoMethod, authContext);
}
}
export function cleanUsername(username: string) {
Expand Down Expand Up @@ -117,7 +117,7 @@ export async function executeScram(

const saslStartCmd = makeFirstMessage(cryptoMethod, credentials, nonce);
const result = await protocol.commandSingle(db, saslStartCmd);
return await continueScramConversation(cryptoMethod, result, authContext);
return continueScramConversation(cryptoMethod, result, authContext);
}

export async function continueScramConversation(
Expand Down Expand Up @@ -210,7 +210,7 @@ export async function continueScramConversation(
payload: new Uint8Array(0),
};

return await protocol.commandSingle(db, retrySaslContinueCmd);
return protocol.commandSingle(db, retrySaslContinueCmd);
}

//this is a hack to fix codification in payload (in being and end of payload exists a codification problem, needs investigation ...)
Expand Down
6 changes: 3 additions & 3 deletions src/auth/x509.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export class X509AuthPlugin extends AuthPlugin {
return handshakeDoc;
}

async auth(authContext: AuthContext): Promise<Document> {
auth(authContext: AuthContext): Promise<Document> {
if (authContext.response!.speculativeAuthenticate) {
return authContext.response!;
return Promise.resolve(authContext.response!);
}
return await authContext.protocol.commandSingle(
return authContext.protocol.commandSingle(
"$external",
x509AuthenticateCommand(authContext.credentials),
);
Expand Down
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export class MongoClient {
}

// TODO: add test cases
async runCommand<T = any>(db: string, body: Document): Promise<T> {
runCommand<T = any>(db: string, body: Document): Promise<T> {
assert(this.#cluster);
return await this.#cluster.protocol.commandSingle(db, body);
return this.#cluster.protocol.commandSingle(db, body);
}

database(name = this.#defaultDbName): Database {
Expand Down
8 changes: 4 additions & 4 deletions src/collection/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ export class Collection<T> {
});
}

async findOne(
findOne(
filter?: Filter<T>,
options?: FindOptions,
): Promise<T | undefined> {
const cursor = this.find(filter, options);
return await cursor.next();
return cursor.next();
}

/**
Expand Down Expand Up @@ -215,12 +215,12 @@ export class Collection<T> {
};
}

async updateMany(
updateMany(
filter: Filter<T>,
doc: UpdateFilter<T>,
options?: UpdateOptions,
) {
return await update(this.#protocol, this.#dbName, this.name, filter, doc, {
return update(this.#protocol, this.#dbName, this.name, filter, doc, {
...options,
multi: options?.multi ?? true,
});
Expand Down
8 changes: 4 additions & 4 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ export class Database {
return names;
}

async createUser(
createUser(
username: string,
password: string,
options?: CreateUserOptions,
) {
await this.#cluster.protocol.commandSingle(this.name, {
return this.#cluster.protocol.commandSingle(this.name, {
createUser: options?.username ?? username,
pwd: options?.password ?? password,
customData: options?.customData,
Expand All @@ -92,11 +92,11 @@ export class Database {
});
}

async dropUser(username: string, options: {
dropUser(username: string, options: {
writeConcern?: Document;
comment?: Document;
} = {}) {
await this.#cluster.protocol.commandSingle(this.name, {
return this.#cluster.protocol.commandSingle(this.name, {
dropUser: username,
writeConcern: options?.writeConcern,
comment: options?.comment,
Expand Down
4 changes: 2 additions & 2 deletions tests/test.deps.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export { exists } from "https://deno.land/std@0.107.0/fs/mod.ts";
export { exists } from "https://deno.land/std@0.110.0/fs/mod.ts";
export {
assert,
assertEquals,
assertThrows,
assertThrowsAsync,
} from "https://deno.land/std@0.107.0/testing/asserts.ts";
} from "https://deno.land/std@0.110.0/testing/asserts.ts";
export * as semver from "https://deno.land/x/semver@v1.4.0/mod.ts";

0 comments on commit 4aa168d

Please sign in to comment.