Compare commits
3 Commits
91aa37b003
...
27671f7a74
Author | SHA1 | Date | |
---|---|---|---|
27671f7a74 | |||
f4e532afdf | |||
9cf686825c |
@ -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",
|
||||||
|
@ -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) => {
|
||||||
|
@ -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`);
|
||||||
|
Loading…
Reference in New Issue
Block a user