Skip to content

Commit

Permalink
Merge pull request #50 from hapinessjs/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
juneil authored Jul 16, 2018
2 parents 787e3b6 + 4edab47 commit 9d903f4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hapiness/mongo",
"version": "2.0.2",
"version": "2.0.3",
"description": "Hapiness Module for MongoDB usage",
"main": "commonjs/index.js",
"types": "index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/module/adapters/hapiness-mongo-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class HapinessMongoAdapter extends EventEmitter {
}

public tryConnect(): Observable<void> {
__debugger.debug('tryConnect', `connecting to ${this._uri}`);
__debugger.debug('tryConnect', `connecting to ${UtilFunctions.hideCredentials(this._uri)}`);
this.emit('connecting', { uri: this._uri });
return this
._tryConnect()
Expand Down Expand Up @@ -127,7 +127,7 @@ export class HapinessMongoAdapter extends EventEmitter {
}

protected onDisconnected(): Observable<void> {
__debugger.debug('onDisconnected', `disconnected from ${this._uri}`);
__debugger.debug('onDisconnected', `disconnected from ${UtilFunctions.hideCredentials(this._uri)}`);

this.emit('disconnected', { uri: this._uri });

Expand Down
8 changes: 4 additions & 4 deletions src/module/adapters/mongoose-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Connection, Mongoose } from 'mongoose';

import { Observable } from 'rxjs/Observable';
import { HapinessMongoAdapter } from './hapiness-mongo-adapter';
import { Debugger } from '../shared';
import { Debugger, UtilFunctions } from '../shared';

const __debugger = new Debugger('MongooseAdapter');

Expand Down Expand Up @@ -35,12 +35,12 @@ export class MongooseAdapter extends HapinessMongoAdapter {
this._connection = mongoose.createConnection(this._uri, connectOptions);

this._connection.on('connected', () => {
__debugger.debug('on#connected', `connected to ${this._uri}`);
__debugger.debug('on#connected', `connected to ${UtilFunctions.hideCredentials(this._uri)}`);
this.emit('connected', { uri: this._uri });
});

this._connection.on('reconnectFailed', () => {
__debugger.debug('on#reconnectFailed', `reconnectFailed on ${this._uri}`);
__debugger.debug('on#reconnectFailed', `reconnectFailed on ${UtilFunctions.hideCredentials(this._uri)}`);
this.emit('reconnectFailed', { uri: this._uri });
});

Expand All @@ -65,7 +65,7 @@ export class MongooseAdapter extends HapinessMongoAdapter {

this._connection.on('error', (...args) => this.emit('error', ...args));
this._connection.on('disconnected', () => {
__debugger.debug('on#disconnected', `disconnected from ${this._uri}`);
__debugger.debug('on#disconnected', `disconnected from ${UtilFunctions.hideCredentials(this._uri)}`);
this.emit('disconnected', { uri: this._uri });
});

Expand Down
2 changes: 1 addition & 1 deletion src/module/mongo.extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class MongoClientExt implements OnExtensionLoad, OnModuleInstantiated, On
}

loadAdapters(mongoManager: MongoManager, adaptersToLoad: HapinessLoadAdapterConfig[]): Observable<void> {
__debugger.debug('loadAdapters', `Params => ${JSON.stringify(adaptersToLoad, null, 2)}`);
__debugger.debug('loadAdapters', '');
return Observable
.create(
observer => {
Expand Down
10 changes: 10 additions & 0 deletions src/module/shared/funct.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import * as Url from 'url';

export class UtilFunctions {

public static hideCredentials(uri: string): string {
if (!uri || !uri.length) {
return '';
}

return uri.replace(/\/\/.*@/, '//***:***@');
}

public static getMongoUri(dbUrl: string, db?: string) {
// If no db is provided we wannot append the db in the url
if (!db) {
Expand All @@ -19,4 +28,5 @@ export class UtilFunctions {

return [dbUrl, db].join('/');
}

}

0 comments on commit 9d903f4

Please sign in to comment.