Compare commits

..

No commits in common. "5cf42e538c1bfcd3fc8aa4ffaecbebdc1b95f7a2" and "fb5c6808049c0a74b11f92af8b6bc340ea32403d" have entirely different histories.

5 changed files with 13 additions and 13 deletions

View File

@ -1,3 +1,3 @@
export { MessageBroker, BrokerOptions } from "./src/MessageBroker.js"; export { MessageBroker } from "./src/MessageBroker.js";
export { MariaDB, MariaOptions } from './src/MariaDB.js'; export { MariaDB } from './src/MariaDB.js';
export { MongoDB, MongoOptions } from './src/MongoDB.js'; export { MongoDB } from './src/MongoDB.js';

View File

@ -1,6 +1,6 @@
{ {
"name": "@navy.gif/wrappers", "name": "@navy.gif/wrappers",
"version": "1.2.2", "version": "1.1.1",
"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

@ -14,7 +14,7 @@ type Credentials = {
database: string database: string
} }
export type MariaOptions = { type MariaOptions = {
load: boolean, load: boolean,
cluster: PoolClusterConfig, cluster: PoolClusterConfig,
client: PoolConfig, client: PoolConfig,

View File

@ -22,7 +22,7 @@ type QueueDef = {
maxPriority: number maxPriority: number
} }
export type BrokerOptions = { type BrokerOptions = {
host: string, host: string,
user: string, user: string,
pass: string, pass: string,

View File

@ -1,5 +1,5 @@
import { inspect } from "node:util"; import { inspect } from "node:util";
import { MongoClient, MongoClientOptions, Db, Document, WithId } from "mongodb"; import { MongoClient, MongoClientOptions, Db } from "mongodb";
import { IServer, ILogger, LoggerClientOptions } from "./interfaces/index.js"; import { IServer, ILogger, LoggerClientOptions } from "./interfaces/index.js";
type Credentials = { type Credentials = {
@ -12,7 +12,7 @@ type Credentials = {
authDb: string authDb: string
} }
export type MongoOptions = { type MongoOptions = {
credentials: Credentials, credentials: Credentials,
loggerOptions: LoggerClientOptions, loggerOptions: LoggerClientOptions,
client: MongoClientOptions client: MongoClientOptions
@ -120,7 +120,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: object, options?: object): Promise<WithId<T>[]> { async find (db: string, query: object, options: object) {
if (!this.#db) if (!this.#db)
throw new Error(`MongoDB not connected`); throw new Error(`MongoDB not connected`);
@ -130,7 +130,7 @@ class MongoDB {
this.#logger.debug(`Incoming find query for ${db} with parameters ${inspect(query)}`); this.#logger.debug(`Incoming find query for ${db} with parameters ${inspect(query)}`);
const cursor = this.#db.collection<T>(db).find(query, options); const cursor = this.#db.collection(db).find(query, options);
return cursor.toArray(); return cursor.toArray();
} }
@ -143,7 +143,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: object, options = {}): Promise<WithId<T> | null> { async findOne (db: string, query: object, options = {}) {
if (!this.#db) if (!this.#db)
throw new Error(`MongoDB not connected`); throw new Error(`MongoDB not connected`);
@ -151,7 +151,7 @@ class MongoDB {
throw new TypeError('Expecting collection name for the first argument'); throw new TypeError('Expecting collection name for the first argument');
this.#logger.debug(`Incoming findOne query for ${db} with parameters ${inspect(query)}`); this.#logger.debug(`Incoming findOne query for ${db} with parameters ${inspect(query)}`);
const result = await this.#db.collection<T>(db).findOne(query, options); const result = await this.#db.collection(db).findOne(query, options);
return result; return result;
} }
@ -299,7 +299,7 @@ class MongoDB {
return this.#db.collection(coll); return this.#db.collection(coll);
} }
async ensureIndex (collection: string, indices: string[] = []) { async ensureIndex (collection: string, indices = []) {
if (!this.#db) if (!this.#db)
throw new Error(`MongoDB not connected`); throw new Error(`MongoDB not connected`);
if (!(indices instanceof Array)) if (!(indices instanceof Array))