typing fixes

This commit is contained in:
Erik 2023-05-15 14:13:24 +03:00
parent 9cf686825c
commit f4e532afdf
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68
2 changed files with 12 additions and 6 deletions

View File

@ -72,7 +72,7 @@ class MessageBroker {
#logger: ILogger;
#subscribers: Map<string, Subscriber[]>;
#consumers: Map<string, {consumer: Consumer, options: Options.Consume}[]>;
#consumers: Map<string, {consumer: Consumer, options?: Options.Consume}[]>;
#_pQueue: InternalPublishMsg[];
#_qQueue: InternalQueueMsg[];
@ -204,7 +204,7 @@ class MessageBroker {
}
// Consume queue
async consume<T> (queue: string, consumer: Consumer<T>, options: Options.Consume) {
async consume<T> (queue: string, consumer: Consumer<T>, 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<T> (queue: string, consumer: Consumer<T>, options: Options.Consume): Promise<void> {
private async _consume<T> (queue: string, consumer: Consumer<T>, options?: Options.Consume): Promise<void> {
if (!this.#channel)
return Promise.reject(new Error('Channel doesn\'t exist'));
await this.#channel.consume(queue, async (msg: ConsumeMessage) => {

View File

@ -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<T extends Document> (db: string, query: MongoQuery, options?: object): Promise<WithId<T>[]> {
async find<T extends Document> (db: string, query: MongoQuery, options?: FindOptions<T>): Promise<WithId<T>[]> {
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<T extends Document> (db: string, query: MongoQuery, options = {}): Promise<WithId<T> | null> {
async findOne<T extends Document> (db: string, query: MongoQuery, options: FindOptions<T> = {}): Promise<WithId<T> | 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`);