From ffcdc003ad326c3007da5fcaf329acdf9ba70a34 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 14 Apr 2023 19:54:01 +0300 Subject: [PATCH] Type params for query funcs --- src/MongoDB.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/MongoDB.ts b/src/MongoDB.ts index 5c3a174..a126433 100644 --- a/src/MongoDB.ts +++ b/src/MongoDB.ts @@ -1,5 +1,5 @@ import { inspect } from "node:util"; -import { MongoClient, MongoClientOptions, Db } from "mongodb"; +import { MongoClient, MongoClientOptions, Db, Document, WithId } from "mongodb"; import { IServer, ILogger, LoggerClientOptions } from "./interfaces/index.js"; type Credentials = { @@ -120,7 +120,7 @@ class MongoDB { * @returns {Array} An array containing the corresponding objects for the query * @memberof Database */ - async find (db: string, query: object, options: object) { + async find (db: string, query: object, options: object): Promise[]> { if (!this.#db) throw new Error(`MongoDB not connected`); @@ -130,7 +130,7 @@ class MongoDB { this.#logger.debug(`Incoming find query for ${db} with parameters ${inspect(query)}`); - const cursor = this.#db.collection(db).find(query, options); + const cursor = this.#db.collection(db).find(query, options); return cursor.toArray(); } @@ -143,7 +143,7 @@ class MongoDB { * @returns {Object} An object containing the queried data * @memberof Database */ - async findOne (db: string, query: object, options = {}) { + async findOne (db: string, query: object, options = {}): Promise | null> { if (!this.#db) throw new Error(`MongoDB not connected`); @@ -151,7 +151,7 @@ class MongoDB { throw new TypeError('Expecting collection name for the first argument'); this.#logger.debug(`Incoming findOne query for ${db} with parameters ${inspect(query)}`); - const result = await this.#db.collection(db).findOne(query, options); + const result = await this.#db.collection(db).findOne(query, options); return result; } @@ -299,7 +299,7 @@ class MongoDB { return this.#db.collection(coll); } - async ensureIndex (collection: string, indices = []) { + async ensureIndex (collection: string, indices: string[] = []) { if (!this.#db) throw new Error(`MongoDB not connected`); if (!(indices instanceof Array))