@rws-framework/db 2.2.7 → 2.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { Collection } from 'mongodb';
1
+ import { Collection, MongoClient } from 'mongodb';
2
2
  import { ITimeSeries } from '../types/ITimeSeries';
3
3
  import { IModel } from '../models/interfaces/IModel';
4
4
  import { IDbConfigHandler } from '../types/DbConfigHandler';
@@ -15,6 +15,7 @@ declare class DBService {
15
15
  constructor(configService: IDbConfigHandler);
16
16
  private connectToDB;
17
17
  reconnect(opts?: IDBClientCreate): void;
18
+ static baseClientConstruct(dbUrl: string): MongoClient;
18
19
  private createBaseMongoClient;
19
20
  private createBaseMongoClientDB;
20
21
  cloneDatabase(source: string, target: string): Promise<void>;
@@ -45,10 +45,14 @@ class DBService {
45
45
  reconnect(opts = null) {
46
46
  this.connectToDB(opts);
47
47
  }
48
+ static baseClientConstruct(dbUrl) {
49
+ const client = new mongodb_1.MongoClient(dbUrl);
50
+ return client;
51
+ }
48
52
  async createBaseMongoClient() {
49
53
  var _a;
50
54
  const dbUrl = ((_a = this.opts) === null || _a === void 0 ? void 0 : _a.dbUrl) || this.configService.get('mongo_url');
51
- const client = new mongodb_1.MongoClient(dbUrl);
55
+ const client = DBService.baseClientConstruct(dbUrl);
52
56
  await client.connect();
53
57
  return client;
54
58
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/db",
3
3
  "private": false,
4
- "version": "2.2.7",
4
+ "version": "2.2.10",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -56,10 +56,17 @@ class DBService {
56
56
  this.connectToDB(opts);
57
57
  }
58
58
 
59
+ static baseClientConstruct(dbUrl: string): MongoClient
60
+ {
61
+ const client = new MongoClient(dbUrl);
62
+
63
+ return client;
64
+ }
65
+
59
66
  private async createBaseMongoClient(): Promise<MongoClient>
60
67
  {
61
68
  const dbUrl = this.opts?.dbUrl || this.configService.get('mongo_url');
62
- const client = new MongoClient(dbUrl);
69
+ const client = DBService.baseClientConstruct(dbUrl);
63
70
 
64
71
  await client.connect();
65
72
 
@@ -70,7 +77,7 @@ class DBService {
70
77
  private async createBaseMongoClientDB(): Promise<Db>
71
78
  {
72
79
  const dbName = this.opts?.dbName || this.configService.get('mongo_db');
73
- const client = await this. createBaseMongoClient();
80
+ const client = await this.createBaseMongoClient();
74
81
  return client.db(dbName);
75
82
  }
76
83