diff --git a/lib/index.js b/lib/index.js index 4bc4ebf..4276e8e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 = [];