owservable 0.8.11 → 0.8.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,7 @@
1
1
  import { Connection } from 'mongoose';
2
2
  export default class MongoDBConnector {
3
- static init(mongoDbUri: string): Connection;
3
+ static init(mongoDbUri: string): Promise<Connection>;
4
4
  static get connection(): Connection;
5
- private static _instance;
6
- private readonly _connection;
5
+ private static _connection;
7
6
  private constructor();
8
7
  }
@@ -1,27 +1,44 @@
1
1
  'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  const mongoose = require("mongoose");
4
13
  class MongoDBConnector {
5
- constructor(mongoDbUri) {
6
- mongoose
7
- .connect(mongoDbUri, {
8
- poolSize: 10,
9
- useNewUrlParser: true,
10
- useUnifiedTopology: true
11
- })
12
- .then(() => ({}))
13
- .catch(console.error);
14
- this._connection = mongoose.connection;
15
- this._connection.on('error', console.error.bind(console, 'connection error:'));
16
- this._connection.once('open', () => console.log('ows -> MongoDB connected to', mongoDbUri));
17
- }
14
+ constructor() { }
18
15
  static init(mongoDbUri) {
19
- if (!MongoDBConnector._instance)
20
- MongoDBConnector._instance = new MongoDBConnector(mongoDbUri);
21
- return MongoDBConnector._instance._connection;
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ if (!this._connection) {
18
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
19
+ console.log('ows -> MongoDB connecting to', mongoDbUri);
20
+ mongoose
21
+ .connect(mongoDbUri, {
22
+ poolSize: 10,
23
+ useNewUrlParser: true,
24
+ useUnifiedTopology: true
25
+ })
26
+ .then(() => {
27
+ this._connection = mongoose.connection;
28
+ this._connection.on('error', console.error.bind(console, 'ows -> MongoDB connection error:'));
29
+ this._connection.once('open', () => console.log('ows -> MongoDB connected to', mongoDbUri));
30
+ resolve(this._connection);
31
+ })
32
+ .catch(reject);
33
+ }));
34
+ }
35
+ else {
36
+ return this._connection;
37
+ }
38
+ });
22
39
  }
23
40
  static get connection() {
24
- return MongoDBConnector._instance._connection;
41
+ return this._connection;
25
42
  }
26
43
  }
27
44
  exports.default = MongoDBConnector;
@@ -1 +1 @@
1
- {"version":3,"file":"mongodb.connector.js","sourceRoot":"","sources":["../../src/mongodb/mongodb.connector.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,qCAAqC;AAGrC,MAAqB,gBAAgB;IAapC,YAAoB,UAAkB;QACrC,QAAQ;aACN,OAAO,CAAC,UAAU,EAAE;YACpB,QAAQ,EAAE,EAAE;YAEZ,eAAe,EAAE,IAAI;YACrB,kBAAkB,EAAE,IAAI;SACxB,CAAC;aACD,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;aAChB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAEvB,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC;QACvC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC;QAC/E,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,UAAU,CAAC,CAAC,CAAC;IAC7F,CAAC;IA1BM,MAAM,CAAC,IAAI,CAAC,UAAkB;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C,CAAC;yBACD,KAAK,CAAC,MAAM,CAAC,CAAC;gBACjB,CAAC,CAAA,CAAC,CAAC;aAGH;iBAAM;gBACN,OAAO,IAAI,CAAC,WAAW,CAAC;aACxB;QACF,CAAC;KAAA;IAEM,MAAM,KAAK,UAAU;QAC3B,OAAO,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;CAKD;AAnCD,mCAmCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owservable",
3
- "version": "0.8.11",
3
+ "version": "0.8.14",
4
4
  "description": "owservable backend",
5
5
  "engines": {
6
6
  "node": ">=16"