Compare commits

...

3 Commits

Author SHA1 Message Date
d781458cee v1.8.0 2024-03-29 09:23:22 +02:00
855096e4d9 Upgrade yarn 2024-03-29 09:22:02 +02:00
ebf2c7de77 Upgrade mongodb & add distinct operator 2024-03-29 09:18:46 +02:00
6 changed files with 2563 additions and 1190 deletions

893
.yarn/releases/yarn-4.1.1.cjs vendored Normal file

File diff suppressed because one or more lines are too long

5
.yarnrc.yml Normal file
View File

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

View File

@ -1,11 +1,10 @@
{ {
"name": "@navy.gif/wrappers", "name": "@navy.gif/wrappers",
"version": "1.7.8", "version": "1.8.0",
"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",
@ -26,7 +25,9 @@
"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": "yarn build && yarn publish", "release:patch": "yarn build && yarn version patch && yarn npm 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": {
@ -35,14 +36,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.0.3" "typescript": "^5.4.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.3.0", "mongodb": "^6.5.0",
"mysql": "^2.18.1" "mysql": "^2.18.1"
}, },
"peerDependencies": { "peerDependencies": {
@ -52,5 +53,6 @@
"prom-client": { "prom-client": {
"optional": true "optional": true
} }
} },
"packageManager": "yarn@4.1.1"
} }

View File

@ -124,7 +124,6 @@ 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 } from 'mongodb'; import { MongoClient, MongoClientOptions, Db, Document, WithId, ObjectId, Filter, IndexSpecification, CreateIndexesOptions, FindOptions, ModifyResult, DistinctOptions } from 'mongodb';
import { IServer, ILogger } from './interfaces/index.js'; import { IServer, ILogger } from './interfaces/index.js';
type Credentials = { type Credentials = {
@ -61,7 +61,6 @@ 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)
@ -108,7 +107,6 @@ 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 ()
@ -350,6 +348,24 @@ 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