@prosopo/database 2.6.5 → 3.0.6
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.
- package/CHANGELOG.md +101 -0
- package/dist/base/mongo.d.ts +3 -1
- package/dist/base/mongo.d.ts.map +1 -1
- package/dist/base/mongo.js +63 -29
- package/dist/base/mongo.js.map +1 -1
- package/dist/cjs/base/mongo.cjs +62 -30
- package/dist/cjs/databases/captcha.cjs +13 -4
- package/dist/cjs/databases/provider.cjs +113 -65
- package/dist/databases/captcha.d.ts.map +1 -1
- package/dist/databases/captcha.js +14 -5
- package/dist/databases/captcha.js.map +1 -1
- package/dist/databases/provider.d.ts +22 -7
- package/dist/databases/provider.d.ts.map +1 -1
- package/dist/databases/provider.js +113 -65
- package/dist/databases/provider.js.map +1 -1
- package/package.json +16 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,106 @@
|
|
|
1
1
|
# @prosopo/database
|
|
2
2
|
|
|
3
|
+
## 3.0.6
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
- b0d7207: Types for proper rotation
|
|
7
|
+
- Updated dependencies [b0d7207]
|
|
8
|
+
- @prosopo/types-database@3.0.6
|
|
9
|
+
- @prosopo/types@3.0.3
|
|
10
|
+
- @prosopo/user-access-policy@3.1.5
|
|
11
|
+
|
|
12
|
+
## 3.0.5
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [745cc89]
|
|
16
|
+
- @prosopo/config@3.1.0
|
|
17
|
+
- @prosopo/types-database@3.0.5
|
|
18
|
+
- @prosopo/user-access-policy@3.1.4
|
|
19
|
+
|
|
20
|
+
## 3.0.4
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies [5619b4b]
|
|
24
|
+
- @prosopo/config@3.0.1
|
|
25
|
+
- @prosopo/types-database@3.0.4
|
|
26
|
+
- @prosopo/user-access-policy@3.1.3
|
|
27
|
+
|
|
28
|
+
## 3.0.3
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- f682f0c: Moving type and fixing i18n config
|
|
32
|
+
- Updated dependencies [f682f0c]
|
|
33
|
+
- @prosopo/types-database@3.0.3
|
|
34
|
+
- @prosopo/types@3.0.2
|
|
35
|
+
- @prosopo/common@3.0.2
|
|
36
|
+
- @prosopo/user-access-policy@3.1.2
|
|
37
|
+
|
|
38
|
+
## 3.0.2
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- @prosopo/common@3.0.1
|
|
42
|
+
- @prosopo/types@3.0.1
|
|
43
|
+
- @prosopo/types-database@3.0.2
|
|
44
|
+
- @prosopo/user-access-policy@3.1.1
|
|
45
|
+
|
|
46
|
+
## 3.0.1
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [913f2a6]
|
|
50
|
+
- @prosopo/user-access-policy@3.1.0
|
|
51
|
+
- @prosopo/types-database@3.0.1
|
|
52
|
+
|
|
53
|
+
## 3.0.0
|
|
54
|
+
### Major Changes
|
|
55
|
+
|
|
56
|
+
- 64b5bcd: Access Controls
|
|
57
|
+
|
|
58
|
+
### Patch Changes
|
|
59
|
+
|
|
60
|
+
- Updated dependencies [64b5bcd]
|
|
61
|
+
- @prosopo/user-access-policy@3.0.0
|
|
62
|
+
- @prosopo/types-database@3.0.0
|
|
63
|
+
- @prosopo/common@3.0.0
|
|
64
|
+
- @prosopo/types@3.0.0
|
|
65
|
+
- @prosopo/config@3.0.0
|
|
66
|
+
|
|
67
|
+
## 2.6.9
|
|
68
|
+
### Patch Changes
|
|
69
|
+
|
|
70
|
+
- Updated dependencies [aee3efe]
|
|
71
|
+
- @prosopo/types@2.10.0
|
|
72
|
+
- @prosopo/types-database@2.7.6
|
|
73
|
+
- @prosopo/user-access-policy@2.6.8
|
|
74
|
+
|
|
75
|
+
## 2.6.8
|
|
76
|
+
### Patch Changes
|
|
77
|
+
|
|
78
|
+
- 86c22b8: structured logging
|
|
79
|
+
- Updated dependencies [86c22b8]
|
|
80
|
+
- @prosopo/user-access-policy@2.6.7
|
|
81
|
+
- @prosopo/types-database@2.7.5
|
|
82
|
+
- @prosopo/common@2.7.2
|
|
83
|
+
- @prosopo/types@2.9.1
|
|
84
|
+
- @prosopo/config@2.6.1
|
|
85
|
+
|
|
86
|
+
## 2.6.7
|
|
87
|
+
### Patch Changes
|
|
88
|
+
|
|
89
|
+
- Updated dependencies [30bb383]
|
|
90
|
+
- @prosopo/types@2.9.0
|
|
91
|
+
- @prosopo/common@2.7.1
|
|
92
|
+
- @prosopo/types-database@2.7.4
|
|
93
|
+
- @prosopo/user-access-policy@2.6.6
|
|
94
|
+
|
|
95
|
+
## 2.6.6
|
|
96
|
+
### Patch Changes
|
|
97
|
+
|
|
98
|
+
- Updated dependencies [8f0644a]
|
|
99
|
+
- @prosopo/common@2.7.0
|
|
100
|
+
- @prosopo/types@2.8.0
|
|
101
|
+
- @prosopo/types-database@2.7.3
|
|
102
|
+
- @prosopo/user-access-policy@2.6.5
|
|
103
|
+
|
|
3
104
|
## 2.6.5
|
|
4
105
|
|
|
5
106
|
### Patch Changes
|
package/dist/base/mongo.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { type Logger } from "@prosopo/common";
|
|
2
|
+
import type { IDatabase } from "@prosopo/types-database";
|
|
2
3
|
import mongoose, { type Connection } from "mongoose";
|
|
3
|
-
export declare class MongoDatabase {
|
|
4
|
+
export declare class MongoDatabase implements IDatabase {
|
|
4
5
|
protected readonly _url: string;
|
|
5
6
|
safeURL: string;
|
|
6
7
|
dbname: string;
|
|
7
8
|
connection?: Connection;
|
|
8
9
|
logger: Logger;
|
|
9
10
|
connected: boolean;
|
|
11
|
+
private connecting?;
|
|
10
12
|
constructor(url: string, dbname?: string, authSource?: string, logger?: Logger);
|
|
11
13
|
get url(): string;
|
|
12
14
|
getConnection(): mongoose.Connection;
|
package/dist/base/mongo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongo.d.ts","sourceRoot":"","sources":["../../src/base/mongo.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,MAAM,
|
|
1
|
+
{"version":3,"file":"mongo.d.ts","sourceRoot":"","sources":["../../src/base/mongo.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,MAAM,EAA6B,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,QAAQ,EAAE,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAarD,qBAAa,aAAc,YAAW,SAAS;IAC9C,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,UAAS;IAClB,OAAO,CAAC,UAAU,CAAC,CAAgB;gBAGlC,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM;IAgBhB,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,aAAa,IAAI,QAAQ,CAAC,UAAU;IAa9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAsGxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO5B"}
|
package/dist/base/mongo.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProsopoDBError,
|
|
1
|
+
import { ProsopoDBError, getLogger } from "@prosopo/common";
|
|
2
2
|
import { ServerApiVersion } from "mongodb";
|
|
3
3
|
import mongoose from "mongoose";
|
|
4
4
|
mongoose.set("strictQuery", false);
|
|
@@ -17,7 +17,7 @@ export class MongoDatabase {
|
|
|
17
17
|
this._url = parsedUrl.toString();
|
|
18
18
|
this.safeURL = this.url.replace(/\w+:\w+/, "<Credentials>");
|
|
19
19
|
this.dbname = dbname || parsedUrl.pathname.replace("/", "");
|
|
20
|
-
this.logger = logger ||
|
|
20
|
+
this.logger = logger || getLogger("info", import.meta.url);
|
|
21
21
|
}
|
|
22
22
|
get url() {
|
|
23
23
|
return this._url;
|
|
@@ -32,63 +32,97 @@ export class MongoDatabase {
|
|
|
32
32
|
return this.connection;
|
|
33
33
|
}
|
|
34
34
|
async connect() {
|
|
35
|
-
this.logger.info(
|
|
35
|
+
this.logger.info(() => ({
|
|
36
|
+
data: { mongoUrl: this.safeURL },
|
|
37
|
+
msg: "Connecting to database",
|
|
38
|
+
}));
|
|
36
39
|
try {
|
|
37
40
|
if (this.connected) {
|
|
38
|
-
this.logger.info(
|
|
41
|
+
this.logger.info(() => ({
|
|
42
|
+
data: { mongoUrl: this.safeURL },
|
|
43
|
+
msg: "Database connection already open",
|
|
44
|
+
}));
|
|
39
45
|
return;
|
|
40
46
|
}
|
|
41
|
-
this.
|
|
47
|
+
if (this.connecting) {
|
|
48
|
+
this.logger.info(() => ({
|
|
49
|
+
data: { mongoUrl: this.safeURL },
|
|
50
|
+
msg: "Database connection in progress, waiting for it to finish",
|
|
51
|
+
}));
|
|
52
|
+
return this.connecting;
|
|
53
|
+
}
|
|
54
|
+
this.connecting = new Promise((resolve, reject) => {
|
|
42
55
|
const connection = mongoose.createConnection(this.url, {
|
|
43
56
|
dbName: this.dbname,
|
|
44
57
|
serverApi: ServerApiVersion.v1,
|
|
45
58
|
});
|
|
46
|
-
|
|
47
|
-
this.logger.info(
|
|
59
|
+
const onConnected = () => {
|
|
60
|
+
this.logger.info(() => ({
|
|
61
|
+
data: { mongoUrl: this.safeURL },
|
|
62
|
+
msg: "Database connection opened",
|
|
63
|
+
}));
|
|
48
64
|
this.connected = true;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
65
|
+
this.connection = connection;
|
|
66
|
+
this.connecting = undefined;
|
|
67
|
+
resolve();
|
|
68
|
+
};
|
|
69
|
+
const onError = (err) => {
|
|
70
|
+
this.logger.error(() => ({
|
|
71
|
+
err,
|
|
72
|
+
data: { mongoUrl: this.safeURL },
|
|
73
|
+
msg: "Database error",
|
|
74
|
+
}));
|
|
52
75
|
this.connected = false;
|
|
53
|
-
this.
|
|
76
|
+
this.connecting = undefined;
|
|
54
77
|
reject(err);
|
|
55
|
-
}
|
|
56
|
-
connection.
|
|
57
|
-
|
|
58
|
-
this.connected = true;
|
|
59
|
-
resolve(connection);
|
|
60
|
-
});
|
|
78
|
+
};
|
|
79
|
+
connection.once("open", onConnected);
|
|
80
|
+
connection.once("error", onError);
|
|
61
81
|
connection.on("disconnected", () => {
|
|
62
82
|
this.connected = false;
|
|
63
|
-
this.logger.info(
|
|
83
|
+
this.logger.info(() => ({
|
|
84
|
+
data: { mongoUrl: this.safeURL },
|
|
85
|
+
msg: "Database disconnected",
|
|
86
|
+
}));
|
|
64
87
|
});
|
|
65
88
|
connection.on("reconnected", () => {
|
|
66
|
-
this.logger.info(`Database reconnected to ${this.safeURL}`);
|
|
67
89
|
this.connected = true;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.logger.error(`Database reconnect failed to ${this.safeURL}`);
|
|
90
|
+
this.logger.info(() => ({
|
|
91
|
+
data: { mongoUrl: this.safeURL },
|
|
92
|
+
msg: "Database reconnected",
|
|
93
|
+
}));
|
|
73
94
|
});
|
|
74
95
|
connection.on("close", () => {
|
|
75
96
|
this.connected = false;
|
|
76
|
-
this.logger.info(
|
|
97
|
+
this.logger.info(() => ({
|
|
98
|
+
data: { mongoUrl: this.safeURL },
|
|
99
|
+
msg: "Database connection closed",
|
|
100
|
+
}));
|
|
77
101
|
});
|
|
78
102
|
connection.on("fullsetup", () => {
|
|
79
103
|
this.connected = true;
|
|
80
|
-
this.logger.info(
|
|
81
|
-
|
|
104
|
+
this.logger.info(() => ({
|
|
105
|
+
data: { mongoUrl: this.safeURL },
|
|
106
|
+
msg: "Database connection is fully setup",
|
|
107
|
+
}));
|
|
82
108
|
});
|
|
83
109
|
});
|
|
110
|
+
return this.connecting;
|
|
84
111
|
}
|
|
85
112
|
catch (e) {
|
|
86
|
-
this.logger.error(
|
|
113
|
+
this.logger.error(() => ({
|
|
114
|
+
err: e,
|
|
115
|
+
data: { mongoUrl: this.safeURL },
|
|
116
|
+
msg: "Database connection error",
|
|
117
|
+
}));
|
|
87
118
|
throw e;
|
|
88
119
|
}
|
|
89
120
|
}
|
|
90
121
|
async close() {
|
|
91
|
-
this.logger.debug(
|
|
122
|
+
this.logger.debug(() => ({
|
|
123
|
+
data: { mongoUrl: this.safeURL },
|
|
124
|
+
msg: "Closing connection",
|
|
125
|
+
}));
|
|
92
126
|
await this.connection?.close();
|
|
93
127
|
}
|
|
94
128
|
}
|
package/dist/base/mongo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongo.js","sourceRoot":"","sources":["../../src/base/mongo.ts"],"names":[],"mappings":"AAaA,OAAO,EAAe,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"mongo.js","sourceRoot":"","sources":["../../src/base/mongo.ts"],"names":[],"mappings":"AAaA,OAAO,EAAe,cAAc,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,QAA6B,MAAM,UAAU,CAAC;AAErD,QAAQ,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;AAGnC,MAAM,gBAAgB,GAAG,2BAA2B,CAAC;AAQrD,MAAM,OAAO,aAAa;IASzB,YACC,GAAW,EACX,MAAe,EACf,UAAmB,EACnB,MAAe;QAPhB,cAAS,GAAG,KAAK,CAAC;QASjB,MAAM,YAAY,GAAG,GAAG,IAAI,gBAAgB,CAAC;QAC7C,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAC;QAC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;wBAChC,GAAG,EAAE,4BAA4B;qBACjC,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;gBAEH,UAAU,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE;oBAC/B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;oBACtB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;wBACvB,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE;wBAChC,GAAG,EAAE,oCAAoC;qBACzC,CAAC,CAAC,CAAC;gBACL,CAAC,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC,UAAU,CAAC;QACxB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;gBACxB,GAAG,EAAE,CAAC;gBACN,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE;gBAChC,GAAG,EAAE,2BAA2B;aAChC,CAAC,CAAC,CAAC;YACJ,MAAM,CAAC,CAAC;QACT,CAAC;IACF,CAAC;IAGD,KAAK,CAAC,KAAK;QACV,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;YACxB,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE;YAChC,GAAG,EAAE,oBAAoB;SACzB,CAAC,CAAC,CAAC;QACJ,MAAM,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC;IAChC,CAAC;CACD"}
|
package/dist/cjs/base/mongo.cjs
CHANGED
|
@@ -19,7 +19,7 @@ class MongoDatabase {
|
|
|
19
19
|
this._url = parsedUrl.toString();
|
|
20
20
|
this.safeURL = this.url.replace(/\w+:\w+/, "<Credentials>");
|
|
21
21
|
this.dbname = dbname || parsedUrl.pathname.replace("/", "");
|
|
22
|
-
this.logger = logger || common.
|
|
22
|
+
this.logger = logger || common.getLogger("info", module);
|
|
23
23
|
}
|
|
24
24
|
get url() {
|
|
25
25
|
return this._url;
|
|
@@ -37,65 +37,97 @@ class MongoDatabase {
|
|
|
37
37
|
* @description Connect to the database and set the various tables
|
|
38
38
|
*/
|
|
39
39
|
async connect() {
|
|
40
|
-
this.logger.info(
|
|
40
|
+
this.logger.info(() => ({
|
|
41
|
+
data: { mongoUrl: this.safeURL },
|
|
42
|
+
msg: "Connecting to database"
|
|
43
|
+
}));
|
|
41
44
|
try {
|
|
42
45
|
if (this.connected) {
|
|
43
|
-
this.logger.info(
|
|
46
|
+
this.logger.info(() => ({
|
|
47
|
+
data: { mongoUrl: this.safeURL },
|
|
48
|
+
msg: "Database connection already open"
|
|
49
|
+
}));
|
|
44
50
|
return;
|
|
45
51
|
}
|
|
46
|
-
this.
|
|
52
|
+
if (this.connecting) {
|
|
53
|
+
this.logger.info(() => ({
|
|
54
|
+
data: { mongoUrl: this.safeURL },
|
|
55
|
+
msg: "Database connection in progress, waiting for it to finish"
|
|
56
|
+
}));
|
|
57
|
+
return this.connecting;
|
|
58
|
+
}
|
|
59
|
+
this.connecting = new Promise((resolve, reject) => {
|
|
47
60
|
const connection = mongoose.createConnection(this.url, {
|
|
48
61
|
dbName: this.dbname,
|
|
49
62
|
serverApi: mongodb.ServerApiVersion.v1
|
|
50
63
|
});
|
|
51
|
-
|
|
52
|
-
this.logger.info(
|
|
64
|
+
const onConnected = () => {
|
|
65
|
+
this.logger.info(() => ({
|
|
66
|
+
data: { mongoUrl: this.safeURL },
|
|
67
|
+
msg: "Database connection opened"
|
|
68
|
+
}));
|
|
53
69
|
this.connected = true;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
70
|
+
this.connection = connection;
|
|
71
|
+
this.connecting = void 0;
|
|
72
|
+
resolve();
|
|
73
|
+
};
|
|
74
|
+
const onError = (err) => {
|
|
75
|
+
this.logger.error(() => ({
|
|
76
|
+
err,
|
|
77
|
+
data: { mongoUrl: this.safeURL },
|
|
78
|
+
msg: "Database error"
|
|
79
|
+
}));
|
|
57
80
|
this.connected = false;
|
|
58
|
-
this.
|
|
81
|
+
this.connecting = void 0;
|
|
59
82
|
reject(err);
|
|
60
|
-
}
|
|
61
|
-
connection.
|
|
62
|
-
|
|
63
|
-
this.connected = true;
|
|
64
|
-
resolve(connection);
|
|
65
|
-
});
|
|
83
|
+
};
|
|
84
|
+
connection.once("open", onConnected);
|
|
85
|
+
connection.once("error", onError);
|
|
66
86
|
connection.on("disconnected", () => {
|
|
67
87
|
this.connected = false;
|
|
68
|
-
this.logger.info(
|
|
88
|
+
this.logger.info(() => ({
|
|
89
|
+
data: { mongoUrl: this.safeURL },
|
|
90
|
+
msg: "Database disconnected"
|
|
91
|
+
}));
|
|
69
92
|
});
|
|
70
93
|
connection.on("reconnected", () => {
|
|
71
|
-
this.logger.info(`Database reconnected to ${this.safeURL}`);
|
|
72
94
|
this.connected = true;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.logger.error(`Database reconnect failed to ${this.safeURL}`);
|
|
95
|
+
this.logger.info(() => ({
|
|
96
|
+
data: { mongoUrl: this.safeURL },
|
|
97
|
+
msg: "Database reconnected"
|
|
98
|
+
}));
|
|
78
99
|
});
|
|
79
100
|
connection.on("close", () => {
|
|
80
101
|
this.connected = false;
|
|
81
|
-
this.logger.info(
|
|
102
|
+
this.logger.info(() => ({
|
|
103
|
+
data: { mongoUrl: this.safeURL },
|
|
104
|
+
msg: "Database connection closed"
|
|
105
|
+
}));
|
|
82
106
|
});
|
|
83
107
|
connection.on("fullsetup", () => {
|
|
84
108
|
this.connected = true;
|
|
85
|
-
this.logger.info(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
109
|
+
this.logger.info(() => ({
|
|
110
|
+
data: { mongoUrl: this.safeURL },
|
|
111
|
+
msg: "Database connection is fully setup"
|
|
112
|
+
}));
|
|
89
113
|
});
|
|
90
114
|
});
|
|
115
|
+
return this.connecting;
|
|
91
116
|
} catch (e) {
|
|
92
|
-
this.logger.error(
|
|
117
|
+
this.logger.error(() => ({
|
|
118
|
+
err: e,
|
|
119
|
+
data: { mongoUrl: this.safeURL },
|
|
120
|
+
msg: "Database connection error"
|
|
121
|
+
}));
|
|
93
122
|
throw e;
|
|
94
123
|
}
|
|
95
124
|
}
|
|
96
125
|
/** Close connection to the database */
|
|
97
126
|
async close() {
|
|
98
|
-
this.logger.debug(
|
|
127
|
+
this.logger.debug(() => ({
|
|
128
|
+
data: { mongoUrl: this.safeURL },
|
|
129
|
+
msg: "Closing connection"
|
|
130
|
+
}));
|
|
99
131
|
await this.connection?.close();
|
|
100
132
|
}
|
|
101
133
|
}
|
|
@@ -4,7 +4,7 @@ const common = require("@prosopo/common");
|
|
|
4
4
|
const typesDatabase = require("@prosopo/types-database");
|
|
5
5
|
require("../base/index.cjs");
|
|
6
6
|
const mongo = require("../base/mongo.cjs");
|
|
7
|
-
const logger = common.
|
|
7
|
+
const logger = common.getLogger("info", module);
|
|
8
8
|
var TableNames = /* @__PURE__ */ ((TableNames2) => {
|
|
9
9
|
TableNames2["frictionlessToken"] = "frictionlessToken";
|
|
10
10
|
TableNames2["session"] = "session";
|
|
@@ -64,7 +64,10 @@ class CaptchaDatabase extends mongo.MongoDatabase {
|
|
|
64
64
|
};
|
|
65
65
|
})
|
|
66
66
|
);
|
|
67
|
-
logger.info(
|
|
67
|
+
logger.info(() => ({
|
|
68
|
+
data: { insertedCount: result.insertedCount },
|
|
69
|
+
msg: "Mongo Saved Session Events"
|
|
70
|
+
}));
|
|
68
71
|
}
|
|
69
72
|
if (imageCaptchaEvents.length) {
|
|
70
73
|
const result = await this.tables.commitment.bulkWrite(
|
|
@@ -79,7 +82,10 @@ class CaptchaDatabase extends mongo.MongoDatabase {
|
|
|
79
82
|
};
|
|
80
83
|
})
|
|
81
84
|
);
|
|
82
|
-
logger.info(
|
|
85
|
+
logger.info(() => ({
|
|
86
|
+
data: { upsertedCount: result.upsertedCount },
|
|
87
|
+
msg: "Mongo Saved Image Events"
|
|
88
|
+
}));
|
|
83
89
|
}
|
|
84
90
|
if (powCaptchaEvents.length) {
|
|
85
91
|
const result = await this.tables.powcaptcha.bulkWrite(
|
|
@@ -94,7 +100,10 @@ class CaptchaDatabase extends mongo.MongoDatabase {
|
|
|
94
100
|
};
|
|
95
101
|
})
|
|
96
102
|
);
|
|
97
|
-
logger.info(
|
|
103
|
+
logger.info(() => ({
|
|
104
|
+
data: { upsertedCount: result.upsertedCount },
|
|
105
|
+
msg: "Mongo Saved PoW Events"
|
|
106
|
+
}));
|
|
98
107
|
}
|
|
99
108
|
await this.close();
|
|
100
109
|
}
|