Compare commits

..

No commits in common. "d781458cee73c261c5f476ecb2d6e73c3ba36cec" and "613399e9286c4367c3e1faa5a38c367c5e879dbf" have entirely different histories.

6 changed files with 1190 additions and 2563 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,5 +0,0 @@
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.1.1.cjs
npmRegistryServer: "https://registry.corgi.wtf"

View File

@ -1,10 +1,11 @@
{ {
"name": "@navy.gif/wrappers", "name": "@navy.gif/wrappers",
"version": "1.8.0", "version": "1.7.8",
"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",
"license": "MIT", "license": "MIT",
"private": false,
"type": "module", "type": "module",
"main": "build/cjs/index.js", "main": "build/cjs/index.js",
"module": "build/esm/index.js", "module": "build/esm/index.js",
@ -25,9 +26,7 @@
"build:cjs": "tsc -p tsconfig.cjs.json && node ./scripts/declareTypes.js --common", "build:cjs": "tsc -p tsconfig.cjs.json && node ./scripts/declareTypes.js --common",
"build:module": "tsc && node ./scripts/declareTypes.js --module", "build:module": "tsc && node ./scripts/declareTypes.js --module",
"test": "yarn build && jest", "test": "yarn build && jest",
"release:patch": "yarn build && yarn version patch && yarn npm publish", "release": "yarn build && yarn publish",
"release:minor": "yarn build && yarn version minor && yarn npm publish",
"release:major": "yarn build && yarn version major && yarn npm publish",
"lint": "eslint --fix" "lint": "eslint --fix"
}, },
"devDependencies": { "devDependencies": {
@ -36,14 +35,14 @@
"@typescript-eslint/eslint-plugin": "^5.57.1", "@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1", "@typescript-eslint/parser": "^5.57.1",
"eslint": "^8.37.0", "eslint": "^8.37.0",
"typescript": "^5.4.3" "typescript": "^5.0.3"
}, },
"dependencies": { "dependencies": {
"@types/amqplib": "^0.10.1", "@types/amqplib": "^0.10.1",
"@types/mysql": "^2.15.21", "@types/mysql": "^2.15.21",
"amqp-connection-manager": "^4.1.12", "amqp-connection-manager": "^4.1.12",
"amqplib": "^0.10.3", "amqplib": "^0.10.3",
"mongodb": "^6.5.0", "mongodb": "^6.3.0",
"mysql": "^2.18.1" "mysql": "^2.18.1"
}, },
"peerDependencies": { "peerDependencies": {
@ -53,6 +52,5 @@
"prom-client": { "prom-client": {
"optional": true "optional": true
} }
}, }
"packageManager": "yarn@4.1.1"
} }

View File

@ -124,6 +124,7 @@ class MessageBroker
async init () async init ()
{ {
if (!this.#load) if (!this.#load)
return this.#logger?.info('Not loading RabbitMQ'); return this.#logger?.info('Not loading RabbitMQ');

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, FindOptions, ModifyResult, DistinctOptions } from 'mongodb'; import { MongoClient, MongoClientOptions, Db, Document, WithId, ObjectId, Filter, IndexSpecification, CreateIndexesOptions, FindOptions, ModifyResult } from 'mongodb';
import { IServer, ILogger } from './interfaces/index.js'; import { IServer, ILogger } from './interfaces/index.js';
type Credentials = { type Credentials = {
@ -61,6 +61,7 @@ class MongoDB
constructor (server: IServer, config: MongoOptions) constructor (server: IServer, config: MongoOptions)
{ {
if (!server) if (!server)
throw new Error('Missing reference to server!'); throw new Error('Missing reference to server!');
if (!config) if (!config)
@ -107,6 +108,7 @@ class MongoDB
.on('timeout', () => this.#logger?.warn('MongoDB timed out')) .on('timeout', () => this.#logger?.warn('MongoDB timed out'))
.on('close', () => this.#logger?.info('MongoDB client disconnected')) .on('close', () => this.#logger?.info('MongoDB client disconnected'))
.on('open', () => this.#logger?.info('MongoDB client connected')); .on('open', () => this.#logger?.info('MongoDB client connected'));
} }
get database () get database ()
@ -348,24 +350,6 @@ class MongoDB
return result; return result;
} }
async distinct<T extends Document> (db: string, key: string, filter: Filter<T> = {}, options: DistinctOptions = {})
{
if (!this.#db)
throw new Error('MongoDB not connected');
if (typeof db !== 'string')
throw new Error('Expecting collection name for the first argument');
if (filter && typeof filter._id === 'string' && filter._id.length === 24)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
filter._id = new ObjectId(filter._id);
const endTimer = MongoDB.#queryHistogram?.startTimer({ type: 'distinct' });
const result = await this.#db.collection<T>(db).distinct(key, filter, options);
if (endTimer)
endTimer();
return result;
}
/** /**
* Push data to an array * Push data to an array
* *

2818
yarn.lock

File diff suppressed because it is too large Load Diff