Comparing version 1.0.6 to 1.1.0
@@ -19,12 +19,22 @@ "use strict"; | ||
const injection_js_1 = require("injection-js"); | ||
const retry = require("retry"); | ||
let Database = class Database { | ||
get connection() { | ||
if (!this.db) { | ||
try { | ||
this.db = mongodb_1.MongoClient.connect(this.uri); | ||
console.log(`Mongo: Connection opened: ${this.uri}`); | ||
} | ||
catch (e) { | ||
console.error('Mongo: Connection error', e); | ||
} | ||
const operation = retry.operation(); | ||
operation.attempt((attempt) => { | ||
this.db = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const db = yield mongodb_1.MongoClient.connect(this.uri); | ||
console.log(`Mongo: Connection opened: ${this.uri}`); | ||
resolve(db); | ||
} | ||
catch (e) { | ||
if (operation.retry(e)) | ||
return; | ||
console.error('Mongo: Connection error', e); | ||
reject(e); | ||
} | ||
})); | ||
}); | ||
} | ||
@@ -44,2 +54,2 @@ return this.db; | ||
exports.Database = Database; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvZGIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLHFDQUFxRjtBQUNyRiwrQ0FBMEM7QUFHMUMsSUFBYSxRQUFRLEdBQXJCO0lBS0UsSUFBSSxVQUFVO1FBQ1osRUFBRSxDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsRUFBRSxDQUFDLENBQUMsQ0FBQztZQUNiLElBQUksQ0FBQztnQkFDSCxJQUFJLENBQUMsRUFBRSxHQUFHLHFCQUFXLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztnQkFDeEMsT0FBTyxDQUFDLEdBQUcsQ0FBQyw2QkFBNkIsSUFBSSxDQUFDLEdBQUcsRUFBRSxDQUFDLENBQUM7WUFDdkQsQ0FBQztZQUFD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ZiAoIXRoaXMuZGIpIHtcbiAgICAgIGNvbnN0IG9wZXJhdGlvbiA9IHJldHJ5Lm9wZXJhdGlvbigpO1xuXG4gICAgICBvcGVyYXRpb24uYXR0ZW1wdCgoYXR0ZW1wdCkgPT4ge1xuICAgICAgICB0aGlzLmRiID0gbmV3IFByb21pc2UoYXN5bmMgKHJlc29sdmUsIHJlamVjdCkgPT4ge1xuICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICBjb25zdCBkYiA9IGF3YWl0IE1vbmdvQ2xpZW50LmNvbm5lY3QodGhpcy51cmkpO1xuICAgICAgICAgICAgY29uc29sZS5sb2coYE1vbmdvOiBDb25uZWN0aW9uIG9wZW5lZDogJHt0aGlzLnVyaX1gKTtcbiAgICAgICAgICAgIHJlc29sdmUoZGIpO1xuICAgICAgICAgIH0gY2F0Y2goZSkge1xuICAgICAgICAgICAgaWYgKG9wZXJhdGlvbi5yZXRyeShlKSkgcmV0dXJuO1xuICAgICAgICAgICAgY29uc29sZS5lcnJvcignTW9uZ286IENvbm5lY3Rpb24gZXJyb3InLCBlKTtcbiAgICAgICAgICAgIHJlamVjdChlKTtcbiAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgICAgfSk7XG4gICAgfVxuXG4gICAgcmV0dXJuIHRoaXMuZGI7XG4gIH1cblxuICBhc3luYyBjb25uZWN0KHVyaSk6IFByb21pc2U8RGI+IHtcbiAgICB0aGlzLnVyaSA9IHVyaTtcbiAgICByZXR1cm4gdGhpcy5jb25uZWN0aW9uO1xuICB9XG5cbn1cbiJdfQ== |
{ | ||
"name": "mongtype", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"description": "Mongo Repository for Node written in TypeScript", | ||
@@ -35,4 +35,5 @@ "main": "dist/index.js", | ||
"mongodb": "^2.2.25", | ||
"reflect-metadata": "^0.1.10" | ||
"reflect-metadata": "^0.1.10", | ||
"retry": "^0.10.1" | ||
} | ||
} |
import { UpdateWriteOpResult, ObjectID, MongoClient, Db, Collection } from 'mongodb'; | ||
import { Injectable } from 'injection-js'; | ||
import * as retry from 'retry'; | ||
@@ -12,8 +13,17 @@ @Injectable() | ||
if (!this.db) { | ||
try { | ||
this.db = MongoClient.connect(this.uri); | ||
console.log(`Mongo: Connection opened: ${this.uri}`); | ||
} catch(e) { | ||
console.error('Mongo: Connection error', e); | ||
} | ||
const operation = retry.operation(); | ||
operation.attempt((attempt) => { | ||
this.db = new Promise(async (resolve, reject) => { | ||
try { | ||
const db = await MongoClient.connect(this.uri); | ||
console.log(`Mongo: Connection opened: ${this.uri}`); | ||
resolve(db); | ||
} catch(e) { | ||
if (operation.retry(e)) return; | ||
console.error('Mongo: Connection error', e); | ||
reject(e); | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -20,0 +30,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46389
577
4
+ Addedretry@^0.10.1
+ Addedretry@0.10.1(transitive)