Compare commits

..

2 Commits

Author SHA1 Message Date
0f44230b48 v.1.9.2 2024-10-12 13:51:44 +03:00
ea31ace0eb Helper func to parse validation error 2024-10-12 13:51:22 +03:00
3 changed files with 15 additions and 2 deletions

View File

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

@ -277,12 +277,15 @@ class MariaDB
} }
return new Promise<void>(resolve => return new Promise<void>(resolve =>
{ {
this.#logger?.info('Closing pool');
if (!this.#pool) if (!this.#pool)
{ {
this.#logger?.debug('Pool was already closed');
resolve(); return; resolve(); return;
} }
this.#pool.end(() => this.#pool.end(() =>
{ {
this.#logger?.status('Pool closed');
this.#pool?.removeAllListeners(); this.#pool?.removeAllListeners();
resolve(); resolve();
}); });

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, DistinctOptions, MongoServerError } from 'mongodb';
import { IServer, ILogger } from './interfaces/index.js'; import { IServer, ILogger } from './interfaces/index.js';
interface Credentials { interface Credentials {
@ -40,6 +40,16 @@ const objIsSubset = (superObj: StringIndexable, subObj: StringIndexable): boolea
}); });
}; };
export const parseValidationError = (error: MongoServerError) =>
{
if (error.code !== 121 || !error.errInfo)
throw new Error('Not a validation error');
const rule = error.errInfo.details.schemaRulesNotSatisfied;
const missing = rule.missingProperties as string[];
const required = rule.specifiedAs.required as string[];
return { missing, required };
};
/** /**
* A dedicated class to locally wrap the mongodb API wrapper * A dedicated class to locally wrap the mongodb API wrapper
* *