diff --git a/src/MessageBroker.ts b/src/MessageBroker.ts index fa70479..955bec7 100644 --- a/src/MessageBroker.ts +++ b/src/MessageBroker.ts @@ -72,7 +72,7 @@ class MessageBroker { #logger: ILogger; #subscribers: Map; - #consumers: Map; + #consumers: Map; #_pQueue: InternalPublishMsg[]; #_qQueue: InternalQueueMsg[]; @@ -204,7 +204,7 @@ class MessageBroker { } // Consume queue - async consume (queue: string, consumer: Consumer, options: Options.Consume) { + async consume (queue: string, consumer: Consumer, options?: Options.Consume) { if (!this.#channel) throw new Error('Channel does not exist'); @@ -216,7 +216,7 @@ class MessageBroker { this.#consumers.set(queue, list); } - private async _consume (queue: string, consumer: Consumer, options: Options.Consume): Promise { + private async _consume (queue: string, consumer: Consumer, options?: Options.Consume): Promise { if (!this.#channel) return Promise.reject(new Error('Channel doesn\'t exist')); await this.#channel.consume(queue, async (msg: ConsumeMessage) => { diff --git a/src/MongoDB.ts b/src/MongoDB.ts index 75c720b..e2910e9 100644 --- a/src/MongoDB.ts +++ b/src/MongoDB.ts @@ -1,5 +1,5 @@ import { inspect } from "node:util"; -import { MongoClient, MongoClientOptions, Db, Document, WithId, ObjectId, Filter, IndexSpecification, CreateIndexesOptions } from "mongodb"; +import { MongoClient, MongoClientOptions, Db, Document, WithId, ObjectId, Filter, IndexSpecification, CreateIndexesOptions, FindOptions } from "mongodb"; import { IServer, ILogger, LoggerClientOptions } from "./interfaces/index.js"; type Credentials = { @@ -136,7 +136,7 @@ class MongoDB { * @returns {Array} An array containing the corresponding objects for the query * @memberof Database */ - async find (db: string, query: MongoQuery, options?: object): Promise[]> { + async find (db: string, query: MongoQuery, options?: FindOptions): Promise[]> { if (!this.#db) throw new Error(`MongoDB not connected`); @@ -162,7 +162,7 @@ class MongoDB { * @returns {Object} An object containing the queried data * @memberof Database */ - async findOne (db: string, query: MongoQuery, options = {}): Promise | null> { + async findOne (db: string, query: MongoQuery, options: FindOptions = {}): Promise | null> { if (!this.#db) throw new Error(`MongoDB not connected`); @@ -333,6 +333,12 @@ class MongoDB { return this.#db.collection(coll); } + count (coll: string, query: Document) { + if (!this.#db) + throw new Error(`MongoDB not connected`); + return this.#db.collection(coll).countDocuments(query); + } + async ensureIndex (collection: string, indices: IndexSpecification = [], options?: CreateIndexesOptions) { if (!this.#db) throw new Error(`MongoDB not connected`);