Compare commits

..

3 Commits

Author SHA1 Message Date
27671f7a74
v1.3.15 2023-05-15 14:14:18 +03:00
f4e532afdf
typing fixes 2023-05-15 14:13:24 +03:00
9cf686825c
v1.3.14 2023-05-08 21:28:20 +03:00
3 changed files with 13 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@navy.gif/wrappers", "name": "@navy.gif/wrappers",
"version": "1.3.13", "version": "1.3.15",
"description": "Various wrapper classes I use in my projects", "description": "Various wrapper classes I use in my projects",
"repository": "https://git.corgi.wtf/Navy.gif/wrappers.git", "repository": "https://git.corgi.wtf/Navy.gif/wrappers.git",
"author": "Navy.gif", "author": "Navy.gif",

View File

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

View File

@ -1,5 +1,5 @@
import { inspect } from "node:util"; 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"; import { IServer, ILogger, LoggerClientOptions } from "./interfaces/index.js";
type Credentials = { type Credentials = {
@ -136,7 +136,7 @@ class MongoDB {
* @returns {Array} An array containing the corresponding objects for the query * @returns {Array} An array containing the corresponding objects for the query
* @memberof Database * @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) if (!this.#db)
throw new Error(`MongoDB not connected`); throw new Error(`MongoDB not connected`);
@ -162,7 +162,7 @@ class MongoDB {
* @returns {Object} An object containing the queried data * @returns {Object} An object containing the queried data
* @memberof Database * @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) if (!this.#db)
throw new Error(`MongoDB not connected`); throw new Error(`MongoDB not connected`);
@ -333,6 +333,12 @@ class MongoDB {
return this.#db.collection(coll); 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) { async ensureIndex (collection: string, indices: IndexSpecification = [], options?: CreateIndexesOptions) {
if (!this.#db) if (!this.#db)
throw new Error(`MongoDB not connected`); throw new Error(`MongoDB not connected`);