Skip to content

Commit

Permalink
build(deps-dev): bump @types/node from 20.4.9 to 20.5.7 (#417)
Browse files Browse the repository at this point in the history
* build(deps-dev): bump @types/node from 20.4.9 to 20.5.7

Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 20.4.9 to 20.5.7.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Fixed ts error.

* Fixed typings.

* Fixed.

* Fixed tests.

* Fixed typescript.

* Added vitest in test.

* Skip certain tests.

* Fixed mockdb tests.

* Fixed tsc error

* Fixed all tests.

* Don't convert tests to js.

* Run all tests.

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: SamTV12345 <[email protected]>
  • Loading branch information
dependabot[bot] and SamTV12345 authored Aug 30, 2023
1 parent 282d21c commit 074bde0
Show file tree
Hide file tree
Showing 20 changed files with 1,189 additions and 599 deletions.
7 changes: 5 additions & 2 deletions databases/mock_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import events from 'events';

export const Database = class extends events.EventEmitter {
private settings: Settings;
public mock: any;
constructor(settings:Settings) {
super();
this.settings = {
writeInterval: 1,
...settings,
};
settings.mock = this;
this.settings = settings;
console.log("Initialized")
}

close(cb: ()=>{}) {
Expand All @@ -29,8 +32,8 @@ export const Database = class extends events.EventEmitter {
this.emit('get', key, cb);
}

init(cb:()=>{}) {
this.emit('init', cb);
async init(cb:()=>{}) {
this.emit('init', cb());
}

remove(key:string, cb:()=>{}) {
Expand Down
2 changes: 1 addition & 1 deletion databases/mongodb_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const Database = class extends AbstractDatabase {

clearPing() {
if (this.interval) {
clearInterval(this.interval);
clearInterval(this.interval[Symbol.toPrimitive]());
}
}

Expand Down
5 changes: 2 additions & 3 deletions databases/mysql_db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import util from 'util';
import {BulkObject} from './cassandra_db';

export const Database = class extends AbstractDatabase {
private _mysqlSettings: Settings;
private readonly _mysqlSettings: Settings;
private _pool: any;
constructor(settings:Settings) {
super();
Expand All @@ -45,8 +45,7 @@ export const Database = class extends AbstractDatabase {
try {
return await new Promise((resolve, reject) => {
options = {timeout: this.settings.queryTimeout, ...options};
// @ts-ignore
this._pool && this._pool.query(options, (err, ...args) => err != null ? reject(err) : resolve(args));
this._pool && this._pool.query(options, (err:Error, ...args:string[]) => err != null ? reject(err) : resolve(args));
});
} catch (err:any) {
this.logger.error(`${err.fatal ? 'Fatal ' : ''}MySQL error: ${err.stack || err}`);
Expand Down
22 changes: 9 additions & 13 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ const makeDoneCallback = (callback: (err?:any)=>{}, deprecated:(err:any)=>{}) =>
};

export const Database = class {
private type: any;
private readonly type: any;
private dbModule: any;
private readonly dbSettings: any;
private readonly wrapperSettings: any | {};
private readonly logger: Function | null;
private readonly db: any;
private db: any;
private metrics: any;
/**
* @param type The type of the database
Expand All @@ -60,7 +60,7 @@ export const Database = class {
* from another logging library should also work, but performance may be reduced if the logger
* object does not have is${Level}Enabled() methods (isDebugEnabled(), etc.).
*/
constructor(type: undefined | string, dbSettings: Settings | null | string, wrapperSettings?: null | {}, logger:any = null) {
constructor(type: undefined | string, dbSettings: Settings | null | string, wrapperSettings?: null | {}, logger: any = null) {
if (!type) {
type = 'sqlite';
dbSettings = null;
Expand All @@ -69,25 +69,21 @@ export const Database = class {

// saves all settings and require the db module
this.type = type;
this.dbModule = require(`./databases/${type}_db`);
this.dbSettings = dbSettings;
this.wrapperSettings = wrapperSettings;
this.logger = normalizeLogger(logger);
const db = new this.dbModule.Database(this.dbSettings);
db.logger = this.logger;
this.db = new DatabaseCache(db, this.wrapperSettings, this.logger);

// Expose the cache wrapper's metrics to the user. See lib/CacheAndBufferLayer.js for details.
//
// WARNING: This feature is EXPERIMENTAL -- do not assume it will continue to exist in its
// current form in a future version.
this.metrics = this.db.metrics;
}

/**
* @param callback - Deprecated. Node-style callback. If null, a Promise is returned.
*/
init(callback = null) {
async init(callback = null) {
this.dbModule = await import(`./databases/${this.type}_db`);
const db = new this.dbModule.Database(this.dbSettings);
db.logger = this.logger;
this.db = new DatabaseCache(db, this.wrapperSettings, this.logger);
this.metrics = this.db.metrics;
if (callback != null) {
return cbDb.init.call(this.db);
}
Expand Down
Loading

0 comments on commit 074bde0

Please sign in to comment.