Compare commits
3 Commits
37a54d9932
...
17d9d124fe
Author | SHA1 | Date | |
---|---|---|---|
17d9d124fe | |||
50a4cb8535 | |||
c0eae8be4b |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@navy.gif/wrappers",
|
"name": "@navy.gif/wrappers",
|
||||||
"version": "1.3.16",
|
"version": "1.3.18",
|
||||||
"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",
|
||||||
|
@ -300,13 +300,13 @@ class MessageBroker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assertExchange (exchange: string, props: ExchangeDef) {
|
assertExchange (exchange: string, props?: ExchangeDef) {
|
||||||
if (!this.#channel)
|
if (!this.#channel)
|
||||||
throw new Error('Channel doesn\'t exist');
|
throw new Error('Channel doesn\'t exist');
|
||||||
return this.#channel.assertExchange(exchange, props.type ?? 'fanout', props);
|
return this.#channel.assertExchange(exchange, props?.type ?? 'fanout', props);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertQueue (queue: string, opts: QueueDef) {
|
assertQueue (queue: string, opts?: QueueDef) {
|
||||||
if (!this.#channel)
|
if (!this.#channel)
|
||||||
throw new Error('Channel doesn\'t exist');
|
throw new Error('Channel doesn\'t exist');
|
||||||
return this.#channel.assertQueue(queue, opts);
|
return this.#channel.assertQueue(queue, opts);
|
||||||
|
@ -301,7 +301,7 @@ class MongoDB {
|
|||||||
* @returns {object}
|
* @returns {object}
|
||||||
* @memberof Database
|
* @memberof Database
|
||||||
*/
|
*/
|
||||||
random (db: string, filter: Document = {}, amount = 1) {
|
random<T extends Document> (db: string, filter: Document = {}, amount = 1) {
|
||||||
|
|
||||||
if (!this.#db)
|
if (!this.#db)
|
||||||
throw new Error(`MongoDB not connected`);
|
throw new Error(`MongoDB not connected`);
|
||||||
@ -315,7 +315,7 @@ class MongoDB {
|
|||||||
if (amount > 100)
|
if (amount > 100)
|
||||||
amount = 100;
|
amount = 100;
|
||||||
|
|
||||||
const cursor = this.#db.collection(db).aggregate([{ $match: filter }, { $sample: { size: amount } }]);
|
const cursor = this.#db.collection(db).aggregate<T>([{ $match: filter }, { $sample: { size: amount } }]);
|
||||||
return cursor.toArray();
|
return cursor.toArray();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -327,10 +327,10 @@ class MongoDB {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
collection (coll: string) {
|
collection<T extends Document> (coll: string) {
|
||||||
if (!this.#db)
|
if (!this.#db)
|
||||||
throw new Error(`MongoDB not connected`);
|
throw new Error(`MongoDB not connected`);
|
||||||
return this.#db.collection(coll);
|
return this.#db.collection<T>(coll);
|
||||||
}
|
}
|
||||||
|
|
||||||
count (coll: string, query: Document) {
|
count (coll: string, query: Document) {
|
||||||
|
Loading…
Reference in New Issue
Block a user