Compare commits
3 Commits
613399e928
...
d781458cee
Author | SHA1 | Date | |
---|---|---|---|
d781458cee | |||
855096e4d9 | |||
ebf2c7de77 |
893
.yarn/releases/yarn-4.1.1.cjs
vendored
Normal file
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
5
.yarnrc.yml
Normal file
@ -0,0 +1,5 @@
|
||||
nodeLinker: node-modules
|
||||
|
||||
yarnPath: .yarn/releases/yarn-4.1.1.cjs
|
||||
|
||||
npmRegistryServer: "https://registry.corgi.wtf"
|
14
package.json
14
package.json
@ -1,11 +1,10 @@
|
||||
{
|
||||
"name": "@navy.gif/wrappers",
|
||||
"version": "1.7.8",
|
||||
"version": "1.8.0",
|
||||
"description": "Various wrapper classes I use in my projects",
|
||||
"repository": "https://git.corgi.wtf/Navy.gif/wrappers.git",
|
||||
"author": "Navy.gif",
|
||||
"license": "MIT",
|
||||
"private": false,
|
||||
"type": "module",
|
||||
"main": "build/cjs/index.js",
|
||||
"module": "build/esm/index.js",
|
||||
@ -26,7 +25,9 @@
|
||||
"build:cjs": "tsc -p tsconfig.cjs.json && node ./scripts/declareTypes.js --common",
|
||||
"build:module": "tsc && node ./scripts/declareTypes.js --module",
|
||||
"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"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -35,14 +36,14 @@
|
||||
"@typescript-eslint/eslint-plugin": "^5.57.1",
|
||||
"@typescript-eslint/parser": "^5.57.1",
|
||||
"eslint": "^8.37.0",
|
||||
"typescript": "^5.0.3"
|
||||
"typescript": "^5.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/amqplib": "^0.10.1",
|
||||
"@types/mysql": "^2.15.21",
|
||||
"amqp-connection-manager": "^4.1.12",
|
||||
"amqplib": "^0.10.3",
|
||||
"mongodb": "^6.3.0",
|
||||
"mongodb": "^6.5.0",
|
||||
"mysql": "^2.18.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
@ -52,5 +53,6 @@
|
||||
"prom-client": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"packageManager": "yarn@4.1.1"
|
||||
}
|
||||
|
@ -124,7 +124,6 @@ class MessageBroker
|
||||
|
||||
async init ()
|
||||
{
|
||||
|
||||
if (!this.#load)
|
||||
return this.#logger?.info('Not loading RabbitMQ');
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
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';
|
||||
|
||||
type Credentials = {
|
||||
@ -61,7 +61,6 @@ class MongoDB
|
||||
|
||||
constructor (server: IServer, config: MongoOptions)
|
||||
{
|
||||
|
||||
if (!server)
|
||||
throw new Error('Missing reference to server!');
|
||||
if (!config)
|
||||
@ -108,7 +107,6 @@ class MongoDB
|
||||
.on('timeout', () => this.#logger?.warn('MongoDB timed out'))
|
||||
.on('close', () => this.#logger?.info('MongoDB client disconnected'))
|
||||
.on('open', () => this.#logger?.info('MongoDB client connected'));
|
||||
|
||||
}
|
||||
|
||||
get database ()
|
||||
@ -350,6 +348,24 @@ class MongoDB
|
||||
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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user