@arque/mongo-config-adapter
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -38,4 +38,6 @@ /// <reference types="mongoose/types/aggregate" /> | ||
private readonly cache; | ||
private connectionPromise; | ||
private _connection; | ||
private _init; | ||
constructor(opts?: Partial<Options>); | ||
init(): Promise<void>; | ||
private connection; | ||
@@ -42,0 +44,0 @@ private model; |
@@ -13,11 +13,11 @@ "use strict"; | ||
this.logger = { | ||
info: (0, debug_1.default)('MongoStoreAdapter:info'), | ||
error: (0, debug_1.default)('MongoStoreAdapter:error'), | ||
warn: (0, debug_1.default)('MongoStoreAdapter:warn'), | ||
verbose: (0, debug_1.default)('MongoStoreAdapter:verbose'), | ||
info: (0, debug_1.default)('info:MongoStoreAdapter'), | ||
error: (0, debug_1.default)('error:MongoStoreAdapter'), | ||
warn: (0, debug_1.default)('warn:MongoStoreAdapter'), | ||
verbose: (0, debug_1.default)('verbose:MongoStoreAdapter'), | ||
}; | ||
this.opts = { | ||
uri: (_a = opts === null || opts === void 0 ? void 0 : opts.uri) !== null && _a !== void 0 ? _a : 'mongodb://localhost:27017/arque', | ||
maxPoolSize: (_b = opts === null || opts === void 0 ? void 0 : opts.maxPoolSize) !== null && _b !== void 0 ? _b : 10, | ||
minPoolSize: (_c = opts === null || opts === void 0 ? void 0 : opts.minPoolSize) !== null && _c !== void 0 ? _c : 2, | ||
maxPoolSize: (_b = opts === null || opts === void 0 ? void 0 : opts.maxPoolSize) !== null && _b !== void 0 ? _b : 100, | ||
minPoolSize: (_c = opts === null || opts === void 0 ? void 0 : opts.minPoolSize) !== null && _c !== void 0 ? _c : 10, | ||
socketTimeoutMS: (_d = opts === null || opts === void 0 ? void 0 : opts.socketTimeoutMS) !== null && _d !== void 0 ? _d : 45000, | ||
@@ -33,20 +33,34 @@ serverSelectionTimeoutMS: (_e = opts === null || opts === void 0 ? void 0 : opts.serverSelectionTimeoutMS) !== null && _e !== void 0 ? _e : 10000, | ||
} | ||
async init() { | ||
if (!this._init) { | ||
this._init = (async () => { | ||
await this.connection(); | ||
})().catch((err) => { | ||
delete this._init; | ||
throw err; | ||
}); | ||
} | ||
await this._init; | ||
} | ||
async connection() { | ||
var _a, _b; | ||
if (!this.connectionPromise) { | ||
this.connectionPromise = mongoose_1.default.createConnection(this.opts.uri, { | ||
writeConcern: { | ||
w: 1, | ||
}, | ||
readPreference: 'secondaryPreferred', | ||
minPoolSize: this.opts.maxPoolSize, | ||
maxPoolSize: this.opts.maxPoolSize, | ||
socketTimeoutMS: (_a = this.opts) === null || _a === void 0 ? void 0 : _a.socketTimeoutMS, | ||
serverSelectionTimeoutMS: (_b = this.opts) === null || _b === void 0 ? void 0 : _b.serverSelectionTimeoutMS, | ||
}).asPromise().catch((err) => { | ||
delete this.connectionPromise; | ||
if (!this._connection) { | ||
this._connection = (async () => { | ||
var _a, _b; | ||
const connection = await mongoose_1.default.createConnection(this.opts.uri, { | ||
writeConcern: { | ||
w: 'majority', | ||
}, | ||
readPreference: 'secondaryPreferred', | ||
minPoolSize: this.opts.minPoolSize, | ||
maxPoolSize: this.opts.maxPoolSize, | ||
socketTimeoutMS: (_a = this.opts) === null || _a === void 0 ? void 0 : _a.socketTimeoutMS, | ||
serverSelectionTimeoutMS: (_b = this.opts) === null || _b === void 0 ? void 0 : _b.serverSelectionTimeoutMS, | ||
}).asPromise(); | ||
return connection; | ||
})().catch((err) => { | ||
delete this._connection; | ||
throw err; | ||
}); | ||
} | ||
return this.connectionPromise; | ||
return this._connection; | ||
} | ||
@@ -87,4 +101,4 @@ async model(model) { | ||
async close() { | ||
if (this.connectionPromise) { | ||
const connection = await this.connectionPromise; | ||
if (this._connection) { | ||
const connection = await this._connection; | ||
await connection.close(); | ||
@@ -91,0 +105,0 @@ } |
{ | ||
"name": "@arque/mongo-config-adapter", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"author": "ScaleForge", | ||
@@ -23,3 +23,3 @@ "homepage": "https://github.com/ScaleForge/arque#README.md", | ||
"dependencies": { | ||
"@arque/core": "^0.5.0", | ||
"@arque/core": "^0.6.0", | ||
"debug": "4.3.4", | ||
@@ -32,3 +32,3 @@ "lru-cache": "10.2.2", | ||
}, | ||
"gitHead": "a3c5c6907d96a89e191077a3c14598f2aaca656d" | ||
"gitHead": "ac65ce278706a8ff357f716b258acd71b00312e0" | ||
} |
Sorry, the diff of this file is not supported yet
13247
215
+ Added@arque/core@0.6.1(transitive)
- Removed@arque/core@0.5.0(transitive)
Updated@arque/core@^0.6.0