-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from hapinessjs/next
Next into master
- Loading branch information
Showing
16 changed files
with
501 additions
and
1,141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
language: node_js | ||
node_js: | ||
- "node" | ||
- 9 | ||
script: | ||
- yarn run test | ||
after_script: | ||
- yarn run coveralls | ||
- yarn run coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,26 @@ | ||
import * as mongoose from 'mongoose'; | ||
import * as mongo from 'mongodb'; | ||
|
||
import { Observable } from 'rxjs/Observable'; | ||
import { HapinessMongoAdapter } from './hapiness-mongo-adapter'; | ||
import { Debugger } from '../shared'; | ||
|
||
const __debugger = new Debugger('MongooseGridfsBucketAdapter'); | ||
import { MongooseAdapter } from './mongoose-adapter'; | ||
|
||
(<any>mongoose).Promise = global.Promise; | ||
|
||
export class MongooseGridFsBucketAdapter extends HapinessMongoAdapter { | ||
private _gridfsBucket: mongo.GridFSBucket; | ||
export class MongooseGridFsBucketAdapter extends MongooseAdapter { | ||
private _gridfsBucket; | ||
|
||
public static getInterfaceName(): string { | ||
return 'mongoose-gridfs-bucket'; | ||
} | ||
|
||
constructor(options) { | ||
super(options); | ||
} | ||
|
||
protected _tryConnect(): Observable<void> { | ||
return Observable | ||
.create(observer => { | ||
this._isReady = false; | ||
|
||
const connectOptions: mongoose.ConnectionOptions = { | ||
reconnectTries: Number.MAX_VALUE, | ||
reconnectInterval: 5000, | ||
}; | ||
|
||
this._connection = mongoose.createConnection(this._uri, connectOptions); | ||
|
||
// Seems that typings are not up to date at the moment | ||
this._connection['then'](connection => { | ||
observer.next(); | ||
observer.complete(); | ||
}) | ||
.catch(err => { | ||
observer.error(err); | ||
}); | ||
}); | ||
} | ||
|
||
protected _afterConnect(): Observable<void> { | ||
return Observable | ||
.create(observer => { | ||
this._gridfsBucket = new mongoose.mongo.GridFSBucket((<mongoose.Connection>this._connection).db); | ||
|
||
this.onConnected().subscribe(_ => { | ||
__debugger.debug('_afterConnect', '(subscribe) On connected success'); | ||
}, (e) => { | ||
__debugger.debug('_afterConnect', `(subscribe) On connected failed ${JSON.stringify(e, null, 2)}`); | ||
}); | ||
|
||
this._connection.once('error', err => | ||
this.onError(err).subscribe(_ => { | ||
__debugger.debug('_afterConnect', '(subscribe) On connection error #success'); | ||
}, (e) => { | ||
__debugger.debug('_afterConnect', `(subscribe) On connection error #failed ${JSON.stringify(e, null, 2)}`); | ||
}) | ||
); | ||
|
||
this._connection.once('disconnected', () => | ||
this.onDisconnected().subscribe(_ => { | ||
__debugger.debug('_afterConnect', '(subscribe) On connection disconnected #success'); | ||
}, (e) => { | ||
__debugger.debug('_afterConnect', `(subscribe) On connection disconnected #failed ${JSON.stringify(e, null, 2)}`); | ||
}) | ||
); | ||
|
||
observer.next(); | ||
observer.complete(); | ||
}); | ||
} | ||
|
||
public registerValue(schema: any, collection: string, collectionName?: string) { | ||
if (!!collectionName && collectionName.length) { | ||
return this._connection.model(collection, schema, collectionName); | ||
} | ||
return this._connection.model(collection, schema); | ||
} | ||
|
||
public getLibrary(): any { | ||
return this._gridfsBucket; | ||
this.on('connected', () => { | ||
this._gridfsBucket = new mongoose.mongo.GridFSBucket((<mongoose.Connection>this._connection).db); | ||
}); | ||
} | ||
|
||
// It seems that there is a bug here and it never really close the connection it always try to reconnect afterwards. | ||
public close(): Observable<void> { | ||
return Observable.fromPromise(this._connection.client.close(true)); | ||
public getLibrary<T = mongo.GridFSBucket>(): T { | ||
return <any>this._gridfsBucket; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
--require ts-node/register | ||
--throw-deprecation | ||
--colors | ||
--timeout 10000 | ||
-b | ||
--timeout 10000 |
Oops, something went wrong.