Skip to content

Commit

Permalink
refactor: refactor init
Browse files Browse the repository at this point in the history
  • Loading branch information
venki91 committed Nov 25, 2024
1 parent 850323b commit 1a0c61c
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,18 @@ class ErrsoleMongoDB extends EventEmitter {
constructor (uri, dbNameOrOptions, options = {}) {
super();

this.name = packageJSON.name;
this.version = packageJSON.version || '0.0.0';

const { collectionPrefix, ...connectionOptions } = typeof dbNameOrOptions === 'object' ? dbNameOrOptions : options;
let { collectionPrefix, ...connectionOptions } = typeof dbNameOrOptions === 'object' ? dbNameOrOptions : options;
collectionPrefix = collectionPrefix ? `${collectionPrefix.toLowerCase().replace(/[^a-z0-9]/g, '')}` : 'errsole';

this.uri = uri;
this.client = new MongoClient(uri, connectionOptions);
this.dbName = typeof dbNameOrOptions === 'string' ? dbNameOrOptions : undefined;
this.connectionOptions = connectionOptions;
this.logsCollectionName = `${collectionPrefix}_logs`;
this.notificationsCollectionName = `${collectionPrefix}_notifications`;
this.usersCollectionName = `${collectionPrefix}_users`;
this.configCollectionName = `${collectionPrefix}_config`;

const prefix = collectionPrefix
? `${collectionPrefix.toLowerCase().replace(/[^a-z0-9]/g, '')}_`
: 'errsole_';

this.client = new MongoClient(this.uri, this.connectionOptions);
this.logsCollectionName = `${prefix}logs`;
this.notificationsCollectionName = `${prefix}notifications`;
this.usersCollectionName = `${prefix}users`;
this.configCollectionName = `${prefix}config`;
this.name = packageJSON.name;
this.version = packageJSON.version || '0.0.0';

this.isConnectionInProgress = true;
this.pendingLogs = [];
Expand Down

0 comments on commit 1a0c61c

Please sign in to comment.